OK In progress...

This commit is contained in:
Kolan Sh 2018-01-22 18:47:24 +03:00
parent 5c556195e3
commit 6f7bc6761d
3 changed files with 66 additions and 64 deletions

View File

@ -152,7 +152,7 @@ namespace CairoChart {
rot_axes_titles (); rot_axes_titles ();
//cursors.get_crossings(); cursors.eval_crossings();
eval_plarea (); eval_plarea ();

View File

@ -9,6 +9,7 @@ namespace CairoChart {
protected List<Point?> list = new List<Point?> (); protected List<Point?> list = new List<Point?> ();
protected Point active_cursor = Point(); // { get; protected set; default = Point128 (); } protected Point active_cursor = Point(); // { get; protected set; default = Point128 (); }
protected bool is_cursor_active = false; // { get; protected set; default = false; } protected bool is_cursor_active = false; // { get; protected set; default = false; }
protected Cursors.CursorCrossings[] crossings = {};
/** /**
* ``Cursors`` lines orientation. * ``Cursors`` lines orientation.
@ -60,9 +61,9 @@ namespace CairoChart {
public Cursors.Style cursor_style = Cursors.Style(); 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``. * Constructs a new ``Chart``.
@ -129,14 +130,71 @@ namespace CairoChart {
is_cursor_active = false; 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. * Draws cursors.
*/ */
public virtual void draw () { public virtual void draw () {
if (chart.series.length == 0) return; if (chart.series.length == 0) return;
get_crossings();
var all_cursors = get_all_cursors(); var all_cursors = get_all_cursors();
calc_cursors_value_positions(); calc_cursors_value_positions();
@ -421,62 +479,6 @@ namespace CairoChart {
return all_cursors; 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 () { protected virtual void calc_cursors_value_positions () {
for (var ccsi = 0, max_ccsi = crossings.length; ccsi < max_ccsi; ++ccsi) { 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) { for (var cci = 0, max_cci = crossings[ccsi].crossings.length; cci < max_cci; ++cci) {

View File

@ -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); 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 // 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) { switch (chart.cursors.cursor_style.orientation) {
case Cursors.Orientation.VERTICAL: case Cursors.Orientation.VERTICAL:
if (is_x && chart.joint_x) { if (is_x && chart.joint_x) {
@ -383,7 +383,7 @@ namespace CairoChart {
if (x_min < s.axis_x.range.zmin) x_min += step; if (x_min < s.axis_x.range.zmin) x_min += step;
// 4.2. Cursor values for joint X axis // 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; var tmp = max_rec_height + s.axis_x.font.vspacing;
switch (s.axis_x.position) { switch (s.axis_x.position) {
case Axis.Position.LOW: chart.evarea.y1 -= tmp; break; 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; if (y_min < s.axis_y.range.zmin) y_min += step;
// 4.2. Cursor values for joint Y axis // 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; var tmp = max_rec_width + s.axis_y.font.hspacing;
switch (s.axis_y.position) { switch (s.axis_y.position) {
case Axis.Position.LOW: chart.evarea.x0 += tmp; break; case Axis.Position.LOW: chart.evarea.x0 += tmp; break;