Fix some minor graph related bugs.
authorBrenden Matthews <brenden@rty.ca>
Mon, 25 May 2009 05:16:36 +0000 (23:16 -0600)
committerBrenden Matthews <brenden@rty.ca>
Mon, 25 May 2009 05:16:36 +0000 (23:16 -0600)
src/conky.c
src/specials.c

index f9f5e9b..10c158b 100644 (file)
@@ -6116,23 +6116,43 @@ static void draw_line(char *s)
                                                if (specials[special_index].last_colour != 0
                                                                || specials[special_index].first_colour != 0) {
                                                        if (specials[special_index].tempgrad) {
+#ifdef DEBUG_lol
+                                                               assert(
+                                                                               (int)((float)(w - 2) - specials[special_index].graph[j] *
+                                                                                       (w - 2) / (float)specials[special_index].graph_scale)
+                                                                               < w - 1
+                                                                         );
+                                                               assert(
+                                                                               (int)((float)(w - 2) - specials[special_index].graph[j] *
+                                                                                       (w - 2) / (float)specials[special_index].graph_scale)
+                                                                               > -1
+                                                                         );
+                                                               if (specials[special_index].graph[j] == specials[special_index].graph_scale) {
+                                                                       assert(
+                                                                                       (int)((float)(w - 2) - specials[special_index].graph[j] *
+                                                                                               (w - 2) / (float)specials[special_index].graph_scale)
+                                                                                       == 0
+                                                                                 );
+                                                               }
+#endif /* DEBUG_lol */
                                                                XSetForeground(display, window.gc, tmpcolour[
-                                                                               (int)((float)(w - 1) - specials[special_index].graph[j] *
-                                                                                (w - 2) / (float)specials[special_index].graph_scale) - 1]);
+                                                                               (int)((float)(w - 2) - specials[special_index].graph[j] *
+                                                                                       (w - 2) / (float)specials[special_index].graph_scale)
+                                                                               ]);
                                                        } else {
                                                                XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
                                                        }
                                                }
+                                               /* this is mugfugly, but it works */
+                                               XDrawLine(display, window.drawable, window.gc,
+                                                               cur_x + i + 1, by + h, cur_x + i + 1,
+                                                               by + h - specials[special_index].graph[j] *
+                                                               (h - 1) / specials[special_index].graph_scale);
                                                if ((w - i) / ((float) (w - 2) /
-                                                               (specials[special_index].graph_width)) > j
+                                                                       (specials[special_index].graph_width)) > j
                                                                && j < MAX_GRAPH_DEPTH - 3) {
                                                        j++;
                                                }
-                                               /* this is mugfugly, but it works */
-                                               XDrawLine(display, window.drawable, window.gc,
-                                                       cur_x + i + 1, by + h, cur_x + i + 1,
-                                                       by + h - specials[special_index].graph[j] *
-                                                       (h - 1) / specials[special_index].graph_scale);
                                        }
                                        if (tmpcolour) free(tmpcolour);
                                        if (h > cur_y_add
index 26b87dc..e35d5f1 100644 (file)
@@ -288,11 +288,15 @@ static void graph_append(struct special_t *graph, double f, char showaslog)
        /* shift all the data by 1 */
        for (i = graph->graph_width - 1; i > 0; i--) {
                graph->graph[i] = graph->graph[i - 1];
-               if (graph->scaled && graph->graph[i] > graph->graph_scale) {
+               if (graph->scaled && graph->graph[i - 1] > graph->graph_scale) {
                        /* check if we need to update the scale */
-                       graph->graph_scale = graph->graph[i];
+                       graph->graph_scale = graph->graph[i - 1];
                }
        }
+       if (graph->scaled && graph->graph[graph->graph_width] > graph->graph_scale) {
+               /* check if we need to update the scale */
+               graph->graph_scale = graph->graph[graph->graph_width];
+       }
 }
 
 void new_graph(char *buf, int w, int h, unsigned int first_colour,