Skip to content

Commit 948ec51

Browse files
committed
feat: add zoom on Detail
1 parent e73921c commit 948ec51

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

src/routes/Detail.svelte

+38-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import { computePosition, shift, flip, offset } from '@floating-ui/dom';
44
import { base } from '$app/paths';
55
import { summaryLabel } from '$lib/constants';
6-
import { DATA_MIN, DATA_MAX, SCROLL_SPEED } from './Devilstable_DEFAULTS.json';
6+
import {
7+
DATA_MIN,
8+
DATA_MAX,
9+
SCROLL_SPEED,
10+
ZOOM_INCREMENT,
11+
ZOOM_MINIMUM_WINDOW_SIZE
12+
} from './Devilstable_DEFAULTS.json';
713
814
/** @type {{codices: any, width?: number, height?: number,data?: {values: boolean[], label: string}[], selection: {start: number, end: number}}} */
915
let { codices, width = 400, height = 400, data = [], selection = $bindable() } = $props();
@@ -41,18 +47,40 @@
4147
4248
const handleWheel = (/** @type {{ deltaY: any; }} */ event) => {
4349
event.preventDefault();
50+
51+
// Check if the CTRL key is held down during the scroll
52+
const isZooming = event.ctrlKey;
53+
4454
let delta = selection.end - selection.start;
45-
if (event.deltaY > 0) {
46-
// Scroll down
47-
selection.end = Math.min(DATA_MAX, (selection.end += SCROLL_SPEED));
48-
selection.start = selection.end - delta;
49-
console.log('down');
55+
56+
if (isZooming) {
57+
// Zoom in
58+
if (event.deltaY > 0) {
59+
// Zoom out
60+
selection.start = Math.max(DATA_MIN, selection.start - ZOOM_INCREMENT);
61+
selection.end = Math.min(DATA_MAX, selection.end + ZOOM_INCREMENT);
62+
} else {
63+
// Zoom in
64+
if (delta > ZOOM_MINIMUM_WINDOW_SIZE) {
65+
selection.start = Math.max(DATA_MIN, selection.start + ZOOM_INCREMENT);
66+
selection.end = Math.max(
67+
selection.start + ZOOM_MINIMUM_WINDOW_SIZE,
68+
Math.min(DATA_MAX, selection.end - ZOOM_INCREMENT)
69+
);
70+
}
71+
}
5072
} else {
51-
// Scroll up
52-
selection.start = Math.max(DATA_MIN, (selection.start -= SCROLL_SPEED));
53-
selection.end = selection.start + delta;
73+
// Scroll
74+
if (event.deltaY > 0) {
75+
// Scroll down
76+
selection.end = Math.min(DATA_MAX, (selection.end += SCROLL_SPEED));
77+
selection.start = selection.end - delta;
78+
} else {
79+
// Scroll up
80+
selection.start = Math.max(DATA_MIN, (selection.start -= SCROLL_SPEED));
81+
selection.end = selection.start + delta;
82+
}
5483
}
55-
console.log('scrolling', selection.start);
5684
};
5785
5886
const handleMouseMove = (/** @type {{ clientX: any; clientY: any; }} */ event) => {

src/routes/Devilstable_DEFAULTS.json

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
"BRUSH_WINDOW_DEFAULT_START": 1,
55
"BRUSH_WINDOW_DEFAULT_END": 100,
66
"SCROLL_SPEED": 50,
7+
"ZOOM_INCREMENT": 40,
8+
"ZOOM_MINIMUM_WINDOW_SIZE": 50
79
}

0 commit comments

Comments
 (0)