Marker.vala ... #2

This commit is contained in:
Kolan Sh 2018-01-10 12:58:35 +03:00
parent 6e577891ae
commit 76fb9d8797
5 changed files with 56 additions and 56 deletions

View File

@ -210,8 +210,6 @@ namespace CairoChart {
title.show(context); title.show(context);
} }
public double marker_size = 8.0;
public Line.Style selection_style = Line.Style (); public Line.Style selection_style = Line.Style ();
public virtual void draw_selection (double x0, double y0, double x1, double y1) { public virtual void draw_selection (double x0, double y0, double x1, double y1) {
@ -950,7 +948,7 @@ namespace CairoChart {
var x = get_scr_x(s, points[i].x); var x = get_scr_x(s, points[i].x);
var y = get_scr_y(s, points[i].y); var y = get_scr_y(s, points[i].y);
if (point_in_plot_area (Point (x, y))) if (point_in_plot_area (Point (x, y)))
Marker.draw_at_pos(this, s.marker_type, x, y, marker_size); s.marker.draw_at_pos(this, x, y);
} }
} }
} }
@ -1446,7 +1444,6 @@ namespace CairoChart {
chart.height = this.height; chart.height = this.height;
chart.is_cursor_active = this.is_cursor_active; chart.is_cursor_active = this.is_cursor_active;
chart.legend = this.legend.copy(); chart.legend = this.legend.copy();
chart.marker_size = this.marker_size;
chart.plot_x_max = this.plot_x_max; chart.plot_x_max = this.plot_x_max;
chart.plot_x_min = this.plot_x_min; chart.plot_x_min = this.plot_x_min;
chart.plot_y_max = this.plot_y_max; chart.plot_y_max = this.plot_y_max;

View File

@ -152,11 +152,7 @@ namespace CairoChart {
s.line_style.set(chart); s.line_style.set(chart);
chart.context.rel_line_to (line_length, 0); chart.context.rel_line_to (line_length, 0);
chart.context.stroke(); chart.context.stroke();
Marker.draw_at_pos (chart, s.marker.draw_at_pos (chart, x + line_length / 2, y - title_sz.height / 2);
s.marker_type,
x + line_length / 2,
y - title_sz.height / 2,
chart.marker_size);
break; break;
} }

View File

