Skip to content

Commit 596606a

Browse files
committed
Keep Trends chart labels readable at accessibility sizes
1 parent 0081d73 commit 596606a

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

‎Loop/Redesign/DayCharts.swift‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct InsulinTimelineView: View {
118118

119119
@State private var selection: Date?
120120
@Environment(\.colorScheme) private var colorScheme
121+
@Environment(\.dynamicTypeSize) private var typeSize
121122

122123
private static let insulinTop = 30.0
123124
private static let basalTop = 12.0
@@ -284,7 +285,9 @@ struct InsulinTimelineView: View {
284285
.chartXScale(domain: window.start...window.end)
285286
.chartYScale(domain: 0...104)
286287
.chartXAxis {
287-
AxisMarks(values: DayAxis.quarterDayMarks(in: window)) { value in
288+
AxisMarks(values: DayAxis.quarterDayMarks(in: window).filter {
289+
!typeSize.isAccessibilitySize || Calendar.current.component(.hour, from: $0).isMultiple(of: 12)
290+
}) { value in
288291
AxisValueLabel {
289292
if let date = value.as(Date.self) {
290293
Text(DayAxis.hourLabel(date))

‎Loop/Redesign/LoopDesign.swift‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,17 @@ struct LoopCard<Content: View>: View {
100100
struct CardHeader<Trailing: View>: View {
101101
let title: String
102102
@ViewBuilder var trailing: Trailing
103+
@Environment(\.dynamicTypeSize) private var typeSize
103104

104105
var body: some View {
105-
HStack(alignment: .firstTextBaseline) {
106+
AdaptiveRow(spacing: typeSize.isAccessibilitySize ? LoopDesign.Space.s1 : LoopDesign.Space.s2) {
106107
Text(title)
107108
.font(LoopDesign.Typeface.headline)
108109
.foregroundStyle(LoopDesign.Palette.ink)
109110
.accessibilityAddTraits(.isHeader)
110-
Spacer(minLength: LoopDesign.Space.s2)
111+
if !typeSize.isAccessibilitySize {
112+
Spacer(minLength: LoopDesign.Space.s2)
113+
}
111114
trailing
112115
.font(LoopDesign.Typeface.footnote)
113116
.foregroundStyle(LoopDesign.Palette.inkMuted)

‎Loop/Redesign/TrendsComponents.swift‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ struct TrendsAGPChart: View {
343343
let unit: GlucoseUnitStyle
344344
let targetRange: ClosedRange<Double>?
345345
var height: CGFloat = 180
346+
@Environment(\.dynamicTypeSize) private var typeSize
346347

347348
private func v(_ mgdl: Double) -> Double {
348349
min(max(unit.value(mgdl), unit.agpDomain.lowerBound), unit.agpDomain.upperBound)
@@ -414,7 +415,7 @@ struct TrendsAGPChart: View {
414415
.chartXScale(domain: 0...1440)
415416
.chartYScale(domain: unit.agpDomain)
416417
.chartXAxis {
417-
AxisMarks(values: Self.hourTicks) { value in
418+
AxisMarks(values: typeSize.isAccessibilitySize ? [0, 720, 1440] : Self.hourTicks) { value in
418419
AxisGridLine().foregroundStyle(P.grid)
419420
AxisValueLabel {
420421
if let minute = value.as(Int.self) { Text(Self.label(minute: minute)) }
@@ -424,7 +425,8 @@ struct TrendsAGPChart: View {
424425
}
425426
}
426427
.chartYAxis {
427-
AxisMarks(position: .leading, values: unit.agpTicks) { _ in
428+
AxisMarks(position: .leading, values: typeSize.isAccessibilitySize
429+
? [unit.agpTicks[0], unit.agpTicks[2], unit.agpTicks[4]] : unit.agpTicks) { _ in
428430
AxisGridLine().foregroundStyle(P.grid)
429431
AxisValueLabel().font(LoopDesign.Typeface.caption).foregroundStyle(P.inkMuted)
430432
}
@@ -660,6 +662,7 @@ struct InsulinDailyTotalsView: View {
660662
let average: Double
661663
var height: CGFloat = 170
662664
@Environment(\.colorScheme) private var scheme
665+
@Environment(\.dynamicTypeSize) private var typeSize
663666

664667
private var yMax: Double {
665668
let top = max(totals.map(\.total).max() ?? 0, average)
@@ -726,7 +729,8 @@ struct InsulinDailyTotalsView: View {
726729
.chartYScale(domain: 0...yMax)
727730
.chartXAxis {
728731
AxisMarks(values: axisDates) { value in
729-
AxisValueLabel(centered: true) {
732+
AxisValueLabel(centered: !typeSize.isAccessibilitySize,
733+
anchor: typeSize.isAccessibilitySize ? (value.index == 0 ? .topLeading : .topTrailing) : nil) {
730734
if let date = value.as(Date.self) {
731735
Text(axisLabel(date))
732736
.multilineTextAlignment(.center)
@@ -737,9 +741,16 @@ struct InsulinDailyTotalsView: View {
737741
}
738742
}
739743
.chartYAxis {
740-
AxisMarks(position: .leading) { _ in
741-
AxisGridLine().foregroundStyle(P.grid)
742-
AxisValueLabel().font(LoopDesign.Typeface.caption).foregroundStyle(P.inkMuted)
744+
if typeSize.isAccessibilitySize {
745+
AxisMarks(position: .leading, values: [0, yMax / 2, yMax]) { _ in
746+
AxisGridLine().foregroundStyle(P.grid)
747+
AxisValueLabel().font(LoopDesign.Typeface.caption).foregroundStyle(P.inkMuted)
748+
}
749+
} else {
750+
AxisMarks(position: .leading) { _ in
751+
AxisGridLine().foregroundStyle(P.grid)
752+
AxisValueLabel().font(LoopDesign.Typeface.caption).foregroundStyle(P.inkMuted)
753+
}
743754
}
744755
}
745756
.accessibilityElement(children: .ignore)
@@ -750,6 +761,10 @@ struct InsulinDailyTotalsView: View {
750761
}
751762

752763
private var axisDates: [Date] {
764+
// Full dates at the largest text sizes need the width between the two ends of the chart.
765+
if typeSize.isAccessibilitySize, let first = totals.first?.day, let last = totals.last?.day {
766+
return first == last ? [first] : [first, last]
767+
}
753768
if weekly {
754769
let stride = max(1, Int(ceil(Double(totals.count) / 6)))
755770
return totals.enumerated().compactMap { index, total in index % stride == 0 ? total.day : nil }

0 commit comments

Comments
 (0)