OK In progress...
This commit is contained in:
parent
d676040023
commit
5b8b712cea
|
@ -152,7 +152,7 @@ namespace CairoChart {
|
|||
|
||||
rot_axes_titles ();
|
||||
|
||||
cursors.get_crossings();
|
||||
//cursors.get_crossings();
|
||||
|
||||
eval_plarea ();
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ namespace CairoChart {
|
|||
|
||||
public class Cursors {
|
||||
|
||||
public List<Point?> list = new List<Point?> ();
|
||||
public Point active_cursor = Point(); // { get; protected set; default = Point128 (); }
|
||||
public bool is_cursor_active = false; // { get; protected set; default = false; }
|
||||
protected List<Point?> list = new List<Point?> ();
|
||||
protected Point active_cursor = Point(); // { get; protected set; default = Point128 (); }
|
||||
protected bool is_cursor_active = false; // { get; protected set; default = false; }
|
||||
public Cursors.Style cursor_style = Cursors.Style();
|
||||
public Cursors.CursorCrossings[] cursors_crossings = {};
|
||||
protected Chart chart = null;
|
||||
public Cursors.CursorCrossings[] crossings = {};
|
||||
Chart chart;
|
||||
|
||||
public Cursors (Chart chart) {
|
||||
this.chart = chart;
|
||||
|
@ -19,16 +19,16 @@ namespace CairoChart {
|
|||
c.active_cursor = active_cursor;
|
||||
c.is_cursor_active = is_cursor_active;
|
||||
c.cursor_style = cursor_style;
|
||||
c.cursors_crossings = cursors_crossings;
|
||||
c.crossings = crossings;
|
||||
return c;
|
||||
}
|
||||
|
||||
public enum Orientation {
|
||||
protected enum Orientation {
|
||||
VERTICAL = 0, // default
|
||||
HORIZONTAL
|
||||
}
|
||||
|
||||
public struct Style {
|
||||
protected struct Style {
|
||||
|
||||
public Orientation orientation;
|
||||
public double select_distance;
|
||||
|
@ -57,26 +57,26 @@ namespace CairoChart {
|
|||
CursorCross[] crossings;
|
||||
}
|
||||
|
||||
public virtual void set_active_cursor (Point p, bool remove = false) {
|
||||
public virtual void set_active (Point p, bool remove = false) {
|
||||
active_cursor.x = chart.zoom.x0 + (p.x - chart.plarea.x0) / chart.plarea.width * chart.zoom.width;
|
||||
active_cursor.y = chart.zoom.y1 - (chart.plarea.y1 - p.y) / chart.plarea.height * chart.zoom.height;
|
||||
is_cursor_active = ! remove;
|
||||
}
|
||||
|
||||
public virtual void add_active_cursor () {
|
||||
public virtual void add_active () {
|
||||
list.append (active_cursor);
|
||||
is_cursor_active = false;
|
||||
}
|
||||
|
||||
public virtual Float128 rel2scr_x(Float128 x) {
|
||||
protected virtual Float128 rel2scr_x(Float128 x) {
|
||||
return chart.plarea.x0 + chart.plarea.width * (x - chart.zoom.x0) / chart.zoom.width;
|
||||
}
|
||||
|
||||
public virtual Float128 rel2scr_y(Float128 y) {
|
||||
protected virtual Float128 rel2scr_y(Float128 y) {
|
||||
return chart.plarea.y0 + chart.plarea.height * (y - chart.zoom.y0) / chart.zoom.height;
|
||||
}
|
||||
|
||||
public virtual void remove_active_cursor () {
|
||||
public virtual void remove_active () {
|
||||
if (list.length() == 0) return;
|
||||
var distance = 1024.0 * 1024;//width * width;
|
||||
uint rm_indx = 0;
|
||||
|
@ -105,7 +105,7 @@ namespace CairoChart {
|
|||
return all_cursors;
|
||||
}
|
||||
|
||||
public void get_crossings () {
|
||||
protected void get_crossings () {
|
||||
var all_cursors = get_all_cursors();
|
||||
|
||||
CursorCrossings[] local_cursor_crossings = {};
|
||||
|
@ -158,14 +158,14 @@ namespace CairoChart {
|
|||
local_cursor_crossings += ccs;
|
||||
}
|
||||
}
|
||||
cursors_crossings = local_cursor_crossings;
|
||||
crossings = local_cursor_crossings;
|
||||
}
|
||||
|
||||
protected virtual void calc_cursors_value_positions () {
|
||||
for (var ccsi = 0, max_ccsi = cursors_crossings.length; ccsi < max_ccsi; ++ccsi) {
|
||||
for (var cci = 0, max_cci = cursors_crossings[ccsi].crossings.length; cci < max_cci; ++cci) {
|
||||
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) {
|
||||
// TODO: Ticket #142: find smart algorithm of cursors values placements
|
||||
unowned CursorCross[] cr = cursors_crossings[ccsi].crossings;
|
||||
unowned CursorCross[] cr = crossings[ccsi].crossings;
|
||||
cr[cci].scr_point = chart.series[cr[cci].series_index].get_scr_point (cr[cci].point);
|
||||
var d_max = double.max (cr[cci].size.x / 1.5, cr[cci].size.y / 1.5);
|
||||
cr[cci].scr_value_point = Point (cr[cci].scr_point.x + d_max, cr[cci].scr_point.y - d_max);
|
||||
|
@ -226,13 +226,15 @@ namespace CairoChart {
|
|||
public virtual void draw () {
|
||||
if (chart.series.length == 0) return;
|
||||
|
||||
get_crossings();
|
||||
|
||||
var all_cursors = get_all_cursors();
|
||||
calc_cursors_value_positions();
|
||||
|
||||
for (var cci = 0, max_cci = cursors_crossings.length; cci < max_cci; ++cci) {
|
||||
for (var cci = 0, max_cci = crossings.length; cci < max_cci; ++cci) {
|
||||
var low = Point128(chart.plarea.x1, chart.plarea.y1); // low and high
|
||||
var high = Point128(chart.plarea.x0, chart.plarea.y0); // points of the cursor
|
||||
unowned CursorCross[] ccs = cursors_crossings[cci].crossings;
|
||||
unowned CursorCross[] ccs = crossings[cci].crossings;
|
||||
cursor_style.line_style.apply(chart);
|
||||
for (var ci = 0, max_ci = ccs.length; ci < max_ci; ++ci) {
|
||||
var si = ccs[ci].series_index;
|
||||
|
@ -270,7 +272,7 @@ namespace CairoChart {
|
|||
chart.ctx.line_to (ccs[ci].scr_value_point.x, ccs[ci].scr_value_point.y);
|
||||
}
|
||||
|
||||
var c = all_cursors.nth_data(cursors_crossings[cci].cursor_index);
|
||||
var c = all_cursors.nth_data(crossings[cci].cursor_index);
|
||||
|
||||
switch (cursor_style.orientation) {
|
||||
case Orientation.VERTICAL:
|
||||
|
@ -415,7 +417,7 @@ namespace CairoChart {
|
|||
}
|
||||
}
|
||||
|
||||
public bool get_cursors_delta (out Float128 delta) {
|
||||
public bool get_delta (out Float128 delta) {
|
||||
delta = 0;
|
||||
if (chart.series.length == 0) return false;
|
||||
if (list.length() + (is_cursor_active ? 1 : 0) != 2) return false;
|
||||
|
@ -448,9 +450,9 @@ namespace CairoChart {
|
|||
return false;
|
||||
}
|
||||
|
||||
public string get_cursors_delta_str () {
|
||||
public string get_delta_str () {
|
||||
Float128 delta = 0;
|
||||
if (!get_cursors_delta(out delta)) return "";
|
||||
if (!get_delta(out delta)) return "";
|
||||
var str = "";
|
||||
var s = chart.series[chart.zoom_1st_idx];
|
||||
if (chart.joint_x)
|
||||
|
|
|
@ -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.cursors_crossings.length != 0) {
|
||||
if (si == chart.zoom_1st_idx && chart.cursors.crossings.length != 0) {
|
||||
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.cursors_crossings.length != 0) {
|
||||
if (chart.joint_x && chart.cursors.cursor_style.orientation == Cursors.Orientation.VERTICAL && chart.cursors.crossings.length != 0) {
|
||||
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.cursors_crossings.length != 0) {
|
||||
if (chart.joint_y && chart.cursors.cursor_style.orientation == Cursors.Orientation.HORIZONTAL && chart.cursors.crossings.length != 0) {
|
||||
var tmp = max_rec_width + s.axis_y.font.hspacing;
|
||||
switch (s.axis_y.position) {
|
||||
case Axis.Position.LOW: chart.evarea.x0 += tmp; break;
|
||||
|
|
|
@ -458,7 +458,7 @@ int main (string[] args) {
|
|||
chart.draw_selection (new Area.with_abs(sel_x0, sel_y0, sel_x1, sel_y1));
|
||||
|
||||
// show delta
|
||||
var str = chart.cursors.get_cursors_delta_str();
|
||||
var str = chart.cursors.get_delta_str();
|
||||
if (str != "") {
|
||||
var text = "Δ = " + str;
|
||||
var text_t = new Text(chart, text);
|
||||
|
@ -483,11 +483,11 @@ int main (string[] args) {
|
|||
switch (event.button) {
|
||||
case 1: // start cursor position selection
|
||||
if ((event.state & Gdk.ModifierType.SHIFT_MASK) != 0) { // remove cursor
|
||||
chart.cursors.set_active_cursor (Point(event.x, event.y), true);
|
||||
chart.cursors.remove_active_cursor();
|
||||
chart.cursors.set_active (Point(event.x, event.y), true);
|
||||
chart.cursors.remove_active();
|
||||
mouse_state = MouseState.FREE;
|
||||
} else { // add cursor
|
||||
chart.cursors.set_active_cursor (Point(event.x, event.y));
|
||||
chart.cursors.set_active (Point(event.x, event.y));
|
||||
mouse_state = MouseState.CURSOR_SELECTION;
|
||||
}
|
||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
|
@ -515,11 +515,11 @@ int main (string[] args) {
|
|||
switch (event.button) {
|
||||
case 1: // start cursor position selection
|
||||
if ((event.state & Gdk.ModifierType.SHIFT_MASK) != 0) { // remove cursor
|
||||
//chart.remove_active_cursor ();
|
||||
//chart.remove_active ();
|
||||
//da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
//mouse_state = MouseState.FREE;
|
||||
} else { // add cursor
|
||||
chart.cursors.add_active_cursor ();
|
||||
chart.cursors.add_active ();
|
||||
mouse_state = MouseState.FREE;
|
||||
}
|
||||
break;
|
||||
|
@ -561,7 +561,7 @@ int main (string[] args) {
|
|||
break;
|
||||
|
||||
case MouseState.CURSOR_SELECTION:
|
||||
chart.cursors.set_active_cursor (Point(event.x, event.y));
|
||||
chart.cursors.set_active (Point(event.x, event.y));
|
||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue