[sysprof/wip/visualizers] line-visualizer-row: simplify data point rendering



commit 4bdbc46381c5ae42ea9aaa7a5a9c9311316224e6
Author: Christian Hergert <chergert redhat com>
Date:   Mon Sep 26 20:08:34 2016 -0700

    line-visualizer-row: simplify data point rendering
    
    We can use some crafty scale/translations to simplify the
    line drawing of data points.

 lib/sp-line-visualizer-row.c |   32 ++++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 10 deletions(-)
---
diff --git a/lib/sp-line-visualizer-row.c b/lib/sp-line-visualizer-row.c
index d488985..2841ade 100644
--- a/lib/sp-line-visualizer-row.c
+++ b/lib/sp-line-visualizer-row.c
@@ -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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]