Skip to content

Commit 5a53a46

Browse files
committed
Use darker gray for 0% chart line
1 parent 5487309 commit 5a53a46

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ private extension AnalyticsHubViewModel {
200200
leadingDeltaColor: Constants.deltaColor(for: totalDelta.direction),
201201
leadingDeltaTextColor: Constants.deltaTextColor(for: totalDelta.direction),
202202
leadingChartData: StatsIntervalDataParser.getChartData(for: .totalRevenue, from: currentPeriodStats),
203+
leadingChartColor: Constants.chartColor(for: totalDelta.direction),
203204
trailingTitle: Localization.RevenueCard.trailingTitle,
204205
trailingValue: StatsDataTextFormatter.createNetRevenueText(orderStats: currentPeriodStats),
205206
trailingDelta: netDelta.string,
206207
trailingDeltaColor: Constants.deltaColor(for: netDelta.direction),
207208
trailingDeltaTextColor: Constants.deltaTextColor(for: netDelta.direction),
208209
trailingChartData: StatsIntervalDataParser.getChartData(for: .netRevenue, from: currentPeriodStats),
210+
trailingChartColor: Constants.chartColor(for: netDelta.direction),
209211
isRedacted: false,
210212
showSyncError: showSyncError,
211213
syncErrorMessage: Localization.RevenueCard.noRevenue)
@@ -224,12 +226,14 @@ private extension AnalyticsHubViewModel {
224226
leadingDeltaColor: Constants.deltaColor(for: ordersCountDelta.direction),
225227
leadingDeltaTextColor: Constants.deltaTextColor(for: ordersCountDelta.direction),
226228
leadingChartData: StatsIntervalDataParser.getChartData(for: .orderCount, from: currentPeriodStats),
229+
leadingChartColor: Constants.chartColor(for: ordersCountDelta.direction),
227230
trailingTitle: Localization.OrderCard.trailingTitle,
228231
trailingValue: StatsDataTextFormatter.createAverageOrderValueText(orderStats: currentPeriodStats),
229232
trailingDelta: orderValueDelta.string,
230233
trailingDeltaColor: Constants.deltaColor(for: orderValueDelta.direction),
231234
trailingDeltaTextColor: Constants.deltaTextColor(for: orderValueDelta.direction),
232235
trailingChartData: StatsIntervalDataParser.getChartData(for: .averageOrderValue, from: currentPeriodStats),
236+
trailingChartColor: Constants.chartColor(for: orderValueDelta.direction),
233237
isRedacted: false,
234238
showSyncError: showSyncError,
235239
syncErrorMessage: Localization.OrderCard.noOrders)
@@ -300,6 +304,17 @@ private extension AnalyticsHubViewModel {
300304
return .text
301305
}
302306
}
307+
308+
static func chartColor(for direction: StatsDataTextFormatter.DeltaPercentage.Direction) -> UIColor {
309+
switch direction {
310+
case .positive:
311+
return .withColorStudio(.green, shade: .shade50)
312+
case .negative:
313+
return .withColorStudio(.red, shade: .shade40)
314+
case .zero:
315+
return .withColorStudio(.gray, shade: .shade30)
316+
}
317+
}
303318
}
304319

