diff --git a/Charts/Classes/Animation/ChartAnimationEasing.swift b/Charts/Classes/Animation/ChartAnimationEasing.swift index b6719ca4d9..64f451d4bf 100644 --- a/Charts/Classes/Animation/ChartAnimationEasing.swift +++ b/Charts/Classes/Animation/ChartAnimationEasing.swift @@ -51,7 +51,7 @@ public enum ChartEasingOption: Int case easeInOutBounce } -public typealias ChartEasingFunctionBlock = ((elapsed: TimeInterval, duration: TimeInterval) -> CGFloat) +public typealias ChartEasingFunctionBlock = ((_ elapsed: TimeInterval, _ duration: TimeInterval) -> CGFloat) internal func easingFunctionFromOption(_ easing: ChartEasingOption) -> ChartEasingFunctionBlock { diff --git a/Charts/Classes/Animation/ChartAnimator.swift b/Charts/Classes/Animation/ChartAnimator.swift index f4ff32f7ff..e9d1ebfe14 100644 --- a/Charts/Classes/Animation/ChartAnimator.swift +++ b/Charts/Classes/Animation/ChartAnimator.swift @@ -118,7 +118,7 @@ public class ChartAnimator: NSObject if (_easingX != nil) { - phaseX = _easingX!(elapsed: elapsed, duration: duration) + phaseX = _easingX!(elapsed, duration) } else { @@ -137,7 +137,7 @@ public class ChartAnimator: NSObject if (_easingY != nil) { - phaseY = _easingY!(elapsed: elapsed, duration: duration) + phaseY = _easingY!(elapsed, duration) } else { diff --git a/Charts/Classes/Charts/BarChartView.swift b/Charts/Classes/Charts/BarChartView.swift index c99afacba1..39937cb927 100644 --- a/Charts/Classes/Charts/BarChartView.swift +++ b/Charts/Classes/Charts/BarChartView.swift @@ -72,8 +72,7 @@ public class BarChartView: BarLineChartViewBase, BarChartDataProvider /// - returns: the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be found in the charts data. public func getBarBounds(_ e: BarChartDataEntry) -> CGRect { - guard let - set = _data?.getDataSetForEntry(e) as? IBarChartDataSet + guard let set = _data?.getDataSetForEntry(e) as? IBarChartDataSet else { return CGRect.null } let barspace = set.barSpace diff --git a/Charts/Classes/Charts/BarLineChartViewBase.swift b/Charts/Classes/Charts/BarLineChartViewBase.swift index 89f6369c11..78e131f7c8 100644 --- a/Charts/Classes/Charts/BarLineChartViewBase.swift +++ b/Charts/Classes/Charts/BarLineChartViewBase.swift @@ -134,7 +134,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar #endif } - public override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey : AnyObject]?, context: UnsafeMutablePointer?) + public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { // Saving current position of chart. var oldPoint: CGPoint? @@ -148,7 +148,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) // Restoring old position of chart - if var newPoint = oldPoint where keepPositionOnRotation + if var newPoint = oldPoint, keepPositionOnRotation { getTransformer(.left).pointValueToPixel(&newPoint) viewPortHandler.centerViewPort(pt: newPoint, chart: self) @@ -981,7 +981,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar // If there is two scrollview together, we pick the superview of the inner scrollview. // In the case of UITableViewWrepperView, the superview will be UITableView - if let superViewOfScrollView = scrollView?.superview where superViewOfScrollView is NSUIScrollView + if let superViewOfScrollView = scrollView?.superview, superViewOfScrollView is NSUIScrollView { scrollView = superViewOfScrollView } @@ -1895,8 +1895,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar getTransformer(.left).pixelToValue(&pt) - guard let - data = _data + guard let data = _data else { return Int(round(pt.x)) } return min(data.xValCount - 1, Int(floor(pt.x))) diff --git a/Charts/Classes/Charts/ChartViewBase.swift b/Charts/Classes/Charts/ChartViewBase.swift index cb9ceac19b..8e67765d94 100755 --- a/Charts/Classes/Charts/ChartViewBase.swift +++ b/Charts/Classes/Charts/ChartViewBase.swift @@ -270,7 +270,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate // check if a custom formatter is set or not var reference = Double(0.0) - if let data = _data where data.xValCount >= 2 + if let data = _data, data.xValCount >= 2 { reference = fabs(max - min) } @@ -300,9 +300,8 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate defer { context.restoreGState() } let hasText = noDataText.characters.count > 0 - let hasDescription = noDataTextDescription?.characters.count > 0 var textHeight = hasText ? infoFont.lineHeight : 0.0 - if hasDescription + if let hasDescription = noDataTextDescription?.characters, hasDescription.count > 0 { textHeight += infoFont.lineHeight } @@ -768,7 +767,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate /// - returns: the x-value at the given index public func getXValue(_ index: Int) -> String! { - guard let data = _data where data.xValCount > index else + guard let data = _data, data.xValCount > index else { return nil } @@ -850,7 +849,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate public func saveToPath(_ path: String, format: ImageFormat, compressionQuality: Double) throws -> Bool { if let image = getChartImage(transparent: format != .jpeg) { - var imageData: NSData? + var imageData: Data? switch (format) { case .png: @@ -882,7 +881,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate internal var _viewportJobs = [ChartViewPortJob]() - public override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey : AnyObject]?, context: UnsafeMutablePointer?) + public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if (keyPath == "bounds" || keyPath == "frame") { @@ -890,7 +889,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate if (_viewPortHandler !== nil && (bounds.size.width != _viewPortHandler.chartWidth || - bounds.size.height != _viewPortHandler.chartHeight)) + bounds.size.height != _viewPortHandler.chartHeight)) { _viewPortHandler.setChartDimens(width: bounds.size.width, height: bounds.size.height) diff --git a/Charts/Classes/Charts/CombinedChartView.swift b/Charts/Classes/Charts/CombinedChartView.swift index 81c23613b2..a686fdd292 100644 --- a/Charts/Classes/Charts/CombinedChartView.swift +++ b/Charts/Classes/Charts/CombinedChartView.swift @@ -79,7 +79,7 @@ public class CombinedChartView: BarLineChartViewBase, LineChartDataProvider, Bar _xAxis.axisRange = abs(_xAxis._axisMaximum - _xAxis._axisMinimum) - if _xAxis.axisRange == 0.0 && self.lineData?.yValCount > 0 + if _xAxis.axisRange == 0.0, let lineData = self.lineData, lineData.yValCount > 0 { _xAxis.axisRange = 1.0 } diff --git a/Charts/Classes/Charts/PieRadarChartViewBase.swift b/Charts/Classes/Charts/PieRadarChartViewBase.swift index f332040614..6d5fd7a82c 100755 --- a/Charts/Classes/Charts/PieRadarChartViewBase.swift +++ b/Charts/Classes/Charts/PieRadarChartViewBase.swift @@ -80,7 +80,7 @@ public class PieRadarChartViewBase: ChartViewBase { calcMinMax() - if let data = _data where _legend !== nil + if let data = _data, _legend !== nil { _legendRenderer.computeLegend(data) } diff --git a/Charts/Classes/Charts/RadarChartView.swift b/Charts/Classes/Charts/RadarChartView.swift index b6feafb01f..e02c029a67 100644 --- a/Charts/Classes/Charts/RadarChartView.swift +++ b/Charts/Classes/Charts/RadarChartView.swift @@ -102,7 +102,7 @@ public class RadarChartView: PieRadarChartViewBase _yAxisRenderer?.computeAxis(yMin: _yAxis._axisMinimum, yMax: _yAxis._axisMaximum) _xAxisRenderer?.computeAxis(xValAverageLength: data?.xValAverageLength ?? 0, xValues: data?.xVals ?? []) - if let data = _data, legend = _legend where !legend.isLegendCustom + if let data = _data, let legend = _legend, !legend.isLegendCustom { _legendRenderer?.computeLegend(data) } diff --git a/Charts/Classes/Components/ChartYAxis.swift b/Charts/Classes/Components/ChartYAxis.swift index cf16a33f5c..340efae395 100644 --- a/Charts/Classes/Components/ChartYAxis.swift +++ b/Charts/Classes/Components/ChartYAxis.swift @@ -254,7 +254,7 @@ public class ChartYAxis: ChartAxisBase return "" } - return (valueFormatter ?? _defaultValueFormatter).string(from: entries[index])! + return (valueFormatter ?? _defaultValueFormatter).string(from: entries[index] as NSNumber)! } /// - returns: true if this axis needs horizontal offset, false if no offset is needed. diff --git a/Charts/Classes/Data/Implementations/ChartBaseDataSet.swift b/Charts/Classes/Data/Implementations/ChartBaseDataSet.swift index b5d8ffb679..dcbfce92d7 100644 --- a/Charts/Classes/Data/Implementations/ChartBaseDataSet.swift +++ b/Charts/Classes/Data/Implementations/ChartBaseDataSet.swift @@ -297,7 +297,7 @@ public class ChartBaseDataSet: NSObject, IChartDataSet public override var description: String { - return String(format: "%@, label: %@, %i entries", arguments: [NSStringFromClass(self.dynamicType), self.label ?? "", self.entryCount]) + return String(format: "%@, label: %@, %i entries", arguments: [NSStringFromClass(type(of: self)), self.label ?? "", self.entryCount]) } public override var debugDescription: String @@ -314,9 +314,9 @@ public class ChartBaseDataSet: NSObject, IChartDataSet // MARK: - NSCopying - public func copyWithZone(_ zone: NSZone?) -> AnyObject + public func copyWithZone(_ zone: NSZone?) -> Any { - let copy = self.dynamicType.init() + let copy = type(of: self).init() copy.colors = colors copy.valueColors = valueColors diff --git a/Charts/Classes/Data/Implementations/Standard/BarChartDataEntry.swift b/Charts/Classes/Data/Implementations/Standard/BarChartDataEntry.swift index 971e4338fb..0041ef4533 100644 --- a/Charts/Classes/Data/Implementations/Standard/BarChartDataEntry.swift +++ b/Charts/Classes/Data/Implementations/Standard/BarChartDataEntry.swift @@ -51,7 +51,7 @@ public class BarChartDataEntry: ChartDataEntry } /// Constructor for normal bars (not stacked). - public override init(value: Double, xIndex: Int, data: AnyObject?) + public override init(value: Double, xIndex: Int, data: Any?) { super.init(value: value, xIndex: xIndex, data: data) } @@ -134,7 +134,7 @@ public class BarChartDataEntry: ChartDataEntry // MARK: NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! BarChartDataEntry copy._values = _values diff --git a/Charts/Classes/Data/Implementations/Standard/BarChartDataSet.swift b/Charts/Classes/Data/Implementations/Standard/BarChartDataSet.swift index 8149364b52..5ccff94d2b 100644 --- a/Charts/Classes/Data/Implementations/Standard/BarChartDataSet.swift +++ b/Charts/Classes/Data/Implementations/Standard/BarChartDataSet.swift @@ -189,7 +189,7 @@ public class BarChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBarChartD // MARK: - NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! BarChartDataSet copy._stackSize = _stackSize diff --git a/Charts/Classes/Data/Implementations/Standard/BarLineScatterCandleBubbleChartDataSet.swift b/Charts/Classes/Data/Implementations/Standard/BarLineScatterCandleBubbleChartDataSet.swift index bc736ae1d0..0152024025 100644 --- a/Charts/Classes/Data/Implementations/Standard/BarLineScatterCandleBubbleChartDataSet.swift +++ b/Charts/Classes/Data/Implementations/Standard/BarLineScatterCandleBubbleChartDataSet.swift @@ -28,7 +28,7 @@ public class BarLineScatterCandleBubbleChartDataSet: ChartDataSet, IBarLineScatt // MARK: - NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! BarLineScatterCandleBubbleChartDataSet copy.highlightColor = highlightColor diff --git a/Charts/Classes/Data/Implementations/Standard/BubbleChartDataEntry.swift b/Charts/Classes/Data/Implementations/Standard/BubbleChartDataEntry.swift index c1164dae36..447b374a85 100644 --- a/Charts/Classes/Data/Implementations/Standard/BubbleChartDataEntry.swift +++ b/Charts/Classes/Data/Implementations/Standard/BubbleChartDataEntry.swift @@ -45,7 +45,7 @@ public class BubbleChartDataEntry: ChartDataEntry // MARK: NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! BubbleChartDataEntry copy.size = size diff --git a/Charts/Classes/Data/Implementations/Standard/BubbleChartDataSet.swift b/Charts/Classes/Data/Implementations/Standard/BubbleChartDataSet.swift index 454d546c15..cf0fcc1d5c 100644 --- a/Charts/Classes/Data/Implementations/Standard/BubbleChartDataSet.swift +++ b/Charts/Classes/Data/Implementations/Standard/BubbleChartDataSet.swift @@ -127,7 +127,7 @@ public class BubbleChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBubble // MARK: - NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! BubbleChartDataSet copy._xMin = _xMin diff --git a/Charts/Classes/Data/Implementations/Standard/CandleChartDataEntry.swift b/Charts/Classes/Data/Implementations/Standard/CandleChartDataEntry.swift index 7f637e6466..52a2ec1dfc 100644 --- a/Charts/Classes/Data/Implementations/Standard/CandleChartDataEntry.swift +++ b/Charts/Classes/Data/Implementations/Standard/CandleChartDataEntry.swift @@ -79,7 +79,7 @@ public class CandleChartDataEntry: ChartDataEntry // MARK: NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! CandleChartDataEntry copy.high = high diff --git a/Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift b/Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift index 8c7af44bb5..7a105b81cf 100644 --- a/Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift +++ b/Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift @@ -38,30 +38,32 @@ public class ChartDataEntry: NSObject self.xIndex = xIndex } - public init(value: Double, xIndex: Int, data: AnyObject?) + public init(value: Double, xIndex: Int, data: Any?) { super.init() self.value = value self.xIndex = xIndex - self.data = data + self.data = data as AnyObject } // MARK: NSObject - public override func isEqual(_ object: AnyObject?) -> Bool + public override func isEqual(_ object: Any?) -> Bool { + let object = object as? AnyObject + if (object === nil) { return false } - if (!object!.isKind(of: self.dynamicType)) + if (!object!.isKind(of: type(of: self))) { return false } - if let d = object as? ChartDataEntry where d.data !== self.data || !d.isEqual(self.data) + if let d = object as? ChartDataEntry, d.data !== self.data || !d.isEqual(self.data) { return false } @@ -88,9 +90,9 @@ public class ChartDataEntry: NSObject // MARK: NSCopying - public func copyWithZone(_ zone: NSZone?) -> AnyObject + public func copyWithZone(_ zone: NSZone?) -> Any { - let copy = self.dynamicType.init() + let copy = type(of: self).init() copy.value = value copy.xIndex = xIndex @@ -107,7 +109,7 @@ public func ==(lhs: ChartDataEntry, rhs: ChartDataEntry) -> Bool return true } - if (!lhs.isKind(of: rhs.dynamicType)) + if (!lhs.isKind(of: type(of: rhs))) { return false } diff --git a/Charts/Classes/Data/Implementations/Standard/ChartDataSet.swift b/Charts/Classes/Data/Implementations/Standard/ChartDataSet.swift index a736366cf5..2b59a9bc98 100644 --- a/Charts/Classes/Data/Implementations/Standard/ChartDataSet.swift +++ b/Charts/Classes/Data/Implementations/Standard/ChartDataSet.swift @@ -393,7 +393,7 @@ public class ChartDataSet: ChartBaseDataSet } } - if _yVals.last?.xIndex > e.xIndex + if let xIndex = _yVals.last?.xIndex, xIndex > e.xIndex { var closestIndex = entryIndex(xIndex: e.xIndex, rounding: .closest) if _yVals[closestIndex].xIndex < e.xIndex @@ -501,7 +501,7 @@ public class ChartDataSet: ChartBaseDataSet // MARK: - NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! ChartDataSet diff --git a/Charts/Classes/Data/Implementations/Standard/LineChartDataSet.swift b/Charts/Classes/Data/Implementations/Standard/LineChartDataSet.swift index 98a8482fdb..4b636c0433 100644 --- a/Charts/Classes/Data/Implementations/Standard/LineChartDataSet.swift +++ b/Charts/Classes/Data/Implementations/Standard/LineChartDataSet.swift @@ -184,7 +184,7 @@ public class LineChartDataSet: LineRadarChartDataSet, ILineChartDataSet // MARK: NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! LineChartDataSet copy.circleColors = circleColors diff --git a/Charts/Classes/Data/Implementations/Standard/LineRadarChartDataSet.swift b/Charts/Classes/Data/Implementations/Standard/LineRadarChartDataSet.swift index c2f2d833d9..01ca56d6c8 100644 --- a/Charts/Classes/Data/Implementations/Standard/LineRadarChartDataSet.swift +++ b/Charts/Classes/Data/Implementations/Standard/LineRadarChartDataSet.swift @@ -78,7 +78,7 @@ public class LineRadarChartDataSet: LineScatterCandleRadarChartDataSet, ILineRad // MARK: NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! LineRadarChartDataSet copy.fillColor = fillColor diff --git a/Charts/Classes/Data/Implementations/Standard/LineScatterCandleRadarChartDataSet.swift b/Charts/Classes/Data/Implementations/Standard/LineScatterCandleRadarChartDataSet.swift index db09290a1e..a648e51ab7 100644 --- a/Charts/Classes/Data/Implementations/Standard/LineScatterCandleRadarChartDataSet.swift +++ b/Charts/Classes/Data/Implementations/Standard/LineScatterCandleRadarChartDataSet.swift @@ -42,7 +42,7 @@ public class LineScatterCandleRadarChartDataSet: BarLineScatterCandleBubbleChart // MARK: NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! LineScatterCandleRadarChartDataSet copy.drawHorizontalHighlightIndicatorEnabled = drawHorizontalHighlightIndicatorEnabled diff --git a/Charts/Classes/Data/Implementations/Standard/PieChartDataSet.swift b/Charts/Classes/Data/Implementations/Standard/PieChartDataSet.swift index d84f047246..9d38c9c3a6 100644 --- a/Charts/Classes/Data/Implementations/Standard/PieChartDataSet.swift +++ b/Charts/Classes/Data/Implementations/Standard/PieChartDataSet.swift @@ -96,7 +96,7 @@ public class PieChartDataSet: ChartDataSet, IPieChartDataSet // MARK: - NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! PieChartDataSet copy._sliceSpace = _sliceSpace diff --git a/Charts/Classes/Data/Implementations/Standard/ScatterChartDataSet.swift b/Charts/Classes/Data/Implementations/Standard/ScatterChartDataSet.swift index 39d91360fb..b5abb8c263 100644 --- a/Charts/Classes/Data/Implementations/Standard/ScatterChartDataSet.swift +++ b/Charts/Classes/Data/Implementations/Standard/ScatterChartDataSet.swift @@ -48,7 +48,7 @@ public class ScatterChartDataSet: LineScatterCandleRadarChartDataSet, IScatterCh // MARK: NSCopying - public override func copyWithZone(_ zone: NSZone?) -> AnyObject + public override func copyWithZone(_ zone: NSZone?) -> Any { let copy = super.copyWithZone(zone) as! ScatterChartDataSet copy.scatterShapeSize = scatterShapeSize diff --git a/Charts/Classes/Highlight/BarChartHighlighter.swift b/Charts/Classes/Highlight/BarChartHighlighter.swift index 9f799c3375..3b007e1365 100644 --- a/Charts/Classes/Highlight/BarChartHighlighter.swift +++ b/Charts/Classes/Highlight/BarChartHighlighter.swift @@ -38,8 +38,7 @@ public class BarChartHighlighter: ChartHighlighter guard let selectionDetail = getSelectionDetail(xIndex: xIndex, y: y, dataSetIndex: dataSetIndex) else { return nil } - if let set = barData.getDataSetByIndex(dataSetIndex) as? IBarChartDataSet - where set.isStacked + if let set = barData.getDataSetByIndex(dataSetIndex) as? IBarChartDataSet, set.isStacked { var pt = CGPoint(x: 0.0, y: y) @@ -139,8 +138,7 @@ public class BarChartHighlighter: ChartHighlighter stackIndex: -1) } - if let ranges = getRanges(entry: entry) - where ranges.count > 0 + if let ranges = getRanges(entry: entry), ranges.count > 0 { let stackIndex = getClosestStackIndex(ranges: ranges, value: yValue) return ChartHighlight(xIndex: xIndex, diff --git a/Charts/Classes/Highlight/ChartHighlight.swift b/Charts/Classes/Highlight/ChartHighlight.swift index 3d26f9e638..23dab174a2 100644 --- a/Charts/Classes/Highlight/ChartHighlight.swift +++ b/Charts/Classes/Highlight/ChartHighlight.swift @@ -17,24 +17,24 @@ import Foundation public class ChartHighlight: NSObject { /// the x-index of the highlighted value - private var _xIndex = Int(0) + fileprivate var _xIndex = Int(0) /// the y-value of the highlighted value - private var _value = Double.nan + fileprivate var _value = Double.nan /// the index of the data object - in case it refers to more than one - private var _dataIndex = Int(0) + fileprivate var _dataIndex = Int(0) /// the index of the dataset the highlighted value is in - private var _dataSetIndex = Int(0) + fileprivate var _dataSetIndex = Int(0) /// index which value of a stacked bar entry is highlighted /// /// **default**: -1 - private var _stackIndex = Int(-1) + fileprivate var _stackIndex = Int(-1) /// the range of the bar that is selected (only for stacked-barchart) - private var _range: ChartRange? + fileprivate var _range: ChartRange? public override init() { @@ -120,14 +120,17 @@ public class ChartHighlight: NSObject return "Highlight, xIndex: \(_xIndex), dataIndex (combined charts): \(_dataIndex),dataSetIndex: \(_dataSetIndex), stackIndex (only stacked barentry): \(_stackIndex), value: \(_value)" } - public override func isEqual(_ object: AnyObject?) -> Bool + public override func isEqual(_ object: Any?) -> Bool { + + let object = object as? AnyObject + if (object === nil) { return false } - if (!object!.isKind(of: self.dynamicType)) + if (!object!.isKind(of: type(of: self))) { return false } @@ -168,7 +171,7 @@ func ==(lhs: ChartHighlight, rhs: ChartHighlight) -> Bool return true } - if (!lhs.isKind(of: rhs.dynamicType)) + if (!lhs.isKind(of: type(of: rhs))) { return false } diff --git a/Charts/Classes/Highlight/ChartHighlighter.swift b/Charts/Classes/Highlight/ChartHighlighter.swift index 69badb30da..c99640001b 100644 --- a/Charts/Classes/Highlight/ChartHighlighter.swift +++ b/Charts/Classes/Highlight/ChartHighlighter.swift @@ -33,8 +33,7 @@ public class ChartHighlighter : NSObject { let xIndex = getXIndex(x) - guard let - selectionDetail = getSelectionDetail(xIndex: xIndex, y: y, dataSetIndex: nil) + guard let selectionDetail = getSelectionDetail(xIndex: xIndex, y: y, dataSetIndex: nil) else { return nil } return ChartHighlight(xIndex: xIndex, value: selectionDetail.value, dataIndex: selectionDetail.dataIndex, dataSetIndex: selectionDetail.dataSetIndex, stackIndex: -1) @@ -82,8 +81,7 @@ public class ChartHighlighter : NSObject var vals = [ChartSelectionDetail]() var pt = CGPoint() - guard let - data = self.chart?.data + guard let data = self.chart?.data else { return vals } for i in 0 ..< data.dataSetCount diff --git a/Charts/Classes/Highlight/CombinedHighlighter.swift b/Charts/Classes/Highlight/CombinedHighlighter.swift index 8a2afc3a8e..f31d12c6ef 100644 --- a/Charts/Classes/Highlight/CombinedHighlighter.swift +++ b/Charts/Classes/Highlight/CombinedHighlighter.swift @@ -25,8 +25,7 @@ public class CombinedHighlighter: ChartHighlighter var vals = [ChartSelectionDetail]() var pt = CGPoint() - guard let - data = self.chart?.data as? CombinedChartData + guard let data = self.chart?.data as? CombinedChartData else { return vals } // get all chartdata objects diff --git a/Charts/Classes/Highlight/HorizontalBarChartHighlighter.swift b/Charts/Classes/Highlight/HorizontalBarChartHighlighter.swift index 965c62812a..2243014ffd 100644 --- a/Charts/Classes/Highlight/HorizontalBarChartHighlighter.swift +++ b/Charts/Classes/Highlight/HorizontalBarChartHighlighter.swift @@ -38,8 +38,7 @@ public class HorizontalBarChartHighlighter: BarChartHighlighter guard let selectionDetail = getSelectionDetail(xIndex: xIndex, y: y, dataSetIndex: dataSetIndex) else { return nil } - if let set = barData.getDataSetByIndex(dataSetIndex) as? IBarChartDataSet - where set.isStacked + if let set = barData.getDataSetByIndex(dataSetIndex) as? IBarChartDataSet, set.isStacked { var pt = CGPoint(x: y, y: 0.0) @@ -63,8 +62,7 @@ public class HorizontalBarChartHighlighter: BarChartHighlighter public override func getXIndex(_ x: CGFloat) -> Int { - if let barData = self.chart?.data as? BarChartData - where !barData.isGrouped + if let barData = self.chart?.data as? BarChartData, !barData.isGrouped { // create an array of the touch-point var pt = CGPoint(x: 0.0, y: x) diff --git a/Charts/Classes/Jobs/AnimatedMoveViewJob.swift b/Charts/Classes/Jobs/AnimatedMoveViewJob.swift index 0e3047676a..238130c425 100644 --- a/Charts/Classes/Jobs/AnimatedMoveViewJob.swift +++ b/Charts/Classes/Jobs/AnimatedMoveViewJob.swift @@ -42,11 +42,10 @@ public class AnimatedMoveChartViewJob: AnimatedViewPortJob internal override func animationUpdate() { - guard let - viewPortHandler = viewPortHandler, - transformer = transformer, - view = view - else { return } + guard let viewPortHandler = viewPortHandler, + let transformer = transformer, + let view = view + else { return } var pt = CGPoint( x: xOrigin + (xIndex - xOrigin) * phase, diff --git a/Charts/Classes/Jobs/AnimatedViewPortJob.swift b/Charts/Classes/Jobs/AnimatedViewPortJob.swift index 5c72688299..e01b35c270 100644 --- a/Charts/Classes/Jobs/AnimatedViewPortJob.swift +++ b/Charts/Classes/Jobs/AnimatedViewPortJob.swift @@ -108,7 +108,7 @@ public class AnimatedViewPortJob: ChartViewPortJob if _easing != nil { - phase = _easing!(elapsed: elapsed, duration: duration) + phase = _easing!(elapsed, duration) } else { diff --git a/Charts/Classes/Jobs/AnimatedZoomViewJob.swift b/Charts/Classes/Jobs/AnimatedZoomViewJob.swift index 115acac503..fe9fec6ca6 100644 --- a/Charts/Classes/Jobs/AnimatedZoomViewJob.swift +++ b/Charts/Classes/Jobs/AnimatedZoomViewJob.swift @@ -62,11 +62,10 @@ public class AnimatedZoomChartViewJob: AnimatedViewPortJob internal override func animationUpdate() { - guard let - viewPortHandler = viewPortHandler, - transformer = transformer, - view = view - else { return } + guard let viewPortHandler = viewPortHandler, + let transformer = transformer, + let view = view + else { return } let scaleX = xOrigin + (self.scaleX - xOrigin) * phase let scaleY = yOrigin + (self.scaleY - yOrigin) * phase diff --git a/Charts/Classes/Jobs/MoveChartViewJob.swift b/Charts/Classes/Jobs/MoveChartViewJob.swift index 5e28c47da4..d663cf3e54 100644 --- a/Charts/Classes/Jobs/MoveChartViewJob.swift +++ b/Charts/Classes/Jobs/MoveChartViewJob.swift @@ -35,11 +35,10 @@ public class MoveChartViewJob: ChartViewPortJob public override func doJob() { - guard let - viewPortHandler = viewPortHandler, - transformer = transformer, - view = view - else { return } + guard let viewPortHandler = viewPortHandler, + let transformer = transformer, + let view = view + else { return } var pt = CGPoint( x: xIndex, @@ -49,4 +48,4 @@ public class MoveChartViewJob: ChartViewPortJob transformer.pointValueToPixel(&pt) viewPortHandler.centerViewPort(pt: pt, chart: view) } -} \ No newline at end of file +} diff --git a/Charts/Classes/Jobs/ZoomChartViewJob.swift b/Charts/Classes/Jobs/ZoomChartViewJob.swift index 758ab8a913..a9e7d333fa 100644 --- a/Charts/Classes/Jobs/ZoomChartViewJob.swift +++ b/Charts/Classes/Jobs/ZoomChartViewJob.swift @@ -46,11 +46,10 @@ public class ZoomChartViewJob: ChartViewPortJob public override func doJob() { - guard let - viewPortHandler = viewPortHandler, - transformer = transformer, - view = view - else { return } + guard let viewPortHandler = viewPortHandler, + let transformer = transformer, + let view = view + else { return } var matrix = viewPortHandler.setZoom(scaleX: scaleX, scaleY: scaleY) viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false) diff --git a/Charts/Classes/Renderers/BarChartRenderer.swift b/Charts/Classes/Renderers/BarChartRenderer.swift index 6af999cd3f..8e6b5e246c 100644 --- a/Charts/Classes/Renderers/BarChartRenderer.swift +++ b/Charts/Classes/Renderers/BarChartRenderer.swift @@ -31,7 +31,7 @@ public class BarChartRenderer: ChartDataRendererBase public override func drawData(context: CGContext) { - guard let dataProvider = dataProvider, barData = dataProvider.barData else { return } + guard let dataProvider = dataProvider, let barData = dataProvider.barData else { return } for i in 0 ..< barData.dataSetCount { @@ -51,11 +51,10 @@ public class BarChartRenderer: ChartDataRendererBase public func drawDataSet(context: CGContext, dataSet: IBarChartDataSet, index: Int) { - guard let - dataProvider = dataProvider, - barData = dataProvider.barData, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let barData = dataProvider.barData, + let animator = animator + else { return } context.saveGState() @@ -284,11 +283,10 @@ public class BarChartRenderer: ChartDataRendererBase // if values are drawn if (passesCheck()) { - guard let - dataProvider = dataProvider, - barData = dataProvider.barData, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let barData = dataProvider.barData, + let animator = animator + else { return } var dataSets = barData.dataSets @@ -359,7 +357,7 @@ public class BarChartRenderer: ChartDataRendererBase let val = e.value drawValue(context: context, - value: formatter.string(from: val)!, + value: formatter.string(from: val as NSNumber)!, xPos: valuePoint.x, yPos: valuePoint.y + (val >= 0.0 ? posOffset : negOffset), font: valueFont, @@ -394,7 +392,7 @@ public class BarChartRenderer: ChartDataRendererBase } drawValue(context: context, - value: formatter.string(from: e.value)!, + value: formatter.string(from: e.value as NSNumber)!, xPos: valuePoint.x, yPos: valuePoint.y + (e.value >= 0.0 ? posOffset : negOffset), font: valueFont, @@ -448,7 +446,7 @@ public class BarChartRenderer: ChartDataRendererBase } drawValue(context: context, - value: formatter.string(from: vals[k])!, + value: formatter.string(from: vals[k] as NSNumber)!, xPos: x, yPos: y, font: valueFont, @@ -477,11 +475,10 @@ public class BarChartRenderer: ChartDataRendererBase public override func drawHighlighted(context: CGContext, indices: [ChartHighlight]) { - guard let - dataProvider = dataProvider, - barData = dataProvider.barData, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let barData = dataProvider.barData, + let animator = animator + else { return } context.saveGState() @@ -577,9 +574,9 @@ public class BarChartRenderer: ChartDataRendererBase trans.pointValuesToPixel(&_highlightArrowPtsBuffer) context.beginPath() - context.moveTo(x: _highlightArrowPtsBuffer[0].x, y: _highlightArrowPtsBuffer[0].y) - context.addLineTo(x: _highlightArrowPtsBuffer[1].x, y: _highlightArrowPtsBuffer[1].y) - context.addLineTo(x: _highlightArrowPtsBuffer[2].x, y: _highlightArrowPtsBuffer[2].y) + context.move(to: CGPoint(x: _highlightArrowPtsBuffer[0].x, y: _highlightArrowPtsBuffer[0].y)) + context.addLine(to: CGPoint(x: _highlightArrowPtsBuffer[1].x, y: _highlightArrowPtsBuffer[1].y)) + context.addLine(to: CGPoint(x: _highlightArrowPtsBuffer[2].x, y: _highlightArrowPtsBuffer[2].y)) context.closePath() context.fillPath() @@ -596,7 +593,7 @@ public class BarChartRenderer: ChartDataRendererBase internal func passesCheck() -> Bool { - guard let dataProvider = dataProvider, barData = dataProvider.barData else { return false } + guard let dataProvider = dataProvider, let barData = dataProvider.barData else { return false } return CGFloat(barData.yValCount) < CGFloat(dataProvider.maxVisibleValueCount) * viewPortHandler.scaleX } diff --git a/Charts/Classes/Renderers/BubbleChartRenderer.swift b/Charts/Classes/Renderers/BubbleChartRenderer.swift index 4265270687..4f2dddb884 100644 --- a/Charts/Classes/Renderers/BubbleChartRenderer.swift +++ b/Charts/Classes/Renderers/BubbleChartRenderer.swift @@ -30,7 +30,7 @@ public class BubbleChartRenderer: ChartDataRendererBase public override func drawData(context: CGContext) { - guard let dataProvider = dataProvider, bubbleData = dataProvider.bubbleData else { return } + guard let dataProvider = dataProvider, let bubbleData = dataProvider.bubbleData else { return } for set in bubbleData.dataSets as! [IBubbleChartDataSet] { @@ -59,10 +59,9 @@ public class BubbleChartRenderer: ChartDataRendererBase public func drawDataSet(context: CGContext, dataSet: IBubbleChartDataSet) { - guard let - dataProvider = dataProvider, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let animator = animator + else { return } let trans = dataProvider.getTransformer(dataSet.axisDependency) @@ -73,10 +72,9 @@ public class BubbleChartRenderer: ChartDataRendererBase let valueToPixelMatrix = trans.valueToPixelMatrix - guard let - entryFrom = dataSet.entryForXIndex(self.minX), - entryTo = dataSet.entryForXIndex(self.maxX) - else { return } + guard let entryFrom = dataSet.entryForXIndex(self.minX), + let entryTo = dataSet.entryForXIndex(self.maxX) + else { return } let minx = max(dataSet.entryIndex(entry: entryFrom), 0) let maxx = min(dataSet.entryIndex(entry: entryTo) + 1, entryCount) @@ -142,11 +140,10 @@ public class BubbleChartRenderer: ChartDataRendererBase public override func drawValues(context: CGContext) { - guard let - dataProvider = dataProvider, - bubbleData = dataProvider.bubbleData, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let bubbleData = dataProvider.bubbleData, + let animator = animator + else { return } // if values are drawn if (bubbleData.yValCount < Int(ceil(CGFloat(dataProvider.maxVisibleValueCount) * viewPortHandler.scaleX))) @@ -174,10 +171,9 @@ public class BubbleChartRenderer: ChartDataRendererBase let entryCount = dataSet.entryCount - guard let - entryFrom = dataSet.entryForXIndex(self.minX), - entryTo = dataSet.entryForXIndex(self.maxX) - else { continue } + guard let entryFrom = dataSet.entryForXIndex(self.minX), + let entryTo = dataSet.entryForXIndex(self.maxX) + else { continue } let minx = max(dataSet.entryIndex(entry: entryFrom), 0) let maxx = min(dataSet.entryIndex(entry: entryTo) + 1, entryCount) @@ -202,7 +198,7 @@ public class BubbleChartRenderer: ChartDataRendererBase continue } - let text = formatter.string(from: e.size) + let text = formatter.string(from: e.size as NSNumber) // Larger font for larger bubbles? let valueFont = dataSet.valueFont @@ -228,11 +224,10 @@ public class BubbleChartRenderer: ChartDataRendererBase public override func drawHighlighted(context: CGContext, indices: [ChartHighlight]) { - guard let - dataProvider = dataProvider, - bubbleData = dataProvider.bubbleData, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let bubbleData = dataProvider.bubbleData, + let animator = animator + else { return } context.saveGState() @@ -247,9 +242,7 @@ public class BubbleChartRenderer: ChartDataRendererBase for dataSetIndex in minDataSetIndex.. Bool { - guard let dataProvider = dataProvider, barData = dataProvider.barData else { return false } + guard let dataProvider = dataProvider, let barData = dataProvider.barData else { return false } return CGFloat(barData.yValCount) < CGFloat(dataProvider.maxVisibleValueCount) * viewPortHandler.scaleY } diff --git a/Charts/Classes/Renderers/LineChartRenderer.swift b/Charts/Classes/Renderers/LineChartRenderer.swift index b0541a2719..5c4c177ca4 100644 --- a/Charts/Classes/Renderers/LineChartRenderer.swift +++ b/Charts/Classes/Renderers/LineChartRenderer.swift @@ -64,11 +64,11 @@ public class LineChartRenderer: LineRadarChartRenderer context.setLineWidth(dataSet.lineWidth) if (dataSet.lineDashLengths != nil) { - context.setLineDash(phase: dataSet.lineDashPhase, lengths: dataSet.lineDashLengths!, count: dataSet.lineDashLengths!.count) + context.setLineDash(phase: dataSet.lineDashPhase, lengths: dataSet.lineDashLengths!) } else { - context.setLineDash(phase: 0.0, lengths: nil, count: 0) + context.setLineDash(phase: 0.0, lengths: []) } // if drawing cubic lines is enabled @@ -90,17 +90,15 @@ public class LineChartRenderer: LineRadarChartRenderer public func drawCubicBezier(context: CGContext, dataSet: ILineChartDataSet) { - guard let - trans = dataProvider?.getTransformer(dataSet.axisDependency), - animator = animator - else { return } + guard let trans = dataProvider?.getTransformer(dataSet.axisDependency), + let animator = animator + else { return } let entryCount = dataSet.entryCount - guard let - entryFrom = dataSet.entryForXIndex(self.minX < 0 ? 0 : self.minX, rounding: .down), - entryTo = dataSet.entryForXIndex(self.maxX, rounding: .up) - else { return } + guard let entryFrom = dataSet.entryForXIndex(self.minX < 0 ? 0 : self.minX, rounding: .down), + let entryTo = dataSet.entryForXIndex(self.maxX, rounding: .up) + else { return } let diff = (entryFrom == entryTo) ? 1 : 0 let minx = max(dataSet.entryIndex(entry: entryFrom) - diff - 1, 0) @@ -136,7 +134,7 @@ public class LineChartRenderer: LineRadarChartRenderer if cur == nil || next == nil { return } // let the spline start - cubicPath.moveTo(&valueToPixelMatrix, x: CGFloat(cur.xIndex), y: CGFloat(cur.value) * phaseY) + cubicPath.move(to: CGPoint(x: CGFloat(cur.xIndex), y: CGFloat(cur.value) * phaseY), transform: valueToPixelMatrix) for j in stride(from: (minx + 1), to: min(size, entryCount), by: 1) { @@ -152,13 +150,7 @@ public class LineChartRenderer: LineRadarChartRenderer curDx = CGFloat(next.xIndex - prev.xIndex) * intensity curDy = CGFloat(next.value - prev.value) * intensity - cubicPath.addCurve(&valueToPixelMatrix, - cp1x: CGFloat(prev.xIndex) + prevDx, - cp1y: (CGFloat(prev.value) + prevDy) * phaseY, - cp2x: CGFloat(cur.xIndex) - curDx, - cp2y: (CGFloat(cur.value) - curDy) * phaseY, - endingAtX: CGFloat(cur.xIndex), - y: CGFloat(cur.value) * phaseY) + cubicPath.addCurve(to: CGPoint(x: CGFloat(cur.xIndex), y: CGFloat(cur.value) * phaseY), control1: CGPoint(x: CGFloat(prev.xIndex) + prevDx, y: (CGFloat(prev.value) + prevDy) * phaseY), control2: CGPoint(x: CGFloat(cur.xIndex) - curDx,y: (CGFloat(cur.value) - curDy) * phaseY), transform: valueToPixelMatrix) } } @@ -182,17 +174,15 @@ public class LineChartRenderer: LineRadarChartRenderer public func drawHorizontalBezier(context: CGContext, dataSet: ILineChartDataSet) { - guard let - trans = dataProvider?.getTransformer(dataSet.axisDependency), - animator = animator - else { return } + guard let trans = dataProvider?.getTransformer(dataSet.axisDependency), + let animator = animator + else { return } let entryCount = dataSet.entryCount - guard let - entryFrom = dataSet.entryForXIndex(self.minX < 0 ? 0 : self.minX, rounding: .down), - entryTo = dataSet.entryForXIndex(self.maxX, rounding: .up) - else { return } + guard let entryFrom = dataSet.entryForXIndex(self.minX < 0 ? 0 : self.minX, rounding: .down), + let entryTo = dataSet.entryForXIndex(self.maxX, rounding: .up) + else { return } let diff = (entryFrom == entryTo) ? 1 : 0 let minx = max(dataSet.entryIndex(entry: entryFrom) - diff, 0) @@ -219,7 +209,7 @@ public class LineChartRenderer: LineRadarChartRenderer if cur == nil { return } // let the spline start - cubicPath.moveTo(&valueToPixelMatrix, x: CGFloat(cur.xIndex), y: CGFloat(cur.value) * phaseY) + cubicPath.move(to: CGPoint(x: CGFloat(cur.xIndex), y: CGFloat(cur.value) * phaseY), transform: valueToPixelMatrix) for j in stride(from: (minx + 1), to: min(size, entryCount), by: 1) { @@ -228,10 +218,7 @@ public class LineChartRenderer: LineRadarChartRenderer let cpx = CGFloat(prev.xIndex) + CGFloat(cur.xIndex - prev.xIndex) / 2.0 - cubicPath.addCurve(&valueToPixelMatrix, - cp1x: cpx, cp1y: CGFloat(prev.value) * phaseY, - cp2x: cpx, cp2y: CGFloat(cur.value) * phaseY, - endingAtX: CGFloat(cur.xIndex), y: CGFloat(cur.value) * phaseY) + cubicPath.addCurve(to: CGPoint(x: CGFloat(cur.xIndex), y: CGFloat(cur.value) * phaseY), control1: CGPoint(x: cpx, y: CGFloat(prev.value) * phaseY), control2: CGPoint(x: cpx, y: CGFloat(cur.value) * phaseY), transform: valueToPixelMatrix) } } @@ -275,8 +262,8 @@ public class LineChartRenderer: LineRadarChartRenderer pt1 = pt1.applying(matrix) pt2 = pt2.applying(matrix) - spline.addLineTo(nil, x: pt1.x, y: pt1.y) - spline.addLineTo(nil, x: pt2.x, y: pt2.y) + spline.addLine(to: CGPoint(x: pt1.x, y: pt1.y)) + spline.addLine(to: CGPoint(x: pt2.x, y: pt2.y)) spline.closeSubpath() if dataSet.fill != nil @@ -293,10 +280,9 @@ public class LineChartRenderer: LineRadarChartRenderer public func drawLinear(context: CGContext, dataSet: ILineChartDataSet) { - guard let - trans = dataProvider?.getTransformer(dataSet.axisDependency), - animator = animator - else { return } + guard let trans = dataProvider?.getTransformer(dataSet.axisDependency), + let animator = animator + else { return } let valueToPixelMatrix = trans.valueToPixelMatrix @@ -307,10 +293,9 @@ public class LineChartRenderer: LineRadarChartRenderer let phaseX = max(0.0, min(1.0, animator.phaseX)) let phaseY = animator.phaseY - guard let - entryFrom = dataSet.entryForXIndex(self.minX < 0 ? 0 : self.minX, rounding: .down), - entryTo = dataSet.entryForXIndex(self.maxX, rounding: .up) - else { return } + guard let entryFrom = dataSet.entryForXIndex(self.minX < 0 ? 0 : self.minX, rounding: .down), + let entryTo = dataSet.entryForXIndex(self.maxX, rounding: .up) + else { return } var diff = (entryFrom == entryTo) ? 1 : 0 if dataSet.mode == .cubicBezier @@ -390,7 +375,7 @@ public class LineChartRenderer: LineRadarChartRenderer // get the color that is set for this line-segment context.setStrokeColor(dataSet.colorAt(j).cgColor) - context.strokeLineSegments(between: _lineSegments, count: pointsPerEntryPair) + context.strokeLineSegments(between: _lineSegments) } } else @@ -448,9 +433,8 @@ public class LineChartRenderer: LineRadarChartRenderer if j > 0 { - let size = max((count - minx - 1) * pointsPerEntryPair, pointsPerEntryPair) context.setStrokeColor(dataSet.colorAt(0).cgColor) - context.strokeLineSegments(between: _lineSegments, count: size) + context.strokeLineSegments(between: _lineSegments) } } } @@ -500,8 +484,8 @@ public class LineChartRenderer: LineRadarChartRenderer e = dataSet.entryForIndex(from) if e != nil { - filled.moveTo(&matrix, x: CGFloat(e.xIndex), y: fillMin) - filled.addLineTo(&matrix, x: CGFloat(e.xIndex), y: CGFloat(e.value) * phaseY) + filled.move(to: CGPoint(x: CGFloat(e.xIndex), y: fillMin), transform: matrix) + filled.addLine(to: CGPoint(x: CGFloat(e.xIndex), y: CGFloat(e.value) * phaseY), transform: matrix) } // create a new path @@ -512,17 +496,17 @@ public class LineChartRenderer: LineRadarChartRenderer if drawSteppedEnabled { guard let ePrev = dataSet.entryForIndex(x-1) else { continue } - filled.addLineTo(&matrix, x: CGFloat(e.xIndex), y: CGFloat(ePrev.value) * phaseY) + filled.addLine(to: CGPoint(x: CGFloat(e.xIndex), y: CGFloat(ePrev.value) * phaseY), transform: matrix) } - filled.addLineTo(&matrix, x: CGFloat(e.xIndex), y: CGFloat(e.value) * phaseY) + filled.addLine(to: CGPoint(x: CGFloat(e.xIndex), y: CGFloat(e.value) * phaseY), transform: matrix) } // close up e = dataSet.entryForIndex(max(min(Int(ceil(CGFloat(to - from) * phaseX + CGFloat(from))) - 1, dataSet.entryCount - 1), 0)) if e != nil { - filled.addLineTo(&matrix, x: CGFloat(e.xIndex), y: fillMin) + filled.addLine(to: CGPoint(x: CGFloat(e.xIndex), y: fillMin), transform: matrix) } filled.closeSubpath() @@ -531,11 +515,10 @@ public class LineChartRenderer: LineRadarChartRenderer public override func drawValues(context: CGContext) { - guard let - dataProvider = dataProvider, - lineData = dataProvider.lineData, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let lineData = dataProvider.lineData, + let animator = animator + else { return } if (CGFloat(lineData.yValCount) < CGFloat(dataProvider.maxVisibleValueCount) * viewPortHandler.scaleX) { @@ -572,10 +555,9 @@ public class LineChartRenderer: LineRadarChartRenderer let entryCount = dataSet.entryCount - guard let - entryFrom = dataSet.entryForXIndex(self.minX < 0 ? 0 : self.minX, rounding: .down), - entryTo = dataSet.entryForXIndex(self.maxX, rounding: .up) - else { continue } + guard let entryFrom = dataSet.entryForXIndex(self.minX < 0 ? 0 : self.minX, rounding: .down), + let entryTo = dataSet.entryForXIndex(self.maxX, rounding: .up) + else { continue } var diff = (entryFrom == entryTo) ? 1 : 0 if dataSet.mode == .cubicBezier @@ -605,7 +587,7 @@ public class LineChartRenderer: LineRadarChartRenderer } ChartUtils.drawText(context: context, - text: formatter.string(from: e.value)!, + text: formatter.string(from: e.value as NSNumber)!, point: CGPoint( x: pt.x, y: pt.y - CGFloat(valOffset) - valueFont.lineHeight), @@ -623,11 +605,10 @@ public class LineChartRenderer: LineRadarChartRenderer private func drawCircles(context: CGContext) { - guard let - dataProvider = dataProvider, - lineData = dataProvider.lineData, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let lineData = dataProvider.lineData, + let animator = animator + else { return } let phaseX = max(0.0, min(1.0, animator.phaseX)) let phaseY = animator.phaseY @@ -665,10 +646,9 @@ public class LineChartRenderer: LineRadarChartRenderer (dataSet.circleHoleColor == nil || dataSet.circleHoleColor == NSUIColor.clear) - guard let - entryFrom = dataSet.entryForXIndex(self.minX < 0 ? 0 : self.minX, rounding: .down), - entryTo = dataSet.entryForXIndex(self.maxX, rounding: .up) - else { continue } + guard let entryFrom = dataSet.entryForXIndex(self.minX < 0 ? 0 : self.minX, rounding: .down), + let entryTo = dataSet.entryForXIndex(self.maxX, rounding: .up) + else { continue } var diff = (entryFrom == entryTo) ? 1 : 0 if dataSet.mode == .cubicBezier @@ -709,10 +689,10 @@ public class LineChartRenderer: LineRadarChartRenderer { // Begin path for circle with hole context.beginPath() - context.addEllipse(inRect: rect) + context.addEllipse(in: rect) // Cut hole in path - context.addArc(centerX: pt.x, y: pt.y, radius: circleHoleRadius, startAngle: 0.0, endAngle: CGFloat(M_PI_2), clockwise: 1) + context.addArc(center: CGPoint(x: pt.x, y: pt.y), radius: circleHoleRadius, startAngle: 0.0, endAngle: CGFloat(M_PI_2), clockwise: true) // Fill in-between context.fillPath() @@ -744,11 +724,10 @@ public class LineChartRenderer: LineRadarChartRenderer public override func drawHighlighted(context: CGContext, indices: [ChartHighlight]) { - guard let - lineData = dataProvider?.lineData, - chartXMax = dataProvider?.chartXMax, - animator = animator - else { return } + guard let lineData = dataProvider?.lineData, + let chartXMax = dataProvider?.chartXMax, + let animator = animator + else { return } context.saveGState() @@ -771,11 +750,11 @@ public class LineChartRenderer: LineRadarChartRenderer context.setLineWidth(set.highlightLineWidth) if (set.highlightLineDashLengths != nil) { - context.setLineDash(phase: set.highlightLineDashPhase, lengths: set.highlightLineDashLengths!, count: set.highlightLineDashLengths!.count) + context.setLineDash(phase: set.highlightLineDashPhase, lengths: set.highlightLineDashLengths!) } else { - context.setLineDash(phase: 0.0, lengths: nil, count: 0) + context.setLineDash(phase: 0.0, lengths: []) } let xIndex = high.xIndex; // get the x-position diff --git a/Charts/Classes/Renderers/LineScatterCandleRadarChartRenderer.swift b/Charts/Classes/Renderers/LineScatterCandleRadarChartRenderer.swift index 7eeae41e56..75564a3dd7 100644 --- a/Charts/Classes/Renderers/LineScatterCandleRadarChartRenderer.swift +++ b/Charts/Classes/Renderers/LineScatterCandleRadarChartRenderer.swift @@ -33,8 +33,8 @@ public class LineScatterCandleRadarChartRenderer: ChartDataRendererBase if set.isVerticalHighlightIndicatorEnabled { context.beginPath() - context.moveTo(x: point.x, y: viewPortHandler.contentTop) - context.addLineTo(x: point.x, y: viewPortHandler.contentBottom) + context.move(to: CGPoint(x: point.x, y: viewPortHandler.contentTop)) + context.addLine(to: CGPoint(x: point.x, y: viewPortHandler.contentBottom)) context.strokePath() } @@ -42,8 +42,8 @@ public class LineScatterCandleRadarChartRenderer: ChartDataRendererBase if set.isHorizontalHighlightIndicatorEnabled { context.beginPath() - context.moveTo(x: viewPortHandler.contentLeft, y: point.y) - context.addLineTo(x: viewPortHandler.contentRight, y: point.y) + context.move(to: CGPoint(x: viewPortHandler.contentLeft, y: point.y)) + context.addLine(to: CGPoint(x: viewPortHandler.contentRight, y: point.y)) context.strokePath() } } diff --git a/Charts/Classes/Renderers/PieChartRenderer.swift b/Charts/Classes/Renderers/PieChartRenderer.swift index ce496b4d09..de6939119e 100755 --- a/Charts/Classes/Renderers/PieChartRenderer.swift +++ b/Charts/Classes/Renderers/PieChartRenderer.swift @@ -91,11 +91,10 @@ public class PieChartRenderer: ChartDataRendererBase public func drawDataSet(context: CGContext, dataSet: IPieChartDataSet) { - guard let - chart = chart, - data = chart.data, - animator = animator - else {return } + guard let chart = chart, + let data = chart.data, + let animator = animator + else {return } var angle: CGFloat = 0.0 let rotationAngle = chart.rotationAngle @@ -156,12 +155,9 @@ public class PieChartRenderer: ChartDataRendererBase let path = CGMutablePath() - path.moveTo(nil, - x: arcStartPointX, - y: arcStartPointY) - path.addRelativeArc(matrix: nil, - x: center.x, - y: center.y, + path.move(to: CGPoint(x: arcStartPointX, y: arcStartPointY)) + + path.addRelativeArc(center: CGPoint(x: center.x, y: center.y), radius: radius, startAngle: startAngleOuter * ChartUtils.Math.FDEG2RAD, delta: sweepAngleOuter * ChartUtils.Math.FDEG2RAD) @@ -197,12 +193,9 @@ public class PieChartRenderer: ChartDataRendererBase } let endAngleInner = startAngleInner + sweepAngleInner - path.addLineTo(nil, - x: center.x + innerRadius * cos(endAngleInner * ChartUtils.Math.FDEG2RAD), - y: center.y + innerRadius * sin(endAngleInner * ChartUtils.Math.FDEG2RAD)) - path.addRelativeArc(matrix: nil, - x: center.x, - y: center.y, + path.addLine(to: CGPoint(x: center.x + innerRadius * cos(endAngleInner * ChartUtils.Math.FDEG2RAD), + y: center.y + innerRadius * sin(endAngleInner * ChartUtils.Math.FDEG2RAD))) + path.addRelativeArc(center: CGPoint(x: center.x, y: center.y), radius: innerRadius, startAngle: endAngleInner * ChartUtils.Math.FDEG2RAD, delta: -sweepAngleInner * ChartUtils.Math.FDEG2RAD) @@ -226,15 +219,11 @@ public class PieChartRenderer: ChartDataRendererBase let arcEndPointX = center.x + sliceSpaceOffset * cos(angleMiddle * ChartUtils.Math.FDEG2RAD) let arcEndPointY = center.y + sliceSpaceOffset * sin(angleMiddle * ChartUtils.Math.FDEG2RAD) - path.addLineTo(nil, - x: arcEndPointX, - y: arcEndPointY) + path.addLine(to: CGPoint(x: arcEndPointX, y: arcEndPointY)) } else { - path.addLineTo(nil, - x: center.x, - y: center.y) + path.addLine(to: CGPoint(x: center.x, y: center.y)) } } @@ -242,7 +231,7 @@ public class PieChartRenderer: ChartDataRendererBase context.beginPath() context.addPath(path) - context.eoFillPath() + context.fillPath(using: .evenOdd) } } @@ -254,11 +243,10 @@ public class PieChartRenderer: ChartDataRendererBase public override func drawValues(context: CGContext) { - guard let - chart = chart, - data = chart.data, - animator = animator - else { return } + guard let chart = chart, + let data = chart.data, + let animator = animator + else { return } let center = chart.centerCircleBox @@ -342,7 +330,7 @@ public class PieChartRenderer: ChartDataRendererBase let transformedAngle = rotationAngle + angle * phaseY let value = usePercentValuesEnabled ? e.value / yValueSum * 100.0 : e.value - let valueText = formatter.string(from: value)! + let valueText = formatter.string(from: value as NSNumber)! let sliceXBase = cos(transformedAngle * ChartUtils.Math.FDEG2RAD) let sliceYBase = sin(transformedAngle * ChartUtils.Math.FDEG2RAD) @@ -403,9 +391,9 @@ public class PieChartRenderer: ChartDataRendererBase context.setStrokeColor(dataSet.valueLineColor!.cgColor) context.setLineWidth(dataSet.valueLineWidth); - context.moveTo(x: pt0.x, y: pt0.y) - context.addLineTo(x: pt1.x, y: pt1.y) - context.addLineTo(x: pt2.x, y: pt2.y) + context.move(to: CGPoint(x: pt0.x, y: pt0.y)) + context.addLine(to: CGPoint(x: pt1.x, y: pt1.y)) + context.addLine(to: CGPoint(x: pt2.x, y: pt2.y)) context.drawPath(using: CGPathDrawingMode.stroke); } @@ -516,10 +504,9 @@ public class PieChartRenderer: ChartDataRendererBase /// draws the hole in the center of the chart and the transparent circle / hole private func drawHole(context: CGContext) { - guard let - chart = chart, - animator = animator - else { return } + guard let chart = chart, + let animator = animator + else { return } if (chart.drawHoleEnabled) { @@ -554,17 +541,17 @@ public class PieChartRenderer: ChartDataRendererBase // draw the transparent-circle context.beginPath() - context.addEllipse(inRect: CGRect( + context.addEllipse(in: CGRect( x: center.x - secondHoleRadius, y: center.y - secondHoleRadius, width: secondHoleRadius * 2.0, height: secondHoleRadius * 2.0)) - context.addEllipse(inRect: CGRect( + context.addEllipse(in: CGRect( x: center.x - holeRadius, y: center.y - holeRadius, width: holeRadius * 2.0, height: holeRadius * 2.0)) - context.eoFillPath() + context.fillPath(using: .evenOdd) } } @@ -575,10 +562,9 @@ public class PieChartRenderer: ChartDataRendererBase /// draws the description text in the center of the pie chart makes most sense when center-hole is enabled private func drawCenterText(context: CGContext) { - guard let - chart = chart, - centerAttributedText = chart.centerAttributedText - else { return } + guard let chart = chart, + let centerAttributedText = chart.centerAttributedText + else { return } if chart.drawCenterTextEnabled && centerAttributedText.length > 0 { @@ -614,11 +600,10 @@ public class PieChartRenderer: ChartDataRendererBase public override func drawHighlighted(context: CGContext, indices: [ChartHighlight]) { - guard let - chart = chart, - data = chart.data, - animator = animator - else { return } + guard let chart = chart, + let data = chart.data, + let animator = animator + else { return } context.saveGState() @@ -707,12 +692,9 @@ public class PieChartRenderer: ChartDataRendererBase let path = CGMutablePath() - path.moveTo(nil, - x: center.x + highlightedRadius * cos(startAngleShifted * ChartUtils.Math.FDEG2RAD), - y: center.y + highlightedRadius * sin(startAngleShifted * ChartUtils.Math.FDEG2RAD)) - path.addRelativeArc(matrix: nil, - x: center.x, - y: center.y, + path.move(to: CGPoint(x: center.x + highlightedRadius * cos(startAngleShifted * ChartUtils.Math.FDEG2RAD), + y: center.y + highlightedRadius * sin(startAngleShifted * ChartUtils.Math.FDEG2RAD))) + path.addRelativeArc(center: CGPoint(x: center.x, y: center.y), radius: highlightedRadius, startAngle: startAngleShifted * ChartUtils.Math.FDEG2RAD, delta: sweepAngleShifted * ChartUtils.Math.FDEG2RAD) @@ -754,12 +736,9 @@ public class PieChartRenderer: ChartDataRendererBase } let endAngleInner = startAngleInner + sweepAngleInner - path.addLineTo(nil, - x: center.x + innerRadius * cos(endAngleInner * ChartUtils.Math.FDEG2RAD), - y: center.y + innerRadius * sin(endAngleInner * ChartUtils.Math.FDEG2RAD)) - path.addRelativeArc(matrix: nil, - x: center.x, - y: center.y, + path.addLine(to: CGPoint(x: center.x + innerRadius * cos(endAngleInner * ChartUtils.Math.FDEG2RAD), + y: center.y + innerRadius * sin(endAngleInner * ChartUtils.Math.FDEG2RAD))) + path.addRelativeArc(center: CGPoint(x: center.x, y: center.y), radius: innerRadius, startAngle: endAngleInner * ChartUtils.Math.FDEG2RAD, delta: -sweepAngleInner * ChartUtils.Math.FDEG2RAD) @@ -773,15 +752,11 @@ public class PieChartRenderer: ChartDataRendererBase let arcEndPointX = center.x + sliceSpaceRadius * cos(angleMiddle * ChartUtils.Math.FDEG2RAD) let arcEndPointY = center.y + sliceSpaceRadius * sin(angleMiddle * ChartUtils.Math.FDEG2RAD) - path.addLineTo(nil, - x: arcEndPointX, - y: arcEndPointY) + path.addLine(to: CGPoint(x: arcEndPointX, y: arcEndPointY)) } else { - path.addLineTo(nil, - x: center.x, - y: center.y) + path.addLine(to: CGPoint(x: center.x, y: center.y)) } } @@ -789,7 +764,7 @@ public class PieChartRenderer: ChartDataRendererBase context.beginPath() context.addPath(path) - context.eoFillPath() + context.fillPath(using: .evenOdd) } context.restoreGState() diff --git a/Charts/Classes/Renderers/RadarChartRenderer.swift b/Charts/Classes/Renderers/RadarChartRenderer.swift index 1c6b6baa99..d1aab086ed 100644 --- a/Charts/Classes/Renderers/RadarChartRenderer.swift +++ b/Charts/Classes/Renderers/RadarChartRenderer.swift @@ -65,10 +65,9 @@ public class RadarChartRenderer: LineRadarChartRenderer /// - parameter mostEntries: the entry count of the dataset with the most entries internal func drawDataSet(context: CGContext, dataSet: IRadarChartDataSet, mostEntries: Int) { - guard let - chart = chart, - animator = animator - else { return } + guard let chart = chart, + let animator = animator + else { return } context.saveGState() @@ -101,12 +100,12 @@ public class RadarChartRenderer: LineRadarChartRenderer if !hasMovedToPoint { - path.moveTo(nil, x: p.x, y: p.y) + path.move(to: CGPoint(x: p.x, y: p.y)) hasMovedToPoint = true } else { - path.addLineTo(nil, x: p.x, y: p.y) + path.addLine(to: CGPoint(x: p.x, y: p.y)) } } @@ -114,7 +113,7 @@ public class RadarChartRenderer: LineRadarChartRenderer if dataSet.entryCount < mostEntries { // if this is not the largest set, draw a line to the center before closing - path.addLineTo(nil, x: center.x, y: center.y) + path.addLine(to: CGPoint(x: center.x, y: center.y)) } path.closeSubpath() @@ -149,11 +148,10 @@ public class RadarChartRenderer: LineRadarChartRenderer public override func drawValues(context: CGContext) { - guard let - chart = chart, - data = chart.data, - animator = animator - else { return } + guard let chart = chart, + let data = chart.data, + let animator = animator + else { return } let phaseX = animator.phaseX let phaseY = animator.phaseY @@ -193,7 +191,7 @@ public class RadarChartRenderer: LineRadarChartRenderer ChartUtils.drawText( context: context, - text: formatter.string(from: e.value)!, + text: formatter.string(from: e.value as NSNumber)!, point: CGPoint(x: p.x, y: p.y - yoffset - valueFont.lineHeight), align: .center, attributes: [NSFontAttributeName: valueFont, @@ -212,10 +210,9 @@ public class RadarChartRenderer: LineRadarChartRenderer public func drawWeb(context: CGContext) { - guard let - chart = chart, - data = chart.data - else { return } + guard let chart = chart, + let data = chart.data + else { return } let sliceangle = chart.sliceAngle @@ -247,7 +244,7 @@ public class RadarChartRenderer: LineRadarChartRenderer _webLineSegmentsBuffer[1].x = p.x _webLineSegmentsBuffer[1].y = p.y - context.strokeLineSegments(between: _webLineSegmentsBuffer, count: 2) + context.strokeLineSegments(between: _webLineSegmentsBuffer) } // draw the inner-web @@ -271,7 +268,7 @@ public class RadarChartRenderer: LineRadarChartRenderer _webLineSegmentsBuffer[1].x = p2.x _webLineSegmentsBuffer[1].y = p2.y - context.strokeLineSegments(between: _webLineSegmentsBuffer, count: 2) + context.strokeLineSegments(between: _webLineSegmentsBuffer) } } @@ -282,21 +279,20 @@ public class RadarChartRenderer: LineRadarChartRenderer public override func drawHighlighted(context: CGContext, indices: [ChartHighlight]) { - guard let - chart = chart, - data = chart.data as? RadarChartData, - animator = animator - else { return } + guard let chart = chart, + let data = chart.data as? RadarChartData, + let animator = animator + else { return } context.saveGState() context.setLineWidth(data.highlightLineWidth) if (data.highlightLineDashLengths != nil) { - context.setLineDash(phase: data.highlightLineDashPhase, lengths: data.highlightLineDashLengths!, count: data.highlightLineDashLengths!.count) + context.setLineDash(phase: data.highlightLineDashPhase, lengths: data.highlightLineDashLengths!) } else { - context.setLineDash(phase: 0.0, lengths: nil, count: 0) + context.setLineDash(phase: 0.0, lengths: []) } let phaseX = animator.phaseX @@ -386,20 +382,20 @@ public class RadarChartRenderer: LineRadarChartRenderer if let fillColor = fillColor { context.beginPath() - context.addEllipse(inRect: CGRect(x: point.x - outerRadius, y: point.y - outerRadius, width: outerRadius * 2.0, height: outerRadius * 2.0)) + context.addEllipse(in: CGRect(x: point.x - outerRadius, y: point.y - outerRadius, width: outerRadius * 2.0, height: outerRadius * 2.0)) if innerRadius > 0.0 { - context.addEllipse(inRect: CGRect(x: point.x - innerRadius, y: point.y - innerRadius, width: innerRadius * 2.0, height: innerRadius * 2.0)) + context.addEllipse(in: CGRect(x: point.x - innerRadius, y: point.y - innerRadius, width: innerRadius * 2.0, height: innerRadius * 2.0)) } context.setFillColor(fillColor.cgColor) - context.eoFillPath() + context.fillPath(using: .evenOdd) } if let strokeColor = strokeColor { context.beginPath() - context.addEllipse(inRect: CGRect(x: point.x - outerRadius, y: point.y - outerRadius, width: outerRadius * 2.0, height: outerRadius * 2.0)) + context.addEllipse(in: CGRect(x: point.x - outerRadius, y: point.y - outerRadius, width: outerRadius * 2.0, height: outerRadius * 2.0)) context.setStrokeColor(strokeColor.cgColor) context.setLineWidth(strokeWidth) context.strokePath() diff --git a/Charts/Classes/Renderers/ScatterChartRenderer.swift b/Charts/Classes/Renderers/ScatterChartRenderer.swift index 2e20ca7744..71838a9304 100644 --- a/Charts/Classes/Renderers/ScatterChartRenderer.swift +++ b/Charts/Classes/Renderers/ScatterChartRenderer.swift @@ -54,10 +54,9 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer public func drawDataSet(context: CGContext, dataSet: IScatterChartDataSet) { - guard let - dataProvider = dataProvider, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let animator = animator + else { return } let trans = dataProvider.getTransformer(dataSet.axisDependency) @@ -173,18 +172,18 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer // create a triangle path context.beginPath() - context.moveTo(x: point.x, y: point.y - shapeHalf) - context.addLineTo(x: point.x + shapeHalf, y: point.y + shapeHalf) - context.addLineTo(x: point.x - shapeHalf, y: point.y + shapeHalf) + context.move(to: CGPoint(x: point.x, y: point.y - shapeHalf)) + context.addLine(to: CGPoint(x: point.x + shapeHalf, y: point.y + shapeHalf)) + context.addLine(to: CGPoint(x: point.x - shapeHalf, y: point.y + shapeHalf)) if shapeHoleSize > 0.0 { - context.addLineTo(x: point.x, y: point.y - shapeHalf) + context.addLine(to: CGPoint(x: point.x, y: point.y - shapeHalf)) - context.moveTo(x: point.x - shapeHalf + shapeStrokeSize, y: point.y + shapeHalf - shapeStrokeSize) - context.addLineTo(x: point.x + shapeHalf - shapeStrokeSize, y: point.y + shapeHalf - shapeStrokeSize) - context.addLineTo(x: point.x, y: point.y - shapeHalf + shapeStrokeSize) - context.addLineTo(x: point.x - shapeHalf + shapeStrokeSize, y: point.y + shapeHalf - shapeStrokeSize) + context.move(to: CGPoint(x: point.x - shapeHalf + shapeStrokeSize, y: point.y + shapeHalf - shapeStrokeSize)) + context.addLine(to: CGPoint(x: point.x + shapeHalf - shapeStrokeSize, y: point.y + shapeHalf - shapeStrokeSize)) + context.addLine(to: CGPoint(x: point.x, y: point.y - shapeHalf + shapeStrokeSize)) + context.addLine(to: CGPoint(x: point.x - shapeHalf + shapeStrokeSize, y: point.y + shapeHalf - shapeStrokeSize)) } context.closePath() @@ -197,9 +196,9 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer // create a triangle path context.beginPath() - context.moveTo(x: point.x, y: point.y - shapeHalf + shapeStrokeSize) - context.addLineTo(x: point.x + shapeHalf - shapeStrokeSize, y: point.y + shapeHalf - shapeStrokeSize) - context.addLineTo(x: point.x - shapeHalf + shapeStrokeSize, y: point.y + shapeHalf - shapeStrokeSize) + context.move(to: CGPoint(x: point.x, y: point.y - shapeHalf + shapeStrokeSize)) + context.addLine(to: CGPoint(x: point.x + shapeHalf - shapeStrokeSize, y: point.y + shapeHalf - shapeStrokeSize)) + context.addLine(to: CGPoint(x: point.x - shapeHalf + shapeStrokeSize, y: point.y + shapeHalf - shapeStrokeSize)) context.closePath() context.fillPath() @@ -212,13 +211,13 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer _lineSegments[0].y = point.y _lineSegments[1].x = point.x + shapeHalf _lineSegments[1].y = point.y - context.strokeLineSegments(between: _lineSegments, count: 2) + context.strokeLineSegments(between: _lineSegments) _lineSegments[0].x = point.x _lineSegments[0].y = point.y - shapeHalf _lineSegments[1].x = point.x _lineSegments[1].y = point.y + shapeHalf - context.strokeLineSegments(between: _lineSegments, count: 2) + context.strokeLineSegments(between: _lineSegments) } else if (shape == .x) { @@ -227,13 +226,13 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer _lineSegments[0].y = point.y - shapeHalf _lineSegments[1].x = point.x + shapeHalf _lineSegments[1].y = point.y + shapeHalf - context.strokeLineSegments(between: _lineSegments, count: 2) + context.strokeLineSegments(between: _lineSegments) _lineSegments[0].x = point.x + shapeHalf _lineSegments[0].y = point.y - shapeHalf _lineSegments[1].x = point.x - shapeHalf _lineSegments[1].y = point.y + shapeHalf - context.strokeLineSegments(between: _lineSegments, count: 2) + context.strokeLineSegments(between: _lineSegments) } else if (shape == .custom) { @@ -263,11 +262,10 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer public override func drawValues(context: CGContext) { - guard let - dataProvider = dataProvider, - scatterData = dataProvider.scatterData, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let scatterData = dataProvider.scatterData, + let animator = animator + else { return } // if values are drawn if (scatterData.yValCount < Int(ceil(CGFloat(dataProvider.maxVisibleValueCount) * viewPortHandler.scaleX))) @@ -320,7 +318,7 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer continue } - let text = formatter.string(from: e.value) + let text = formatter.string(from: e.value as NSNumber) ChartUtils.drawText( context: context, @@ -345,11 +343,10 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer public override func drawHighlighted(context: CGContext, indices: [ChartHighlight]) { - guard let - dataProvider = dataProvider, - scatterData = dataProvider.scatterData, - animator = animator - else { return } + guard let dataProvider = dataProvider, + let scatterData = dataProvider.scatterData, + let animator = animator + else { return } let chartXMax = dataProvider.chartXMax @@ -374,11 +371,11 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer context.setLineWidth(set.highlightLineWidth) if (set.highlightLineDashLengths != nil) { - context.setLineDash(phase: set.highlightLineDashPhase, lengths: set.highlightLineDashLengths!, count: set.highlightLineDashLengths!.count) + context.setLineDash(phase: set.highlightLineDashPhase, lengths: set.highlightLineDashLengths!) } else { - context.setLineDash(phase: 0.0, lengths: nil, count: 0) + context.setLineDash(phase: 0.0, lengths: []) } let xIndex = high.xIndex; // get the x-position diff --git a/Charts/Classes/Utils/ChartFill.swift b/Charts/Classes/Utils/ChartFill.swift index 4c7ef3d742..b8a69996d4 100644 --- a/Charts/Classes/Utils/ChartFill.swift +++ b/Charts/Classes/Utils/ChartFill.swift @@ -267,17 +267,17 @@ public class ChartFill: NSObject case .image: context.clip() - context.draw(in: rect, image: _image!) + context.draw(_image!, in: rect) case .tiledImage: context.clip() - context.draw(in: rect, byTiling: _image!) + context.draw(_image!, in: rect, byTiling: true) case .layer: context.clip() - context.draw(in: rect, layer: _layer!) + context.draw(_layer!, in: rect) case .linearGradient: diff --git a/Charts/Classes/Utils/ChartPlatform.swift b/Charts/Classes/Utils/ChartPlatform.swift index 7785e1375c..0ad387e6fe 100644 --- a/Charts/Classes/Utils/ChartPlatform.swift +++ b/Charts/Classes/Utils/ChartPlatform.swift @@ -180,12 +180,12 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple UIGraphicsEndImageContext() } - func NSUIImagePNGRepresentation(image: NSUIImage) -> NSData? + func NSUIImagePNGRepresentation(image: NSUIImage) -> Data? { return UIImagePNGRepresentation(image) } - func NSUIImageJPEGRepresentation(image: NSUIImage, _ quality: CGFloat = 0.8) -> NSData? + func NSUIImageJPEGRepresentation(image: NSUIImage, _ quality: CGFloat = 0.8) -> Data? { return UIImageJPEGRepresentation(image, quality) } diff --git a/Charts/Classes/Utils/ChartSelectionDetail.swift b/Charts/Classes/Utils/ChartSelectionDetail.swift index 4151d830f8..253d572e25 100644 --- a/Charts/Classes/Utils/ChartSelectionDetail.swift +++ b/Charts/Classes/Utils/ChartSelectionDetail.swift @@ -75,14 +75,17 @@ public class ChartSelectionDetail: NSObject // MARK: NSObject - public override func isEqual(_ object: AnyObject?) -> Bool + public override func isEqual(_ object: Any?) -> Bool { + + let object = object as? AnyObject + if (object === nil) { return false } - if (!object!.isKind(of: self.dynamicType)) + if (!object!.isKind(of: type(of: self))) { return false } @@ -113,7 +116,7 @@ public func ==(lhs: ChartSelectionDetail, rhs: ChartSelectionDetail) -> Bool return true } - if (!lhs.isKind(of: rhs.dynamicType)) + if (!lhs.isKind(of: type(of: rhs))) { return false } diff --git a/Charts/Classes/Utils/ChartUtils.swift b/Charts/Classes/Utils/ChartUtils.swift index 169769ae58..db44c3e88b 100755 --- a/Charts/Classes/Utils/ChartUtils.swift +++ b/Charts/Classes/Utils/ChartUtils.swift @@ -394,7 +394,7 @@ public class ChartUtils } else { - newArray.append(val!) + newArray.append(val as! NSObject) } } return newArray