From a495f6b21701ca9c6b4e6c4767225d945329164b Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Wed, 24 Jan 2018 11:04:18 +0300 Subject: [PATCH] Fixes #155: LabelStyle never used, why? --- src/Cursor.vala | 17 ++++++++++++++++- src/Label.vala | 46 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/Cursor.vala b/src/Cursor.vala index 974f7be..89d7475 100644 --- a/src/Cursor.vala +++ b/src/Cursor.vala @@ -60,6 +60,11 @@ namespace CairoChart { */ public Style style = Style(); + /** + * Value label style. + */ + public LabelStyle label_style = new LabelStyle(); + /** * Has crossings. */ @@ -82,6 +87,7 @@ namespace CairoChart { c.active_cursor = active_cursor; c.is_cursor_active = is_cursor_active; c.style = style; + c.label_style = label_style.copy(); c.crossings = crossings; return c; } @@ -340,9 +346,18 @@ namespace CairoChart { var show_time = ccs[ci].show_time; var show_y = ccs[ci].show_y; - chart.color = chart.bg_color; + // value label background + chart.color = label_style.bg_color; chart.ctx.rectangle (svp.x - size.x / 2, svp.y - size.y / 2, size.x, size.y); chart.ctx.fill(); + // value label frame + label_style.frame_style.apply(chart); + chart.ctx.move_to (svp.x - size.x / 2, svp.y - size.y / 2); + chart.ctx.rel_line_to (size.x, 0); + chart.ctx.rel_line_to (0, size.y); + chart.ctx.rel_line_to (-size.x, 0); + chart.ctx.rel_line_to (0, -size.y); + chart.ctx.stroke(); if (show_x) { chart.color = s.axis_x.color; diff --git a/src/Label.vala b/src/Label.vala index 2983f0f..e47afe4 100644 --- a/src/Label.vala +++ b/src/Label.vala @@ -3,26 +3,44 @@ namespace CairoChart { /** * ``LabelStyle`` Style. */ - public struct LabelStyle { - - /** - * Font style. - */ - Font font; - - /** - * Frame line style. - */ - LineStyle frame_line_style; + public class LabelStyle { /** * Background color. */ - Color bg_color; + public Color bg_color; /** - * Frame/border color. + * Frame line style. */ - Color frame_color; + public LineStyle frame_style; + + /** + * Font style. + */ + public Font font; + + /** + * Constructs a new ``LabelStyle``. + * @param font font style. + * @param bg_color background color. + * @param frame_style frame line style. + */ + public LabelStyle ( + Color bg_color = Color(1, 1, 1, 1), + LineStyle frame_style = LineStyle(Color(0, 0, 0, 0.1)), + Font font = new Font() + ) { + this.bg_color = bg_color; + this.frame_style = frame_style; + this.font = font; + } + + /** + * Gets a copy of the ``LabelStyle``. + */ + public virtual LabelStyle copy () { + return new LabelStyle(bg_color, frame_style, font); + } } }