line-visualizer-row: use cairo_curve_to()

This makes our line graph match more closely to the design
coming from Builder's cpu graph.
This commit is contained in:
Christian Hergert
2016-09-26 21:57:33 -07:00
parent 4bdbc46381
commit 573ba7bf51

View File

@ -778,47 +778,45 @@ sp_line_visualizer_row_render_worker (GTask *task,
goto cleanup; goto cleanup;
} }
/* /* Flip the coordinate space so that 0,0 is in the bottom left. */
* 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_translate (cr, 0, render->height);
cairo_scale (cr, render->width, -render->height); cairo_scale (cr, 1.0, -1.0);
for (guint i = 0; i < render->lines->len; i++) for (guint i = 0; i < render->lines->len; i++)
{ {
const LineInfo *info = &g_array_index (render->lines, LineInfo, i); const LineInfo *line_info = &g_array_index (render->lines, LineInfo, i);
const Point *points; const Point *points;
guint n_points; guint n_points;
points = point_cache_get_points (render->cache, info->id, &n_points); points = point_cache_get_points (render->cache, line_info->id, &n_points);
cairo_move_to (cr, 0, 0); if (n_points > 0)
for (guint j = 0; j < n_points; j++)
{ {
const Point *p = &points[i]; gdouble last_x = points[0].x * render->width;
gdouble last_y = points[0].y * render->height;
cairo_line_to (cr, p->x, p->y); cairo_move_to (cr, last_x, last_y);
if G_UNLIKELY (j + 1 == n_points) for (guint j = 1; j < n_points; j++)
{ {
gdk_cairo_set_source_rgba (cr, &info->foreground); gdouble x = points[j].x * render->width;
cairo_set_line_width (cr, info->line_width / (gdouble)render->height); gdouble y = points[j].y * render->height;
cairo_stroke_preserve (cr);
cairo_line_to (cr, p->x, 0.0);
}
}
if (n_points > 0 && info->background.alpha > 0) cairo_curve_to (cr,
{ last_x + ((x - last_x) / 2),
/* last_y,
* Close the path and fill if nencessary. last_x + ((x - last_x) / 2),
*/ y,
cairo_line_to (cr, 0, 0); x,
gdk_cairo_set_source_rgba (cr, &info->background); y);
cairo_fill (cr);
last_x = x;
last_y = y;
}
cairo_set_line_width (cr, line_info->line_width);
gdk_cairo_set_source_rgba (cr, &line_info->foreground);
cairo_stroke (cr);
} }
} }