@@ -99,32 +99,23 @@ struct HeartChartView: View {
9999
100100 @ChartContentBuilder
101101 func chartContent( for point: HeartChartDataPoint ) -> some ChartContent {
102- if isSingleReading ( point) {
103- PointMark (
104- x: . value( " Time " , point. date) ,
105- y: . value( " BPM " , point. min)
106- )
107- . foregroundStyle ( heartColor)
108- . symbolSize ( 40 )
109- . symbol ( . circle)
110- } else {
111- RectangleMark (
112- x: . value( " Time " , point. date) ,
113- yStart: . value( " Min " , point. min) ,
114- yEnd: . value( " Max " , point. max) ,
115- width: 7
116- )
117- . foregroundStyle ( darkHeartColor)
118- . clipShape ( Capsule ( ) )
119-
120- PointMark (
121- x: . value( " Time " , point. date) ,
122- y: . value( " BPM " , point. average)
123- )
124- . foregroundStyle ( heartColor)
125- . symbolSize ( CGSize ( width: 7 , height: 7 ) )
126- . symbol ( . circle)
127- }
102+ BarMark (
103+ x: . value( " Time " , point. date) ,
104+ yStart: . value( " Min " , point. min) ,
105+ yEnd: . value( " Max " , point. max) ,
106+ width: 7
107+ )
108+ . foregroundStyle ( darkHeartColor)
109+ . cornerRadius ( 4 )
110+ //.clipShape(Capsule())
111+
112+ PointMark (
113+ x: . value( " Time " , point. date) ,
114+ y: . value( " BPM " , point. average)
115+ )
116+ . foregroundStyle ( heartColor)
117+ . symbolSize ( CGSize ( width: 7 , height: 7 ) )
118+ . symbol ( . circle)
128119 }
129120
130121 // fixed graph
@@ -134,6 +125,7 @@ struct HeartChartView: View {
134125 displayedMax = Int ( windowPoints. map ( { $0. max } ) . max ( ) ?? 0 )
135126 }
136127
128+ // MARK: iOS 16- fixed chart
137129 func chartPage( for offset: Int ) -> some View {
138130 let start = Calendar . current. startOfDay ( for: Calendar . current. date ( byAdding: . day, value: offset, to: Date ( ) ) !)
139131 let end = Date ( timeInterval: 86400 , since: start)
@@ -164,7 +156,6 @@ struct HeartChartView: View {
164156 }
165157 }
166158
167- // MARK: iOS 16- fixed chart
168159 var pagedChart : some View {
169160 VStack ( spacing: 0 ) {
170161 HStack {
@@ -197,14 +188,20 @@ struct HeartChartView: View {
197188 // MARK: iOS 17+ scrollable chart
198189 @available ( iOS 17 , * )
199190 var scrollableChart : some View {
200- Chart {
191+ let xMin = Calendar . current. startOfDay ( for: earliestDate)
192+ //let xMax = Calendar.current.date(byAdding: .day, value: 2, to: Calendar.current.startOfDay(for: latestDate)) ?? latestDate
193+ let xMax = Calendar . current. startOfDay ( for: latestDate) + 86400 + 3600
194+ let yMin = displayedMin - 20
195+ let yMax = displayedMax + 20
196+
197+ return Chart {
201198 ForEach ( points) { point in
202199 chartContent ( for: point)
203200 }
204201 }
205202 . frame ( height: 280 )
206203 . padding ( . horizontal, 8 )
207- . chartYScale ( domain: ( displayedMin - 20 ) ... ( displayedMax + 20 ) )
204+ . chartYScale ( domain: ( yMin ... yMax ) )
208205 . chartXAxis {
209206 AxisMarks ( values: . stride( by: . hour, count: 6 ) ) { value in
210207 AxisGridLine ( stroke: StrokeStyle ( lineWidth: 0.5 , dash: [ 4 ] ) )
@@ -219,9 +216,14 @@ struct HeartChartView: View {
219216 }
220217 . chartScrollableAxes ( . horizontal)
221218 . chartXVisibleDomain ( length: 86400 )
222- . chartXScale ( domain: ( earliestDate - 1800 ) ... ( latestDate + 1800 ) )
219+ . chartXScale ( domain: ( xMin ... xMax ) )
223220 . chartScrollPosition ( x: $scrollPositionDate)
224- . chartScrollTargetBehavior ( . valueAligned( unit: 3600 ) )
221+ . chartScrollTargetBehavior (
222+ . valueAligned(
223+ matching: DateComponents ( timeZone: . current, minute: 0 , second: 0 ) ,
224+ majorAlignment: . matching( DateComponents ( timeZone: . current, hour: 0 ) )
225+ )
226+ )
225227 }
226228
227229 var body : some View {
@@ -263,15 +265,17 @@ struct HeartChartView: View {
263265 }
264266 }
265267 . listRowBackground ( Color . clear)
266- if points. count >= 3 {
268+ /*
269+ if points.count >= 3 {
267270 Section {
268271 Text("Today your heart rate reached a high of \(displayedMax), and dropped to a low of \(displayedMin) BPM.")
269272 }
270273 }
274+ */
271275 }
272276 . onAppear {
273277 points = heartPoints ( )
274- scrollPositionDate = Date ( timeInterval : - 86400 , since : latestDate)
278+ scrollPositionDate = Calendar . current . startOfDay ( for : latestDate)
275279 displayedDate = scrollPositionDate
276280 updateDisplayed ( )
277281 updateYScale ( )
@@ -306,3 +310,4 @@ struct HeartChartView: View {
306310 }
307311 }
308312}
313+
0 commit comments