Skip to content

Commit fd0722d

Browse files
authored
[LOOP1992] Do not allow a value of -0 on the y-axis (dosing chart) (#272)
* do not allow a value of -0 on the y-axis * avoid -0 even when padding is not needed
1 parent fc27085 commit fd0722d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

LoopUI/Charts/DoseChart.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ public extension DoseChart {
6565

6666
let points = generateDosePoints(startDate: startDate)
6767

68-
let yAxisValues = ChartAxisValuesStaticGenerator.generateYAxisValuesWithChartPoints(points.basal + points.bolus + doseDisplayRangePoints, minSegmentCount: 2, maxSegmentCount: 3, multiple: log(2) / 2, axisValueGenerator: { ChartAxisValueDoubleLog(screenLocDouble: $0, formatter: integerFormatter, labelSettings: axisLabelSettings) }, addPaddingSegmentIfEdge: true)
69-
68+
let yAxisValues = ChartAxisValuesStaticGenerator.generateYAxisValuesUsingLinearSegmentStep(
69+
chartPoints: points.basal + points.bolus + doseDisplayRangePoints,
70+
minSegmentCount: 2,
71+
maxSegmentCount: 3,
72+
multiple: log(2) / 2,
73+
axisValueGenerator: { ChartAxisValueDoubleLog(screenLocDouble: $0, formatter: integerFormatter, labelSettings: axisLabelSettings) },
74+
addPaddingSegmentIfEdge: true)
75+
7076
let yAxisModel = ChartAxisModel(axisValues: yAxisValues, lineColor: colors.axisLine, labelSpaceReservationMode: .fixed(labelsWidthY))
7177

7278
let coordsSpace = ChartCoordsSpaceLeftBottomSingleAxis(chartSettings: chartSettings, chartFrame: frame, xModel: xAxisModel, yModel: yAxisModel)

LoopUI/Extensions/ChartAxisValuesStaticGenerator.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ extension ChartAxisValuesStaticGenerator {
4040

4141
/// If there should be a padding segment added when a scalar value falls on the first or last axis value, adjust the first and last axis values
4242
if firstValue =~ first && addPaddingSegmentIfEdge {
43+
firstValue = firstValue - segmentSize
44+
}
45+
46+
// do not allow a value of -0 on the axis
47+
while firstValue < 0 && firstValue.rounded() == -0 {
4348
firstValue = firstValue - segmentSize
4449
}
50+
4551
if lastValue =~ last && addPaddingSegmentIfEdge {
4652
lastValue = lastValue + segmentSize
4753
}

0 commit comments

Comments
 (0)