OK In progress...

This commit is contained in:
Kolan Sh 2018-01-23 15:14:54 +03:00
parent 7759d914a0
commit fa93997f27
2 changed files with 71 additions and 118 deletions

View File

@ -287,49 +287,61 @@ namespace CairoChart {
* Draws horizontal axis. * Draws horizontal axis.
* @param nskip number of series to skip printing. * @param nskip number of series to skip printing.
*/ */
public virtual void draw_haxis (ref int nskip) { public virtual void draw (ref int nskip) {
if (!ser.zoom_show) return; if (!ser.zoom_show) return;
var si = Math.find_arr<Series>(chart.series, ser); var si = Math.find_arr<Series>(chart.series, ser);
if (si == -1) return; if (si == -1) return;
if (chart.joint_x && si != chart.zoom_1st_idx) return; if ((is_x && chart.joint_x || !is_x && chart.joint_y) && si != chart.zoom_1st_idx) return;
// 1. Detect max record width/height by axis.nrecords equally selected points using format. // 1. Detect max record width/height by axis.nrecords equally selected points using format.
double max_rec_width, max_rec_height; double max_rec_width, max_rec_height;
calc_rec_sizes (this, out max_rec_width, out max_rec_height, true); calc_rec_sizes (this, out max_rec_width, out max_rec_height, is_x);
// 2. Calculate maximal available number of records, take into account the space width. // 2. Calculate maximal available number of records, take into account the space width.
long max_nrecs = (long) (chart.plarea.width * place.zrange / max_rec_width); long max_nrecs = (long) (is_x ? chart.plarea.width * place.zrange / max_rec_width
: chart.plarea.height * place.zrange / max_rec_height);
// 3. Calculate grid step. // 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 == Axis.DType.DATE_TIME);
if (step > range.zrange) if (step > range.zrange)
step = range.zrange; step = range.zrange;
// 4. Calculate x_min (range.zmin / step, round, multiply on step, add step if < range.zmin). // 4. Calculate min (range.zmin / step, round, multiply on step, add step if < range.zmin).
Float128 x_min = 0; Float128 min = 0;
if (step >= 1) { if (step >= 1) {
int64 x_min_nsteps = (int64) (range.zmin / step); int64 min_nsteps = (int64) (range.zmin / step);
x_min = x_min_nsteps * step; min = min_nsteps * step;
} else { } else {
int64 round_axis_x_min = (int64)range.zmin; int64 round_axis_min = (int64)range.zmin;
int64 x_min_nsteps = (int64) ((range.zmin - round_axis_x_min) / step); int64 min_nsteps = (int64) ((range.zmin - round_axis_min) / step);
x_min = round_axis_x_min + x_min_nsteps * step; min = round_axis_min + min_nsteps * step;
} }
if (x_min < range.zmin) x_min += step; if (min < range.zmin) min += step;
// 4.2. Cursor values for joint X axis // 4.2. Cursor values for joint axes
if (chart.joint_x && chart.cursors.style.orientation == Cursors.Orientation.VERTICAL && chart.cursors.has_crossings) { if (chart.cursors.has_crossings)
var tmp = max_rec_height + font.vspacing; if ( is_x && chart.joint_x && chart.cursors.style.orientation == Cursors.Orientation.VERTICAL
|| !is_x && chart.joint_y && chart.cursors.style.orientation == Cursors.Orientation.HORIZONTAL) {
var tmp = 0.0;
if (is_x) tmp = max_rec_height + font.vspacing;
else tmp = max_rec_width + font.hspacing;
switch (position) { switch (position) {
case Axis.Position.LOW: chart.evarea.y1 -= tmp; break; case Axis.Position.LOW:
case Axis.Position.HIGH: chart.evarea.y0 += tmp; break; if (is_x) chart.evarea.y1 -= tmp;
else chart.evarea.x0 += tmp;
break;
case Axis.Position.HIGH:
if (is_x) chart.evarea.y0 += tmp;
else chart.evarea.x1 -= tmp;
break;
} }
} }
// 4.5. Draw Axis title // 4.5. Draw Axis title
if (title.text != "") { if (title.text != "") {
if (is_x) {
var scr_x = chart.plarea.x0 + chart.plarea.width * (place.zmin + place.zmax) / 2; var scr_x = chart.plarea.x0 + chart.plarea.width * (place.zmin + place.zmax) / 2;
var scr_y = 0.0; var scr_y = 0.0;
switch (position) { switch (position) {
@ -339,71 +351,7 @@ namespace CairoChart {
chart.ctx.move_to(scr_x - title.width / 2, scr_y); chart.ctx.move_to(scr_x - title.width / 2, scr_y);
chart.color = color; chart.color = color;
if (chart.joint_x) chart.color = chart.joint_color; if (chart.joint_x) chart.color = chart.joint_color;
title.show();
}
draw_hrecs (step, max_rec_height, x_min);
chart.ctx.stroke ();
var tmp1 = 0.0, tmp2 = 0.0, tmp3 = 0.0, tmp4 = 0.0;
join_rel_axes (si, false, ref tmp1, ref tmp2, ref tmp3, ref tmp4, ref nskip);
if (nskip != 0) {--nskip; return;}
var tmp = max_rec_height + font.vspacing + (title.text == "" ? 0 : title.height + font.vspacing);
switch (position) {
case Axis.Position.LOW: chart.evarea.y1 -= tmp; break;
case Axis.Position.HIGH: chart.evarea.y0 += tmp; break;
}
}
/**
* Draws vertical axis.
* @param nskip number of series to skip printing.
*/
public virtual void draw_vaxis (ref int nskip) {
if (!ser.zoom_show) return;
var si = Math.find_arr<Series>(chart.series, ser);
if (si == -1) return;
if (chart.joint_y && si != chart.zoom_1st_idx) return;
// 1. Detect max record width/height by axis.nrecords equally selected points using format.
double max_rec_width, max_rec_height;
calc_rec_sizes (this, out max_rec_width, out max_rec_height, false);
// 2. Calculate maximal available number of records, take into account the space width.
long max_nrecs = (long) (chart.plarea.height * place.zrange / max_rec_height);
// 3. Calculate grid step.
Float128 step = Math.calc_round_step (range.zrange / max_nrecs);
if (step > range.zrange)
step = range.zrange;
// 4. Calculate y_min (range.zmin / step, round, multiply on step, add step if < range.zmin).
Float128 y_min = 0;
if (step >= 1) {
int64 y_min_nsteps = (int64) (range.zmin / step);
y_min = y_min_nsteps * step;
} else { } else {
int64 round_axis_y_min = (int64)range.zmin;
int64 y_min_nsteps = (int64) ((range.zmin - round_axis_y_min) / step);
y_min = round_axis_y_min + y_min_nsteps * step;
}
if (y_min < range.zmin) y_min += step;
// 4.2. Cursor values for joint Y axis
if (chart.joint_y && chart.cursors.style.orientation == Cursors.Orientation.HORIZONTAL && chart.cursors.has_crossings) {
var tmp = max_rec_width + font.hspacing;
switch (position) {
case Axis.Position.LOW: chart.evarea.x0 += tmp; break;
case Axis.Position.HIGH: chart.evarea.x1 -= tmp; break;
}
}
// 4.5. Draw Axis title
if (title.text != "") {
var scr_y = chart.plarea.y0 + chart.plarea.height * (1 - (place.zmin + place.zmax) / 2); var scr_y = chart.plarea.y0 + chart.plarea.height * (1 - (place.zmin + place.zmax) / 2);
switch (position) { switch (position) {
case Axis.Position.LOW: case Axis.Position.LOW:
@ -417,10 +365,12 @@ namespace CairoChart {
} }
chart.color = color; chart.color = color;
if (chart.joint_y) chart.color = chart.joint_color; if (chart.joint_y) chart.color = chart.joint_color;
}
title.show(); title.show();
} }
draw_vrecs (step, max_rec_width, y_min); if (is_x) draw_hrecs (step, max_rec_height, min);
else draw_vrecs (step, max_rec_width, min);
chart.ctx.stroke (); chart.ctx.stroke ();
@ -429,10 +379,18 @@ namespace CairoChart {
if (nskip != 0) {--nskip; return;} if (nskip != 0) {--nskip; return;}
var tmp = max_rec_width + font.hspacing + (title.text == "" ? 0 : title.width + font.hspacing); var tmp = 0.0;
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) { switch (position) {
case Axis.Position.LOW: chart.evarea.x0 += tmp; break; case Axis.Position.LOW:
case Axis.Position.HIGH: chart.evarea.x1 -= tmp; break; if (is_x) chart.evarea.y1 -= tmp;
else chart.evarea.x0 += tmp;
break;
case Axis.Position.HIGH:
if (is_x) chart.evarea.y0 += tmp;
else chart.evarea.x1 -= tmp;
break;
} }
} }

View File

@ -156,10 +156,7 @@ namespace CairoChart {
eval_plarea (); eval_plarea ();
draw_haxes (); draw_axes ();
fix_evarea ();
draw_vaxes ();
fix_evarea (); fix_evarea ();
draw_plarea_border (); draw_plarea_border ();
@ -372,13 +369,11 @@ namespace CairoChart {
ctx.move_to (area.width/2 - title.width/2, title.height + title.font.vspacing); ctx.move_to (area.width/2 - title.width/2, title.height + title.font.vspacing);
title.show(); title.show();
} }
protected virtual void draw_haxes () { protected virtual void draw_axes () {
for (var si = series.length - 1, nskip = 0; si >=0; --si) for (var si = series.length - 1, nskip = 0; si >=0; --si)
series[si].axis_x.draw_haxis (ref nskip); series[si].axis_x.draw(ref nskip);
}
protected virtual void draw_vaxes () {
for (var si = series.length - 1, nskip = 0; si >=0; --si) for (var si = series.length - 1, nskip = 0; si >=0; --si)
series[si].axis_y.draw_vaxis (ref nskip); series[si].axis_y.draw(ref nskip);
} }
protected virtual void draw_series () { protected virtual void draw_series () {
foreach (var s in series) foreach (var s in series)