+} /* }}} int update_graph_prettyping */
+
+static int update_graph_histogram (ping_context_t *ctx) /* {{{ */
+{
+ uint32_t *counters;
+ uint32_t *accumulated;
+ uint32_t num;
+ uint32_t max;
+ size_t i;
+ size_t x_max;
+ size_t x;
+
+ size_t symbols_num = hist_symbols_acs_num;
+
+ if (has_utf8 ())
+ symbols_num = hist_symbols_utf8_num;
+
+ x_max = (size_t) getmaxx (ctx->window);
+ if (x_max <= 4)
+ return (EINVAL);
+ x_max -= 4;
+
+ counters = calloc (x_max, sizeof (*counters));
+ accumulated = calloc (x_max, sizeof (*accumulated));
+
+ /* Downsample */
+ max = 0;
+ for (i = 0; i < ctx->latency_histogram_size; i++)
+ {
+ x = i * x_max / ctx->latency_histogram_size;
+ counters[x] += ctx->histogram_counters[i];
+ accumulated[x] = counters[x];
+
+ if (max < counters[x])
+ max = counters[x];
+ }
+
+ /* Sum */
+ for (x = 1; x < x_max; x++)
+ accumulated[x] += accumulated[x - 1];
+ num = accumulated[x_max - 1];
+
+ /* Calculate ratios */
+ for (x = 0; x < x_max; x++)
+ {
+ double height = ((double) counters[x]) / ((double) max);
+ double ratio_this = ((double) accumulated[x]) / ((double) num);
+ double ratio_prev = 0.0;
+ size_t index;
+ int color = 0;
+
+ index = (size_t) (height * ((double) symbols_num));
+ if (index >= symbols_num)
+ index = symbols_num - 1;
+
+ if (x > 0)
+ ratio_prev = ((double) accumulated[x - 1]) / ((double) num);
+
+ if (has_colors () == TRUE)
+ {
+ if ((ratio_this <= 0.5) || ((ratio_prev < 0.5) && (ratio_this > 0.5)))
+ color = OPING_GREEN;
+ else if ((ratio_this <= 0.95) || ((ratio_prev < 0.95) && (ratio_this > 0.95)))
+ color = OPING_YELLOW;
+ else
+ color = OPING_RED;
+
+ wattron (ctx->window, COLOR_PAIR(color));
+ }
+
+ if (counters[x] == 0)
+ mvwaddch (ctx->window, /* y = */ 3, /* x = */ x + 2, ' ');
+ else if (has_utf8 ())
+ mvwprintw (ctx->window, /* y = */ 3, /* x = */ x + 2,
+ hist_symbols_utf8[index]);
+ else
+ mvwaddch (ctx->window, /* y = */ 3, /* x = */ x + 2,
+ hist_symbols_acs[index] | A_ALTCHARSET);
+
+ if (has_colors () == TRUE)
+ wattroff (ctx->window, COLOR_PAIR(color));
+
+ }
+
+ free (accumulated);
+ return (0);
+} /* }}} int update_graph_histogram */