const {spanGaps, segment} = this.options;
const maxGapLength = isNumber(spanGaps) ? spanGaps : Number.POSITIVE_INFINITY;
const directUpdate = this.chart._animationsDisabled || reset || mode === 'none';
+ const end = start + count;
+ const pointsCount = points.length;
let prevParsed = start > 0 && this.getParsed(start - 1);
- for (let i = start; i < start + count; ++i) {
+ for (let i = 0; i < pointsCount; ++i) {
const point = points[i];
- const parsed = this.getParsed(i);
const properties = directUpdate ? point : {};
+
+ if (i < start || i >= end) {
+ properties.skip = true;
+ continue;
+ }
+
+ const parsed = this.getParsed(i);
const nullData = isNullOrUndef(parsed[vAxis]);
const iPixel = properties[iAxis] = iScale.getPixelForValue(parsed[iAxis], i);
const vPixel = properties[vAxis] = reset || nullData ? vScale.getBasePixel() : vScale.getPixelForValue(_stacked ? this.applyStack(vScale, parsed, _stacked) : parsed[vAxis], i);
*/
export const _lookupByKey = (table, key, value, last) =>
_lookup(table, value, last
- ? index => table[index][key] <= value
+ ? index => {
+ const ti = table[index][key];
+ return ti < value || ti === value && table[index + 1][key] === value;
+ }
: index => table[index][key] < value);
/**
expect(_lookupByKey(data, 'x', 9)).toEqual({lo: 2, hi: 3});
});
+ it('Should do binary search by key with last', () => {
+ expect(_lookupByKey([{x: 0}, {x: 2}, {x: 6}, {x: 9}], 'x', 25, true)).toEqual({lo: 2, hi: 3});
+ expect(_lookupByKey([{x: 0}, {x: 2}, {x: 9}, {x: 9}], 'x', 25, true)).toEqual({lo: 2, hi: 3});
+ expect(_lookupByKey([{x: 0}, {x: 2}, {x: 9}, {x: 9}, {x: 22}], 'x', 25, true)).toEqual({lo: 3, hi: 4});
+ expect(_lookupByKey([{x: 0}, {x: 2}, {x: 25}, {x: 28}], 'x', 25, true)).toEqual({lo: 1, hi: 2});
+ expect(_lookupByKey([{x: 0}, {x: 2}, {x: 25}, {x: 25}], 'x', 25, true)).toEqual({lo: 2, hi: 3});
+ expect(_lookupByKey([{x: 0}, {x: 2}, {x: 25}, {x: 25}, {x: 28}], 'x', 25, true)).toEqual({lo: 2, hi: 3});
+ expect(_lookupByKey([{x: 0}, {x: 2}, {x: 25}, {x: 25}, {x: 25}, {x: 28}, {x: 29}], 'x', 25, true)).toEqual({lo: 3, hi: 4});
+ });
+
it('Should do reverse binary search by key', function() {
const data = [{x: 10}, {x: 7}, {x: 3}, {x: 0}];
expect(_rlookupByKey(data, 'x', 0)).toEqual({lo: 2, hi: 3});