Skip to content

Commit

Permalink
used index APIs instead of raw integers
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixHerrmann committed May 26, 2022
1 parent d768a74 commit 2095115
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 2095115

Please sign in to comment.