From c28880a196d1835548b1d515f93e257361d3826e Mon Sep 17 00:00:00 2001 From: Jacob Christie Date: Mon, 13 Nov 2017 21:42:59 -0800 Subject: [PATCH 1/3] Minor cleanup to Highlighter types --- Source/Charts/Highlight/BarHighlighter.swift | 78 ++++++++----------- .../Charts/Highlight/ChartHighlighter.swift | 45 ++++------- .../Highlight/CombinedHighlighter.swift | 51 +++++------- .../Highlight/HorizontalBarHighlighter.swift | 38 ++++----- Source/Charts/Highlight/PieHighlighter.swift | 8 +- .../Highlight/PieRadarHighlighter.swift | 38 +++++---- .../Charts/Highlight/RadarHighlighter.swift | 13 ++-- 7 files changed, 110 insertions(+), 161 deletions(-) diff --git a/Source/Charts/Highlight/BarHighlighter.swift b/Source/Charts/Highlight/BarHighlighter.swift index ff115fe147..046e858567 100644 --- a/Source/Charts/Highlight/BarHighlighter.swift +++ b/Source/Charts/Highlight/BarHighlighter.swift @@ -17,30 +17,22 @@ open class BarHighlighter: ChartHighlighter { open override func getHighlight(x: CGFloat, y: CGFloat) -> Highlight? { - let high = super.getHighlight(x: x, y: y) - - if high == nil - { - return nil - } + guard let barData = (self.chart as? BarChartDataProvider)?.barData, + let high = super.getHighlight(x: x, y: y) + else { return nil } - if let barData = (self.chart as? BarChartDataProvider)?.barData + let pos = getValsForTouch(x: x, y: y) + + if let set = barData.getDataSetByIndex(high.dataSetIndex) as? IBarChartDataSet, + set.isStacked { - let pos = getValsForTouch(x: x, y: y) - - if - let set = barData.getDataSetByIndex(high!.dataSetIndex) as? IBarChartDataSet, - set.isStacked - { - return getStackedHighlight(high: high!, - set: set, - xValue: Double(pos.x), - yValue: Double(pos.y)) - } - + return getStackedHighlight(high: high, + set: set, + xValue: Double(pos.x), + yValue: Double(pos.y)) + } else { return high } - return nil } internal override func getDistance(x1: CGFloat, y1: CGFloat, x2: CGFloat, y2: CGFloat) -> CGFloat @@ -75,25 +67,22 @@ open class BarHighlighter: ChartHighlighter return high } - if let ranges = entry.ranges, + guard let ranges = entry.ranges, ranges.count > 0 - { - let stackIndex = getClosestStackIndex(ranges: ranges, value: yValue) - - let pixel = chart - .getTransformer(forAxis: set.axisDependency) - .pixelForValues(x: high.x, y: ranges[stackIndex].to) - - return Highlight(x: entry.x, - y: entry.y, - xPx: pixel.x, - yPx: pixel.y, - dataSetIndex: high.dataSetIndex, - stackIndex: stackIndex, - axis: high.axis) - } - - return nil + else { return nil } + + let stackIndex = getClosestStackIndex(ranges: ranges, value: yValue) + let pixel = chart + .getTransformer(forAxis: set.axisDependency) + .pixelForValues(x: high.x, y: ranges[stackIndex].to) + + return Highlight(x: entry.x, + y: entry.y, + xPx: pixel.x, + yPx: pixel.y, + dataSetIndex: high.dataSetIndex, + stackIndex: stackIndex, + axis: high.axis) } /// - returns: The index of the closest value inside the values array / ranges (stacked barchart) to the value given as a parameter. @@ -102,14 +91,11 @@ open class BarHighlighter: ChartHighlighter /// - returns: @objc open func getClosestStackIndex(ranges: [Range]?, value: Double) -> Int { - if ranges == nil - { - return 0 - } - + guard let ranges = ranges else { return 0 } + var stackIndex = 0 - for range in ranges! + for range in ranges { if range.contains(value) { @@ -121,8 +107,8 @@ open class BarHighlighter: ChartHighlighter } } - let length = max(ranges!.count - 1, 0) + let length = max(ranges.count - 1, 0) - return (value > ranges![length].to) ? length : 0 + return (value > ranges[length].to) ? length : 0 } } diff --git a/Source/Charts/Highlight/ChartHighlighter.swift b/Source/Charts/Highlight/ChartHighlighter.swift index d8e1d0bc4d..3644206b9d 100644 --- a/Source/Charts/Highlight/ChartHighlighter.swift +++ b/Source/Charts/Highlight/ChartHighlighter.swift @@ -48,19 +48,15 @@ open class ChartHighlighter : NSObject, IHighlighter /// - returns: @objc open func getHighlight(xValue xVal: Double, x: CGFloat, y: CGFloat) -> Highlight? { - guard let chart = chart - else { return nil } + guard let chart = chart else { return nil } let closestValues = getHighlights(xValue: xVal, x: x, y: y) - if closestValues.isEmpty - { - return nil - } + guard !closestValues.isEmpty else { return nil } - let leftAxisMinDist = getMinimumDistance(closestValues: closestValues, y: y, axis: YAxis.AxisDependency.left) - let rightAxisMinDist = getMinimumDistance(closestValues: closestValues, y: y, axis: YAxis.AxisDependency.right) + let leftAxisMinDist = getMinimumDistance(closestValues: closestValues, y: y, axis: .left) + let rightAxisMinDist = getMinimumDistance(closestValues: closestValues, y: y, axis: .right) - let axis = leftAxisMinDist < rightAxisMinDist ? YAxis.AxisDependency.left : YAxis.AxisDependency.right + let axis = leftAxisMinDist < rightAxisMinDist ? YAxis.AxisDependency.left : .right let detail = closestSelectionDetailByPixel(closestValues: closestValues, x: x, y: y, axis: axis, minSelectionDistance: chart.maxHighlightDistance) @@ -77,21 +73,15 @@ open class ChartHighlighter : NSObject, IHighlighter { var vals = [Highlight]() - guard let - data = self.data - else { return vals } + guard let data = self.data else { return vals } for i in 0 ..< data.dataSetCount { - guard let dataSet = data.getDataSetByIndex(i) + guard let dataSet = data.getDataSetByIndex(i), + dataSet.isHighlightEnabled // don't include datasets that cannot be highlighted else { continue } - // don't include datasets that cannot be highlighted - if !dataSet.isHighlightEnabled - { - continue - } - + // extract all y-values from all DataSets at the given x-value. // some datasets (i.e bubble charts) make sense to have multiple values for an x-value. We'll have to find a way to handle that later on. It's more complicated now when x-indices are floating point. @@ -114,13 +104,10 @@ open class ChartHighlighter : NSObject, IHighlighter else { return highlights } var entries = set.entriesForXValue(xValue) - if entries.count == 0 + if entries.count == 0, let closest = set.entryForXValue(xValue, closestToY: .nan, rounding: rounding) { // Try to find closest x-value and take all entries for that x-value - if let closest = set.entryForXValue(xValue, closestToY: Double.nan, rounding: rounding) - { - entries = set.entriesForXValue(closest.x) - } + entries = set.entriesForXValue(closest.x) } for e in entries @@ -146,14 +133,12 @@ open class ChartHighlighter : NSObject, IHighlighter var distance = minSelectionDistance var closest: Highlight? - for i in 0 ..< closestValues.count + for high in closestValues { - let high = closestValues[i] - if axis == nil || high.axis == axis { let cDistance = getDistance(x1: x, y1: y, x2: high.xPx, y2: high.yPx) - + if cDistance < distance { closest = high @@ -173,10 +158,8 @@ open class ChartHighlighter : NSObject, IHighlighter { var distance = CGFloat.greatestFiniteMagnitude - for i in 0 ..< closestValues.count + for high in closestValues { - let high = closestValues[i] - if high.axis == axis { let tempDistance = abs(getHighlightPos(high: high) - y) diff --git a/Source/Charts/Highlight/CombinedHighlighter.swift b/Source/Charts/Highlight/CombinedHighlighter.swift index 86e841993c..7279570978 100644 --- a/Source/Charts/Highlight/CombinedHighlighter.swift +++ b/Source/Charts/Highlight/CombinedHighlighter.swift @@ -30,46 +30,37 @@ open class CombinedHighlighter: ChartHighlighter { var vals = [Highlight]() - guard let chart = self.chart as? CombinedChartDataProvider + guard let chart = self.chart as? CombinedChartDataProvider, + let dataObjects = chart.combinedData?.allData else { return vals } - if let dataObjects = chart.combinedData?.allData + for i in 0.. Highlight? { - if let barData = self.chart?.data as? BarChartData + guard let barData = self.chart?.data as? BarChartData else { return nil } + let pos = getValsForTouch(x: y, y: x) + + guard let high = getHighlight(xValue: Double(pos.y), x: y, y: x) + else { return nil } + + if let set = barData.getDataSetByIndex(high.dataSetIndex) as? IBarChartDataSet, + set.isStacked { - let pos = getValsForTouch(x: y, y: x) - - guard let high = getHighlight(xValue: Double(pos.y), x: y, y: x) - else { return nil } - - if let set = barData.getDataSetByIndex(high.dataSetIndex) as? IBarChartDataSet, - set.isStacked - { - return getStackedHighlight(high: high, - set: set, - xValue: Double(pos.y), - yValue: Double(pos.x)) - } - - return high + return getStackedHighlight(high: high, + set: set, + xValue: Double(pos.y), + yValue: Double(pos.x)) } - return nil + + return high } internal override func buildHighlights( @@ -50,13 +47,10 @@ open class HorizontalBarHighlighter: BarHighlighter else { return highlights } var entries = set.entriesForXValue(xValue) - if entries.count == 0 + if entries.count == 0, let closest = set.entryForXValue(xValue, closestToY: .nan, rounding: rounding) { // Try to find closest x-value and take all entries for that x-value - if let closest = set.entryForXValue(xValue, closestToY: Double.nan, rounding: rounding) - { - entries = set.entriesForXValue(closest.x) - } + entries = set.entriesForXValue(closest.x) } for e in entries diff --git a/Source/Charts/Highlight/PieHighlighter.swift b/Source/Charts/Highlight/PieHighlighter.swift index 2d0a18534e..4ada042328 100644 --- a/Source/Charts/Highlight/PieHighlighter.swift +++ b/Source/Charts/Highlight/PieHighlighter.swift @@ -17,12 +17,10 @@ open class PieHighlighter: PieRadarHighlighter { open override func closestHighlight(index: Int, x: CGFloat, y: CGFloat) -> Highlight? { - guard let set = chart?.data?.dataSets[0] + guard let set = chart?.data?.dataSets[0], + let entry = set.entryForIndex(index) else { return nil } - - guard let entry = set.entryForIndex(index) - else { return nil } - + return Highlight(x: Double(index), y: entry.y, xPx: x, yPx: y, dataSetIndex: 0, axis: set.axisDependency) } } diff --git a/Source/Charts/Highlight/PieRadarHighlighter.swift b/Source/Charts/Highlight/PieRadarHighlighter.swift index abcea4aca8..c5398c71d2 100644 --- a/Source/Charts/Highlight/PieRadarHighlighter.swift +++ b/Source/Charts/Highlight/PieRadarHighlighter.swift @@ -23,32 +23,30 @@ open class PieRadarHighlighter: ChartHighlighter let touchDistanceToCenter = chart.distanceToCenter(x: x, y: y) // check if a slice was touched - if touchDistanceToCenter > chart.radius - { + guard touchDistanceToCenter <= chart.radius else { // if no slice was touched, highlight nothing return nil } + + var angle = chart.angleForPoint(x: x ,y: y) + + if chart is PieChartView + { + angle /= CGFloat(chart.chartAnimator.phaseY) + } + + let index = chart.indexForAngle(angle) + + // check if the index could be found + if index < 0 || index >= chart.data?.maxEntryCountSet?.entryCount ?? 0 + { + return nil + } else { - var angle = chart.angleForPoint(x: x ,y: y) - - if chart is PieChartView - { - angle /= CGFloat(chart.chartAnimator.phaseY) - } - - let index = chart.indexForAngle(angle) - - // check if the index could be found - if index < 0 || index >= chart.data?.maxEntryCountSet?.entryCount ?? 0 - { - return nil - } - else - { - return closestHighlight(index: index, x: x, y: y) - } + return closestHighlight(index: index, x: x, y: y) } + } /// - returns: The closest Highlight object of the given objects based on the touch position inside the chart. diff --git a/Source/Charts/Highlight/RadarHighlighter.swift b/Source/Charts/Highlight/RadarHighlighter.swift index 6e25ac20d1..741fe17d27 100644 --- a/Source/Charts/Highlight/RadarHighlighter.swift +++ b/Source/Charts/Highlight/RadarHighlighter.swift @@ -48,20 +48,19 @@ open class RadarHighlighter: PieRadarHighlighter { var vals = [Highlight]() - guard let chart = self.chart as? RadarChartView + guard let chart = self.chart as? RadarChartView, + let chartData = chart.data else { return vals } let phaseX = chart.chartAnimator.phaseX let phaseY = chart.chartAnimator.phaseY let sliceangle = chart.sliceAngle let factor = chart.factor - - for i in 0..<(chart.data?.dataSetCount ?? 0) + + for i in chartData.dataSets.indices { - guard let dataSet = chart.data?.getDataSetByIndex(i) - else { continue } - - guard let entry = dataSet.entryForIndex(index) + guard let dataSet = chartData.getDataSetByIndex(i), + let entry = dataSet.entryForIndex(index) else { continue } let y = (entry.y - chart.chartYMin) From df3b8526a2cc8aec09b73b41e51b33ab3f0791d0 Mon Sep 17 00:00:00 2001 From: Jacob Christie Date: Wed, 15 Nov 2017 00:03:23 -0800 Subject: [PATCH 2/3] Fixes for PR --- Source/Charts/Highlight/BarHighlighter.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Charts/Highlight/BarHighlighter.swift b/Source/Charts/Highlight/BarHighlighter.swift index 046e858567..e9747622d5 100644 --- a/Source/Charts/Highlight/BarHighlighter.swift +++ b/Source/Charts/Highlight/BarHighlighter.swift @@ -17,7 +17,8 @@ open class BarHighlighter: ChartHighlighter { open override func getHighlight(x: CGFloat, y: CGFloat) -> Highlight? { - guard let barData = (self.chart as? BarChartDataProvider)?.barData, + guard + let barData = (self.chart as? BarChartDataProvider)?.barData, let high = super.getHighlight(x: x, y: y) else { return nil } @@ -67,7 +68,8 @@ open class BarHighlighter: ChartHighlighter return high } - guard let ranges = entry.ranges, + guard + let ranges = entry.ranges, ranges.count > 0 else { return nil } From fa1297a46f065650e0f08a41543ce0a8a4f357cc Mon Sep 17 00:00:00 2001 From: Jacob Christie Date: Sat, 6 Jan 2018 09:34:43 -0400 Subject: [PATCH 3/3] Pulled master and updated code style --- Source/Charts/Highlight/BarHighlighter.swift | 4 +++- .../Charts/Highlight/ChartHighlighter.swift | 20 +++++++++---------- .../Highlight/CombinedHighlighter.swift | 3 ++- Source/Charts/Highlight/Highlight.swift | 1 - .../Highlight/HorizontalBarHighlighter.swift | 8 +++----- Source/Charts/Highlight/PieHighlighter.swift | 3 ++- .../Highlight/PieRadarHighlighter.swift | 6 +++--- .../Charts/Highlight/RadarHighlighter.swift | 16 ++++++++------- 8 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Source/Charts/Highlight/BarHighlighter.swift b/Source/Charts/Highlight/BarHighlighter.swift index e9747622d5..2bb81a2a33 100644 --- a/Source/Charts/Highlight/BarHighlighter.swift +++ b/Source/Charts/Highlight/BarHighlighter.swift @@ -31,7 +31,9 @@ open class BarHighlighter: ChartHighlighter set: set, xValue: Double(pos.x), yValue: Double(pos.y)) - } else { + } + else + { return high } } diff --git a/Source/Charts/Highlight/ChartHighlighter.swift b/Source/Charts/Highlight/ChartHighlighter.swift index 42eaae12d8..3fe679f20d 100644 --- a/Source/Charts/Highlight/ChartHighlighter.swift +++ b/Source/Charts/Highlight/ChartHighlighter.swift @@ -25,7 +25,6 @@ open class ChartHighlighter : NSObject, IHighlighter open func getHighlight(x: CGFloat, y: CGFloat) -> Highlight? { let xVal = Double(getValsForTouch(x: x, y: y).x) - return getHighlight(xValue: xVal, x: x, y: y) } @@ -34,11 +33,10 @@ open class ChartHighlighter : NSObject, IHighlighter /// - returns: @objc open func getValsForTouch(x: CGFloat, y: CGFloat) -> CGPoint { - guard let chart = self.chart as? BarLineScatterCandleBubbleChartDataProvider - else { return CGPoint.zero } + guard let chart = self.chart as? BarLineScatterCandleBubbleChartDataProvider else { return .zero } // take any transformer to determine the values - return chart.getTransformer(forAxis: YAxis.AxisDependency.left).valueForTouchPoint(x: x, y: y) + return chart.getTransformer(forAxis: .left).valueForTouchPoint(x: x, y: y) } /// - returns: The corresponding ChartHighlight for a given x-value and xy-touch position in pixels. @@ -56,7 +54,7 @@ open class ChartHighlighter : NSObject, IHighlighter let leftAxisMinDist = getMinimumDistance(closestValues: closestValues, y: y, axis: .left) let rightAxisMinDist = getMinimumDistance(closestValues: closestValues, y: y, axis: .right) - let axis = leftAxisMinDist < rightAxisMinDist ? YAxis.AxisDependency.left : .right + let axis: YAxis.AxisDependency = leftAxisMinDist < rightAxisMinDist ? .left : .right let detail = closestSelectionDetailByPixel(closestValues: closestValues, x: x, y: y, axis: axis, minSelectionDistance: chart.maxHighlightDistance) @@ -77,14 +75,14 @@ open class ChartHighlighter : NSObject, IHighlighter for i in 0 ..< data.dataSetCount { - guard let dataSet = data.getDataSetByIndex(i), + guard + let dataSet = data.getDataSetByIndex(i), dataSet.isHighlightEnabled // don't include datasets that cannot be highlighted else { continue } // extract all y-values from all DataSets at the given x-value. // some datasets (i.e bubble charts) make sense to have multiple values for an x-value. We'll have to find a way to handle that later on. It's more complicated now when x-indices are floating point. - vals.append(contentsOf: buildHighlights(dataSet: dataSet, dataSetIndex: i, xValue: xValue, rounding: .closest)) } @@ -100,8 +98,7 @@ open class ChartHighlighter : NSObject, IHighlighter { var highlights = [Highlight]() - guard let chart = self.chart as? BarLineScatterCandleBubbleChartDataProvider - else { return highlights } + guard let chart = self.chart as? BarLineScatterCandleBubbleChartDataProvider else { return highlights } var entries = set.entriesForXValue(xValue) if entries.count == 0, let closest = set.entryForXValue(xValue, closestToY: .nan, rounding: rounding) @@ -113,8 +110,9 @@ open class ChartHighlighter : NSObject, IHighlighter for e in entries { let px = chart.getTransformer(forAxis: set.axisDependency).pixelForValues(x: e.x, y: e.y) - - highlights.append(Highlight(x: e.x, y: e.y, xPx: px.x, yPx: px.y, dataSetIndex: dataSetIndex, axis: set.axisDependency)) + + let highlight = Highlight(x: e.x, y: e.y, xPx: px.x, yPx: px.y, dataSetIndex: dataSetIndex, axis: set.axisDependency) + highlights.append(highlight) } return highlights diff --git a/Source/Charts/Highlight/CombinedHighlighter.swift b/Source/Charts/Highlight/CombinedHighlighter.swift index c9eb0d501a..7053df09d3 100644 --- a/Source/Charts/Highlight/CombinedHighlighter.swift +++ b/Source/Charts/Highlight/CombinedHighlighter.swift @@ -30,7 +30,8 @@ open class CombinedHighlighter: ChartHighlighter { var vals = [Highlight]() - guard let chart = self.chart as? CombinedChartDataProvider, + guard + let chart = self.chart as? CombinedChartDataProvider, let dataObjects = chart.combinedData?.allData else { return vals } diff --git a/Source/Charts/Highlight/Highlight.swift b/Source/Charts/Highlight/Highlight.swift index 5c3c9df3a4..2205db1131 100644 --- a/Source/Charts/Highlight/Highlight.swift +++ b/Source/Charts/Highlight/Highlight.swift @@ -192,6 +192,5 @@ extension Highlight /*: Equatable*/ { && dataIndex == object.dataIndex && _dataSetIndex == object._dataSetIndex && _stackIndex == object._stackIndex - } } diff --git a/Source/Charts/Highlight/HorizontalBarHighlighter.swift b/Source/Charts/Highlight/HorizontalBarHighlighter.swift index 3269886be6..c3b6e2867b 100644 --- a/Source/Charts/Highlight/HorizontalBarHighlighter.swift +++ b/Source/Charts/Highlight/HorizontalBarHighlighter.swift @@ -18,10 +18,9 @@ open class HorizontalBarHighlighter: BarHighlighter open override func getHighlight(x: CGFloat, y: CGFloat) -> Highlight? { guard let barData = self.chart?.data as? BarChartData else { return nil } - let pos = getValsForTouch(x: y, y: x) - guard let high = getHighlight(xValue: Double(pos.y), x: y, y: x) - else { return nil } + let pos = getValsForTouch(x: y, y: x) + guard let high = getHighlight(xValue: Double(pos.y), x: y, y: x) else { return nil } if let set = barData.getDataSetByIndex(high.dataSetIndex) as? IBarChartDataSet, set.isStacked @@ -43,8 +42,7 @@ open class HorizontalBarHighlighter: BarHighlighter { var highlights = [Highlight]() - guard let chart = self.chart as? BarLineScatterCandleBubbleChartDataProvider - else { return highlights } + guard let chart = self.chart as? BarLineScatterCandleBubbleChartDataProvider else { return highlights } var entries = set.entriesForXValue(xValue) if entries.count == 0, let closest = set.entryForXValue(xValue, closestToY: .nan, rounding: rounding) diff --git a/Source/Charts/Highlight/PieHighlighter.swift b/Source/Charts/Highlight/PieHighlighter.swift index 4ada042328..54bb3d7b83 100644 --- a/Source/Charts/Highlight/PieHighlighter.swift +++ b/Source/Charts/Highlight/PieHighlighter.swift @@ -17,7 +17,8 @@ open class PieHighlighter: PieRadarHighlighter { open override func closestHighlight(index: Int, x: CGFloat, y: CGFloat) -> Highlight? { - guard let set = chart?.data?.dataSets[0], + guard + let set = chart?.data?.dataSets[0], let entry = set.entryForIndex(index) else { return nil } diff --git a/Source/Charts/Highlight/PieRadarHighlighter.swift b/Source/Charts/Highlight/PieRadarHighlighter.swift index c5398c71d2..ec77e72f5b 100644 --- a/Source/Charts/Highlight/PieRadarHighlighter.swift +++ b/Source/Charts/Highlight/PieRadarHighlighter.swift @@ -17,13 +17,13 @@ open class PieRadarHighlighter: ChartHighlighter { open override func getHighlight(x: CGFloat, y: CGFloat) -> Highlight? { - guard let chart = self.chart as? PieRadarChartViewBase - else { return nil } + guard let chart = self.chart as? PieRadarChartViewBase else { return nil } let touchDistanceToCenter = chart.distanceToCenter(x: x, y: y) // check if a slice was touched - guard touchDistanceToCenter <= chart.radius else { + guard touchDistanceToCenter <= chart.radius else + { // if no slice was touched, highlight nothing return nil } diff --git a/Source/Charts/Highlight/RadarHighlighter.swift b/Source/Charts/Highlight/RadarHighlighter.swift index 3f62619fc8..d54193c2f8 100644 --- a/Source/Charts/Highlight/RadarHighlighter.swift +++ b/Source/Charts/Highlight/RadarHighlighter.swift @@ -17,14 +17,13 @@ open class RadarHighlighter: PieRadarHighlighter { open override func closestHighlight(index: Int, x: CGFloat, y: CGFloat) -> Highlight? { - guard let chart = self.chart as? RadarChartView - else { return nil } + guard let chart = self.chart as? RadarChartView else { return nil } let highlights = getHighlights(forIndex: index) let distanceToCenter = Double(chart.distanceToCenter(x: x, y: y) / chart.factor) - var closest: Highlight? = nil + var closest: Highlight? var distance = Double.greatestFiniteMagnitude for high in highlights @@ -48,7 +47,8 @@ open class RadarHighlighter: PieRadarHighlighter { var vals = [Highlight]() - guard let chart = self.chart as? RadarChartView, + guard + let chart = self.chart as? RadarChartView, let chartData = chart.data else { return vals } @@ -59,7 +59,8 @@ open class RadarHighlighter: PieRadarHighlighter for i in chartData.dataSets.indices { - guard let dataSet = chartData.getDataSetByIndex(i), + guard + let dataSet = chartData.getDataSetByIndex(i), let entry = dataSet.entryForIndex(index) else { continue } @@ -67,8 +68,9 @@ open class RadarHighlighter: PieRadarHighlighter let p = chart.centerOffsets.moving(distance: CGFloat(y) * factor * CGFloat(phaseY), atAngle: sliceangle * CGFloat(index) * CGFloat(phaseX) + chart.rotationAngle) - - vals.append(Highlight(x: Double(index), y: entry.y, xPx: p.x, yPx: p.y, dataSetIndex: i, axis: dataSet.axisDependency)) + + let highlight = Highlight(x: Double(index), y: entry.y, xPx: p.x, yPx: p.y, dataSetIndex: i, axis: dataSet.axisDependency) + vals.append(highlight) } return vals