From: Scott Worley Date: Fri, 24 Feb 2023 03:59:01 +0000 (-0800) Subject: Chart margin X-Git-Url: http://git.scottworley.com/batteryviewer/commitdiff_plain/abe665b44d168ff43c052b47d0517628316cf6d3?ds=sidebyside Chart margin --- diff --git a/chart.c b/chart.c index 808a275..835c63d 100644 --- 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); - 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_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); - 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);