added support of smooth curve setting
[psensor.git] / src / graph.c
index a69b65a..be5d8b4 100644 (file)
@@ -33,6 +33,8 @@
 /* vertical padding */
 #define GRAPH_V_PADDING 4
 
+bool is_smooth_curves_enabled;
+
 static time_t get_graph_end_time_s()
 {
        struct timeval tv;
@@ -170,8 +172,11 @@ static void draw_background_lines(cairo_t *cr,
        cairo_set_dash(cr, 0, 0, 0);
 }
 
-/* contains the time_t of the measures which have been draw ie not the
- * bezier control points for each sensor. */
+/* Keys: sensor identifier.
+ *
+ * Values: array of time_t. Each time_t is corresponding to a sensor
+ * measure which has been used as the start point of a Bezier curve.
+ */
 static GHashTable *times;
 
 static void draw_sensor_smooth_curve(struct psensor *s,
@@ -202,6 +207,10 @@ static void draw_sensor_smooth_curve(struct psensor *s,
                             s->color->green,
                             s->color->blue);
 
+       /* search the index of the first measure used as a start point
+        * of a Bezier curve. The start and end points of the Bezier
+        * curves must be preserved to ensure the same overall shape
+        * of the graph. */
        i = 0;
        if (stimes) {
                while (i < s->values_max_length) {
@@ -253,7 +262,6 @@ static void draw_sensor_smooth_curve(struct psensor *s,
                        x[0 + j] = ((double)vdt * g_width) / dt + g_xoff;
                        y[0 + j] = compute_y(v, min, max, g_height, g_yoff);
 
-
                        if (j == 0)
                                t0 = t;
 
@@ -345,10 +353,10 @@ graph_update(struct psensor **sensors,
 {
        struct color *fgcolor = config->graph_fgcolor;
        int et, bt, width, height, g_width, g_height;
-       double min_rpm, max_rpm, mint, maxt;
+       double min_rpm, max_rpm, mint, maxt, min, max;
        char *strmin, *strmax;
        /* horizontal and vertical offset of the graph */
-       int g_xoff, g_yoff, no_graphs, min, max;
+       int g_xoff, g_yoff, no_graphs;
        cairo_surface_t *cst;
        cairo_t *cr, *cr_pixmap;
        char *str_btime, *str_etime;
@@ -476,7 +484,7 @@ graph_update(struct psensor **sensors,
                                max = maxt;
                        }
 
-                       if (1)
+                       if (is_smooth_curves_enabled)
                                draw_sensor_smooth_curve(s, cr,
                                                         min, max,
                                                         bt, et,