In progress...

This commit is contained in:
Kolan Sh 2018-01-16 18:49:37 +03:00
parent fb7971fed6
commit b6a8c4e6ee
4 changed files with 72 additions and 72 deletions

View File

@ -164,10 +164,10 @@ namespace CairoChart {
for (var si = 0, max_i = series.length; si < max_i; ++si) {
var s = series[si];
if (!s.zoom_show) continue;
var real_x0 = get_real_x (s, rect.x);
var real_x1 = get_real_x (s, x1);
var real_y0 = get_real_y (s, rect.y);
var real_y1 = get_real_y (s, y1);
var real_x0 = s.get_real_x (rect.x);
var real_x1 = s.get_real_x (x1);
var real_y0 = s.get_real_y (rect.y);
var real_y1 = s.get_real_y (y1);
// if selected square does not intersect with the series's square
if ( real_x1 <= s.axis_x.zoom_min || real_x0 >= s.axis_x.zoom_max
|| real_y0 <= s.axis_y.zoom_min || real_y1 >= s.axis_y.zoom_max) {
@ -375,34 +375,6 @@ namespace CairoChart {
context.stroke ();
}
public virtual double get_scr_x (Series s, Float128 x) {
return plot_x_min + (plot_x_max - plot_x_min) * (s.place.zoom_x_min + (x - s.axis_x.zoom_min)
/ (s.axis_x.zoom_max - s.axis_x.zoom_min) * (s.place.zoom_x_max - s.place.zoom_x_min));
}
public virtual double get_scr_y (Series s, Float128 y) {
return plot_y_max - (plot_y_max - plot_y_min) * (s.place.zoom_y_min + (y - s.axis_y.zoom_min)
/ (s.axis_y.zoom_max - s.axis_y.zoom_min) * (s.place.zoom_y_max - s.place.zoom_y_min));
}
public virtual Point128 get_scr_point (Series s, Point128 p) {
return Point128 (get_scr_x(s, p.x), get_scr_y(s, p.y));
}
public virtual Float128 get_real_x (Series s, double scr_x) {
return s.axis_x.zoom_min + ((scr_x - plot_x_min) / (plot_x_max - plot_x_min) - s.place.zoom_x_min)
* (s.axis_x.zoom_max - s.axis_x.zoom_min) / (s.place.zoom_x_max - s.place.zoom_x_min);
}
public virtual Float128 get_real_y (Series s, double scr_y) {
return s.axis_y.zoom_min + ((plot_y_max - scr_y) / (plot_y_max - plot_y_min) - s.place.zoom_y_min)
* (s.axis_y.zoom_max - s.axis_y.zoom_min) / (s.place.zoom_y_max - s.place.zoom_y_min);
}
public virtual Point128 get_real_point (Series s, Point128 p) {
return Point128 (get_real_x(s, p.x), get_real_y(s, p.y));
}
protected virtual bool x_in_plot_area (double x) {
if (math.x_in_range(x, plot_x_min, plot_x_max))
return true;
@ -415,7 +387,7 @@ namespace CairoChart {
return false;
}
public virtual bool point_in_plot_area (Point128 p) {
public virtual bool point_in_plot_area (Point p) {
if (math.point_in_rect (p, plot_x_min, plot_x_max, plot_y_min, plot_y_max))
return true;
return false;

View File

@ -36,8 +36,8 @@ namespace CairoChart {
bool show_date;
bool show_time;
bool show_y;
Point128 scr_point;
Point128 scr_value_point;
Point scr_point;
Point scr_value_point;
}
protected struct CursorCrossings {
uint cursor_index;
@ -84,9 +84,9 @@ namespace CairoChart {
switch (chart.cursor_style.orientation) {
case Orientation.VERTICAL:
Float128 y = 0.0;
if (chart.math.vcross(chart.get_scr_point(s, points[i]), chart.get_scr_point(s, points[i+1]), chart.rel2scr_x(c.x),
if (chart.math.vcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]), chart.rel2scr_x(c.x),
chart.plot_y_min, chart.plot_y_max, out y)) {
var point = Point128(chart.get_real_x(s, chart.rel2scr_x(c.x)), chart.get_real_y(s, y));
var point = Point128(s.get_real_x(chart.rel2scr_x(c.x)), s.get_real_y(y));
Point128 size; bool show_x, show_date, show_time, show_y;
cross_what_to_show(chart, s, out show_x, out show_time, out show_date, out show_y);
calc_cross_sizes (chart, s, point, out size, show_x, show_time, show_date, show_y);
@ -96,9 +96,9 @@ namespace CairoChart {
break;
case Orientation.HORIZONTAL:
Float128 x = 0.0;
if (chart.math.hcross(chart.get_scr_point(s, points[i]), chart.get_scr_point(s, points[i+1]),
if (chart.math.hcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]),
chart.plot_x_min, chart.plot_x_max, chart.rel2scr_y(c.y), out x)) {
var point = Point128(chart.get_real_x(s, x), chart.get_real_y(s, chart.rel2scr_y(c.y)));
var point = Point128(s.get_real_x(x), s.get_real_y(chart.rel2scr_y(c.y)));
Point128 size; bool show_x, show_date, show_time, show_y;
cross_what_to_show(chart, s, out show_x, out show_time, out show_date, out show_y);
calc_cross_sizes (chart, s, point, out size, show_x, show_time, show_date, show_y);
@ -122,9 +122,9 @@ namespace CairoChart {
for (var cci = 0, max_cci = chart.cursors_crossings[ccsi].crossings.length; cci < max_cci; ++cci) {
// TODO: Ticket #142: find smart algorithm of cursors values placements
unowned CursorCross[] cr = chart.cursors_crossings[ccsi].crossings;
cr[cci].scr_point = chart.get_scr_point (chart.series[cr[cci].series_index], cr[cci].point);
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 = Point128 (cr[cci].scr_point.x + d_max, cr[cci].scr_point.y - d_max);
cr[cci].scr_value_point = Point (cr[cci].scr_point.x + d_max, cr[cci].scr_point.y - d_max);
}
}
}
@ -194,8 +194,8 @@ namespace CairoChart {
var si = ccs[ci].series_index;
var s = chart.series[si];
var p = ccs[ci].point;
var scrx = chart.get_scr_x(s, p.x);
var scry = chart.get_scr_y(s, p.y);
var scrx = s.get_scr_x(p.x);
var scry = s.get_scr_y(p.y);
if (scrx < low.x) low.x = scrx;
if (scry < low.y) low.y = scry;
if (scrx > high.x) high.x = scrx;
@ -237,7 +237,7 @@ namespace CairoChart {
// show joint X value
if (chart.joint_x) {
var s = chart.series[chart.zoom_first_show];
var x = chart.get_real_x(s, chart.rel2scr_x(c.x));
var x = s.get_real_x(chart.rel2scr_x(c.x));
string text = "", time_text = "";
switch (s.axis_x.type) {
case Axis.Type.NUMBERS:
@ -295,7 +295,7 @@ namespace CairoChart {
// show joint Y value
if (chart.joint_y) {
var s = chart.series[chart.zoom_first_show];
var y = chart.get_real_y(s, chart.rel2scr_y(c.y));
var y = s.get_real_y(chart.rel2scr_y(c.y));
var text_t = new Text(s.axis_y.format.printf((LongDouble)y, s.axis_y.font_style));
var print_y = s.compact_rec_y_pos (y, text_t);
var print_x = 0.0;
@ -383,12 +383,12 @@ namespace CairoChart {
if (chart.series.length == 0) return false;
if (chart.cursors.length() + (chart.is_cursor_active ? 1 : 0) != 2) return false;
if (chart.joint_x && chart.cursor_style.orientation == Orientation.VERTICAL) {
Float128 val1 = chart.get_real_x (chart.series[chart.zoom_first_show], chart.rel2scr_x(chart.cursors.nth_data(0).x));
Float128 val1 = chart.series[chart.zoom_first_show].get_real_x(chart.rel2scr_x(chart.cursors.nth_data(0).x));
Float128 val2 = 0;
if (chart.is_cursor_active)
val2 = chart.get_real_x (chart.series[chart.zoom_first_show], chart.rel2scr_x(chart.active_cursor.x));
val2 = chart.series[chart.zoom_first_show].get_real_x(chart.rel2scr_x(chart.active_cursor.x));
else
val2 = chart.get_real_x (chart.series[chart.zoom_first_show], chart.rel2scr_x(chart.cursors.nth_data(1).x));
val2 = chart.series[chart.zoom_first_show].get_real_x(chart.rel2scr_x(chart.cursors.nth_data(1).x));
if (val2 > val1)
delta = val2 - val1;
else
@ -396,12 +396,12 @@ namespace CairoChart {
return true;
}
if (chart.joint_y && chart.cursor_style.orientation == Orientation.HORIZONTAL) {
Float128 val1 = chart.get_real_y (chart.series[chart.zoom_first_show], chart.rel2scr_y(chart.cursors.nth_data(0).y));
Float128 val1 = chart.series[chart.zoom_first_show].get_real_y(chart.rel2scr_y(chart.cursors.nth_data(0).y));
Float128 val2 = 0;
if (chart.is_cursor_active)
val2 = chart.get_real_y (chart.series[chart.zoom_first_show], chart.rel2scr_y(chart.active_cursor.y));
val2 = chart.series[chart.zoom_first_show].get_real_y(chart.rel2scr_y(chart.active_cursor.y));
else
val2 = chart.get_real_y (chart.series[chart.zoom_first_show], chart.rel2scr_y(chart.cursors.nth_data(1).y));
val2 = chart.series[chart.zoom_first_show].get_real_y(chart.rel2scr_y(chart.cursors.nth_data(1).y));
if (val2 > val1)
delta = val2 - val1;
else

View File

@ -46,13 +46,13 @@ namespace CairoChart {
return false;
}
public virtual bool point_in_rect (Point128 p, double x0, double x1, double y0, double y1) {
public virtual bool point_in_rect (Point p, double x0, double x1, double y0, double y1) {
if (x_in_range(p.x, x0, x1) && y_in_range(p.y, y0, y1))
return true;
return false;
}
public virtual bool hcross (Point128 a1, Point128 a2, Float128 h_x1, Float128 h_x2, Float128 h_y, out Float128 x) {
public virtual bool hcross (Point a1, Point a2, double h_x1, double h_x2, double h_y, out double x) {
x = 0;
if (a1.y == a2.y) return false;
if (a1.y >= h_y && a2.y >= h_y || a1.y <= h_y && a2.y <= h_y) return false;
@ -62,7 +62,7 @@ namespace CairoChart {
return false;
}
public virtual bool vcross (Point128 a1, Point128 a2, Float128 v_x, Float128 v_y1, Float128 v_y2, out Float128 y) {
public virtual bool vcross (Point a1, Point a2, double v_x, double v_y1, double v_y2, out double y) {
y = 0;
if (a1.x == a2.x) return false;
if (a1.x >= v_x && a2.x >= v_x || a1.x <= v_x && a2.x <= v_x) return false;
@ -86,18 +86,18 @@ namespace CairoChart {
}
}
public virtual bool cut_line (Point128 p_min, Point128 p_max, Point128 a, Point128 b, out Point128 c, out Point128 d) {
public virtual bool cut_line (Point p_min, Point p_max, Point a, Point b, out Point c, out Point d) {
int ncross = 0;
Float128 x = 0, y = 0;
Point128 pc[4];
Point pc[4];
if (hcross(a, b, p_min.x, p_max.x, p_min.y, out x))
pc[ncross++] = Point128(x, p_min.y);
pc[ncross++] = Point(x, p_min.y);
if (hcross(a, b, p_min.x, p_max.x, p_max.y, out x))
pc[ncross++] = Point128(x, p_max.y);
pc[ncross++] = Point(x, p_max.y);
if (vcross(a, b, p_min.x, p_min.y, p_max.y, out y))
pc[ncross++] = Point128(p_min.x, y);
pc[ncross++] = Point(p_min.x, y);
if (vcross(a, b, p_max.x, p_min.y, p_max.y, out y))
pc[ncross++] = Point128(p_max.x, y);
pc[ncross++] = Point(p_max.x, y);
c = a;
d = b;
if (ncross == 0) {

View File

@ -68,12 +68,12 @@ namespace CairoChart {
line_style.set(chart);
// draw series line
for (int i = 1; i < points.length; ++i) {
Point128 c, d;
Point c, d;
if (chart.math.cut_line (
Point128(chart.plot_x_min, chart.plot_y_min),
Point128(chart.plot_x_max, chart.plot_y_max),
Point128(chart.get_scr_x(this, points[i - 1].x), chart.get_scr_y(this, points[i - 1].y)),
Point128(chart.get_scr_x(this, points[i].x), chart.get_scr_y(this, points[i].y)),
Point(chart.plot_x_min, chart.plot_y_min),
Point(chart.plot_x_max, chart.plot_y_max),
Point(get_scr_x(points[i - 1].x), get_scr_y(points[i - 1].y)),
Point(get_scr_x(points[i].x), get_scr_y(points[i].y)),
out c, out d)
) {
chart.context.move_to (c.x, c.y);
@ -82,9 +82,9 @@ namespace CairoChart {
}
chart.context.stroke();
for (int i = 0; i < points.length; ++i) {
var x = chart.get_scr_x(this, points[i].x);
var y = chart.get_scr_y(this, points[i].y);
if (chart.point_in_plot_area (Point128 (x, y)))
var x = get_scr_x(points[i].x);
var y = get_scr_y(points[i].y);
if (chart.point_in_plot_area (Point (x, y)))
marker.draw_at_pos(chart, x, y);
}
}
@ -204,7 +204,7 @@ namespace CairoChart {
axis_x.format_date_time(x, out text, out time_text);
break;
}
var scr_x = chart.get_scr_x (this, x);
var scr_x = get_scr_x (x);
var text_t = new Text(text, axis_x.font_style, axis_x.color);
var sz = axis_x.title.get_size(context);
@ -351,7 +351,7 @@ namespace CairoChart {
if (joint_y) chart.set_source_rgba(chart.joint_axis_color);
else chart.set_source_rgba(axis_y.color);
var text = axis_y.format.printf((LongDouble)y);
var scr_y = chart.get_scr_y (this, y);
var scr_y = get_scr_y (y);
var text_t = new Text(text, axis_y.font_style, axis_y.color);
var text_sz = text_t.get_size(context);
var sz = axis_y.title.get_size(context);
@ -470,14 +470,42 @@ namespace CairoChart {
public virtual double compact_rec_x_pos (Float128 x, Text text) {
var sz = text.get_size(chart.context);
return chart.get_scr_x(this, x) - sz.width / 2.0
return get_scr_x(x) - sz.width / 2.0
- sz.width * (x - (axis_x.zoom_min + axis_x.zoom_max) / 2.0) / (axis_x.zoom_max - axis_x.zoom_min);
}
public virtual double compact_rec_y_pos (Float128 y, Text text) {
var sz = text.get_size(chart.context);
return chart.get_scr_y(this, y) + sz.height / 2.0
return get_scr_y(y) + sz.height / 2.0
+ sz.height * (y - (axis_y.zoom_min + axis_y.zoom_max) / 2.0) / (axis_y.zoom_max - axis_y.zoom_min);
}
public virtual double get_scr_x (Float128 x) {
return chart.plot_x_min + (chart.plot_x_max - chart.plot_x_min) * (place.zoom_x_min + (x - axis_x.zoom_min)
/ (axis_x.zoom_max - axis_x.zoom_min) * (place.zoom_x_max - place.zoom_x_min));
}
public virtual double get_scr_y (Float128 y) {
return chart.plot_y_max - (chart.plot_y_max - chart.plot_y_min) * (place.zoom_y_min + (y - axis_y.zoom_min)
/ (axis_y.zoom_max - axis_y.zoom_min) * (place.zoom_y_max - place.zoom_y_min));
}
public virtual Point get_scr_point (Point128 p) {
return Point (get_scr_x(p.x), get_scr_y(p.y));
}
public virtual Float128 get_real_x (double scr_x) {
return axis_x.zoom_min + ((scr_x - chart.plot_x_min) / (chart.plot_x_max - chart.plot_x_min) - place.zoom_x_min)
* (axis_x.zoom_max - axis_x.zoom_min) / (place.zoom_x_max - place.zoom_x_min);
}
public virtual Float128 get_real_y (double scr_y) {
return axis_y.zoom_min + ((chart.plot_y_max - scr_y) / (chart.plot_y_max - chart.plot_y_min) - place.zoom_y_min)
* (axis_y.zoom_max - axis_y.zoom_min) / (place.zoom_y_max - place.zoom_y_min);
}
public virtual Point128 get_real_point (Point p) {
return Point128 (get_real_x(p.x), get_real_y(p.y));
}
}
}