updated doc with libatasmart information
[psensor.git] / src / graph.c
index 70b29df..26a84d3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2011 jeanfi@gmail.com
+ * Copyright (C) 2010-2012 jeanfi@gmail.com
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -171,27 +171,28 @@ static void draw_sensor_curve(struct psensor *s,
                              int g_xoff,
                              int g_yoff)
 {
-       int first = 1;
-       int i;
+       int first, i, x, y, t, dt, vdt;
+       double v;
 
        cairo_set_source_rgb(cr,
                             s->color->f_red,
                             s->color->f_green,
                             s->color->f_blue);
-       cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
-       cairo_set_line_width(cr, 1);
 
+       dt = et - bt;
+       first = 1;
        for (i = 0; i < s->values_max_length; i++) {
-               int x, y, t;
-               double v;
-
                t = s->measures[i].time.tv_sec;
                v = s->measures[i].value.d_num;
 
-               if (v == UNKNOWN_DBL_VALUE || !t || (t - bt) < 0)
+               if (v == UNKNOWN_DBL_VALUE || !t)
                        continue;
 
-               x = (t - bt) * g_width / (et - bt) + g_xoff;
+               vdt = t - bt;
+               if (vdt < 0)
+                       continue;
+
+               x = vdt * g_width / dt + g_xoff;
 
                y = compute_y(v, min, max, g_height, g_yoff);
 
@@ -314,6 +315,9 @@ graph_update(struct psensor **sensors,
 
        if (bt && et) {
                sensor_cur = sensors;
+
+               cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
+               cairo_set_line_width(cr, 1);
                while (*sensor_cur) {
                        struct psensor *s = *sensor_cur;