|
|
@@ -447,6 +447,10 @@ public class BarGraphView extends View {
|
|
|
|
|
|
// max vrijednost unutar Data arraya, max vrijednost podataka koje imamo
|
|
|
maxDataValue = getDataMaxValue();
|
|
|
+ String maxValueFormatted = adapter.getVerticalMarkingText(maxDataValue);
|
|
|
+ float maxValueTextWidth = verticalAxisRect.getPaintLine().measureText(maxValueFormatted);
|
|
|
+ verticalAxisValues.setMinDistanceBetweenMarkings(maxValueTextWidth);
|
|
|
+
|
|
|
// max vrijednost grafa, ovisi o max vrijednosti data arraya, ali nije
|
|
|
// ista (nekad imamo lufta)
|
|
|
maxGraphValue = getGraphMaxValue(maxDataValue);
|
|
|
@@ -464,6 +468,8 @@ public class BarGraphView extends View {
|
|
|
|
|
|
public void setAdapter(BarGraphAdapter adapter) {
|
|
|
this.adapter = adapter;
|
|
|
+ // Reset scroll
|
|
|
+ this.offsetX = 0;
|
|
|
|
|
|
adapterChanged();
|
|
|
}
|
|
|
@@ -608,13 +614,30 @@ public class BarGraphView extends View {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Best values of vertical markings are satisfying
|
|
|
+ * 1) n = 2^k or
|
|
|
+ * 2) n = 5 * k.
|
|
|
+ * Try to find highest possible value
|
|
|
+ * E.g.
|
|
|
+ * 7 is not good, but could be lowered to 5 (satisfies no. 2).
|
|
|
+ * 8 is ok (no. 1)
|
|
|
+ * 12 -> 10 (no. 2)
|
|
|
+ *
|
|
|
+ * @param distance minimum possible distance
|
|
|
+ * @return number of vertical markings
|
|
|
+ */
|
|
|
private int calculateMaximumNumberOfVerticalMarkings(float distance) {
|
|
|
- // na koliko dijelova možemo raspodijeliti
|
|
|
int discreteY = (int) (getGraphHeight() / distance);
|
|
|
- // trazimo najmanju nizu potenciju od 2 koja bi odgovorala discreteY
|
|
|
- int log2 = (int) Math.floor(Math.log(discreteY) / Math.log(2.));
|
|
|
- int normDiscreteY = (int) Math.pow(2, log2);
|
|
|
- return normDiscreteY;
|
|
|
+
|
|
|
+ // Find greatest k which satisfies discreteY >= 2^k (no 1)
|
|
|
+ int k = (int) Math.floor(Math.log(discreteY) / Math.log(2.));
|
|
|
+ int powerOfTwoSolution = (int) Math.pow(2, k);
|
|
|
+
|
|
|
+ // Find greatest k which satisfies discrete> >= 5*k
|
|
|
+ int multipleOfFiveSolution = (discreteY / 5) * 5;
|
|
|
+ // Return the greatest value.
|
|
|
+ return Math.max(powerOfTwoSolution, multipleOfFiveSolution);
|
|
|
}
|
|
|
|
|
|
private double getDataMaxValue() {
|