From d32370cf8ab4ff0df2f8830c21129348b578ec67 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Sat, 17 Feb 2018 21:36:59 +0300 Subject: [PATCH] Fixes #160: All .{h,v}spacing fxd. --- src/Axis.vala | 14 +++++++------- src/Chart.vala | 4 ++-- src/Font.vala | 10 +++++----- src/Legend.vala | 26 +++++++++++++------------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Axis.vala b/src/Axis.vala index 9e392a0..a7faab1 100644 --- a/src/Axis.vala +++ b/src/Axis.vala @@ -305,7 +305,7 @@ namespace CairoChart { } } - var max_rec_spacing = is_x ? font.vspacing : font.hspacing; + var max_rec_spacing = 2 * (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; @@ -387,7 +387,7 @@ namespace CairoChart { if (nskip != 0) {--nskip; return;} var max_rec_width = 0.0, max_rec_height = 0.0; calc_rec_sizes (this, out max_rec_width, out max_rec_height, is_x); - var max_rec_spacing = is_x ? font.vspacing : font.hspacing; + var max_rec_spacing = 2 * (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; @@ -445,8 +445,8 @@ namespace CairoChart { switch (axis.dtype) { 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); + max_rec_width = double.max (max_rec_width, text.width + (horizontal ? text.font.hspacing : 0)); + max_rec_height = double.max (max_rec_height, text.height + (horizontal ? 0 : text.font.vspacing)); break; case DType.DATE_TIME: string date, time; @@ -455,12 +455,12 @@ namespace CairoChart { var h = 0.0; if (axis.date_format != "") { var text = new Text (chart, date + (horizontal ? "_" : ""), axis.font); - max_rec_width = double.max (max_rec_width, text.width); + max_rec_width = double.max (max_rec_width, text.width + text.font.hspacing); h = text.height; } if (axis.time_format != "") { var text = new Text (chart, time + (horizontal ? "_" : ""), axis.font); - max_rec_width = double.max (max_rec_width, text.width); + max_rec_width = double.max (max_rec_width, text.width + text.font.hspacing); h += text.height; } max_rec_height = double.max (max_rec_height, h); @@ -497,7 +497,7 @@ namespace CairoChart { 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_height = double.max (max_rec_height, tmp_max_rec_height); - max_rec_spacing = double.max (max_rec_spacing, is_x ? a2.font.vspacing : a2.font.hspacing); + max_rec_spacing = double.max (max_rec_spacing, 2 * (is_x ? a2.font.vspacing : a2.font.hspacing)); max_title_size = double.max ( max_title_size, a2.title.text == "" ? 0 diff --git a/src/Chart.vala b/src/Chart.vala index e6b19b0..95f22a7 100644 --- a/src/Chart.vala +++ b/src/Chart.vala @@ -413,9 +413,9 @@ namespace CairoChart { title.show(); } 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(ref nskip); - 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(ref nskip); } protected virtual void draw_series () { diff --git a/src/Font.vala b/src/Font.vala index d9065ae..857975a 100644 --- a/src/Font.vala +++ b/src/Font.vala @@ -34,12 +34,12 @@ namespace CairoChart { /** * Vertical spacing. */ - public double vspacing = 4; + public double vspacing = 2; /** * Horizontal spacing. */ - public double hspacing = 4; + public double hspacing = 2; /** * Both vertical & horizontal spacing (set only). @@ -51,7 +51,7 @@ namespace CairoChart { set { vspacing = hspacing = value; } - default = 4; + default = 2; } /** @@ -67,8 +67,8 @@ namespace CairoChart { Cairo.FontSlant slant = Cairo.FontSlant.NORMAL, Cairo.FontWeight weight = Cairo.FontWeight.NORMAL, Gtk.Orientation orient = Gtk.Orientation.HORIZONTAL, - double vspacing = 4, - double hspacing = 4 + double vspacing = 2, + double hspacing = 2 ) { this.family = family; this.size = size; diff --git a/src/Legend.vala b/src/Legend.vala index 2576605..54a9196 100644 --- a/src/Legend.vala +++ b/src/Legend.vala @@ -180,8 +180,8 @@ namespace CairoChart { switch (position) { case Position.TOP: case Position.BOTTOM: - var ser_title_width = s.title.width + line_length; - if (leg_width_sum + (leg_width_sum == 0 ? 0 : s.title.font.hspacing) + ser_title_width > chart.area.width) { // carry + var ser_title_width = line_length + s.title.width + s.title.font.hspacing * 2; + if (leg_width_sum + ser_title_width > chart.area.width) { // carry leg_height_sum += max_font_h; switch (process_type) { case ProcessType.CALC: @@ -200,43 +200,43 @@ namespace CairoChart { switch (process_type) { case ProcessType.DRAW: - var x = legend_x0 + leg_width_sum + (leg_width_sum == 0 ? 0 : s.title.font.hspacing); - var y = legend_y0 + leg_height_sum + mfh[heights_idx] / 2 + s.title.height / 2; + var x = legend_x0 + leg_width_sum + s.title.font.hspacing; + var y = legend_y0 + leg_height_sum + mfh[heights_idx] / 2; // series title - chart.ctx.move_to (x + line_length, y); + chart.ctx.move_to (x + line_length, y + s.title.height / 2); chart.color = s.title.color; s.title.show(); // series line style - chart.ctx.move_to (x, y - s.title.height / 2); + chart.ctx.move_to (x, y); s.line_style.apply(chart); chart.ctx.rel_line_to (line_length, 0); chart.ctx.stroke(); - s.marker.draw_at_pos (Point(x + line_length / 2, y - s.title.height / 2)); + s.marker.draw_at_pos (Point(x + line_length / 2, y)); break; } switch (position) { case Position.TOP: case Position.BOTTOM: - var ser_title_width = s.title.width + line_length; - leg_width_sum += (leg_width_sum == 0 ? 0 : s.title.font.hspacing) + ser_title_width; - max_font_h = double.max (max_font_h, s.title.height) + (leg_height_sum != 0 ? s.title.font.vspacing : 0); + var ser_title_width = line_length + s.title.width + s.title.font.hspacing * 2; + leg_width_sum += ser_title_width; + max_font_h = double.max (max_font_h, s.title.height + s.title.font.vspacing * 2); break; case Position.LEFT: case Position.RIGHT: switch (process_type) { case ProcessType.CALC: - mfh += s.title.height + (leg_height_sum != 0 ? s.title.font.vspacing : 0); - width = double.max (width, s.title.width + line_length); + mfh += s.title.height + s.title.font.vspacing * 2; + width = double.max (width, s.title.font.hspacing * 2 + line_length + s.title.width); break; case ProcessType.DRAW: heights_idx++; break; } - leg_height_sum += s.title.height + (leg_height_sum != 0 ? s.title.font.vspacing : 0); + leg_height_sum += s.title.height + s.title.font.vspacing * 2; break; } }