Skip to content

Commit fdaf8e9

Browse files
authored
Merge pull request #326 from woocommerce/feature/261-chart-style
Dashboard: Updated chart style
2 parents bb05110 + dc28979 commit fdaf8e9

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

Networking/Networking/Extensions/DateFormatter+Woo.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public extension DateFormatter {
3131
public static let statsDayFormatter: DateFormatter = {
3232
let formatter = DateFormatter()
3333
formatter.locale = Locale(identifier: "en_US_POSIX")
34-
formatter.timeZone = TimeZone(identifier: "GMT")
3534
formatter.dateFormat = "yyyy'-'MM'-'dd"
3635
return formatter
3736
}()
@@ -42,7 +41,6 @@ public extension DateFormatter {
4241
public static let statsWeekFormatter: DateFormatter = {
4342
let formatter = DateFormatter()
4443
formatter.locale = Locale(identifier: "en_US_POSIX")
45-
formatter.timeZone = TimeZone(identifier: "GMT")
4644
formatter.dateFormat = "yyyy'-W'ww"
4745
return formatter
4846
}()
@@ -53,7 +51,6 @@ public extension DateFormatter {
5351
public static let statsMonthFormatter: DateFormatter = {
5452
let formatter = DateFormatter()
5553
formatter.locale = Locale(identifier: "en_US_POSIX")
56-
formatter.timeZone = TimeZone(identifier: "GMT")
5754
formatter.dateFormat = "yyyy'-'MM"
5855
return formatter
5956
}()
@@ -64,7 +61,6 @@ public extension DateFormatter {
6461
public static let statsYearFormatter: DateFormatter = {
6562
let formatter = DateFormatter()
6663
formatter.locale = Locale(identifier: "en_US_POSIX")
67-
formatter.timeZone = TimeZone(identifier: "GMT")
6864
formatter.dateFormat = "yyyy"
6965
return formatter
7066
}()

WooCommerce/Classes/Model/OrderStats+Woo.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ import Yosemite
66
//
77
extension OrderStats {
88

9-
/// Returns the Currency Symbol associated with the current order stats.
9+
/// Returns the currency code associated with the current order stats.
1010
///
11-
var currencySymbol: String {
12-
guard let currency = items?.filter({ !$0.currency.isEmpty }).first?.currency else {
13-
return ""
14-
}
15-
guard let identifier = Locale.availableIdentifiers.first(where: { Locale(identifier: $0).currencyCode == currency }) else {
16-
return currency
11+
var currencyCode: String {
12+
guard let currencyCode = items?.filter({ !$0.currency.isEmpty }).first?.currency else {
13+
return String()
1714
}
1815

19-
return Locale(identifier: identifier).currencySymbol ?? currency
16+
return currencyCode
2017
}
2118

2219
/// Returns the sum of total sales this stats period. This value is typically used in the dashboard for revenue reporting.

WooCommerce/Classes/Model/TopEarnerStatsItem+Woo.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ extension TopEarnerStatsItem {
1010
///
1111
var currencySymbol: String {
1212
guard !currency.isEmpty else {
13-
return ""
13+
return String()
1414
}
15-
guard let identifier = Locale.availableIdentifiers.first(where: { Locale(identifier: $0).currencyCode == currency }) else {
16-
return currency
17-
}
18-
19-
return Locale(identifier: identifier).currencySymbol ?? currency
15+
return MoneyFormatter().currencySymbol(currencyCode: currency) ?? String()
2016
}
2117

2218
/// Returns a friendly-formatted total string including the currency symbol

WooCommerce/Classes/ViewRelated/Dashboard/MyStore/PeriodDataViewController.swift

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ class PeriodDataViewController: UIViewController, IndicatorInfoProvider {
5353

5454
// MARK: - Computed Properties
5555

56+
private var currencySymbol: String {
57+
guard let code = orderStats?.currencyCode else {
58+
return String()
59+
}
60+
return MoneyFormatter().currencySymbol(currencyCode: code) ?? String()
61+
}
62+
5663
private var summaryDateUpdated: String {
5764
if let lastUpdatedDate = lastUpdatedDate {
5865
return String.localizedStringWithFormat(NSLocalizedString("Updated %@",
@@ -172,6 +179,7 @@ private extension PeriodDataViewController {
172179
barChartView.noDataFont = StyleManager.chartLabelFont
173180
barChartView.noDataTextColor = StyleManager.wooSecondary
174181
barChartView.extraRightOffset = Constants.chartExtraRightOffset
182+
barChartView.extraTopOffset = Constants.chartExtraTopOffset
175183
barChartView.delegate = self
176184

177185
let xAxis = barChartView.xAxis
@@ -193,15 +201,14 @@ private extension PeriodDataViewController {
193201
yAxis.labelTextColor = StyleManager.wooSecondary
194202
yAxis.axisLineColor = StyleManager.wooGreyBorder
195203
yAxis.gridColor = StyleManager.wooGreyBorder
196-
yAxis.gridLineDashLengths = Constants.chartXAxisDashLengths
197-
yAxis.axisLineDashPhase = Constants.chartXAxisDashPhase
198204
yAxis.zeroLineColor = StyleManager.wooGreyBorder
199205
yAxis.drawLabelsEnabled = true
200206
yAxis.drawGridLinesEnabled = true
201207
yAxis.drawAxisLineEnabled = false
202208
yAxis.drawZeroLineEnabled = true
203209
yAxis.axisMinimum = Constants.chartYAxisMinimum
204210
yAxis.valueFormatter = self
211+
yAxis.setLabelCount(3, force: true)
205212
}
206213
}
207214

@@ -257,7 +264,7 @@ extension PeriodDataViewController: IAxisValueFormatter {
257264
return ""
258265
} else {
259266
yAxisMaximum = value.friendlyString()
260-
return yAxisMaximum
267+
return currencySymbol + yAxisMaximum
261268
}
262269
}
263270
}
@@ -319,9 +326,8 @@ private extension PeriodDataViewController {
319326
var totalRevenueText = Constants.placeholderText
320327
if let orderStats = orderStats {
321328
totalOrdersText = Double(orderStats.totalOrders).friendlyString()
322-
let currencySymbol = orderStats.currencySymbol
323329
let totalRevenue = orderStats.totalSales.friendlyString()
324-
totalRevenueText = "\(currencySymbol)\(totalRevenue)"
330+
totalRevenueText = currencySymbol + totalRevenue
325331
}
326332
ordersData.text = totalOrdersText
327333
revenueData.text = totalRevenueText
@@ -364,16 +370,18 @@ private extension PeriodDataViewController {
364370
}
365371

366372
var barCount = 0
373+
var barColors: [UIColor] = []
367374
var dataEntries: [BarChartDataEntry] = []
368375
statItems.forEach { (item) in
369376
let entry = BarChartDataEntry(x: Double(barCount), y: item.totalSales)
370-
entry.accessibilityValue = "\(item.period): \(orderStats.currencySymbol)\(item.totalSales.friendlyString())"
377+
entry.accessibilityValue = "\(item.period): \(currencySymbol)\(item.totalSales.friendlyString())"
378+
barColors.append(barColor(for: item.period))
371379
dataEntries.append(entry)
372380
barCount += 1
373381
}
374382

375383
let dataSet = BarChartDataSet(values: dataEntries, label: "Data")
376-
dataSet.setColor(StyleManager.wooCommerceBrandColor)
384+
dataSet.colors = barColors
377385
dataSet.highlightEnabled = true
378386
dataSet.highlightColor = StyleManager.wooAccent
379387
dataSet.highlightAlpha = Constants.chartHighlightAlpha
@@ -403,6 +411,16 @@ private extension PeriodDataViewController {
403411
}
404412
return dateString
405413
}
414+
415+
func barColor(for period: String) -> UIColor {
416+
guard granularity == .day,
417+
let periodDate = DateFormatter.Stats.statsDayFormatter.date(from: period),
418+
Calendar.current.isDateInWeekend(periodDate) else {
419+
return StyleManager.wooCommerceBrandColor
420+
}
421+
422+
return StyleManager.wooGreyMid
423+
}
406424
}
407425

408426

@@ -414,14 +432,13 @@ private extension PeriodDataViewController {
414432

415433
static let chartAnimationDuration: TimeInterval = 0.75
416434
static let chartExtraRightOffset: CGFloat = 25.0
435+
static let chartExtraTopOffset: CGFloat = 20.0
417436
static let chartHighlightAlpha: CGFloat = 1.0
418437

419438
static let chartMarkerInsets: UIEdgeInsets = UIEdgeInsets(top: 5.0, left: 2.0, bottom: 5.0, right: 2.0)
420439
static let chartMarkerMinimumSize: CGSize = CGSize(width: 50.0, height: 30.0)
421440
static let chartMarkerArrowSize: CGSize = CGSize(width: 8, height: 6)
422441

423-
static let chartXAxisDashLengths: [CGFloat] = [5.0, 5.0]
424-
static let chartXAxisDashPhase: CGFloat = 0.0
425442
static let chartXAxisGranularity: Double = 1.0
426443
static let chartYAxisMinimum: Double = 0.0
427444
}

0 commit comments

Comments
 (0)