@ -2,48 +2,65 @@ namespace CairoChart {
public class Marker { public class Marker {
public static void draw_at_pos (Chart chart, public enum Type {
Series.MarkerType marker_type, NONE = 0, // default
double x, SQUARE,
double y, CIRCLE,
double marker_size = 8.0) { TRIANGLE,
PRICLE_SQUARE,
PRICLE_CIRCLE,
PRICLE_TRIANGLE
}
public Type type = Type.NONE;
public double size = 8.0;
public Marker (Type type = Type.NONE, double size = 8.0) {
this.type = type;
this.size = size;
}
public Marker copy () {
return new Marker (type, size);
}
public virtual void draw_at_pos (Chart chart, double x, double y) {
chart.context.move_to (x, y); chart.context.move_to (x, y);
switch (marker_type) { switch (type) {
case Series.MarkerType.SQUARE: case Type.SQUARE:
chart.context.rectangle (x - marker_size / 2, y - marker_size / 2, chart.context.rectangle (x - size / 2, y - size / 2, size, size);
marker_size, marker_size);
chart.context.fill(); chart.context.fill();
break; break;
case Series.MarkerType.CIRCLE: case Type.CIRCLE:
chart.context.arc (x, y, marker_size / 2, 0, 2*Math.PI); chart.context.arc (x, y, size / 2, 0, 2*Math.PI);
chart.context.fill(); chart.context.fill();
break; break;
case Series.MarkerType.TRIANGLE: case Type.TRIANGLE:
chart.context.move_to (x - marker_size / 2, y - marker_size / 2); chart.context.move_to (x - size / 2, y - size / 2);
chart.context.line_to (x + marker_size / 2, y - marker_size / 2); chart.context.line_to (x + size / 2, y - size / 2);
chart.context.line_to (x, y + marker_size / 2); chart.context.line_to (x, y + size / 2);
chart.context.line_to (x - marker_size / 2, y - marker_size / 2); chart.context.line_to (x - size / 2, y - size / 2);
chart.context.fill(); chart.context.fill();
break; break;
case Series.MarkerType.PRICLE_SQUARE: case Type.PRICLE_SQUARE:
chart.context.rectangle (x - marker_size / 2, y - marker_size / 2, chart.context.rectangle (x - size / 2, y - size / 2,
marker_size, marker_size); size, size);
chart.context.stroke(); chart.context.stroke();
break; break;
case Series.MarkerType.PRICLE_CIRCLE: case Type.PRICLE_CIRCLE:
chart.context.arc (x, y, marker_size / 2, 0, 2*Math.PI); chart.context.arc (x, y, size / 2, 0, 2*Math.PI);
chart.context.stroke(); chart.context.stroke();
break; break;
case Series.MarkerType.PRICLE_TRIANGLE: case Type.PRICLE_TRIANGLE:
chart.context.move_to (x - marker_size / 2, y - marker_size / 2); chart.context.move_to (x - size / 2, y - size / 2);
chart.context.line_to (x + marker_size / 2, y - marker_size / 2); chart.context.line_to (x + size / 2, y - size / 2);
chart.context.line_to (x, y + marker_size / 2); chart.context.line_to (x, y + size / 2);
chart.context.line_to (x - marker_size / 2, y - marker_size / 2); chart.context.line_to (x - size / 2, y - size / 2);
chart.context.stroke(); chart.context.stroke();
break; break;
} }

View File

@ -15,19 +15,9 @@ namespace CairoChart {
public Axis axis_x = new Axis(); public Axis axis_x = new Axis();
public Axis axis_y = new Axis(); public Axis axis_y = new Axis();
public enum MarkerType {
NONE = 0, // default
SQUARE,
CIRCLE,
TRIANGLE,
PRICLE_SQUARE,
PRICLE_CIRCLE,
PRICLE_TRIANGLE
}
public Place place = new Place(); public Place place = new Place();
public Text title = new Text (); public Text title = new Text ();
public MarkerType marker_type = MarkerType.SQUARE; public Marker marker = new Marker ();
public Grid grid = new Grid (); public Grid grid = new Grid ();
@ -58,7 +48,7 @@ namespace CairoChart {
series.axis_y = this.axis_y.copy (); series.axis_y = this.axis_y.copy ();
series.grid = this.grid.copy (); series.grid = this.grid.copy ();
series.line_style = this.line_style; series.line_style = this.line_style;
series.marker_type = this.marker_type; series.marker = this.marker;
series.place = this.place.copy(); series.place = this.place.copy();
series.points = this.points; series.points = this.points;
series.sort = this.sort; series.sort = this.sort;

View File

@ -30,8 +30,8 @@ void plot_chart1 (Chart chart) {
s3.place.x_min = 0; s3.place.x_max = 0.5; s3.place.x_min = 0; s3.place.x_max = 0.5;
s3.place.y_min = 0.5; s3.place.y_max = 1.0; s3.place.y_min = 0.5; s3.place.y_max = 1.0;
s2.marker_type = Series.MarkerType.CIRCLE; s2.marker.type = Marker.Type.CIRCLE;
s3.marker_type = Series.MarkerType.PRICLE_TRIANGLE; s3.marker.type = Marker.Type.PRICLE_TRIANGLE;
s1.axis_x.title = new Text("Series 1: Axis X."); s1.axis_x.title = new Text("Series 1: Axis X.");
s1.axis_y.title = new Text("Series 1: Axis Y."); s1.axis_y.title = new Text("Series 1: Axis Y.");
@ -73,8 +73,8 @@ void plot_chart2 (Chart chart) {
s3.place.x_min = 0.0; s3.place.x_max = 1.0; s3.place.x_min = 0.0; s3.place.x_max = 1.0;
s3.place.y_min = 0.5; s3.place.y_max = 1.0; s3.place.y_min = 0.5; s3.place.y_max = 1.0;
s1.marker_type = Series.MarkerType.PRICLE_CIRCLE; s1.marker.type = Marker.Type.PRICLE_CIRCLE;
s2.marker_type = Series.MarkerType.PRICLE_SQUARE; s2.marker.type = Marker.Type.PRICLE_SQUARE;
s1.axis_x.title = new Text("All Series: Axis X."); s1.axis_x.title = new Text("All Series: Axis X.");
s1.axis_y.title = new Text("Series 1: Axis Y."); s1.axis_y.title = new Text("Series 1: Axis Y.");
@ -122,8 +122,8 @@ void plot_chart3 (Chart chart) {
s3.place.x_min = 0; s3.place.x_max = 0.5; s3.place.x_min = 0; s3.place.x_max = 0.5;
s3.place.y_min = 0.0; s3.place.y_max = 1.0; s3.place.y_min = 0.0; s3.place.y_max = 1.0;
s2.marker_type = Series.MarkerType.PRICLE_CIRCLE; s2.marker.type = Marker.Type.PRICLE_CIRCLE;
s3.marker_type = Series.MarkerType.TRIANGLE; s3.marker.type = Marker.Type.TRIANGLE;
s1.axis_x.title = new Text("Series 1: Axis X."); s1.axis_x.title = new Text("Series 1: Axis X.");
s1.axis_y.title = new Text("Series 1: Axis Y."); s1.axis_y.title = new Text("Series 1: Axis Y.");
@ -185,9 +185,9 @@ void plot_chart4 (Chart chart) {
s4.place.x_min = 0.2; s4.place.x_max = 1.0; s4.place.x_min = 0.2; s4.place.x_max = 1.0;
s4.place.y_min = 0.0; s4.place.y_max = 1.0; s4.place.y_min = 0.0; s4.place.y_max = 1.0;
s2.marker_type = Series.MarkerType.PRICLE_CIRCLE; s2.marker.type = Marker.Type.PRICLE_CIRCLE;
s3.marker_type = Series.MarkerType.TRIANGLE; s3.marker.type = Marker.Type.TRIANGLE;
s4.marker_type = Series.MarkerType.PRICLE_SQUARE; s4.marker.type = Marker.Type.PRICLE_SQUARE;
s1.axis_x.title = new Text("Series 1: Axis X."); s1.axis_x.title = new Text("Series 1: Axis X.");
s1.axis_y.title = new Text("Series 1: Axis Y."); s1.axis_y.title = new Text("Series 1: Axis Y.");