Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chartdata collection refactor #3024

Merged
merged 29 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6e80eb0
Added Collection conformances
jjatie Nov 18, 2017
d36d11b
[#3018]
jjatie Nov 19, 2017
36ca566
Fixed required initializers
jjatie Nov 20, 2017
cb32b08
ChartData adopts ExressibleByArrayLiteral
jjatie Dec 1, 2017
ad0d148
Merge remote-tracking branch 'origin/chartdata-collection-conformance…
jjatie Dec 1, 2017
fcd9fa2
Modified demos
jjatie Dec 1, 2017
716f182
Pulled latest 4.0.0 and code style fixes
jjatie Jan 6, 2018
ca5afad
Updates for PR
jjatie Jan 11, 2018
0d41175
Pulled latest base
jjatie Jan 11, 2018
8976b95
PR review fixes
jjatie Jan 12, 2018
f28d3d5
Removed unnecessary `get` from subscripts.
jjatie Jan 12, 2018
793e437
Merge remote-tracking branch 'origin/chartdata-collection-conformance…
jjatie Jan 15, 2018
583dab6
Disabled `remove(at:)` for CombinedChartView
jjatie Jan 15, 2018
0cce64d
Merge remote-tracking branch 'origin/chartdata-collection-conformance…
jjatie Jan 15, 2018
47b6a1c
Removed redundant methods
jjatie Jan 15, 2018
c0b7d65
Relocated `appendEntry(_:todataSet:)`
jjatie Jan 15, 2018
1d1e380
Merge remote-tracking branch 'origin/chartdata-collection-conformance…
jjatie Jan 15, 2018
a71f87c
Removed methods from CombinedChartData
jjatie Jan 15, 2018
efc5a72
Merge remote-tracking branch 'origin/chartdata-collection-conformance…
jjatie Jan 15, 2018
bfb750b
Merge branch '4.0.0' into chartdata-collection-refactor
jjatie Jan 15, 2018
6adde98
Merge branch '4.0.0' into chartdata-collection-refactor
jjatie Jan 15, 2018
ae8279a
Merge branch '4.0.0' into chartdata-collection-refactor
jjatie Jan 16, 2018
6de1114
Merge branch '4.0.0' into chartdata-collection-refactor
jjatie Jan 16, 2018
37b29ad
Merge branch '4.0.0' of https://github.com/danielgindi/Charts into ch…
jjatie Jan 21, 2018
329e00c
Fixed merge conflicts
jjatie Jan 21, 2018
2572f04
Merge remote-tracking branch 'upstream/4.0.0' into chartdata-collecti…
jjatie Jan 23, 2018
31a76eb
Fixed merge conflicts
jjatie Jan 23, 2018
b7e6f93
updated demos
jjatie Jan 26, 2018
eb8e031
Updated macOS demos
jjatie Jan 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ open class BarDemoViewController: NSViewController
let data = BarChartData()
let ds1 = BarChartDataSet(values: yse1, label: "Hello")
ds1.colors = [NSUIColor.red]
data.addDataSet(ds1)
data.append(ds1)

let ds2 = BarChartDataSet(values: yse2, label: "World")
ds2.colors = [NSUIColor.blue]
data.addDataSet(ds2)
data.append(ds2)

let barWidth = 0.4
let barSpace = 0.05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ open class LineDemoViewController: NSViewController
let data = LineChartData()
let ds1 = LineChartDataSet(values: yse1, label: "Hello")
ds1.colors = [NSUIColor.red]
data.addDataSet(ds1)
data.append(ds1)

let ds2 = LineChartDataSet(values: yse2, label: "World")
ds2.colors = [NSUIColor.blue]
data.addDataSet(ds2)
data.append(ds2)
self.lineChartView.data = data

self.lineChartView.gridBackgroundColor = NSUIColor.white
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ open class PieDemoViewController: NSViewController

ds1.colors = ChartColorTemplates.vordiplom()

data.addDataSet(ds1)
data.append(ds1)

let paragraphStyle: NSMutableParagraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paragraphStyle.lineBreakMode = .byTruncatingTail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ open class RadarDemoViewController: NSViewController
let data = RadarChartData()
let ds1 = RadarChartDataSet(values: yse1, label: "Hello")
ds1.colors = [NSUIColor.red]
data.addDataSet(ds1)
data.append(ds1)

let ds2 = RadarChartDataSet(values: yse2, label: "World")
ds2.colors = [NSUIColor.blue]
data.addDataSet(ds2)
data.append(ds2)
self.radarChartView.data = data
self.radarChartView.chartDescription.text = "Radarchart Demo"

Expand Down
6 changes: 3 additions & 3 deletions ChartsDemo/Swift/DemoBaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ class DemoBaseViewController: UIViewController, ChartViewDelegate {
func handleOption(_ option: Option, forChartView chartView: ChartViewBase) {
switch option {
case .toggleValues:
for set in chartView.data!.dataSets {
for set in chartView.data! {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a feeling that for set in data is less natural than for set in data.dataSets, what you think? Maybe need time to adapt?
So in the future, we will deprecate data.dataSet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's just new to you. We need to continue to support data.dataSet as long as we keep Obj-C compatibility.

set.drawValuesEnabled = !set.drawValuesEnabled
}
chartView.setNeedsDisplay()

case .toggleIcons:
for set in chartView.data!.dataSets {
for set in chartView.data! {
set.drawIconsEnabled = !set.drawIconsEnabled
}
chartView.setNeedsDisplay()
Expand Down Expand Up @@ -159,7 +159,7 @@ class DemoBaseViewController: UIViewController, ChartViewDelegate {
updateChartData()

case .toggleBarBorders:
for set in chartView.data!.dataSets {
for set in chartView.data! {
if let set = set as? BarChartDataSet {
set.barBorderWidth = set.barBorderWidth == 1.0 ? 0.0 : 1.0
}
Expand Down
2 changes: 1 addition & 1 deletion ChartsDemo/Swift/Demos/AnotherBarChartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class AnotherBarChartViewController: DemoBaseViewController {
}

var set1: BarChartDataSet! = nil
if let set = chartView.data?.dataSets.first as? BarChartDataSet {
if let set = chartView.data?.first as? BarChartDataSet {
set1 = set
set1?.values = yVals
chartView.data?.notifyDataChanged()
Expand Down
2 changes: 1 addition & 1 deletion ChartsDemo/Swift/Demos/BarChartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class BarChartViewController: DemoBaseViewController {
}

var set1: BarChartDataSet! = nil
if let set = chartView.data?.dataSets.first as? BarChartDataSet {
if let set = chartView.data?.first as? BarChartDataSet {
set1 = set
set1.values = yVals
chartView.data?.notifyDataChanged()
Expand Down
2 changes: 1 addition & 1 deletion ChartsDemo/Swift/Demos/BubbleChartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class BubbleChartViewController: DemoBaseViewController {
set3.setColor(ChartColorTemplates.colorful()[2], alpha: 0.5)
set3.drawValuesEnabled = true

let data = BubbleChartData(dataSets: [set1, set2, set3])
let data = [set1, set2, set3] as BubbleChartData
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may I know which protocol method enables this convenient conversion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpressibleByArrayLiteral

data.setDrawValues(false)
data.setValueFont(UIFont(name: "HelveticaNeue-Light", size: 7)!)
data.setHighlightCircleWidth(1.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class CandleStickChartViewController: DemoBaseViewController {

override func optionTapped(_ option: Option) {
if .toggleShadowColorSameAsCandle ~= option {
for set in chartView.data!.dataSets as! [CandleChartDataSet] {
for case let set as CandleChartDataSet in chartView.data! {
set.shadowColorSameAsCandle = !set.shadowColorSameAsCandle
}
chartView.notifyDataSetChanged()
Expand Down
6 changes: 3 additions & 3 deletions ChartsDemo/Swift/Demos/CombinedChartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class CombinedChartViewController: DemoBaseViewController {
override func optionTapped(_ option: Option) {
switch option {
case .toggleLineValues:
for set in chartView.data!.dataSets {
for set in chartView.data! {
if let set = set as? LineChartDataSet {
set.drawValuesEnabled = !set .drawValuesEnabled

Expand All @@ -103,7 +103,7 @@ class CombinedChartViewController: DemoBaseViewController {
chartView.setNeedsDisplay()

case .toggleBarValues:
for set in chartView.data!.dataSets {
for set in chartView.data! {
if let set = set as? BarChartDataSet {
set.drawValuesEnabled = !set .drawValuesEnabled
}
Expand Down Expand Up @@ -171,7 +171,7 @@ class CombinedChartViewController: DemoBaseViewController {
let barWidth = 0.45 // x2 dataset
// (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group"

let data = BarChartData(dataSets: [set1, set2])
let data: BarChartData = [set1, set2]
data.barWidth = barWidth

// make this BarData object grouped
Expand Down
12 changes: 7 additions & 5 deletions ChartsDemo/Swift/Demos/CubicLineChartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,35 @@ class CubicLineChartViewController: DemoBaseViewController {
}

override func optionTapped(_ option: Option) {
guard let data = chartView.data else { return }

switch option {
case .toggleFilled:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.drawFilledEnabled = !set.drawFilledEnabled
}
chartView.setNeedsDisplay()

case .toggleCircles:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.drawCirclesEnabled = !set.drawCirclesEnabled
}
chartView.setNeedsDisplay()

case .toggleCubic:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .cubicBezier) ? .linear : .cubicBezier
}
chartView.setNeedsDisplay()

case .toggleStepped:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .stepped) ? .linear : .stepped
}
chartView.setNeedsDisplay()

case .toggleHorizontalCubic:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .cubicBezier) ? .horizontalBezier : .cubicBezier
}
chartView.setNeedsDisplay()
Expand Down
12 changes: 7 additions & 5 deletions ChartsDemo/Swift/Demos/LineChart1ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,35 @@ class LineChart1ViewController: DemoBaseViewController {
}

override func optionTapped(_ option: Option) {
guard let data = chartView.data else { return }

switch option {
case .toggleFilled:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.drawFilledEnabled = !set.drawFilledEnabled
}
chartView.setNeedsDisplay()

case .toggleCircles:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.drawCirclesEnabled = !set.drawCirclesEnabled
}
chartView.setNeedsDisplay()

case .toggleCubic:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .cubicBezier) ? .linear : .cubicBezier
}
chartView.setNeedsDisplay()

case .toggleStepped:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .stepped) ? .linear : .stepped
}
chartView.setNeedsDisplay()

case .toggleHorizontalCubic:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .cubicBezier) ? .horizontalBezier : .cubicBezier
}
chartView.setNeedsDisplay()
Expand Down
14 changes: 8 additions & 6 deletions ChartsDemo/Swift/Demos/LineChart2ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,41 +135,43 @@ class LineChart2ViewController: DemoBaseViewController {
set3.highlightColor = UIColor(red: 244/255, green: 117/255, blue: 117/255, alpha: 1)
set3.drawCircleHoleEnabled = false

let data = LineChartData(dataSets: [set1, set2, set3])
let data: LineChartData = [set1, set2, set3]
data.setValueTextColor(.white)
data.setValueFont(.systemFont(ofSize: 9))

chartView.data = data
}

override func optionTapped(_ option: Option) {
guard let data = chartView.data else { return }

switch option {
case .toggleFilled:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.drawFilledEnabled = !set.drawFilledEnabled
}
chartView.setNeedsDisplay()

case .toggleCircles:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.drawCirclesEnabled = !set.drawCirclesEnabled
}
chartView.setNeedsDisplay()

case .toggleCubic:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .cubicBezier) ? .linear : .cubicBezier
}
chartView.setNeedsDisplay()

case .toggleStepped:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .stepped) ? .linear : .stepped
}
chartView.setNeedsDisplay()

case .toggleHorizontalCubic:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .cubicBezier) ? .horizontalBezier : .cubicBezier
}
chartView.setNeedsDisplay()
Expand Down
2 changes: 1 addition & 1 deletion ChartsDemo/Swift/Demos/LineChartFilledViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class LineChartFilledViewController: DemoBaseViewController {
return CGFloat(self.chartView.leftAxis.axisMaximum)
}

let data = LineChartData(dataSets: [set1, set2])
let data: LineChartData = [set1, set2]
data.setDrawValues(false)

chartView.data = data
Expand Down
12 changes: 7 additions & 5 deletions ChartsDemo/Swift/Demos/LineChartTimeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,33 +118,35 @@ class LineChartTimeViewController: DemoBaseViewController {
}

override func optionTapped(_ option: Option) {
guard let data = chartView.data else { return }

switch option {
case .toggleFilled:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.drawFilledEnabled = !set.drawFilledEnabled
}
chartView.setNeedsDisplay()

case .toggleCircles:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.drawCirclesEnabled = !set.drawCirclesEnabled
}
chartView.setNeedsDisplay()

case .toggleCubic:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .cubicBezier) ? .linear : .cubicBezier
}
chartView.setNeedsDisplay()

case .toggleStepped:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .stepped) ? .linear : .stepped
}
chartView.setNeedsDisplay()

case .toggleHorizontalCubic:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .cubicBezier) ? .horizontalBezier : .cubicBezier
}
chartView.setNeedsDisplay()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class MultipleBarChartViewController: DemoBaseViewController {
let set4 = BarChartDataSet(values: yVals4, label: "Company D")
set4.setColor(UIColor(red: 255/255, green: 102/255, blue: 0/255, alpha: 1))

let data = BarChartData(dataSets: [set1, set2, set3, set4])
let data: BarChartData = [set1, set2, set3, set4]
data.setValueFont(.systemFont(ofSize: 10, weight: .light))
data.setValueFormatter(LargeValueFormatter())

Expand Down
10 changes: 6 additions & 4 deletions ChartsDemo/Swift/Demos/MultipleLinesChartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,29 @@ class MultipleLinesChartViewController: DemoBaseViewController {
}

override func optionTapped(_ option: Option) {
guard let data = chartView.data else { return }

switch option {
case .toggleFilled:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.drawFilledEnabled = !set.drawFilledEnabled
}
chartView.setNeedsDisplay()

case .toggleCircles:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.drawCirclesEnabled = !set.drawCirclesEnabled
}
chartView.setNeedsDisplay()

case .toggleCubic:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .cubicBezier) ? .linear : .cubicBezier
}
chartView.setNeedsDisplay()

case .toggleStepped:
for set in chartView.data!.dataSets as! [LineChartDataSet] {
for case let set as LineChartDataSet in data {
set.mode = (set.mode == .stepped) ? .linear : .stepped
}
chartView.setNeedsDisplay()
Expand Down
8 changes: 5 additions & 3 deletions ChartsDemo/Swift/Demos/RadarChartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class RadarChartViewController: DemoBaseViewController {
set2.drawHighlightCircleEnabled = true
set2.setDrawHighlightIndicators(false)

let data = RadarChartData(dataSets: [set1, set2])
let data: RadarChartData = [set1, set2]
data.setValueFont(.systemFont(ofSize: 8, weight: .light))
data.setDrawValues(false)
data.setValueTextColor(.white)
Expand All @@ -151,6 +151,8 @@ class RadarChartViewController: DemoBaseViewController {
}

override func optionTapped(_ option: Option) {
guard let data = chartView.data else { return }

switch option {
case .toggleXLabels:
chartView.xAxis.drawLabelsEnabled = !chartView.xAxis.drawLabelsEnabled
Expand All @@ -166,14 +168,14 @@ class RadarChartViewController: DemoBaseViewController {
chartView.rotationEnabled = !chartView.rotationEnabled

case .toggleFilled:
for set in chartView.data!.dataSets as! [RadarChartDataSet] {
for case let set as RadarChartDataSet in data {
set.drawFilledEnabled = !set.drawFilledEnabled
}

chartView.setNeedsDisplay()

case .toggleHighlightCircle:
for set in chartView.data!.dataSets as! [RadarChartDataSet] {
for case let set as RadarChartDataSet in data {
set.drawHighlightCircleEnabled = !set.drawHighlightCircleEnabled
}
chartView.setNeedsDisplay()
Expand Down
Loading