summaryrefslogtreecommitdiff
path: root/multiload/load-graph.c
diff options
context:
space:
mode:
authorMarian Gasparovic <[email protected]>2018-02-04 18:36:36 +0100
committerraveit65 <[email protected]>2018-02-04 19:15:28 +0100
commite6d55cba85fc49b3dfac8150c397540bda369847 (patch)
treede6d8272b079641679b718258d4be7d9adc1594d /multiload/load-graph.c
parent560c27fb0638d41fe39ad0e0719dd6153b17eea0 (diff)
downloadmate-applets-e6d55cba85fc49b3dfac8150c397540bda369847.tar.bz2
mate-applets-e6d55cba85fc49b3dfac8150c397540bda369847.tar.xz
Scaling network graph using thresholds defined by user
Diffstat (limited to 'multiload/load-graph.c')
-rw-r--r--multiload/load-graph.c88
1 files changed, 86 insertions, 2 deletions
diff --git a/multiload/load-graph.c b/multiload/load-graph.c
index e3d0c12c..5eb90e8f 100644
--- a/multiload/load-graph.c
+++ b/multiload/load-graph.c
@@ -66,8 +66,8 @@ load_graph_draw (LoadGraph *g)
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
- /* all graphs except Load go this path */
- if (g->id != 4)
+ /* all graphs except Load and Net go this path */
+ if (g->id != 4 && g->id != 2)
{
for (i = 0; i < g->draw_width; i++)
g->pos [i] = g->draw_height - 1;
@@ -87,7 +87,91 @@ load_graph_draw (LoadGraph *g)
}
cairo_stroke (cr);
}
+ }
+ /* This is for network graph */
+ else if (g->id == 2)
+ {
+ guint maxnet = 1;
+ gint segments = 1;
+ gint combined = 0;
+ for (i = 0; i < g->draw_width; i++)
+ {
+ g->pos [i] = g->draw_height - 1;
+ combined = 0;
+ combined += g->data[i][0];
+ combined += g->data[i][1];
+ combined += g->data[i][2];
+ if (combined > maxnet)
+ maxnet = combined;
+ }
+ //printf("max = %d ", maxnet);
+ guint level = 0;
+ GdkRGBA grid_color;
+ if (maxnet > g->net_threshold3) {
+ g->net_threshold = g->net_threshold3;
+ level = 3;
+ }
+ else
+ if (maxnet > g->net_threshold2) {
+ g->net_threshold = g->net_threshold2;
+ level = 2;
+ }
+ else {
+ g->net_threshold = g->net_threshold1;
+ level = 1;
+ if (maxnet < g->net_threshold1)
+ level = 0;
+ }
+
+ //printf("level %d maxnet = %d ", level, maxnet);
+ maxnet = maxnet/g->net_threshold;
+ segments = MAX (maxnet+1,1);
+ float ratio = (float)g->draw_height/g->net_threshold/segments;
+ //printf("segments %d ratio = %f t1=%ld t2=%ld t3=%ld t=%ld\n", segments, ratio, g->net_threshold1, g->net_threshold2, g->net_threshold3, g->net_threshold);
+
+ for (j = 0; j < g->n-1; j++)
+ {
+ gdk_cairo_set_source_rgba (cr, &(g->colors [j]));
+
+ for (i = 0; i < g->draw_width; i++)
+ {
+ cairo_move_to (cr, g->draw_width - i - 0.5, g->pos[i] + 0.5);
+ cairo_line_to (cr, g->draw_width - i - 0.5, g->pos[i] - 0.5 - ((g->data [i][j] * ratio)));
+ g->pos [i] -= ((g->data [i][j] * ratio));
+ }
+ cairo_stroke (cr);
+ }
+
+ for (j = g->n-1; j < g->n; j++)
+ {
+ gdk_cairo_set_source_rgba (cr, &(g->colors [j]));
+ for (i = 0; i < g->draw_width; i++)
+ {
+ cairo_move_to (cr, g->draw_width - i - 0.5, g->pos[i] + 0.5);
+ cairo_line_to (cr, g->draw_width - i - 0.5, 0.5);
+ }
+ cairo_stroke (cr);
+ }
+ /* draw grid lines if needed */
+ gdk_cairo_set_source_rgba (cr, &(g->colors [4]));
+ double spacing = 0;
+ for (k = 0; k < segments -1; k++)
+ {
+ spacing = ((double) g->draw_height/segments) * (k+1);
+ cairo_move_to (cr, 0.5, spacing);
+ cairo_line_to (cr, g->draw_width-0.5, spacing);
+ }
+ cairo_stroke (cr);
+ /* draw indicator if needed */
+ if (level > 0)
+ {
+ gdk_cairo_set_source_rgba (cr, &(g->colors [5]));
+ for (k = 0; k< level; k++ )
+ cairo_rectangle(cr, 0.5, (k*2) * g->draw_height/5, 5, g->draw_height/5);
+ cairo_fill(cr);
+ }
+ cairo_stroke (cr);
}
/* this is Load graph */
else