OK In progress...

This commit is contained in:
Kolan Sh 2018-01-22 14:31:34 +03:00
parent ded95b77ce
commit bcb847c65e
4 changed files with 46 additions and 45 deletions

View File

@ -1,12 +1,13 @@
namespace CairoChart { namespace CairoChart {
// If one of axis:title or axis:range.min/range.max are different
// then draw separate axis for each/all series /**
// or specify series name near the axis *
*/
public class Axis { public class Axis {
public Range range = new Range(); public Range range = new Range();
Chart chart; Chart chart;
public Text title; public Text title;
public enum Type { public enum DType {
NUMBERS = 0, NUMBERS = 0,
DATE_TIME DATE_TIME
} }
@ -15,7 +16,7 @@ namespace CairoChart {
// LOGARITHMIC, // TODO // LOGARITHMIC, // TODO
// etc // etc
} }
public Type type; public DType dtype;
public ScaleType scale_type; public ScaleType scale_type;
public enum Position { public enum Position {
LOW = 0, LOW = 0,
@ -80,7 +81,7 @@ namespace CairoChart {
axis.position = this.position; axis.position = this.position;
axis.scale_type = this.scale_type; axis.scale_type = this.scale_type;
axis.title = this.title.copy(); axis.title = this.title.copy();
axis.type = this.type; axis.dtype = this.dtype;
axis.nrecords = this.nrecords; axis.nrecords = this.nrecords;
return axis; return axis;
} }
@ -105,13 +106,13 @@ namespace CairoChart {
max_rec_width = max_rec_height = 0; max_rec_width = max_rec_height = 0;
for (var i = 0; i < nrecords; ++i) { for (var i = 0; i < nrecords; ++i) {
Float128 x = (int64)(range.zmin + range.zrange / nrecords * i) + 1.0/3.0; Float128 x = (int64)(range.zmin + range.zrange / nrecords * i) + 1.0/3.0;
switch (type) { switch (dtype) {
case Axis.Type.NUMBERS: case Axis.DType.NUMBERS:
var text = new Text (chart, format.printf((LongDouble)x) + (horizontal ? "_" : ""), font_style); var text = new Text (chart, format.printf((LongDouble)x) + (horizontal ? "_" : ""), font_style);
max_rec_width = double.max (max_rec_width, text.width); max_rec_width = double.max (max_rec_width, text.width);
max_rec_height = double.max (max_rec_height, text.height); max_rec_height = double.max (max_rec_height, text.height);
break; break;
case Axis.Type.DATE_TIME: case Axis.DType.DATE_TIME:
string date, time; string date, time;
format_date_time(x, out date, out time); format_date_time(x, out date, out time);

View File

@ -180,9 +180,9 @@ namespace CairoChart {
case Orientation.VERTICAL: case Orientation.VERTICAL:
show_y = true; show_y = true;
if (!chart.joint_x) if (!chart.joint_x)
switch (s.axis_x.type) { switch (s.axis_x.dtype) {
case Axis.Type.NUMBERS: show_x = true; break; case Axis.DType.NUMBERS: show_x = true; break;
case Axis.Type.DATE_TIME: case Axis.DType.DATE_TIME:
if (s.axis_x.date_format != "") show_date = true; if (s.axis_x.date_format != "") show_date = true;
if (s.axis_x.time_format != "") show_time = true; if (s.axis_x.time_format != "") show_time = true;
break; break;
@ -190,9 +190,9 @@ namespace CairoChart {
break; break;
case Orientation.HORIZONTAL: case Orientation.HORIZONTAL:
if (!chart.joint_y) show_y = true; if (!chart.joint_y) show_y = true;
switch (s.axis_x.type) { switch (s.axis_x.dtype) {
case Axis.Type.NUMBERS: show_x = true; break; case Axis.DType.NUMBERS: show_x = true; break;
case Axis.Type.DATE_TIME: case Axis.DType.DATE_TIME:
if (s.axis_x.date_format != "") show_date = true; if (s.axis_x.date_format != "") show_date = true;
if (s.axis_x.time_format != "") show_time = true; if (s.axis_x.time_format != "") show_time = true;
break; break;
@ -283,9 +283,9 @@ namespace CairoChart {
var s = chart.series[chart.zoom_1st_idx]; var s = chart.series[chart.zoom_1st_idx];
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.dtype) {
case Axis.Type.NUMBERS: text = s.axis_x.format.printf((LongDouble)x); break; case Axis.DType.NUMBERS: text = s.axis_x.format.printf((LongDouble)x); break;
case Axis.Type.DATE_TIME: s.axis_x.format_date_time(x, out text, out time_text); break; case Axis.DType.DATE_TIME: s.axis_x.format_date_time(x, out text, out time_text); break;
} }
var text_t = new Text(chart, text, s.axis_x.font_style, s.axis_x.color); var text_t = new Text(chart, text, s.axis_x.font_style, s.axis_x.color);
var time_text_t = new Text(chart, time_text, s.axis_x.font_style, s.axis_x.color); var time_text_t = new Text(chart, time_text, s.axis_x.font_style, s.axis_x.color);
@ -299,11 +299,11 @@ namespace CairoChart {
chart.title.vspacing * 2 : chart.title.vspacing); chart.title.vspacing * 2 : chart.title.vspacing);
print_y = chart.area.y0 + 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.dtype) {
case Axis.Type.NUMBERS: case Axis.DType.NUMBERS:
print_y += text_t.height; print_y += text_t.height;
break; break;
case Axis.Type.DATE_TIME: case Axis.DType.DATE_TIME:
print_y += (s.axis_x.date_format == "" ? 0 : text_t.height) print_y += (s.axis_x.date_format == "" ? 0 : text_t.height)
+ (s.axis_x.time_format == "" ? 0 : time_text_t.height) + (s.axis_x.time_format == "" ? 0 : time_text_t.height)
+ (s.axis_x.date_format == "" || s.axis_x.time_format == "" ? 0 : s.axis_x.font_spacing); + (s.axis_x.date_format == "" || s.axis_x.time_format == "" ? 0 : s.axis_x.font_spacing);
@ -314,11 +314,11 @@ namespace CairoChart {
var print_x = s.compact_rec_x_pos (x, text_t); var print_x = s.compact_rec_x_pos (x, text_t);
chart.ctx.move_to (print_x, print_y); chart.ctx.move_to (print_x, print_y);
switch (s.axis_x.type) { switch (s.axis_x.dtype) {
case Axis.Type.NUMBERS: case Axis.DType.NUMBERS:
text_t.show(); text_t.show();
break; break;
case Axis.Type.DATE_TIME: case Axis.DType.DATE_TIME:
if (s.axis_x.date_format != "") text_t.show(); if (s.axis_x.date_format != "") text_t.show();
print_x = s.compact_rec_x_pos (x, time_text_t); print_x = s.compact_rec_x_pos (x, time_text_t);
chart.ctx.move_to (print_x, print_y - (s.axis_x.date_format == "" ? 0 : text_t.height + s.axis_x.font_spacing)); chart.ctx.move_to (print_x, print_y - (s.axis_x.date_format == "" ? 0 : text_t.height + s.axis_x.font_spacing));
@ -454,11 +454,11 @@ namespace CairoChart {
var str = ""; var str = "";
var s = chart.series[chart.zoom_1st_idx]; var s = chart.series[chart.zoom_1st_idx];
if (chart.joint_x) if (chart.joint_x)
switch (s.axis_x.type) { switch (s.axis_x.dtype) {
case Axis.Type.NUMBERS: case Axis.DType.NUMBERS:
str = s.axis_x.format.printf((LongDouble)delta); str = s.axis_x.format.printf((LongDouble)delta);
break; break;
case Axis.Type.DATE_TIME: case Axis.DType.DATE_TIME:
var date = "", time = ""; var date = "", time = "";
int64 days = (int64)(delta / 24 / 3600); int64 days = (int64)(delta / 24 / 3600);
s.axis_x.format_date_time(delta, out date, out time); s.axis_x.format_date_time(delta, out date, out time);

View File

@ -98,7 +98,7 @@ namespace CairoChart {
|| axis_x.range.zmax != s.axis_x.range.zmax || axis_x.range.zmax != s.axis_x.range.zmax
|| place.zx0 != s.place.zx0 || place.zx0 != s.place.zx0
|| place.zx1 != s.place.zx1 || place.zx1 != s.place.zx1
|| axis_x.type != s.axis_x.type || axis_x.dtype != s.axis_x.dtype
) )
return false; return false;
return true; return true;
@ -110,7 +110,7 @@ namespace CairoChart {
|| axis_y.range.zmax != s.axis_y.range.zmax || axis_y.range.zmax != s.axis_y.range.zmax
|| place.zy0 != s.place.zy0 || place.zy0 != s.place.zy0
|| place.zy1 != s.place.zy1 || place.zy1 != s.place.zy1
|| axis_y.type != s.axis_y.type || axis_y.dtype != s.axis_y.dtype
) )
return false; return false;
return true; return true;
@ -188,7 +188,7 @@ namespace CairoChart {
if (!s3.zoom_show) continue; if (!s3.zoom_show) continue;
if (Math.coord_cross(s2.place.zx0, s2.place.zx1, s3.place.zx0, s3.place.zx1) if (Math.coord_cross(s2.place.zx0, s2.place.zx1, s3.place.zx0, s3.place.zx1)
|| s2.axis_x.position != s3.axis_x.position || s2.axis_x.position != s3.axis_x.position
|| s2.axis_x.type != s3.axis_x.type) { || s2.axis_x.dtype != s3.axis_x.dtype) {
has_intersection = true; has_intersection = true;
break; break;
} }
@ -226,7 +226,7 @@ namespace CairoChart {
if (!s3.zoom_show) continue; if (!s3.zoom_show) continue;
if (Math.coord_cross(s2.place.zy0, s2.place.zy1, s3.place.zy0, s3.place.zy1) if (Math.coord_cross(s2.place.zy0, s2.place.zy1, s3.place.zy0, s3.place.zy1)
|| s2.axis_y.position != s3.axis_y.position || s2.axis_y.position != s3.axis_y.position
|| s2.axis_y.type != s3.axis_y.type) { || s2.axis_y.dtype != s3.axis_y.dtype) {
has_intersection = true; has_intersection = true;
break; break;
} }
@ -255,9 +255,9 @@ namespace CairoChart {
if (joint_x) chart.color = chart.joint_color; if (joint_x) chart.color = chart.joint_color;
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.dtype) {
case Axis.Type.NUMBERS: text = axis_x.format.printf((LongDouble)x); break; case Axis.DType.NUMBERS: text = axis_x.format.printf((LongDouble)x); break;
case Axis.Type.DATE_TIME: axis_x.format_date_time(x, out text, out time_text); break; case Axis.DType.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(chart, text, axis_x.font_style, axis_x.color); var text_t = new Text(chart, text, axis_x.font_style, axis_x.color);
@ -267,11 +267,11 @@ namespace CairoChart {
var print_y = chart.evarea.y1 - axis_x.font_spacing - (axis_x.title.text == "" ? 0 : axis_x.title.height + axis_x.font_spacing); var print_y = chart.evarea.y1 - axis_x.font_spacing - (axis_x.title.text == "" ? 0 : axis_x.title.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.dtype) {
case Axis.Type.NUMBERS: case Axis.DType.NUMBERS:
text_t.show(); text_t.show();
break; break;
case Axis.Type.DATE_TIME: case Axis.DType.DATE_TIME:
if (axis_x.date_format != "") text_t.show(); if (axis_x.date_format != "") text_t.show();
var time_text_t = new Text(chart, time_text, axis_x.font_style, axis_x.color); var time_text_t = new Text(chart, time_text, axis_x.font_style, axis_x.color);
print_x = compact_rec_x_pos (x, time_text_t); print_x = compact_rec_x_pos (x, time_text_t);
@ -295,11 +295,11 @@ namespace CairoChart {
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.dtype) {
case Axis.Type.NUMBERS: case Axis.DType.NUMBERS:
text_t.show(); text_t.show();
break; break;
case Axis.Type.DATE_TIME: case Axis.DType.DATE_TIME:
if (axis_x.date_format != "") text_t.show(); if (axis_x.date_format != "") text_t.show();
var time_text_t = new Text(chart, time_text, axis_x.font_style, axis_x.color); var time_text_t = new Text(chart, time_text, axis_x.font_style, axis_x.color);
print_x = compact_rec_x_pos (x, time_text_t); print_x = compact_rec_x_pos (x, time_text_t);
@ -335,7 +335,7 @@ namespace CairoChart {
long max_nrecs = (long) (chart.plarea.width * s.place.zwidth / max_rec_width); long max_nrecs = (long) (chart.plarea.width * s.place.zwidth / max_rec_width);
// 3. Calculate grid step. // 3. Calculate grid step.
Float128 step = Math.calc_round_step (s.axis_x.range.zrange / max_nrecs, s.axis_x.type == Axis.Type.DATE_TIME); Float128 step = Math.calc_round_step (s.axis_x.range.zrange / max_nrecs, s.axis_x.dtype == Axis.DType.DATE_TIME);
if (step > s.axis_x.range.zrange) if (step > s.axis_x.range.zrange)
step = s.axis_x.range.zrange; step = s.axis_x.range.zrange;

View File

@ -115,7 +115,7 @@ void plot_chart2 (Chart chart) {
s3.axis_y.title = new Text(chart, "Series 3: Axis Y."); s3.axis_y.title = new Text(chart, "Series 3: Axis Y.");
//s1.axis_x.position = s2.axis_x.position = s3.axis_x.position = Axis.Position.HIGH; //s1.axis_x.position = s2.axis_x.position = s3.axis_x.position = Axis.Position.HIGH;
//s1.axis_x.type = s2.axis_x.type = s3.axis_x.type = Axis.Type.DATE_TIME; //s1.axis_x.dtype = s2.axis_x.dtype = s3.axis_x.dtype = Axis.DType.DATE_TIME;
//s1.axis_x.range.max = s2.axis_x.range.max = s3.axis_x.range.max = 5*24*3600; //s1.axis_x.range.max = s2.axis_x.range.max = s3.axis_x.range.max = 5*24*3600;
chart.series = { s1, s2, s3 }; chart.series = { s1, s2, s3 };
@ -175,9 +175,9 @@ void plot_chart4 (Chart chart) {
var s3 = new Series (chart); var s3 = new Series (chart);
var s4 = new Series (chart); var s4 = new Series (chart);
s1.axis_x.type = Axis.Type.DATE_TIME; s1.axis_x.dtype = Axis.DType.DATE_TIME;
s3.axis_x.type = Axis.Type.DATE_TIME; s3.axis_x.dtype = Axis.DType.DATE_TIME;
s4.axis_x.type = Axis.Type.DATE_TIME; s4.axis_x.dtype = Axis.DType.DATE_TIME;
s4.axis_x.dsec_signs = 5; s4.axis_x.dsec_signs = 5;
var now = new DateTime.now_local().to_unix(); var now = new DateTime.now_local().to_unix();