In progress...

This commit is contained in:
Kolan Sh 2018-01-17 10:36:10 +03:00
parent df3c3b1693
commit a79254c716
9 changed files with 169 additions and 166 deletions

View File

@ -117,7 +117,7 @@ namespace CairoChart {
switch (type) {
case Axis.Type.NUMBERS:
var text = new Text (format.printf((LongDouble)x) + (horizontal ? "_" : ""), font_style);
var sz = text.get_size(chart.context);
var sz = text.get_size(chart.ctx);
max_rec_width = double.max (max_rec_width, sz.width);
max_rec_height = double.max (max_rec_height, sz.height);
break;
@ -128,13 +128,13 @@ namespace CairoChart {
var h = 0.0;
if (date_format != "") {
var text = new Text (date + (horizontal ? "_" : ""), font_style);
var sz = text.get_size(chart.context);
var sz = text.get_size(chart.ctx);
max_rec_width = double.max (max_rec_width, sz.width);
h = sz.height;
}
if (time_format != "") {
var text = new Text (time + (horizontal ? "_" : ""), font_style);
var sz = text.get_size(chart.context);
var sz = text.get_size(chart.ctx);
max_rec_width = double.max (max_rec_width, sz.width);
h += sz.height;
}

View File

@ -7,7 +7,10 @@ namespace CairoChart {
*/
public Cairo.Rectangle pos = Cairo.Rectangle();
public Cairo.Context context = null;
/**
* Cairo Context of the Drawing Area.
*/
public Cairo.Context ctx = null;
public Color bg_color = Color(1, 1, 1);
public Text title = new Text ("Cairo Chart");
@ -51,7 +54,7 @@ namespace CairoChart {
public Color color {
private get { return Color(); }
set { context.set_source_rgba (value.red, value.green, value.blue, value.alpha); }
set { ctx.set_source_rgba (value.red, value.green, value.blue, value.alpha); }
default = Color();
}
@ -63,7 +66,7 @@ namespace CairoChart {
chart.border_color = this.border_color;
chart.joint_x = this.joint_x;
chart.joint_y = this.joint_y;
chart.context = this.context;
chart.ctx = this.ctx;
chart.cur_x_max = this.cur_x_max;
chart.cur_x_min = this.cur_x_min;
chart.cur_y_max = this.cur_y_max;
@ -103,9 +106,9 @@ namespace CairoChart {
}
public virtual void clear () {
if (context != null) {
if (ctx != null) {
color = bg_color;
context.paint();
ctx.paint();
color = Color (0, 0, 0, 1);
}
}
@ -147,17 +150,17 @@ namespace CairoChart {
return true;
}
protected virtual void draw_chart_title () {
var sz = title.get_size(context);
var sz = title.get_size(ctx);
title_height = sz.height + (legend.position == Legend.Position.TOP ? title_indent * 2 : title_indent);
cur_y_min += title_height;
color = title.color;
context.move_to (pos.width/2 - sz.width/2, sz.height + title_indent);
title.show(context);
ctx.move_to (pos.width/2 - sz.width/2, sz.height + title_indent);
title.show(ctx);
}
public virtual void draw_selection (Cairo.Rectangle rect) {
selection_style.set(this);
context.rectangle (rect.x, rect.y, rect.width, rect.height);
context.stroke();
ctx.rectangle (rect.x, rect.y, rect.width, rect.height);
ctx.stroke();
}
protected virtual void draw_horizontal_axes () {
for (var si = series.length - 1, nskip = 0; si >=0; --si)
@ -169,13 +172,13 @@ namespace CairoChart {
}
protected virtual void draw_plot_area_border () {
color = border_color;
context.set_dash(null, 0);
context.move_to (plot_x_min, plot_y_min);
context.line_to (plot_x_min, plot_y_max);
context.line_to (plot_x_max, plot_y_max);
context.line_to (plot_x_max, plot_y_min);
context.line_to (plot_x_min, plot_y_min);
context.stroke ();
ctx.set_dash(null, 0);
ctx.move_to (plot_x_min, plot_y_min);
ctx.line_to (plot_x_min, plot_y_max);
ctx.line_to (plot_x_max, plot_y_max);
ctx.line_to (plot_x_max, plot_y_min);
ctx.line_to (plot_x_min, plot_y_min);
ctx.stroke ();
}
protected virtual void draw_series () {
for (var si = 0; si < series.length; ++si) {

View File

@ -217,10 +217,10 @@ namespace CairoChart {
var x_t = new Text (s.axis_x.format.printf((LongDouble)p.x), s.axis_x.font_style, s.axis_x.color);
var y_t = new Text (s.axis_y.format.printf((LongDouble)p.y), s.axis_y.font_style, s.axis_y.color);
double h_x = 0.0, h_y = 0.0;
if (show_x) { var sz = x_t.get_size(chart.context); size.x = sz.width; h_x = sz.height; }
if (show_date) { var sz = date_t.get_size(chart.context); size.x = sz.width; h_x = sz.height; }
if (show_time) { var sz = time_t.get_size(chart.context); size.x = double.max(size.x, sz.width); h_x += sz.height; }
if (show_y) { var sz = y_t.get_size(chart.context); size.x += sz.width; h_y = sz.height; }
if (show_x) { var sz = x_t.get_size(chart.ctx); size.x = sz.width; h_x = sz.height; }
if (show_date) { var sz = date_t.get_size(chart.ctx); size.x = sz.width; h_x = sz.height; }
if (show_time) { var sz = time_t.get_size(chart.ctx); size.x = double.max(size.x, sz.width); h_x += sz.height; }
if (show_y) { var sz = y_t.get_size(chart.ctx); size.x += sz.width; h_y = sz.height; }
if ((show_x || show_date || show_time) && show_y) size.x += double.max(s.axis_x.font_indent, s.axis_y.font_indent);
if (show_date && show_time) h_x += s.axis_x.font_indent;
size.y = double.max (h_x, h_y);
@ -269,8 +269,8 @@ namespace CairoChart {
}
}
chart.context.move_to (ccs[ci].scr_point.x, ccs[ci].scr_point.y);
chart.context.line_to (ccs[ci].scr_value_point.x, ccs[ci].scr_value_point.y);
chart.ctx.move_to (ccs[ci].scr_point.x, ccs[ci].scr_point.y);
chart.ctx.line_to (ccs[ci].scr_value_point.x, ccs[ci].scr_value_point.y);
}
var c = all_cursors.nth_data(cursors_crossings[cci].cursor_index);
@ -278,8 +278,8 @@ namespace CairoChart {
switch (cursor_style.orientation) {
case Orientation.VERTICAL:
if (low.y > high.y) continue;
chart.context.move_to (chart.rel2scr_x(c.x), low.y);
chart.context.line_to (chart.rel2scr_x(c.x), high.y);
chart.ctx.move_to (chart.rel2scr_x(c.x), low.y);
chart.ctx.line_to (chart.rel2scr_x(c.x), high.y);
// show joint X value
if (chart.joint_x) {
@ -297,7 +297,7 @@ namespace CairoChart {
break;
}
var text_t = new Text(text, s.axis_x.font_style, s.axis_x.color);
var sz = text_t.get_size(chart.context);
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 print_y = 0.0;
switch (s.axis_x.position) {
@ -312,32 +312,32 @@ namespace CairoChart {
break;
case Axis.Type.DATE_TIME:
print_y += (s.axis_x.date_format == "" ? 0 : sz.height)
+ (s.axis_x.time_format == "" ? 0 : time_text_t.get_height(chart.context))
+ (s.axis_x.time_format == "" ? 0 : time_text_t.get_height(chart.ctx))
+ (s.axis_x.date_format == "" || s.axis_x.time_format == "" ? 0 : s.axis_x.font_indent);
break;
}
break;
}
var print_x = s.compact_rec_x_pos (x, text_t);
chart.context.move_to (print_x, print_y);
chart.ctx.move_to (print_x, print_y);
switch (s.axis_x.type) {
case Axis.Type.NUMBERS:
text_t.show(chart.context);
text_t.show(chart.ctx);
break;
case Axis.Type.DATE_TIME:
if (s.axis_x.date_format != "") text_t.show(chart.context);
if (s.axis_x.date_format != "") text_t.show(chart.ctx);
print_x = s.compact_rec_x_pos (x, time_text_t);
chart.context.move_to (print_x, print_y - (s.axis_x.date_format == "" ? 0 : sz.height + s.axis_x.font_indent));
if (s.axis_x.time_format != "") time_text_t.show(chart.context);
chart.ctx.move_to (print_x, print_y - (s.axis_x.date_format == "" ? 0 : sz.height + s.axis_x.font_indent));
if (s.axis_x.time_format != "") time_text_t.show(chart.ctx);
break;
}
}
break;
case Orientation.HORIZONTAL:
if (low.x > high.x) continue;
chart.context.move_to (low.x, chart.rel2scr_y(c.y));
chart.context.line_to (high.x, chart.rel2scr_y(c.y));
chart.ctx.move_to (low.x, chart.rel2scr_y(c.y));
chart.ctx.line_to (high.x, chart.rel2scr_y(c.y));
// show joint Y value
if (chart.joint_y) {
@ -352,16 +352,16 @@ namespace CairoChart {
+ (chart.legend.position == Legend.Position.LEFT ? chart.legend.width : 0);
break;
case Axis.Position.HIGH:
print_x = chart.pos.x + chart.pos.width - text_t.get_width(chart.context) - s.axis_y.font_indent
print_x = chart.pos.x + chart.pos.width - text_t.get_width(chart.ctx) - s.axis_y.font_indent
- (chart.legend.position == Legend.Position.RIGHT ? chart.legend.width : 0);
break;
}
chart.context.move_to (print_x, print_y);
text_t.show(chart.context);
chart.ctx.move_to (print_x, print_y);
text_t.show(chart.ctx);
}
break;
}
chart.context.stroke ();
chart.ctx.stroke ();
// show value (X, Y or [X;Y])
for (var ci = 0, max_ci = ccs.length; ci < max_ci; ++ci) {
@ -376,15 +376,15 @@ namespace CairoChart {
var show_y = ccs[ci].show_y;
chart.color = chart.bg_color;
chart.context.rectangle (svp.x - size.x / 2, svp.y - size.y / 2, size.x, size.y);
chart.context.fill();
chart.ctx.rectangle (svp.x - size.x / 2, svp.y - size.y / 2, size.x, size.y);
chart.ctx.fill();
if (show_x) {
chart.color = s.axis_x.color;
var text_t = new Text(s.axis_x.format.printf((LongDouble)point.x), s.axis_x.font_style);
chart.context.move_to (svp.x - size.x / 2, svp.y + text_t.get_height(chart.context) / 2);
chart.ctx.move_to (svp.x - size.x / 2, svp.y + text_t.get_height(chart.ctx) / 2);
if (chart.joint_x) chart.color = chart.joint_axis_color;
text_t.show(chart.context);
text_t.show(chart.ctx);
}
if (show_time) {
@ -392,12 +392,12 @@ namespace CairoChart {
string date = "", time = "";
s.axis_x.format_date_time(point.x, out date, out time);
var text_t = new Text(time, s.axis_x.font_style);
var sz = text_t.get_size(chart.context);
var sz = text_t.get_size(chart.ctx);
var y = svp.y + sz.height / 2;
if (show_date) y -= sz.height / 2 + s.axis_x.font_indent / 2;
chart.context.move_to (svp.x - size.x / 2, y);
chart.ctx.move_to (svp.x - size.x / 2, y);
if (chart.joint_x) chart.color = chart.joint_axis_color;
text_t.show(chart.context);
text_t.show(chart.ctx);
}
if (show_date) {
@ -405,21 +405,21 @@ namespace CairoChart {
string date = "", time = "";
s.axis_x.format_date_time(point.x, out date, out time);
var text_t = new Text(date, s.axis_x.font_style);
var sz = text_t.get_size(chart.context);
var sz = text_t.get_size(chart.ctx);
var y = svp.y + sz.height / 2;
if (show_time) y += sz.height / 2 + s.axis_x.font_indent / 2;
chart.context.move_to (svp.x - size.x / 2, y);
chart.ctx.move_to (svp.x - size.x / 2, y);
if (chart.joint_x) chart.color = chart.joint_axis_color;
text_t.show(chart.context);
text_t.show(chart.ctx);
}
if (show_y) {
chart.color = s.axis_y.color;
var text_t = new Text(s.axis_y.format.printf((LongDouble)point.y), s.axis_y.font_style);
var sz = text_t.get_size(chart.context);
chart.context.move_to (svp.x + size.x / 2 - sz.width, svp.y + sz.height / 2);
var sz = text_t.get_size(chart.ctx);
chart.ctx.move_to (svp.x + size.x / 2 - sz.width, svp.y + sz.height / 2);
if (chart.joint_y) chart.color = chart.joint_axis_color;
text_t.show(chart.context);
text_t.show(chart.ctx);
}
}
}

View File

@ -48,7 +48,7 @@ namespace CairoChart {
public virtual void draw_rect (Chart chart, out double x0, out double y0) {
x0 = y0 = 0.0;
if (chart.context != null) {
if (chart.ctx != null) {
switch (position) {
case Position.TOP:
x0 = (chart.pos.width - width) / 2;
@ -71,15 +71,15 @@ namespace CairoChart {
break;
}
chart.color = bg_color;
chart.context.rectangle (x0, y0, width, height);
chart.context.fill();
chart.ctx.rectangle (x0, y0, width, height);
chart.ctx.fill();
border_style.set(chart);
chart.context.move_to (x0, y0);
chart.context.rel_line_to (width, 0);
chart.context.rel_line_to (0, height);
chart.context.rel_line_to (-width, 0);
chart.context.rel_line_to (0, -height);
chart.context.stroke ();
chart.ctx.move_to (x0, y0);
chart.ctx.rel_line_to (width, 0);
chart.ctx.rel_line_to (0, height);
chart.ctx.rel_line_to (-width, 0);
chart.ctx.rel_line_to (0, -height);
chart.ctx.stroke ();
}
}
@ -113,7 +113,7 @@ namespace CairoChart {
if (!s.zoom_show) continue;
var title_sz = s.title.get_size(chart.context);
var title_sz = s.title.get_size(chart.ctx);
// carry
switch (position) {
@ -143,15 +143,15 @@ namespace CairoChart {
var y = legend_y0 + leg_height_sum + max_font_heights[heights_idx];
// series title
chart.context.move_to (x + line_length, y);
chart.ctx.move_to (x + line_length, y);
chart.color = s.title.color;
s.title.show(chart.context);
s.title.show(chart.ctx);
// series line style
chart.context.move_to (x, y - title_sz.height / 2);
chart.ctx.move_to (x, y - title_sz.height / 2);
s.line_style.set(chart);
chart.context.rel_line_to (line_length, 0);
chart.context.stroke();
chart.ctx.rel_line_to (line_length, 0);
chart.ctx.stroke();
s.marker.draw_at_pos (chart, x + line_length / 2, y - title_sz.height / 2);
break;
}

View File

@ -27,10 +27,10 @@ namespace CairoChart {
public void set (Chart chart) {
chart.color = color;
chart.context.set_line_join(join);
chart.context.set_line_cap(cap);
chart.context.set_line_width(width);
chart.context.set_dash(dashes, dash_offset);
chart.ctx.set_line_join(join);
chart.ctx.set_line_cap(cap);
chart.ctx.set_line_width(width);
chart.ctx.set_dash(dashes, dash_offset);
}
}
}

View File

@ -25,43 +25,43 @@ namespace CairoChart {
}
public virtual void draw_at_pos (Chart chart, double x, double y) {
chart.context.move_to (x, y);
chart.ctx.move_to (x, y);
switch (type) {
case Type.SQUARE:
chart.context.rectangle (x - size / 2, y - size / 2, size, size);
chart.context.fill();
chart.ctx.rectangle (x - size / 2, y - size / 2, size, size);
chart.ctx.fill();
break;
case Type.CIRCLE:
chart.context.arc (x, y, size / 2, 0, 2 * GLib.Math.PI);
chart.context.fill();
chart.ctx.arc (x, y, size / 2, 0, 2 * GLib.Math.PI);
chart.ctx.fill();
break;
case Type.TRIANGLE:
chart.context.move_to (x - size / 2, y - size / 2);
chart.context.line_to (x + size / 2, y - size / 2);
chart.context.line_to (x, y + size / 2);
chart.context.line_to (x - size / 2, y - size / 2);
chart.context.fill();
chart.ctx.move_to (x - size / 2, y - size / 2);
chart.ctx.line_to (x + size / 2, y - size / 2);
chart.ctx.line_to (x, y + size / 2);
chart.ctx.line_to (x - size / 2, y - size / 2);
chart.ctx.fill();
break;
case Type.PRICLE_SQUARE:
chart.context.rectangle (x - size / 2, y - size / 2,
chart.ctx.rectangle (x - size / 2, y - size / 2,
size, size);
chart.context.stroke();
chart.ctx.stroke();
break;
case Type.PRICLE_CIRCLE:
chart.context.arc (x, y, size / 2, 0, 2 * GLib.Math.PI);
chart.context.stroke();
chart.ctx.arc (x, y, size / 2, 0, 2 * GLib.Math.PI);
chart.ctx.stroke();
break;
case Type.PRICLE_TRIANGLE:
chart.context.move_to (x - size / 2, y - size / 2);
chart.context.line_to (x + size / 2, y - size / 2);
chart.context.line_to (x, y + size / 2);
chart.context.line_to (x - size / 2, y - size / 2);
chart.context.stroke();
chart.ctx.move_to (x - size / 2, y - size / 2);
chart.ctx.line_to (x + size / 2, y - size / 2);
chart.ctx.line_to (x, y + size / 2);
chart.ctx.line_to (x - size / 2, y - size / 2);
chart.ctx.stroke();
break;
}
}

View File

@ -76,11 +76,11 @@ namespace CairoChart {
Point(get_scr_x(points[i].x), get_scr_y(points[i].y)),
out c, out d)
) {
chart.context.move_to (c.x, c.y);
chart.context.line_to (d.x, d.y);
chart.ctx.move_to (c.x, c.y);
chart.ctx.line_to (d.x, d.y);
}
}
chart.context.stroke();
chart.ctx.stroke();
for (int i = 0; i < points.length; ++i) {
var x = get_scr_x(points[i].x);
var y = get_scr_y(points[i].y);
@ -122,8 +122,8 @@ namespace CairoChart {
double max_rec_width = 0; double max_rec_height = 0;
axis.calc_rec_sizes (chart, out max_rec_width, out max_rec_height, is_x);
var max_font_indent = axis.font_indent;
var max_axis_font_width = axis.title.text == "" ? 0 : axis.title.get_width(chart.context) + axis.font_indent;
var max_axis_font_height = axis.title.text == "" ? 0 : axis.title.get_height(chart.context) + axis.font_indent;
var max_axis_font_width = axis.title.text == "" ? 0 : axis.title.get_width(chart.ctx) + axis.font_indent;
var max_axis_font_height = axis.title.text == "" ? 0 : axis.title.get_height(chart.ctx) + axis.font_indent;
if (is_x)
s.join_relative_x_axes (si, true, ref max_rec_width, ref max_rec_height, ref max_font_indent, ref max_axis_font_height, ref nskip);
@ -190,7 +190,7 @@ namespace CairoChart {
max_rec_height = double.max (max_rec_height, tmp_max_rec_height);
max_font_indent = double.max (max_font_indent, s2.axis_x.font_indent);
max_axis_font_height = double.max (max_axis_font_height, s2.axis_x.title.text == "" ? 0 :
s2.axis_x.title.get_height(chart.context) + this.axis_x.font_indent);
s2.axis_x.title.get_height(chart.ctx) + this.axis_x.font_indent);
}
++nskip;
} else {
@ -227,7 +227,7 @@ namespace CairoChart {
max_rec_height = double.max (max_rec_height, tmp_max_rec_height);
max_font_indent = double.max (max_font_indent, s2.axis_y.font_indent);
max_axis_font_width = double.max (max_axis_font_width, s2.axis_y.title.text == "" ? 0
: s2.axis_y.title.get_width(chart.context) + this.axis_y.font_indent);
: s2.axis_y.title.get_width(chart.ctx) + this.axis_y.font_indent);
++nskip;
} else {
break;
@ -237,7 +237,7 @@ namespace CairoChart {
protected virtual void draw_horizontal_records (Float128 step, double max_rec_height, Float128 x_min) {
// 5. Draw records, update cur_{x,y}_{min,max}.
var context = chart.context;
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) {
@ -254,23 +254,23 @@ namespace CairoChart {
}
var scr_x = get_scr_x (x);
var text_t = new Text(text, axis_x.font_style, axis_x.color);
var sz = axis_x.title.get_size(context);
var sz = axis_x.title.get_size(ctx);
switch (axis_x.position) {
case Axis.Position.LOW:
var print_y = chart.cur_y_max - axis_x.font_indent - (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_indent);
var print_x = compact_rec_x_pos (x, text_t);
context.move_to (print_x, print_y);
ctx.move_to (print_x, print_y);
switch (axis_x.type) {
case Axis.Type.NUMBERS:
text_t.show(context);
text_t.show(ctx);
break;
case Axis.Type.DATE_TIME:
if (axis_x.date_format != "") text_t.show(context);
if (axis_x.date_format != "") text_t.show(ctx);
var time_text_t = new Text(time_text, axis_x.font_style, axis_x.color);
print_x = compact_rec_x_pos (x, time_text_t);
context.move_to (print_x, print_y - (axis_x.date_format == "" ? 0 : text_t.get_height(context) + axis_x.font_indent));
if (axis_x.time_format != "") time_text_t.show(context);
ctx.move_to (print_x, print_y - (axis_x.date_format == "" ? 0 : text_t.get_height(ctx) + axis_x.font_indent));
if (axis_x.time_format != "") time_text_t.show(ctx);
break;
}
// 6. Draw grid lines to the place.zoom_y_min.
@ -278,27 +278,27 @@ namespace CairoChart {
if (joint_x) line_style.color = Color(0, 0, 0, 0.5);
line_style.set(chart);
double y = chart.cur_y_max - max_rec_height - axis_x.font_indent - (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_indent);
context.move_to (scr_x, y);
ctx.move_to (scr_x, y);
if (joint_x)
context.line_to (scr_x, chart.plot_y_min);
ctx.line_to (scr_x, chart.plot_y_min);
else
context.line_to (scr_x, double.min (y, chart.plot_y_max - (chart.plot_y_max - chart.plot_y_min) * place.zoom_y_max));
ctx.line_to (scr_x, double.min (y, chart.plot_y_max - (chart.plot_y_max - chart.plot_y_min) * place.zoom_y_max));
break;
case Axis.Position.HIGH:
var print_y = chart.cur_y_min + max_rec_height + axis_x.font_indent + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_indent);
var print_x = compact_rec_x_pos (x, text_t);
context.move_to (print_x, print_y);
ctx.move_to (print_x, print_y);
switch (axis_x.type) {
case Axis.Type.NUMBERS:
text_t.show(context);
text_t.show(ctx);
break;
case Axis.Type.DATE_TIME:
if (axis_x.date_format != "") text_t.show(context);
if (axis_x.date_format != "") text_t.show(ctx);
var time_text_t = new Text(time_text, axis_x.font_style, axis_x.color);
print_x = compact_rec_x_pos (x, time_text_t);
context.move_to (print_x, print_y - (axis_x.date_format == "" ? 0 : text_t.get_height(context) + axis_x.font_indent));
if (axis_x.time_format != "") time_text_t.show(context);
ctx.move_to (print_x, print_y - (axis_x.date_format == "" ? 0 : text_t.get_height(ctx) + axis_x.font_indent));
if (axis_x.time_format != "") time_text_t.show(ctx);
break;
}
// 6. Draw grid lines to the place.zoom_y_max.
@ -306,11 +306,11 @@ namespace CairoChart {
if (joint_x) line_style.color = Color(0, 0, 0, 0.5);
line_style.set(chart);
double y = chart.cur_y_min + max_rec_height + axis_x.font_indent + (axis_x.title.text == "" ? 0 : sz.height + axis_x.font_indent);
context.move_to (scr_x, y);
ctx.move_to (scr_x, y);
if (joint_x)
context.line_to (scr_x, chart.plot_y_max);
ctx.line_to (scr_x, chart.plot_y_max);
else
context.line_to (scr_x, double.max (y, chart.plot_y_max - (chart.plot_y_max - chart.plot_y_min) * place.zoom_y_min));
ctx.line_to (scr_x, double.max (y, chart.plot_y_max - (chart.plot_y_max - chart.plot_y_min) * place.zoom_y_min));
break;
}
}
@ -353,7 +353,7 @@ namespace CairoChart {
}
}
var sz = s.axis_x.title.get_size(chart.context);
var sz = s.axis_x.title.get_size(chart.ctx);
// 4.5. Draw Axis title
if (s.axis_x.title.text != "") {
@ -363,15 +363,15 @@ namespace CairoChart {
case Axis.Position.LOW: scr_y = chart.cur_y_max - s.axis_x.font_indent; break;
case Axis.Position.HIGH: scr_y = chart.cur_y_min + s.axis_x.font_indent + sz.height; break;
}
chart.context.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;
if (chart.joint_x) chart.color = chart.joint_axis_color;
s.axis_x.title.show(chart.context);
s.axis_x.title.show(chart.ctx);
}
s.draw_horizontal_records (step, max_rec_height, x_min);
chart.context.stroke ();
chart.ctx.stroke ();
double tmp1 = 0, tmp2 = 0, tmp3 = 0, tmp4 = 0;
s.join_relative_x_axes (si, false, ref tmp1, ref tmp2, ref tmp3, ref tmp4, ref nskip);
@ -392,7 +392,7 @@ namespace CairoChart {
protected virtual void draw_vertical_records (Float128 step, double max_rec_width, Float128 y_min) {
// 5. Draw records, update cur_{x,y}_{min,max}.
var context = chart.context;
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) {
@ -401,41 +401,41 @@ namespace CairoChart {
var text = axis_y.format.printf((LongDouble)y);
var scr_y = get_scr_y (y);
var text_t = new Text(text, axis_y.font_style, axis_y.color);
var text_sz = text_t.get_size(context);
var sz = axis_y.title.get_size(context);
var text_sz = text_t.get_size(ctx);
var sz = axis_y.title.get_size(ctx);
switch (axis_y.position) {
case Axis.Position.LOW:
context.move_to (chart.cur_x_min + max_rec_width - text_sz.width + axis_y.font_indent
ctx.move_to (chart.cur_x_min + max_rec_width - text_sz.width + axis_y.font_indent
+ (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_indent),
compact_rec_y_pos (y, text_t));
text_t.show(context);
text_t.show(ctx);
// 6. Draw grid lines to the place.zoom_x_min.
var line_style = grid.line_style;
if (joint_y) line_style.color = Color(0, 0, 0, 0.5);
line_style.set(chart);
double x = chart.cur_x_min + max_rec_width + axis_y.font_indent + (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_indent);
context.move_to (x, scr_y);
ctx.move_to (x, scr_y);
if (joint_y)
context.line_to (chart.plot_x_max, scr_y);
ctx.line_to (chart.plot_x_max, scr_y);
else
context.line_to (double.max (x, chart.plot_x_min + (chart.plot_x_max - chart.plot_x_min) * place.zoom_x_max), scr_y);
ctx.line_to (double.max (x, chart.plot_x_min + (chart.plot_x_max - chart.plot_x_min) * place.zoom_x_max), scr_y);
break;
case Axis.Position.HIGH:
context.move_to (chart.cur_x_max - text_sz.width - axis_y.font_indent
ctx.move_to (chart.cur_x_max - text_sz.width - axis_y.font_indent
- (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_indent),
compact_rec_y_pos (y, text_t));
text_t.show(context);
text_t.show(ctx);
// 6. Draw grid lines to the place.zoom_x_max.
var line_style = grid.line_style;
if (joint_y) line_style.color = Color(0, 0, 0, 0.5);
line_style.set(chart);
double x = chart.cur_x_max - max_rec_width - axis_y.font_indent - (axis_y.title.text == "" ? 0 : sz.width + axis_y.font_indent);
context.move_to (x, scr_y);
ctx.move_to (x, scr_y);
if (joint_y)
context.line_to (chart.plot_x_min, scr_y);
ctx.line_to (chart.plot_x_min, scr_y);
else
context.line_to (double.min (x, chart.plot_x_min + (chart.plot_x_max - chart.plot_x_min) * place.zoom_x_min), scr_y);
ctx.line_to (double.min (x, chart.plot_x_min + (chart.plot_x_max - chart.plot_x_min) * place.zoom_x_min), scr_y);
break;
}
}
@ -477,7 +477,7 @@ namespace CairoChart {
}
}
var sz = s.axis_y.title.get_size(chart.context);
var sz = s.axis_y.title.get_size(chart.ctx);
// 4.5. Draw Axis title
if (s.axis_y.title.text != "") {
@ -485,21 +485,21 @@ namespace CairoChart {
switch (s.axis_y.position) {
case Axis.Position.LOW:
var scr_x = chart.cur_x_min + s.axis_y.font_indent + sz.width;
chart.context.move_to(scr_x, scr_y + sz.height / 2.0);
chart.ctx.move_to(scr_x, scr_y + sz.height / 2.0);
break;
case Axis.Position.HIGH:
var scr_x = chart.cur_x_max - s.axis_y.font_indent;
chart.context.move_to(scr_x, scr_y + sz.height / 2.0);
chart.ctx.move_to(scr_x, scr_y + sz.height / 2.0);
break;
}
chart.color = s.axis_y.color;
if (chart.joint_y) chart.color = chart.joint_axis_color;
s.axis_y.title.show(chart.context);
s.axis_y.title.show(chart.ctx);
}
s.draw_vertical_records (step, max_rec_width, y_min);
chart.context.stroke ();
chart.ctx.stroke ();
double tmp1 = 0, tmp2 = 0, tmp3 = 0, tmp4 = 0;
s.join_relative_y_axes (si, false, ref tmp1, ref tmp2, ref tmp3, ref tmp4, ref nskip);
@ -517,13 +517,13 @@ namespace CairoChart {
}
public virtual double compact_rec_x_pos (Float128 x, Text text) {
var sz = text.get_size(chart.context);
var sz = text.get_size(chart.ctx);
return get_scr_x(x) - sz.width / 2.0
- sz.width * (x - (axis_x.zoom_min + axis_x.zoom_max) / 2.0) / (axis_x.zoom_max - axis_x.zoom_min);
}
public virtual double compact_rec_y_pos (Float128 y, Text text) {
var sz = text.get_size(chart.context);
var sz = text.get_size(chart.ctx);
return get_scr_y(y) + sz.height / 2.0
+ sz.height * (y - (axis_y.zoom_min + axis_y.zoom_max) / 2.0) / (axis_y.zoom_max - axis_y.zoom_min);
}

View File

@ -4,16 +4,16 @@ namespace CairoChart {
public Font.Style style = Font.Style ();
public Color color = Color();
public virtual Cairo.TextExtents get_extents (Cairo.Context context) {
context.select_font_face (style.family, style.slant, style.weight);
context.set_font_size (style.size);
public virtual Cairo.TextExtents get_extents (Cairo.Context ctx) {
ctx.select_font_face (style.family, style.slant, style.weight);
ctx.set_font_size (style.size);
Cairo.TextExtents extents;
context.text_extents (text, out extents);
ctx.text_extents (text, out extents);
return extents;
}
public virtual double get_width (Cairo.Context context) {
var extents = get_extents (context);
public virtual double get_width (Cairo.Context ctx) {
var extents = get_extents (ctx);
switch (style.orientation) {
case Font.Orientation.HORIZONTAL: return extents.width;
case Font.Orientation.VERTICAL: return extents.height;
@ -21,8 +21,8 @@ namespace CairoChart {
}
}
public virtual double get_height (Cairo.Context context) {
var extents = get_extents (context);
public virtual double get_height (Cairo.Context ctx) {
var extents = get_extents (ctx);
switch (style.orientation) {
case Font.Orientation.HORIZONTAL: return extents.height;
case Font.Orientation.VERTICAL: return extents.width;
@ -35,9 +35,9 @@ namespace CairoChart {
double height;
}
public virtual Size get_size (Cairo.Context context) {
public virtual Size get_size (Cairo.Context ctx) {
var sz = Size();
var extents = get_extents (context);
var extents = get_extents (ctx);
switch (style.orientation) {
case Font.Orientation.HORIZONTAL:
sz.width = extents.width + extents.x_bearing;
@ -51,17 +51,17 @@ namespace CairoChart {
return sz;
}
public virtual void show (Cairo.Context context) {
context.select_font_face(style.family,
public virtual void show (Cairo.Context ctx) {
ctx.select_font_face(style.family,
style.slant,
style.weight);
context.set_font_size(style.size);
ctx.set_font_size(style.size);
if (style.orientation == Font.Orientation.VERTICAL) {
context.rotate(- GLib.Math.PI / 2.0);
context.show_text(text);
context.rotate(GLib.Math.PI / 2.0);
ctx.rotate(- GLib.Math.PI / 2.0);
ctx.show_text(text);
ctx.rotate(GLib.Math.PI / 2.0);
} else {
context.show_text(text);
ctx.show_text(text);
}
}

View File

@ -413,8 +413,8 @@ int main (string[] args) {
double sel_x0 = 0, sel_x1 = 0, sel_y0 = 0, sel_y1 = 0;
double mov_x0 = 0, mov_y0 = 0;
da.draw.connect((context) => {
chart.context = context;
da.draw.connect((ctx) => {
chart.ctx = ctx;
chart.pos.width = da.get_allocated_width();
chart.pos.height = da.get_allocated_height();
chart.clear();
@ -433,16 +433,16 @@ int main (string[] args) {
if (str != "") {
var text = "Δ = " + str;
var text_t = new Text(text);
var w = text_t.get_width(context);
var h = text_t.get_height(context);
var w = text_t.get_width(ctx);
var h = text_t.get_height(ctx);
var x0 = chart.plot_x_max - w - 5;
var y0 = chart.plot_y_min + h + 5;
chart.color = chart.legend.bg_color;
context.rectangle (x0, y0 - h, w, h);
context.fill();
context.move_to (x0, y0);
ctx.rectangle (x0, y0 - h, w, h);
ctx.fill();
ctx.move_to (x0, y0);
chart.color = chart.joint_axis_color;
context.show_text(text);
ctx.show_text(text);
}
return true;//ret;