File tree Expand file tree Collapse file tree 6 files changed +23
-9
lines changed
Modules/Sources/JetpackStats Expand file tree Collapse file tree 6 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ struct ChartCard: View {
8585 }
8686 chartContentView
8787 }
88+ . environment ( \. showComparison, dateRange. comparison != . off)
8889 . animation ( . spring, value: selectedMetric)
8990 . animation ( . spring, value: selectedChartType)
9091 . animation ( . easeInOut, value: viewModel. isFirstLoad)
@@ -272,9 +273,9 @@ struct ChartCard: View {
272273 private func chartContentView( data: ChartData ) -> some View {
273274 switch selectedChartType {
274275 case . line:
275- LineChartView ( data: data, showComparison : dateRange . comparison != . off )
276+ LineChartView ( data: data)
276277 case . columns:
277- BarChartView ( data: data, showComparison : dateRange . comparison != . off ) { selection in
278+ BarChartView ( data: data) { selection in
278279 handleDateSelection ( selection, data: data)
279280 }
280281 }
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ struct StandaloneChartCard: View {
6363 dateRangeControls
6464 . dynamicTypeSize ( ... DynamicTypeSize . xLarge)
6565 }
66+ . environment ( \. showComparison, dateRange. comparison != . off)
6667 . padding ( . vertical, Constants . step2)
6768 . padding ( . horizontal, Constants . step3)
6869 . dynamicTypeSize ( ... DynamicTypeSize . xxLarge)
@@ -127,9 +128,9 @@ struct StandaloneChartCard: View {
127128 private func chartContent( chartData: ChartData ) -> some View {
128129 switch chartType {
129130 case . line:
130- LineChartView ( data: chartData, showComparison : dateRange . comparison != . off )
131+ LineChartView ( data: chartData)
131132 case . columns:
132- BarChartView ( data: chartData, showComparison : dateRange . comparison != . off )
133+ BarChartView ( data: chartData)
133134 }
134135 }
135136
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ import Charts
33
44struct BarChartView : View {
55 let data : ChartData
6- var showComparison : Bool = true
76 var onDateSelected : ( ( Date ) -> Void ) ? = nil
87
98 @State private var selectedDataPoints : SelectedDataPoints ?
@@ -12,6 +11,7 @@ struct BarChartView: View {
1211
1312 @Environment ( \. context) var context
1413 @Environment ( \. colorScheme) var colorScheme
14+ @Environment ( \. showComparison) private var showComparison
1515
1616 private var valueFormatter : StatsValueFormatter {
1717 StatsValueFormatter ( metric: data. metric)
Original file line number Diff line number Diff line change @@ -3,13 +3,13 @@ import Charts
33
44struct LineChartView : View {
55 let data : ChartData
6- var showComparison : Bool = true
76
87 @State private var selectedDate : Date ?
98 @State private var selectedDataPoints : SelectedDataPoints ?
109
1110 @Environment ( \. colorScheme) var colorScheme
1211 @Environment ( \. context) var context
12+ @Environment ( \. showComparison) private var showComparison
1313
1414 private var valueFormatter : StatsValueFormatter {
1515 StatsValueFormatter ( metric: data. metric)
Original file line number Diff line number Diff line change 1+ import SwiftUI
2+
3+ private struct ShowComparisonKey : EnvironmentKey {
4+ static let defaultValue = true
5+ }
6+
7+ extension EnvironmentValues {
8+ var showComparison : Bool {
9+ get { self [ ShowComparisonKey . self] }
10+ set { self [ ShowComparisonKey . self] = newValue }
11+ }
12+ }
Original file line number Diff line number Diff line change @@ -51,7 +51,6 @@ struct StatsDateRangePickerMenu: View {
5151 selection. update ( preset: preset)
5252 UIImpactFeedbackGenerator ( style: . light) . impactOccurred ( )
5353
54- // Track preset selection
5554 context. tracker? . send ( . dateRangePresetSelected, properties: [
5655 " selected_preset " : preset. analyticsName
5756 ] )
@@ -64,10 +63,11 @@ struct StatsDateRangePickerMenu: View {
6463 ForEach ( DateRangeComparisonPeriod . allCases) { period in
6564 Button ( action: {
6665 let previousPeriod = selection. comparison
67- selection. update ( comparisonPeriod: period)
66+ withAnimation {
67+ selection. update ( comparisonPeriod: period)
68+ }
6869 UIImpactFeedbackGenerator ( style: . light) . impactOccurred ( )
6970
70- // Track comparison period change
7171 context. tracker? . send ( . comparisonPeriodChanged, properties: [
7272 " from_period " : previousPeriod. analyticsName,
7373 " to_period " : period. analyticsName
You can’t perform that action at this time.
0 commit comments