diff --git a/src/Area.vala b/src/Area.vala index 000b61e..350fabd 100644 --- a/src/Area.vala +++ b/src/Area.vala @@ -9,10 +9,26 @@ namespace CairoChart { double _x1 = 1; double _y0 = 0; double _y1 = 1; - double _zx0 = 0; - double _zx1 = 1; - double _zy0 = 0; - double _zy1 = 1; + + /** + * Zoomed Left bound. + */ + public double zx0 = 0; + + /** + * Zoomed Top bound. + */ + public double zx1 = 1; + + /** + * Zoomed Right bound. + */ + public double zy0 = 0; + + /** + * Zoomed Bottom bound. + */ + public double zy1 = 1; /** * Left bound. @@ -22,7 +38,7 @@ namespace CairoChart { return _x0; } set { - _zx0 = _x0 = value; + zx0 = _x0 = value; } } @@ -34,7 +50,7 @@ namespace CairoChart { return _y0; } set { - _zy0 = _y0 = value; + zy0 = _y0 = value; } } @@ -46,7 +62,7 @@ namespace CairoChart { return _x1; } set { - _zx1 = _x1 = value; + zx1 = _x1 = value; } } @@ -58,59 +74,7 @@ namespace CairoChart { return _y1; } set { - _zy1 = _y1 = value; - } - } - - /** - * Zoomed Left bound. - */ - public double zx0 { - get { - return _zx0; - } - set { - if (_x0 <= value <= _x1) - _zx0 = value; - } - } - - /** - * Zoomed Top bound. - */ - public double zy0 { - get { - return _zy0; - } - set { - if (_y0 <= value <= _y1) - _zy0 = value; - } - } - - /** - * Zoomed Right bound. - */ - public double zx1 { - get { - return _zx1; - } - set { - if (_x0 <= value <= _x1) - _zx1 = value; - } - } - - /** - * Zoomed Bottom bound. - */ - public double zy1 { - get { - return _zy1; - } - set { - if (_y0 <= value <= _y1) - _zy1 = value; + zy1 = _y1 = value; } } @@ -122,7 +86,7 @@ namespace CairoChart { return _x1 - _x0; } set { - _zx1 = _x1 = _x0 + value; + zx1 = _x1 = _x0 + value; } } @@ -134,7 +98,7 @@ namespace CairoChart { return _y1 - _y0; } set { - _zy1 = _y1 = _y0 + value; + zy1 = _y1 = _y0 + value; } } @@ -143,11 +107,11 @@ namespace CairoChart { */ public double zwidth { get { - return _zx1 - _zx0; + return zx1 - zx0; } set { - if (_zx0 <= _zx0 + value <= _x1) - _zx1 = _zx0 + value; + if (zx0 <= zx0 + value <= _x1) + zx1 = zx0 + value; } } @@ -156,11 +120,11 @@ namespace CairoChart { */ public double zheight { get { - return _zy1 - _zy0; + return zy1 - zy0; } set { - if (_zy0 <= _zy0 + value <= _y1) - _zy1 = _zy0 + value; + if (zy0 <= zy0 + value <= _y1) + zy1 = zy0 + value; } } @@ -230,10 +194,10 @@ namespace CairoChart { * Unzooms ``Area``. */ public void unzoom () { - _zx0 = x0; - _zy0 = y0; - _zx1 = x1; - _zy1 = y1; + zx0 = x0; + zy0 = y0; + zx1 = x1; + zy1 = y1; } } } diff --git a/src/Chart.vala b/src/Chart.vala index 1dcca27..bcb8cde 100644 --- a/src/Chart.vala +++ b/src/Chart.vala @@ -203,27 +203,27 @@ namespace CairoChart { } if (real_x0 >= s.axis_x.zoom_min) { s.axis_x.zoom_min = real_x0; - s.place.zoom_x_min = 0.0; + s.place.zx0 = 0.0; } else { - s.place.zoom_x_min = (s.axis_x.zoom_min - real_x0) / real_width; + s.place.zx0 = (s.axis_x.zoom_min - real_x0) / real_width; } if (real_x1 <= s.axis_x.zoom_max) { s.axis_x.zoom_max = real_x1; - s.place.zoom_x_max = 1.0; + s.place.zx1 = 1.0; } else { - s.place.zoom_x_max = (s.axis_x.zoom_max - real_x0) / real_width; + s.place.zx1 = (s.axis_x.zoom_max - real_x0) / real_width; } if (real_y1 >= s.axis_y.zoom_min) { s.axis_y.zoom_min = real_y1; - s.place.zoom_y_min = 0.0; + s.place.zy0 = 0.0; } else { - s.place.zoom_y_min = (s.axis_y.zoom_min - real_y1) / real_height; + s.place.zy0 = (s.axis_y.zoom_min - real_y1) / real_height; } if (real_y0 <= s.axis_y.zoom_max) { s.axis_y.zoom_max = real_y0; - s.place.zoom_y_max = 1.0; + s.place.zy1 = 1.0; } else { - s.place.zoom_y_max = (s.axis_y.zoom_max - real_y1) / real_height; + s.place.zy1 = (s.axis_y.zoom_max - real_y1) / real_height; } } diff --git a/src/Series.vala b/src/Series.vala index 60e4234..7e8921f 100644 --- a/src/Series.vala +++ b/src/Series.vala @@ -15,7 +15,7 @@ namespace CairoChart { public Axis axis_x = new Axis(); public Axis axis_y = new Axis(); - public Place place = new Place(); + public Area place = new Area(); public Text title = new Text (); public Marker marker = new Marker (); @@ -94,8 +94,8 @@ namespace CairoChart { if ( axis_x.position != s.axis_x.position || axis_x.zoom_min != s.axis_x.zoom_min || axis_x.zoom_max != s.axis_x.zoom_max - || place.zoom_x_min != s.place.zoom_x_min - || place.zoom_x_max != s.place.zoom_x_max + || place.zx0 != s.place.zx0 + || place.zx1 != s.place.zx1 || axis_x.type != s.axis_x.type ) return false; @@ -106,8 +106,8 @@ namespace CairoChart { if ( axis_y.position != s.axis_y.position || axis_y.zoom_min != s.axis_y.zoom_min || axis_y.zoom_max != s.axis_y.zoom_max - || place.zoom_y_min != s.place.zoom_y_min - || place.zoom_y_max != s.place.zoom_y_max + || place.zy0 != s.place.zy0 + || place.zy1 != s.place.zy1 || axis_y.type != s.axis_y.type ) return false; @@ -184,7 +184,7 @@ namespace CairoChart { for (int sk = si; sk > sj; --sk) { var s3 = chart.series[sk]; if (!s3.zoom_show) continue; - if (Math.coord_cross(s2.place.zoom_x_min, s2.place.zoom_x_max, s3.place.zoom_x_min, s3.place.zoom_x_max) + if (Math.coord_cross(s2.place.zx0, s2.place.zx1, s3.place.zx0, s3.place.zx1) || s2.axis_x.position != s3.axis_x.position || s2.axis_x.type != s3.axis_x.type) { has_intersection = true; @@ -222,7 +222,7 @@ namespace CairoChart { for (int sk = si; sk > sj; --sk) { var s3 = chart.series[sk]; if (!s3.zoom_show) continue; - if (Math.coord_cross(s2.place.zoom_y_min, s2.place.zoom_y_max, s3.place.zoom_y_min, s3.place.zoom_y_max) + if (Math.coord_cross(s2.place.zy0, s2.place.zy1, s3.place.zy0, s3.place.zy1) || s2.axis_y.position != s3.axis_y.position || s2.axis_y.type != s3.axis_y.type) { has_intersection = true; @@ -278,7 +278,7 @@ namespace CairoChart { if (axis_x.time_format != "") time_text_t.show(ctx); break; } - // 6. Draw grid lines to the place.zoom_y_min. + // 6. Draw grid lines to the place.zy0. var line_style = grid.line_style; if (joint_x) line_style.color = Color(0, 0, 0, 0.5); line_style.apply(chart); @@ -287,7 +287,7 @@ namespace CairoChart { if (joint_x) ctx.line_to (scr_x, chart.plarea.y0); else - ctx.line_to (scr_x, double.min (y, chart.plarea.y0 + chart.plarea.height * (1.0 - place.zoom_y_max))); + ctx.line_to (scr_x, double.min (y, chart.plarea.y0 + chart.plarea.height * (1.0 - place.zy1))); break; case Axis.Position.HIGH: var print_y = chart.evarea.y0 + max_rec_height + axis_x.font_spacing + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_spacing); @@ -306,7 +306,7 @@ namespace CairoChart { if (axis_x.time_format != "") time_text_t.show(ctx); break; } - // 6. Draw grid lines to the place.zoom_y_max. + // 6. Draw grid lines to the place.zy1. var line_style = grid.line_style; if (joint_x) line_style.color = Color(0, 0, 0, 0.5); line_style.apply(chart); @@ -315,7 +315,7 @@ namespace CairoChart { if (joint_x) ctx.line_to (scr_x, chart.plarea.y1); else - ctx.line_to (scr_x, double.max (y, chart.plarea.y0 + chart.plarea.height * (1.0 - place.zoom_y_min))); + ctx.line_to (scr_x, double.max (y, chart.plarea.y0 + chart.plarea.height * (1.0 - place.zy0))); break; } } @@ -331,7 +331,7 @@ namespace CairoChart { 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. - long max_nrecs = (long) (chart.plarea.width * (s.place.zoom_x_max - s.place.zoom_x_min) / max_rec_width); + long max_nrecs = (long) (chart.plarea.width * (s.place.zx1 - s.place.zx0) / max_rec_width); // 3. Calculate grid step. Float128 step = Math.calc_round_step ((s.axis_x.zoom_max - s.axis_x.zoom_min) / max_nrecs, s.axis_x.type == Axis.Type.DATE_TIME); @@ -363,7 +363,7 @@ namespace CairoChart { // 4.5. Draw Axis title if (s.axis_x.title.text != "") { - var scr_x = chart.plarea.x0 + chart.plarea.width * (s.place.zoom_x_min + s.place.zoom_x_max) / 2.0; + var scr_x = chart.plarea.x0 + chart.plarea.width * (s.place.zx0 + s.place.zx1) / 2.0; double scr_y = 0.0; switch (s.axis_x.position) { case Axis.Position.LOW: scr_y = chart.evarea.y1 - s.axis_x.font_spacing; break; @@ -411,7 +411,7 @@ namespace CairoChart { + (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_spacing), compact_rec_y_pos (y, text_t)); text_t.show(ctx); - // 6. Draw grid lines to the place.zoom_x_min. + // 6. Draw grid lines to the place.zx0. var line_style = grid.line_style; if (joint_y) line_style.color = Color(0, 0, 0, 0.5); line_style.apply(chart); @@ -420,14 +420,14 @@ namespace CairoChart { if (joint_y) ctx.line_to (chart.plarea.x1, scr_y); else - ctx.line_to (double.max (x, chart.plarea.x0 + chart.plarea.width * place.zoom_x_max), scr_y); + ctx.line_to (double.max (x, chart.plarea.x0 + chart.plarea.width * place.zx1), scr_y); break; case Axis.Position.HIGH: ctx.move_to (chart.evarea.x1 - text_sz.width - axis_y.font_spacing - (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_spacing), compact_rec_y_pos (y, text_t)); text_t.show(ctx); - // 6. Draw grid lines to the place.zoom_x_max. + // 6. Draw grid lines to the place.zx1. var line_style = grid.line_style; if (joint_y) line_style.color = Color(0, 0, 0, 0.5); line_style.apply(chart); @@ -436,7 +436,7 @@ namespace CairoChart { if (joint_y) ctx.line_to (chart.plarea.x0, scr_y); else - ctx.line_to (double.min (x, chart.plarea.x0 + chart.plarea.width * place.zoom_x_min), scr_y); + ctx.line_to (double.min (x, chart.plarea.x0 + chart.plarea.width * place.zx0), scr_y); break; } } @@ -451,7 +451,7 @@ namespace CairoChart { 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. - long max_nrecs = (long) (chart.plarea.height * (s.place.zoom_y_max - s.place.zoom_y_min) / max_rec_height); + long max_nrecs = (long) (chart.plarea.height * (s.place.zy1 - s.place.zy0) / max_rec_height); // 3. Calculate grid step. Float128 step = Math.calc_round_step ((s.axis_y.zoom_max - s.axis_y.zoom_min) / max_nrecs); @@ -483,7 +483,7 @@ namespace CairoChart { // 4.5. Draw Axis title if (s.axis_y.title.text != "") { - var scr_y = chart.plarea.y0 + chart.plarea.height * (1.0 - (s.place.zoom_y_min + s.place.zoom_y_max) / 2.0); + var scr_y = chart.plarea.y0 + chart.plarea.height * (1.0 - (s.place.zy0 + s.place.zy1) / 2.0); switch (s.axis_y.position) { case Axis.Position.LOW: var scr_x = chart.evarea.x0 + s.axis_y.font_spacing + sz.width; @@ -528,11 +528,11 @@ namespace CairoChart { } public virtual double get_scr_x (Float128 x) { - return chart.plarea.x0 + 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)); + return chart.plarea.x0 + chart.plarea.width * (place.zx0 + (x - axis_x.zoom_min) / (axis_x.zoom_max - axis_x.zoom_min) * (place.zx1 - place.zx0)); } public virtual double get_scr_y (Float128 y) { - return chart.plarea.y0 + 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))); + return chart.plarea.y0 + chart.plarea.height * (1.0 - (place.zy0 + (y - axis_y.zoom_min) / (axis_y.zoom_max - axis_y.zoom_min) * (place.zy1 - place.zy0))); } public virtual Point get_scr_point (Point128 p) { @@ -540,13 +540,13 @@ namespace CairoChart { } public virtual Float128 get_real_x (double scr_x) { - return axis_x.zoom_min + ((scr_x - chart.plarea.x0) / chart.plarea.width - place.zoom_x_min) - * (axis_x.zoom_max - axis_x.zoom_min) / (place.zoom_x_max - place.zoom_x_min); + return axis_x.zoom_min + ((scr_x - chart.plarea.x0) / chart.plarea.width - place.zx0) + * (axis_x.zoom_max - axis_x.zoom_min) / (place.zx1 - place.zx0); } public virtual Float128 get_real_y (double scr_y) { - return axis_y.zoom_min + ((chart.plarea.y1 - 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); + return axis_y.zoom_min + ((chart.plarea.y1 - scr_y) / chart.plarea.height - place.zy0) + * (axis_y.zoom_max - axis_y.zoom_min) / (place.zy1 - place.zy0); } public virtual Point128 get_real_point (Point p) { diff --git a/test/ChartTest.vala b/test/ChartTest.vala index 69a0d40..9c4eef8 100644 --- a/test/ChartTest.vala +++ b/test/ChartTest.vala @@ -17,18 +17,18 @@ void plot_chart1 (Chart chart) { s1.axis_x.min = 0; s1.axis_x.max = 2; s1.axis_y.min = 0; s1.axis_y.max = 3; - s1.place.x_min = 0.25; s1.place.x_max = 0.75; - s1.place.y_min = 0.3; s1.place.y_max = 0.9; + s1.place.x0 = 0.25; s1.place.x1 = 0.75; + s1.place.y0 = 0.3; s1.place.y1 = 0.9; s2.axis_x.min = -15; s2.axis_x.max = 30; s2.axis_y.min = -20; s2.axis_y.max = 200; - s2.place.x_min = 0.5; s2.place.x_max = 1; - s2.place.y_min = 0.0; s2.place.y_max = 0.5; + s2.place.x0 = 0.5; s2.place.x1 = 1; + s2.place.y0 = 0.0; s2.place.y1 = 0.5; s3.axis_x.min = 0; s3.axis_x.max = 130; s3.axis_y.min = 15; s3.axis_y.max = 35; - s3.place.x_min = 0; s3.place.x_max = 0.5; - s3.place.y_min = 0.5; s3.place.y_max = 1.0; + s3.place.x0 = 0; s3.place.x1 = 0.5; + s3.place.y0 = 0.5; s3.place.y1 = 1.0; s1.marker.type = Marker.Type.SQUARE; s2.marker.type = Marker.Type.CIRCLE; @@ -61,18 +61,18 @@ void plot_chart2 (Chart chart) { s1.axis_x.min = -15; s1.axis_x.max = 30; s1.axis_y.min = 0; s1.axis_y.max = 3; - s1.place.x_min = 0.0; s1.place.x_max = 1.0; - s1.place.y_min = 0.3; s1.place.y_max = 0.9; + s1.place.x0 = 0.0; s1.place.x1 = 1.0; + s1.place.y0 = 0.3; s1.place.y1 = 0.9; s2.axis_x.min = -15; s2.axis_x.max = 30; s2.axis_y.min = -20; s2.axis_y.max = 200; - s2.place.x_min = 0.0; s2.place.x_max = 1.0; - s2.place.y_min = 0.0; s2.place.y_max = 0.5; + s2.place.x0 = 0.0; s2.place.x1 = 1.0; + s2.place.y0 = 0.0; s2.place.y1 = 0.5; s3.axis_x.min = -15; s3.axis_x.max = 30; s3.axis_y.min = 15; s3.axis_y.max = 35; - s3.place.x_min = 0.0; s3.place.x_max = 1.0; - s3.place.y_min = 0.5; s3.place.y_max = 1.0; + s3.place.x0 = 0.0; s3.place.x1 = 1.0; + s3.place.y0 = 0.5; s3.place.y1 = 1.0; s1.marker.type = Marker.Type.PRICLE_CIRCLE; s2.marker.type = Marker.Type.PRICLE_SQUARE; @@ -111,18 +111,18 @@ void plot_chart3 (Chart chart) { s1.axis_x.min = 0; s1.axis_x.max = 2; s1.axis_y.min = -20; s1.axis_y.max = 200; - s1.place.x_min = 0.25; s1.place.x_max = 0.75; - s1.place.y_min = 0.0; s1.place.y_max = 1.0; + s1.place.x0 = 0.25; s1.place.x1 = 0.75; + s1.place.y0 = 0.0; s1.place.y1 = 1.0; s2.axis_x.min = -15; s2.axis_x.max = 30; s2.axis_y.min = -20; s2.axis_y.max = 200; - s2.place.x_min = 0.5; s2.place.x_max = 1; - s2.place.y_min = 0.0; s2.place.y_max = 1.0; + s2.place.x0 = 0.5; s2.place.x1 = 1; + s2.place.y0 = 0.0; s2.place.y1 = 1.0; s3.axis_x.min = 0; s3.axis_x.max = 130; s3.axis_y.min = -20; s3.axis_y.max = 200; - s3.place.x_min = 0; s3.place.x_max = 0.5; - s3.place.y_min = 0.0; s3.place.y_max = 1.0; + s3.place.x0 = 0; s3.place.x1 = 0.5; + s3.place.y0 = 0.0; s3.place.y1 = 1.0; s1.marker.type = Marker.Type.SQUARE; s2.marker.type = Marker.Type.PRICLE_CIRCLE; @@ -170,23 +170,23 @@ void plot_chart4 (Chart chart) { s1.axis_x.min = now - 100000; s1.axis_x.max = now + 100000; s1.axis_y.min = -20; s1.axis_y.max = 200; - s1.place.x_min = 0.25; s1.place.x_max = 0.75; - s1.place.y_min = 0.0; s1.place.y_max = 1.0; + s1.place.x0 = 0.25; s1.place.x1 = 0.75; + s1.place.y0 = 0.0; s1.place.y1 = 1.0; s2.axis_x.min = -15; s2.axis_x.max = 30; s2.axis_y.min = -20; s2.axis_y.max = 200; - s2.place.x_min = 0.2; s2.place.x_max = 1; - s2.place.y_min = 0.0; s2.place.y_max = 1.0; + s2.place.x0 = 0.2; s2.place.x1 = 1; + s2.place.y0 = 0.0; s2.place.y1 = 1.0; s3.axis_x.min = high - 2; s3.axis_x.max = high + 1; s3.axis_y.min = -20; s3.axis_y.max = 200; - s3.place.x_min = 0; s3.place.x_max = 0.8; - s3.place.y_min = 0.0; s3.place.y_max = 1.0; + s3.place.x0 = 0; s3.place.x1 = 0.8; + s3.place.y0 = 0.0; s3.place.y1 = 1.0; s4.axis_x.min = high + 0.0049; s4.axis_x.max = high + 0.0054; s4.axis_y.min = -20; s4.axis_y.max = 200; - s4.place.x_min = 0.2; s4.place.x_max = 1.0; - s4.place.y_min = 0.0; s4.place.y_max = 1.0; + s4.place.x0 = 0.2; s4.place.x1 = 1.0; + s4.place.y0 = 0.0; s4.place.y1 = 1.0; s1.marker.type = Marker.Type.SQUARE; s2.marker.type = Marker.Type.PRICLE_CIRCLE;