diff --git a/core/src/main/java/info/nightscout/androidaps/utils/ui/BasalProfileGraph.kt b/core/src/main/java/info/nightscout/androidaps/utils/ui/BasalProfileGraph.kt index c31de87275..79ed829b0f 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/ui/BasalProfileGraph.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/ui/BasalProfileGraph.kt @@ -10,8 +10,8 @@ import info.nightscout.androidaps.core.R import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.utils.Round import java.text.NumberFormat -import java.util.ArrayList import kotlin.math.max +import kotlin.math.min class BasalProfileGraph : GraphView { @@ -22,8 +22,9 @@ class BasalProfileGraph : GraphView { removeAllSeries() val basalArray: MutableList = ArrayList() for (hour in 0..23) { - basalArray.add(DataPoint(hour.toDouble(), profile.getBasalTimeFromMidnight(hour * 60 * 60))) - basalArray.add(DataPoint((hour + 1).toDouble(), profile.getBasalTimeFromMidnight(hour * 60 * 60))) + val basal = profile.getBasalTimeFromMidnight(hour * 60 * 60) + basalArray.add(DataPoint(hour.toDouble(), basal)) + basalArray.add(DataPoint((hour + 1).toDouble(), basal)) } val basalDataPoints: Array = Array(basalArray.size) { i -> basalArray[i] } val basalSeries: LineGraphSeries = LineGraphSeries(basalDataPoints) @@ -41,7 +42,7 @@ class BasalProfileGraph : GraphView { val nf: NumberFormat = NumberFormat.getInstance() nf.maximumFractionDigits = 1 - gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf)) + gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf) } fun show(profile1: Profile, profile2: Profile) { @@ -49,9 +50,14 @@ class BasalProfileGraph : GraphView { // profile 1 val basalArray1: MutableList = ArrayList() + var minBasal = 1000.0 + var maxBasal = 0.0 for (hour in 0..23) { - basalArray1.add(DataPoint(hour.toDouble(), profile1.getBasalTimeFromMidnight(hour * 60 * 60))) - basalArray1.add(DataPoint((hour + 1).toDouble(), profile1.getBasalTimeFromMidnight(hour * 60 * 60))) + val basal = profile1.getBasalTimeFromMidnight(hour * 60 * 60) + minBasal = min(minBasal, basal) + maxBasal = max(maxBasal, basal) + basalArray1.add(DataPoint(hour.toDouble(), basal)) + basalArray1.add(DataPoint((hour + 1).toDouble(), basal)) } val basalSeries1: LineGraphSeries = LineGraphSeries(Array(basalArray1.size) { i -> basalArray1[i] }) addSeries(basalSeries1) @@ -61,8 +67,11 @@ class BasalProfileGraph : GraphView { // profile 2 val basalArray2: MutableList = ArrayList() for (hour in 0..23) { - basalArray2.add(DataPoint(hour.toDouble(), profile2.getBasalTimeFromMidnight(hour * 60 * 60))) - basalArray2.add(DataPoint((hour + 1).toDouble(), profile2.getBasalTimeFromMidnight(hour * 60 * 60))) + val basal = profile2.getBasalTimeFromMidnight(hour * 60 * 60) + minBasal = min(minBasal, basal) + maxBasal = max(maxBasal, basal) + basalArray2.add(DataPoint(hour.toDouble(), basal)) + basalArray2.add(DataPoint((hour + 1).toDouble(), basal)) } val basalSeries2: LineGraphSeries = LineGraphSeries(Array(basalArray2.size) { i -> basalArray2[i] }) addSeries(basalSeries2) @@ -75,8 +84,12 @@ class BasalProfileGraph : GraphView { viewport.setMinX(0.0) viewport.setMaxX(24.0) viewport.isYAxisBoundsManual = true - viewport.setMinY(0.0) - viewport.setMaxY(Round.ceilTo(max(profile1.getMaxDailyBasal(), profile2.getMaxDailyBasal()) * 1.1, 0.5)) + viewport.setMinY(Round.floorTo(minBasal / 1.1, 0.5)) + viewport.setMaxY(Round.ceilTo(maxBasal * 1.1, 0.5)) gridLabelRenderer.numHorizontalLabels = 13 + + val nf: NumberFormat = NumberFormat.getInstance() + nf.maximumFractionDigits = 1 + gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf) } } \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/utils/ui/IcProfileGraph.kt b/core/src/main/java/info/nightscout/androidaps/utils/ui/IcProfileGraph.kt index 74d6b08ce8..02dc50a0f4 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/ui/IcProfileGraph.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/ui/IcProfileGraph.kt @@ -10,8 +10,8 @@ import info.nightscout.androidaps.core.R import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.utils.Round import java.text.NumberFormat -import java.util.* import kotlin.math.max +import kotlin.math.min class IcProfileGraph : GraphView { @@ -44,17 +44,19 @@ class IcProfileGraph : GraphView { val nf: NumberFormat = NumberFormat.getInstance() nf.maximumFractionDigits = 1 - gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf)) + gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf) } fun show(profile1: Profile, profile2: Profile) { removeAllSeries() + var minIc = 1000.0 var maxIc = 0.0 // ic 1 val icArray1: MutableList = ArrayList() for (hour in 0..23) { val ic = profile1.getIcTimeFromMidnight(hour * 60 * 60) + minIc = min(minIc, ic) maxIc = max(maxIc, ic) icArray1.add(DataPoint(hour.toDouble(), ic)) icArray1.add(DataPoint((hour + 1).toDouble(), ic)) @@ -68,6 +70,7 @@ class IcProfileGraph : GraphView { val icArray2: MutableList = ArrayList() for (hour in 0..23) { val ic = profile2.getIcTimeFromMidnight(hour * 60 * 60) + minIc = min(minIc, ic) maxIc = max(maxIc, ic) icArray2.add(DataPoint(hour.toDouble(), ic)) icArray2.add(DataPoint((hour + 1).toDouble(), ic)) @@ -82,8 +85,12 @@ class IcProfileGraph : GraphView { viewport.setMinX(0.0) viewport.setMaxX(24.0) viewport.isYAxisBoundsManual = true - viewport.setMinY(0.0) + viewport.setMinY(Round.floorTo(minIc / 1.1, 0.5)) viewport.setMaxY(Round.ceilTo(maxIc * 1.1, 0.5)) gridLabelRenderer.numHorizontalLabels = 13 + + val nf: NumberFormat = NumberFormat.getInstance() + nf.maximumFractionDigits = 1 + gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf) } } \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/utils/ui/IsfProfileGraph.kt b/core/src/main/java/info/nightscout/androidaps/utils/ui/IsfProfileGraph.kt index 35d9d72e11..d449cdf15a 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/ui/IsfProfileGraph.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/ui/IsfProfileGraph.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.utils.Round import java.text.NumberFormat import kotlin.math.max +import kotlin.math.min class IsfProfileGraph : GraphView { @@ -45,18 +46,20 @@ class IsfProfileGraph : GraphView { val nf: NumberFormat = NumberFormat.getInstance() nf.maximumFractionDigits = 1 - gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf)) + gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf) } fun show(profile1: Profile, profile2: Profile) { removeAllSeries() + var minIsf = 1000.0 var maxIsf = 0.0 val units = profile1.units // isf 1 val isfArray1: MutableList = ArrayList() for (hour in 0..23) { val isf = Profile.fromMgdlToUnits(profile1.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units) + minIsf = min(minIsf, isf) maxIsf = max(maxIsf, isf) isfArray1.add(DataPoint(hour.toDouble(), isf)) isfArray1.add(DataPoint((hour + 1).toDouble(), isf)) @@ -70,6 +73,7 @@ class IsfProfileGraph : GraphView { val isfArray2: MutableList = ArrayList() for (hour in 0..23) { val isf = Profile.fromMgdlToUnits(profile2.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units) + minIsf = min(minIsf, isf) maxIsf = max(maxIsf, isf) isfArray2.add(DataPoint(hour.toDouble(), isf)) isfArray2.add(DataPoint((hour + 1).toDouble(), isf)) @@ -84,8 +88,12 @@ class IsfProfileGraph : GraphView { viewport.setMinX(0.0) viewport.setMaxX(24.0) viewport.isYAxisBoundsManual = true - viewport.setMinY(0.0) + viewport.setMinY(Round.floorTo(minIsf / 1.1, 0.5)) viewport.setMaxY(Round.ceilTo(maxIsf * 1.1, 0.5)) gridLabelRenderer.numHorizontalLabels = 13 + + val nf: NumberFormat = NumberFormat.getInstance() + nf.maximumFractionDigits = 1 + gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf) } } \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/utils/ui/TargetBgProfileGraph.kt b/core/src/main/java/info/nightscout/androidaps/utils/ui/TargetBgProfileGraph.kt index 3f7325a04b..7ff5dba32c 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/ui/TargetBgProfileGraph.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/ui/TargetBgProfileGraph.kt @@ -7,12 +7,12 @@ import com.jjoe64.graphview.GraphView import info.nightscout.androidaps.core.R import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.interfaces.Profile -import info.nightscout.androidaps.utils.Round import info.nightscout.androidaps.plugins.general.overview.graphExtensions.AreaGraphSeries import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DoubleDataPoint +import info.nightscout.androidaps.utils.Round import java.text.NumberFormat -import java.util.ArrayList import kotlin.math.max +import kotlin.math.min class TargetBgProfileGraph : GraphView { @@ -48,18 +48,20 @@ class TargetBgProfileGraph : GraphView { val nf: NumberFormat = NumberFormat.getInstance() nf.maximumFractionDigits = if (units == GlucoseUnit.MMOL) 1 else 0 - gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf)) + gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf) } fun show(profile1: Profile, profile2: Profile) { removeAllSeries() val targetArray1: MutableList = ArrayList() + var minValue = 1000.0 var maxValue = 0.0 val units = profile1.units for (hour in 0..23) { val valueLow = Profile.fromMgdlToUnits(profile1.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60), units) val valueHigh = Profile.fromMgdlToUnits(profile1.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60), units) + minValue = min(minValue, valueLow) maxValue = max(maxValue, valueHigh) targetArray1.add(DoubleDataPoint(hour.toDouble(), valueLow, valueHigh)) targetArray1.add(DoubleDataPoint((hour + 1).toDouble(), valueLow, valueHigh)) @@ -73,6 +75,7 @@ class TargetBgProfileGraph : GraphView { for (hour in 0..23) { val valueLow = Profile.fromMgdlToUnits(profile2.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60), units) val valueHigh = Profile.fromMgdlToUnits(profile2.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60), units) + minValue = min(minValue, valueLow) maxValue = max(maxValue, valueHigh) targetArray2.add(DoubleDataPoint(hour.toDouble(), valueLow, valueHigh)) targetArray2.add(DoubleDataPoint((hour + 1).toDouble(), valueLow, valueHigh)) @@ -87,13 +90,13 @@ class TargetBgProfileGraph : GraphView { viewport.setMinX(0.0) viewport.setMaxX(24.0) viewport.isYAxisBoundsManual = true - viewport.setMinY(0.0) + viewport.setMinY(Round.floorTo(minValue / 1.1, 0.5)) viewport.setMaxY(Round.ceilTo(maxValue * 1.1, 0.5)) gridLabelRenderer.numHorizontalLabels = 13 gridLabelRenderer.verticalLabelsColor = targetSeries1.color val nf: NumberFormat = NumberFormat.getInstance() nf.maximumFractionDigits = if (units == GlucoseUnit.MMOL) 1 else 0 - gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf)) + gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf) } }