State timeline: defer quadtree construction until first mousemove (#34949)

This commit is contained in:
Leon Sorokin 2021-05-29 14:01:58 -05:00 committed by GitHub
parent 50775651dd
commit 13768da417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -143,7 +143,7 @@ export function getConfig(opts: TimelineCoreOptions) {
const fieldConfig = getFieldConfig(seriesIdx);
const fillColor = getFillColor(fieldConfig, valueColor);
const boxRect = (boxRectsBySeries[seriesIdx][valueIdx] = {
boxRectsBySeries[seriesIdx][valueIdx] = {
x: round(left - xOff),
y: round(top - yOff),
w: boxWidth,
@ -152,9 +152,7 @@ export function getConfig(opts: TimelineCoreOptions) {
didx: valueIdx,
// for computing label contrast
fillColor,
});
qt.add(boxRect);
};
if (discrete) {
let fillStyle = fillColor;
@ -429,6 +427,16 @@ export function getConfig(opts: TimelineCoreOptions) {
const setCursor = (u: uPlot) => {
let cx = round(u.cursor!.left! * pxRatio);
let cy = round(u.cursor!.top! * pxRatio);
// if quadtree is empty, fill it
if (!qt.o.length && qt.q == null) {
for (const seriesRects of boxRectsBySeries) {
for (const rect of seriesRects) {
rect && qt.add(rect);
}
}
}
doHover(cx, cy);
};