From 4626587d45ab5ffaf76651e9f9230f2fe09a6a13 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Mon, 22 Jan 2018 16:54:54 +0300 Subject: [PATCH] OK In progress... --- src/Chart.vala | 6 +++--- src/Legend.vala | 32 +++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Chart.vala b/src/Chart.vala index 42cfee9..c848812 100644 --- a/src/Chart.vala +++ b/src/Chart.vala @@ -48,7 +48,7 @@ namespace CairoChart { /** * Legend. */ - public Legend legend = new Legend(); + public Legend legend; /** * ``Chart`` Series array. @@ -100,7 +100,7 @@ namespace CairoChart { public Chart () { cursors = new Cursors (this); title = new Text(this, "Cairo Chart"); - + legend = new Legend(this); } /** @@ -147,7 +147,7 @@ namespace CairoChart { draw_title (); fix_evarea (); - legend.draw (this); + legend.draw (); fix_evarea (); rot_axes_titles (); diff --git a/src/Legend.vala b/src/Legend.vala index 9bfc614..3ecd264 100644 --- a/src/Legend.vala +++ b/src/Legend.vala @@ -5,6 +5,8 @@ namespace CairoChart { */ public class Legend { + Chart chart; + /** * ``Legend`` position. */ @@ -53,8 +55,20 @@ namespace CairoChart { public double text_vspace = 2.0; public bool show = true; + /** + * Constructs a new ``Legend``. + * @param chart ``Chart`` instance. + */ + public Legend (Chart chart) { + this.chart = chart; + border_style.color = Color (0, 0, 0, 0.3); + } + + /** + * Gets a copy of the ``Legend``. + */ public virtual Legend copy () { - var legend = new Legend (); + var legend = new Legend (chart); legend.position = this.position; legend.bg_color = this.bg_color; legend.spacing = this.spacing; @@ -68,17 +82,13 @@ namespace CairoChart { return legend; } - public Legend () { - border_style.color = Color (0, 0, 0, 0.3); - } - - public virtual void draw (Chart chart) { + public virtual void draw () { if (!show) return; - process (chart, ProcessType.CALC); - process (chart, ProcessType.DRAW); + process (ProcessType.CALC); + process (ProcessType.DRAW); } - public virtual void draw_rect (Chart chart, out double x0, out double y0) { + public virtual void draw_rect (out double x0, out double y0) { x0 = y0 = 0.0; if (chart.ctx != null) { switch (position) { @@ -123,7 +133,7 @@ namespace CairoChart { } double [] max_font_heights; - public virtual void process (Chart chart, ProcessType process_type) { + public virtual void process (ProcessType process_type) { var legend_x0 = 0.0, legend_y0 = 0.0; var heights_idx = 0; var leg_width_sum = 0.0; @@ -139,7 +149,7 @@ namespace CairoChart { heights_idx = 0; break; case ProcessType.DRAW: - draw_rect(chart, out legend_x0, out legend_y0); + draw_rect(out legend_x0, out legend_y0); break; }