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

Added Bubble Chart Type #25

Merged
merged 3 commits into from
Apr 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions Charts/Charts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
55E356531ADC63BF00A57971 /* BubbleChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E356521ADC63BF00A57971 /* BubbleChartView.swift */; };
55E356571ADC63CD00A57971 /* BubbleChartData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E356541ADC63CD00A57971 /* BubbleChartData.swift */; };
55E356581ADC63CD00A57971 /* BubbleChartDataEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E356551ADC63CD00A57971 /* BubbleChartDataEntry.swift */; };
55E356591ADC63CD00A57971 /* BubbleChartDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E356561ADC63CD00A57971 /* BubbleChartDataSet.swift */; };
55E3565B1ADC63EB00A57971 /* BubbleChartRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E3565A1ADC63EB00A57971 /* BubbleChartRenderer.swift */; };
5B378F171AD500A4009414A4 /* ChartAnimationEasing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B378F161AD500A4009414A4 /* ChartAnimationEasing.swift */; };
5B4BCD3E1AA9C0A60063F019 /* ChartFillFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B4BCD3D1AA9C0A60063F019 /* ChartFillFormatter.swift */; };
5B4BCD401AA9C4930063F019 /* ChartTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B4BCD3F1AA9C4930063F019 /* ChartTransformer.swift */; };
Expand Down Expand Up @@ -82,6 +87,11 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
55E356521ADC63BF00A57971 /* BubbleChartView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BubbleChartView.swift; sourceTree = "<group>"; };
55E356541ADC63CD00A57971 /* BubbleChartData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BubbleChartData.swift; sourceTree = "<group>"; };
55E356551ADC63CD00A57971 /* BubbleChartDataEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BubbleChartDataEntry.swift; sourceTree = "<group>"; };
55E356561ADC63CD00A57971 /* BubbleChartDataSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BubbleChartDataSet.swift; sourceTree = "<group>"; };
55E3565A1ADC63EB00A57971 /* BubbleChartRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BubbleChartRenderer.swift; sourceTree = "<group>"; };
5B378F161AD500A4009414A4 /* ChartAnimationEasing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartAnimationEasing.swift; sourceTree = "<group>"; };
5B4BCD3D1AA9C0A60063F019 /* ChartFillFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartFillFormatter.swift; sourceTree = "<group>"; };
5B4BCD3F1AA9C4930063F019 /* ChartTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartTransformer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -192,6 +202,7 @@
children = (
5B6A54711AA5DCA8000F57C2 /* ChartAxisRendererBase.swift */,
5B6A54961AA66AD2000F57C2 /* BarChartRenderer.swift */,
55E3565A1ADC63EB00A57971 /* BubbleChartRenderer.swift */,
5B6A54941AA66AC0000F57C2 /* CandleStickChartRenderer.swift */,
5B6A54921AA66AAB000F57C2 /* CombinedChartRenderer.swift */,
5B6A54901AA66A8D000F57C2 /* ChartDataRendererBase.swift */,
Expand Down Expand Up @@ -259,6 +270,7 @@
children = (
5B6A54981AA66B14000F57C2 /* BarChartView.swift */,
5B6A549A1AA66B2C000F57C2 /* BarLineChartViewBase.swift */,
55E356521ADC63BF00A57971 /* BubbleChartView.swift */,
5B6A549C1AA66B3C000F57C2 /* CandleStickChartView.swift */,
5BA8EC671A9D151C00CE82E1 /* ChartViewBase.swift */,
5B6A549E1AA66B59000F57C2 /* CombinedChartView.swift */,
Expand Down Expand Up @@ -294,6 +306,9 @@
5B6A54B91AA74516000F57C2 /* BarChartDataSet.swift */,
5B6A54BA1AA74516000F57C2 /* BarLineScatterCandleChartData.swift */,
5B6A54BB1AA74516000F57C2 /* BarLineScatterCandleChartDataSet.swift */,
55E356541ADC63CD00A57971 /* BubbleChartData.swift */,
55E356551ADC63CD00A57971 /* BubbleChartDataEntry.swift */,
55E356561ADC63CD00A57971 /* BubbleChartDataSet.swift */,
5B6A54BC1AA74516000F57C2 /* CandleChartData.swift */,
5B6A54BD1AA74516000F57C2 /* CandleChartDataEntry.swift */,
5B6A54BE1AA74516000F57C2 /* CandleChartDataSet.swift */,
Expand Down Expand Up @@ -451,6 +466,7 @@
5B6A54CE1AA74516000F57C2 /* BarChartDataSet.swift in Sources */,
5B6A54871AA669F4000F57C2 /* RadarChartRenderer.swift in Sources */,
5B6A548D1AA66A60000F57C2 /* ChartLegendRenderer.swift in Sources */,
55E356591ADC63CD00A57971 /* BubbleChartDataSet.swift in Sources */,
5BB6EC1D1ACC28AB006E9C25 /* ChartTransformerHorizontalBarChart.swift in Sources */,
5B680D271A9D17C30026A057 /* ChartColorTemplates.swift in Sources */,
5B6A54951AA66AC0000F57C2 /* CandleStickChartRenderer.swift in Sources */,
Expand All @@ -466,18 +482,22 @@
5B6A549B1AA66B2C000F57C2 /* BarLineChartViewBase.swift in Sources */,
5B6A54A51AA66B92000F57C2 /* PieChartView.swift in Sources */,
5B6A54D81AA74516000F57C2 /* LineChartData.swift in Sources */,
55E356581ADC63CD00A57971 /* BubbleChartDataEntry.swift in Sources */,
5B6A54911AA66A8D000F57C2 /* ChartDataRendererBase.swift in Sources */,
5BD8F06D1AB897D500566E05 /* ChartViewPortHandler.swift in Sources */,
5B6A54D51AA74516000F57C2 /* ChartData.swift in Sources */,
5B6A54971AA66AD2000F57C2 /* BarChartRenderer.swift in Sources */,
5B6A546B1AA5C23F000F57C2 /* ChartMarker.swift in Sources */,
5B6A54D61AA74516000F57C2 /* ChartDataEntry.swift in Sources */,
55E356571ADC63CD00A57971 /* BubbleChartData.swift in Sources */,
5B6A54DF1AA74516000F57C2 /* ScatterChartData.swift in Sources */,
5B6A54D31AA74516000F57C2 /* CandleChartDataSet.swift in Sources */,
5B6A54D71AA74516000F57C2 /* ChartDataSet.swift in Sources */,
5B6A54781AA5DEF0000F57C2 /* ChartXAxisRendererRadarChart.swift in Sources */,
5B6A54A71AA66BA7000F57C2 /* PieRadarChartViewBase.swift in Sources */,
5B6A546E1AA5D2DC000F57C2 /* ChartAnimator.swift in Sources */,
55E3565B1ADC63EB00A57971 /* BubbleChartRenderer.swift in Sources */,
55E356531ADC63BF00A57971 /* BubbleChartView.swift in Sources */,
5B6A547E1AA5DF1A000F57C2 /* ChartYAxisRenderer.swift in Sources */,
5B6A549F1AA66B59000F57C2 /* CombinedChartView.swift in Sources */,
5B6556F71AB72BA000FFBFD3 /* ChartComponentBase.swift in Sources */,
Expand Down
105 changes: 105 additions & 0 deletions Charts/Classes/Charts/BubbleChartView.swift
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;
}
}
22 changes: 22 additions & 0 deletions Charts/Classes/Data/BubbleChartData.swift
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
{

}
48 changes: 48 additions & 0 deletions Charts/Classes/Data/BubbleChartDataEntry.swift
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;
}
}
99 changes: 99 additions & 0 deletions Charts/Classes/Data/BubbleChartDataSet.swift
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
}
}
Loading