Skip to content

Commit

Permalink
perf(ScatterPlot): slighly faster rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Jan 21, 2025
1 parent d0df2f4 commit d760cd9
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions vue-components/src/components/ScatterPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,24 @@ 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([])
scatterPlot.setSequences(sequences.value)
}
})
watch(
[
scatterPlotRef,
dataset,
selectedPoints,
highlightedPoint,
colorMap,
hideSourcePoints,
sequences
],
() => scatterPlot?.render(dataset.value)
)
onMounted(() => {
if (!plotContainer.value) {
return
Expand All @@ -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])
Expand Down

0 comments on commit d760cd9

Please sign in to comment.