Skip to content

Commit

Permalink
Merge pull request ChartsOrg#4829 from FelixHerrmann/master
Browse files Browse the repository at this point in the history
Fix chart only drawing first entry
  • Loading branch information
pmairoldi authored Aug 29, 2022
2 parents 4ed3db5 + 2095115 commit 2c77b2b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Source/Charts/Data/Implementations/Standard/ChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 2c77b2b

Please sign in to comment.