OK In progress...

This commit is contained in:
Kolan Sh 2018-01-18 16:27:53 +03:00
parent ada0922c69
commit 55f2ced6bb
4 changed files with 96 additions and 93 deletions

View File

@ -14,7 +14,7 @@ namespace CairoChart {
* Current evaluated area. * Current evaluated area.
*/ */
public Cairo.Rectangle evarea = Cairo.Rectangle() public Cairo.Rectangle evarea = Cairo.Rectangle()
{ x = 0, y = 0, width = 1, height = 1 }; { x = 0, y = 0, width = 1, height = 1 };
/** /**
* Zoom Limits (relative coordinates: 0.0-1.0). * Zoom Limits (relative coordinates: 0.0-1.0).
@ -22,6 +22,12 @@ namespace CairoChart {
public Cairo.Rectangle zoom = Cairo.Rectangle() public Cairo.Rectangle zoom = Cairo.Rectangle()
{ x = 0, y = 0, width = 1, height = 1 }; { x = 0, y = 0, width = 1, height = 1 };
/**
* Plot Area Bounds.
*/
public Cairo.Rectangle plarea = Cairo.Rectangle()
{ x = 0, y = 0, width = 1, height = 1 };
/** /**
* Cairo Context of the Drawing Area. * Cairo Context of the Drawing Area.
*/ */
@ -61,16 +67,6 @@ namespace CairoChart {
public Line.Style selection_style = Line.Style (); public Line.Style selection_style = Line.Style ();
/**
* Plot Area Bounds.
*/
//public Cairo.Rectangle plot = ;
public double plot_x_min = 0;
public double plot_x_max = 0;
public double plot_y_min = 0;
public double plot_y_max = 0;
public bool joint_x { get; protected set; default = false; } public bool joint_x { get; protected set; default = false; }
public bool joint_y { get; protected set; default = false; } public bool joint_y { get; protected set; default = false; }
public Color joint_axis_color = Color (0, 0, 0, 1); public Color joint_axis_color = Color (0, 0, 0, 1);
@ -96,10 +92,7 @@ namespace CairoChart {
chart.evarea = this.evarea; chart.evarea = this.evarea;
chart.cursors = this.cursors.copy(); chart.cursors = this.cursors.copy();
chart.legend = this.legend.copy(); chart.legend = this.legend.copy();
chart.plot_x_max = this.plot_x_max; chart.plarea = this.plarea;
chart.plot_x_min = this.plot_x_min;
chart.plot_y_max = this.plot_y_max;
chart.plot_y_min = this.plot_y_min;
chart.zoom = this.zoom; chart.zoom = this.zoom;
chart.selection_style = this.selection_style; chart.selection_style = this.selection_style;
chart.series = this.series; chart.series = this.series;
@ -187,11 +180,11 @@ namespace CairoChart {
protected virtual void draw_plot_area_border () { protected virtual void draw_plot_area_border () {
color = border_color; color = border_color;
ctx.set_dash(null, 0); ctx.set_dash(null, 0);
ctx.move_to (plot_x_min, plot_y_min); ctx.move_to (plarea.x, plarea.y);
ctx.line_to (plot_x_min, plot_y_max); ctx.line_to (plarea.x, plarea.y + plarea.height);
ctx.line_to (plot_x_max, plot_y_max); ctx.line_to (plarea.x + plarea.width, plarea.y + plarea.height);
ctx.line_to (plot_x_max, plot_y_min); ctx.line_to (plarea.x + plarea.width, plarea.y);
ctx.line_to (plot_x_min, plot_y_min); ctx.line_to (plarea.x, plarea.y);
ctx.stroke (); ctx.stroke ();
} }
protected virtual void draw_series () { protected virtual void draw_series () {
@ -252,11 +245,11 @@ namespace CairoChart {
} }
var new_zoom = zoom; var new_zoom = zoom;
// TODO // TODO
new_zoom.x += (rect.x - plot_x_min) / (plot_x_max - plot_x_min) * zoom.width; new_zoom.x += (rect.x - plarea.x) / plarea.width * zoom.width;
var x_max = zoom.x + (x1 - plot_x_min) / (plot_x_max - plot_x_min) * zoom.width; var x_max = zoom.x + (x1 - plarea.x) / plarea.width * zoom.width;
new_zoom.width = x_max - new_zoom.x; new_zoom.width = x_max - new_zoom.x;
new_zoom.y += (rect.y - plot_y_min) / (plot_y_max - plot_y_min) * zoom.height; new_zoom.y += (rect.y - plarea.y) / plarea.height * zoom.height;
var y_max = zoom.y + (y1 - plot_y_min) / (plot_y_max - plot_y_min) * zoom.height; var y_max = zoom.y + (y1 - plarea.y) / plarea.height * zoom.height;
new_zoom.height = y_max - new_zoom.y; new_zoom.height = y_max - new_zoom.y;
zoom = new_zoom; zoom = new_zoom;
} }
@ -277,23 +270,23 @@ namespace CairoChart {
} }
public virtual void move (Point delta) { public virtual void move (Point delta) {
var d = delta; var d = delta;
d.x /= plot_x_max - plot_x_min; d.x *= - 1.0; d.x /= plarea.width; d.x *= - 1.0;
d.y /= plot_y_max - plot_y_min; d.y *= - 1.0; d.y /= plarea.height; d.y *= - 1.0;
var rzxmin = zoom.x, rzxmax = zoom.x + zoom.width, rzymin = zoom.y, rzymax = zoom.y + zoom.height; var rzxmin = zoom.x, rzxmax = zoom.x + zoom.width, rzymin = zoom.y, rzymax = zoom.y + zoom.height;
zoom_out(); zoom_out();
d.x *= plot_x_max - plot_x_min; d.x *= plarea.width;
d.y *= plot_y_max - plot_y_min; d.y *= plarea.height;
var xmin = plot_x_min + (plot_x_max - plot_x_min) * rzxmin; var xmin = plarea.x + plarea.width * rzxmin;
var xmax = plot_x_min + (plot_x_max - plot_x_min) * rzxmax; var xmax = plarea.x + plarea.width * rzxmax;
var ymin = plot_y_min + (plot_y_max - plot_y_min) * rzymin; var ymin = plarea.y + plarea.height * rzymin;
var ymax = plot_y_min + (plot_y_max - plot_y_min) * rzymax; var ymax = plarea.y + plarea.height * rzymax;
d.x *= rzxmax - rzxmin; d.y *= rzymax - rzymin; d.x *= rzxmax - rzxmin; d.y *= rzymax - rzymin;
if (xmin + d.x < plot_x_min) d.x = plot_x_min - xmin; if (xmin + d.x < plarea.x) d.x = plarea.x - xmin;
if (xmax + d.x > plot_x_max) d.x = plot_x_max - xmax; if (xmax + d.x > plarea.x + plarea.width) d.x = plarea.x + plarea.width - xmax;
if (ymin + d.y < plot_y_min) d.y = plot_y_min - ymin; if (ymin + d.y < plarea.y) d.y = plarea.y - ymin;
if (ymax + d.y > plot_y_max) d.y = plot_y_max - ymax; if (ymax + d.y > plarea.y + plarea.height) d.y = plarea.y + plarea.height - ymax;
zoom_in (Cairo.Rectangle(){x = xmin + d.x, y = ymin + d.y, width = xmax - xmin, height = ymax - ymin}); zoom_in (Cairo.Rectangle(){x = xmin + d.x, y = ymin + d.y, width = xmax - xmin, height = ymax - ymin});
} }
@ -303,10 +296,10 @@ namespace CairoChart {
series[si].join_calc(is_x, si, ref nskip); series[si].join_calc(is_x, si, ref nskip);
} }
protected virtual void calc_plot_area () { protected virtual void calc_plot_area () {
plot_x_min = evarea.x + legend.indent; plarea.x = evarea.x + legend.indent;
plot_x_max = evarea.x + evarea.width - legend.indent; plarea.width = evarea.width - 2 * legend.indent;
plot_y_min = evarea.y + legend.indent; plarea.y = evarea.y + legend.indent;
plot_y_max = evarea.y + evarea.height - legend.indent; plarea.height = evarea.height - 2 * legend.indent;
// Check for joint axes // Check for joint axes
joint_x = joint_y = true; joint_x = joint_y = true;
@ -325,35 +318,35 @@ namespace CairoChart {
} }
protected virtual bool x_in_plot_area (double x) { protected virtual bool x_in_plot_area (double x) {
if (math.x_in_range(x, plot_x_min, plot_x_max)) if (math.x_in_range(x, plarea.x, plarea.x + plarea.width))
return true; return true;
return false; return false;
} }
protected virtual bool y_in_plot_area (double y) { protected virtual bool y_in_plot_area (double y) {
if (math.y_in_range(y, plot_y_min, plot_y_max)) if (math.y_in_range(y, plarea.y, plarea.y + plarea.height))
return true; return true;
return false; return false;
} }
public virtual bool point_in_plot_area (Point p) { public virtual bool point_in_plot_area (Point p) {
if (math.point_in_rect (p, plot_x_min, plot_x_max, plot_y_min, plot_y_max)) if (math.point_in_rect (p, plarea.x, plarea.x + plarea.width, plarea.y, plarea.y + plarea.height))
return true; return true;
return false; return false;
} }
public virtual Float128 scr2rel_x (Float128 x) { public virtual Float128 scr2rel_x (Float128 x) {
return zoom.x + (x - plot_x_min) / (plot_x_max - plot_x_min) * zoom.width; return zoom.x + (x - plarea.x) / plarea.width * zoom.width;
} }
public virtual Float128 scr2rel_y (Float128 y) { public virtual Float128 scr2rel_y (Float128 y) {
return zoom.y + zoom.height - (plot_y_max - y) / (plot_y_max - plot_y_min) * zoom.height; return zoom.y + zoom.height - (plarea.y + plarea.height - y) / plarea.height * zoom.height;
} }
public virtual Point scr2rel_point (Point p) { public virtual Point scr2rel_point (Point p) {
return Point (scr2rel_x(p.x), scr2rel_y(p.y)); return Point (scr2rel_x(p.x), scr2rel_y(p.y));
} }
public virtual Float128 rel2scr_x(Float128 x) { public virtual Float128 rel2scr_x(Float128 x) {
return plot_x_min + (plot_x_max - plot_x_min) * (x - zoom.x) / zoom.width; return plarea.x + plarea.width * (x - zoom.x) / zoom.width;
} }
public virtual Float128 rel2scr_y(Float128 y) { public virtual Float128 rel2scr_y(Float128 y) {
return plot_y_min + (plot_y_max - plot_y_min) * (y - zoom.y) / zoom.height; return plarea.y + plarea.height * (y - zoom.y) / zoom.height;
} }
public virtual Point128 rel2scr_point (Point128 p) { public virtual Point128 rel2scr_point (Point128 p) {
return Point128 (rel2scr_x(p.x), rel2scr_y(p.y)); return Point128 (rel2scr_x(p.x), rel2scr_y(p.y));

View File

@ -132,7 +132,7 @@ namespace CairoChart {
case Orientation.VERTICAL: case Orientation.VERTICAL:
Float128 y = 0.0; Float128 y = 0.0;
if (chart.math.vcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]), chart.rel2scr_x(c.x), if (chart.math.vcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]), chart.rel2scr_x(c.x),
chart.plot_y_min, chart.plot_y_max, out y)) { chart.plarea.y, chart.plarea.y + chart.plarea.height, out y)) {
var point = Point128(s.get_real_x(chart.rel2scr_x(c.x)), s.get_real_y(y)); var point = Point128(s.get_real_x(chart.rel2scr_x(c.x)), s.get_real_y(y));
Point128 size; bool show_x, show_date, show_time, show_y; Point128 size; bool show_x, show_date, show_time, show_y;
cross_what_to_show(chart, s, out show_x, out show_time, out show_date, out show_y); cross_what_to_show(chart, s, out show_x, out show_time, out show_date, out show_y);
@ -144,7 +144,7 @@ namespace CairoChart {
case Orientation.HORIZONTAL: case Orientation.HORIZONTAL:
Float128 x = 0.0; Float128 x = 0.0;
if (chart.math.hcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]), if (chart.math.hcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]),
chart.plot_x_min, chart.plot_x_max, chart.rel2scr_y(c.y), out x)) { chart.plarea.x, chart.plarea.x + chart.plarea.width, chart.rel2scr_y(c.y), out x)) {
var point = Point128(s.get_real_x(x), s.get_real_y(chart.rel2scr_y(c.y))); var point = Point128(s.get_real_x(x), s.get_real_y(chart.rel2scr_y(c.y)));
Point128 size; bool show_x, show_date, show_time, show_y; Point128 size; bool show_x, show_date, show_time, show_y;
cross_what_to_show(chart, s, out show_x, out show_time, out show_date, out show_y); cross_what_to_show(chart, s, out show_x, out show_time, out show_date, out show_y);
@ -233,8 +233,8 @@ namespace CairoChart {
calc_cursors_value_positions(chart); calc_cursors_value_positions(chart);
for (var cci = 0, max_cci = cursors_crossings.length; cci < max_cci; ++cci) { for (var cci = 0, max_cci = cursors_crossings.length; cci < max_cci; ++cci) {
var low = Point128(chart.plot_x_max, chart.plot_y_max); // low and high var low = Point128(chart.plarea.x + chart.plarea.width, chart.plarea.y + chart.plarea.height); // low and high
var high = Point128(chart.plot_x_min, chart.plot_y_min); // points of the cursor var high = Point128(chart.plarea.x, chart.plarea.y); // points of the cursor
unowned CursorCross[] ccs = cursors_crossings[cci].crossings; unowned CursorCross[] ccs = cursors_crossings[cci].crossings;
cursor_style.line_style.set(chart); cursor_style.line_style.set(chart);
for (var ci = 0, max_ci = ccs.length; ci < max_ci; ++ci) { for (var ci = 0, max_ci = ccs.length; ci < max_ci; ++ci) {
@ -250,21 +250,21 @@ namespace CairoChart {
if (chart.joint_x) { if (chart.joint_x) {
switch (s.axis_x.position) { switch (s.axis_x.position) {
case Axis.Position.LOW: high.y = chart.plot_y_max + s.axis_x.font_indent; break; case Axis.Position.LOW: high.y = chart.plarea.y + chart.plarea.height + s.axis_x.font_indent; break;
case Axis.Position.HIGH: low.y = chart.plot_y_min - s.axis_x.font_indent; break; case Axis.Position.HIGH: low.y = chart.plarea.y - s.axis_x.font_indent; break;
case Axis.Position.BOTH: case Axis.Position.BOTH:
high.y = chart.plot_y_max + s.axis_x.font_indent; high.y = chart.plarea.y + chart.plarea.height + s.axis_x.font_indent;
low.y = chart.plot_y_min - s.axis_x.font_indent; low.y = chart.plarea.y - s.axis_x.font_indent;
break; break;
} }
} }
if (chart.joint_y) { if (chart.joint_y) {
switch (s.axis_y.position) { switch (s.axis_y.position) {
case Axis.Position.LOW: low.x = chart.plot_x_min - s.axis_y.font_indent; break; case Axis.Position.LOW: low.x = chart.plarea.x - s.axis_y.font_indent; break;
case Axis.Position.HIGH: high.x = chart.plot_x_max + s.axis_y.font_indent; break; case Axis.Position.HIGH: high.x = chart.plarea.x + chart.plarea.width + s.axis_y.font_indent; break;
case Axis.Position.BOTH: case Axis.Position.BOTH:
low.x = chart.plot_x_min - s.axis_y.font_indent; low.x = chart.plarea.x - s.axis_y.font_indent;
high.x = chart.plot_x_max + s.axis_y.font_indent; high.x = chart.plarea.x + chart.plarea.width + s.axis_y.font_indent;
break; break;
} }
} }

View File

@ -70,8 +70,8 @@ namespace CairoChart {
for (int i = 1; i < points.length; ++i) { for (int i = 1; i < points.length; ++i) {
Point c, d; Point c, d;
if (chart.math.cut_line ( if (chart.math.cut_line (
Point(chart.plot_x_min, chart.plot_y_min), Point(chart.plarea.x, chart.plarea.y),
Point(chart.plot_x_max, chart.plot_y_max), Point(chart.plarea.x + chart.plarea.width, chart.plarea.y + chart.plarea.height),
Point(get_scr_x(points[i - 1].x), get_scr_y(points[i - 1].y)), Point(get_scr_x(points[i - 1].x), get_scr_y(points[i - 1].y)),
Point(get_scr_x(points[i].x), get_scr_y(points[i].y)), Point(get_scr_x(points[i].x), get_scr_y(points[i].y)),
out c, out d) out c, out d)
@ -136,28 +136,40 @@ namespace CairoChart {
case Cursors.Orientation.VERTICAL: case Cursors.Orientation.VERTICAL:
if (is_x && chart.joint_x) if (is_x && chart.joint_x)
switch (axis.position) { switch (axis.position) {
case Axis.Position.LOW: chart.plot_y_max -= max_rec_height + axis.font_indent; break; case Axis.Position.LOW: chart.plarea.height -= max_rec_height + axis.font_indent; break;
case Axis.Position.HIGH: chart.plot_y_min += max_rec_height + axis.font_indent; break; case Axis.Position.HIGH:
var tmp = max_rec_height + axis.font_indent;
chart.plarea.y += tmp; chart.plarea.height -= tmp;
break;
} }
break; break;
case Cursors.Orientation.HORIZONTAL: case Cursors.Orientation.HORIZONTAL:
if (!is_x && chart.joint_y) if (!is_x && chart.joint_y)
switch (s.axis_y.position) { switch (s.axis_y.position) {
case Axis.Position.LOW: chart.plot_x_min += max_rec_width + s.axis_y.font_indent; break; case Axis.Position.LOW:
case Axis.Position.HIGH: chart.plot_x_max -= max_rec_width + s.axis_y.font_indent; break; var tmp = max_rec_width + s.axis_y.font_indent;
chart.plarea.x += tmp; chart.plarea.width -= tmp;
break;
case Axis.Position.HIGH: chart.plarea.width -= max_rec_width + s.axis_y.font_indent; break;
} }
break; break;
} }
} }
if (is_x && (!chart.joint_x || si == chart.zoom_1st_idx)) if (is_x && (!chart.joint_x || si == chart.zoom_1st_idx))
switch (axis.position) { switch (axis.position) {
case Axis.Position.LOW: chart.plot_y_max -= max_rec_height + max_font_indent + max_axis_font_height; break; case Axis.Position.LOW: chart.plarea.height -= max_rec_height + max_font_indent + max_axis_font_height; break;
case Axis.Position.HIGH: chart.plot_y_min += max_rec_height + max_font_indent + max_axis_font_height; break; case Axis.Position.HIGH:
var tmp = max_rec_height + max_font_indent + max_axis_font_height;
chart.plarea.y += tmp; chart.plarea.height -= tmp;
break;
} }
if (!is_x && (!chart.joint_y || si == chart.zoom_1st_idx)) if (!is_x && (!chart.joint_y || si == chart.zoom_1st_idx))
switch (s.axis_y.position) { switch (s.axis_y.position) {
case Axis.Position.LOW: chart.plot_x_min += max_rec_width + max_font_indent + max_axis_font_width; break; case Axis.Position.LOW:
case Axis.Position.HIGH: chart.plot_x_max -= max_rec_width + max_font_indent + max_axis_font_width; break; var tmp = max_rec_width + max_font_indent + max_axis_font_width;
chart.plarea.x += tmp; chart.plarea.width -= tmp;
break;
case Axis.Position.HIGH: chart.plarea.width -= max_rec_width + max_font_indent + max_axis_font_width; break;
} }
} }
@ -280,9 +292,9 @@ namespace CairoChart {
double y = chart.evarea.y + chart.evarea.height - max_rec_height - axis_x.font_indent - (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_indent); double y = chart.evarea.y + chart.evarea.height - max_rec_height - axis_x.font_indent - (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_indent);
ctx.move_to (scr_x, y); ctx.move_to (scr_x, y);
if (joint_x) if (joint_x)
ctx.line_to (scr_x, chart.plot_y_min); ctx.line_to (scr_x, chart.plarea.y);
else else
ctx.line_to (scr_x, double.min (y, chart.plot_y_max - (chart.plot_y_max - chart.plot_y_min) * place.zoom_y_max)); ctx.line_to (scr_x, double.min (y, chart.plarea.y + chart.plarea.height * (1.0 - place.zoom_y_max)));
break; break;
case Axis.Position.HIGH: case Axis.Position.HIGH:
var print_y = chart.evarea.y + max_rec_height + axis_x.font_indent + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_indent); var print_y = chart.evarea.y + max_rec_height + axis_x.font_indent + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_indent);
@ -308,9 +320,9 @@ namespace CairoChart {
double y = chart.evarea.y + max_rec_height + axis_x.font_indent + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_indent); double y = chart.evarea.y + max_rec_height + axis_x.font_indent + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_indent);
ctx.move_to (scr_x, y); ctx.move_to (scr_x, y);
if (joint_x) if (joint_x)
ctx.line_to (scr_x, chart.plot_y_max); ctx.line_to (scr_x, chart.plarea.y + chart.plarea.height);
else else
ctx.line_to (scr_x, double.max (y, chart.plot_y_max - (chart.plot_y_max - chart.plot_y_min) * place.zoom_y_min)); ctx.line_to (scr_x, double.max (y, chart.plarea.y + chart.plarea.height * (1.0 - place.zoom_y_min)));
break; break;
} }
} }
@ -326,7 +338,7 @@ namespace CairoChart {
s.axis_x.calc_rec_sizes (chart, out max_rec_width, out max_rec_height, true); s.axis_x.calc_rec_sizes (chart, out max_rec_width, out max_rec_height, true);
// 2. Calculate maximal available number of records, take into account the space width. // 2. Calculate maximal available number of records, take into account the space width.
long max_nrecs = (long) ((chart.plot_x_max - chart.plot_x_min) * (s.place.zoom_x_max - s.place.zoom_x_min) / max_rec_width); long max_nrecs = (long) (chart.plarea.width * (s.place.zoom_x_max - s.place.zoom_x_min) / max_rec_width);
// 3. Calculate grid step. // 3. Calculate grid step.
Float128 step = chart.math.calc_round_step ((s.axis_x.zoom_max - s.axis_x.zoom_min) / max_nrecs, s.axis_x.type == Axis.Type.DATE_TIME); Float128 step = chart.math.calc_round_step ((s.axis_x.zoom_max - s.axis_x.zoom_min) / max_nrecs, s.axis_x.type == Axis.Type.DATE_TIME);
@ -357,7 +369,7 @@ namespace CairoChart {
// 4.5. Draw Axis title // 4.5. Draw Axis title
if (s.axis_x.title.text != "") { if (s.axis_x.title.text != "") {
var scr_x = chart.plot_x_min + (chart.plot_x_max - chart.plot_x_min) * (s.place.zoom_x_min + s.place.zoom_x_max) / 2.0; var scr_x = chart.plarea.x + chart.plarea.width * (s.place.zoom_x_min + s.place.zoom_x_max) / 2.0;
double scr_y = 0.0; double scr_y = 0.0;
switch (s.axis_x.position) { switch (s.axis_x.position) {
case Axis.Position.LOW: scr_y = chart.evarea.y + chart.evarea.height - s.axis_x.font_indent; break; case Axis.Position.LOW: scr_y = chart.evarea.y + chart.evarea.height - s.axis_x.font_indent; break;
@ -417,9 +429,9 @@ namespace CairoChart {
double x = chart.evarea.x + max_rec_width + axis_y.font_indent + (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_indent); double x = chart.evarea.x + max_rec_width + axis_y.font_indent + (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_indent);
ctx.move_to (x, scr_y); ctx.move_to (x, scr_y);
if (joint_y) if (joint_y)
ctx.line_to (chart.plot_x_max, scr_y); ctx.line_to (chart.plarea.x + chart.plarea.width, scr_y);
else else
ctx.line_to (double.max (x, chart.plot_x_min + (chart.plot_x_max - chart.plot_x_min) * place.zoom_x_max), scr_y); ctx.line_to (double.max (x, chart.plarea.x + chart.plarea.width * place.zoom_x_max), scr_y);
break; break;
case Axis.Position.HIGH: case Axis.Position.HIGH:
ctx.move_to (chart.evarea.x + chart.evarea.width - text_sz.width - axis_y.font_indent ctx.move_to (chart.evarea.x + chart.evarea.width - text_sz.width - axis_y.font_indent
@ -433,9 +445,9 @@ namespace CairoChart {
double x = chart.evarea.x + chart.evarea.width - max_rec_width - axis_y.font_indent - (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_indent); double x = chart.evarea.x + chart.evarea.width - max_rec_width - axis_y.font_indent - (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_indent);
ctx.move_to (x, scr_y); ctx.move_to (x, scr_y);
if (joint_y) if (joint_y)
ctx.line_to (chart.plot_x_min, scr_y); ctx.line_to (chart.plarea.x, scr_y);
else else
ctx.line_to (double.min (x, chart.plot_x_min + (chart.plot_x_max - chart.plot_x_min) * place.zoom_x_min), scr_y); ctx.line_to (double.min (x, chart.plarea.x + chart.plarea.width * place.zoom_x_min), scr_y);
break; break;
} }
} }
@ -450,7 +462,7 @@ namespace CairoChart {
s.axis_y.calc_rec_sizes (chart, out max_rec_width, out max_rec_height, false); s.axis_y.calc_rec_sizes (chart, out max_rec_width, out max_rec_height, false);
// 2. Calculate maximal available number of records, take into account the space width. // 2. Calculate maximal available number of records, take into account the space width.
long max_nrecs = (long) ((chart.plot_y_max - chart.plot_y_min) * (s.place.zoom_y_max - s.place.zoom_y_min) / max_rec_height); long max_nrecs = (long) (chart.plarea.height * (s.place.zoom_y_max - s.place.zoom_y_min) / max_rec_height);
// 3. Calculate grid step. // 3. Calculate grid step.
Float128 step = chart.math.calc_round_step ((s.axis_y.zoom_max - s.axis_y.zoom_min) / max_nrecs); Float128 step = chart.math.calc_round_step ((s.axis_y.zoom_max - s.axis_y.zoom_min) / max_nrecs);
@ -481,7 +493,7 @@ namespace CairoChart {
// 4.5. Draw Axis title // 4.5. Draw Axis title
if (s.axis_y.title.text != "") { if (s.axis_y.title.text != "") {
var scr_y = chart.plot_y_max - (chart.plot_y_max - chart.plot_y_min) * (s.place.zoom_y_min + s.place.zoom_y_max) / 2.0; var scr_y = chart.plarea.y + chart.plarea.height * (1.0 - (s.place.zoom_y_min + s.place.zoom_y_max) / 2.0);
switch (s.axis_y.position) { switch (s.axis_y.position) {
case Axis.Position.LOW: case Axis.Position.LOW:
var scr_x = chart.evarea.x + s.axis_y.font_indent + sz.width; var scr_x = chart.evarea.x + s.axis_y.font_indent + sz.width;
@ -530,13 +542,11 @@ namespace CairoChart {
} }
public virtual double get_scr_x (Float128 x) { public virtual double get_scr_x (Float128 x) {
return chart.plot_x_min + (chart.plot_x_max - chart.plot_x_min) * (place.zoom_x_min + (x - axis_x.zoom_min) return chart.plarea.x + chart.plarea.width * (place.zoom_x_min + (x - axis_x.zoom_min) / (axis_x.zoom_max - axis_x.zoom_min) * (place.zoom_x_max - place.zoom_x_min));
/ (axis_x.zoom_max - axis_x.zoom_min) * (place.zoom_x_max - place.zoom_x_min));
} }
public virtual double get_scr_y (Float128 y) { public virtual double get_scr_y (Float128 y) {
return chart.plot_y_max - (chart.plot_y_max - chart.plot_y_min) * (place.zoom_y_min + (y - axis_y.zoom_min) return chart.plarea.y + chart.plarea.height * (1.0 - (place.zoom_y_min + (y - axis_y.zoom_min) / (axis_y.zoom_max - axis_y.zoom_min) * (place.zoom_y_max - place.zoom_y_min)));
/ (axis_y.zoom_max - axis_y.zoom_min) * (place.zoom_y_max - place.zoom_y_min));
} }
public virtual Point get_scr_point (Point128 p) { public virtual Point get_scr_point (Point128 p) {
@ -544,12 +554,12 @@ namespace CairoChart {
} }
public virtual Float128 get_real_x (double scr_x) { public virtual Float128 get_real_x (double scr_x) {
return axis_x.zoom_min + ((scr_x - chart.plot_x_min) / (chart.plot_x_max - chart.plot_x_min) - place.zoom_x_min) return axis_x.zoom_min + ((scr_x - chart.plarea.x) / chart.plarea.width - place.zoom_x_min)
* (axis_x.zoom_max - axis_x.zoom_min) / (place.zoom_x_max - place.zoom_x_min); * (axis_x.zoom_max - axis_x.zoom_min) / (place.zoom_x_max - place.zoom_x_min);
} }
public virtual Float128 get_real_y (double scr_y) { public virtual Float128 get_real_y (double scr_y) {
return axis_y.zoom_min + ((chart.plot_y_max - scr_y) / (chart.plot_y_max - chart.plot_y_min) - place.zoom_y_min) return axis_y.zoom_min + ((chart.plarea.y + chart.plarea.height - scr_y) / chart.plarea.height - place.zoom_y_min)
* (axis_y.zoom_max - axis_y.zoom_min) / (place.zoom_y_max - place.zoom_y_min); * (axis_y.zoom_max - axis_y.zoom_min) / (place.zoom_y_max - place.zoom_y_min);
} }

View File

@ -206,10 +206,10 @@ void plot_chart4 (Chart chart) {
} }
bool point_in_chart (Chart chart, double x, double y) { bool point_in_chart (Chart chart, double x, double y) {
if (x < chart.plot_x_min) return false; if (x < chart.plarea.x) return false;
if (x > chart.plot_x_max) return false; if (x > chart.plarea.x + chart.plarea.width) return false;
if (y < chart.plot_y_min) return false; if (y < chart.plarea.y) return false;
if (y > chart.plot_y_max) return false; if (y > chart.plarea.y + chart.plarea.height) return false;
return true; return true;
} }
@ -435,8 +435,8 @@ int main (string[] args) {
var text_t = new Text(text); var text_t = new Text(text);
var w = text_t.get_width(ctx); var w = text_t.get_width(ctx);
var h = text_t.get_height(ctx); var h = text_t.get_height(ctx);
var x0 = chart.plot_x_max - w - 5; var x0 = chart.plarea.x + chart.plarea.width - w - 5;
var y0 = chart.plot_y_min + h + 5; var y0 = chart.plarea.y + h + 5;
chart.color = chart.legend.bg_color; chart.color = chart.legend.bg_color;
ctx.rectangle (x0, y0 - h, w, h); ctx.rectangle (x0, y0 - h, w, h);
ctx.fill(); ctx.fill();