Skip to content

Commit

Permalink
Fixed entry searching algorithm to handle sequential same values
Browse files Browse the repository at this point in the history
(Closes #1482)
  • Loading branch information
danielgindi committed Sep 21, 2016
1 parent 95ea820 commit c4480ef
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions Source/Charts/Data/Implementations/Standard/ChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,37 @@ open class ChartDataSet: ChartBaseDataSet
{
let m = (low + high) / 2

let d1 = abs(_values[m].x - xValue)
let d2 = abs(_values[m + 1].x - xValue)
let d1 = _values[m].x - xValue
let d2 = _values[m + 1].x - xValue
let ad1 = abs(d1), ad2 = abs(d2)

if d2 <= d1
if ad2 < ad1
{
// [m + 1] is closer to xValue
// Search in an higher place
low = m + 1
}
else
else if ad1 < ad2
{
// [m] is closer to xValue
// Search in a lower place
high = m
}
else
{
// We have multiple sequential x-value with same distance

if d1 >= 0.0
{
// Search in a lower place
high = m
}
else if d1 < 0.0
{
// Search in an higher place
low = m + 1
}
}
}

if high != -1
Expand Down

0 comments on commit c4480ef

Please sign in to comment.