Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes markers not appearing as expected (#4645) and entriesForXValue not finding match (#4668) #4731

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Source/Charts/Data/Implementations/Standard/ChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ open class ChartDataSet: ChartBaseDataSet
/// An empty array if no Entry object at that index.
open override func entriesForXValue(_ xValue: Double) -> [ChartDataEntry]
{
let match: (ChartDataEntry) -> Bool = { $0.x == xValue }
let i = partitioningIndex(where: match)
guard i < endIndex else { return [] }
return self[i...].prefix(while: match)
let i = partitioningIndex(where: { $0.x >= xValue })
guard i < endIndex, self[i].x == xValue else { return [] }
return self[i...].prefix { $0.x == xValue }
}

/// - Parameters:
Expand All @@ -216,7 +215,12 @@ open class ChartDataSet: ChartBaseDataSet
var closest = partitioningIndex { $0.x >= xValue }
guard closest < endIndex else { return -1 }

let closestXValue = self[closest].x
// because our partition is >=, our closest match may be behind us
var closestXValue = self[closest].x
if closest > startIndex && abs(closestXValue - xValue) > abs(xValue - self[index(before: closest)].x) {
formIndex(before: &closest)
closestXValue = self[closest].x
}

switch rounding {
case .up:
Expand Down