Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calc visible points on update #10467 #10523

Merged
merged 1 commit into from Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/controllers/controller.line.js
Expand Up @@ -153,8 +153,8 @@ function getStartAndCountOfVisiblePoints(meta, points, animationsDisabled) {
}
if (maxDefined) {
count = _limitValue(Math.max(
_lookupByKey(_parsed, iScale.axis, max).hi + 1,
animationsDisabled ? 0 : _lookupByKey(points, axis, iScale.getPixelForValue(max)).hi + 1),
_lookupByKey(_parsed, iScale.axis, max, true).hi + 1,
animationsDisabled ? 0 : _lookupByKey(points, axis, iScale.getPixelForValue(max), true).hi + 1),
start, pointCount) - start;
} else {
count = pointCount - start;
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/helpers.collection.js
Expand Up @@ -30,10 +30,13 @@ export function _lookup(table, value, cmp) {
* @param {array} table - the table search. must be sorted!
* @param {string} key - property name for the value in each entry
* @param {number} value - value to find
* @param {boolean} [last] - lookup last index
* @private
*/
export const _lookupByKey = (table, key, value) =>
_lookup(table, value, index => table[index][key] < value);
export const _lookupByKey = (table, key, value, last) =>
_lookup(table, value, last
? index => table[index][key] <= value
: index => table[index][key] < value);

/**
* Reverse binary search
Expand Down
47 changes: 47 additions & 0 deletions test/specs/controller.line.tests.js
Expand Up @@ -1016,4 +1016,51 @@ describe('Chart.controllers.line', function() {
expect(point.stop).toBe(i === 3);
}
});

it('should correctly calc visible points on update', async() => {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
data: [
{x: 10, y: 20},
{x: 15, y: 19},
]
}],
},
options: {
scales: {
y: {
type: 'linear',
min: 0,
max: 25,
},
x: {
type: 'linear',
min: 0,
max: 50
},
}
}
});

chart.data.datasets[0].data = [
{x: 10, y: 20},
{x: 15, y: 19},
{x: 17, y: 12},
{x: 50, y: 9},
{x: 50, y: 9},
{x: 50, y: 9},
];
chart.update();

var point = chart.getDatasetMeta(0).data[0];
var event = {
type: 'mousemove',
native: true,
...point
};

chart._handleEvent(event, false, true);
}, 500);
});