Skip to content

Commit ae57df7

Browse files
committed
Added style to chart
1 parent a31062d commit ae57df7

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

WooCommerce/Classes/Extensions/Date+Helpers.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension DateFormatter {
2929
let formatter = DateFormatter()
3030
formatter.locale = Locale(identifier: "en_US_POSIX")
3131
formatter.timeZone = TimeZone(identifier: "GMT")
32-
formatter.dateFormat = "MMM dd"
32+
formatter.dateFormat = "MMM d"
3333
return formatter
3434
}()
3535

@@ -39,7 +39,7 @@ extension DateFormatter {
3939
let formatter = DateFormatter()
4040
formatter.locale = Locale(identifier: "en_US_POSIX")
4141
formatter.timeZone = TimeZone(identifier: "GMT")
42-
formatter.dateFormat = "MMM yyyy"
42+
formatter.dateFormat = "MMM d"
4343
return formatter
4444
}()
4545

@@ -49,7 +49,7 @@ extension DateFormatter {
4949
let formatter = DateFormatter()
5050
formatter.locale = Locale(identifier: "en_US_POSIX")
5151
formatter.timeZone = TimeZone(identifier: "GMT")
52-
formatter.dateFormat = "MMM yyyy"
52+
formatter.dateFormat = "MMM"
5353
return formatter
5454
}()
5555

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class PeriodDataViewController: UIViewController, IndicatorInfoProvider {
6666
}
6767

6868
let dataSet = BarChartDataSet(values: dataEntries, label: "Data")
69+
dataSet.setColor(StyleManager.wooCommerceBrandColor)
6970
return BarChartData(dataSet: dataSet)
7071
}
7172

@@ -148,33 +149,36 @@ private extension PeriodDataViewController {
148149
barChartView.noDataText = NSLocalizedString("No data available", comment: "Text displayed when no data is available for revenue chart.")
149150
barChartView.noDataFont = StyleManager.chartLabelFont
150151
barChartView.noDataTextColor = StyleManager.wooSecondary
152+
barChartView.extraRightOffset = Constants.chartExtraRightOffset
151153

152154
let xAxis = barChartView.xAxis
153155
xAxis.labelPosition = .bottom
156+
xAxis.setLabelCount(2, force: true)
154157
xAxis.labelFont = StyleManager.chartLabelFont
155158
xAxis.labelTextColor = StyleManager.wooSecondary
156159
xAxis.axisLineColor = StyleManager.wooGreyBorder
157160
xAxis.gridColor = StyleManager.wooGreyBorder
158161
xAxis.drawLabelsEnabled = true
159162
xAxis.drawGridLinesEnabled = false
160163
xAxis.drawAxisLineEnabled = false
161-
xAxis.granularity = 1.0
164+
xAxis.granularity = Constants.chartXAxisGranularity
162165
xAxis.granularityEnabled = true
163-
xAxis.setLabelCount(2, force: true)
164166
xAxis.valueFormatter = self
165167

166168
let yAxis = barChartView.leftAxis
167169
yAxis.labelFont = StyleManager.chartLabelFont
168170
yAxis.labelTextColor = StyleManager.wooSecondary
169171
yAxis.axisLineColor = StyleManager.wooGreyBorder
170172
yAxis.gridColor = StyleManager.wooGreyBorder
173+
yAxis.gridLineDashLengths = Constants.chartXAxisDashLengths
174+
yAxis.axisLineDashPhase = Constants.chartXAxisDashPhase
171175
yAxis.zeroLineColor = StyleManager.wooGreyBorder
172-
yAxis.valueFormatter = self
173176
yAxis.drawLabelsEnabled = true
174177
yAxis.drawGridLinesEnabled = true
175178
yAxis.drawAxisLineEnabled = false
176179
yAxis.drawZeroLineEnabled = true
177-
yAxis.axisMinimum = 0
180+
yAxis.axisMinimum = Constants.chartYAxisMinimum
181+
yAxis.valueFormatter = self
178182
}
179183
}
180184

@@ -280,7 +284,12 @@ extension PeriodDataViewController: IAxisValueFormatter {
280284
return ""
281285
}
282286
} else {
283-
return value.friendlyString()
287+
if value == 0.0 {
288+
// Do not show the 0 label on the Y axis
289+
return ""
290+
} else {
291+
return value.friendlyString()
292+
}
284293
}
285294
}
286295
}
@@ -290,7 +299,14 @@ extension PeriodDataViewController: IAxisValueFormatter {
290299
//
291300
private extension PeriodDataViewController {
292301
enum Constants {
293-
static let placeholderText = "-"
294-
static let chartAnimationDuration = 0.75
302+
static let placeholderText = "-"
303+
304+
static let chartAnimationDuration: TimeInterval = 0.75
305+
static let chartExtraRightOffset: CGFloat = 20.0
306+
307+
static let chartXAxisDashLengths: [CGFloat] = [5.0, 5.0]
308+
static let chartXAxisDashPhase: CGFloat = 0.0
309+
static let chartXAxisGranularity: Double = 1.0
310+
static let chartYAxisMinimum: Double = 0.0
295311
}
296312
}

0 commit comments

Comments
 (0)