Skip to content

Commit

Permalink
Merge pull request #1290 from acegreen/Swift-3.0
Browse files Browse the repository at this point in the history
Swift 3.0 - Xcode 8 Beta 4
  • Loading branch information
liuxuan30 authored Aug 5, 2016
2 parents 30edf8e + c4c6e85 commit c9ac170
Show file tree
Hide file tree
Showing 32 changed files with 108 additions and 103 deletions.
6 changes: 5 additions & 1 deletion Charts/Classes/Animation/ChartAnimationEasing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ internal struct EasingFunctions
return CGFloat( -0.5 * (pow(2.0, 10.0 * position) * sin((position * duration - s) * (2.0 * M_PI) / p)) )
}
position -= 1.0
return CGFloat( pow(2.0, -10.0 * position) * sin((position * duration - s) * (2.0 * M_PI) / p) * 0.5 + 1.0 )

let tempPOW = pow(2.0, -10.0 * position)
let tempSIN = sin((position * duration - s) * (2.0 * M_PI) / p)

return CGFloat( tempPOW * tempSIN * 0.5 + 1.0 )
}

internal static let EaseInBack = { (elapsed: TimeInterval, duration: TimeInterval) -> CGFloat in
Expand Down
16 changes: 8 additions & 8 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
/// the color for the background of the chart-drawing area (everything behind the grid lines).
public var gridBackgroundColor = NSUIColor(red: 240/255.0, green: 240/255.0, blue: 240/255.0, alpha: 1.0)

public var borderColor = NSUIColor.black()
public var borderColor = NSUIColor.black
public var borderLineWidth: CGFloat = 1.0

/// flag indicating if the grid background should be drawn or not
Expand Down Expand Up @@ -216,7 +216,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar

// make sure the graph values and grid cannot be drawn outside the content-rect
context.saveGState()
context.clipTo(_viewPortHandler.contentRect)
context.clip(to: _viewPortHandler.contentRect)

_xAxisRenderer?.renderGridLines(context: context)
_leftYAxisRenderer?.renderGridLines(context: context)
Expand Down Expand Up @@ -248,7 +248,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
renderer!.drawExtras(context: context)

context.saveGState()
context.clipTo(_viewPortHandler.contentRect)
context.clip(to: _viewPortHandler.contentRect)

if !_xAxis.drawLimitLinesBehindDataEnabled
{
Expand Down Expand Up @@ -325,7 +325,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar

// calculate / set x-axis range
_xAxis._axisMaximum = Double((_data?.xVals.count ?? 0) - 1)
_xAxis.axisRange = .abs(_xAxis._axisMaximum - _xAxis._axisMinimum);
_xAxis.axisRange = abs(_xAxis._axisMaximum - _xAxis._axisMinimum);

// calculate axis range (min / max) according to provided data
_leftAxis.calculate(min: _data?.getYMin(.left) ?? 0.0, max: _data?.getYMax(.left) ?? 0.0)
Expand Down Expand Up @@ -715,10 +715,10 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
let scaleY = canZoomMoreY ? recognizer.nsuiScale : 1.0

var matrix = CGAffineTransform(translationX: location.x, y: location.y)
matrix = matrix.scaleBy(x: scaleX, y: scaleY)
matrix = matrix.translateBy(x: -location.x, y: -location.y)
matrix = matrix.scaledBy(x: scaleX, y: scaleY)
matrix = matrix.translatedBy(x: -location.x, y: -location.y)

matrix = _viewPortHandler.touchMatrix.concat(matrix)
matrix = _viewPortHandler.touchMatrix.concatenating(matrix)

_viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true)

Expand Down Expand Up @@ -858,7 +858,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
let originalMatrix = _viewPortHandler.touchMatrix

var matrix = CGAffineTransform(translationX: translation.x, y: translation.y)
matrix = originalMatrix.concat(matrix)
matrix = originalMatrix.concatenating(matrix)

matrix = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true)

