Methods order changed according to usage probabilities.

This commit is contained in:
Kolan Sh 2018-01-23 19:44:22 +03:00
parent d285906004
commit b5a173f4ed
5 changed files with 194 additions and 194 deletions

View File

@ -28,6 +28,31 @@ namespace CairoChart {
*/ */
public Range place = new Range(); 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. * Data type.
*/ */
@ -68,31 +93,6 @@ namespace CairoChart {
*/ */
public Scale scale; 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. * Float128 numbers print string format.
*/ */

View File

@ -131,62 +131,66 @@ namespace CairoChart {
} }
/** /**
* Evaluates crossings. * Gets delta between 2 cursors values.
* @param delta returns delta value.
*/ */
public void eval_crossings () { public bool get_delta (out Float128 delta) {
var all_cursors = get_all_cursors(); delta = 0;
if (chart.series.length == 0) return false;
CursorCrossings[] local_cursor_crossings = {}; if (list.length() + (is_cursor_active ? 1 : 0) != 2) return false;
if (chart.joint_x && style.orientation == Orientation.VERTICAL) {
for (var ci = 0, max_ci = all_cursors.length(); ci < max_ci; ++ci) { Float128 val1 = chart.series[chart.zoom_1st_idx].axis_x.axis_val(rel2scr_x(list.nth_data(0).x));
var c = all_cursors.nth_data(ci); Float128 val2 = 0;
switch (style.orientation) { if (is_cursor_active)
case Orientation.VERTICAL: if (c.x <= chart.zoom.x0 || c.x >= chart.zoom.x1) continue; break; val2 = chart.series[chart.zoom_1st_idx].axis_x.axis_val(rel2scr_x(active_cursor.x));
case Orientation.HORIZONTAL: if (c.y <= chart.zoom.y0 || c.y >= chart.zoom.y1) continue; break; 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) { * Gets delta formatted string.
var s = chart.series[si]; */
if (!s.zoom_show) continue; public string get_delta_str () {
Float128 delta = 0;
var points = Math.sort_points (s, s.sort); if (!get_delta(out delta)) return "";
var str = "";
for (var i = 0; i + 1 < points.length; ++i) { var s = chart.series[chart.zoom_1st_idx];
switch (style.orientation) { if (chart.joint_x)
case Orientation.VERTICAL: switch (s.axis_x.dtype) {
Float128 y = 0; case Axis.DType.NUMBERS:
if (Math.vcross(s.scr_pnt(points[i]), s.scr_pnt(points[i+1]), rel2scr_x(c.x), str = s.axis_x.format.printf((LongDouble)delta);
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; break;
case Orientation.HORIZONTAL: case Axis.DType.DATE_TIME:
Float128 x = 0; var date = "", time = "";
if (Math.hcross(s.scr_pnt(points[i]), s.scr_pnt(points[i+1]), int64 days = (int64)(delta / 24 / 3600);
chart.plarea.x0, chart.plarea.x1, rel2scr_y(c.y), out x)) { s.axis_x.print_dt(delta, out date, out time);
var point = Point128(s.axis_x.axis_val(x), s.axis_y.axis_val(rel2scr_y(c.y))); str = days.to_string() + " + " + time;
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; 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;
} }
/** /**
@ -384,66 +388,62 @@ namespace CairoChart {
} }
/** /**
* Gets delta between 2 cursors values. * Evaluates crossings.
* @param delta returns delta value.
*/ */
public bool get_delta (out Float128 delta) { public void eval_crossings () {
delta = 0; var all_cursors = get_all_cursors();
if (chart.series.length == 0) return false;
if (list.length() + (is_cursor_active ? 1 : 0) != 2) return false; CursorCrossings[] local_cursor_crossings = {};
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)); for (var ci = 0, max_ci = all_cursors.length(); ci < max_ci; ++ci) {
Float128 val2 = 0; var c = all_cursors.nth_data(ci);
if (is_cursor_active) switch (style.orientation) {
val2 = chart.series[chart.zoom_1st_idx].axis_x.axis_val(rel2scr_x(active_cursor.x)); case Orientation.VERTICAL: if (c.x <= chart.zoom.x0 || c.x >= chart.zoom.x1) continue; break;
else case Orientation.HORIZONTAL: if (c.y <= chart.zoom.y0 || c.y >= chart.zoom.y1) continue; break;
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 = {};
* Gets delta formatted string. for (var si = 0, max_si = chart.series.length; si < max_si; ++si) {
*/ var s = chart.series[si];
public string get_delta_str () { if (!s.zoom_show) continue;
Float128 delta = 0;
if (!get_delta(out delta)) return ""; var points = Math.sort_points (s, s.sort);
var str = "";
var s = chart.series[chart.zoom_1st_idx]; for (var i = 0; i + 1 < points.length; ++i) {
if (chart.joint_x) switch (style.orientation) {
switch (s.axis_x.dtype) { case Orientation.VERTICAL:
case Axis.DType.NUMBERS: Float128 y = 0;
str = s.axis_x.format.printf((LongDouble)delta); 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; break;
case Axis.DType.DATE_TIME: case Orientation.HORIZONTAL:
var date = "", time = ""; Float128 x = 0;
int64 days = (int64)(delta / 24 / 3600); if (Math.hcross(s.scr_pnt(points[i]), s.scr_pnt(points[i+1]),
s.axis_x.print_dt(delta, out date, out time); chart.plarea.x0, chart.plarea.x1, rel2scr_y(c.y), out x)) {
str = days.to_string() + " + " + time; 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; 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 { protected struct CursorCross {

View File

@ -8,6 +8,11 @@ namespace CairoChart {
protected unowned Chart chart; protected unowned Chart chart;
protected double [] max_font_heights; protected double [] max_font_heights;
/**
* Show legend?
*/
public bool show = true;
/** /**
* ``Legend`` position. * ``Legend`` position.
*/ */
@ -68,11 +73,6 @@ namespace CairoChart {
*/ */
public double line_length = 30; public double line_length = 30;
/**
* Show legend?
*/
public bool show = true;
/** /**
* Constructs a new ``Legend``. * Constructs a new ``Legend``.
* @param chart ``Chart`` instance. * @param chart ``Chart`` instance.

View File

@ -9,11 +9,31 @@ namespace CairoChart {
protected unowned Chart chart { get; protected set; default = null; } 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. * 128-bit (X;Y) points.
*/ */
public Point128[] points = {}; public Point128[] points = {};
/**
* ``Marker`` style.
*/
public Marker marker;
/**
* Grid style.
*/
public Grid grid = new Grid ();
/** /**
* Sort style. * Sort style.
*/ */
@ -49,26 +69,6 @@ namespace CairoChart {
*/ */
public Axis axis_y; 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). * ``Series`` color (set only).
*/ */
@ -118,6 +118,22 @@ namespace CairoChart {
return series; 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``. * 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``. * Zooms out the ``Series``.
*/ */

View File

@ -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``. * Constructs a new ``Text``.
* @param chart ``Chart`` instance. * @param chart ``Chart`` instance.
@ -138,5 +120,23 @@ namespace CairoChart {
text.color = this.color; text.color = this.color;
return text; 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);
}
}
} }
} }