2017-02-16 15:10:53 +03:00
|
|
|
using Cairo;
|
|
|
|
|
2018-01-08 23:33:13 +03:00
|
|
|
namespace CairoChart {
|
2017-02-16 15:10:53 +03:00
|
|
|
|
|
|
|
public class Series {
|
|
|
|
|
|
|
|
public Point[] points = {};
|
|
|
|
public enum Sort {
|
|
|
|
BY_X = 0,
|
|
|
|
BY_Y = 1,
|
2018-01-08 23:33:13 +03:00
|
|
|
UNSORTED
|
2017-02-16 15:10:53 +03:00
|
|
|
}
|
|
|
|
public Sort sort = Sort.BY_X;
|
|
|
|
|
|
|
|
public Axis axis_x = new Axis();
|
|
|
|
public Axis axis_y = new Axis();
|
|
|
|
|
2017-08-22 11:54:18 +03:00
|
|
|
public Place place = new Place();
|
2017-02-16 15:10:53 +03:00
|
|
|
public Text title = new Text ();
|
2018-01-10 12:58:35 +03:00
|
|
|
public Marker marker = new Marker ();
|
2017-02-16 15:10:53 +03:00
|
|
|
|
|
|
|
public Grid grid = new Grid ();
|
|
|
|
|
2018-01-08 23:33:13 +03:00
|
|
|
public Line.Style line_style = Line.Style ();
|
2017-02-16 15:10:53 +03:00
|
|
|
|
|
|
|
protected Color _color = Color (0.0, 0.0, 0.0, 1.0);
|
|
|
|
public Color color {
|
|
|
|
get { return _color; }
|
|
|
|
set {
|
|
|
|
_color = value;
|
|
|
|
line_style.color = _color;
|
|
|
|
axis_x.color = _color;
|
|
|
|
axis_y.color = _color;
|
|
|
|
grid.color = _color;
|
|
|
|
grid.color.alpha = 0.5;
|
|
|
|
grid.line_style.color = _color;
|
|
|
|
grid.line_style.color.alpha = 0.5;
|
|
|
|
}
|
2017-08-19 00:07:04 +03:00
|
|
|
default = Color (0.0, 0.0, 0.0, 1.0);
|
2017-02-16 15:10:53 +03:00
|
|
|
}
|
|
|
|
|
2017-10-25 19:31:30 +03:00
|
|
|
public bool zoom_show = true;
|
|
|
|
|
2018-01-15 12:05:21 +03:00
|
|
|
public virtual Series copy () {
|
2017-08-28 18:16:48 +03:00
|
|
|
var series = new Series ();
|
|
|
|
series._color = this._color;
|
|
|
|
series.axis_x = this.axis_x.copy ();
|
|
|
|
series.axis_y = this.axis_y.copy ();
|
|
|
|
series.grid = this.grid.copy ();
|
|
|
|
series.line_style = this.line_style;
|
2018-01-10 12:58:35 +03:00
|
|
|
series.marker = this.marker;
|
2017-08-22 11:54:18 +03:00
|
|
|
series.place = this.place.copy();
|
2017-12-15 20:50:13 +03:00
|
|
|
series.points = this.points;
|
2017-08-28 18:16:48 +03:00
|
|
|
series.sort = this.sort;
|
|
|
|
series.title = this.title.copy();
|
2017-10-25 19:31:30 +03:00
|
|
|
series.zoom_show = this.zoom_show;
|
2017-08-28 18:16:48 +03:00
|
|
|
return series;
|
2017-02-16 15:10:53 +03:00
|
|
|
}
|
|
|
|
|
2017-08-28 18:16:48 +03:00
|
|
|
public Series () {
|
|
|
|
}
|
2018-01-15 12:32:47 +03:00
|
|
|
|
|
|
|
public virtual void draw (Chart chart) {
|
|
|
|
var points = chart.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 (
|
|
|
|
Point(chart.plot_x_min, chart.plot_y_min),
|
|
|
|
Point(chart.plot_x_max, chart.plot_y_max),
|
|
|
|
Point(chart.get_scr_x(this, points[i - 1].x), chart.get_scr_y(this, points[i - 1].y)),
|
|
|
|
Point(chart.get_scr_x(this, points[i].x), chart.get_scr_y(this, points[i].y)),
|
|
|
|
out c, out d)
|
|
|
|
) {
|
|
|
|
chart.context.move_to (c.x, c.y);
|
|
|
|
chart.context.line_to (d.x, d.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 (Point (x, y)))
|
|
|
|
marker.draw_at_pos(chart, x, y);
|
|
|
|
}
|
|
|
|
}
|
2018-01-15 13:12:42 +03:00
|
|
|
|
|
|
|
public virtual bool equal_x_axis (Series s) {
|
|
|
|
if ( axis_x.position != s.axis_x.position
|
|
|
|
|| axis_x.zoom_min != s.axis_x.zoom_min
|
|
|
|
|| axis_x.zoom_max != s.axis_x.zoom_max
|
|
|
|
|| place.zoom_x_min != s.place.zoom_x_min
|
|
|
|
|| place.zoom_x_max != s.place.zoom_x_max
|
|
|
|
|| axis_x.type != s.axis_x.type
|
|
|
|
)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual bool equal_y_axis (Series s) {
|
|
|
|
if ( axis_y.position != s.axis_y.position
|
|
|
|
|| axis_y.zoom_min != s.axis_y.zoom_min
|
|
|
|
|| axis_y.zoom_max != s.axis_y.zoom_max
|
|
|
|
|| place.zoom_y_min != s.place.zoom_y_min
|
|
|
|
|| place.zoom_y_max != s.place.zoom_y_max
|
|
|
|
|| axis_y.type != s.axis_y.type
|
|
|
|
)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-16 15:10:53 +03:00
|
|
|
}
|
|
|
|
}
|