style
[psensor.git] / src / graph.c
index a69b65a..749544f 100644 (file)
 /* vertical padding */
 #define GRAPH_V_PADDING 4
 
+bool is_smooth_curves_enabled;
+
 static time_t get_graph_end_time_s()
 {
        struct timeval tv;
 
        if (gettimeofday(&tv, NULL) == 0)
                return tv.tv_sec;
-       else
-               return 0;
+
+       return 0;
 }
 
 static time_t get_graph_begin_time_s(struct config *cfg)
@@ -59,6 +61,7 @@ static double
 compute_y(double value, double min, double max, int height, int off)
 {
        double t = value - min;
+
        return height - ((double)height * (t / (max - min))) + off;
 }
 
@@ -150,6 +153,7 @@ static void draw_background_lines(cairo_t *cr,
        /* vertical lines representing time steps */
        for (i = 0; i <= 5; i++) {
                int x = i * (g_width / 5) + g_xoff;
+
                cairo_move_to(cr, x, g_yoff);
                cairo_line_to(cr, x, g_yoff + g_height);
                cairo_stroke(cr);
@@ -170,8 +174,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 +209,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 +264,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 +355,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;
@@ -359,7 +369,7 @@ graph_update(struct psensor **sensors,
        GdkRGBA rgba;
 
        if (!gtk_widget_is_drawable(w_graph))
-               return ;
+               return;
 
        enabled_sensors = psensor_list_filter_graph_enabled(sensors);
 
@@ -476,7 +486,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,