Skip to content

Commit b77e139

Browse files
committed
Atoms - Slicer - Improve speed of selection drag on large datasets
1 parent fa97867 commit b77e139

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/atoms/Slicer.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,19 @@ const dragThreshold = computed(() => {
322322
return w / (props.max - props.min);
323323
});
324324
325+
const selectionWidth = computed(() => {
326+
const w = zoomWrapper.value.getBoundingClientRect().width - 48;
327+
return w / (props.max - props.min) * currentRange.value;
328+
})
329+
330+
const RA_SPECIAL_MAGIC_NUMBER = ref(2.5);
331+
332+
const flooredDatapointsToWidth = computed(() => {
333+
const w = zoomWrapper.value.getBoundingClientRect().width - 48;
334+
335+
return Math.ceil((props.max - props.min) / ((w - selectionWidth.value) / RA_SPECIAL_MAGIC_NUMBER.value));
336+
})
337+
325338
const startDragging = (event) => {
326339
if (!props.enableSelectionDrag) {
327340
return;
@@ -361,13 +374,13 @@ function updateDragging(currentX) {
361374
if (Math.abs(deltaX) > dragThreshold.value) {
362375
if (deltaX > 0) {
363376
if (Number(endValue.value) + 1 <= props.max) {
364-
const v = Number(endValue.value) + 1;
377+
const v = Math.min(props.max, Number(endValue.value) + flooredDatapointsToWidth.value)
365378
setEndValue(v);
366379
setStartValue(v - currentRange.value);
367380
}
368381
} else {
369382
if (Number(startValue.value) - 1 >= props.min) {
370-
const v = Number(startValue.value) - 1;
383+
const v = Math.max(0, Number(startValue.value) - flooredDatapointsToWidth.value);
371384
setStartValue(v);
372385
setEndValue(v + currentRange.value);
373386
}

0 commit comments

Comments
 (0)