]> git.scottworley.com Git - batteryviewer/commitdiff
Chart margin
authorScott Worley <scottworley@scottworley.com>
Fri, 24 Feb 2023 03:59:01 +0000 (19:59 -0800)
committerScott Worley <scottworley@scottworley.com>
Fri, 24 Feb 2023 04:08:59 +0000 (20:08 -0800)
chart.c

diff --git a/chart.c b/chart.c
index 808a275289830ebf36c179c1063ab704055222ad..835c63dc2c6a310e96ffa0b5da7dfdf2fca2145a 100644 (file)
--- a/chart.c
+++ b/chart.c
@@ -37,18 +37,19 @@ static gboolean bv_chart_draw(GtkWidget *widget, cairo_t *cr) {
   GtkAllocation allocation;
   gtk_widget_get_allocation(widget, &allocation);
 
   GtkAllocation allocation;
   gtk_widget_get_allocation(widget, &allocation);
 
-  float xscale = allocation.width / (priv->maxx - priv->minx);
-  float yscale = allocation.height / (priv->miny - priv->maxy);
+  int margin = 3;
+  float xscale = (allocation.width - 2 * margin) / (priv->maxx - priv->minx);
+  float yscale = (allocation.height - 2 * margin) / (priv->miny - priv->maxy);
   cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);
   struct BVChartPoint *start =
       &g_array_index(priv->points, struct BVChartPoint, 0);
   cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);
   struct BVChartPoint *start =
       &g_array_index(priv->points, struct BVChartPoint, 0);
-  cairo_move_to(cr, xscale * (start->x - priv->minx),
-                yscale * (start->y - priv->maxy));
+  cairo_move_to(cr, xscale * (start->x - priv->minx) + margin,
+                yscale * (start->y - priv->maxy) + margin);
   for (guint i = 1; i < priv->points->len; i++) {
     struct BVChartPoint *p =
         &g_array_index(priv->points, struct BVChartPoint, i);
   for (guint i = 1; i < priv->points->len; i++) {
     struct BVChartPoint *p =
         &g_array_index(priv->points, struct BVChartPoint, i);
-    cairo_line_to(cr, xscale * (p->x - priv->minx),
-                  yscale * (p->y - priv->maxy));
+    cairo_line_to(cr, xscale * (p->x - priv->minx) + margin,
+                  yscale * (p->y - priv->maxy) + margin);
   }
   cairo_stroke(cr);
 
   }
   cairo_stroke(cr);