summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen M. Cameron <stephenmcameron@gmail.com>2012-03-11 11:33:46 +0100
committerJens Axboe <axboe@kernel.dk>2012-03-11 11:33:46 +0100
commit1e1ffcc41c12011f665d8f962d0d387305e32522 (patch)
tree2d5552e9d7e62589a7cfb9371b37f2bc33707788
parenta31d9fa466bfeefb30ff56a3e697779c5079771b (diff)
downloadfio-1e1ffcc41c12011f665d8f962d0d387305e32522.tar.gz
fio-1e1ffcc41c12011f665d8f962d0d387305e32522.tar.bz2
gfio: do not mix K M and G when shortening axis labels
That is, do not scale axis labels by differing amounts like 900K, 1M, 1100K, instead: 900k, 1000k, 1100k. Signed-off-by: Stephen M. Cameron <stephenmcameron@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--tickmarks.c51
1 files changed, 37 insertions, 14 deletions
diff --git a/tickmarks.c b/tickmarks.c
index 21f77da0..52fd5568 100644
--- a/tickmarks.c
+++ b/tickmarks.c
@@ -39,20 +39,43 @@ static double nicenum(double x, int round)
return 10.0 * pow(10.0, exp);
}
-static void shorten(char *str)
+static void shorten(struct tickmark *tm, int nticks)
{
- int l;
-
- l = strlen(str);
- if (l > 9 && strcmp(&str[l - 9], "000000000") == 0) {
- str[l - 9] = 'G';
- str[l - 8] = '\0';
- } else if (l > 6 && strcmp(&str[l - 6], "000000") == 0) {
- str[l - 6] = 'M';
- str[l - 5] = '\0';
- } else if (l > 3 && strcmp(&str[l - 3], "000") == 0) {
- str[l - 3] = 'K';
- str[l - 2] = '\0';
+ int i, l, minshorten, can_shorten_by;
+ char *str;
+ char shorten_char = '?';
+
+ minshorten = 100;
+ for (i = 0; i < nticks; i++) {
+ str = tm[i].string;
+ l = strlen(str);
+
+ if (l > 9 && strcmp(&str[l - 9], "000000000") == 0) {
+ can_shorten_by = 9;
+ shorten_char = 'G';
+ } else if (6 < minshorten && l > 6 &&
+ strcmp(&str[l - 6], "000000") == 0) {
+ can_shorten_by = 6;
+ shorten_char = 'M';
+ } else if (l > 3 && strcmp(&str[l - 3], "000") == 0) {
+ can_shorten_by = 3;
+ shorten_char = 'K';
+ } else {
+ can_shorten_by = 0;
+ }
+
+ if (can_shorten_by < minshorten)
+ minshorten = can_shorten_by;
+ }
+
+ if (minshorten == 0)
+ return;
+
+ for (i = 0; i < nticks; i++) {
+ str = tm[i].string;
+ l = strlen(str);
+ str[l - minshorten] = shorten_char;
+ str[l - minshorten + 1] = '\0';
}
}
@@ -80,9 +103,9 @@ int calc_tickmarks(double min, double max, int nticks, struct tickmark **tm)
for (x = graphmin; x < graphmax + 0.5 * d; x += d) {
(*tm)[i].value = x;
sprintf((*tm)[i].string, str, x);
- shorten((*tm)[i].string);
i++;
}
+ shorten(*tm, i);
return i;
}