305320
enum Localization {

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsReportCard.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ struct AnalyticsReportCard: View {
1111
let leadingDeltaColor: UIColor
1212
let leadingDeltaTextColor: UIColor
1313
let leadingChartData: [Double]
14+
let leadingChartColor: UIColor
1415
let trailingTitle: String
1516
let trailingValue: String
1617
let trailingDelta: String
1718
let trailingDeltaColor: UIColor
1819
let trailingDeltaTextColor: UIColor
1920
let trailingChartData: [Double]
21+
let trailingChartColor: UIColor
2022

2123
let isRedacted: Bool
2224

@@ -54,7 +56,7 @@ struct AnalyticsReportCard: View {
5456
.redacted(reason: isRedacted ? .placeholder : [])
5557
.shimmering(active: isRedacted)
5658

57-
AnalyticsLineChart(dataPoints: leadingChartData, lineChartColor: leadingDeltaColor)
59+
AnalyticsLineChart(dataPoints: leadingChartData, lineChartColor: leadingChartColor)
5860
.frame(width: scaledChartWidth, height: scaledChartHeight)
5961
}
6062

@@ -78,7 +80,7 @@ struct AnalyticsReportCard: View {
7880
.redacted(reason: isRedacted ? .placeholder : [])
7981
.shimmering(active: isRedacted)
8082

81-
AnalyticsLineChart(dataPoints: trailingChartData, lineChartColor: trailingDeltaColor)
83+
AnalyticsLineChart(dataPoints: trailingChartData, lineChartColor: trailingChartColor)
8284
.frame(width: scaledChartWidth, height: scaledChartHeight)
8385
}
8486
}
@@ -118,12 +120,14 @@ struct Previews: PreviewProvider {
118120
leadingDeltaColor: .withColorStudio(.green, shade: .shade40),
119121
leadingDeltaTextColor: .textInverted,
120122
leadingChartData: [0.0, 10.0, 2.0, 20.0, 15.0, 40.0, 0.0, 10.0, 2.0, 20.0, 15.0, 50.0],
123+
leadingChartColor: .withColorStudio(.green, shade: .shade40),
121124
trailingTitle: "Net Sales",
122125
trailingValue: "$3.232",
123126
trailingDelta: "-3%",
124127
trailingDeltaColor: .withColorStudio(.red, shade: .shade40),
125128
trailingDeltaTextColor: .textInverted,
126129
trailingChartData: [50.0, 15.0, 20.0, 2.0, 10.0, 0.0, 40.0, 15.0, 20.0, 2.0, 10.0, 0.0],
130+
trailingChartColor: .withColorStudio(.red, shade: .shade40),
127131
isRedacted: false,
128132
showSyncError: false,
129133
syncErrorMessage: "")
@@ -136,12 +140,14 @@ struct Previews: PreviewProvider {
136140
leadingDeltaColor: .withColorStudio(.gray, shade: .shade0),
137141
leadingDeltaTextColor: .text,
138142
leadingChartData: [],
143+
leadingChartColor: .withColorStudio(.gray, shade: .shade30),
139144
trailingTitle: "Net Sales",
140145
trailingValue: "-",
141146
trailingDelta: "0%",
142147
trailingDeltaColor: .withColorStudio(.gray, shade: .shade0),
143148
trailingDeltaTextColor: .text,
144149
trailingChartData: [],
150+
trailingChartColor: .withColorStudio(.gray, shade: .shade30),
145151
isRedacted: false,
146152
showSyncError: true,
147153
syncErrorMessage: "Error loading revenue analytics")

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsReportCardViewModel.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ struct AnalyticsReportCardViewModel {
3333
///
3434
let leadingChartData: [Double]
3535

36+
/// First Column Chart Color
37+
///
38+
let leadingChartColor: UIColor
39+
3640
/// Second Column Title
3741
///
3842
let trailingTitle: String
@@ -57,6 +61,10 @@ struct AnalyticsReportCardViewModel {
5761
///
5862
let trailingChartData: [Double]
5963

64+
/// Second Column Chart Color
65+
///
66+
let trailingChartColor: UIColor
67+
6068
/// Indicates if the values should be hidden (for loading state)
6169
///
6270
let isRedacted: Bool
@@ -83,12 +91,14 @@ extension AnalyticsReportCardViewModel {
8391
leadingDeltaColor: .lightGray,
8492
leadingDeltaTextColor: .text,
8593
leadingChartData: [],
94+
leadingChartColor: .lightGray,
8695
trailingTitle: trailingTitle,
8796
trailingValue: "$1000",
8897
trailingDelta: "+50%",
8998
trailingDeltaColor: .lightGray,
9099
trailingDeltaTextColor: .text,
91100
trailingChartData: [],
101+
trailingChartColor: .lightGray,
92102
isRedacted: true,
93103
showSyncError: false,
94104
syncErrorMessage: "")
@@ -106,12 +116,14 @@ extension AnalyticsReportCard {
106116
self.leadingDeltaColor = viewModel.leadingDeltaColor
107117
self.leadingDeltaTextColor = viewModel.leadingDeltaTextColor
108118
self.leadingChartData = viewModel.leadingChartData
119+
self.leadingChartColor = viewModel.leadingChartColor
109120
self.trailingTitle = viewModel.trailingTitle
110121
self.trailingValue = viewModel.trailingValue
111122
self.trailingDelta = viewModel.trailingDelta
112123
self.trailingDeltaColor = viewModel.trailingDeltaColor
113124
self.trailingDeltaTextColor = viewModel.trailingDeltaTextColor
114125
self.trailingChartData = viewModel.trailingChartData
126+
self.trailingChartColor = viewModel.trailingChartColor
115127
self.isRedacted = viewModel.isRedacted
116128
self.showSyncError = viewModel.showSyncError
117129
self.syncErrorMessage = viewModel.syncErrorMessage

0 commit comments

Comments
 (0)