Methods order changed according to usage probabilities.
This commit is contained in:
parent
d285906004
commit
b5a173f4ed
|
@ -28,6 +28,31 @@ namespace CairoChart {
|
|||
*/
|
||||
public Range place = new Range();
|
||||
|
||||
/**
|
||||
* ``Axis`` position.
|
||||
*/
|
||||
public enum Position {
|
||||
/**
|
||||
* Bottom/Left ``Axis``.
|
||||
*/
|
||||
LOW = 0,
|
||||
|
||||
/**
|
||||
* Top/Right ``Axis``.
|
||||
*/
|
||||
HIGH = 1,
|
||||
|
||||
/**
|
||||
* 2 ``Axes``.
|
||||
*/
|
||||
BOTH = 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Position.
|
||||
*/
|
||||
public Position position = Position.LOW;
|
||||
|
||||
/**
|
||||
* Data type.
|
||||
*/
|
||||
|
@ -68,31 +93,6 @@ namespace CairoChart {
|
|||
*/
|
||||
public Scale scale;
|
||||
|
||||
/**
|
||||
* ``Axis`` position.
|
||||
*/
|
||||
public enum Position {
|
||||
/**
|
||||
* Bottom/Left ``Axis``.
|
||||
*/
|
||||
LOW = 0,
|
||||
|
||||
/**
|
||||
* Top/Right ``Axis``.
|
||||
*/
|
||||
HIGH = 1,
|
||||
|
||||
/**
|
||||
* 2 ``Axes``.
|
||||
*/
|
||||
BOTH = 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Position.
|
||||
*/
|
||||
public Position position = Position.LOW;
|
||||
|
||||
/**
|
||||
* Float128 numbers print string format.
|
||||
*/
|
||||
|
|
204
src/Cursor.vala
204
src/Cursor.vala
|
@ -131,62 +131,66 @@ namespace CairoChart {
|
|||
}
|
||||
|
||||
/**
|
||||
* Evaluates crossings.
|
||||
* Gets delta between 2 cursors values.
|
||||
* @param delta returns delta value.
|
||||
*/
|
||||
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 (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;
|
||||
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;
|
||||
if (chart.joint_x && style.orientation == Orientation.VERTICAL) {
|
||||
Float128 val1 = chart.series[chart.zoom_1st_idx].axis_x.axis_val(rel2scr_x(list.nth_data(0).x));
|
||||
Float128 val2 = 0;
|
||||
if (is_cursor_active)
|
||||
val2 = chart.series[chart.zoom_1st_idx].axis_x.axis_val(rel2scr_x(active_cursor.x));
|
||||
else
|
||||
val2 = chart.series[chart.zoom_1st_idx].axis_x.axis_val(rel2scr_x(list.nth_data(1).x));
|
||||
if (val2 > val1)
|
||||
delta = val2 - val1;
|
||||
else
|
||||
delta = val1 - val2;
|
||||
return true;
|
||||
}
|
||||
if (chart.joint_y && style.orientation == Orientation.HORIZONTAL) {
|
||||
Float128 val1 = chart.series[chart.zoom_1st_idx].axis_y.axis_val(rel2scr_y(list.nth_data(0).y));
|
||||
Float128 val2 = 0;
|
||||
if (is_cursor_active)
|
||||
val2 = chart.series[chart.zoom_1st_idx].axis_y.axis_val(rel2scr_y(active_cursor.y));
|
||||
else
|
||||
val2 = chart.series[chart.zoom_1st_idx].axis_y.axis_val(rel2scr_y(list.nth_data(1).y));
|
||||
if (val2 > val1)
|
||||
delta = val2 - val1;
|
||||
else
|
||||
delta = val1 - val2;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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 (style.orientation) {
|
||||
case Orientation.VERTICAL:
|
||||
Float128 y = 0;
|
||||
if (Math.vcross(s.scr_pnt(points[i]), s.scr_pnt(points[i+1]), rel2scr_x(c.x),
|
||||
chart.plarea.y0, chart.plarea.y1, out y)) {
|
||||
var point = Point128(s.axis_x.axis_val(rel2scr_x(c.x)), s.axis_y.axis_val(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;
|
||||
}
|
||||
/**
|
||||
* Gets delta formatted string.
|
||||
*/
|
||||
public string get_delta_str () {
|
||||
Float128 delta = 0;
|
||||
if (!get_delta(out delta)) return "";
|
||||
var str = "";
|
||||
var s = chart.series[chart.zoom_1st_idx];
|
||||
if (chart.joint_x)
|
||||
switch (s.axis_x.dtype) {
|
||||
case Axis.DType.NUMBERS:
|
||||
str = s.axis_x.format.printf((LongDouble)delta);
|
||||
break;
|
||||
case Orientation.HORIZONTAL:
|
||||
Float128 x = 0;
|
||||
if (Math.hcross(s.scr_pnt(points[i]), s.scr_pnt(points[i+1]),
|
||||
chart.plarea.x0, chart.plarea.x1, rel2scr_y(c.y), out x)) {
|
||||
var point = Point128(s.axis_x.axis_val(x), s.axis_y.axis_val(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;
|
||||
}
|
||||
case Axis.DType.DATE_TIME:
|
||||
var date = "", time = "";
|
||||
int64 days = (int64)(delta / 24 / 3600);
|
||||
s.axis_x.print_dt(delta, out date, out time);
|
||||
str = days.to_string() + " + " + time;
|
||||
break;
|
||||
}
|
||||
if (chart.joint_y) {
|
||||
str = s.axis_y.format.printf((LongDouble)delta);
|
||||
}
|
||||
}
|
||||
if (crossings.length != 0) {
|
||||
CursorCrossings ccs = {ci, crossings};
|
||||
local_cursor_crossings += ccs;
|
||||
}
|
||||
}
|
||||
crossings = local_cursor_crossings;
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -384,66 +388,62 @@ namespace CairoChart {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets delta between 2 cursors values.
|
||||
* @param delta returns delta value.
|
||||
* Evaluates crossings.
|
||||
*/
|
||||
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;
|
||||
if (chart.joint_x && style.orientation == Orientation.VERTICAL) {
|
||||
Float128 val1 = chart.series[chart.zoom_1st_idx].axis_x.axis_val(rel2scr_x(list.nth_data(0).x));
|
||||
Float128 val2 = 0;
|
||||
if (is_cursor_active)
|
||||
val2 = chart.series[chart.zoom_1st_idx].axis_x.axis_val(rel2scr_x(active_cursor.x));
|
||||
else
|
||||
val2 = chart.series[chart.zoom_1st_idx].axis_x.axis_val(rel2scr_x(list.nth_data(1).x));
|
||||
if (val2 > val1)
|
||||
delta = val2 - val1;
|
||||
else
|
||||
delta = val1 - val2;
|
||||
return true;
|
||||
}
|
||||
if (chart.joint_y && style.orientation == Orientation.HORIZONTAL) {
|
||||
Float128 val1 = chart.series[chart.zoom_1st_idx].axis_y.axis_val(rel2scr_y(list.nth_data(0).y));
|
||||
Float128 val2 = 0;
|
||||
if (is_cursor_active)
|
||||
val2 = chart.series[chart.zoom_1st_idx].axis_y.axis_val(rel2scr_y(active_cursor.y));
|
||||
else
|
||||
val2 = chart.series[chart.zoom_1st_idx].axis_y.axis_val(rel2scr_y(list.nth_data(1).y));
|
||||
if (val2 > val1)
|
||||
delta = val2 - val1;
|
||||
else
|
||||
delta = val1 - val2;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
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 (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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets delta formatted string.
|
||||
*/
|
||||
public string get_delta_str () {
|
||||
Float128 delta = 0;
|
||||
if (!get_delta(out delta)) return "";
|
||||
var str = "";
|
||||
var s = chart.series[chart.zoom_1st_idx];
|
||||
if (chart.joint_x)
|
||||
switch (s.axis_x.dtype) {
|
||||
case Axis.DType.NUMBERS:
|
||||
str = s.axis_x.format.printf((LongDouble)delta);
|
||||
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 (style.orientation) {
|
||||
case Orientation.VERTICAL:
|
||||
Float128 y = 0;
|
||||
if (Math.vcross(s.scr_pnt(points[i]), s.scr_pnt(points[i+1]), rel2scr_x(c.x),
|
||||
chart.plarea.y0, chart.plarea.y1, out y)) {
|
||||
var point = Point128(s.axis_x.axis_val(rel2scr_x(c.x)), s.axis_y.axis_val(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 Axis.DType.DATE_TIME:
|
||||
var date = "", time = "";
|
||||
int64 days = (int64)(delta / 24 / 3600);
|
||||
s.axis_x.print_dt(delta, out date, out time);
|
||||
str = days.to_string() + " + " + time;
|
||||
case Orientation.HORIZONTAL:
|
||||
Float128 x = 0;
|
||||
if (Math.hcross(s.scr_pnt(points[i]), s.scr_pnt(points[i+1]),
|
||||
chart.plarea.x0, chart.plarea.x1, rel2scr_y(c.y), out x)) {
|
||||
var point = Point128(s.axis_x.axis_val(x), s.axis_y.axis_val(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 (chart.joint_y) {
|
||||
str = s.axis_y.format.printf((LongDouble)delta);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
if (crossings.length != 0) {
|
||||
CursorCrossings ccs = {ci, crossings};
|
||||
local_cursor_crossings += ccs;
|
||||
}
|
||||
}
|
||||
crossings = local_cursor_crossings;
|
||||
}
|
||||
|
||||
protected struct CursorCross {
|
||||
|
|
|
@ -8,6 +8,11 @@ namespace CairoChart {
|
|||
protected unowned Chart chart;
|
||||
protected double [] max_font_heights;
|
||||
|
||||
/**
|
||||
* Show legend?
|
||||
*/
|
||||
public bool show = true;
|
||||
|
||||
/**
|
||||
* ``Legend`` position.
|
||||
*/
|
||||
|
@ -68,11 +73,6 @@ namespace CairoChart {
|
|||
*/
|
||||
public double line_length = 30;
|
||||
|
||||
/**
|
||||
* Show legend?
|
||||
*/
|
||||
public bool show = true;
|
||||
|
||||
/**
|
||||
* Constructs a new ``Legend``.
|
||||
* @param chart ``Chart`` instance.
|
||||
|
|
|
@ -9,11 +9,31 @@ namespace CairoChart {
|
|||
|
||||
protected unowned Chart chart { get; protected set; default = null; }
|
||||
|
||||
/**
|
||||
* Title of the ``Chart``.
|
||||
*/
|
||||
public Text title;
|
||||
|
||||
/**
|
||||
* ``Series`` line style.
|
||||
*/
|
||||
public LineStyle line_style = LineStyle ();
|
||||
|
||||
/**
|
||||
* 128-bit (X;Y) points.
|
||||
*/
|
||||
public Point128[] points = {};
|
||||
|
||||
/**
|
||||
* ``Marker`` style.
|
||||
*/
|
||||
public Marker marker;
|
||||
|
||||
/**
|
||||
* Grid style.
|
||||
*/
|
||||
public Grid grid = new Grid ();
|
||||
|
||||
/**
|
||||
* Sort style.
|
||||
*/
|
||||
|
@ -49,26 +69,6 @@ namespace CairoChart {
|
|||
*/
|
||||
public Axis axis_y;
|
||||
|
||||
/**
|
||||
* Title of the ``Chart``.
|
||||
*/
|
||||
public Text title;
|
||||
|
||||
/**
|
||||
* ``Marker`` style.
|
||||
*/
|
||||
public Marker marker;
|
||||
|
||||
/**
|
||||
* Grid style.
|
||||
*/
|
||||
public Grid grid = new Grid ();
|
||||
|
||||
/**
|
||||
* ``Series`` line style.
|
||||
*/
|
||||
public LineStyle line_style = LineStyle ();
|
||||
|
||||
/**
|
||||
* ``Series`` color (set only).
|
||||
*/
|
||||
|
@ -118,6 +118,22 @@ namespace CairoChart {
|
|||
return series;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets screen point by real ``Series`` (X;Y) value.
|
||||
* @param p real ``Series`` (X;Y) value.
|
||||
*/
|
||||
public virtual Point scr_pnt (Point128 p) {
|
||||
return Point(axis_x.scr_pos(p.x), axis_y.scr_pos(p.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets real ``Series`` (X;Y) value by plot area screen point.
|
||||
* @param p (X;Y) screen point.
|
||||
*/
|
||||
public virtual Point128 axis_pnt (Point p) {
|
||||
return Point128 (axis_x.axis_val(p.x), axis_y.axis_val(p.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the ``Series``.
|
||||
*/
|
||||
|
@ -147,22 +163,6 @@ namespace CairoChart {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets screen point by real ``Series`` (X;Y) value.
|
||||
* @param p real ``Series`` (X;Y) value.
|
||||
*/
|
||||
public virtual Point scr_pnt (Point128 p) {
|
||||
return Point(axis_x.scr_pos(p.x), axis_y.scr_pos(p.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets real ``Series`` (X;Y) value by plot area screen point.
|
||||
* @param p (X;Y) screen point.
|
||||
*/
|
||||
public virtual Point128 axis_pnt (Point p) {
|
||||
return Point128 (axis_x.axis_val(p.x), axis_y.axis_val(p.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Zooms out the ``Series``.
|
||||
*/
|
||||
|
|
|
@ -90,24 +90,6 @@ namespace CairoChart {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show ``Text``.
|
||||
*/
|
||||
public virtual void show () {
|
||||
if (text == "") return;
|
||||
chart.ctx.select_font_face(font.family,
|
||||
font.slant,
|
||||
font.weight);
|
||||
chart.ctx.set_font_size(font.size);
|
||||
if (font.orient == Gtk.Orientation.VERTICAL) {
|
||||
chart.ctx.rotate(- GLib.Math.PI / 2);
|
||||
chart.ctx.show_text(text);
|
||||
chart.ctx.rotate(GLib.Math.PI / 2);
|
||||
} else {
|
||||
chart.ctx.show_text(text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ``Text``.
|
||||
* @param chart ``Chart`` instance.
|
||||
|
@ -138,5 +120,23 @@ namespace CairoChart {
|
|||
text.color = this.color;
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show ``Text``.
|
||||
*/
|
||||
public virtual void show () {
|
||||
if (text == "") return;
|
||||
chart.ctx.select_font_face(font.family,
|
||||
font.slant,
|
||||
font.weight);
|
||||
chart.ctx.set_font_size(font.size);
|
||||
if (font.orient == Gtk.Orientation.VERTICAL) {
|
||||
chart.ctx.rotate(- GLib.Math.PI / 2);
|
||||
chart.ctx.show_text(text);
|
||||
chart.ctx.rotate(GLib.Math.PI / 2);
|
||||
} else {
|
||||
chart.ctx.show_text(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue