From 35a72f5a95b3f8223b4747be8343f1922724ecd0 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sun, 24 May 2009 23:16:36 -0600 Subject: [PATCH] Fix some minor graph related bugs. --- src/conky.c | 36 ++++++++++++++++++++++++++++-------- src/specials.c | 8 ++++++-- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/conky.c b/src/conky.c index f9f5e9bb..10c158bf 100644 --- a/src/conky.c +++ b/src/conky.c @@ -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 diff --git a/src/specials.c b/src/specials.c index 26b87dca..e35d5f19 100644 --- a/src/specials.c +++ b/src/specials.c @@ -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,