From 42b846fa75fee632bc85ab33482af1fda294dae9 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Fri, 6 Oct 2017 22:46:28 +0300 Subject: [PATCH] Fix width/height when context is out of the Chart. --- src/Chart.vala | 17 ++++------------- test/ChartTest.vala | 2 ++ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Chart.vala b/src/Chart.vala index 1328fe7..281f4a8 100644 --- a/src/Chart.vala +++ b/src/Chart.vala @@ -1,8 +1,8 @@ namespace Gtk.CairoChart { public class Chart { - protected double width = 0; - protected double height = 0; + public double width = 0; + public double height = 0; public Cairo.Context context = null; @@ -35,9 +35,9 @@ namespace Gtk.CairoChart { } protected double cur_x_min = 0.0; - protected double cur_x_max = 0.0; + protected double cur_x_max = 1.0; protected double cur_y_min = 0.0; - protected double cur_y_max = 0.0; + protected double cur_y_max = 1.0; public virtual void check_cur_values () { if (cur_x_min > cur_x_max) @@ -48,8 +48,6 @@ namespace Gtk.CairoChart { public virtual bool draw () { - update_size (); - draw_background (); cur_x_min = cur_y_min = 0.0; @@ -84,13 +82,6 @@ namespace Gtk.CairoChart { return true; } - protected virtual void update_size () { - if (context != null) { - width = context.copy_clip_rectangle_list().rectangles[0].width; - height = context.copy_clip_rectangle_list().rectangles[0].height; - } - } - protected virtual void set_source_rgba (Color color) { context.set_source_rgba (color.red, color.green, color.blue, color.alpha); } diff --git a/test/ChartTest.vala b/test/ChartTest.vala index 1cfb4a9..f3db13a 100644 --- a/test/ChartTest.vala +++ b/test/ChartTest.vala @@ -341,6 +341,8 @@ int main (string[] args) { // user's pre draw operations here... chart.context = context; + chart.width = da.get_allocated_width(); + chart.height = da.get_allocated_height(); /*var ret = */chart.draw(); // user's post draw operations here...