From 6f7bc6761d201fb8514a3a07a5ec1db9c3b52850 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Mon, 22 Jan 2018 18:47:24 +0300 Subject: [PATCH] OK In progress... --- src/Chart.vala | 2 +- src/Cursor.vala | 122 ++++++++++++++++++++++++------------------------ src/Series.vala | 6 +-- 3 files changed, 66 insertions(+), 64 deletions(-) diff --git a/src/Chart.vala b/src/Chart.vala index 6c6fe24..4efcc20 100644 --- a/src/Chart.vala +++ b/src/Chart.vala @@ -152,7 +152,7 @@ namespace CairoChart { rot_axes_titles (); - //cursors.get_crossings(); + cursors.eval_crossings(); eval_plarea (); diff --git a/src/Cursor.vala b/src/Cursor.vala index 5e19b1a..3e07325 100644 --- a/src/Cursor.vala +++ b/src/Cursor.vala @@ -9,6 +9,7 @@ namespace CairoChart { protected List list = new List (); protected Point active_cursor = Point(); // { get; protected set; default = Point128 (); } protected bool is_cursor_active = false; // { get; protected set; default = false; } + protected Cursors.CursorCrossings[] crossings = {}; /** * ``Cursors`` lines orientation. @@ -60,9 +61,9 @@ namespace CairoChart { public Cursors.Style cursor_style = Cursors.Style(); /** - * Crossings. + * Has crossings. */ - public Cursors.CursorCrossings[] crossings = {}; + public bool has_crossings { get { return crossings.length != 0; } protected set {} } /** * Constructs a new ``Chart``. @@ -129,14 +130,71 @@ namespace CairoChart { is_cursor_active = false; } + /** + * Evaluates crossings. + */ + public void eval_crossings () { + var all_cursors = get_all_cursors(); + + CursorCrossings[] local_cursor_crossings = {}; + + for (var ci = 0, max_ci = all_cursors.length(); ci < max_ci; ++ci) { + var c = all_cursors.nth_data(ci); + switch (cursor_style.orientation) { + case Orientation.VERTICAL: if (c.x <= chart.zoom.x0 || c.x >= chart.zoom.x1) continue; break; + case Orientation.HORIZONTAL: if (c.y <= chart.zoom.y0 || c.y >= chart.zoom.y1) continue; break; + } + + CursorCross[] crossings = {}; + for (var si = 0, max_si = chart.series.length; si < max_si; ++si) { + var s = chart.series[si]; + if (!s.zoom_show) continue; + + var points = Math.sort_points (s, s.sort); + + for (var i = 0; i + 1 < points.length; ++i) { + switch (cursor_style.orientation) { + case Orientation.VERTICAL: + Float128 y = 0; + if (Math.vcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]), rel2scr_x(c.x), + chart.plarea.y0, chart.plarea.y1, out y)) { + var point = Point128(s.get_real_x(rel2scr_x(c.x)), s.get_real_y(y)); + Point128 size; bool show_x, show_date, show_time, show_y; + cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y); + calc_cross_sizes (s, point, out size, show_x, show_time, show_date, show_y); + CursorCross cc = {si, point, size, show_x, show_date, show_time, show_y}; + crossings += cc; + } + break; + case Orientation.HORIZONTAL: + Float128 x = 0; + if (Math.hcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]), + chart.plarea.x0, chart.plarea.x1, rel2scr_y(c.y), out x)) { + var point = Point128(s.get_real_x(x), s.get_real_y(rel2scr_y(c.y))); + Point128 size; bool show_x, show_date, show_time, show_y; + cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y); + calc_cross_sizes (s, point, out size, show_x, show_time, show_date, show_y); + CursorCross cc = {si, point, size, show_x, show_date, show_time, show_y}; + crossings += cc; + } + break; + } + } + } + if (crossings.length != 0) { + CursorCrossings ccs = {ci, crossings}; + local_cursor_crossings += ccs; + } + } + crossings = local_cursor_crossings; + } + /** * Draws cursors. */ public virtual void draw () { if (chart.series.length == 0) return; - get_crossings(); - var all_cursors = get_all_cursors(); calc_cursors_value_positions(); @@ -421,62 +479,6 @@ namespace CairoChart { return all_cursors; } - protected void get_crossings () { - var all_cursors = get_all_cursors(); - - CursorCrossings[] local_cursor_crossings = {}; - - for (var ci = 0, max_ci = all_cursors.length(); ci < max_ci; ++ci) { - var c = all_cursors.nth_data(ci); - switch (cursor_style.orientation) { - case Orientation.VERTICAL: if (c.x <= chart.zoom.x0 || c.x >= chart.zoom.x1) continue; break; - case Orientation.HORIZONTAL: if (c.y <= chart.zoom.y0 || c.y >= chart.zoom.y1) continue; break; - } - - CursorCross[] crossings = {}; - for (var si = 0, max_si = chart.series.length; si < max_si; ++si) { - var s = chart.series[si]; - if (!s.zoom_show) continue; - - var points = Math.sort_points (s, s.sort); - - for (var i = 0; i + 1 < points.length; ++i) { - switch (cursor_style.orientation) { - case Orientation.VERTICAL: - Float128 y = 0; - if (Math.vcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]), rel2scr_x(c.x), - chart.plarea.y0, chart.plarea.y1, out y)) { - var point = Point128(s.get_real_x(rel2scr_x(c.x)), s.get_real_y(y)); - Point128 size; bool show_x, show_date, show_time, show_y; - cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y); - calc_cross_sizes (s, point, out size, show_x, show_time, show_date, show_y); - CursorCross cc = {si, point, size, show_x, show_date, show_time, show_y}; - crossings += cc; - } - break; - case Orientation.HORIZONTAL: - Float128 x = 0; - if (Math.hcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]), - chart.plarea.x0, chart.plarea.x1, rel2scr_y(c.y), out x)) { - var point = Point128(s.get_real_x(x), s.get_real_y(rel2scr_y(c.y))); - Point128 size; bool show_x, show_date, show_time, show_y; - cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y); - calc_cross_sizes (s, point, out size, show_x, show_time, show_date, show_y); - CursorCross cc = {si, point, size, show_x, show_date, show_time, show_y}; - crossings += cc; - } - break; - } - } - } - if (crossings.length != 0) { - CursorCrossings ccs = {ci, crossings}; - local_cursor_crossings += ccs; - } - } - crossings = local_cursor_crossings; - } - protected virtual void calc_cursors_value_positions () { for (var ccsi = 0, max_ccsi = crossings.length; ccsi < max_ccsi; ++ccsi) { for (var cci = 0, max_cci = crossings[ccsi].crossings.length; cci < max_cci; ++cci) { diff --git a/src/Series.vala b/src/Series.vala index a0940d1..b72ff89 100644 --- a/src/Series.vala +++ b/src/Series.vala @@ -165,7 +165,7 @@ namespace CairoChart { s.join_relative_y_axes (si, true, ref max_rec_width, ref max_rec_height, ref max_font_spacing, ref max_axis_font_width, ref nskip); // for 4.2. Cursor values for joint X axis - if (si == chart.zoom_1st_idx && chart.cursors.crossings.length != 0) { + if (si == chart.zoom_1st_idx && chart.cursors.has_crossings) { switch (chart.cursors.cursor_style.orientation) { case Cursors.Orientation.VERTICAL: if (is_x && chart.joint_x) { @@ -383,7 +383,7 @@ namespace CairoChart { if (x_min < s.axis_x.range.zmin) x_min += step; // 4.2. Cursor values for joint X axis - if (chart.joint_x && chart.cursors.cursor_style.orientation == Cursors.Orientation.VERTICAL && chart.cursors.crossings.length != 0) { + if (chart.joint_x && chart.cursors.cursor_style.orientation == Cursors.Orientation.VERTICAL && chart.cursors.has_crossings) { var tmp = max_rec_height + s.axis_x.font.vspacing; switch (s.axis_x.position) { case Axis.Position.LOW: chart.evarea.y1 -= tmp; break; @@ -499,7 +499,7 @@ namespace CairoChart { if (y_min < s.axis_y.range.zmin) y_min += step; // 4.2. Cursor values for joint Y axis - if (chart.joint_y && chart.cursors.cursor_style.orientation == Cursors.Orientation.HORIZONTAL && chart.cursors.crossings.length != 0) { + if (chart.joint_y && chart.cursors.cursor_style.orientation == Cursors.Orientation.HORIZONTAL && chart.cursors.has_crossings) { var tmp = max_rec_width + s.axis_y.font.hspacing; switch (s.axis_y.position) { case Axis.Position.LOW: chart.evarea.x0 += tmp; break;