Skip to content

Commit

Permalink
Integrate itk-viewer-2d component
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Jun 10, 2024
1 parent b5a8ec8 commit bfc0f41
Show file tree
Hide file tree
Showing 6 changed files with 3,254 additions and 197 deletions.
4 changes: 4 additions & 0 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { MetaFunction } from "@remix-run/node";
import { Viewer } from "../viewer.js";

export const meta: MetaFunction = () => {
return [
Expand All @@ -10,6 +11,9 @@ export const meta: MetaFunction = () => {
export default function Index() {
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<div style={{ width: "100%", height: "300px" }}>
<Viewer imagePath="https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/idr0079A/9836998.zarr" />
</div>
<h1>Welcome to Remix</h1>
<ul>
<li>
Expand Down
42 changes: 42 additions & 0 deletions app/viewer.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useEffect, useRef } from "react";

import "@shoelace-style/shoelace/dist/themes/light.css";
import "@shoelace-style/shoelace/dist/components/card/card.js";
import "@shoelace-style/shoelace/dist/components/range/range.js";
import "@shoelace-style/shoelace/dist/components/select/select.js";
import "@shoelace-style/shoelace/dist/components/option/option.js";
import type { ItkViewer2d } from "@itk-viewer/element/itk-viewer-2d.js";
import "@itk-viewer/element/itk-viewer-2d.js";
import { ZarrMultiscaleSpatialImage } from "@itk-viewer/io/ZarrMultiscaleSpatialImage.js";

export function ViewerClient({ imagePath }: { imagePath: string }) {
const viewer = useRef<ItkViewer2d>(null);

useEffect(() => {
const element = viewer.current;
if (!element) {
return;
}
const url = new URL(imagePath, document.location.origin);
ZarrMultiscaleSpatialImage.fromUrl(url).then((image) => {
const actor = element.getActor();
actor!.send({ type: "setImage", image, name: "image" });
});
}, [imagePath, viewer]);

return (
<itk-viewer-2d
ref={viewer}
style={{ width: "100%", height: "100%" }}
></itk-viewer-2d>
);
}

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace JSX {
interface IntrinsicElements {
"itk-viewer-2d": ItkViewer2d;
}
}
}
16 changes: 16 additions & 0 deletions app/viewer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ClientOnly } from "remix-utils/client-only";
import { ViewerClient } from "~/viewer.client";

function SSRFallback() {
return (
<div style={{ width: "100%", height: "100%" }}>Loading itk-viewer...</div>
);
}

export function Viewer({ imagePath }: { imagePath: string }) {
return (
<ClientOnly fallback={<SSRFallback />}>
{() => <ViewerClient imagePath={imagePath} />}
</ClientOnly>
);
}
Loading

0 comments on commit bfc0f41

Please sign in to comment.