Skip to content

Commit

Permalink
Refactored ChartData (#3169)
Browse files Browse the repository at this point in the history
* Added Collection conformances

MutableCollection
RandomAccessCollection
RangeReplaceableCollection

* [#3018]

Refactored use of `ChartData` to use new `Collection` conformances

* Fixed required initializers

* ChartData adopts ExressibleByArrayLiteral

* Modified demos

to take advantage of collection conformance.

* Updates for PR

Also added remove subrange.

* Refactored ChartData

Removed redundancy from min/max logic.
Lots of naming changes.
Cleaner implementations.

* PR review fixes

* Removed unnecessary `get` from subscripts.

* Disabled `remove(at:)` for CombinedChartView

* Removed redundant methods

* Relocated `appendEntry(_:todataSet:)`

* pulled latest 4.0.0

* Disabled Collection support for CombinedChartData

* Removed methods from CombinedChartData

* Pulled latest 4.0

* Fixes after merge

* Removed used of dataSet(forIndex:)

* Fixed merge conflicts

* Fixed merge conflicts

* updated demos

* Pulled latest 4.0.0

* Fixed demos

* Fixed objective c demos

* Moved travis to Xcode 9.3 beta temporarily

* Fixed macOS demo info.plist and tv demo device name

* PR Fixes

* Fixed objective-c naming

* PR Fixes

* fix comment
  • Loading branch information
jjatie authored and liuxuan30 committed Apr 8, 2018
1 parent 32ef09e commit d74ce61
Show file tree
Hide file tree
Showing 37 changed files with 281 additions and 492 deletions.
86 changes: 47 additions & 39 deletions Charts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@
098621EDFBF928494B94BEA1 /* Data */ = {
isa = PBXGroup;
children = (
3B9DD76FCE8D873300A822C7 /* Implementations */,
22C014222006FFE800D5B025 /* ChartData */,
3B9DD76FCE8D873300A822C7 /* ChartDataSet */,
22C014232006FFFA00D5B025 /* ChartEntry */,
DB2D9648877455028EBEAA8F /* DataSet Protocols */,
);
name = Data;
Expand Down Expand Up @@ -409,6 +411,37 @@
name = ChartRenderers;
sourceTree = "<group>";
};
22C014222006FFE800D5B025 /* ChartData */ = {
isa = PBXGroup;
children = (
0108D5925E21A47DA36A66AA /* BarChartData.swift */,
559DB735FEA17AB90676D6CA /* BarLineScatterCandleBubbleChartData.swift */,
7EDA3AD550AEFC93C8D15B9C /* BubbleChartData.swift */,
F4785FEACAE4367F36FB8868 /* CandleChartData.swift */,
E120E76C6F1B5877D56126DD /* ChartData.swift */,
0DDE409E9ECF54D2C146A6F0 /* CombinedChartData.swift */,
4C978F31F23C7D21197DC2A1 /* LineChartData.swift */,
6E03A4987F72414A02A0631B /* PieChartData.swift */,
4BBB57D6FA41029B08F26D7B /* RadarChartData.swift */,
E7AD2FC320A16CA1EE0A52F4 /* ScatterChartData.swift */,
);
name = ChartData;
sourceTree = "<group>";
};
22C014232006FFFA00D5B025 /* ChartEntry */ = {
isa = PBXGroup;
children = (
E3F8BFF1CBC58D5B9DBFFB9B /* BarChartDataEntry.swift */,
DD8ED233775EEC31243A6919 /* BubbleChartDataEntry.swift */,
D2E698FF540029B70AC97AD7 /* CandleChartDataEntry.swift */,
F22750328058DEC2F019646F /* ChartDataEntry.swift */,
12409C3EA15787C11AF0D2BC /* ChartDataEntryBase.swift */,
BD02157CF8CEE1189BF681DA /* PieChartDataEntry.swift */,
91EEEDE2AB8F2DA3AFCF0733 /* RadarChartDataEntry.swift */,
);
name = ChartEntry;
sourceTree = "<group>";
};
2647844720BC6574A544A337 /* Charts */ = {
isa = PBXGroup;
children = (
Expand All @@ -427,13 +460,23 @@
name = Charts;
sourceTree = "<group>";
};
3B9DD76FCE8D873300A822C7 /* Implementations */ = {
3B9DD76FCE8D873300A822C7 /* ChartDataSet */ = {
isa = PBXGroup;
children = (
C9FE42E868A225C116537368 /* ChartBaseDataSet.swift */,
740017197A160047EBB8A9A0 /* Standard */,
C31AA65EA27776F8C653C7E8 /* BarChartDataSet.swift */,
6D717F0808DE7EC8A4AE9C2A /* BarLineScatterCandleBubbleChartDataSet.swift */,
B44829AF0ADA583F1F0279B7 /* BubbleChartDataSet.swift */,
274116834B1B0345D622E027 /* CandleChartDataSet.swift */,
6CEC0C69C89CE9B99F3B4409 /* ChartDataSet.swift */,
A5A75AA73C5AA381DA517959 /* LineChartDataSet.swift */,
45E31A4356CC6F283C29954B /* LineRadarChartDataSet.swift */,
C58BD7B14BEA440783ED8D2B /* LineScatterCandleRadarChartDataSet.swift */,
A4FB5E3761EF8B4D1E1E1014 /* PieChartDataSet.swift */,
B1BA6B21CBDF77A15848994F /* RadarChartDataSet.swift */,
CB1DD1A0F64266A10EE94194 /* ScatterChartDataSet.swift */,
);
name = Implementations;
name = ChartDataSet;
sourceTree = "<group>";
};
42824E1F334B0C484AF4C594 /* Highlight */ = {
Expand Down Expand Up @@ -471,41 +514,6 @@
name = Components;
sourceTree = "<group>";
};
740017197A160047EBB8A9A0 /* Standard */ = {
isa = PBXGroup;
children = (
0108D5925E21A47DA36A66AA /* BarChartData.swift */,
E3F8BFF1CBC58D5B9DBFFB9B /* BarChartDataEntry.swift */,
C31AA65EA27776F8C653C7E8 /* BarChartDataSet.swift */,
559DB735FEA17AB90676D6CA /* BarLineScatterCandleBubbleChartData.swift */,
6D717F0808DE7EC8A4AE9C2A /* BarLineScatterCandleBubbleChartDataSet.swift */,
7EDA3AD550AEFC93C8D15B9C /* BubbleChartData.swift */,
DD8ED233775EEC31243A6919 /* BubbleChartDataEntry.swift */,
B44829AF0ADA583F1F0279B7 /* BubbleChartDataSet.swift */,
F4785FEACAE4367F36FB8868 /* CandleChartData.swift */,
D2E698FF540029B70AC97AD7 /* CandleChartDataEntry.swift */,
274116834B1B0345D622E027 /* CandleChartDataSet.swift */,
E120E76C6F1B5877D56126DD /* ChartData.swift */,
F22750328058DEC2F019646F /* ChartDataEntry.swift */,
12409C3EA15787C11AF0D2BC /* ChartDataEntryBase.swift */,
6CEC0C69C89CE9B99F3B4409 /* ChartDataSet.swift */,
0DDE409E9ECF54D2C146A6F0 /* CombinedChartData.swift */,
4C978F31F23C7D21197DC2A1 /* LineChartData.swift */,
A5A75AA73C5AA381DA517959 /* LineChartDataSet.swift */,
45E31A4356CC6F283C29954B /* LineRadarChartDataSet.swift */,
C58BD7B14BEA440783ED8D2B /* LineScatterCandleRadarChartDataSet.swift */,
6E03A4987F72414A02A0631B /* PieChartData.swift */,
BD02157CF8CEE1189BF681DA /* PieChartDataEntry.swift */,
A4FB5E3761EF8B4D1E1E1014 /* PieChartDataSet.swift */,
4BBB57D6FA41029B08F26D7B /* RadarChartData.swift */,
91EEEDE2AB8F2DA3AFCF0733 /* RadarChartDataEntry.swift */,
B1BA6B21CBDF77A15848994F /* RadarChartDataSet.swift */,
E7AD2FC320A16CA1EE0A52F4 /* ScatterChartData.swift */,
CB1DD1A0F64266A10EE94194 /* ScatterChartDataSet.swift */,
);
name = Standard;
sourceTree = "<group>";
};
74A391010038924F637D6752 /* Formatters */ = {
isa = PBXGroup;
children = (
Expand Down
2 changes: 1 addition & 1 deletion ChartsDemo-iOS/Objective-C/DemoBaseViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ - (void)handleOption:(NSString *)key forChartView:(ChartViewBase *)chartView

if ([key isEqualToString:@"toggleHighlight"])
{
chartView.data.highlightEnabled = !chartView.data.isHighlightEnabled;
chartView.data.isHighlightEnabled = !chartView.data.isHighlightEnabled;
[chartView setNeedsDisplay];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ - (void)viewDidLoad

- (void)setupChart:(LineChartView *)chart data:(LineChartData *)data color:(UIColor *)color
{
[(LineChartDataSet *)[data getDataSetByIndex:0] setCircleHoleColor:color];
[(LineChartDataSet *)[data dataSetAtIndex:0] setCircleHoleColor:color];

chart.delegate = self;
chart.backgroundColor = color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ - (void)optionTapped:(NSString *)key
if ([key isEqualToString:@"removeDataSet"])
{
int rnd = (int)arc4random_uniform((float)_chartView.data.dataSetCount);
[_chartView.data removeDataSet:[_chartView.data getDataSetByIndex:rnd]];
[_chartView.data removeDataSet:[_chartView.data dataSetAtIndex:rnd]];
[_chartView.data notifyDataChanged];
[_chartView notifyDataSetChanged];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ - (void)chartValueSelected:(ChartViewBase * __nonnull)chartView entry:(ChartData
{
NSLog(@"chartValueSelected");

[_chartView centerViewToAnimatedWithXValue:entry.x yValue:entry.y axis:[_chartView.data getDataSetByIndex:highlight.dataSetIndex].axisDependency duration:1.0];
[_chartView centerViewToAnimatedWithXValue:entry.x yValue:entry.y axis:[_chartView.data dataSetAtIndex:highlight.dataSetIndex].axisDependency duration:1.0];
//[_chartView moveViewToAnimatedWithXValue:entry.x yValue:entry.y axis:[_chartView.data getDataSetByIndex:dataSetIndex].axisDependency duration:1.0];
//[_chartView zoomAndCenterViewAnimatedWithScaleX:1.8 scaleY:1.8 xValue:entry.x yValue:entry.y axis:[_chartView.data getDataSetByIndex:dataSetIndex].axisDependency duration:1.0];

Expand Down
2 changes: 1 addition & 1 deletion ChartsDemo-iOS/Swift/DemoBaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class DemoBaseViewController: UIViewController, ChartViewDelegate {
chartView.setNeedsDisplay()

case .toggleHighlight:
chartView.data!.highlightEnabled = !chartView.data!.isHighlightEnabled
chartView.data!.isHighlightEnabled = !chartView.data!.isHighlightEnabled
chartView.setNeedsDisplay()

case .animateX:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ColoredLineChartViewController: DemoBaseViewController {
}

func setupChart(_ chart: LineChartView, data: LineChartData, color: UIColor) {
(data.getDataSetByIndex(0) as! LineChartDataSet).circleHoleColor = color
(data[0] as! LineChartDataSet).circleHoleColor = color

chart.delegate = self
chart.backgroundColor = color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class CombinedChartViewController: DemoBaseViewController {

case .removeDataSet:
let rnd = Int(arc4random_uniform(UInt32(chartView.data!.dataSetCount)))
chartView.data?.removeDataSet(chartView.data!.getDataSetByIndex(rnd))
chartView.data?.removeDataSet(chartView.data![rnd])
chartView.data?.notifyDataChanged()
chartView.notifyDataSetChanged()

Expand Down
2 changes: 1 addition & 1 deletion ChartsDemo-iOS/Swift/Demos/LineChart2ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class LineChart2ViewController: DemoBaseViewController {
super.chartValueSelected(chartView, entry: entry, highlight: highlight)

self.chartView.centerViewToAnimated(xValue: entry.x, yValue: entry.y,
axis: self.chartView.data!.getDataSetByIndex(highlight.dataSetIndex).axisDependency,
axis: self.chartView.data![highlight.dataSetIndex].axisDependency,
duration: 1)
//[_chartView moveViewToAnimatedWithXValue:entry.x yValue:entry.y axis:[_chartView.data getDataSetByIndex:dataSetIndex].axisDependency duration:1.0];
//[_chartView zoomAndCenterViewAnimatedWithScaleX:1.8 scaleY:1.8 xValue:entry.x yValue:entry.y axis:[_chartView.data getDataSetByIndex:dataSetIndex].axisDependency duration:1.0];
Expand Down
4 changes: 2 additions & 2 deletions Source/Charts/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
{
if let h = getHighlightByTouchPoint(pt)
{
return data!.entryForHighlight(h)
return data!.entry(for: h)
}
return nil
}
Expand All @@ -1695,7 +1695,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
let h = getHighlightByTouchPoint(pt)
if let h = h
{
return data?.getDataSetByIndex(h.dataSetIndex) as? BarLineScatterCandleBubbleChartDataSetProtocol
return data?[h.dataSetIndex] as? BarLineScatterCandleBubbleChartDataSetProtocol
}
return nil
}
Expand Down
16 changes: 8 additions & 8 deletions Source/Charts/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
guard let data = data else { return }

// calculate how many digits are needed
setupDefaultFormatter(min: data.getYMin(), max: data.getYMax())
setupDefaultFormatter(min: data.yMin, max: data.yMax)

for set in data.dataSets
{
Expand Down Expand Up @@ -411,14 +411,14 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
Swift.print("Value not highlighted because data is nil")
return
}
if dataSetIndex < 0 || dataSetIndex >= data.dataSetCount

if data.indices.contains(dataSetIndex)
{
highlightValue(nil, callDelegate: callDelegate)
highlightValue(Highlight(x: x, y: y, dataSetIndex: dataSetIndex, dataIndex: dataIndex), callDelegate: callDelegate)
}
else
{
highlightValue(Highlight(x: x, y: y, dataSetIndex: dataSetIndex, dataIndex: dataIndex), callDelegate: callDelegate)
highlightValue(nil, callDelegate: callDelegate)
}
}

Expand All @@ -436,7 +436,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
var high = highlight
guard
let h = high,
let entry = data?.entryForHighlight(h)
let entry = data?.entry(for: h)
else
{
high = nil
Expand Down Expand Up @@ -493,8 +493,8 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
for highlight in highlighted
{
guard
let set = data?.getDataSetByIndex(highlight.dataSetIndex),
let e = data?.entryForHighlight(highlight)
let set = data?[highlight.dataSetIndex],
let e = data?.entry(for: highlight)
else { continue }

let entryIndex = set.entryIndex(entry: e)
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Charts/CombinedChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ open class CombinedChartView: BarLineChartViewBase, CombinedChartDataProvider

guard
let set = combinedData?.getDataSetByHighlight(highlight),
let e = data?.entryForHighlight(highlight)
let e = data?.entry(for: highlight)
else { continue }

let entryIndex = set.entryIndex(entry: e)
Expand Down
5 changes: 1 addition & 4 deletions Source/Charts/Charts/PieChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,11 @@ open class PieChartView: PieRadarChartViewBase
_absoluteAngles.reserveCapacity(entryCount)

let yValueSum = (data as! PieChartData).yValueSum

var dataSets = data.dataSets

var cnt = 0

for i in 0 ..< data.dataSetCount
for set in data
{
let set = dataSets[i]
let entryCount = set.entryCount

for j in 0 ..< entryCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ open class BarChartData: BarLineScatterCandleBubbleChartData
super.init()
}

public override init(dataSets: [ChartDataSetProtocol]?)
public override init(dataSets: [ChartDataSetProtocol])
{
super.init(dataSets: dataSets)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ open class BarLineScatterCandleBubbleChartData: ChartData
super.init()
}

public override init(dataSets: [ChartDataSetProtocol]?)
public override init(dataSets: [ChartDataSetProtocol])
{
super.init(dataSets: dataSets)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ open class BubbleChartData: BarLineScatterCandleBubbleChartData
super.init()
}

public override init(dataSets: [ChartDataSetProtocol]?)
public override init(dataSets: [ChartDataSetProtocol])
{
super.init(dataSets: dataSets)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ open class CandleChartData: BarLineScatterCandleBubbleChartData
super.init()
}

public override init(dataSets: [ChartDataSetProtocol]?)
public override init(dataSets: [ChartDataSetProtocol])
{
super.init(dataSets: dataSets)
}
Expand Down
Loading

0 comments on commit d74ce61

Please sign in to comment.