From 5e3fe90c6b924ef261faf44a40df72e077e9dd2a Mon Sep 17 00:00:00 2001 From: OliE Date: Sun, 5 Aug 2018 17:26:03 +0200 Subject: [PATCH] set a maximum viewport for the bottom graph --- .../health/openscale/gui/fragments/GraphFragment.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java index 104a65cf..81dd0746 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java @@ -333,6 +333,8 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener { PolynomialFitter polyFitter = new PolynomialFitter(Math.min(regressLineOrder, 100)); + float maxYValue = 0; + for (MeasurementView view : measurementViews) { if (view instanceof FloatMeasurementView) { FloatMeasurementView measurementView = (FloatMeasurementView) view; @@ -383,6 +385,11 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener { if (avgBin.size() > 1) { avgValue.setLabel(String.format("Ø %.2f", avgValue.getY())); } + + if (avgValue.getY() > maxYValue) { + maxYValue = avgValue.getY(); + } + valuesStack.push(avgValue); pointIndexScaleMeasurementList.add(indexScaleMeasurement[i]); } @@ -459,6 +466,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener { chartBottom.setLineChartData(lineData); chartBottom.setCurrentViewport(defaultTopViewport); + chartBottom.setMaximumViewport(new Viewport(0, maxYValue + (maxYValue / 100) * 20, calDays.getMaximum(field)+1, 0)); } private void generateColumnData() @@ -485,7 +493,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener { for (int i=0; i<12; i++) { normNumOfMonth[i] = (numOfMonth[i] - min) / (float)(max - min); // normalize data to [0..1] - if (normNumOfMonth[i] != 1.0f && normNumOfMonth[i] != 0.0f) { + if (normNumOfMonth[i] != 0.0f) { normNumOfMonth[i] += heightOffset; } }