In progress...

This commit is contained in:
Kolan Sh 2018-01-16 14:59:00 +03:00
parent e682d881ff
commit 597007a6f9
2 changed files with 59 additions and 60 deletions

View File

@ -9,7 +9,7 @@ namespace CairoChart {
public Cairo.Context context = null;
public Color bg_color;
public Color bg_color = Color(1, 1, 1);
public Text title = new Text ("Cairo Chart");
public Color border_color = Color(0, 0, 0, 0.3);
@ -56,7 +56,6 @@ namespace CairoChart {
public Cursors.CursorCrossings[] cursors_crossings = {};
public Chart () {
bg_color = Color (1, 1, 1);
}
public Chart copy () {

View File

@ -189,82 +189,82 @@ namespace CairoChart {
}
}
protected virtual void draw_horizontal_records (Chart chart, Series s, Float128 step, double max_rec_height, Float128 x_min) {
protected virtual void draw_horizontal_records (Chart chart, Float128 step, double max_rec_height, Float128 x_min) {
// 5. Draw records, update cur_{x,y}_{min,max}.
var context = chart.context;
var joint_x = chart.joint_x;
for (Float128 x = x_min, x_max = s.axis_x.zoom_max; chart.math.point_belong (x, x_min, x_max); x += step) {
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(s.axis_x.color);
else chart.set_source_rgba(axis_x.color);
string text = "", time_text = "";
switch (s.axis_x.type) {
switch (axis_x.type) {
case Axis.Type.NUMBERS:
text = s.axis_x.format.printf((LongDouble)x);
text = axis_x.format.printf((LongDouble)x);
break;
case Axis.Type.DATE_TIME:
s.axis_x.format_date_time(x, out text, out time_text);
axis_x.format_date_time(x, out text, out time_text);
break;
}
var scr_x = chart.get_scr_x (s, x);
var text_t = new Text(text, s.axis_x.font_style, s.axis_x.color);
var sz = s.axis_x.title.get_size(context);
var scr_x = chart.get_scr_x (this, x);
var text_t = new Text(text, axis_x.font_style, axis_x.color);
var sz = axis_x.title.get_size(context);
switch (s.axis_x.position) {
switch (axis_x.position) {
case Axis.Position.LOW:
var print_y = chart.cur_y_max - s.axis_x.font_indent - (s.axis_x.title.text == "" ? 0 : sz.height + s.axis_x.font_indent);
var print_x = s.compact_rec_x_pos (x, text_t);
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);
switch (s.axis_x.type) {
switch (axis_x.type) {
case Axis.Type.NUMBERS:
text_t.show(context);
break;
case Axis.Type.DATE_TIME:
if (s.axis_x.date_format != "") text_t.show(context);
var time_text_t = new Text(time_text, s.axis_x.font_style, s.axis_x.color);
print_x = s.compact_rec_x_pos (x, time_text_t);
context.move_to (print_x, print_y - (s.axis_x.date_format == "" ? 0 : text_t.get_height(context) + s.axis_x.font_indent));
if (s.axis_x.time_format != "") time_text_t.show(context);
if (axis_x.date_format != "") text_t.show(context);
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);
break;
}
// 6. Draw grid lines to the s.place.zoom_y_min.
var line_style = s.grid.line_style;
// 6. Draw grid lines to the place.zoom_y_min.
var line_style = grid.line_style;
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 - s.axis_x.font_indent - (s.axis_x.title.text == "" ? 0 : sz.height + s.axis_x.font_indent);
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);
if (joint_x)
context.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) * s.place.zoom_y_max));
context.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 + s.axis_x.font_indent + (s.axis_x.title.text == "" ? 0 : sz.height + s.axis_x.font_indent);
var print_x = s.compact_rec_x_pos (x, text_t);
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);
switch (s.axis_x.type) {
switch (axis_x.type) {
case Axis.Type.NUMBERS:
text_t.show(context);
break;
case Axis.Type.DATE_TIME:
if (s.axis_x.date_format != "") text_t.show(context);
var time_text_t = new Text(time_text, s.axis_x.font_style, s.axis_x.color);
print_x = s.compact_rec_x_pos (x, time_text_t);
context.move_to (print_x, print_y - (s.axis_x.date_format == "" ? 0 : text_t.get_height(context) + s.axis_x.font_indent));
if (s.axis_x.time_format != "") time_text_t.show(context);
if (axis_x.date_format != "") text_t.show(context);
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);
break;
}
// 6. Draw grid lines to the s.place.zoom_y_max.
var line_style = s.grid.line_style;
// 6. Draw grid lines to the place.zoom_y_max.
var line_style = grid.line_style;
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 + s.axis_x.font_indent + (s.axis_x.title.text == "" ? 0 : sz.height + s.axis_x.font_indent);
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);
if (joint_x)
context.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) * s.place.zoom_y_min));
context.line_to (scr_x, double.max (y, chart.plot_y_max - (chart.plot_y_max - chart.plot_y_min) * place.zoom_y_min));
break;
}
}
@ -323,7 +323,7 @@ namespace CairoChart {
s.axis_x.title.show(chart.context);
}
draw_horizontal_records (chart, s, step, max_rec_height, x_min);
s.draw_horizontal_records (chart, step, max_rec_height, x_min);
chart.context.stroke ();
@ -344,52 +344,52 @@ namespace CairoChart {
}
}
protected virtual void draw_vertical_records (Chart chart, Series s, Float128 step, double max_rec_width, Float128 y_min) {
protected virtual void draw_vertical_records (Chart chart, Float128 step, double max_rec_width, Float128 y_min) {
// 5. Draw records, update cur_{x,y}_{min,max}.
var context = chart.context;
var joint_y = chart.joint_y;
for (Float128 y = y_min, y_max = s.axis_y.zoom_max; chart.math.point_belong (y, y_min, y_max); y += step) {
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(s.axis_y.color);
var text = s.axis_y.format.printf((LongDouble)y);
var scr_y = chart.get_scr_y (s, y);
var text_t = new Text(text, s.axis_y.font_style, s.axis_y.color);
else chart.set_source_rgba(axis_y.color);
var text = axis_y.format.printf((LongDouble)y);
var scr_y = chart.get_scr_y (this, y);
var text_t = new Text(text, axis_y.font_style, axis_y.color);
var text_sz = text_t.get_size(context);
var sz = s.axis_y.title.get_size(context);
var sz = axis_y.title.get_size(context);
switch (s.axis_y.position) {
switch (axis_y.position) {
case Axis.Position.LOW:
context.move_to (chart.cur_x_min + max_rec_width - text_sz.width + s.axis_y.font_indent
+ (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_indent),
s.compact_rec_y_pos (y, text_t));
context.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);
// 6. Draw grid lines to the s.place.zoom_x_min.
var line_style = s.grid.line_style;
// 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 + s.axis_y.font_indent + (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_indent);
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);
if (joint_y)
context.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) * s.place.zoom_x_max), scr_y);
context.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 - s.axis_y.font_indent
- (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_indent),
s.compact_rec_y_pos (y, text_t));
context.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);
// 6. Draw grid lines to the s.place.zoom_x_max.
var line_style = s.grid.line_style;
// 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 - s.axis_y.font_indent - (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_indent);
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);
if (joint_y)
context.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) * s.place.zoom_x_min), scr_y);
context.line_to (double.min (x, chart.plot_x_min + (chart.plot_x_max - chart.plot_x_min) * place.zoom_x_min), scr_y);
break;
}
}
@ -451,7 +451,7 @@ namespace CairoChart {
s.axis_y.title.show(chart.context);
}
draw_vertical_records (chart, s, step, max_rec_width, y_min);
s.draw_vertical_records (chart, step, max_rec_width, y_min);
chart.context.stroke ();