Expand Down
8 changes: 4 additions & 4 deletions Charts/Classes/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate
public var descriptionFont: NSUIFont? = NSUIFont(name: "HelveticaNeue", size: 9.0)

/// Text color used for drawing the description text
public var descriptionTextColor: NSUIColor? = NSUIColor.black()
public var descriptionTextColor: NSUIColor? = NSUIColor.black

/// Text align used for drawing the description text
public var descriptionTextAlign: NSTextAlignment = NSTextAlignment.right
Expand Down Expand Up @@ -157,7 +157,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate
super.init(frame: frame)

#if os(iOS)
self.backgroundColor = NSUIColor.clear()
self.backgroundColor = NSUIColor.clear
#endif
initialize()
}
Expand Down Expand Up @@ -358,7 +358,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate
// 23 is the smallest recommended font size on the TV
font = NSUIFont.systemFont(ofSize: 23, weight: UIFontWeightMedium)
#else
font = NSUIFont.systemFont(ofSize: NSUIFont.systemFontSize())
font = NSUIFont.systemFont(ofSize: NSUIFont.systemFontSize)
#endif
}

Expand Down Expand Up @@ -813,7 +813,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate
if (isOpaque || !transparent)
{
// Background color may be partially transparent, we must fill with white if we want to output an opaque image
context.setFillColor(NSUIColor.white().cgColor)
context.setFillColor(NSUIColor.white.cgColor)
context.fill(rect)

if (self.backgroundColor !== nil)
Expand Down
10 changes: 5 additions & 5 deletions Charts/Classes/Charts/PieChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class PieChartView: PieRadarChartViewBase
/// if true, the hole inside the chart will be drawn
private var _drawHoleEnabled = true

private var _holeColor: NSUIColor? = NSUIColor.white()
private var _holeColor: NSUIColor? = NSUIColor.white

/// if true, the hole will see-through to the inner tips of the slices
private var _drawSlicesUnderHoleEnabled = false
Expand All @@ -44,7 +44,7 @@ public class PieChartView: PieRadarChartViewBase
private var _usePercentValuesEnabled = false

/// variable for the text that is drawn in the center of the pie-chart
private var _centerAttributedText: AttributedString?
private var _centerAttributedText: NSAttributedString?

/// indicates the size of the hole in the center of the piechart
///
Expand Down Expand Up @@ -358,13 +358,13 @@ public class PieChartView: PieRadarChartViewBase
}
else
{
let paragraphStyle = NSParagraphStyle.default().mutableCopy() as! NSMutableParagraphStyle
let paragraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paragraphStyle.lineBreakMode = NSLineBreakMode.byTruncatingTail
paragraphStyle.alignment = .center

attrString = NSMutableAttributedString(string: newValue!)
attrString?.setAttributes([
NSForegroundColorAttributeName: NSUIColor.black(),
NSForegroundColorAttributeName: NSUIColor.black,
NSFontAttributeName: NSUIFont.systemFont(ofSize: 12.0),
NSParagraphStyleAttributeName: paragraphStyle
], range: NSMakeRange(0, attrString!.length))
Expand All @@ -374,7 +374,7 @@ public class PieChartView: PieRadarChartViewBase
}

