Skip to content

Commit 6883f09

Browse files
authored
Some quick minor fixes to the examples in starlight (#158)
1 parent ccd0fc1 commit 6883f09

File tree

7 files changed

+72
-41
lines changed

7 files changed

+72
-41
lines changed

pnpm-lock.yaml

Lines changed: 32 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default defineConfig({
1313
integrations: [
1414
starlight({
1515
title: 'Vis',
16+
customCss: ['./custom.css'],
1617
social: [{ icon: 'github', label: 'GitHub', href: 'https://github.com/AllenInstitute/vis' }],
1718
sidebar: [
1819
{

site/custom.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:root {
2+
--sl-content-width: 50rem;
3+
}

site/src/content/docs/examples/layers.mdx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,11 @@ import { ClientLayersScript } from '../../../examples/layers/layers-loader.tsx';
77

88
See instructions below the demo app UI for how to run this example.
99

10-
<div style="height: 600px; width 100%;">
11-
<div style="display: flex;">
12-
<div
13-
id="sidebar"
14-
style="width: 15%; height: 100%;"
15-
></div>
16-
<canvas
17-
id="glCanvas"
18-
style="width: 85%; height: 100%;"
19-
/>
20-
</div>
10+
<div style="height: 1000px; width 1000px;">
11+
<div style="display: flex;">
12+
<div id="sidebar" style="width: 200px; height: 1000px;"></div>
13+
<canvas id="glCanvas" style="width: 800px; height: 1000px;" />
14+
</div>
2115
</div>
2216

2317
<ClientLayersScript client:only="react" />

site/src/examples/layers.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box2D, Vec2, type box2D, type vec2 } from '@alleninstitute/vis-geometry';
1+
import { Box2D, CartesianPlane, Vec2, type box2D, type vec2 } from '@alleninstitute/vis-geometry';
22
import { sizeInUnits } from '@alleninstitute/vis-omezarr';
33
import { AsyncDataCache, type FrameLifecycle, logger, type NormalStatus, ReglLayer2D } from '@alleninstitute/vis-core';
44
import pkg from 'file-saver';
@@ -178,7 +178,7 @@ export class Demo {
178178
setPlane(param: AxisAlignedPlane) {
179179
const layer = this.layers[this.selectedLayer];
180180
if (layer && (layer.type === 'volumeSlice' || layer.type === 'volumeGrid')) {
181-
layer.data.plane = param;
181+
layer.data.plane = new CartesianPlane(param);
182182
this.uiChange();
183183
}
184184
}
@@ -701,9 +701,15 @@ export class Demo {
701701
// account for gl-origin vs. screen origin:
702702
this.mouseMove([-e.movementX, -e.movementY], [e.offsetX, canvas.clientHeight - e.offsetY]);
703703
};
704-
canvas.onwheel = (e: WheelEvent) => {
705-
this.zoom(e.deltaY > 0 ? 1.1 : 0.9);
706-
};
704+
canvas.addEventListener(
705+
'wheel',
706+
(e: WheelEvent) => {
707+
this.zoom(e.deltaY > 0 ? 1.1 : 0.9);
708+
e.preventDefault();
709+
},
710+
{ passive: false },
711+
);
712+
707713
window.onkeyup = (e: KeyboardEvent) => {
708714
const layer = this.layers[this.selectedLayer];
709715
if (e.key === ' ') {
@@ -722,6 +728,7 @@ export class Demo {
722728
this.uiChange();
723729
}
724730
}
731+
e.preventDefault();
725732
};
726733
}
727734

site/src/examples/omezarr/omezarr-demo.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { pan, zoom } from '../common/camera';
88
import { RenderServerProvider } from '../common/react/render-server-provider';
99
import { OmezarrViewer } from './omezarr-viewer';
1010
import { SliceView } from './sliceview';
11-
1211
type DemoOption = { value: string; label: string; res: WebResource };
1312

1413
const demoOptions: DemoOption[] = [
@@ -46,7 +45,7 @@ const demoOptions: DemoOption[] = [
4645
},
4746
];
4847

49-
const screenSize: vec2 = [500, 500];
48+
const screenSize: vec2 = [800, 800];
5049

5150
const defaultInterval: Interval = { min: 0, max: 80 };
5251

@@ -136,10 +135,10 @@ export function OmezarrDemo() {
136135
setPlaneIndex((prev) => Math.max(0, Math.min(prev + next, (omezarr?.maxOrthogonal(PLANE_XY) ?? 1) - 1)));
137136
};
138137

139-
const handleZoom = (e: React.WheelEvent<HTMLCanvasElement>) => {
140-
// e.preventDefault();
138+
const handleZoom = (e: WheelEvent) => {
139+
e.preventDefault();
141140
const zoomScale = e.deltaY > 0 ? 1.1 : 0.9;
142-
const v = zoom(view, screenSize, zoomScale, [e.nativeEvent.offsetX, e.nativeEvent.offsetY]);
141+
const v = zoom(view, screenSize, zoomScale, [e.offsetX, e.offsetY]);
143142
setView(v);
144143
};
145144

site/src/examples/omezarr/omezarr-viewer.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface OmezarrViewerProps {
1717
id: string;
1818
screenSize: vec2;
1919
settings: RenderSettings;
20-
onWheel?: (e: React.WheelEvent<HTMLCanvasElement>) => void;
20+
onWheel?: (e: WheelEvent) => void;
2121
onMouseDown?: (e: React.MouseEvent<HTMLCanvasElement>) => void;
2222
onMouseUp?: (e: React.MouseEvent<HTMLCanvasElement>) => void;
2323
onMouseMove?: (e: React.MouseEvent<HTMLCanvasElement>) => void;
@@ -51,6 +51,7 @@ export function OmezarrViewer({
5151
// setup renderer and delete it when component goes away
5252
useEffect(() => {
5353
const c = canvas?.current;
54+
5455
if (server?.regl && omezarr) {
5556
const numChannels = omezarr.colorChannels.length || 3;
5657
renderer.current = buildAsyncOmezarrRenderer(server.regl, multithreadedDecoder, {
@@ -66,6 +67,19 @@ export function OmezarrViewer({
6667
}
6768
};
6869
}, [server, omezarr]);
70+
71+
useEffect(() => {
72+
const handleWheel = (e: WheelEvent) => onWheel?.(e);
73+
if (canvas?.current) {
74+
canvas.current.addEventListener('wheel', handleWheel, { passive: false });
75+
}
76+
return () => {
77+
if (canvas?.current) {
78+
canvas.current.removeEventListener('wheel', handleWheel);
79+
}
80+
};
81+
}, [onWheel]);
82+
6983
useEffect(() => {
7084
// set up the stash:
7185
if (server?.regl) {
@@ -199,7 +213,6 @@ export function OmezarrViewer({
199213
onMouseUp={onMouseUp}
200214
onMouseMove={onMouseMove}
201215
onMouseLeave={onMouseLeave}
202-
onWheel={onWheel}
203216
/>
204217
);
205218
}

0 commit comments

Comments
 (0)