1 | if (dataset.getDomainOrder() == DomainOrder.DESCENDING) {↵ | | 1 | if (dataset.getDomainOrder() == DomainOrder.DESCENDING) {↵
|
2 | // when the x-values are sorted in descending order, the lower↵ | | 2 | // when the x-values are descending↵
|
3 | // bound is found by calculating relative to the xHigh value↵ | | 3 | , the upper bound is found by↵
|
| | | 4 | // comparing against xLow↵
|
4 | int low = 0;↵ | | 5 | int low = 0;↵
|
5 | int high = itemCount - 1;↵ | | 6 | int high = itemCount - 1;↵
|
6 | int mid = (low + high) / 2;↵ | | 7 | int mid = (low + high) / 2;↵
|
7 | double lowValue = dataset.getXValue(series, low);↵ | | 8 | double lowValue = dataset.getXValue(series, low);↵
|
8 | if (lowValue <= xHigh) {↵ | | 9 | if (lowValue < xLow) {↵
|
9 | return low;↵ | | 10 | return low;↵
|
10 | }↵ | | 11 | }↵
|
11 | double highValue = dataset.getXValue(series, high);↵ | | 12 | double highValue = dataset.getXValue(series, high);↵
|
12 | if (highValue > xHigh) {↵ | | 13 | if (highValue >= xLow) {↵
|
13 | return high;↵ | | 14 | return high;↵
|
14 | }↵ | | 15 | }↵
|
15 | while (high - low > 1) {↵ | | 16 | while (high - low > 1) {↵
|
16 | double midV = dataset.getXValue(series, mid);↵ | | 17 | double midV = dataset.getXValue(series, mid);↵
|
17 | if (midV > xHigh) {↵ | | 18 | if (midV >= xLow) {↵
|
18 | low = mid;↵ | | 19 | low = mid;↵
|
19 | }↵ | | 20 | }↵
|
20 | else {↵ | | 21 | else {↵
|
21 | high = mid;↵ | | 22 | high = mid;↵
|
22 | }↵ | | 23 | }↵
|
23 | mid = (low + high) / 2;↵ | | 24 | mid = (low + high) / 2;↵
|
24 | }↵ | | 25 | }↵
|
25 | return mid;↵ | | 26 | return mid;↵
|
26 | }↵ | | 27 | }↵
|
27 | else {↵ | | 28 | else {↵
|
28 | // we don't know anything about the ordering of the x-values,↵ | | 29 | // we don't know anything about the ordering of the x-values,↵
|
29 | // but we can still skip any initial values that fall outside the↵ | | 30 | // but we can still skip any trailing values that fall outside the↵
|
30 | // range...↵ | | 31 | // range...↵
|
31 | int index = 0;↵ | | 32 | int index = itemCount - 1;↵
|
32 | // skip any items that don't need including...↵ | | 33 | // skip any items that don't need including...↵
|
33 | while (index < itemCount && dataset.getXValue(series, index) ↵ | | 34 | while (index >= 0 && dataset.getXValue(series, index) ↵
|
34 | < xLow) {↵ | | 35 | > xHigh) {↵
|
35 | index++;↵ | | 36 | index--;↵
|
36 | }↵ | | 37 | }↵
|
37 | return Math.max(0, index - 1);↵ | | 38 | return Math.min(itemCount - 1, index + 1);↵
|
38 | } | | 39 | }
|