In progress...

This commit is contained in:
Kolan Sh 2018-01-17 10:18:47 +03:00
parent 621dd5f685
commit df3c3b1693
4 changed files with 23 additions and 26 deletions

View File

@ -2,10 +2,10 @@ namespace CairoChart {
public class Chart { public class Chart {
public double x_min = 0.0; /**
public double y_min = 0.0; * Chart Position.
public double width = 0.0; */
public double height = 0.0; public Cairo.Rectangle pos = Cairo.Rectangle();
public Cairo.Context context = null; public Cairo.Context context = null;
@ -69,7 +69,6 @@ namespace CairoChart {
chart.cur_y_max = this.cur_y_max; chart.cur_y_max = this.cur_y_max;
chart.cur_y_min = this.cur_y_min; chart.cur_y_min = this.cur_y_min;
chart.cursors = this.cursors.copy(); chart.cursors = this.cursors.copy();
chart.height = this.height;
chart.legend = this.legend.copy(); chart.legend = this.legend.copy();
chart.plot_x_max = this.plot_x_max; chart.plot_x_max = this.plot_x_max;
chart.plot_x_min = this.plot_x_min; chart.plot_x_min = this.plot_x_min;
@ -85,9 +84,7 @@ namespace CairoChart {
chart.title_height = this.title_height; chart.title_height = this.title_height;
chart.title_indent = this.title_indent; chart.title_indent = this.title_indent;
chart.title_width = this.title_width; chart.title_width = this.title_width;
chart.width = this.width; chart.pos = this.pos;
chart.x_min = this.x_min;
chart.y_min = this.y_min;
chart.zoom_first_show = this.zoom_first_show; chart.zoom_first_show = this.zoom_first_show;
return chart; return chart;
} }
@ -115,10 +112,10 @@ namespace CairoChart {
public virtual bool draw () { public virtual bool draw () {
cur_x_min = x_min; cur_x_min = pos.x;
cur_y_min = y_min; cur_y_min = pos.y;
cur_x_max = x_min + width; cur_x_max = pos.x + pos.width;
cur_y_max = y_min + height; cur_y_max = pos.y + pos.height;
draw_chart_title (); draw_chart_title ();
check_cur_values (); check_cur_values ();
@ -154,7 +151,7 @@ namespace CairoChart {
title_height = sz.height + (legend.position == Legend.Position.TOP ? title_indent * 2 : title_indent); title_height = sz.height + (legend.position == Legend.Position.TOP ? title_indent * 2 : title_indent);
cur_y_min += title_height; cur_y_min += title_height;
color = title.color; color = title.color;
context.move_to (width/2 - sz.width/2, sz.height + title_indent); context.move_to (pos.width/2 - sz.width/2, sz.height + title_indent);
title.show(context); title.show(context);
} }
public virtual void draw_selection (Cairo.Rectangle rect) { public virtual void draw_selection (Cairo.Rectangle rect) {

View File

@ -301,10 +301,10 @@ namespace CairoChart {
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.y_min + chart.height - s.axis_x.font_indent case Axis.Position.LOW: print_y = chart.pos.y + chart.pos.height - s.axis_x.font_indent
- (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: print_y = chart.y_min + chart.title_height + s.axis_x.font_indent case Axis.Position.HIGH: print_y = chart.pos.y + chart.title_height + s.axis_x.font_indent
+ (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:
@ -348,11 +348,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.x_min + s.axis_y.font_indent print_x = chart.pos.x + s.axis_y.font_indent
+ (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.x_min + chart.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.context) - s.axis_y.font_indent
- (chart.legend.position == Legend.Position.RIGHT ? chart.legend.width : 0); - (chart.legend.position == Legend.Position.RIGHT ? chart.legend.width : 0);
break; break;
} }

View File

@ -51,23 +51,23 @@ namespace CairoChart {
if (chart.context != null) { if (chart.context != null) {
switch (position) { switch (position) {
case Position.TOP: case Position.TOP:
x0 = (chart.width - width) / 2; x0 = (chart.pos.width - width) / 2;
y0 = chart.title_height; y0 = chart.title_height;
break; break;
case Position.BOTTOM: case Position.BOTTOM:
x0 = (chart.width - width) / 2; x0 = (chart.pos.width - width) / 2;
y0 = chart.height - height; y0 = chart.pos.height - height;
break; break;
case Position.LEFT: case Position.LEFT:
x0 = 0; x0 = 0;
y0 = (chart.height - height) / 2; y0 = (chart.pos.height - height) / 2;
break; break;
case Position.RIGHT: case Position.RIGHT:
x0 = chart.width - width; x0 = chart.pos.width - width;
y0 = (chart.height - height) / 2; y0 = (chart.pos.height - height) / 2;
break; break;
} }
chart.color = bg_color; chart.color = bg_color;
@ -120,7 +120,7 @@ namespace CairoChart {
case Position.TOP: case Position.TOP:
case Position.BOTTOM: case Position.BOTTOM:
var ser_title_width = title_sz.width + line_length; var ser_title_width = title_sz.width + line_length;
if (leg_width_sum + (leg_width_sum == 0 ? 0 : text_hspace) + ser_title_width > chart.width) { // carry if (leg_width_sum + (leg_width_sum == 0 ? 0 : text_hspace) + ser_title_width > chart.pos.width) { // carry
leg_height_sum += max_font_h; leg_height_sum += max_font_h;
switch (process_type) { switch (process_type) {
case ProcessType.CALC: case ProcessType.CALC:

View File

@ -415,8 +415,8 @@ int main (string[] args) {
da.draw.connect((context) => { da.draw.connect((context) => {
chart.context = context; chart.context = context;
chart.width = da.get_allocated_width(); chart.pos.width = da.get_allocated_width();
chart.height = da.get_allocated_height(); chart.pos.height = da.get_allocated_height();
chart.clear(); chart.clear();
// user's pre draw operations here... // user's pre draw operations here...