Cairo-Chart/src/Marker.vala

101 lines
2.0 KiB
Vala
Raw Normal View History

2018-01-10 11:32:51 +03:00
namespace CairoChart {
2018-01-21 15:36:08 +03:00
/**
* {@link Series} Marker.
*/
2018-01-10 11:32:51 +03:00
public class Marker {
2018-01-22 09:04:26 +03:00
Chart chart;
2018-01-21 15:41:04 +03:00
2018-01-21 15:36:08 +03:00
/**
* ``Marker`` shape.
*/
2018-01-10 12:58:35 +03:00
public enum Type {
2018-01-21 15:36:08 +03:00
NONE = 0,
2018-01-10 12:58:35 +03:00
SQUARE,
CIRCLE,
TRIANGLE,
PRICLE_SQUARE,
PRICLE_CIRCLE,
PRICLE_TRIANGLE
}
2018-01-21 15:36:08 +03:00
/**
* ``Marker`` shape.
*/
2018-01-22 09:06:24 +03:00
public Type type;
2018-01-21 15:36:08 +03:00
/**
* ``Marker`` size.
*/
2018-01-22 09:04:26 +03:00
public double size;
2018-01-10 12:58:35 +03:00
2018-01-21 15:36:08 +03:00
/**
* Constructs a new ``Marker``.
* @param type ``Marker`` shape.
* @param size ``Marker`` size.
*/
2018-01-21 15:41:04 +03:00
public Marker (Chart chart,
Type type = Type.NONE,
2018-01-19 20:34:08 +03:00
double size = 8.0
) {
2018-01-21 15:41:04 +03:00
this.chart = chart;
2018-01-10 12:58:35 +03:00
this.type = type;
this.size = size;
}
2018-01-21 15:36:08 +03:00
/**
* Gets a copy of the ``Marker``.
*/
2018-01-15 12:05:21 +03:00
public virtual Marker copy () {
2018-01-21 15:41:04 +03:00
return new Marker (chart, type, size);
2018-01-10 12:58:35 +03:00
}
2018-01-21 15:36:08 +03:00
/**
* Draws the ``Marker`` at specific position.
* @param x x-coordinate.
* @param y y-coordinate.
*/
2018-01-21 15:41:04 +03:00
public virtual void draw_at_pos (double x, double y) {
2018-01-17 10:36:10 +03:00
chart.ctx.move_to (x, y);
2018-01-10 12:58:35 +03:00
switch (type) {
case Type.SQUARE:
2018-01-17 10:36:10 +03:00
chart.ctx.rectangle (x - size / 2, y - size / 2, size, size);
chart.ctx.fill();
2018-01-10 11:32:51 +03:00
break;
2018-01-10 12:58:35 +03:00
case Type.CIRCLE:
2018-01-17 10:36:10 +03:00
chart.ctx.arc (x, y, size / 2, 0, 2 * GLib.Math.PI);
chart.ctx.fill();
2018-01-10 11:32:51 +03:00
break;
2018-01-10 12:58:35 +03:00
case Type.TRIANGLE:
2018-01-17 10:36:10 +03:00
chart.ctx.move_to (x - size / 2, y - size / 2);
2018-01-22 08:55:59 +03:00
chart.ctx.rel_line_to (size, 0);
chart.ctx.rel_line_to (-size / 2, size);
chart.ctx.rel_line_to (-size / 2, -size);
2018-01-17 10:36:10 +03:00
chart.ctx.fill();
2018-01-10 11:32:51 +03:00
break;
2018-01-10 12:58:35 +03:00
case Type.PRICLE_SQUARE:
2018-01-22 08:57:36 +03:00
chart.ctx.rectangle (x - size / 2, y - size / 2, size, size);
2018-01-17 10:36:10 +03:00
chart.ctx.stroke();
2018-01-10 11:32:51 +03:00
break;
2018-01-10 12:58:35 +03:00
case Type.PRICLE_CIRCLE:
2018-01-17 10:36:10 +03:00
chart.ctx.arc (x, y, size / 2, 0, 2 * GLib.Math.PI);
chart.ctx.stroke();
2018-01-10 11:32:51 +03:00
break;
2018-01-10 12:58:35 +03:00
case Type.PRICLE_TRIANGLE:
2018-01-17 10:36:10 +03:00
chart.ctx.move_to (x - size / 2, y - size / 2);
2018-01-22 08:57:36 +03:00
chart.ctx.rel_line_to (size, 0);
chart.ctx.rel_line_to (-size / 2, size);
chart.ctx.rel_line_to (-size / 2, -size);
2018-01-17 10:36:10 +03:00
chart.ctx.stroke();
2018-01-10 11:32:51 +03:00
break;
}
}
}
}