From d760cd9eac4b170b88112d004867e3b867bf4c41 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 21 Jan 2025 14:07:27 -0500 Subject: [PATCH] perf(ScatterPlot): slighly faster rendering --- vue-components/src/components/ScatterPlot.vue | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/vue-components/src/components/ScatterPlot.vue b/vue-components/src/components/ScatterPlot.vue index 678a15a..e567359 100644 --- a/vue-components/src/components/ScatterPlot.vue +++ b/vue-components/src/components/ScatterPlot.vue @@ -90,13 +90,17 @@ const dataset = computed(() => { return new ScatterGL.Dataset(allPoints) }) +watch([scatterPlotRef, dataset, selectedPoints, highlightedPoint, colorMap, hideSourcePoints], () => + scatterPlot?.render(dataset.value) +) + const sequences = computed(() => { return transformedPointIds.value.map((id) => ({ indices: [idToIndex(id, false), idToIndex(id, true)] })) }) -watchEffect(() => { +watch([sequences, scatterPlotRef], () => { if (scatterPlotRef.value && scatterPlot) { // Due to a bug in scatter-gl we unselect all points before setting the sequences scatterPlot.select([]) @@ -104,19 +108,6 @@ watchEffect(() => { } }) -watch( - [ - scatterPlotRef, - dataset, - selectedPoints, - highlightedPoint, - colorMap, - hideSourcePoints, - sequences - ], - () => scatterPlot?.render(dataset.value) -) - onMounted(() => { if (!plotContainer.value) { return @@ -135,8 +126,10 @@ onMounted(() => { return `rgba(255,0,0,255)` } - if (isTrans) { - const p0 = props.points[id] + // check p0 because sometimes scatterPlot.setSequences called after props.points updated + // but before scatterPlot gets updated Dataset + const p0 = props.points[id] + if (isTrans && p0) { const p1 = props.transformedPoints[id] const dx = Math.abs(p0[0] - p1[0]) const dy = Math.abs(p0[1] - p1[1])