line-visualizer-row: simplify data point rendering

We can use some crafty scale/translations to simplify the
line drawing of data points.
This commit is contained in:
Christian Hergert
2016-09-26 20:08:34 -07:00
parent 63e7e1d1dd
commit 4bdbc46381

View File

@ -778,6 +778,14 @@ sp_line_visualizer_row_render_worker (GTask *task,
goto cleanup;
}
/*
* Flip the coordinate space so that we can just use the x,y pairs
* as our position between 0.0 and 1.0 and have both the direction
* and the placement correct.
*/
cairo_translate (cr, 0, render->height);
cairo_scale (cr, render->width, -render->height);
for (guint i = 0; i < render->lines->len; i++)
{
const LineInfo *info = &g_array_index (render->lines, LineInfo, i);
@ -786,28 +794,32 @@ sp_line_visualizer_row_render_worker (GTask *task,
points = point_cache_get_points (render->cache, info->id, &n_points);
cairo_move_to (cr, 0, render->height);
gdk_cairo_set_source_rgba (cr, &info->foreground);
cairo_set_line_width (cr, info->line_width);
cairo_move_to (cr, 0, 0);
for (guint j = 0; j < n_points; j++)
{
const Point *p = &points[i];
cairo_line_to (cr, p->x * render->width, 1.0 - p->y * render->height);
cairo_line_to (cr, p->x, p->y);
if G_UNLIKELY (j + 1 == n_points)
{
gdk_cairo_set_source_rgba (cr, &info->foreground);
cairo_set_line_width (cr, info->line_width / (gdouble)render->height);
cairo_stroke_preserve (cr);
cairo_line_to (cr, p->x * render->width, render->height);
cairo_line_to (cr, p->x, 0.0);
}
}
cairo_line_to (cr, 0, render->height);
gdk_cairo_set_source_rgba (cr, &info->background);
cairo_fill (cr);
if (n_points > 0 && info->background.alpha > 0)
{
/*
* Close the path and fill if nencessary.
*/
cairo_line_to (cr, 0, 0);
gdk_cairo_set_source_rgba (cr, &info->background);
cairo_fill (cr);
}
}
g_task_return_pointer (task,