/// the text that is displayed in the center of the pie-chart
public var centerAttributedText: AttributedString?
public var centerAttributedText: NSAttributedString?
{
get
{
Expand Down
6 changes: 3 additions & 3 deletions Charts/Classes/Components/ChartAxisBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import CoreGraphics
public class ChartAxisBase: ChartComponentBase
{
public var labelFont = NSUIFont.systemFont(ofSize: 10.0)
public var labelTextColor = NSUIColor.black()
public var labelTextColor = NSUIColor.black

public var axisLineColor = NSUIColor.gray()
public var axisLineColor = NSUIColor.gray
public var axisLineWidth = CGFloat(0.5)
public var axisLineDashPhase = CGFloat(0.0)
public var axisLineDashLengths: [CGFloat]!

public var gridColor = NSUIColor.gray().withAlphaComponent(0.9)
public var gridColor = NSUIColor.gray.withAlphaComponent(0.9)
public var gridLineWidth = CGFloat(0.5)
public var gridLineDashPhase = CGFloat(0.0)
public var gridLineDashLengths: [CGFloat]!
Expand Down
3 changes: 1 addition & 2 deletions Charts/Classes/Components/ChartLegend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ public class ChartLegend: ChartComponentBase
public var direction: Direction = Direction.leftToRight

public var font: NSUIFont = NSUIFont.systemFont(ofSize: 10.0)
public var textColor = NSUIColor.black()

public var textColor = NSUIColor.black
public var form = Form.square
public var formSize = CGFloat(8.0)
public var formLineWidth = CGFloat(1.5)
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Components/ChartLimitLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ChartLimitLine: ChartComponentBase
public var lineColor = NSUIColor(red: 237.0/255.0, green: 91.0/255.0, blue: 91.0/255.0, alpha: 1.0)
public var lineDashPhase = CGFloat(0.0)
public var lineDashLengths: [CGFloat]?
public var valueTextColor = NSUIColor.black()
public var valueTextColor = NSUIColor.black
public var valueFont = NSUIFont.systemFont(ofSize: 13.0)
public var label = ""
public var drawLabelEnabled = true
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Components/ChartYAxis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class ChartYAxis: ChartAxisBase
public var drawZeroLineEnabled = false

/// Color of the zero line
public var zeroLineColor: NSUIColor? = NSUIColor.gray()
public var zeroLineColor: NSUIColor? = NSUIColor.gray

/// Width of the zero line
public var zeroLineWidth: CGFloat = 1.0
Expand Down
4 changes: 2 additions & 2 deletions Charts/Classes/Data/Implementations/ChartBaseDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ChartBaseDataSet: NSObject, IChartDataSet

// default color
colors.append(NSUIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0))
valueColors.append(NSUIColor.black())
valueColors.append(NSUIColor.black)
}

public init(label: String?)
Expand All @@ -33,7 +33,7 @@ public class ChartBaseDataSet: NSObject, IChartDataSet

// default color
colors.append(NSUIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0))
valueColors.append(NSUIColor.black())
valueColors.append(NSUIColor.black)

