Created
February 16, 2012 18:59
-
-
Save kragen/1847029 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -urN vidalia-0.3.0-alpha/src//vidalia/bwgraph/GraphFrame.cpp vidalia-0.3.0-alpha-roundbandwidth/src//vidalia/bwgraph/GraphFrame.cpp | |
--- vidalia-0.3.0-alpha/src//vidalia/bwgraph/GraphFrame.cpp 2011-05-08 19:54:48.000000000 -0300 | |
+++ vidalia-0.3.0-alpha-roundbandwidth/src//vidalia/bwgraph/GraphFrame.cpp 2012-02-16 15:57:43.565950942 -0300 | |
@@ -15,6 +15,8 @@ | |
#include "GraphFrame.h" | |
+#include <cmath> | |
+ | |
#include <QtGlobal> | |
@@ -56,6 +58,19 @@ | |
return width; | |
} | |
+/** Return the smallest “round number” greater than or equal to value. | |
+ * A number is “round” if it is either a power of ten, two times a | |
+ * power of ten (equivalently one fifth of a power of ten), or five | |
+ * times a power of ten (equivalently half of a power of ten). | |
+ */ | |
+static inline qreal roundUp(qreal value) | |
+{ | |
+ qreal powerOfTen = exp(ceil(log(value)/log(10)) * log(10)); | |
+ if (value < powerOfTen / 5) return powerOfTen / 5; | |
+ if (value < powerOfTen / 2) return powerOfTen / 2; | |
+ return powerOfTen; | |
+} | |
+ | |
/** Adds new data points to the graph. */ | |
void | |
GraphFrame::addPoints(qreal recv, qreal send) | |
@@ -75,8 +90,8 @@ | |
_totalRecv += recv; | |
/* Check for a new maximum value */ | |
- if (send > _maxValue) _maxValue = send; | |
- if (recv > _maxValue) _maxValue = recv; | |
+ if (send > _maxValue) _maxValue = roundUp(send); | |
+ if (recv > _maxValue) _maxValue = roundUp(recv); | |
this->update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment