-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from petester42/bubble-chart
Added Bubble Chart Type
- Loading branch information
Showing
12 changed files
with
929 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// BubbleChartView.swift | ||
// Charts | ||
// | ||
// Copyright 2015 Pierre-Marc Airoldi | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import Foundation | ||
|
||
public class BubbleChartView: BarLineChartViewBase, BubbleChartRendererDelegate | ||
{ | ||
public override func initialize() | ||
{ | ||
super.initialize(); | ||
|
||
renderer = BubbleChartRenderer(delegate: self, animator: _animator, viewPortHandler: _viewPortHandler); | ||
} | ||
|
||
public override func calcMinMax() | ||
{ | ||
super.calcMinMax(); | ||
|
||
if (_deltaX == 0.0 && _data.yValCount > 0) | ||
{ | ||
_deltaX = 1.0; | ||
} | ||
|
||
_chartXMin = -0.5 | ||
_chartXMax = Float(_data.xVals.count) - 0.5 | ||
|
||
if let r = renderer as? BubbleChartRenderer, sets = bubbleChartRendererData(r).dataSets as? [BubbleChartDataSet] | ||
{ | ||
for set in sets { | ||
|
||
let xmin = set.xMin | ||
let xmax = set.xMax | ||
|
||
if (xmin < _chartXMin) | ||
{ | ||
_chartXMin = xmin; | ||
} | ||
|
||
if (xmax > _chartXMax) | ||
{ | ||
_chartXMax = xmax; | ||
} | ||
} | ||
} | ||
|
||
_deltaX = CGFloat(abs(_chartXMax - _chartXMin)); | ||
} | ||
|
||
// MARK: - BubbleChartRendererDelegate | ||
|
||
public func bubbleChartRendererData(renderer: BubbleChartRenderer) -> BubbleChartData! | ||
{ | ||
return _data as! BubbleChartData!; | ||
} | ||
|
||
public func bubbleChartRenderer(renderer: BubbleChartRenderer, transformerForAxis which: ChartYAxis.AxisDependency) -> ChartTransformer! | ||
{ | ||
return getTransformer(which); | ||
} | ||
|
||
public func bubbleChartDefaultRendererValueFormatter(renderer: BubbleChartRenderer) -> NSNumberFormatter! | ||
{ | ||
return self._defaultValueFormatter; | ||
} | ||
|
||
public func bubbleChartRendererChartYMax(renderer: BubbleChartRenderer) -> Float | ||
{ | ||
return self.chartYMax; | ||
} | ||
|
||
public func bubbleChartRendererChartYMin(renderer: BubbleChartRenderer) -> Float | ||
{ | ||
return self.chartYMin; | ||
} | ||
|
||
public func bubbleChartRendererChartXMax(renderer: BubbleChartRenderer) -> Float | ||
{ | ||
return self.chartXMax; | ||
} | ||
|
||
public func bubbleChartRendererChartXMin(renderer: BubbleChartRenderer) -> Float | ||
{ | ||
return self.chartXMin; | ||
} | ||
|
||
public func bubbleChartRendererMaxVisibleValueCount(renderer: BubbleChartRenderer) -> Int | ||
{ | ||
return self.maxVisibleValueCount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// BubbleChartData.swift | ||
// Charts | ||
// | ||
// Copyright 2015 Pierre-Marc Airoldi | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
public class BubbleChartData: BarLineScatterCandleChartData | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// BubbleDataEntry.swift | ||
// Charts | ||
// | ||
// Copyright 2015 Pierre-Marc Airoldi | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import Foundation | ||
|
||
public class BubbleChartDataEntry: ChartDataEntry | ||
{ | ||
/// size value | ||
public var size = Float(0.0) | ||
|
||
public init(xIndex: Int, value:Float, size: Float) | ||
{ | ||
super.init(value: value, xIndex: xIndex) | ||
|
||
self.size = size | ||
} | ||
|
||
public init(xIndex: Int, value:Float, size: Float, data: AnyObject?) | ||
{ | ||
super.init(value: value, xIndex: xIndex, data: data) | ||
|
||
self.size = size | ||
} | ||
|
||
// MARK: NSCopying | ||
|
||
public override func copyWithZone(zone: NSZone) -> AnyObject | ||
{ | ||
var copy = super.copyWithZone(zone) as! BubbleChartDataEntry; | ||
copy.size = size; | ||
return copy; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// BubbleChartDataSet.swift | ||
// Charts | ||
// | ||
// Copyright 2015 Pierre-Marc Airoldi | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import Foundation | ||
import CoreGraphics; | ||
|
||
public class BubbleChartDataSet: BarLineScatterCandleChartDataSet | ||
{ | ||
internal var _xMax = Float(0.0) | ||
internal var _xMin = Float(0.0) | ||
internal var _maxSize = Float(1.0) | ||
|
||
public var xMin: Float { return _xMin } | ||
public var xMax: Float { return _xMax } | ||
public var maxSize: Float { return _maxSize } | ||
|
||
public override func setColor(color: UIColor) | ||
{ | ||
super.setColor(color.colorWithAlphaComponent(0.5)) | ||
} | ||
|
||
internal override func calcMinMax() | ||
{ | ||
let entries = yVals as! [BubbleChartDataEntry]; | ||
|
||
//need chart width to guess this properly | ||
|
||
for entry in entries | ||
{ | ||
let ymin = yMin(entry) | ||
let ymax = yMax(entry) | ||
|
||
if (ymin < _yMin) | ||
{ | ||
_yMin = ymin | ||
} | ||
|
||
if (ymax > _yMax) | ||
{ | ||
_yMax = ymax; | ||
} | ||
|
||
let xmin = xMin(entry) | ||
let xmax = xMax(entry) | ||
|
||
if (xmin < _xMin) | ||
{ | ||
_xMin = xmin; | ||
} | ||
|
||
if (xmax > _xMax) | ||
{ | ||
_xMax = xmax; | ||
} | ||
|
||
let size = largestSize(entry) | ||
|
||
if (size > _maxSize) | ||
{ | ||
_maxSize = size | ||
} | ||
} | ||
} | ||
|
||
private func yMin(entry: BubbleChartDataEntry) -> Float { | ||
return entry.value | ||
} | ||
|
||
private func yMax(entry: BubbleChartDataEntry) -> Float { | ||
return entry.value | ||
} | ||
|
||
private func xMin(entry: BubbleChartDataEntry) -> Float { | ||
return Float(entry.xIndex) | ||
} | ||
|
||
private func xMax(entry: BubbleChartDataEntry) -> Float { | ||
return Float(entry.xIndex) | ||
} | ||
|
||
private func largestSize(entry: BubbleChartDataEntry) -> Float { | ||
return entry.size | ||
} | ||
} |
Oops, something went wrong.