Skip to content

Commit

Permalink
Catch up with a small feature from 2.1.1 (Fixes #249)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jul 29, 2015
1 parent 3e51af3 commit 2a0e534
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 47 deletions.
8 changes: 8 additions & 0 deletions Charts/Charts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
5B6A54DE1AA74516000F57C2 /* RadarChartDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6A54C91AA74516000F57C2 /* RadarChartDataSet.swift */; };
5B6A54DF1AA74516000F57C2 /* ScatterChartData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6A54CA1AA74516000F57C2 /* ScatterChartData.swift */; };
5B6A54E01AA74516000F57C2 /* ScatterChartDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6A54CB1AA74516000F57C2 /* ScatterChartDataSet.swift */; };
5B8FE2AF1B68F8F600910C9E /* LineScatterCandleChartDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B8FE2AE1B68F8F600910C9E /* LineScatterCandleChartDataSet.swift */; };
5B8FE2B11B68FFF900910C9E /* LineScatterCandleRadarChartRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B8FE2B01B68FFF900910C9E /* LineScatterCandleRadarChartRenderer.swift */; };
5BA8EC7D1A9D151C00CE82E1 /* ChartViewBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA8EC671A9D151C00CE82E1 /* ChartViewBase.swift */; };
5BA8EC881A9D151C00CE82E1 /* ChartDataApproximatorFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA8EC751A9D151C00CE82E1 /* ChartDataApproximatorFilter.swift */; };
5BA8EC891A9D151C00CE82E1 /* ChartDataBaseFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA8EC761A9D151C00CE82E1 /* ChartDataBaseFilter.swift */; };
Expand Down Expand Up @@ -159,6 +161,8 @@
5B6A54C91AA74516000F57C2 /* RadarChartDataSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadarChartDataSet.swift; sourceTree = "<group>"; };
5B6A54CA1AA74516000F57C2 /* ScatterChartData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScatterChartData.swift; sourceTree = "<group>"; };
5B6A54CB1AA74516000F57C2 /* ScatterChartDataSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScatterChartDataSet.swift; sourceTree = "<group>"; };
5B8FE2AE1B68F8F600910C9E /* LineScatterCandleChartDataSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineScatterCandleChartDataSet.swift; sourceTree = "<group>"; };
5B8FE2B01B68FFF900910C9E /* LineScatterCandleRadarChartRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineScatterCandleRadarChartRenderer.swift; sourceTree = "<group>"; };
5BA8EC401A9D14DC00CE82E1 /* Charts.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Charts.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5BA8EC441A9D14DC00CE82E1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5BA8EC671A9D151C00CE82E1 /* ChartViewBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartViewBase.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -229,6 +233,7 @@
5B6A548E1AA66A7A000F57C2 /* HorizontalBarChartRenderer.swift */,
5B6A548C1AA66A60000F57C2 /* ChartLegendRenderer.swift */,
5B6A548A1AA66A3D000F57C2 /* LineChartRenderer.swift */,
5B8FE2B01B68FFF900910C9E /* LineScatterCandleRadarChartRenderer.swift */,
5B6A54881AA66A1A000F57C2 /* PieChartRenderer.swift */,
5B6A54861AA669F4000F57C2 /* RadarChartRenderer.swift */,
5B6A546F1AA5DB34000F57C2 /* ChartRendererBase.swift */,
Expand Down Expand Up @@ -340,6 +345,7 @@
5B6A54C31AA74516000F57C2 /* LineChartData.swift */,
5B6A54C41AA74516000F57C2 /* LineChartDataSet.swift */,
5B6A54C51AA74516000F57C2 /* LineRadarChartDataSet.swift */,
5B8FE2AE1B68F8F600910C9E /* LineScatterCandleChartDataSet.swift */,
5B6A54C61AA74516000F57C2 /* PieChartData.swift */,
5B6A54C71AA74516000F57C2 /* PieChartDataSet.swift */,
5B6A54C81AA74516000F57C2 /* RadarChartData.swift */,
Expand Down Expand Up @@ -454,6 +460,7 @@
5B680D1F1A9D17C30026A057 /* ChartAxisBase.swift in Sources */,
5B4BCD3E1AA9C0A60063F019 /* ChartFillFormatter.swift in Sources */,
5B6A54DE1AA74516000F57C2 /* RadarChartDataSet.swift in Sources */,
5B8FE2AF1B68F8F600910C9E /* LineScatterCandleChartDataSet.swift in Sources */,
5B680D211A9D17C30026A057 /* ChartLimitLine.swift in Sources */,
5B6A54DB1AA74516000F57C2 /* PieChartData.swift in Sources */,
5B6A54D91AA74516000F57C2 /* LineChartDataSet.swift in Sources */,
Expand Down Expand Up @@ -505,6 +512,7 @@
55E356581ADC63CD00A57971 /* BubbleChartDataEntry.swift in Sources */,
5B6A54911AA66A8D000F57C2 /* ChartDataRendererBase.swift in Sources */,
5BD8F06D1AB897D500566E05 /* ChartViewPortHandler.swift in Sources */,
5B8FE2B11B68FFF900910C9E /* LineScatterCandleRadarChartRenderer.swift in Sources */,
5B6A54D51AA74516000F57C2 /* ChartData.swift in Sources */,
5B6A54971AA66AD2000F57C2 /* BarChartRenderer.swift in Sources */,
5B6A546B1AA5C23F000F57C2 /* ChartMarker.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Data/BarLineScatterCandleChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import UIKit
public class BarLineScatterCandleChartDataSet: ChartDataSet
{
public var highlightColor = UIColor(red: 255.0/255.0, green: 187.0/255.0, blue: 115.0/255.0, alpha: 1.0)
public var highlightLineWidth = CGFloat(1.0)
public var highlightLineWidth = CGFloat(0.5)
public var highlightLineDashPhase = CGFloat(0.0)
public var highlightLineDashLengths: [CGFloat]?

Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Data/CandleChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
import CoreGraphics
import UIKit

public class CandleChartDataSet: BarLineScatterCandleChartDataSet
public class CandleChartDataSet: LineScatterCandleChartDataSet
{
/// the width of the candle-shadow-line in pixels.
/// :default: 3.0
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Data/LineRadarChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
import CoreGraphics
import UIKit

public class LineRadarChartDataSet: BarLineScatterCandleChartDataSet
public class LineRadarChartDataSet: LineScatterCandleChartDataSet
{
public var fillColor = UIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0)
public var fillAlpha = CGFloat(0.33)
Expand Down
45 changes: 45 additions & 0 deletions Charts/Classes/Data/LineScatterCandleChartDataSet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// LineScatterCandleChartDataSet.swift
// Charts
//
// Created by Daniel Cohen Gindi on 29/7/15.
//
// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda
// A port of MPAndroidChart for iOS
// Licensed under Apache License 2.0
//
// https://github.com/danielgindi/ios-charts
//

import Foundation
import UIKit

public class LineScatterCandleChartDataSet: BarLineScatterCandleChartDataSet
{
/// Enables / disables the horizontal highlight-indicator. If disabled, the indicator is not drawn.
public var drawHorizontalHighlightIndicatorEnabled = true

/// Enables / disables the vertical highlight-indicator. If disabled, the indicator is not drawn.
public var drawVerticalHighlightIndicatorEnabled = true

public var isHorizontalHighlightIndicatorEnabled: Bool { return drawHorizontalHighlightIndicatorEnabled }
public var isVerticalHighlightIndicatorEnabled: Bool { return drawVerticalHighlightIndicatorEnabled }

/// Enables / disables both vertical and horizontal highlight-indicators.
/// :param: enabled
public func setDrawHighlightIndicators(enabled: Bool)
{
drawHorizontalHighlightIndicatorEnabled = enabled
drawVerticalHighlightIndicatorEnabled = enabled
}

// MARK: NSCopying

public override func copyWithZone(zone: NSZone) -> AnyObject
{
var copy = super.copyWithZone(zone) as! LineScatterCandleChartDataSet
copy.drawHorizontalHighlightIndicatorEnabled = drawHorizontalHighlightIndicatorEnabled
copy.drawVerticalHighlightIndicatorEnabled = drawVerticalHighlightIndicatorEnabled
return copy
}
}
2 changes: 1 addition & 1 deletion Charts/Classes/Data/ScatterChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import Foundation
import CoreGraphics

public class ScatterChartDataSet: BarLineScatterCandleChartDataSet
public class ScatterChartDataSet: LineScatterCandleChartDataSet
{
@objc
public enum ScatterShape: Int
Expand Down
33 changes: 11 additions & 22 deletions Charts/Classes/Renderers/CandleStickChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public protocol CandleStickChartRendererDelegate
func candleStickChartRendererMaxVisibleValueCount(renderer: CandleStickChartRenderer) -> Int
}

public class CandleStickChartRenderer: ChartDataRendererBase
public class CandleStickChartRenderer: LineScatterCandleRadarChartRenderer
{
public weak var delegate: CandleStickChartRendererDelegate?

Expand Down Expand Up @@ -246,8 +246,7 @@ public class CandleStickChartRenderer: ChartDataRendererBase
{
}

private var _vertPtsBuffer = [CGPoint](count: 4, repeatedValue: CGPoint())
private var _horzPtsBuffer = [CGPoint](count: 4, repeatedValue: CGPoint())
private var _highlightPtsBuffer = [CGPoint](count: 4, repeatedValue: CGPoint())
public override func drawHighlighted(#context: CGContext, indices: [ChartHighlight])
{
var candleData = delegate!.candleStickChartRendererCandleData(self)
Expand Down Expand Up @@ -289,28 +288,18 @@ public class CandleStickChartRenderer: ChartDataRendererBase

var low = CGFloat(e.low) * _animator.phaseY
var high = CGFloat(e.high) * _animator.phaseY
var y = (low + high) / 2.0

var min = delegate!.candleStickChartRendererChartYMin(self)
var max = delegate!.candleStickChartRendererChartYMax(self)
_highlightPtsBuffer[0] = CGPoint(x: CGFloat(xIndex), y: CGFloat(delegate!.candleStickChartRendererChartYMax(self)))
_highlightPtsBuffer[1] = CGPoint(x: CGFloat(xIndex), y: CGFloat(delegate!.candleStickChartRendererChartYMin(self)))
_highlightPtsBuffer[2] = CGPoint(x: CGFloat(delegate!.candleStickChartRendererChartXMin(self)), y: y)
_highlightPtsBuffer[3] = CGPoint(x: CGFloat(delegate!.candleStickChartRendererChartXMax(self)), y: y)

_vertPtsBuffer[0] = CGPoint(x: CGFloat(xIndex) - 0.5, y: CGFloat(max))
_vertPtsBuffer[1] = CGPoint(x: CGFloat(xIndex) - 0.5, y: CGFloat(min))
_vertPtsBuffer[2] = CGPoint(x: CGFloat(xIndex) + 0.5, y: CGFloat(max))
_vertPtsBuffer[3] = CGPoint(x: CGFloat(xIndex) + 0.5, y: CGFloat(min))
trans.pointValuesToPixel(&_highlightPtsBuffer)

_horzPtsBuffer[0] = CGPoint(x: CGFloat(delegate!.candleStickChartRendererChartXMin(self)), y: low)
_horzPtsBuffer[1] = CGPoint(x: CGFloat(delegate!.candleStickChartRendererChartXMax(self)), y: low)
_horzPtsBuffer[2] = CGPoint(x: CGFloat(delegate!.candleStickChartRendererChartXMin(self)), y: high)
_horzPtsBuffer[3] = CGPoint(x: CGFloat(delegate!.candleStickChartRendererChartXMax(self)), y: high)

trans.pointValuesToPixel(&_vertPtsBuffer)
trans.pointValuesToPixel(&_horzPtsBuffer)

// draw the vertical highlight lines
CGContextStrokeLineSegments(context, _vertPtsBuffer, 4)

// draw the horizontal highlight lines
CGContextStrokeLineSegments(context, _horzPtsBuffer, 4)
// draw the lines
drawHighlightLines(context: context, points: _highlightPtsBuffer,
horizontal: set.isHorizontalHighlightIndicatorEnabled, vertical: set.isVerticalHighlightIndicatorEnabled)
}
}
}
7 changes: 4 additions & 3 deletions Charts/Classes/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public protocol LineChartRendererDelegate
func lineChartRendererMaxVisibleValueCount(renderer: LineChartRenderer) -> Int
}

public class LineChartRenderer: ChartDataRendererBase
public class LineChartRenderer: LineScatterCandleRadarChartRenderer
{
public weak var delegate: LineChartRendererDelegate?

Expand Down Expand Up @@ -619,8 +619,9 @@ public class LineChartRenderer: ChartDataRendererBase

trans.pointValuesToPixel(&_highlightPtsBuffer)

// draw the highlight lines
CGContextStrokeLineSegments(context, _highlightPtsBuffer, 4)
// draw the lines
drawHighlightLines(context: context, points: _highlightPtsBuffer,
horizontal: set.isHorizontalHighlightIndicatorEnabled, vertical: set.isVerticalHighlightIndicatorEnabled)
}

CGContextRestoreGState(context)
Expand Down
45 changes: 45 additions & 0 deletions Charts/Classes/Renderers/LineScatterCandleRadarChartRenderer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// LineScatterCandleRadarChartRenderer.swift
// Charts
//
// Created by Daniel Cohen Gindi on 29/7/15.
//
// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda
// A port of MPAndroidChart for iOS
// Licensed under Apache License 2.0
//
// https://github.com/danielgindi/ios-charts
//

import Foundation
import CoreGraphics
import UIKit

public class LineScatterCandleRadarChartRenderer: ChartDataRendererBase
{
public override init(animator: ChartAnimator?, viewPortHandler: ChartViewPortHandler)
{
super.init(animator: animator, viewPortHandler: viewPortHandler)
}

/// Draws vertical & horizontal highlight-lines if enabled.
/// :param: context
/// :param: points
/// :param: horizontal
/// :param: vertical
public func drawHighlightLines(#context: CGContext, points: UnsafePointer<CGPoint>, horizontal: Bool, vertical: Bool)
{
// draw vertical highlight lines
if vertical
{
CGContextStrokeLineSegments(context, points, 2)
}

// draw horizontal highlight lines
if horizontal
{
var pts = UnsafePointer<CGPoint>()
CGContextStrokeLineSegments(context, points.advancedBy(2), 2)
}
}
}
17 changes: 10 additions & 7 deletions Charts/Classes/Renderers/RadarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
import CoreGraphics
import UIKit

public class RadarChartRenderer: ChartDataRendererBase
public class RadarChartRenderer: LineScatterCandleRadarChartRenderer
{
internal weak var _chart: RadarChartView!

Expand Down Expand Up @@ -225,7 +225,7 @@ public class RadarChartRenderer: ChartDataRendererBase
CGContextRestoreGState(context)
}

private var _lineSegments = [CGPoint](count: 4, repeatedValue: CGPoint())
private var _highlightPtsBuffer = [CGPoint](count: 4, repeatedValue: CGPoint())

public override func drawHighlighted(#context: CGContext, indices: [ChartHighlight])
{
Expand Down Expand Up @@ -283,11 +283,14 @@ public class RadarChartRenderer: ChartDataRendererBase
var p = ChartUtils.getPosition(center: center, dist: CGFloat(y) * factor,
angle: sliceangle * CGFloat(j) + _chart.rotationAngle)

_lineSegments[0] = CGPoint(x: p.x, y: 0.0)
_lineSegments[1] = CGPoint(x: p.x, y: viewPortHandler.chartHeight)
_lineSegments[2] = CGPoint(x: 0.0, y: p.y)
_lineSegments[3] = CGPoint(x: viewPortHandler.chartWidth, y: p.y)
CGContextStrokeLineSegments(context, _lineSegments, 4)
_highlightPtsBuffer[0] = CGPoint(x: p.x, y: 0.0)
_highlightPtsBuffer[1] = CGPoint(x: p.x, y: viewPortHandler.chartHeight)
_highlightPtsBuffer[2] = CGPoint(x: 0.0, y: p.y)
_highlightPtsBuffer[3] = CGPoint(x: viewPortHandler.chartWidth, y: p.y)

// draw the lines
drawHighlightLines(context: context, points: _highlightPtsBuffer,
horizontal: set.isHorizontalHighlightIndicatorEnabled, vertical: set.isVerticalHighlightIndicatorEnabled)
}

CGContextRestoreGState(context)
Expand Down
21 changes: 11 additions & 10 deletions Charts/Classes/Renderers/ScatterChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public protocol ScatterChartRendererDelegate
func scatterChartRendererMaxVisibleValueCount(renderer: ScatterChartRenderer) -> Int
}

public class ScatterChartRenderer: ChartDataRendererBase
public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer
{
public weak var delegate: ScatterChartRendererDelegate?

Expand Down Expand Up @@ -241,6 +241,8 @@ public class ScatterChartRenderer: ChartDataRendererBase

}

private var _highlightPtsBuffer = [CGPoint](count: 4, repeatedValue: CGPoint())

public override func drawHighlighted(#context: CGContext, indices: [ChartHighlight])
{
var scatterData = delegate!.scatterChartRendererData(self)
Expand All @@ -251,8 +253,6 @@ public class ScatterChartRenderer: ChartDataRendererBase

CGContextSaveGState(context)

var pts = [CGPoint](count: 4, repeatedValue: CGPoint())

for (var i = 0; i < indices.count; i++)
{
var set = scatterData.getDataSetByIndex(indices[i].dataSetIndex) as! ScatterChartDataSet!
Expand Down Expand Up @@ -288,17 +288,18 @@ public class ScatterChartRenderer: ChartDataRendererBase

var y = CGFloat(yVal) * _animator.phaseY; // get the y-position

pts[0] = CGPoint(x: CGFloat(xIndex), y: CGFloat(chartYMax))
pts[1] = CGPoint(x: CGFloat(xIndex), y: CGFloat(chartYMin))
pts[2] = CGPoint(x: CGFloat(chartXMin), y: y)
pts[3] = CGPoint(x: CGFloat(chartXMax), y: y)
_highlightPtsBuffer[0] = CGPoint(x: CGFloat(xIndex), y: CGFloat(chartYMax))
_highlightPtsBuffer[1] = CGPoint(x: CGFloat(xIndex), y: CGFloat(chartYMin))
_highlightPtsBuffer[2] = CGPoint(x: CGFloat(chartXMin), y: y)
_highlightPtsBuffer[3] = CGPoint(x: CGFloat(chartXMax), y: y)

var trans = delegate!.scatterChartRenderer(self, transformerForAxis: set.axisDependency)

trans.pointValuesToPixel(&pts)
trans.pointValuesToPixel(&_highlightPtsBuffer)

// draw the highlight lines
CGContextStrokeLineSegments(context, pts, pts.count)
// draw the lines
drawHighlightLines(context: context, points: _highlightPtsBuffer,
horizontal: set.isHorizontalHighlightIndicatorEnabled, vertical: set.isVerticalHighlightIndicatorEnabled)
}

CGContextRestoreGState(context)
Expand Down
1 change: 1 addition & 0 deletions ChartsDemo/Classes/Demos/CubicLineChartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ - (void)setDataCount:(int)count range:(double)range
set1.highlightColor = [UIColor colorWithRed:244/255.f green:117/255.f blue:117/255.f alpha:1.f];
[set1 setColor:[UIColor colorWithRed:104/255.f green:241/255.f blue:175/255.f alpha:1.f]];
set1.fillColor = [UIColor colorWithRed:51/255.f green:181/255.f blue:229/255.f alpha:1.f];
set1.drawHorizontalHighlightIndicatorEnabled = NO;

LineChartData *data = [[LineChartData alloc] initWithXVals:xVals dataSet:set1];
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:9.f]];
Expand Down
1 change: 0 additions & 1 deletion ChartsDemo/Classes/Demos/LineChart1ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ - (void)viewDidLoad
_chartView.descriptionText = @"";
_chartView.noDataTextDescription = @"You need to provide data for the chart.";

_chartView.highlightEnabled = NO;
_chartView.dragEnabled = YES;
[_chartView setScaleEnabled:YES];
_chartView.pinchZoomEnabled = YES;
Expand Down

0 comments on commit 2a0e534

Please sign in to comment.