In progress...

This commit is contained in:
Kolan Sh 2018-01-18 20:43:52 +03:00
parent 3aaa53e96c
commit 0fed63c109
4 changed files with 26 additions and 34 deletions

View File

@ -88,11 +88,6 @@ namespace CairoChart {
*/
public Cursors cursors { get; protected set; default = null; }
/**
* Math functions.
*/
public CairoChart.Math math { get; protected set; default = new Math(); }
/**
* Set paint color for further drawing.
*/

View File

@ -131,10 +131,10 @@ namespace CairoChart {
Point128[] points = {};
switch (cursor_style.orientation) {
case Orientation.VERTICAL:
points = chart.math.sort_points (s, s.sort);
points = Math.sort_points (s, s.sort);
break;
case Orientation.HORIZONTAL:
points = chart.math.sort_points (s, s.sort);
points = Math.sort_points (s, s.sort);
break;
}
@ -142,7 +142,7 @@ namespace CairoChart {
switch (cursor_style.orientation) {
case Orientation.VERTICAL:
Float128 y = 0.0;
if (chart.math.vcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]), rel2scr_x(c.x),
if (Math.vcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]), rel2scr_x(c.x),
chart.plarea.y, chart.plarea.y + chart.plarea.height, out y)) {
var point = Point128(s.get_real_x(rel2scr_x(c.x)), s.get_real_y(y));
Point128 size; bool show_x, show_date, show_time, show_y;
@ -154,7 +154,7 @@ namespace CairoChart {
break;
case Orientation.HORIZONTAL:
Float128 x = 0.0;
if (chart.math.hcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]),
if (Math.hcross(s.get_scr_point(points[i]), s.get_scr_point(points[i+1]),
chart.plarea.x, chart.plarea.x + chart.plarea.width, rel2scr_y(c.y), out x)) {
var point = Point128(s.get_real_x(x), s.get_real_y(rel2scr_y(c.y)));
Point128 size; bool show_x, show_date, show_time, show_y;

View File

@ -1,8 +1,8 @@
namespace CairoChart {
public class Math {
namespace Math {
public virtual Float128 calc_round_step (Float128 aver_step, bool date_time = false) {
internal Float128 calc_round_step (Float128 aver_step, bool date_time = false) {
Float128 step = 1.0;
if (aver_step > 1.0) {
@ -21,38 +21,38 @@ namespace CairoChart {
return step;
}
public virtual bool are_intersect (double a_min, double a_max, double b_min, double b_max) {
internal bool are_intersect (double a_min, double a_max, double b_min, double b_max) {
if ( a_min < a_max <= b_min < b_max
|| b_min < b_max <= a_min < a_max)
return false;
return true;
}
public virtual bool point_belong (Float128 p, Float128 a, Float128 b) {
internal bool point_belong (Float128 p, Float128 a, Float128 b) {
if (a > b) { Float128 tmp = a; a = b; b = tmp; }
if (a <= p <= b) return true;
return false;
}
public virtual bool x_in_range (double x, double x0, double x1) {
internal bool x_in_range (double x, double x0, double x1) {
if (x0 <= x <= x1 || x1 <= x <= x0)
return true;
return false;
}
public virtual bool y_in_range (double y, double y0, double y1) {
internal bool y_in_range (double y, double y0, double y1) {
if (y0 <= y <= y1 || y1 <= y <= y0)
return true;
return false;
}
public virtual bool point_in_rect (Point p, double x0, double x1, double y0, double y1) {
internal 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 (Point a1, Point a2, double h_x1, double h_x2, double h_y, out double x) {
internal 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 (Point a1, Point a2, double v_x, double v_y1, double v_y2, out double y) {
internal 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;
@ -72,9 +72,9 @@ namespace CairoChart {
return false;
}
public delegate int PointComparator(Point128 a, Point128 b);
internal delegate int PointComparator(Point128 a, Point128 b);
public virtual void sort_points_delegate(Point128[] points, PointComparator compare) {
internal void sort_points_delegate(Point128[] points, PointComparator compare) {
for(var i = 0; i < points.length; ++i) {
for(var j = i + 1; j < points.length; ++j) {
if(compare(points[i], points[j]) > 0) {
@ -86,7 +86,7 @@ namespace CairoChart {
}
}
public virtual bool cut_line (Point p_min, Point p_max, Point a, Point b, out Point c, out Point d) {
internal 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;
Point pc[4];
@ -124,7 +124,7 @@ namespace CairoChart {
return false;
}
public virtual Point128[] sort_points (Series s, Series.Sort sort) {
internal Point128[] sort_points (Series s, Series.Sort sort) {
var points = s.points;
switch(sort) {
case Series.Sort.BY_X:
@ -144,8 +144,5 @@ namespace CairoChart {
}
return points;
}
public Math () {}
}
}

View File

@ -64,12 +64,12 @@ namespace CairoChart {
}
public virtual void draw () {
var points = chart.math.sort_points(this, sort);
var points = Math.sort_points(this, sort);
line_style.set(chart);
// draw series line
for (int i = 1; i < points.length; ++i) {
Point c, d;
if (chart.math.cut_line (
if (Math.cut_line (
Point(chart.plarea.x, chart.plarea.y),
Point(chart.plarea.x + chart.plarea.width, chart.plarea.y + chart.plarea.height),
Point(get_scr_x(points[i - 1].x), get_scr_y(points[i - 1].y)),
@ -84,7 +84,7 @@ namespace CairoChart {
for (int i = 0; i < points.length; ++i) {
var x = get_scr_x(points[i].x);
var y = get_scr_y(points[i].y);
if (chart.math.point_in_rect (Point(x, y), chart.plarea.x, chart.plarea.x + chart.plarea.width,
if (Math.point_in_rect (Point(x, y), chart.plarea.x, chart.plarea.x + chart.plarea.width,
chart.plarea.y, chart.plarea.y + chart.plarea.height))
marker.draw_at_pos(chart, x, y);
}
@ -188,7 +188,7 @@ namespace CairoChart {
for (int sk = si; sk > sj; --sk) {
var s3 = chart.series[sk];
if (!s3.zoom_show) continue;
if (chart.math.are_intersect(s2.place.zoom_x_min, s2.place.zoom_x_max, s3.place.zoom_x_min, s3.place.zoom_x_max)
if (Math.are_intersect(s2.place.zoom_x_min, s2.place.zoom_x_max, s3.place.zoom_x_min, s3.place.zoom_x_max)
|| s2.axis_x.position != s3.axis_x.position
|| s2.axis_x.type != s3.axis_x.type) {
has_intersection = true;
@ -226,7 +226,7 @@ namespace CairoChart {
for (int sk = si; sk > sj; --sk) {
var s3 = chart.series[sk];
if (!s3.zoom_show) continue;
if (chart.math.are_intersect(s2.place.zoom_y_min, s2.place.zoom_y_max, s3.place.zoom_y_min, s3.place.zoom_y_max)
if (Math.are_intersect(s2.place.zoom_y_min, s2.place.zoom_y_max, s3.place.zoom_y_min, s3.place.zoom_y_max)
|| s2.axis_y.position != s3.axis_y.position
|| s2.axis_y.type != s3.axis_y.type) {
has_intersection = true;
@ -253,7 +253,7 @@ namespace CairoChart {
var ctx = chart.ctx;
var joint_x = chart.joint_x;
for (Float128 x = x_min, x_max = axis_x.zoom_max; chart.math.point_belong (x, x_min, x_max); x += step) {
for (Float128 x = x_min, x_max = axis_x.zoom_max; Math.point_belong (x, x_min, x_max); x += step) {
if (joint_x) chart.color = chart.joint_color;
else chart.color = axis_x.color;
string text = "", time_text = "";
@ -342,7 +342,7 @@ namespace CairoChart {
long max_nrecs = (long) (chart.plarea.width * (s.place.zoom_x_max - s.place.zoom_x_min) / max_rec_width);
// 3. Calculate grid step.
Float128 step = chart.math.calc_round_step ((s.axis_x.zoom_max - s.axis_x.zoom_min) / max_nrecs, s.axis_x.type == Axis.Type.DATE_TIME);
Float128 step = Math.calc_round_step ((s.axis_x.zoom_max - s.axis_x.zoom_min) / max_nrecs, s.axis_x.type == Axis.Type.DATE_TIME);
if (step > s.axis_x.zoom_max - s.axis_x.zoom_min)
step = s.axis_x.zoom_max - s.axis_x.zoom_min;
@ -408,7 +408,7 @@ namespace CairoChart {
var ctx = chart.ctx;
var joint_y = chart.joint_y;
for (Float128 y = y_min, y_max = axis_y.zoom_max; chart.math.point_belong (y, y_min, y_max); y += step) {
for (Float128 y = y_min, y_max = axis_y.zoom_max; Math.point_belong (y, y_min, y_max); y += step) {
if (joint_y) chart.color = chart.joint_color;
else chart.color = axis_y.color;
var text = axis_y.format.printf((LongDouble)y);
@ -466,7 +466,7 @@ namespace CairoChart {
long max_nrecs = (long) (chart.plarea.height * (s.place.zoom_y_max - s.place.zoom_y_min) / max_rec_height);
// 3. Calculate grid step.
Float128 step = chart.math.calc_round_step ((s.axis_y.zoom_max - s.axis_y.zoom_min) / max_nrecs);
Float128 step = Math.calc_round_step ((s.axis_y.zoom_max - s.axis_y.zoom_min) / max_nrecs);
if (step > s.axis_y.zoom_max - s.axis_y.zoom_min)
step = s.axis_y.zoom_max - s.axis_y.zoom_min;