OK In progress...
This commit is contained in:
parent
5c8904d502
commit
545221c11f
|
@ -53,7 +53,7 @@ namespace CairoChart {
|
||||||
/**
|
/**
|
||||||
* Constructs a new ``Area``.
|
* Constructs a new ``Area``.
|
||||||
*/
|
*/
|
||||||
Area () { }
|
public Area () { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new ``Area`` with absolute coordinates.
|
* Constructs a new ``Area`` with absolute coordinates.
|
||||||
|
@ -62,7 +62,7 @@ namespace CairoChart {
|
||||||
* @param x1 right bound.
|
* @param x1 right bound.
|
||||||
* @param y1 bottom bound.
|
* @param y1 bottom bound.
|
||||||
*/
|
*/
|
||||||
Area.with_abs (double x0, double y0, double x1, double y1) {
|
public Area.with_abs (double x0, double y0, double x1, double y1) {
|
||||||
this.x0 = x0;
|
this.x0 = x0;
|
||||||
this.y0 = y0;
|
this.y0 = y0;
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
|
@ -76,7 +76,7 @@ namespace CairoChart {
|
||||||
* @param width ``Area`` width.
|
* @param width ``Area`` width.
|
||||||
* @param height ``Area`` height.
|
* @param height ``Area`` height.
|
||||||
*/
|
*/
|
||||||
Area.with_rel (double x0, double y0, double width, double height) {
|
public Area.with_rel (double x0, double y0, double width, double height) {
|
||||||
this.x0 = x0;
|
this.x0 = x0;
|
||||||
this.y0 = y0;
|
this.y0 = y0;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
|
@ -87,18 +87,18 @@ namespace CairoChart {
|
||||||
* Constructs a new ``Area`` by other ``Area``.
|
* Constructs a new ``Area`` by other ``Area``.
|
||||||
* @param area ``Area`` instance.
|
* @param area ``Area`` instance.
|
||||||
*/
|
*/
|
||||||
Area.with_area (Area area) {
|
public Area.with_area (Area area) {
|
||||||
this.x0 = area.x0;
|
this.x0 = area.x0;
|
||||||
this.y0 = area.y0;
|
this.y0 = area.y0;
|
||||||
this.x1 = area.x1;
|
this.x1 = area.x1;
|
||||||
this.y1 = area.y0;
|
this.y1 = area.y1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new ``Area`` by ``Cairo.Rectangle``.
|
* Constructs a new ``Area`` by ``Cairo.Rectangle``.
|
||||||
* @param rectangle ``Cairo.Rectangle`` instance.
|
* @param rectangle ``Cairo.Rectangle`` instance.
|
||||||
*/
|
*/
|
||||||
Area.with_rectangle (Cairo.Rectangle rectangle) {
|
public Area.with_rectangle (Cairo.Rectangle rectangle) {
|
||||||
this.x0 = rectangle.x;
|
this.x0 = rectangle.x;
|
||||||
this.y0 = rectangle.y;
|
this.y0 = rectangle.y;
|
||||||
this.width = rectangle.width;
|
this.width = rectangle.width;
|
||||||
|
|
101
src/Chart.vala
101
src/Chart.vala
|
@ -8,25 +8,22 @@ namespace CairoChart {
|
||||||
/**
|
/**
|
||||||
* ``Chart`` Position.
|
* ``Chart`` Position.
|
||||||
*/
|
*/
|
||||||
public Cairo.Rectangle area = Cairo.Rectangle();
|
public Area area = new Area();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current evaluated area.
|
* Current evaluated area.
|
||||||
*/
|
*/
|
||||||
public Cairo.Rectangle evarea = Cairo.Rectangle()
|
public Area evarea = new Area.with_abs(0, 0, 1, 1);
|
||||||
{ x = 0, y = 0, width = 1, height = 1 };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zoom area limits (relative coordinates: 0.0-1.0).
|
* Zoom area limits (relative coordinates: 0.0-1.0).
|
||||||
*/
|
*/
|
||||||
public Cairo.Rectangle zoom = Cairo.Rectangle()
|
public Area zoom = new Area.with_abs(0, 0, 1, 1);
|
||||||
{ x = 0, y = 0, width = 1, height = 1 };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plot area bounds.
|
* Plot area bounds.
|
||||||
*/
|
*/
|
||||||
public Cairo.Rectangle plarea = Cairo.Rectangle()
|
public Area plarea = new Area.with_abs(0, 0, 1, 1);
|
||||||
{ x = 0, y = 0, width = 1, height = 1 };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cairo ``Context`` of the Drawing Area.
|
* Cairo ``Context`` of the Drawing Area.
|
||||||
|
@ -109,21 +106,21 @@ namespace CairoChart {
|
||||||
*/
|
*/
|
||||||
public Chart copy () {
|
public Chart copy () {
|
||||||
var chart = new Chart ();
|
var chart = new Chart ();
|
||||||
chart.area = this.area;
|
chart.area = this.area.copy();
|
||||||
chart.bg_color = this.bg_color;
|
chart.bg_color = this.bg_color;
|
||||||
chart.border_color = this.border_color;
|
chart.border_color = this.border_color;
|
||||||
chart.ctx = this.ctx;
|
chart.ctx = this.ctx;
|
||||||
chart.cursors = this.cursors.copy();
|
chart.cursors = this.cursors.copy();
|
||||||
chart.evarea = this.evarea;
|
chart.evarea = this.evarea.copy();
|
||||||
chart.joint_color = this.joint_color;
|
chart.joint_color = this.joint_color;
|
||||||
chart.joint_x = this.joint_x;
|
chart.joint_x = this.joint_x;
|
||||||
chart.joint_y = this.joint_y;
|
chart.joint_y = this.joint_y;
|
||||||
chart.legend = this.legend.copy();
|
chart.legend = this.legend.copy();
|
||||||
chart.plarea = this.plarea;
|
chart.plarea = this.plarea.copy();
|
||||||
chart.selection_style = this.selection_style;
|
chart.selection_style = this.selection_style;
|
||||||
chart.series = this.series;
|
chart.series = this.series;
|
||||||
chart.title = this.title.copy();
|
chart.title = this.title.copy();
|
||||||
chart.zoom = this.zoom;
|
chart.zoom = this.zoom.copy();
|
||||||
chart.zoom_1st_idx = this.zoom_1st_idx;
|
chart.zoom_1st_idx = this.zoom_1st_idx;
|
||||||
return chart;
|
return chart;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +140,7 @@ namespace CairoChart {
|
||||||
*/
|
*/
|
||||||
public virtual bool draw () {
|
public virtual bool draw () {
|
||||||
|
|
||||||
evarea = area;
|
evarea = area.copy();
|
||||||
|
|
||||||
draw_title ();
|
draw_title ();
|
||||||
fix_evarea ();
|
fix_evarea ();
|
||||||
|
@ -177,26 +174,26 @@ namespace CairoChart {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws selection with a {@link selection_style} line style.
|
* Draws selection with a {@link selection_style} line style.
|
||||||
* @param rect selection square.
|
* @param area selection area.
|
||||||
*/
|
*/
|
||||||
public virtual void draw_selection (Cairo.Rectangle rect) {
|
public virtual void draw_selection (Area area) {
|
||||||
selection_style.apply(this);
|
selection_style.apply(this);
|
||||||
ctx.rectangle (rect.x, rect.y, rect.width, rect.height);
|
ctx.rectangle (area.x0, area.y0, area.width, area.height);
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zooms the ``Chart``.
|
* Zooms the ``Chart``.
|
||||||
* @param rect selected zoom area.
|
* @param area selected zoom area.
|
||||||
*/
|
*/
|
||||||
public virtual void zoom_in (Cairo.Rectangle rect) {
|
public virtual void zoom_in (Area area) {
|
||||||
foreach (var s in series) {
|
foreach (var s in series) {
|
||||||
if (!s.zoom_show) continue;
|
if (!s.zoom_show) continue;
|
||||||
var real_x0 = s.get_real_x (rect.x);
|
var real_x0 = s.get_real_x (area.x0);
|
||||||
var real_x1 = s.get_real_x (rect.x + rect.width);
|
var real_x1 = s.get_real_x (area.x1);
|
||||||
var real_width = real_x1 - real_x0;
|
var real_width = real_x1 - real_x0;
|
||||||
var real_y0 = s.get_real_y (rect.y);
|
var real_y0 = s.get_real_y (area.y0);
|
||||||
var real_y1 = s.get_real_y (rect.y + rect.height);
|
var real_y1 = s.get_real_y (area.y1);
|
||||||
var real_height = real_y0 - real_y1;
|
var real_height = real_y0 - real_y1;
|
||||||
// if selected square does not intersect with the series's square
|
// 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
|
if ( real_x1 <= s.axis_x.zoom_min || real_x0 >= s.axis_x.zoom_max
|
||||||
|
@ -236,18 +233,18 @@ namespace CairoChart {
|
||||||
zoom_1st_idx = si;
|
zoom_1st_idx = si;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var new_zoom = zoom;
|
var new_zoom = zoom.copy();
|
||||||
var rmpx = rect.x - plarea.x;
|
var rmpx = area.x0 - plarea.x0;
|
||||||
var zdpw = zoom.width / plarea.width;
|
var zdpw = zoom.width / plarea.width;
|
||||||
new_zoom.x += rmpx * zdpw;
|
new_zoom.x0 += rmpx * zdpw;
|
||||||
var x_max = zoom.x + (rmpx + rect.width) * zdpw;
|
var x_max = zoom.x0 + (rmpx + area.width) * zdpw;
|
||||||
new_zoom.width = x_max - new_zoom.x;
|
new_zoom.width = x_max - new_zoom.x0;
|
||||||
var rmpy = rect.y - plarea.y;
|
var rmpy = area.y0 - plarea.y0;
|
||||||
var zdph = zoom.height / plarea.height;
|
var zdph = zoom.height / plarea.height;
|
||||||
new_zoom.y += rmpy * zdph;
|
new_zoom.y0 += rmpy * zdph;
|
||||||
var y_max = zoom.y + (rmpy + rect.height) * zdph;
|
var y_max = zoom.y0 + (rmpy + area.height) * zdph;
|
||||||
new_zoom.height = y_max - new_zoom.y;
|
new_zoom.height = y_max - new_zoom.y0;
|
||||||
zoom = new_zoom;
|
zoom = new_zoom.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -255,7 +252,7 @@ namespace CairoChart {
|
||||||
*/
|
*/
|
||||||
public virtual void zoom_out () {
|
public virtual void zoom_out () {
|
||||||
foreach (var s in series) s.unzoom();
|
foreach (var s in series) s.unzoom();
|
||||||
zoom = Cairo.Rectangle() { x = 0, y = 0, width = 1, height = 1 };
|
zoom = new Area.with_abs (0, 0, 1, 1);
|
||||||
zoom_1st_idx = 0;
|
zoom_1st_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,33 +265,35 @@ namespace CairoChart {
|
||||||
|
|
||||||
d.x /= -plarea.width; d.y /= -plarea.height;
|
d.x /= -plarea.width; d.y /= -plarea.height;
|
||||||
|
|
||||||
var z = zoom;
|
var z = zoom.copy();
|
||||||
|
|
||||||
zoom_out();
|
zoom_out();
|
||||||
|
|
||||||
d.x *= plarea.width; d.y *= plarea.height;
|
d.x *= plarea.width; d.y *= plarea.height;
|
||||||
|
|
||||||
var x0 = plarea.x + plarea.width * z.x;
|
var x0 = plarea.x0 + plarea.width * z.x0;
|
||||||
var x1 = plarea.x + plarea.width * (z.x + z.width);
|
var x1 = plarea.x0 + plarea.width * z.x1;
|
||||||
var y0 = plarea.y + plarea.height * z.y;
|
var y0 = plarea.y0 + plarea.height * z.y0;
|
||||||
var y1 = plarea.y + plarea.height * (z.y + z.height);
|
var y1 = plarea.y0 + plarea.height * z.y1;
|
||||||
|
|
||||||
d.x *= z.width; d.y *= z.height;
|
d.x *= z.width; d.y *= z.height;
|
||||||
|
|
||||||
var px1 = plarea.x + plarea.width;
|
var px1 = plarea.x1;
|
||||||
var py1 = plarea.y + plarea.height;
|
var py1 = plarea.y1;
|
||||||
|
|
||||||
if (x0 + d.x < plarea.x) d.x = plarea.x - x0;
|
if (x0 + d.x < plarea.x0) d.x = plarea.x0 - x0;
|
||||||
if (x1 + d.x > px1) d.x = px1 - x1;
|
if (x1 + d.x > px1) d.x = px1 - x1;
|
||||||
if (y0 + d.y < plarea.y) d.y = plarea.y - y0;
|
if (y0 + d.y < plarea.y0) d.y = plarea.y0 - y0;
|
||||||
if (y1 + d.y > py1) d.y = py1 - y1;
|
if (y1 + d.y > py1) d.y = py1 - y1;
|
||||||
|
|
||||||
zoom_in(Cairo.Rectangle() {
|
zoom_in(
|
||||||
x = x0 + d.x,
|
new Area.with_rel(
|
||||||
y = y0 + d.y,
|
x0 + d.x,
|
||||||
width = plarea.width * z.width,
|
y0 + d.y,
|
||||||
height = plarea.height * z.height
|
plarea.width * z.width,
|
||||||
});
|
plarea.height * z.height
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void fix_evarea () {
|
protected virtual void fix_evarea () {
|
||||||
|
@ -307,9 +306,9 @@ namespace CairoChart {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void eval_plarea () {
|
protected virtual void eval_plarea () {
|
||||||
plarea.x = evarea.x + legend.spacing;
|
plarea.x0 = evarea.x0 + legend.spacing;
|
||||||
plarea.width = evarea.width - 2 * legend.spacing;
|
plarea.width = evarea.width - 2 * legend.spacing;
|
||||||
plarea.y = evarea.y + legend.spacing;
|
plarea.y0 = evarea.y0 + legend.spacing;
|
||||||
plarea.height = evarea.height - 2 * legend.spacing;
|
plarea.height = evarea.height - 2 * legend.spacing;
|
||||||
|
|
||||||
// Check for joint axes
|
// Check for joint axes
|
||||||
|
@ -333,13 +332,13 @@ namespace CairoChart {
|
||||||
protected virtual void draw_plarea_border () {
|
protected virtual void draw_plarea_border () {
|
||||||
color = border_color;
|
color = border_color;
|
||||||
ctx.set_dash(null, 0);
|
ctx.set_dash(null, 0);
|
||||||
ctx.rectangle(plarea.x, plarea.y, plarea.width, plarea.height);
|
ctx.rectangle(plarea.x0, plarea.y0, plarea.width, plarea.height);
|
||||||
ctx.stroke ();
|
ctx.stroke ();
|
||||||
}
|
}
|
||||||
protected virtual void draw_title () {
|
protected virtual void draw_title () {
|
||||||
var sz = title.get_size(ctx);
|
var sz = title.get_size(ctx);
|
||||||
var title_height = sz.height + title.vspacing * 2;
|
var title_height = sz.height + title.vspacing * 2;
|
||||||
evarea.y += title_height;
|
evarea.y0 += title_height;
|
||||||
evarea.height -= title_height;
|
evarea.height -= title_height;
|
||||||
color = title.color;
|
color = title.color;
|
||||||
ctx.move_to (area.width/2 - sz.width/2, sz.height + title.vspacing);
|
ctx.move_to (area.width/2 - sz.width/2, sz.height + title.vspacing);
|
||||||
|
|
|
@ -58,8 +58,8 @@ namespace CairoChart {
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void set_active_cursor (Point p, bool remove = false) {
|
public virtual void set_active_cursor (Point p, bool remove = false) {
|
||||||
active_cursor.x = chart.zoom.x + (p.x - chart.plarea.x) / chart.plarea.width * chart.zoom.width;
|
active_cursor.x = chart.zoom.x0 + (p.x - chart.plarea.x0) / chart.plarea.width * chart.zoom.width;
|
||||||
active_cursor.y = chart.zoom.y + chart.zoom.height - (chart.plarea.y + chart.plarea.height - p.y) / chart.plarea.height * chart.zoom.height;
|
active_cursor.y = chart.zoom.y1 - (chart.plarea.y1 - p.y) / chart.plarea.height * chart.zoom.height;
|
||||||
is_cursor_active = ! remove;
|
is_cursor_active = ! remove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,11 +69,11 @@ namespace CairoChart {
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Float128 rel2scr_x(Float128 x) {
|
public virtual Float128 rel2scr_x(Float128 x) {
|
||||||
return chart.plarea.x + chart.plarea.width * (x - chart.zoom.x) / chart.zoom.width;
|
return chart.plarea.x0 + chart.plarea.width * (x - chart.zoom.x0) / chart.zoom.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Float128 rel2scr_y(Float128 y) {
|
public virtual Float128 rel2scr_y(Float128 y) {
|
||||||
return chart.plarea.y + chart.plarea.height * (y - chart.zoom.y) / chart.zoom.height;
|
return chart.plarea.y0 + chart.plarea.height * (y - chart.zoom.y0) / chart.zoom.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void remove_active_cursor () {
|
public virtual void remove_active_cursor () {
|
||||||
|
@ -84,12 +84,8 @@ namespace CairoChart {
|
||||||
foreach (var c in list) {
|
foreach (var c in list) {
|
||||||
double d = distance;
|
double d = distance;
|
||||||
switch (cursor_style.orientation) {
|
switch (cursor_style.orientation) {
|
||||||
case Cursors.Orientation.VERTICAL:
|
case Cursors.Orientation.VERTICAL: d = (rel2scr_x(c.x) - rel2scr_x(active_cursor.x)).abs(); break;
|
||||||
d = (rel2scr_x(c.x) - rel2scr_x(active_cursor.x)).abs();
|
case Cursors.Orientation.HORIZONTAL: d = (rel2scr_y(c.y) - rel2scr_y(active_cursor.y)).abs(); break;
|
||||||
break;
|
|
||||||
case Cursors.Orientation.HORIZONTAL:
|
|
||||||
d = (rel2scr_y(c.y) - rel2scr_y(active_cursor.y)).abs();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (d < distance) {
|
if (d < distance) {
|
||||||
distance = d;
|
distance = d;
|
||||||
|
@ -117,10 +113,8 @@ namespace CairoChart {
|
||||||
for (var ci = 0, max_ci = all_cursors.length(); ci < max_ci; ++ci) {
|
for (var ci = 0, max_ci = all_cursors.length(); ci < max_ci; ++ci) {
|
||||||
var c = all_cursors.nth_data(ci);
|
var c = all_cursors.nth_data(ci);
|
||||||
switch (cursor_style.orientation) {
|
switch (cursor_style.orientation) {
|
||||||
case Orientation.VERTICAL:
|
case Orientation.VERTICAL: if (c.x <= chart.zoom.x0 || c.x >= chart.zoom.x1) continue; break;
|
||||||
if (c.x <= chart.zoom.x || c.x >= chart.zoom.x + chart.zoom.width) continue; break;
|
case Orientation.HORIZONTAL: if (c.y <= chart.zoom.y0 || c.y >= chart.zoom.y1) continue; break;
|
||||||
case Orientation.HORIZONTAL:
|
|
||||||
if (c.y <= chart.zoom.y || c.y >= chart.zoom.y + chart.zoom.height) continue; break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CursorCross[] crossings = {};
|
CursorCross[] crossings = {};
|
||||||
|
@ -128,22 +122,14 @@ namespace CairoChart {
|
||||||
var s = chart.series[si];
|
var s = chart.series[si];
|
||||||
if (!s.zoom_show) continue;
|
if (!s.zoom_show) continue;
|
||||||
|
|
||||||
Point128[] points = {};
|
var points = Math.sort_points (s, s.sort);
|
||||||
switch (cursor_style.orientation) {
|
|
||||||
case Orientation.VERTICAL:
|
|
||||||
points = Math.sort_points (s, s.sort);
|
|
||||||
break;
|
|
||||||
case Orientation.HORIZONTAL:
|
|
||||||
points = Math.sort_points (s, s.sort);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i + 1 < points.length; ++i) {
|
for (var i = 0; i + 1 < points.length; ++i) {
|
||||||
switch (cursor_style.orientation) {
|
switch (cursor_style.orientation) {
|
||||||
case Orientation.VERTICAL:
|
case Orientation.VERTICAL:
|
||||||
Float128 y = 0.0;
|
Float128 y = 0.0;
|
||||||
if (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)) {
|
chart.plarea.y0, chart.plarea.y1, out y)) {
|
||||||
var point = Point128(s.get_real_x(rel2scr_x(c.x)), s.get_real_y(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;
|
Point128 size; bool show_x, show_date, show_time, show_y;
|
||||||
cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y);
|
cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y);
|
||||||
|
@ -155,7 +141,7 @@ namespace CairoChart {
|
||||||
case Orientation.HORIZONTAL:
|
case Orientation.HORIZONTAL:
|
||||||
Float128 x = 0.0;
|
Float128 x = 0.0;
|
||||||
if (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)) {
|
chart.plarea.x0, chart.plarea.x1, rel2scr_y(c.y), out x)) {
|
||||||
var point = Point128(s.get_real_x(x), s.get_real_y(rel2scr_y(c.y)));
|
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;
|
Point128 size; bool show_x, show_date, show_time, show_y;
|
||||||
cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y);
|
cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y);
|
||||||
|
@ -244,8 +230,8 @@ namespace CairoChart {
|
||||||
calc_cursors_value_positions();
|
calc_cursors_value_positions();
|
||||||
|
|
||||||
for (var cci = 0, max_cci = cursors_crossings.length; cci < max_cci; ++cci) {
|
for (var cci = 0, max_cci = cursors_crossings.length; cci < max_cci; ++cci) {
|
||||||
var low = Point128(chart.plarea.x + chart.plarea.width, chart.plarea.y + chart.plarea.height); // low and high
|
var low = Point128(chart.plarea.x1, chart.plarea.y1); // low and high
|
||||||
var high = Point128(chart.plarea.x, chart.plarea.y); // points of the cursor
|
var high = Point128(chart.plarea.x0, chart.plarea.y0); // points of the cursor
|
||||||
unowned CursorCross[] ccs = cursors_crossings[cci].crossings;
|
unowned CursorCross[] ccs = cursors_crossings[cci].crossings;
|
||||||
cursor_style.line_style.apply(chart);
|
cursor_style.line_style.apply(chart);
|
||||||
for (var ci = 0, max_ci = ccs.length; ci < max_ci; ++ci) {
|
for (var ci = 0, max_ci = ccs.length; ci < max_ci; ++ci) {
|
||||||
|
@ -261,21 +247,21 @@ namespace CairoChart {
|
||||||
|
|
||||||
if (chart.joint_x) {
|
if (chart.joint_x) {
|
||||||
switch (s.axis_x.position) {
|
switch (s.axis_x.position) {
|
||||||
case Axis.Position.LOW: high.y = chart.plarea.y + chart.plarea.height + s.axis_x.font_spacing; break;
|
case Axis.Position.LOW: high.y = chart.plarea.y1 + s.axis_x.font_spacing; break;
|
||||||
case Axis.Position.HIGH: low.y = chart.plarea.y - s.axis_x.font_spacing; break;
|
case Axis.Position.HIGH: low.y = chart.plarea.y0 - s.axis_x.font_spacing; break;
|
||||||
case Axis.Position.BOTH:
|
case Axis.Position.BOTH:
|
||||||
high.y = chart.plarea.y + chart.plarea.height + s.axis_x.font_spacing;
|
high.y = chart.plarea.y1 + s.axis_x.font_spacing;
|
||||||
low.y = chart.plarea.y - s.axis_x.font_spacing;
|
low.y = chart.plarea.y0 - s.axis_x.font_spacing;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (chart.joint_y) {
|
if (chart.joint_y) {
|
||||||
switch (s.axis_y.position) {
|
switch (s.axis_y.position) {
|
||||||
case Axis.Position.LOW: low.x = chart.plarea.x - s.axis_y.font_spacing; break;
|
case Axis.Position.LOW: low.x = chart.plarea.x0 - s.axis_y.font_spacing; break;
|
||||||
case Axis.Position.HIGH: high.x = chart.plarea.x + chart.plarea.width + s.axis_y.font_spacing; break;
|
case Axis.Position.HIGH: high.x = chart.plarea.x1 + s.axis_y.font_spacing; break;
|
||||||
case Axis.Position.BOTH:
|
case Axis.Position.BOTH:
|
||||||
low.x = chart.plarea.x - s.axis_y.font_spacing;
|
low.x = chart.plarea.x0 - s.axis_y.font_spacing;
|
||||||
high.x = chart.plarea.x + chart.plarea.width + s.axis_y.font_spacing;
|
high.x = chart.plarea.x1 + s.axis_y.font_spacing;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,27 +284,21 @@ namespace CairoChart {
|
||||||
var x = s.get_real_x(rel2scr_x(c.x));
|
var x = s.get_real_x(rel2scr_x(c.x));
|
||||||
string text = "", time_text = "";
|
string text = "", time_text = "";
|
||||||
switch (s.axis_x.type) {
|
switch (s.axis_x.type) {
|
||||||
case Axis.Type.NUMBERS:
|
case Axis.Type.NUMBERS: text = s.axis_x.format.printf((LongDouble)x); break;
|
||||||
text = s.axis_x.format.printf((LongDouble)x);
|
case Axis.Type.DATE_TIME: s.axis_x.format_date_time(x, out text, out time_text); break;
|
||||||
break;
|
|
||||||
case Axis.Type.DATE_TIME:
|
|
||||||
s.axis_x.format_date_time(x, out text, out time_text);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
var text_t = new Text(text, s.axis_x.font_style, s.axis_x.color);
|
var text_t = new Text(text, s.axis_x.font_style, s.axis_x.color);
|
||||||
var sz = text_t.get_size(chart.ctx);
|
var sz = text_t.get_size(chart.ctx);
|
||||||
var time_text_t = new Text(time_text, s.axis_x.font_style, s.axis_x.color);
|
var time_text_t = new Text(time_text, s.axis_x.font_style, s.axis_x.color);
|
||||||
var print_y = 0.0;
|
var print_y = 0.0;
|
||||||
switch (s.axis_x.position) {
|
switch (s.axis_x.position) {
|
||||||
case Axis.Position.LOW: print_y = chart.area.y + chart.area.height - s.axis_x.font_spacing
|
case Axis.Position.LOW: print_y = chart.area.y1 - s.axis_x.font_spacing
|
||||||
- (chart.legend.position == Legend.Position.BOTTOM ? chart.legend.height : 0);
|
- (chart.legend.position == Legend.Position.BOTTOM ? chart.legend.height : 0);
|
||||||
break;
|
break;
|
||||||
case Axis.Position.HIGH:
|
case Axis.Position.HIGH:
|
||||||
var title_height = chart.title.get_height(chart.ctx) + (chart.legend.position == Legend.Position.TOP ?
|
var title_height = chart.title.get_height(chart.ctx) + (chart.legend.position == Legend.Position.TOP ?
|
||||||
chart.title.vspacing * 2 : chart.title.vspacing);
|
chart.title.vspacing * 2 : chart.title.vspacing);
|
||||||
print_y = chart.area.y + title_height + s.axis_x.font_spacing
|
print_y = chart.area.y0 + title_height + s.axis_x.font_spacing
|
||||||
+ (chart.legend.position == Legend.Position.TOP ? chart.legend.height : 0);
|
+ (chart.legend.position == Legend.Position.TOP ? chart.legend.height : 0);
|
||||||
switch (s.axis_x.type) {
|
switch (s.axis_x.type) {
|
||||||
case Axis.Type.NUMBERS:
|
case Axis.Type.NUMBERS:
|
||||||
|
@ -362,11 +342,11 @@ namespace CairoChart {
|
||||||
var print_x = 0.0;
|
var print_x = 0.0;
|
||||||
switch (s.axis_y.position) {
|
switch (s.axis_y.position) {
|
||||||
case Axis.Position.LOW:
|
case Axis.Position.LOW:
|
||||||
print_x = chart.area.x + s.axis_y.font_spacing
|
print_x = chart.area.x0 + s.axis_y.font_spacing
|
||||||
+ (chart.legend.position == Legend.Position.LEFT ? chart.legend.width : 0);
|
+ (chart.legend.position == Legend.Position.LEFT ? chart.legend.width : 0);
|
||||||
break;
|
break;
|
||||||
case Axis.Position.HIGH:
|
case Axis.Position.HIGH:
|
||||||
print_x = chart.area.x + chart.area.width - text_t.get_width(chart.ctx) - s.axis_y.font_spacing
|
print_x = chart.area.x1 - text_t.get_width(chart.ctx) - s.axis_y.font_spacing
|
||||||
- (chart.legend.position == Legend.Position.RIGHT ? chart.legend.width : 0);
|
- (chart.legend.position == Legend.Position.RIGHT ? chart.legend.width : 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,20 +202,10 @@ namespace CairoChart {
|
||||||
case ProcessType.CALC:
|
case ProcessType.CALC:
|
||||||
height = leg_height_sum;
|
height = leg_height_sum;
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case Position.TOP:
|
case Position.TOP: chart.evarea.y0 += height; break;
|
||||||
chart.evarea.y += height;
|
case Position.BOTTOM: chart.evarea.y1 -= height; break;
|
||||||
chart.evarea.height -= height;
|
case Position.LEFT: chart.evarea.x0 += width; break;
|
||||||
break;
|
case Position.RIGHT: chart.evarea.x1 -= width; break;
|
||||||
case Position.BOTTOM:
|
|
||||||
chart.evarea.height -= height;
|
|
||||||
break;
|
|
||||||
case Position.LEFT:
|
|
||||||
chart.evarea.x += width;
|
|
||||||
chart.evarea.width -= width;
|
|
||||||
break;
|
|
||||||
case Position.RIGHT:
|
|
||||||
chart.evarea.width -= width;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,12 +31,12 @@ namespace CairoChart {
|
||||||
/**
|
/**
|
||||||
* Constructs a new ``Range``.
|
* Constructs a new ``Range``.
|
||||||
*/
|
*/
|
||||||
Range () { }
|
public Range () { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new ``Range`` with a ``Range`` instance.
|
* Constructs a new ``Range`` with a ``Range`` instance.
|
||||||
*/
|
*/
|
||||||
Range.with_range (Range range) {
|
public Range.with_range (Range range) {
|
||||||
this.low = range.low;
|
this.low = range.low;
|
||||||
this.high = range.high;
|
this.high = range.high;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ namespace CairoChart {
|
||||||
/**
|
/**
|
||||||
* Constructs a new ``Range`` with absolute coordinates.
|
* Constructs a new ``Range`` with absolute coordinates.
|
||||||
*/
|
*/
|
||||||
Range.with_abs (double low, double high) {
|
public Range.with_abs (double low, double high) {
|
||||||
this.low = low;
|
this.low = low;
|
||||||
this.high = high;
|
this.high = high;
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,9 @@ namespace CairoChart {
|
||||||
/**
|
/**
|
||||||
* Constructs a new ``Range`` with relative coordinates.
|
* Constructs a new ``Range`` with relative coordinates.
|
||||||
*/
|
*/
|
||||||
Range.with_rel (double low, double range) {
|
public Range.with_rel (double low, double range) {
|
||||||
this.low = low;
|
this.low = low;
|
||||||
this.high = low + range;
|
this.range = range;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
153
src/Series.vala
153
src/Series.vala
|
@ -70,8 +70,8 @@ namespace CairoChart {
|
||||||
for (int i = 1; i < points.length; ++i) {
|
for (int i = 1; i < points.length; ++i) {
|
||||||
Point c, d;
|
Point c, d;
|
||||||
if (Math.cut_line (
|
if (Math.cut_line (
|
||||||
Point(chart.plarea.x, chart.plarea.y),
|
Point(chart.plarea.x0, chart.plarea.y0),
|
||||||
Point(chart.plarea.x + chart.plarea.width, chart.plarea.y + chart.plarea.height),
|
Point(chart.plarea.x1, chart.plarea.y1),
|
||||||
Point(get_scr_x(points[i - 1].x), get_scr_y(points[i - 1].y)),
|
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)),
|
Point(get_scr_x(points[i].x), get_scr_y(points[i].y)),
|
||||||
out c, out d)
|
out c, out d)
|
||||||
|
@ -84,8 +84,8 @@ namespace CairoChart {
|
||||||
for (int i = 0; i < points.length; ++i) {
|
for (int i = 0; i < points.length; ++i) {
|
||||||
var x = get_scr_x(points[i].x);
|
var x = get_scr_x(points[i].x);
|
||||||
var y = get_scr_y(points[i].y);
|
var y = get_scr_y(points[i].y);
|
||||||
if (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.x0, chart.plarea.x1,
|
||||||
chart.plarea.y, chart.plarea.y + chart.plarea.height))
|
chart.plarea.y0, chart.plarea.y1))
|
||||||
marker.draw_at_pos(chart, x, y);
|
marker.draw_at_pos(chart, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,42 +135,38 @@ namespace CairoChart {
|
||||||
if (si == chart.zoom_1st_idx && chart.cursors.cursors_crossings.length != 0) {
|
if (si == chart.zoom_1st_idx && chart.cursors.cursors_crossings.length != 0) {
|
||||||
switch (chart.cursors.cursor_style.orientation) {
|
switch (chart.cursors.cursor_style.orientation) {
|
||||||
case Cursors.Orientation.VERTICAL:
|
case Cursors.Orientation.VERTICAL:
|
||||||
if (is_x && chart.joint_x)
|
if (is_x && chart.joint_x) {
|
||||||
switch (axis.position) {
|
|
||||||
case Axis.Position.LOW: chart.plarea.height -= max_rec_height + axis.font_spacing; break;
|
|
||||||
case Axis.Position.HIGH:
|
|
||||||
var tmp = max_rec_height + axis.font_spacing;
|
var tmp = max_rec_height + axis.font_spacing;
|
||||||
chart.plarea.y += tmp; chart.plarea.height -= tmp;
|
switch (axis.position) {
|
||||||
break;
|
case Axis.Position.LOW: chart.plarea.y1 -= tmp; break;
|
||||||
|
case Axis.Position.HIGH: chart.plarea.y0 += tmp; break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Cursors.Orientation.HORIZONTAL:
|
case Cursors.Orientation.HORIZONTAL:
|
||||||
if (!is_x && chart.joint_y)
|
if (!is_x && chart.joint_y) {
|
||||||
switch (s.axis_y.position) {
|
|
||||||
case Axis.Position.LOW:
|
|
||||||
var tmp = max_rec_width + s.axis_y.font_spacing;
|
var tmp = max_rec_width + s.axis_y.font_spacing;
|
||||||
chart.plarea.x += tmp; chart.plarea.width -= tmp;
|
|
||||||
break;
|
|
||||||
case Axis.Position.HIGH: chart.plarea.width -= max_rec_width + s.axis_y.font_spacing; break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is_x && (!chart.joint_x || si == chart.zoom_1st_idx))
|
|
||||||
switch (axis.position) {
|
|
||||||
case Axis.Position.LOW: chart.plarea.height -= max_rec_height + max_font_spacing + max_axis_font_height; break;
|
|
||||||
case Axis.Position.HIGH:
|
|
||||||
var tmp = max_rec_height + max_font_spacing + max_axis_font_height;
|
|
||||||
chart.plarea.y += tmp; chart.plarea.height -= tmp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!is_x && (!chart.joint_y || si == chart.zoom_1st_idx))
|
|
||||||
switch (s.axis_y.position) {
|
switch (s.axis_y.position) {
|
||||||
case Axis.Position.LOW:
|
case Axis.Position.LOW: chart.plarea.x0 += tmp; break;
|
||||||
var tmp = max_rec_width + max_font_spacing + max_axis_font_width;
|
case Axis.Position.HIGH: chart.plarea.x1 -= tmp; break;
|
||||||
chart.plarea.x += tmp; chart.plarea.width -= tmp;
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Axis.Position.HIGH: chart.plarea.width -= max_rec_width + max_font_spacing + max_axis_font_width; break;
|
}
|
||||||
|
}
|
||||||
|
if (is_x && (!chart.joint_x || si == chart.zoom_1st_idx)) {
|
||||||
|
var tmp = max_rec_height + max_font_spacing + max_axis_font_height;
|
||||||
|
switch (axis.position) {
|
||||||
|
case Axis.Position.LOW: chart.plarea.y1 -= tmp; break;
|
||||||
|
case Axis.Position.HIGH: chart.plarea.y0 += tmp; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!is_x && (!chart.joint_y || si == chart.zoom_1st_idx)) {
|
||||||
|
var tmp = max_rec_width + max_font_spacing + max_axis_font_width;
|
||||||
|
switch (s.axis_y.position) {
|
||||||
|
case Axis.Position.LOW: chart.plarea.x0 += tmp; break;
|
||||||
|
case Axis.Position.HIGH: chart.plarea.x1 -= tmp; break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,12 +254,8 @@ namespace CairoChart {
|
||||||
else chart.color = axis_x.color;
|
else chart.color = axis_x.color;
|
||||||
string text = "", time_text = "";
|
string text = "", time_text = "";
|
||||||
switch (axis_x.type) {
|
switch (axis_x.type) {
|
||||||
case Axis.Type.NUMBERS:
|
case Axis.Type.NUMBERS: text = axis_x.format.printf((LongDouble)x); break;
|
||||||
text = axis_x.format.printf((LongDouble)x);
|
case Axis.Type.DATE_TIME: axis_x.format_date_time(x, out text, out time_text); break;
|
||||||
break;
|
|
||||||
case Axis.Type.DATE_TIME:
|
|
||||||
axis_x.format_date_time(x, out text, out time_text);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
var scr_x = get_scr_x (x);
|
var scr_x = get_scr_x (x);
|
||||||
var text_t = new Text(text, axis_x.font_style, axis_x.color);
|
var text_t = new Text(text, axis_x.font_style, axis_x.color);
|
||||||
|
@ -271,7 +263,7 @@ namespace CairoChart {
|
||||||
|
|
||||||
switch (axis_x.position) {
|
switch (axis_x.position) {
|
||||||
case Axis.Position.LOW:
|
case Axis.Position.LOW:
|
||||||
var print_y = chart.evarea.y + chart.evarea.height - axis_x.font_spacing - (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_spacing);
|
var print_y = chart.evarea.y1 - axis_x.font_spacing - (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_spacing);
|
||||||
var print_x = compact_rec_x_pos (x, text_t);
|
var print_x = compact_rec_x_pos (x, text_t);
|
||||||
ctx.move_to (print_x, print_y);
|
ctx.move_to (print_x, print_y);
|
||||||
switch (axis_x.type) {
|
switch (axis_x.type) {
|
||||||
|
@ -290,15 +282,15 @@ namespace CairoChart {
|
||||||
var line_style = grid.line_style;
|
var line_style = grid.line_style;
|
||||||
if (joint_x) line_style.color = Color(0, 0, 0, 0.5);
|
if (joint_x) line_style.color = Color(0, 0, 0, 0.5);
|
||||||
line_style.apply(chart);
|
line_style.apply(chart);
|
||||||
double y = chart.evarea.y + chart.evarea.height - max_rec_height - axis_x.font_spacing - (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_spacing);
|
double y = chart.evarea.y1 - max_rec_height - axis_x.font_spacing - (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_spacing);
|
||||||
ctx.move_to (scr_x, y);
|
ctx.move_to (scr_x, y);
|
||||||
if (joint_x)
|
if (joint_x)
|
||||||
ctx.line_to (scr_x, chart.plarea.y);
|
ctx.line_to (scr_x, chart.plarea.y0);
|
||||||
else
|
else
|
||||||
ctx.line_to (scr_x, double.min (y, chart.plarea.y + chart.plarea.height * (1.0 - place.zoom_y_max)));
|
ctx.line_to (scr_x, double.min (y, chart.plarea.y0 + chart.plarea.height * (1.0 - place.zoom_y_max)));
|
||||||
break;
|
break;
|
||||||
case Axis.Position.HIGH:
|
case Axis.Position.HIGH:
|
||||||
var print_y = chart.evarea.y + max_rec_height + axis_x.font_spacing + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_spacing);
|
var print_y = chart.evarea.y0 + max_rec_height + axis_x.font_spacing + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_spacing);
|
||||||
var print_x = compact_rec_x_pos (x, text_t);
|
var print_x = compact_rec_x_pos (x, text_t);
|
||||||
ctx.move_to (print_x, print_y);
|
ctx.move_to (print_x, print_y);
|
||||||
|
|
||||||
|
@ -318,12 +310,12 @@ namespace CairoChart {
|
||||||
var line_style = grid.line_style;
|
var line_style = grid.line_style;
|
||||||
if (joint_x) line_style.color = Color(0, 0, 0, 0.5);
|
if (joint_x) line_style.color = Color(0, 0, 0, 0.5);
|
||||||
line_style.apply(chart);
|
line_style.apply(chart);
|
||||||
double y = chart.evarea.y + max_rec_height + axis_x.font_spacing + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_spacing);
|
double y = chart.evarea.y0 + max_rec_height + axis_x.font_spacing + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_spacing);
|
||||||
ctx.move_to (scr_x, y);
|
ctx.move_to (scr_x, y);
|
||||||
if (joint_x)
|
if (joint_x)
|
||||||
ctx.line_to (scr_x, chart.plarea.y + chart.plarea.height);
|
ctx.line_to (scr_x, chart.plarea.y1);
|
||||||
else
|
else
|
||||||
ctx.line_to (scr_x, double.max (y, chart.plarea.y + chart.plarea.height * (1.0 - place.zoom_y_min)));
|
ctx.line_to (scr_x, double.max (y, chart.plarea.y0 + chart.plarea.height * (1.0 - place.zoom_y_min)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,9 +352,10 @@ namespace CairoChart {
|
||||||
|
|
||||||
// 4.2. Cursor values for joint X axis
|
// 4.2. Cursor values for joint X axis
|
||||||
if (chart.joint_x && chart.cursors.cursor_style.orientation == Cursors.Orientation.VERTICAL && chart.cursors.cursors_crossings.length != 0) {
|
if (chart.joint_x && chart.cursors.cursor_style.orientation == Cursors.Orientation.VERTICAL && chart.cursors.cursors_crossings.length != 0) {
|
||||||
|
var tmp = max_rec_height + s.axis_x.font_spacing;
|
||||||
switch (s.axis_x.position) {
|
switch (s.axis_x.position) {
|
||||||
case Axis.Position.LOW: chart.evarea.height -= max_rec_height + s.axis_x.font_spacing; break;
|
case Axis.Position.LOW: chart.evarea.y1 -= tmp; break;
|
||||||
case Axis.Position.HIGH: var tmp = max_rec_height + s.axis_x.font_spacing; chart.evarea.y += tmp; chart.evarea.height -= tmp; break;
|
case Axis.Position.HIGH: chart.evarea.y0 += tmp; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,11 +363,11 @@ namespace CairoChart {
|
||||||
|
|
||||||
// 4.5. Draw Axis title
|
// 4.5. Draw Axis title
|
||||||
if (s.axis_x.title.text != "") {
|
if (s.axis_x.title.text != "") {
|
||||||
var scr_x = chart.plarea.x + chart.plarea.width * (s.place.zoom_x_min + s.place.zoom_x_max) / 2.0;
|
var scr_x = chart.plarea.x0 + chart.plarea.width * (s.place.zoom_x_min + s.place.zoom_x_max) / 2.0;
|
||||||
double scr_y = 0.0;
|
double scr_y = 0.0;
|
||||||
switch (s.axis_x.position) {
|
switch (s.axis_x.position) {
|
||||||
case Axis.Position.LOW: scr_y = chart.evarea.y + chart.evarea.height - s.axis_x.font_spacing; break;
|
case Axis.Position.LOW: scr_y = chart.evarea.y1 - s.axis_x.font_spacing; break;
|
||||||
case Axis.Position.HIGH: scr_y = chart.evarea.y + s.axis_x.font_spacing + sz.height; break;
|
case Axis.Position.HIGH: scr_y = chart.evarea.y0 + s.axis_x.font_spacing + sz.height; break;
|
||||||
}
|
}
|
||||||
chart.ctx.move_to(scr_x - sz.width / 2.0, scr_y);
|
chart.ctx.move_to(scr_x - sz.width / 2.0, scr_y);
|
||||||
chart.color = s.axis_x.color;
|
chart.color = s.axis_x.color;
|
||||||
|
@ -391,15 +384,10 @@ namespace CairoChart {
|
||||||
|
|
||||||
if (nskip != 0) {--nskip; return;}
|
if (nskip != 0) {--nskip; return;}
|
||||||
|
|
||||||
switch (s.axis_x.position) {
|
|
||||||
case Axis.Position.LOW:
|
|
||||||
chart.evarea.height -= max_rec_height + s.axis_x.font_spacing
|
|
||||||
+ (s.axis_x.title.text == "" ? 0 : sz.height + s.axis_x.font_spacing);
|
|
||||||
break;
|
|
||||||
case Axis.Position.HIGH:
|
|
||||||
var tmp = max_rec_height + s.axis_x.font_spacing + (s.axis_x.title.text == "" ? 0 : sz.height + s.axis_x.font_spacing);
|
var tmp = max_rec_height + s.axis_x.font_spacing + (s.axis_x.title.text == "" ? 0 : sz.height + s.axis_x.font_spacing);
|
||||||
chart.evarea.y += tmp; chart.evarea.height -= tmp;
|
switch (s.axis_x.position) {
|
||||||
break;
|
case Axis.Position.LOW: chart.evarea.y1 -= tmp; break;
|
||||||
|
case Axis.Position.HIGH: chart.evarea.y0 += tmp; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +407,7 @@ namespace CairoChart {
|
||||||
|
|
||||||
switch (axis_y.position) {
|
switch (axis_y.position) {
|
||||||
case Axis.Position.LOW:
|
case Axis.Position.LOW:
|
||||||
ctx.move_to (chart.evarea.x + max_rec_width - text_sz.width + axis_y.font_spacing
|
ctx.move_to (chart.evarea.x0 + max_rec_width - text_sz.width + axis_y.font_spacing
|
||||||
+ (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_spacing),
|
+ (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_spacing),
|
||||||
compact_rec_y_pos (y, text_t));
|
compact_rec_y_pos (y, text_t));
|
||||||
text_t.show(ctx);
|
text_t.show(ctx);
|
||||||
|
@ -427,15 +415,15 @@ namespace CairoChart {
|
||||||
var line_style = grid.line_style;
|
var line_style = grid.line_style;
|
||||||
if (joint_y) line_style.color = Color(0, 0, 0, 0.5);
|
if (joint_y) line_style.color = Color(0, 0, 0, 0.5);
|
||||||
line_style.apply(chart);
|
line_style.apply(chart);
|
||||||
double x = chart.evarea.x + max_rec_width + axis_y.font_spacing + (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_spacing);
|
double x = chart.evarea.x0 + max_rec_width + axis_y.font_spacing + (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_spacing);
|
||||||
ctx.move_to (x, scr_y);
|
ctx.move_to (x, scr_y);
|
||||||
if (joint_y)
|
if (joint_y)
|
||||||
ctx.line_to (chart.plarea.x + chart.plarea.width, scr_y);
|
ctx.line_to (chart.plarea.x1, scr_y);
|
||||||
else
|
else
|
||||||
ctx.line_to (double.max (x, chart.plarea.x + chart.plarea.width * place.zoom_x_max), scr_y);
|
ctx.line_to (double.max (x, chart.plarea.x0 + chart.plarea.width * place.zoom_x_max), scr_y);
|
||||||
break;
|
break;
|
||||||
case Axis.Position.HIGH:
|
case Axis.Position.HIGH:
|
||||||
ctx.move_to (chart.evarea.x + chart.evarea.width - text_sz.width - axis_y.font_spacing
|
ctx.move_to (chart.evarea.x1 - text_sz.width - axis_y.font_spacing
|
||||||
- (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_spacing),
|
- (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_spacing),
|
||||||
compact_rec_y_pos (y, text_t));
|
compact_rec_y_pos (y, text_t));
|
||||||
text_t.show(ctx);
|
text_t.show(ctx);
|
||||||
|
@ -443,12 +431,12 @@ namespace CairoChart {
|
||||||
var line_style = grid.line_style;
|
var line_style = grid.line_style;
|
||||||
if (joint_y) line_style.color = Color(0, 0, 0, 0.5);
|
if (joint_y) line_style.color = Color(0, 0, 0, 0.5);
|
||||||
line_style.apply(chart);
|
line_style.apply(chart);
|
||||||
double x = chart.evarea.x + chart.evarea.width - max_rec_width - axis_y.font_spacing - (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_spacing);
|
double x = chart.evarea.x1 - max_rec_width - axis_y.font_spacing - (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_spacing);
|
||||||
ctx.move_to (x, scr_y);
|
ctx.move_to (x, scr_y);
|
||||||
if (joint_y)
|
if (joint_y)
|
||||||
ctx.line_to (chart.plarea.x, scr_y);
|
ctx.line_to (chart.plarea.x0, scr_y);
|
||||||
else
|
else
|
||||||
ctx.line_to (double.min (x, chart.plarea.x + chart.plarea.width * place.zoom_x_min), scr_y);
|
ctx.line_to (double.min (x, chart.plarea.x0 + chart.plarea.width * place.zoom_x_min), scr_y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -484,9 +472,10 @@ namespace CairoChart {
|
||||||
|
|
||||||
// 4.2. Cursor values for joint Y axis
|
// 4.2. Cursor values for joint Y axis
|
||||||
if (chart.joint_y && chart.cursors.cursor_style.orientation == Cursors.Orientation.HORIZONTAL && chart.cursors.cursors_crossings.length != 0) {
|
if (chart.joint_y && chart.cursors.cursor_style.orientation == Cursors.Orientation.HORIZONTAL && chart.cursors.cursors_crossings.length != 0) {
|
||||||
|
var tmp = max_rec_width + s.axis_y.font_spacing;
|
||||||
switch (s.axis_y.position) {
|
switch (s.axis_y.position) {
|
||||||
case Axis.Position.LOW: var tmp = max_rec_width + s.axis_y.font_spacing; chart.evarea.x += tmp; chart.evarea.width -= tmp; break;
|
case Axis.Position.LOW: chart.evarea.x0 += tmp; break;
|
||||||
case Axis.Position.HIGH: chart.evarea.width -= max_rec_width + s.axis_y.font_spacing; break;
|
case Axis.Position.HIGH: chart.evarea.x1 -= tmp; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,14 +483,14 @@ namespace CairoChart {
|
||||||
|
|
||||||
// 4.5. Draw Axis title
|
// 4.5. Draw Axis title
|
||||||
if (s.axis_y.title.text != "") {
|
if (s.axis_y.title.text != "") {
|
||||||
var scr_y = chart.plarea.y + chart.plarea.height * (1.0 - (s.place.zoom_y_min + s.place.zoom_y_max) / 2.0);
|
var scr_y = chart.plarea.y0 + chart.plarea.height * (1.0 - (s.place.zoom_y_min + s.place.zoom_y_max) / 2.0);
|
||||||
switch (s.axis_y.position) {
|
switch (s.axis_y.position) {
|
||||||
case Axis.Position.LOW:
|
case Axis.Position.LOW:
|
||||||
var scr_x = chart.evarea.x + s.axis_y.font_spacing + sz.width;
|
var scr_x = chart.evarea.x0 + s.axis_y.font_spacing + sz.width;
|
||||||
chart.ctx.move_to(scr_x, scr_y + sz.height / 2.0);
|
chart.ctx.move_to(scr_x, scr_y + sz.height / 2.0);
|
||||||
break;
|
break;
|
||||||
case Axis.Position.HIGH:
|
case Axis.Position.HIGH:
|
||||||
var scr_x = chart.evarea.x + chart.evarea.width - s.axis_y.font_spacing;
|
var scr_x = chart.evarea.x1 - s.axis_y.font_spacing;
|
||||||
chart.ctx.move_to(scr_x, scr_y + sz.height / 2.0);
|
chart.ctx.move_to(scr_x, scr_y + sz.height / 2.0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -519,14 +508,10 @@ namespace CairoChart {
|
||||||
|
|
||||||
if (nskip != 0) {--nskip; return;}
|
if (nskip != 0) {--nskip; return;}
|
||||||
|
|
||||||
switch (s.axis_y.position) {
|
|
||||||
case Axis.Position.LOW:
|
|
||||||
var tmp = max_rec_width + s.axis_y.font_spacing + (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_spacing);
|
var tmp = max_rec_width + s.axis_y.font_spacing + (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_spacing);
|
||||||
chart.evarea.x += tmp; chart.evarea.width -= tmp;
|
switch (s.axis_y.position) {
|
||||||
break;
|
case Axis.Position.LOW: chart.evarea.x0 += tmp; break;
|
||||||
case Axis.Position.HIGH:
|
case Axis.Position.HIGH: chart.evarea.x1 -= tmp; break;
|
||||||
chart.evarea.width -= max_rec_width + s.axis_y.font_spacing
|
|
||||||
+ (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_spacing); break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,11 +528,11 @@ namespace CairoChart {
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual double get_scr_x (Float128 x) {
|
public virtual double get_scr_x (Float128 x) {
|
||||||
return chart.plarea.x + chart.plarea.width * (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));
|
return chart.plarea.x0 + chart.plarea.width * (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) {
|
public virtual double get_scr_y (Float128 y) {
|
||||||
return chart.plarea.y + chart.plarea.height * (1.0 - (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)));
|
return chart.plarea.y0 + chart.plarea.height * (1.0 - (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) {
|
public virtual Point get_scr_point (Point128 p) {
|
||||||
|
@ -555,12 +540,12 @@ namespace CairoChart {
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Float128 get_real_x (double scr_x) {
|
public virtual Float128 get_real_x (double scr_x) {
|
||||||
return axis_x.zoom_min + ((scr_x - chart.plarea.x) / chart.plarea.width - place.zoom_x_min)
|
return axis_x.zoom_min + ((scr_x - chart.plarea.x0) / chart.plarea.width - place.zoom_x_min)
|
||||||
* (axis_x.zoom_max - axis_x.zoom_min) / (place.zoom_x_max - 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) {
|
public virtual Float128 get_real_y (double scr_y) {
|
||||||
return axis_y.zoom_min + ((chart.plarea.y + chart.plarea.height - scr_y) / chart.plarea.height - place.zoom_y_min)
|
return axis_y.zoom_min + ((chart.plarea.y1 - scr_y) / chart.plarea.height - place.zoom_y_min)
|
||||||
* (axis_y.zoom_max - axis_y.zoom_min) / (place.zoom_y_max - place.zoom_y_min);
|
* (axis_y.zoom_max - axis_y.zoom_min) / (place.zoom_y_max - place.zoom_y_min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,10 +206,10 @@ void plot_chart4 (Chart chart) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool point_in_chart (Chart chart, double x, double y) {
|
bool point_in_chart (Chart chart, double x, double y) {
|
||||||
if (x < chart.plarea.x) return false;
|
if (x < chart.plarea.x0) return false;
|
||||||
if (x > chart.plarea.x + chart.plarea.width) return false;
|
if (x > chart.plarea.x1) return false;
|
||||||
if (y < chart.plarea.y) return false;
|
if (y < chart.plarea.y0) return false;
|
||||||
if (y > chart.plarea.y + chart.plarea.height) return false;
|
if (y > chart.plarea.y1) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,7 +426,7 @@ int main (string[] args) {
|
||||||
|
|
||||||
// user's post draw operations here...
|
// user's post draw operations here...
|
||||||
if (mouse_state == MouseState.DRAW_SELECTION)
|
if (mouse_state == MouseState.DRAW_SELECTION)
|
||||||
chart.draw_selection (Cairo.Rectangle() {x = sel_x0, y = sel_y0, width = sel_x1 - sel_x0, height = sel_y1 - sel_y0});
|
chart.draw_selection (new Area.with_abs(sel_x0, sel_y0, sel_x1, sel_y1));
|
||||||
|
|
||||||
// show delta
|
// show delta
|
||||||
var str = chart.cursors.get_cursors_delta_str();
|
var str = chart.cursors.get_cursors_delta_str();
|
||||||
|
@ -435,8 +435,8 @@ int main (string[] args) {
|
||||||
var text_t = new Text(text);
|
var text_t = new Text(text);
|
||||||
var w = text_t.get_width(ctx);
|
var w = text_t.get_width(ctx);
|
||||||
var h = text_t.get_height(ctx);
|
var h = text_t.get_height(ctx);
|
||||||
var x0 = chart.plarea.x + chart.plarea.width - w - 5;
|
var x0 = chart.plarea.x1 - w - 5;
|
||||||
var y0 = chart.plarea.y + h + 5;
|
var y0 = chart.plarea.y0 + h + 5;
|
||||||
chart.color = chart.legend.bg_color;
|
chart.color = chart.legend.bg_color;
|
||||||
ctx.rectangle (x0, y0 - h, w, h);
|
ctx.rectangle (x0, y0 - h, w, h);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
|
@ -499,7 +499,7 @@ int main (string[] args) {
|
||||||
sel_x1 = event.x;
|
sel_x1 = event.x;
|
||||||
sel_y1 = event.y;
|
sel_y1 = event.y;
|
||||||
if (sel_x1 > sel_x0 && sel_y1 > sel_y0)
|
if (sel_x1 > sel_x0 && sel_y1 > sel_y0)
|
||||||
chart.zoom_in (Cairo.Rectangle(){x = sel_x0, y = sel_y0, width = sel_x1 - sel_x0, height = sel_y1 - sel_y0});
|
chart.zoom_in (new Area.with_abs(sel_x0, sel_y0, sel_x1, sel_y1));
|
||||||
else
|
else
|
||||||
chart.zoom_out ();
|
chart.zoom_out ();
|
||||||
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
|
||||||
|
|
Loading…
Reference in New Issue