Skip to content

Comments

feat: Multiple improvements to CareKitEssentialChartView#48

Merged
cbaker6 merged 113 commits intomainfrom
improveChartView
Apr 29, 2025
Merged

feat: Multiple improvements to CareKitEssentialChartView#48
cbaker6 merged 113 commits intomainfrom
improveChartView

Conversation

@cbaker6
Copy link
Member

@cbaker6 cbaker6 commented Apr 25, 2025

Support for multiple chart types was discussed in carekit-apple/CareKit#285. An initial implementation using Swift Charts was done in #21. This PR builds out the respective cards to support all Swift Chart Marks.

  • Update CI Xcode to version 16.3
  • Bump minimum macOS requirement to 14
  • Bump minimum watchOS requirement to 10
  • Use CareKit style in all cards and align all card styles
  • Fix displaying data over day, week, months, and year
  • CareEssentialChartView is now deprecated. Created a new view named CareKitEssentialChartView
  • Make CareKitEssentialChartView fully accessible by conforming to AXChartDescriptorRepresentable
  • Added boilerplate code for using custom functions to graph data (this is not enabled yet and shouldn't be used by developers as it may have breaking changes in the future)
  • Make CareKitEssentialChartView interactive
  • Add detail view for seeing a more detailed CareEssentialChartView
  • Allow showing of mean and median Marks in detailed CareEssentialChartView
  • Added more sum and is complete binary tasks (copies of CareKit) the only difference is these can filter out kind of OCKOutcomeValue
  • The functionality of the chart detail view is there, but needs to be improve aesthetics
  • Add unit tests (needs to be done in a future PR

Screenshots of new charts

imageimage

Code examples

import CareKit
import CareKitEssentials
import CareKitStore
import CareKitUI
import SwiftUI

struct InsightsView: View {

	@CareStoreFetchRequest(query: query()) private var events
	@State var intervalSelected = 0 // Default to week since chart isn't working for others.
	@State var chartInterval = DateInterval()
	@State var period: PeriodComponent = .day
	@State var configurations: [CKEDataSeriesConfiguration] = []

    var body: some View {
		ScrollView {
			// This is for loop is useful when you want a chart for
			// for every task which may not always be the case.
			ForEach(sortedEvents) { event in

				let eventResult = event.result
// Example of showing nausea vs doxlymine

						// dynamic gradient colors
						let nauseaGradientStart = Color(TintColorFlipKey.defaultValue)
						let nauseaGradientEnd = Color.accentColor

						let nauseaConfiguration = CKEDataSeriesConfiguration(
							taskID: TaskID.nausea,
							dataStrategy: .sum,
							mark: .bar,
							legendTitle: String(localized: "NAUSEA"),
							showMarkWhenHighlighted: true,
							showMeanMark: true,
							showMedianMark: false,
							color: nauseaGradientEnd,
							gradientStartColor: nauseaGradientStart,
							stackingMethod: .unstacked
						) { event in
							event.computeProgress(by: .averagingOutcomeValues())
						}

						let doxylamineConfiguration = CKEDataSeriesConfiguration(
							taskID: eventResult.task.id,
							dataStrategy: .sum,
							mark: .bar,
							legendTitle: String(localized: "DOXYLAMINE"),
							color: Color(UIColor.systemGray2),
							gradientStartColor: .gray,
							stackingMethod: .unstacked,
							symbol: .diamond,
							interpolation: .catmullRom
						) { event in
							event.computeProgress(by: .averagingOutcomeValues())
						}

						CareKitEssentialChartView(
							title: String(localized: "NAUSEA_DOXYLAMINE_INTAKE"),
							subtitle: subtitle,
							dateInterval: $chartInterval,
							period: $period,
							configurations: [
								nauseaConfiguration,
								doxylamineConfiguration
							]
						)
}

@codecov
Copy link

codecov bot commented Apr 25, 2025

Codecov Report

Attention: Patch coverage is 1.85071% with 1591 lines in your changes missing coverage. Please review.

Project coverage is 6.61%. Comparing base (8efb3cd) to head (a6ce786).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ntials/Cards/Shared/Chart/Data/CKEDataSeries.swift 0.00% 228 Missing ⚠️
...ed/Chart/Protocols/CareKitEssentialChartable.swift 0.00% 223 Missing ⚠️
...Shared/Chart/CareKitEssentialChartDetailView.swift 0.00% 173 Missing ⚠️
...s/Shared/Chart/CareKitEssentialChartBodyView.swift 0.00% 163 Missing ⚠️
...ls/Cards/Shared/Chart/CareEssentialChartView.swift 0.00% 124 Missing ⚠️
...ces/CareKitEssentials/Models/PeriodComponent.swift 0.00% 116 Missing ⚠️
...Cards/Shared/Chart/CareKitEssentialChartView.swift 0.00% 115 Missing ⚠️
...ials/Cards/Shared/Chart/CKEConfigurationView.swift 0.00% 79 Missing ⚠️
...s/CareKitEssentialChartBodyView+ChartContent.swift 0.00% 78 Missing ⚠️
...tials/Extensions/LinearCareTaskProgress+Math.swift 31.25% 66 Missing ⚠️
... and 18 more
Additional details and impacted files
@@           Coverage Diff            @@
##            main     #48      +/-   ##
========================================
- Coverage   8.47%   6.61%   -1.86%     
========================================
  Files         73      79       +6     
  Lines       3281    4384    +1103     
========================================
+ Hits         278     290      +12     
- Misses      3003    4094    +1091     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cbaker6 cbaker6 merged commit 810a2e6 into main Apr 29, 2025
@cbaker6 cbaker6 deleted the improveChartView branch April 29, 2025 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant