feat: React Examples Components (DT-7024)#49
Conversation
lanesawyer
left a comment
There was a problem hiding this comment.
Routing works! Let's get the Layers app showing too, since that's an important one.
There is a type error that keeps Vite from building, easy fix though.
I'll poke at this again once it's fully baked!
examples/src/home.tsx
Outdated
| <a href="/omezarr">OMEZARR</a> | ||
| <br /> | ||
| </li> | ||
| {/* layers is not in the AC to be converted to a react component |
There was a problem hiding this comment.
Let's at least let it render like it was, since there's a good Markdown page explaining how to use it in the docs still so we want it working.
lanesawyer
left a comment
There was a problem hiding this comment.
Could you remove examples/public/layers.html? Only examples/layers.html is needed.
Looking great, everything works! The demos don't render until you interact with the page, like a scroll event, and then they pop up. That would be nice to fix, or we can add a message on the screen for now.
| camera={{ ...exampleSettings.camera, view }} | ||
| wheel={zoom} | ||
| /> | ||
| <div style={{ display: 'flex', flexDirection: 'row' }}> |
There was a problem hiding this comment.
Could you add some text to the page encouraging users to scroll to get the demos to appear? Alternatively, we figure out why it takes interaction to make these show up properly.
There was a problem hiding this comment.
In bkp we solve that problem with an "onComplete" callback with a hook, but lets wait to look into this deeper in another ticket
examples/src/dzi/dzi-viewer.tsx
Outdated
| } | ||
| return () => { | ||
| if (cnvs.current) { | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps |
There was a problem hiding this comment.
I think this is out of place? This isn't disabling the useEffect dependency lint issues. We also still need to actually integrate a linter soon 😅
| }; | ||
|
|
||
| return omezarr && settings ? ( | ||
| <RenderServerProvider> |
There was a problem hiding this comment.
This might be why the omezarr demo requires interaction like a scroll to show up. Always return the provider, then do the ternary inside it as children
There was a problem hiding this comment.
that fixes it, yep!
examples/src/layers/examples.ts
Outdated
| const colorByGene: ColumnRequest = { name: '88', type: 'QUANTITATIVE' }; | ||
| const scottpoc = 'https://tissuecyte-ome-zarr-poc.s3.amazonaws.com/40_128_128/1145081396'; | ||
|
|
||
| export const examples: Record<string, any> = { |
There was a problem hiding this comment.
| export const examples: Record<string, any> = { | |
| export const examples = { |
There was a problem hiding this comment.
dont erase types with any...
examples/src/layers/examples.ts
Outdated
| plane: 'xy', | ||
| slices: 4, | ||
| } as ZarrSliceGridConfig, | ||
| ['structureAnnotation']: { |
There was a problem hiding this comment.
what happened here? why do these all have [' '] wrappings?
whats wrong with structureAnnotation: {...}
examples/src/dzi/use-dzi-image.ts
Outdated
| onComplete?: (imgSize: vec2) => void; | ||
| } | ||
|
|
||
| function decodeDzi(s: string, url: string): DziImage | undefined { |
There was a problem hiding this comment.
this is is a nice-ish function that shows how to decode the dzi xml/json metadata "format".
I think you should add some documentation, and maybe clean up or explain the url.split('.dzi') stuff
examples/src/dzi/use-dzi-image.ts
Outdated
| callback(images); | ||
| } | ||
|
|
||
| export function useDziImages({ imageUrls, onComplete }: useDziImageProps) { |
There was a problem hiding this comment.
useDziImages and getImages are unused, stateful, clunky - lets remove them?
| const size = sizeInUnits('xy', v.multiscales[0].axes, v.multiscales[0].datasets[0]); | ||
| if (size) { | ||
| console.log(size); | ||
| setView(Box2D.create([0, 0], [size[0], size[1]])); |
There was a problem hiding this comment.
| setView(Box2D.create([0, 0], [size[0], size[1]])); | |
| setView(Box2D.create([0, 0], size)); |
| * @param {string} name - name will show up in console log | ||
| * @param {Object} props - entire props object of the component being tested | ||
| */ | ||
| export function useWhyDidYouUpdate<P extends object>(name: string, props: P) { |
examples/src/layers/examples.ts
Outdated
| import type { ZarrSliceGridConfig } from '~/data-sources/ome-zarr/slice-grid'; | ||
| import type { ScatterplotGridConfig, ScatterPlotGridSlideConfig } from '~/data-sources/scatterplot/dynamic-grid'; | ||
|
|
||
| const slide32 = 'MQ1B9QBZFIPXQO6PETJ'; |
There was a problem hiding this comment.
ok this whole file is unused - it was nice that it was pulled out of the code for the layers example logic, but the types got a bit messed up.
either fix the types and use it, or delete it and keep the actual values on line 745 of src/layers.ts
| "lodash": "^4.17.21", | ||
| "react": "^18.3.0", | ||
| "react-dom": "^18.3.0", | ||
| "react-router": "^7.0.2", |
There was a problem hiding this comment.
are a handful of static, independant pages worth pulling in this dependency?
There was a problem hiding this comment.
I suppose it does let us delete the kinda gross repetetative {demo-name.html} files....
There was a problem hiding this comment.
lets keep it, seems fine
| }); | ||
| }, []); | ||
|
|
||
| const zoom = (e: WheelEvent) => { |
There was a problem hiding this comment.
I thought part of the improvements we were going to add was around the cameras - currently the dzi demo cant pan, only zoom. Perhaps we could consolidate their zoom and pan handlers and have both working on both?
There was a problem hiding this comment.
I made simple functions for zoom and pan rather than wrap it in a hook just so it's more transparent for anyone reading the examples. I think it's easier to understand but I can move them into separate hooks if you think that's better.
There was a problem hiding this comment.
not asking for hooks...
one of the learnings from integrating these components was that the hard-coded cameras in different spaces was confusing. My ask here is that you share the zoom & pan interactions (event handlers) between the two components, if possible.
right now, the dzi and omezarr components have different capabilities, but there is no reason for that to be the case, right?
froyo-np
left a comment
There was a problem hiding this comment.
Cleanup please, consider camera event handing consolidation
examples/src/dzi/decode-dzi.ts
Outdated
| // At the end of the file you can see two examples of the metadata format you might see, one as XML and another as JSON | ||
| /** | ||
| * This function helps decode xml metadata for a dzi file. | ||
| * @param s xml string |
There was a problem hiding this comment.
| * @param s xml string | |
| * @param s the contents of the @param url - expected to be an XML document describing a DZI image |
examples/src/common/camera.ts
Outdated
| * @param view your current view | ||
| * @param screenSize the size of your canvas/screen | ||
| * @param zoomScale the scale you want to apply to your view | ||
| * @param mousePos the offsetX and offsetY of your mouse |
There was a problem hiding this comment.
none of these comments are helpful are they?
a parameter named screenSize is obviously the size of the screen - maybe give the units?
mousePos - is this in pixels, or the data space?
view - what is this? obviously its the current view. this is a box, in dataspace, that gets mapped to the screen or canvas.
examples/src/common/camera.ts
Outdated
| * @param zoomScale the scale you want to apply to your view | ||
| * @param mousePos the offsetX and offsetY of your mouse | ||
| */ | ||
| export function zoom(view: box2D, screenSize: vec2, zoomScale: number, mousePos: vec2) { |
There was a problem hiding this comment.
other than the unhelpful docs, these are excellent - thanks for unifying the camera logic!
| return undefined; | ||
| } | ||
|
|
||
| /* Example XML |
lanesawyer
left a comment
There was a problem hiding this comment.
Everything still works, I think you hit all the main points Noah called out.
Even if there is something left over let's just ship it now so everything is in main as we keep iterating on it.
There was a problem hiding this comment.
This will be a good base to build on for pre-baked camera solutions as we make more comprehensive "out of the box" components!
What
Create react components for our examples(excluding layers).
How
PR Checklist
main?