In progress...
This commit is contained in:
parent
117796a64c
commit
374b07e049
|
@ -47,7 +47,7 @@ namespace CairoChart {
|
||||||
public Color joint_axis_color = Color (0, 0, 0, 1);
|
public Color joint_axis_color = Color (0, 0, 0, 1);
|
||||||
|
|
||||||
public CairoChart.Math math { get; protected set; default = new Math(); }
|
public CairoChart.Math math { get; protected set; default = new Math(); }
|
||||||
public Cursors cursors2 { get; protected set; default = new Cursors (); }
|
public Cursors cursors { get; protected set; default = new Cursors (); }
|
||||||
|
|
||||||
public Chart () {
|
public Chart () {
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ namespace CairoChart {
|
||||||
chart.cur_x_min = this.cur_x_min;
|
chart.cur_x_min = this.cur_x_min;
|
||||||
chart.cur_y_max = this.cur_y_max;
|
chart.cur_y_max = this.cur_y_max;
|
||||||
chart.cur_y_min = this.cur_y_min;
|
chart.cur_y_min = this.cur_y_min;
|
||||||
chart.cursors2 = this.cursors2.copy();
|
chart.cursors = this.cursors.copy();
|
||||||
chart.height = this.height;
|
chart.height = this.height;
|
||||||
chart.legend = this.legend.copy();
|
chart.legend = this.legend.copy();
|
||||||
chart.plot_x_max = this.plot_x_max;
|
chart.plot_x_max = this.plot_x_max;
|
||||||
|
@ -113,7 +113,7 @@ namespace CairoChart {
|
||||||
|
|
||||||
set_vertical_axes_titles ();
|
set_vertical_axes_titles ();
|
||||||
|
|
||||||
cursors2.get_cursors_crossings(this);
|
cursors.get_cursors_crossings(this);
|
||||||
|
|
||||||
calc_plot_area ();
|
calc_plot_area ();
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ namespace CairoChart {
|
||||||
draw_series ();
|
draw_series ();
|
||||||
check_cur_values ();
|
check_cur_values ();
|
||||||
|
|
||||||
cursors2.draw_cursors (this);
|
cursors.draw_cursors (this);
|
||||||
check_cur_values ();
|
check_cur_values ();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -290,8 +290,8 @@ namespace CairoChart {
|
||||||
s.join_relative_y_axes (si, true, ref max_rec_width, ref max_rec_height, ref max_font_indent, 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_indent, 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 == zoom_first_show && cursors2.cursors_crossings.length != 0) {
|
if (si == zoom_first_show && cursors.cursors_crossings.length != 0) {
|
||||||
switch (cursors2.cursor_style.orientation) {
|
switch (cursors.cursor_style.orientation) {
|
||||||
case Cursors.Orientation.VERTICAL:
|
case Cursors.Orientation.VERTICAL:
|
||||||
if (is_x && joint_x)
|
if (is_x && joint_x)
|
||||||
switch (axis.position) {
|
switch (axis.position) {
|
||||||
|
@ -391,28 +391,28 @@ namespace CairoChart {
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void set_active_cursor (Point p, bool remove = false) {
|
public virtual void set_active_cursor (Point p, bool remove = false) {
|
||||||
cursors2.active_cursor = scr2rel_point(p);
|
cursors.active_cursor = scr2rel_point(p);
|
||||||
cursors2.is_cursor_active = ! remove;
|
cursors.is_cursor_active = ! remove;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void add_active_cursor () {
|
public virtual void add_active_cursor () {
|
||||||
cursors2.cursors.append (cursors2.active_cursor);
|
cursors.list.append (cursors.active_cursor);
|
||||||
cursors2.is_cursor_active = false;
|
cursors.is_cursor_active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void remove_active_cursor () {
|
public virtual void remove_active_cursor () {
|
||||||
if (cursors2.cursors.length() == 0) return;
|
if (cursors.list.length() == 0) return;
|
||||||
var distance = width * width;
|
var distance = width * width;
|
||||||
uint rm_indx = 0;
|
uint rm_indx = 0;
|
||||||
uint i = 0;
|
uint i = 0;
|
||||||
foreach (var c in cursors2.cursors) {
|
foreach (var c in cursors.list) {
|
||||||
double d = distance;
|
double d = distance;
|
||||||
switch (cursors2.cursor_style.orientation) {
|
switch (cursors.cursor_style.orientation) {
|
||||||
case Cursors.Orientation.VERTICAL:
|
case Cursors.Orientation.VERTICAL:
|
||||||
d = (rel2scr_x(c.x) - rel2scr_x(cursors2.active_cursor.x)).abs();
|
d = (rel2scr_x(c.x) - rel2scr_x(cursors.active_cursor.x)).abs();
|
||||||
break;
|
break;
|
||||||
case Cursors.Orientation.HORIZONTAL:
|
case Cursors.Orientation.HORIZONTAL:
|
||||||
d = (rel2scr_y(c.y) - rel2scr_y(cursors2.active_cursor.y)).abs();
|
d = (rel2scr_y(c.y) - rel2scr_y(cursors.active_cursor.y)).abs();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (d < distance) {
|
if (d < distance) {
|
||||||
|
@ -421,9 +421,9 @@ namespace CairoChart {
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (distance < cursors2.cursor_style.select_distance)
|
if (distance < cursors.cursor_style.select_distance)
|
||||||
cursors2.cursors.delete_link(cursors2.cursors.nth(rm_indx));
|
cursors.list.delete_link(cursors.list.nth(rm_indx));
|
||||||
cursors2.is_cursor_active = false;
|
cursors.is_cursor_active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Float128 scr2rel_x (Float128 x) {
|
protected virtual Float128 scr2rel_x (Float128 x) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ namespace CairoChart {
|
||||||
|
|
||||||
public class Cursors {
|
public class Cursors {
|
||||||
|
|
||||||
public List<Point?> cursors = new List<Point?> ();
|
public List<Point?> list = new List<Point?> ();
|
||||||
public Point active_cursor = Point(); // { get; protected set; default = Point128 (); }
|
public Point active_cursor = Point(); // { get; protected set; default = Point128 (); }
|
||||||
public bool is_cursor_active = false; // { get; protected set; default = false; }
|
public bool is_cursor_active = false; // { get; protected set; default = false; }
|
||||||
public Cursors.Style cursor_style = Cursors.Style();
|
public Cursors.Style cursor_style = Cursors.Style();
|
||||||
|
@ -13,7 +13,7 @@ namespace CairoChart {
|
||||||
|
|
||||||
public Cursors copy () {
|
public Cursors copy () {
|
||||||
var c = new Cursors ();
|
var c = new Cursors ();
|
||||||
c.cursors = cursors.copy();
|
c.list = list.copy();
|
||||||
c.active_cursor = active_cursor;
|
c.active_cursor = active_cursor;
|
||||||
c.is_cursor_active = is_cursor_active;
|
c.is_cursor_active = is_cursor_active;
|
||||||
c.cursor_style = cursor_style;
|
c.cursor_style = cursor_style;
|
||||||
|
@ -56,7 +56,7 @@ namespace CairoChart {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Point?> get_all_cursors (Chart chart) {
|
protected List<Point?> get_all_cursors (Chart chart) {
|
||||||
var all_cursors = cursors.copy_deep ((src) => { return src; });
|
var all_cursors = list.copy_deep ((src) => { return src; });
|
||||||
if (is_cursor_active)
|
if (is_cursor_active)
|
||||||
all_cursors.append(active_cursor);
|
all_cursors.append(active_cursor);
|
||||||
return all_cursors;
|
return all_cursors;
|
||||||
|
@ -392,14 +392,14 @@ namespace CairoChart {
|
||||||
public bool get_cursors_delta (Chart chart, out Float128 delta) {
|
public bool get_cursors_delta (Chart chart, out Float128 delta) {
|
||||||
delta = 0.0;
|
delta = 0.0;
|
||||||
if (chart.series.length == 0) return false;
|
if (chart.series.length == 0) return false;
|
||||||
if (cursors.length() + (is_cursor_active ? 1 : 0) != 2) return false;
|
if (list.length() + (is_cursor_active ? 1 : 0) != 2) return false;
|
||||||
if (chart.joint_x && cursor_style.orientation == Orientation.VERTICAL) {
|
if (chart.joint_x && cursor_style.orientation == Orientation.VERTICAL) {
|
||||||
Float128 val1 = chart.series[chart.zoom_first_show].get_real_x(chart.rel2scr_x(cursors.nth_data(0).x));
|
Float128 val1 = chart.series[chart.zoom_first_show].get_real_x(chart.rel2scr_x(list.nth_data(0).x));
|
||||||
Float128 val2 = 0;
|
Float128 val2 = 0;
|
||||||
if (is_cursor_active)
|
if (is_cursor_active)
|
||||||
val2 = chart.series[chart.zoom_first_show].get_real_x(chart.rel2scr_x(active_cursor.x));
|
val2 = chart.series[chart.zoom_first_show].get_real_x(chart.rel2scr_x(active_cursor.x));
|
||||||
else
|
else
|
||||||
val2 = chart.series[chart.zoom_first_show].get_real_x(chart.rel2scr_x(cursors.nth_data(1).x));
|
val2 = chart.series[chart.zoom_first_show].get_real_x(chart.rel2scr_x(list.nth_data(1).x));
|
||||||
if (val2 > val1)
|
if (val2 > val1)
|
||||||
delta = val2 - val1;
|
delta = val2 - val1;
|
||||||
else
|
else
|
||||||
|
@ -407,12 +407,12 @@ namespace CairoChart {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (chart.joint_y && cursor_style.orientation == Orientation.HORIZONTAL) {
|
if (chart.joint_y && cursor_style.orientation == Orientation.HORIZONTAL) {
|
||||||
Float128 val1 = chart.series[chart.zoom_first_show].get_real_y(chart.rel2scr_y(cursors.nth_data(0).y));
|
Float128 val1 = chart.series[chart.zoom_first_show].get_real_y(chart.rel2scr_y(list.nth_data(0).y));
|
||||||
Float128 val2 = 0;
|
Float128 val2 = 0;
|
||||||
if (is_cursor_active)
|
if (is_cursor_active)
|
||||||
val2 = chart.series[chart.zoom_first_show].get_real_y(chart.rel2scr_y(active_cursor.y));
|
val2 = chart.series[chart.zoom_first_show].get_real_y(chart.rel2scr_y(active_cursor.y));
|
||||||
else
|
else
|
||||||
val2 = chart.series[chart.zoom_first_show].get_real_y(chart.rel2scr_y(cursors.nth_data(1).y));
|
val2 = chart.series[chart.zoom_first_show].get_real_y(chart.rel2scr_y(list.nth_data(1).y));
|
||||||
if (val2 > val1)
|
if (val2 > val1)
|
||||||
delta = val2 - val1;
|
delta = val2 - val1;
|
||||||
else
|
else
|
||||||
|
|
|
@ -298,7 +298,7 @@ namespace CairoChart {
|
||||||
if (x_min < s.axis_x.zoom_min) x_min += step;
|
if (x_min < s.axis_x.zoom_min) x_min += step;
|
||||||
|
|
||||||
// 4.2. Cursor values for joint X axis
|
// 4.2. Cursor values for joint X axis
|
||||||
if (chart.joint_x && chart.cursors2.cursor_style.orientation == Cursors.Orientation.VERTICAL && chart.cursors2.cursors_crossings.length != 0) {
|
if (chart.joint_x && chart.cursors.cursor_style.orientation == Cursors.Orientation.VERTICAL && chart.cursors.cursors_crossings.length != 0) {
|
||||||
switch (s.axis_x.position) {
|
switch (s.axis_x.position) {
|
||||||
case Axis.Position.LOW: chart.cur_y_max -= max_rec_height + s.axis_x.font_indent; break;
|
case Axis.Position.LOW: chart.cur_y_max -= max_rec_height + s.axis_x.font_indent; break;
|
||||||
case Axis.Position.HIGH: chart.cur_y_min += max_rec_height + s.axis_x.font_indent; break;
|
case Axis.Position.HIGH: chart.cur_y_min += max_rec_height + s.axis_x.font_indent; break;
|
||||||
|
@ -422,7 +422,7 @@ namespace CairoChart {
|
||||||
if (y_min < s.axis_y.zoom_min) y_min += step;
|
if (y_min < s.axis_y.zoom_min) y_min += step;
|
||||||
|
|
||||||
// 4.2. Cursor values for joint Y axis
|
// 4.2. Cursor values for joint Y axis
|
||||||
if (chart.joint_y && chart.cursors2.cursor_style.orientation == Cursors.Orientation.HORIZONTAL && chart.cursors2.cursors_crossings.length != 0) {
|
if (chart.joint_y && chart.cursors.cursor_style.orientation == Cursors.Orientation.HORIZONTAL && chart.cursors.cursors_crossings.length != 0) {
|
||||||
switch (s.axis_y.position) {
|
switch (s.axis_y.position) {
|
||||||
case Axis.Position.LOW: chart.cur_x_min += max_rec_width + s.axis_y.font_indent; break;
|
case Axis.Position.LOW: chart.cur_x_min += max_rec_width + s.axis_y.font_indent; break;
|
||||||
case Axis.Position.HIGH: chart.cur_x_max -= max_rec_width + s.axis_y.font_indent; break;
|
case Axis.Position.HIGH: chart.cur_x_max -= max_rec_width + s.axis_y.font_indent; break;
|
||||||
|
|
|
@ -274,7 +274,7 @@ int main (string[] args) {
|
||||||
case Legend.Position.LEFT: radio_button3.set_active(true); break;
|
case Legend.Position.LEFT: radio_button3.set_active(true); break;
|
||||||
case Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
case Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
||||||
}
|
}
|
||||||
switch (chart.cursors2.cursor_style.orientation) {
|
switch (chart.cursors.cursor_style.orientation) {
|
||||||
case Cursors.Orientation.VERTICAL: radio_button7.set_active(true); break;
|
case Cursors.Orientation.VERTICAL: radio_button7.set_active(true); break;
|
||||||
case Cursors.Orientation.HORIZONTAL: radio_button8.set_active(true); break;
|
case Cursors.Orientation.HORIZONTAL: radio_button8.set_active(true); break;
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ int main (string[] args) {
|
||||||
case Legend.Position.LEFT: radio_button3.set_active(true); break;
|
case Legend.Position.LEFT: radio_button3.set_active(true); break;
|
||||||
case Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
case Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
||||||
}
|
}
|
||||||
switch (chart.cursors2.cursor_style.orientation) {
|
switch (chart.cursors.cursor_style.orientation) {
|
||||||
case Cursors.Orientation.VERTICAL: radio_button7.set_active(true); break;
|
case Cursors.Orientation.VERTICAL: radio_button7.set_active(true); break;
|
||||||
case Cursors.Orientation.HORIZONTAL: radio_button8.set_active(true); break;
|
case Cursors.Orientation.HORIZONTAL: radio_button8.set_active(true); break;
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ int main (string[] args) {
|
||||||
case Legend.Position.LEFT: radio_button3.set_active(true); break;
|
case Legend.Position.LEFT: radio_button3.set_active(true); break;
|
||||||
case Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
case Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
||||||
}
|
}
|
||||||
switch (chart.cursors2.cursor_style.orientation) {
|
switch (chart.cursors.cursor_style.orientation) {
|
||||||
case Cursors.Orientation.VERTICAL: radio_button7.set_active(true); break;
|
case Cursors.Orientation.VERTICAL: radio_button7.set_active(true); break;
|
||||||
case Cursors.Orientation.HORIZONTAL: radio_button8.set_active(true); break;
|
case Cursors.Orientation.HORIZONTAL: radio_button8.set_active(true); break;
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ int main (string[] args) {
|
||||||
case Legend.Position.LEFT: radio_button4.set_active(true); break;
|
case Legend.Position.LEFT: radio_button4.set_active(true); break;
|
||||||
case Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
case Legend.Position.BOTTOM: radio_button4.set_active(true); break;
|
||||||
}
|
}
|
||||||
switch (chart.cursors2.cursor_style.orientation) {
|
switch (chart.cursors.cursor_style.orientation) {
|
||||||
case Cursors.Orientation.VERTICAL: radio_button7.set_active(true); break;
|
case Cursors.Orientation.VERTICAL: radio_button7.set_active(true); break;
|
||||||
case Cursors.Orientation.HORIZONTAL: radio_button8.set_active(true); break;
|
case Cursors.Orientation.HORIZONTAL: radio_button8.set_active(true); break;
|
||||||
}
|
}
|
||||||
|
@ -397,13 +397,13 @@ int main (string[] args) {
|
||||||
|
|
||||||
radio_button7.toggled.connect ((button) => {
|
radio_button7.toggled.connect ((button) => {
|
||||||
if (button.get_active()) {
|
if (button.get_active()) {
|
||||||
chart.cursors2.cursor_style.orientation = Cursors.Orientation.VERTICAL;
|
chart.cursors.cursor_style.orientation = Cursors.Orientation.VERTICAL;
|
||||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
radio_button8.toggled.connect ((button) => {
|
radio_button8.toggled.connect ((button) => {
|
||||||
if (button.get_active()) {
|
if (button.get_active()) {
|
||||||
chart.cursors2.cursor_style.orientation = Cursors.Orientation.HORIZONTAL;
|
chart.cursors.cursor_style.orientation = Cursors.Orientation.HORIZONTAL;
|
||||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -429,7 +429,7 @@ int main (string[] args) {
|
||||||
chart.draw_selection (Cairo.Rectangle() {x = sel_x0, y = sel_y0, width = sel_x1 - sel_x0, height = sel_y1 - sel_y0});
|
chart.draw_selection (Cairo.Rectangle() {x = sel_x0, y = sel_y0, width = sel_x1 - sel_x0, height = sel_y1 - sel_y0});
|
||||||
|
|
||||||
// show delta
|
// show delta
|
||||||
var str = chart.cursors2.get_cursors_delta_str(chart);
|
var str = chart.cursors.get_cursors_delta_str(chart);
|
||||||
if (str != "") {
|
if (str != "") {
|
||||||
var text = "Δ = " + str;
|
var text = "Δ = " + str;
|
||||||
var text_t = new Text(text);
|
var text_t = new Text(text);
|
||||||
|
|
Loading…
Reference in New Issue