@@ -9,6 +9,7 @@ protocol StatsLineChartViewDelegate: AnyObject {
9
9
10
10
// MARK: - StatsLineChartView
11
11
12
+ private let LineChartAnalyticsPropertyKey = " property "
12
13
private let LineChartAnalyticsPropertyGranularityKey = " granularity "
13
14
14
15
class StatsLineChartView : LineChartView {
@@ -31,6 +32,7 @@ class StatsLineChartView: LineChartView {
31
32
static let xAxisWidth = 4.0
32
33
static let xAxisTickWidth = 2.0
33
34
static let lineWidth = 2.0
35
+ static let numberDaysInWeek = 7
34
36
}
35
37
36
38
/// This adapts the data set for presentation by the Charts framework.
@@ -53,6 +55,8 @@ class StatsLineChartView: LineChartView {
53
55
///
54
56
private weak var statsLineChartViewDelegate : StatsLineChartViewDelegate ?
55
57
58
+ private var statsInsightsFilterDimension : StatsInsightsFilterDimension
59
+
56
60
private var isHighlightNeeded : Bool {
57
61
guard let primaryDataSet = primaryDataSet, primaryDataSet. isHighlightEnabled else {
58
62
return false
@@ -79,12 +83,13 @@ class StatsLineChartView: LineChartView {
79
83
updateXAxisTicks ( )
80
84
}
81
85
82
- init ( configuration: StatsLineChartConfiguration , delegate: StatsLineChartViewDelegate ? = nil ) {
86
+ init ( configuration: StatsLineChartConfiguration , delegate: StatsLineChartViewDelegate ? = nil , statsInsightsFilterDimension : StatsInsightsFilterDimension = . views ) {
83
87
self . lineChartData = configuration. data
84
88
self . styling = configuration. styling
85
89
self . analyticsGranularity = configuration. analyticsGranularity
86
90
self . statsLineChartViewDelegate = delegate
87
91
self . xAxisDates = configuration. xAxisDates
92
+ self . statsInsightsFilterDimension = statsInsightsFilterDimension
88
93
89
94
super. init ( frame: . zero)
90
95
@@ -119,6 +124,8 @@ private extension StatsLineChartView {
119
124
properties [ LineChartAnalyticsPropertyGranularityKey] = specifiedAnalyticsGranularity. rawValue
120
125
}
121
126
127
+ properties [ LineChartAnalyticsPropertyKey] = statsInsightsFilterDimension. analyticsProperty
128
+
122
129
WPAnalytics . track ( . statsLineChartTapped, properties: properties)
123
130
}
124
131
@@ -164,8 +171,6 @@ private extension StatsLineChartView {
164
171
primaryDataSet. drawValuesEnabled = false
165
172
primaryDataSet. drawCirclesEnabled = false
166
173
primaryDataSet. lineWidth = Constants . lineWidth
167
- // TODO having issue with horizontalBezier (smoothing) - issue seems to be with this old version of lib
168
- // https://github.com/danielgindi/Charts/issues/3960
169
174
primaryDataSet. mode = . horizontalBezier
170
175
171
176
let gradientColors = [ styling. primaryLineColor. withAlphaComponent ( 1 ) . cgColor,
@@ -228,8 +233,10 @@ private extension StatsLineChartView {
228
233
func updateXAxisTicks( ) {
229
234
if contentRect. width > 0 {
230
235
xAxis. axisLineWidth = Constants . xAxisWidth
231
- let contentWidthMinusTicks = contentRect. width - ( Constants . xAxisTickWidth * CGFloat( xAxisDates. count) )
232
- xAxis. axisLineDashLengths = [ Constants . xAxisTickWidth, ( contentWidthMinusTicks / CGFloat( xAxisDates. count - 1 ) ) ]
236
+
237
+ let count = max ( xAxisDates. count, Constants . numberDaysInWeek)
238
+ let contentWidthMinusTicks = contentRect. width - ( Constants . xAxisTickWidth * CGFloat( count) )
239
+ xAxis. axisLineDashLengths = [ Constants . xAxisTickWidth, ( contentWidthMinusTicks / CGFloat( count - 1 ) ) ]
233
240
}
234
241
}
235
242
0 commit comments