OK. In progress...

This commit is contained in:
Kolan Sh 2018-01-16 20:39:59 +03:00
parent efa0c07ccb
commit 1aed98dfec
6 changed files with 67 additions and 74 deletions

View File

@ -49,9 +49,14 @@ namespace CairoChart {
public CairoChart.Math math { get; protected set; default = new Math(); }
public Cursors cursors { get; protected set; default = new Cursors (); }
public Chart () {
public Color color {
private get { return Color(); }
set { context.set_source_rgba (value.red, value.green, value.blue, value.alpha); }
default = Color();
}
public Chart () { }
public Chart copy () {
var chart = new Chart ();
chart.bg_color = this.bg_color;
@ -96,9 +101,9 @@ namespace CairoChart {
public virtual void clear () {
if (context != null) {
set_source_rgba (bg_color);
color = bg_color;
context.paint();
set_source_rgba (Color (0, 0, 0, 1));
color = Color (0, 0, 0, 1);
}
}
@ -138,9 +143,43 @@ namespace CairoChart {
return true;
}
public virtual void set_source_rgba (Color color) {
context.set_source_rgba (color.red, color.green, color.blue, color.alpha);
protected virtual void draw_chart_title () {
var sz = title.get_size(context);
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 (width/2 - sz.width/2, sz.height + title_indent);
title.show(context);
}
public virtual void draw_selection (Cairo.Rectangle rect) {
selection_style.set(this);
context.rectangle (rect.x, rect.y, rect.width, rect.height);
context.stroke();
}
protected virtual void draw_horizontal_axes () {
for (var si = series.length - 1, nskip = 0; si >=0; --si)
series[si].draw_horizontal_axis (si, ref nskip);
}
protected virtual void draw_vertical_axes () {
for (var si = series.length - 1, nskip = 0; si >=0; --si)
series[si].draw_vertical_axis (si, ref nskip);
}
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 ();
}
protected virtual void draw_series () {
for (var si = 0; si < series.length; ++si) {
var s = series[si];
if (s.zoom_show && s.points.length != 0)
s.draw();
}
}
public virtual void zoom_in (Cairo.Rectangle rect) {
@ -201,7 +240,6 @@ namespace CairoChart {
rz_y_min = new_rz_y_min;
rz_y_max = new_rz_y_max;
}
public virtual void zoom_out () {
foreach (var s in series) {
s.zoom_show = true;
@ -221,7 +259,6 @@ namespace CairoChart {
zoom_first_show = 0;
}
public virtual void move (Point delta) {
var d = delta;
d.x /= plot_x_max - plot_x_min; d.x *= - 1.0;
@ -245,21 +282,6 @@ namespace CairoChart {
zoom_in (Cairo.Rectangle(){x = xmin + d.x, y = ymin + d.y, width = xmax - xmin, height = ymax - ymin});
}
protected virtual void draw_chart_title () {
var sz = title.get_size(context);
title_height = sz.height + (legend.position == Legend.Position.TOP ? title_indent * 2 : title_indent);
cur_y_min += title_height;
set_source_rgba(title.color);
context.move_to (width/2 - sz.width/2, sz.height + title_indent);
title.show(context);
}
public virtual void draw_selection (Cairo.Rectangle rect) {
selection_style.set(this);
context.rectangle (rect.x, rect.y, rect.width, rect.height);
context.stroke();
}
protected virtual void set_vertical_axes_titles () {
for (var si = 0; si < series.length; ++si) {
var s = series[si];
@ -339,35 +361,6 @@ namespace CairoChart {
join_calc (false);
}
protected virtual void draw_horizontal_axes () {
for (var si = series.length - 1, nskip = 0; si >=0; --si)
series[si].draw_horizontal_axis (si, ref nskip);
}
protected virtual void draw_vertical_axes () {
for (var si = series.length - 1, nskip = 0; si >=0; --si)
series[si].draw_vertical_axis (si, ref nskip);
}
protected virtual void draw_plot_area_border () {
set_source_rgba (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 ();
}
protected virtual void draw_series () {
for (var si = 0; si < series.length; ++si) {
var s = series[si];
if (s.zoom_show && s.points.length != 0)
s.draw();
}
}
protected virtual bool x_in_plot_area (double x) {
if (math.x_in_range(x, plot_x_min, plot_x_max))
return true;

View File

@ -375,20 +375,20 @@ namespace CairoChart {
var show_time = ccs[ci].show_time;
var show_y = ccs[ci].show_y;
chart.set_source_rgba(chart.bg_color);
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();
if (show_x) {
chart.set_source_rgba(s.axis_x.color);
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);
if (chart.joint_x) chart.set_source_rgba (chart.joint_axis_color);
if (chart.joint_x) chart.color = chart.joint_axis_color;
text_t.show(chart.context);
}
if (show_time) {
chart.set_source_rgba(s.axis_x.color);
chart.color = s.axis_x.color;
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);
@ -396,12 +396,12 @@ namespace CairoChart {
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);
if (chart.joint_x) chart.set_source_rgba (chart.joint_axis_color);
if (chart.joint_x) chart.color = chart.joint_axis_color;
text_t.show(chart.context);
}
if (show_date) {
chart.set_source_rgba(s.axis_x.color);
chart.color = s.axis_x.color;
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);
@ -409,16 +409,16 @@ namespace CairoChart {
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);
if (chart.joint_x) chart.set_source_rgba (chart.joint_axis_color);
if (chart.joint_x) chart.color = chart.joint_axis_color;
text_t.show(chart.context);
}
if (show_y) {
chart.set_source_rgba(s.axis_y.color);
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);
if (chart.joint_y) chart.set_source_rgba (chart.joint_axis_color);
if (chart.joint_y) chart.color = chart.joint_axis_color;
text_t.show(chart.context);
}
}

View File

@ -70,7 +70,7 @@ namespace CairoChart {
y0 = (chart.height - height) / 2;
break;
}
chart.set_source_rgba(bg_color);
chart.color = bg_color;
chart.context.rectangle (x0, y0, width, height);
chart.context.fill();
border_style.set(chart);
@ -144,7 +144,7 @@ namespace CairoChart {
// series title
chart.context.move_to (x + line_length, y);
chart.set_source_rgba (s.title.color);
chart.color = s.title.color;
s.title.show(chart.context);
// series line style

View File

@ -26,7 +26,7 @@ namespace CairoChart {
}
public void set (Chart chart) {
chart.set_source_rgba(color);
chart.color = color;
chart.context.set_line_join(join);
chart.context.set_line_cap(cap);
chart.context.set_line_width(width);

View File

@ -193,8 +193,8 @@ namespace CairoChart {
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) {
if (joint_x) chart.set_source_rgba(chart.joint_axis_color);
else chart.set_source_rgba(axis_x.color);
if (joint_x) chart.color = chart.joint_axis_color;
else chart.color = axis_x.color;
string text = "", time_text = "";
switch (axis_x.type) {
case Axis.Type.NUMBERS:
@ -316,8 +316,8 @@ namespace CairoChart {
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.set_source_rgba(s.axis_x.color);
if (chart.joint_x) chart.set_source_rgba(chart.joint_axis_color);
chart.color = s.axis_x.color;
if (chart.joint_x) chart.color = chart.joint_axis_color;
s.axis_x.title.show(chart.context);
}
@ -348,8 +348,8 @@ namespace CairoChart {
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) {
if (joint_y) chart.set_source_rgba(chart.joint_axis_color);
else chart.set_source_rgba(axis_y.color);
if (joint_y) chart.color = chart.joint_axis_color;
else chart.color = axis_y.color;
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);
@ -444,8 +444,8 @@ namespace CairoChart {
chart.context.move_to(scr_x, scr_y + sz.height / 2.0);
break;
}
chart.set_source_rgba(s.axis_y.color);
if (chart.joint_y) chart.set_source_rgba(chart.joint_axis_color);
chart.color = s.axis_y.color;
if (chart.joint_y) chart.color = chart.joint_axis_color;
s.axis_y.title.show(chart.context);
}

View File

@ -437,11 +437,11 @@ int main (string[] args) {
var h = text_t.get_height(context);
var x0 = chart.plot_x_max - w - 5;
var y0 = chart.plot_y_min + h + 5;
chart.set_source_rgba(chart.legend.bg_color);
chart.color = chart.legend.bg_color;
context.rectangle (x0, y0 - h, w, h);
context.fill();
context.move_to (x0, y0);
chart.set_source_rgba(chart.joint_axis_color);
chart.color = chart.joint_axis_color;
context.show_text(text);
}