diff --git a/Package.resolved b/Package.resolved index 27daaabac3..888ca3b156 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/apple/swift-algorithms", "state": { "branch": null, - "revision": "bb3bafeca0e164ece3403a9de646b7d38c07dd49", - "version": "0.0.2" + "revision": "b14b7f4c528c942f121c8b860b9410b2bf57825e", + "version": "1.0.0" } }, { @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/apple/swift-numerics", "state": { "branch": null, - "revision": "6b24333510e9044cf4716a07bed65eeed6bc6393", - "version": "0.0.8" + "revision": "0a5bc04095a675662cf24757cc0640aa2204253b", + "version": "1.0.2" } } ] diff --git a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift index 70d2da5582..440a737882 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift @@ -217,7 +217,7 @@ open class ChartDataSet: ChartBaseDataSet rounding: ChartDataSetRounding) -> Int { var closest = partitioningIndex { $0.x >= xValue } - guard closest < endIndex else { return rounding == .closest ? (endIndex-1) : -1 } + guard closest < endIndex else { return index(before: endIndex) } var closestXValue = self[closest].x @@ -240,10 +240,13 @@ open class ChartDataSet: ChartBaseDataSet // The closest value in the beginning of this function // `var closest = partitioningIndex { $0.x >= xValue }` // doesn't guarantee closest rounding method - if closest > 0 { + if closest > startIndex { let distanceAfter = abs(self[closest].x - xValue) - let distanceBefore = abs(self[closest-1].x - xValue) - distanceBefore < distanceAfter ? closest -= 1 : () + let distanceBefore = abs(self[index(before: closest)].x - xValue) + if distanceBefore < distanceAfter + { + closest = index(before: closest) + } closestXValue = self[closest].x } }