-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: React Examples Components (DT-7024) #49
Open
TheMooseman
wants to merge
10
commits into
main
Choose a base branch
from
skyler/react-components
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
31b7d09
create basic components
TheMooseman bdd3856
make layers work again
TheMooseman 1163339
rename things so there are fewer app files
TheMooseman f55e099
clean up dzi viewer
TheMooseman 65753c8
omezarr
TheMooseman 099c385
lanes comments
TheMooseman c17368c
Merge branch 'main' into skyler/react-components
TheMooseman 03fd5b6
noahs comments
TheMooseman 543a482
remove unused examples file
TheMooseman 0547305
some better comments
TheMooseman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
<!doctype html> | ||
<html> | ||
<body> | ||
EXAMPLES | ||
<br /> | ||
<ul> | ||
<li><a href="/dzi">Deep Zoom Image</a><br /></li> | ||
<li><a href="/omezarr">OMEZARR</a><br /></li> | ||
<li><a href="/layers">Layers</a><br /></li> | ||
</ul> | ||
<div id="app"></div> | ||
<script | ||
type="module" | ||
src="/src/index.tsx" | ||
></script> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,27 @@ | ||
import React from 'react'; | ||
import { SliceViewLayer } from './ui/slice-ui'; | ||
import type { Demo } from './layers'; | ||
import { AnnotationGrid } from './ui/annotation-grid'; | ||
import { ContactSheetUI } from './ui/contact-sheet'; | ||
import { ScatterplotUI } from './ui/scatterplot-ui'; | ||
import { Button } from '@czi-sds/components'; | ||
import { BrowserRouter, Route, Routes } from 'react-router'; | ||
import { Home } from './home'; | ||
import { OmezarrDemo } from './omezarr/omezarr-demo'; | ||
import { DziDemo } from './dzi/dzi-demo'; | ||
|
||
export function AppUi(props: { demo: Demo }) { | ||
const { demo } = props; | ||
export function App() { | ||
return ( | ||
<div> | ||
<Button | ||
onClick={() => { | ||
demo.requestSnapshot(3000); | ||
}} | ||
> | ||
{'📸'} | ||
</Button> | ||
<label>{`Layer ${demo.selectedLayer}`}</label> | ||
<Button | ||
onClick={() => { | ||
demo.selectLayer(demo.selectedLayer - 1); | ||
}} | ||
> | ||
{'<-'} | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
demo.selectLayer(demo.selectedLayer + 1); | ||
}} | ||
> | ||
{'->'} | ||
</Button> | ||
<LayerUi demo={demo} /> | ||
</div> | ||
<BrowserRouter> | ||
<Routes> | ||
<Route | ||
index | ||
element={<Home />} | ||
/> | ||
<Route | ||
path="/dzi" | ||
element={<DziDemo />} | ||
/> | ||
<Route | ||
path="/omezarr" | ||
element={<OmezarrDemo />} | ||
/> | ||
<Route path="/layers" /> | ||
</Routes> | ||
</BrowserRouter> | ||
); | ||
} | ||
function LayerUi(props: { demo: Demo }) { | ||
const { demo } = props; | ||
const layer = demo.layers[demo.selectedLayer]; | ||
if (layer) { | ||
switch (layer.type) { | ||
case 'annotationGrid': | ||
return <AnnotationGrid demo={demo} />; | ||
case 'volumeGrid': | ||
return <ContactSheetUI demo={demo} />; | ||
case 'volumeSlice': | ||
return <SliceViewLayer demo={demo} />; | ||
case 'scatterplot': | ||
case 'scatterplotGrid': | ||
return <ScatterplotUI demo={demo} />; | ||
default: | ||
return null; | ||
} | ||
} | ||
return <SliceViewLayer demo={props.demo} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,43 @@ | ||
import type { box2D, vec2 } from '@alleninstitute/vis-geometry'; | ||
import { Box2D, Vec2, type box2D, type vec2 } from '@alleninstitute/vis-geometry'; | ||
|
||
// a basic camera, for viewing slices | ||
export type Camera = { | ||
readonly view: box2D; // a view in 'data space' | ||
readonly screen: vec2; // what that view projects to in display space, aka pixels | ||
readonly projection: 'webImage' | 'cartesian'; | ||
}; | ||
/** | ||
* Zooms relative to your current mouse position | ||
* @param view box2d in dataspace that is mapped to the canvas | ||
* @param screenSize in pixels | ||
* @param zoomScale | ||
* @param mousePos mouse position in pixels | ||
*/ | ||
export function zoom(view: box2D, screenSize: vec2, zoomScale: number, mousePos: vec2): box2D { | ||
// translate mouse pos to data space | ||
// offset divided by screen size gives us a percentage of the canvas where the mouse is | ||
// multiply percentage by view size to make it data space | ||
// add offset of the min corner so that the position takes into account any box offset | ||
const zoomPoint: vec2 = Vec2.add(view.minCorner, Vec2.mul(Vec2.div(mousePos, screenSize), Box2D.size(view))); | ||
|
||
// scale the box with our new zoom point as the center | ||
const newView = Box2D.translate( | ||
Box2D.scale(Box2D.translate(view, Vec2.scale(zoomPoint, -1)), [zoomScale, zoomScale]), | ||
zoomPoint | ||
); | ||
|
||
return newView; | ||
} | ||
|
||
/** | ||
* | ||
* @param view box2d in dataspace that is mapped to the canvas | ||
* @param screenSize | ||
* @param mousePos mouse position in pixels | ||
*/ | ||
export function pan(view: box2D, screenSize: vec2, mousePos: vec2): box2D { | ||
const relativePos = Vec2.div(Vec2.mul(mousePos, [-1, -1]), screenSize); | ||
const scaledOffset = Vec2.mul(relativePos, Box2D.size(view)); | ||
const newView = Box2D.translate(view, scaledOffset); | ||
return newView; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import type { DziImage } from '@alleninstitute/vis-dzi'; | ||
|
||
// DZI files will come with XML or JSON to give you important information such as the width, height, and format. | ||
// Below is a function for parsing an xml with that data, althought sometimes it comes in JSON format. | ||
// 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 the contents of the url param - expected to be an XML doc describing the DZI image | ||
* @param url location of the .dzi file | ||
* @returns formatted dzi image data | ||
*/ | ||
function decodeDziXml(s: string, url: string): DziImage | undefined { | ||
const parser = new DOMParser(); | ||
const doc = parser.parseFromString(s, 'text/xml'); | ||
// catch any errors if the xml is malformed | ||
const err = doc.querySelector('Error'); | ||
if (err) return undefined; | ||
|
||
if (doc) { | ||
const img = doc.getElementsByTagName('Image')[0]; | ||
const size = doc.getElementsByTagName('Size')[0]; | ||
// format: as jpg/png | ||
// overlap: how much overlap there is between images so that we can compensate the rendering | ||
// tile size: how big in pixels each tile is | ||
const [format, overlap, tileSize] = [ | ||
img.getAttribute('Format'), | ||
img.getAttribute('Overlap'), | ||
img.getAttribute('TileSize'), | ||
]; | ||
if (size && format && overlap && tileSize) { | ||
// width and height of the image, so we can properly size the view | ||
const width = size.getAttribute('Width'); | ||
const height = size.getAttribute('Height'); | ||
|
||
// the url ends with .dzi to denote that we're reaching for a dzi file | ||
// in order to get the images from that url we need to remove the .dzi | ||
// and replace it with _files/ so that the image viewer knows where to look | ||
const dataLoc = url.split('.dzi')[0]; | ||
if (width && height && dataLoc) { | ||
return { | ||
imagesUrl: `${dataLoc}_files/`, | ||
format: format as 'jpeg' | 'png' | 'jpg' | 'JPG' | 'PNG', | ||
overlap: Number.parseInt(overlap, 10), | ||
tileSize: Number.parseInt(tileSize, 10), | ||
size: { | ||
width: Number.parseInt(width, 10), | ||
height: Number.parseInt(height, 10), | ||
}, | ||
}; | ||
} | ||
} | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
/* Example XML | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Image xmlns="http://schemas.microsoft.com/deepzoom/2008" | ||
Format="jpg" | ||
Overlap="2" | ||
TileSize="256" > | ||
<Size Height="9221" | ||
Width="7026"/> | ||
</Image> | ||
*/ | ||
|
||
/* Example JSON | ||
{ | ||
"Image": { | ||
"xmlns": "http://schemas.microsoft.com/deepzoom/2008", | ||
"Format": "jpg", | ||
"Overlap": "2", | ||
"TileSize": "256", | ||
"Size": { | ||
"Height": "9221", | ||
"Width": "7026" | ||
} | ||
} | ||
} | ||
*/ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are a handful of static, independant pages worth pulling in this dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it does let us delete the kinda gross repetetative {demo-name.html} files....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets keep it, seems fine