From cb91a6dc0b03b9c15fb8bbf51649fcac7deb3356 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
Date: Fri, 5 May 2017 22:27:50 +0000
Subject: [PATCH] hist: improve output and style of plot

---
 lib/hist.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/lib/hist.c b/lib/hist.c
index 4f0e938bc..e884c2fa4 100644
--- a/lib/hist.c
+++ b/lib/hist.c
@@ -135,12 +135,15 @@ double hist_stddev(struct hist *h)
 
 void hist_print(struct hist *h, int details)
 { INDENT
-	if (h->length > 0) {
+	if (h->total > 0) {
 		hist_cnt_t missed = h->total - h->higher - h->lower;
 
 		stats("Counted values: %ju (%ju between %f and %f)", h->total, missed, h->low, h->high);
-		stats("Highest: %f Lowest: %f", h->highest, h->lowest);
-		stats("Mu: %f Sigma2: %f Sigma: %f", hist_mean(h), hist_var(h), hist_stddev(h));
+		stats("Highest:  %f", h->highest);
+		stats("Lowest:   %f", h->lowest);
+		stats("Mu:       %f", hist_mean(h));
+		stats("Variance: %f", hist_var(h));
+		stats("Stddev:   %f", hist_stddev(h));
 
 		if (details > 0 && h->total - h->higher - h->lower > 0) {
 			char *buf = hist_dump(h);
@@ -156,9 +159,6 @@ void hist_print(struct hist *h, int details)
 
 void hist_plot(struct hist *h)
 {
-	char buf[HIST_HEIGHT];
-	memset(buf, '#', sizeof(buf));
-
 	hist_cnt_t max = 1;
 
 	/* Get highest bar */
@@ -176,9 +176,17 @@ void hist_plot(struct hist *h)
 		hist_cnt_t cnt = h->data[i];
 		int bar = HIST_HEIGHT * ((double) cnt / max);
 
-		if (value >= h->lowest || value <= h->highest)
-			stats("%+9g | %5ju | %.*s", value, cnt, bar, buf);
+		char *buf = 0;
+		buf = strcatf(&buf, "%+9.3g | %5ju | ", value, cnt);
+
+		for (int i = 0; i < bar; i++)
+			buf = strcatf(&buf, "\u2588");
+
+		stats(buf);
+		free(buf);
 	}
+
+	line();
 }
 
 char * hist_dump(struct hist *h)