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)
CursorCross[] crossings = {}; delta = val2 - val1;
for (var si = 0, max_si = chart.series.length; si < max_si; ++si) { else
var s = chart.series[si]; delta = val1 - val2;
if (!s.zoom_show) continue; return true;
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 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 (crossings.length != 0) {
CursorCrossings ccs = {ci, crossings};
local_cursor_crossings += ccs;
}
} }
crossings = local_cursor_crossings; 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;
}
/**
* 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 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);
}
return str;
} }
/** /**
@ -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;
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;
}
/** CursorCrossings[] local_cursor_crossings = {};
* Gets delta formatted string.
*/ for (var ci = 0, max_ci = all_cursors.length(); ci < max_ci; ++ci) {
public string get_delta_str () { var c = all_cursors.nth_data(ci);
Float128 delta = 0; switch (style.orientation) {
if (!get_delta(out delta)) return ""; case Orientation.VERTICAL: if (c.x <= chart.zoom.x0 || c.x >= chart.zoom.x1) continue; break;
var str = ""; case Orientation.HORIZONTAL: if (c.y <= chart.zoom.y0 || c.y >= chart.zoom.y1) continue; break;
var s = chart.series[chart.zoom_1st_idx]; }
if (chart.joint_x)
switch (s.axis_x.dtype) { CursorCross[] crossings = {};
case Axis.DType.NUMBERS: for (var si = 0, max_si = chart.series.length; si < max_si; ++si) {
str = s.axis_x.format.printf((LongDouble)delta); var s = chart.series[si];
break; if (!s.zoom_show) continue;
case Axis.DType.DATE_TIME:
var date = "", time = ""; var points = Math.sort_points (s, s.sort);
int64 days = (int64)(delta / 24 / 3600);
s.axis_x.print_dt(delta, out date, out time); for (var i = 0; i + 1 < points.length; ++i) {
str = days.to_string() + " + " + time; switch (style.orientation) {
break; 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 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 (crossings.length != 0) {
CursorCrossings ccs = {ci, crossings};
local_cursor_crossings += ccs;
} }
if (chart.joint_y) {
str = s.axis_y.format.printf((LongDouble)delta);
} }
return str; 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);
}
}
} }
} }