From 044f0f622e4ed5b8ff8d849c8721466998dd45da Mon Sep 17 00:00:00 2001 From: Gavyn Riebau Date: Tue, 23 Mar 2021 07:41:01 +0800 Subject: [PATCH] Fix for issue where data points are not highlighted The `entriesForXValue` func finds the data entries for a given x-axis value. It used an optimization where it would do a binary search to find the first matching entry then take a slice of data stopping when no more entries matched. The optimization broke the highlight feature because data points that should have matched were not matching resulting in no entries being returned. This commit replaces the optimized code with a call to `.filter` which will be slower for larger data sets but correctly returns filtered entries. --- .../Charts/Data/Implementations/Standard/ChartDataSet.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift index 703c0abe72..5fdb3068c5 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift @@ -196,10 +196,7 @@ 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) + return self.filter { $0.x == xValue } } /// - Parameters: