OK In progress...

This commit is contained in:
Kolan Sh 2018-01-23 20:40:23 +03:00
parent 74ba064a56
commit 21f8e595ec
3 changed files with 40 additions and 40 deletions

View File

@ -270,7 +270,7 @@ namespace CairoChart {
: chart.plarea.height * place.zrange / max_rec_height);
// 3. Calculate grid step.
Float128 step = Math.calc_round_step (range.zrange / max_nrecs, dtype == Axis.DType.DATE_TIME);
Float128 step = Math.calc_round_step (range.zrange / max_nrecs, dtype == DType.DATE_TIME);
if (step > range.zrange)
step = range.zrange;
@ -294,11 +294,11 @@ namespace CairoChart {
if (is_x) tmp = max_rec_height + font.vspacing;
else tmp = max_rec_width + font.hspacing;
switch (position) {
case Axis.Position.LOW:
case Position.LOW:
if (is_x) chart.evarea.y1 -= tmp;
else chart.evarea.x0 += tmp;
break;
case Axis.Position.HIGH:
case Position.HIGH:
if (is_x) chart.evarea.y0 += tmp;
else chart.evarea.x1 -= tmp;
break;
@ -311,19 +311,19 @@ namespace CairoChart {
var scr_x = chart.plarea.x0 + chart.plarea.width * (place.zmin + place.zmax) / 2;
var scr_y = 0.0;
switch (position) {
case Axis.Position.LOW: scr_y = chart.evarea.y1 - font.vspacing; break;
case Axis.Position.HIGH: scr_y = chart.evarea.y0 + font.vspacing + title.height; break;
case Position.LOW: scr_y = chart.evarea.y1 - font.vspacing; break;
case Position.HIGH: scr_y = chart.evarea.y0 + font.vspacing + title.height; break;
}
chart.ctx.move_to(scr_x - title.width / 2, scr_y);
chart.color = color;
} else {
var scr_y = chart.plarea.y0 + chart.plarea.height * (1 - (place.zmin + place.zmax) / 2);
switch (position) {
case Axis.Position.LOW:
case Position.LOW:
var scr_x = chart.evarea.x0 + font.hspacing + title.width;
chart.ctx.move_to(scr_x, scr_y + title.height / 2);
break;
case Axis.Position.HIGH:
case Position.HIGH:
var scr_x = chart.evarea.x1 - font.hspacing;
chart.ctx.move_to(scr_x, scr_y + title.height / 2);
break;
@ -350,11 +350,11 @@ namespace CairoChart {
if (is_x) tmp = max_rec_height + font.vspacing + (title.text == "" ? 0 : title.height + font.vspacing);
else tmp = max_rec_width + font.hspacing + (title.text == "" ? 0 : title.width + font.hspacing);
switch (position) {
case Axis.Position.LOW:
case Position.LOW:
if (is_x) chart.evarea.y1 -= tmp;
else chart.evarea.x0 += tmp;
break;
case Axis.Position.HIGH:
case Position.HIGH:
if (is_x) chart.evarea.y0 += tmp;
else chart.evarea.x1 -= tmp;
break;
@ -390,8 +390,8 @@ namespace CairoChart {
if (is_x && chart.joint_x) {
var tmp = max_rec_height + axis.font.vspacing;
switch (axis.position) {
case Axis.Position.LOW: chart.plarea.y1 -= tmp; break;
case Axis.Position.HIGH: chart.plarea.y0 += tmp; break;
case Position.LOW: chart.plarea.y1 -= tmp; break;
case Position.HIGH: chart.plarea.y0 += tmp; break;
}
}
break;
@ -399,8 +399,8 @@ namespace CairoChart {
if (!is_x && chart.joint_y) {
var tmp = max_rec_width + font.hspacing;
switch (position) {
case Axis.Position.LOW: chart.plarea.x0 += tmp; break;
case Axis.Position.HIGH: chart.plarea.x1 -= tmp; break;
case Position.LOW: chart.plarea.x0 += tmp; break;
case Position.HIGH: chart.plarea.x1 -= tmp; break;
}
}
break;
@ -409,15 +409,15 @@ namespace CairoChart {
if (is_x && (!chart.joint_x || si == chart.zoom_1st_idx)) {
var tmp = max_rec_height + max_font_spacing + max_axis_font_height;
switch (axis.position) {
case Axis.Position.LOW: chart.plarea.y1 -= tmp; break;
case Axis.Position.HIGH: chart.plarea.y0 += tmp; break;
case Position.LOW: chart.plarea.y1 -= tmp; break;
case Position.HIGH: chart.plarea.y0 += tmp; break;
}
}
if (!is_x && (!chart.joint_y || si == chart.zoom_1st_idx)) {
var tmp = max_rec_width + max_font_spacing + max_axis_font_width;
switch (position) {
case Axis.Position.LOW: chart.plarea.x0 += tmp; break;
case Axis.Position.HIGH: chart.plarea.x1 -= tmp; break;
case Position.LOW: chart.plarea.x0 += tmp; break;
case Position.HIGH: chart.plarea.x1 -= tmp; break;
}
}
}
@ -427,12 +427,12 @@ namespace CairoChart {
for (var i = 0; i < axis.nrecords; ++i) {
Float128 x = (int64)(axis.range.zmin + axis.range.zrange / axis.nrecords * i) + 1/3.0;
switch (axis.dtype) {
case Axis.DType.NUMBERS:
case DType.NUMBERS:
var text = new Text (chart, axis.format.printf((LongDouble)x) + (horizontal ? "_" : ""), axis.font);
max_rec_width = double.max (max_rec_width, text.width);
max_rec_height = double.max (max_rec_height, text.height);
break;
case Axis.DType.DATE_TIME:
case DType.DATE_TIME:
string date, time;
axis.print_dt(x, out date, out time);
@ -504,8 +504,8 @@ namespace CairoChart {
chart.color = color;
string text = "", time_text = ""; var time_text_t = new Text(chart); var crpt = 0.0;
switch (dtype) {
case Axis.DType.NUMBERS: text = format.printf((LongDouble)v); break;
case Axis.DType.DATE_TIME:
case DType.NUMBERS: text = format.printf((LongDouble)v); break;
case DType.DATE_TIME:
print_dt(v, out text, out time_text);
time_text_t = new Text(chart, time_text, font, color);
crpt = compact_rec_pos (v, time_text_t);
@ -522,7 +522,7 @@ namespace CairoChart {
if (is_x) {
var crp = compact_rec_pos (v, text_t);
switch (position) {
case Axis.Position.LOW:
case Position.LOW:
chart.ctx.move_to (crp, ey1); text_t.show();
chart.ctx.move_to (crpt, ey1 - dtf); time_text_t.show();
ser.axis_x.grid_style.apply(chart);
@ -530,7 +530,7 @@ namespace CairoChart {
if (chart.joint_x) chart.ctx.line_to (scr_v, py0);
else chart.ctx.line_to (scr_v, double.min (y, py0 + ph * (1 - ser.axis_y.place.zmax)));
break;
case Axis.Position.HIGH:
case Position.HIGH:
chart.ctx.move_to (crp, ey0); text_t.show();
chart.ctx.move_to (crpt, ey0 - dtf); time_text_t.show();
ser.axis_x.grid_style.apply(chart); chart.ctx.move_to (scr_v, ey0);
@ -541,14 +541,14 @@ namespace CairoChart {
} else {
var crp = compact_rec_pos (v, text_t);
switch (position) {
case Axis.Position.LOW:
case Position.LOW:
chart.ctx.move_to (ex0 - text_t.width, crp);
text_t.show(); ser.axis_y.grid_style.apply(chart);
chart.ctx.move_to (ex0, scr_v);
if (chart.joint_y) chart.ctx.line_to (chart.plarea.x1, scr_v);
else chart.ctx.line_to (double.max (ex0, px0 + pw * ser.axis_x.place.zmax), scr_v);
break;
case Axis.Position.HIGH:
case Position.HIGH:
chart.ctx.move_to (ex1 - text_t.width, crp);
text_t.show(); ser.axis_y.grid_style.apply(chart);
double x = ex1 - max_rec_size; chart.ctx.move_to (x, scr_v);

View File

@ -9,7 +9,7 @@ namespace CairoChart {
protected List<Point?> list = new List<Point?> ();
protected Point active_cursor = Point(); // { get; protected set; default = Point128 (); }
protected bool is_cursor_active = false; // { get; protected set; default = false; }
protected Cursors.CursorCrossings[] crossings = {};
protected Crossings[] crossings = {};
/**
* ``Cursors`` lines orientation.
@ -58,7 +58,7 @@ namespace CairoChart {
/**
* Cursor style.
*/
public Cursors.Style style = Cursors.Style();
public Style style = Style();
/**
* Has crossings.
@ -116,8 +116,8 @@ namespace CairoChart {
foreach (var c in list) {
double d = distance;
switch (style.orientation) {
case Cursors.Orientation.VERTICAL: d = (rel2scr_x(c.x) - rel2scr_x(active_cursor.x)).abs(); break;
case Cursors.Orientation.HORIZONTAL: d = (rel2scr_y(c.y) - rel2scr_y(active_cursor.y)).abs(); break;
case Orientation.VERTICAL: d = (rel2scr_x(c.x) - rel2scr_x(active_cursor.x)).abs(); break;
case Orientation.HORIZONTAL: d = (rel2scr_y(c.y) - rel2scr_y(active_cursor.y)).abs(); break;
}
if (d < distance) {
distance = d;
@ -205,7 +205,7 @@ namespace CairoChart {
for (var cci = 0, max_cci = crossings.length; cci < max_cci; ++cci) {
var low = Point128(chart.plarea.x1, chart.plarea.y1); // low and high
var high = Point128(chart.plarea.x0, chart.plarea.y0); // points of the cursor
unowned CursorCross[] ccs = crossings[cci].crossings;
unowned Cross[] ccs = crossings[cci].crossings;
style.line_style.apply(chart);
for (var ci = 0, max_ci = ccs.length; ci < max_ci; ++ci) {
var si = ccs[ci].series_index;
@ -393,7 +393,7 @@ namespace CairoChart {
public void eval_crossings () {
var all_cursors = get_all_cursors();
CursorCrossings[] local_cursor_crossings = {};
Crossings[] local_cursor_crossings = {};
for (var ci = 0, max_ci = all_cursors.length(); ci < max_ci; ++ci) {
var c = all_cursors.nth_data(ci);
@ -402,7 +402,7 @@ namespace CairoChart {
case Orientation.HORIZONTAL: if (c.y <= chart.zoom.y0 || c.y >= chart.zoom.y1) continue; break;
}
CursorCross[] crossings = {};
Cross[] crossings = {};
for (var si = 0, max_si = chart.series.length; si < max_si; ++si) {
var s = chart.series[si];
if (!s.zoom_show) continue;
@ -419,7 +419,7 @@ namespace CairoChart {
Point128 size; bool show_x, show_date, show_time, show_y;
cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y);
calc_cross_sizes (s, point, out size, show_x, show_time, show_date, show_y);
CursorCross cc = {si, point, size, show_x, show_date, show_time, show_y};
Cross cc = {si, point, size, show_x, show_date, show_time, show_y};
crossings += cc;
}
break;
@ -431,7 +431,7 @@ namespace CairoChart {
Point128 size; bool show_x, show_date, show_time, show_y;
cross_what_to_show(s, out show_x, out show_time, out show_date, out show_y);
calc_cross_sizes (s, point, out size, show_x, show_time, show_date, show_y);
CursorCross cc = {si, point, size, show_x, show_date, show_time, show_y};
Cross cc = {si, point, size, show_x, show_date, show_time, show_y};
crossings += cc;
}
break;
@ -439,14 +439,14 @@ namespace CairoChart {
}
}
if (crossings.length != 0) {
CursorCrossings ccs = {ci, crossings};
Crossings ccs = {ci, crossings};
local_cursor_crossings += ccs;
}
}
crossings = local_cursor_crossings;
}
protected struct CursorCross {
protected struct Cross {
uint series_index;
Point128 point;
Point128 size;
@ -458,9 +458,9 @@ namespace CairoChart {
Point scr_value_point;
}
protected struct CursorCrossings {
protected struct Crossings {
uint cursor_index;
CursorCross[] crossings;
Cross[] crossings;
}
protected virtual Float128 rel2scr_x(Float128 x) {
@ -482,7 +482,7 @@ namespace CairoChart {
for (var ccsi = 0, max_ccsi = crossings.length; ccsi < max_ccsi; ++ccsi) {
for (var cci = 0, max_cci = crossings[ccsi].crossings.length; cci < max_cci; ++cci) {
// TODO: Ticket #142: find smart algorithm of cursors values placements
unowned CursorCross[] cr = crossings[ccsi].crossings;
unowned Cross[] cr = crossings[ccsi].crossings;
cr[cci].scr_point = chart.series[cr[cci].series_index].scr_pnt (cr[cci].point);
var d_max = double.max (cr[cci].size.x / 1.5, cr[cci].size.y / 1.5);
cr[cci].scr_value_point = Point (cr[cci].scr_point.x + d_max, cr[cci].scr_point.y - d_max);

View File

@ -113,7 +113,7 @@ namespace CairoChart {
switch (position) {
case Position.TOP:
x0 = (chart.area.width - width) / 2;
var title_height = chart.title.height + (chart.legend.position == Legend.Position.TOP ?
var title_height = chart.title.height + (chart.legend.position == Position.TOP ?
chart.title.font.vspacing * 2 : chart.title.font.vspacing);
y0 = title_height;
break;