File tree Expand file tree Collapse file tree
MPChartLib/src/main/java/com/github/mikephil/charting/data Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -298,13 +298,28 @@ public int getEntryIndex(float xValue, Rounding rounding) {
298298 while (low < high ) {
299299 int m = (low + high ) / 2 ;
300300
301- float d1 = Math .abs (mValues .get (m ).getX () - xValue );
302- float d2 = Math .abs (mValues .get (m + 1 ).getX () - xValue );
301+ final float d1 = mValues .get (m ).getX () - xValue ,
302+ d2 = mValues .get (m + 1 ).getX () - xValue ,
303+ ad1 = Math .abs (d1 ), ad2 = Math .abs (d2 );
303304
304- if (d2 <= d1 ) {
305+ if (ad2 < ad1 ) {
306+ // [m + 1] is closer to xValue
307+ // Search in an higher place
305308 low = m + 1 ;
306- } else {
309+ } else if (ad1 < ad2 ) {
310+ // [m] is closer to xValue
311+ // Search in a lower place
307312 high = m ;
313+ } else {
314+ // We have multiple sequential x-value with same distance
315+
316+ if (d1 >= 0.0 ) {
317+ // Search in a lower place
318+ high = m ;
319+ } else if (d1 < 0.0 ) {
320+ // Search in an higher place
321+ low = m + 1 ;
322+ }
308323 }
309324 }
310325
You can’t perform that action at this time.
0 commit comments