|
3 | 3 | import { computePosition, shift, flip, offset } from '@floating-ui/dom';
|
4 | 4 | import { base } from '$app/paths';
|
5 | 5 | 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'; |
7 | 13 |
|
8 | 14 | /** @type {{codices: any, width?: number, height?: number,data?: {values: boolean[], label: string}[], selection: {start: number, end: number}}} */
|
9 | 15 | let { codices, width = 400, height = 400, data = [], selection = $bindable() } = $props();
|
|
41 | 47 |
|
42 | 48 | const handleWheel = (/** @type {{ deltaY: any; }} */ event) => {
|
43 | 49 | event.preventDefault();
|
| 50 | +
|
| 51 | + // Check if the CTRL key is held down during the scroll |
| 52 | + const isZooming = event.ctrlKey; |
| 53 | +
|
44 | 54 | 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 | + } |
50 | 72 | } 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 | + } |
54 | 83 | }
|
55 |
| - console.log('scrolling', selection.start); |
56 | 84 | };
|
57 | 85 |
|
58 | 86 | const handleMouseMove = (/** @type {{ clientX: any; clientY: any; }} */ event) => {
|
|
0 commit comments