self.label = label
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BarChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBarChartD
{
private func initialize()
{
self.highlightColor = NSUIColor.black()
self.highlightColor = NSUIColor.black

self.calcStackSize(yVals as! [BarChartDataEntry])
self.calcEntryCountIncludingStacks(yVals as! [BarChartDataEntry])
Expand Down Expand Up @@ -182,7 +182,7 @@ public class BarChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBarChartD
public var barBorderWidth : CGFloat = 0.0

/// the color drawing borders around the bars.
public var barBorderColor = NSUIColor.black()
public var barBorderColor = NSUIColor.black

/// the alpha value (transparency) that is used for drawing the highlight indicator bar. min = 0.0 (fully transparent), max = 1.0 (fully opaque)
public var highlightAlpha = CGFloat(120.0 / 255.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class LineChartDataSet: LineRadarChartDataSet, ILineChartDataSet
public var drawCirclesEnabled = true

/// The color of the inner circle (the circle-hole).
public var circleHoleColor: NSUIColor? = NSUIColor.white()
public var circleHoleColor: NSUIColor? = NSUIColor.white

/// True if drawing circles for this DataSet is enabled, false if not
public var drawCircleHoleEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PieChartDataSet: ChartDataSet, IPieChartDataSet

private func initialize()
{
self.valueTextColor = NSUIColor.white()
self.valueTextColor = NSUIColor.white
self.valueFont = NSUIFont.systemFont(ofSize: 13.0)
}

Expand Down Expand Up @@ -77,7 +77,7 @@ public class PieChartDataSet: ChartDataSet, IPieChartDataSet
public var yValuePosition: ValuePosition = .insideSlice

/// When valuePosition is OutsideSlice, indicates line color
public var valueLineColor: NSUIColor? = NSUIColor.black()
public var valueLineColor: NSUIColor? = NSUIColor.black

/// When valuePosition is OutsideSlice, indicates line width
public var valueLineWidth: CGFloat = 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RadarChartDataSet: LineRadarChartDataSet, IRadarChartDataSet
/// **default**: false
public var drawHighlightCircleEnabled: Bool = false

public var highlightCircleFillColor: NSUIColor? = NSUIColor.white()
public var highlightCircleFillColor: NSUIColor? = NSUIColor.white

/// The stroke color for highlight circle.
/// If `nil`, the color of the dataset is taken.
Expand Down
7 changes: 3 additions & 4 deletions Charts/Classes/Jobs/AnimatedZoomViewJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ public class AnimatedZoomChartViewJob: AnimatedViewPortJob
let valsInView = CGFloat(yAxis?.axisRange ?? 0.0) / viewPortHandler.scaleY
let xsInView = CGFloat(xValCount) / viewPortHandler.scaleX

var pt = CGPoint(
x: zoomOriginX + ((zoomCenterX - xsInView / 2.0) - zoomOriginX) * phase,
y: zoomOriginY + ((zoomCenterY + valsInView / 2.0) - zoomOriginY) * phase
)
let x = zoomOriginX + ((zoomCenterX - xsInView / 2.0) - zoomOriginX) * phase
let y = zoomOriginY + ((zoomCenterY + valsInView / 2.0) - zoomOriginY) * phase
var pt = CGPoint(x: x, y: y)

transformer.pointValueToPixel(&pt)

Expand Down
5 changes: 4 additions & 1 deletion Charts/Classes/Renderers/BarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,10 @@ public class BarChartRenderer: ChartDataRendererBase
context.saveGState()

let pixelToValueMatrix = trans.pixelToValueMatrix
let xToYRel = abs(sqrt(pixelToValueMatrix.b * pixelToValueMatrix.b + pixelToValueMatrix.d * pixelToValueMatrix.d) / sqrt(pixelToValueMatrix.a * pixelToValueMatrix.a + pixelToValueMatrix.c * pixelToValueMatrix.c))
let sqrtAC = sqrt(pixelToValueMatrix.a * pixelToValueMatrix.a + pixelToValueMatrix.c * pixelToValueMatrix.c)
let sqrtBD = sqrt(pixelToValueMatrix.b * pixelToValueMatrix.b + pixelToValueMatrix.d * pixelToValueMatrix.d)

let xToYRel = abs(sqrtBD / sqrtAC)

let arrowWidth = set.barSpace / 2.0
let arrowHeight = arrowWidth * xToYRel
Expand Down
4 changes: 2 additions & 2 deletions Charts/Classes/Renderers/BubbleChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class BubbleChartRenderer: ChartDataRendererBase

_pointBuffer.x = CGFloat(entry.xIndex - minx) * phaseX + CGFloat(minx)
_pointBuffer.y = CGFloat(entry.value) * phaseY
_pointBuffer = _pointBuffer.apply(transform: valueToPixelMatrix)
_pointBuffer = _pointBuffer.applying(valueToPixelMatrix)

let shapeSize = getShapeSize(entrySize: entry.size, maxSize: dataSet.maxSize, reference: referenceSize, normalizeSize: normalizeSize)
let shapeHalf = shapeSize / 2.0
Expand Down Expand Up @@ -190,7 +190,7 @@ public class BubbleChartRenderer: ChartDataRendererBase

pt.x = CGFloat(e.xIndex - minx) * phaseX + CGFloat(minx)
pt.y = CGFloat(e.value) * phaseY
pt = pt.apply(transform: valueToPixelMatrix)
pt = pt.applying(valueToPixelMatrix)

if (!viewPortHandler.isInBoundsRight(pt.x))
{
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Renderers/CandleStickChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public class CandleStickChartRenderer: LineScatterCandleRadarChartRenderer

pt.x = CGFloat(e.xIndex)
pt.y = CGFloat(e.high) * phaseY
pt = pt.apply(transform: valueToPixelMatrix)
pt = pt.applying(valueToPixelMatrix)

if (!viewPortHandler.isInBoundsRight(pt.x))
{
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Renderers/ChartLegendRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public class ChartLegendRenderer: ChartRendererBase
/// Draws the Legend-form at the given position with the color at the given index.
public func drawForm(context: CGContext, x: CGFloat, y: CGFloat, colorIndex: Int, legend: ChartLegend)
{
guard let formColor = legend.colors[colorIndex] where formColor != NSUIColor.clear() else {
guard let formColor = legend.colors[colorIndex] where formColor != NSUIColor.clear else {
return
}

Expand Down
8 changes: 4 additions & 4 deletions Charts/Classes/Renderers/ChartXAxisRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public class ChartXAxisRenderer: ChartAxisRendererBase
{
guard let xAxis = xAxis else { return }

let paraStyle = NSParagraphStyle.default().mutableCopy() as! NSMutableParagraphStyle
let paraStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paraStyle.alignment = .center

let labelAttrs = [NSFontAttributeName: xAxis.labelFont,
Expand Down Expand Up @@ -177,7 +177,7 @@ public class ChartXAxisRenderer: ChartAxisRendererBase

position.x = CGFloat(i)
position.y = 0.0
position = position.apply(transform: valueToPixelMatrix)
position = position.applying(valueToPixelMatrix)

if (viewPortHandler.isInBoundsX(position.x))
{
Expand Down Expand Up @@ -251,7 +251,7 @@ public class ChartXAxisRenderer: ChartAxisRendererBase
{
position.x = CGFloat(i)
position.y = 0.0
position = position.apply(transform: valueToPixelMatrix)
position = position.applying(valueToPixelMatrix)

if (position.x >= viewPortHandler.offsetLeft
&& position.x <= viewPortHandler.chartWidth)
Expand Down Expand Up @@ -295,7 +295,7 @@ public class ChartXAxisRenderer: ChartAxisRendererBase

position.x = CGFloat(l.limit)
position.y = 0.0
position = position.apply(transform: trans)
position = position.applying(trans)

renderLimitLineLine(context: context, limitLine: l, position: position)
renderLimitLineLabel(context: context, limitLine: l, position: position, yOffset: 2.0 + l.yOffset)
Expand Down
6 changes: 3 additions & 3 deletions Charts/Classes/Renderers/ChartXAxisRendererBarChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ChartXAxisRendererBarChart: ChartXAxisRenderer
barData = chart?.data as? BarChartData
else { return }

let paraStyle = NSParagraphStyle.default().mutableCopy() as! NSMutableParagraphStyle
let paraStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paraStyle.alignment = .center

let labelAttrs = [NSFontAttributeName: xAxis.labelFont,
Expand Down Expand Up @@ -76,7 +76,7 @@ public class ChartXAxisRendererBarChart: ChartXAxisRenderer
position.x += (CGFloat(step) - 1.0) / 2.0
}

position = position.apply(transform: valueToPixelMatrix)
position = position.applying(valueToPixelMatrix)

if (viewPortHandler.isInBoundsX(position.x))
{
Expand Down Expand Up @@ -148,7 +148,7 @@ public class ChartXAxisRendererBarChart: ChartXAxisRenderer
{
position.x = CGFloat(i * step) + CGFloat(i) * barData.groupSpace - 0.5
position.y = 0.0
position = position.apply(transform: valueToPixelMatrix)
position = position.applying(valueToPixelMatrix)

if (viewPortHandler.isInBoundsX(position.x))
{
Expand Down
Loading

0 comments on commit c9ac170

Please sign in to comment.