Merge branch '#153_axis_title_font' into develop

This commit is contained in:
Kolan Sh 2018-01-25 10:37:01 +03:00
commit 2834fa6c59
1 changed files with 57 additions and 39 deletions

View File

@ -250,7 +250,7 @@ namespace CairoChart {
} }
/** /**
* Draws horizontal axis. * Draws axis.
* @param nskip number of series to skip printing. * @param nskip number of series to skip printing.
*/ */
public virtual void draw (ref int nskip) { public virtual void draw (ref int nskip) {
@ -305,6 +305,40 @@ namespace CairoChart {
} }
} }
var max_rec_spacing = is_x ? font.vspacing : font.hspacing;
var max_title_width = title.text == "" ? 0 : title.width + font.hspacing;
var max_title_height = title.text == "" ? 0 : title.height + font.vspacing;
var dx = max_rec_width + max_rec_spacing + max_title_width;
var dy = max_rec_height + max_rec_spacing + max_title_height;
chart.evarea.x0 -= dx; chart.evarea.x1 += dx; chart.evarea.y0 -= dy; chart.evarea.y1 += dy;
if (nskip != 0)
--nskip;
else {
var max_rec_height_all = max_rec_height;
var max_rec_width_all = max_rec_width;
if (is_x)
join_rel_axes (si, true, ref max_rec_width_all, ref max_rec_height_all, ref max_rec_spacing, ref max_title_height, ref nskip);
else
join_rel_axes (si, true, ref max_rec_width_all, ref max_rec_height_all, ref max_rec_spacing, ref max_title_width, ref nskip);
if (is_x && (!chart.joint_x || si == chart.zoom_1st_idx)) {
var tmp = max_rec_height_all + max_rec_spacing + max_title_height;
switch (position) {
case Position.LOW: chart.evarea.y1 -= tmp; break;
case Position.HIGH: chart.evarea.y0 += tmp; break;
}
}
if (!is_x && (!chart.joint_y || si == chart.zoom_1st_idx)) {
var tmp = max_rec_width_all + max_rec_spacing + max_title_width;
switch (position) {
case Position.LOW: chart.evarea.x0 += tmp; break;
case Position.HIGH: chart.evarea.x1 -= tmp; break;
}
}
}
// 4.5. Draw Axis title // 4.5. Draw Axis title
if (title.text != "") { if (title.text != "") {
if (is_x) { if (is_x) {
@ -339,26 +373,9 @@ namespace CairoChart {
if (is_x) draw_recs (min, step, max_rec_height); if (is_x) draw_recs (min, step, max_rec_height);
else draw_recs (min, step, max_rec_width); else draw_recs (min, step, max_rec_width);
chart.evarea.x0 += dx; chart.evarea.x1 -= dx; chart.evarea.y0 += dy; chart.evarea.y1 -= dy;
chart.ctx.stroke (); 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 = 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) {
case Position.LOW:
if (is_x) chart.evarea.y1 -= tmp;
else chart.evarea.x0 += tmp;
break;
case Position.HIGH:
if (is_x) chart.evarea.y0 += tmp;
else chart.evarea.x1 -= tmp;
break;
}
} }
/** /**
@ -366,30 +383,29 @@ namespace CairoChart {
* @param nskip returns number of series to skip printing. * @param nskip returns number of series to skip printing.
*/ */
public virtual void join_axes (ref int nskip) { public virtual void join_axes (ref int nskip) {
Axis axis = this;
if (!ser.zoom_show) return; if (!ser.zoom_show) return;
if (nskip != 0) {--nskip; return;} if (nskip != 0) {--nskip; return;}
var max_rec_width = 0.0, max_rec_height = 0.0; var max_rec_width = 0.0, max_rec_height = 0.0;
calc_rec_sizes (axis, out max_rec_width, out max_rec_height, is_x); calc_rec_sizes (this, out max_rec_width, out max_rec_height, is_x);
var max_font_spacing = is_x ? axis.font.vspacing : axis.font.hspacing; var max_rec_spacing = is_x ? font.vspacing : font.hspacing;
var max_axis_font_width = axis.title.text == "" ? 0 : axis.title.width + axis.font.hspacing; var max_title_width = title.text == "" ? 0 : title.width + font.hspacing;
var max_axis_font_height = axis.title.text == "" ? 0 : axis.title.height + axis.font.vspacing; var max_title_height = title.text == "" ? 0 : title.height + font.vspacing;
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 (is_x) if (is_x)
join_rel_axes (si, true, ref max_rec_width, ref max_rec_height, ref max_font_spacing, ref max_axis_font_height, ref nskip); join_rel_axes (si, true, ref max_rec_width, ref max_rec_height, ref max_rec_spacing, ref max_title_height, ref nskip);
else else
join_rel_axes (si, true, ref max_rec_width, ref max_rec_height, ref max_font_spacing, ref max_axis_font_width, ref nskip); join_rel_axes (si, true, ref max_rec_width, ref max_rec_height, ref max_rec_spacing, ref max_title_width, ref nskip);
// for 4.2. Cursor values for joint X axis // for 4.2. Cursor values for joint X axis
if (si == chart.zoom_1st_idx && chart.cursors.has_crossings) { if (si == chart.zoom_1st_idx && chart.cursors.has_crossings) {
switch (chart.cursors.style.orientation) { switch (chart.cursors.style.orientation) {
case Cursors.Orientation.VERTICAL: case Cursors.Orientation.VERTICAL:
if (is_x && chart.joint_x) { if (is_x && chart.joint_x) {
var tmp = max_rec_height + axis.font.vspacing; var tmp = max_rec_height + font.vspacing;
switch (axis.position) { switch (position) {
case Position.LOW: chart.plarea.y1 -= tmp; break; case Position.LOW: chart.plarea.y1 -= tmp; break;
case Position.HIGH: chart.plarea.y0 += tmp; break; case Position.HIGH: chart.plarea.y0 += tmp; break;
} }
@ -407,14 +423,14 @@ namespace CairoChart {
} }
} }
if (is_x && (!chart.joint_x || si == chart.zoom_1st_idx)) { if (is_x && (!chart.joint_x || si == chart.zoom_1st_idx)) {
var tmp = max_rec_height + max_font_spacing + max_axis_font_height; var tmp = max_rec_height + max_rec_spacing + max_title_height;
switch (axis.position) { switch (position) {
case Position.LOW: chart.plarea.y1 -= tmp; break; case Position.LOW: chart.plarea.y1 -= tmp; break;
case Position.HIGH: chart.plarea.y0 += tmp; break; case Position.HIGH: chart.plarea.y0 += tmp; break;
} }
} }
if (!is_x && (!chart.joint_y || si == chart.zoom_1st_idx)) { if (!is_x && (!chart.joint_y || si == chart.zoom_1st_idx)) {
var tmp = max_rec_width + max_font_spacing + max_axis_font_width; var tmp = max_rec_width + max_rec_spacing + max_title_width;
switch (position) { switch (position) {
case Position.LOW: chart.plarea.x0 += tmp; break; case Position.LOW: chart.plarea.x0 += tmp; break;
case Position.HIGH: chart.plarea.x1 -= tmp; break; case Position.HIGH: chart.plarea.x1 -= tmp; break;
@ -457,8 +473,8 @@ namespace CairoChart {
bool calc_max_values, bool calc_max_values,
ref double max_rec_width, ref double max_rec_width,
ref double max_rec_height, ref double max_rec_height,
ref double max_font_spacing, ref double max_rec_spacing,
ref double max_axis_font_size, ref double max_title_size,
ref int nskip) { ref int nskip) {
for (int sj = si - 1; sj >= 0; --sj) { for (int sj = si - 1; sj >= 0; --sj) {
var s2 = chart.series[sj]; var s2 = chart.series[sj];
@ -481,11 +497,13 @@ namespace CairoChart {
calc_rec_sizes (a2, out tmp_max_rec_width, out tmp_max_rec_height, is_x); calc_rec_sizes (a2, out tmp_max_rec_width, out tmp_max_rec_height, is_x);
max_rec_width = double.max (max_rec_width, tmp_max_rec_width); max_rec_width = double.max (max_rec_width, tmp_max_rec_width);
max_rec_height = double.max (max_rec_height, tmp_max_rec_height); max_rec_height = double.max (max_rec_height, tmp_max_rec_height);
max_font_spacing = double.max (max_font_spacing, is_x ? a2.font.vspacing : a2.font.hspacing); max_rec_spacing = double.max (max_rec_spacing, is_x ? a2.font.vspacing : a2.font.hspacing);
max_axis_font_size = double.max (max_axis_font_size, max_title_size = double.max (
max_title_size,
a2.title.text == "" ? 0 a2.title.text == "" ? 0
: is_x ? a2.title.height + font.vspacing : is_x ? a2.title.height + font.vspacing
: a2.title.width + font.hspacing); : a2.title.width + font.hspacing
);
} }
++nskip; ++nskip;
} else { } else {