Skip to content

Commit

Permalink
feat(viewer): add multi frame viewport handling logic to useViewport
Browse files Browse the repository at this point in the history
  • Loading branch information
LTakhyunKim committed Jan 3, 2023
1 parent 002a3f0 commit ef2fc12
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libs/insight-viewer/src/Viewport/useViewport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function useViewport(
const imageRef = useRef(image)
const elementRef = useRef(element)
const getInitialViewportRef = useRef(getInitialViewport)
const imageSeriesKeyRef = useRef<string | undefined>()

const resetViewport = useCallback(() => {
const defaultViewport = getDefaultViewport(imageRef.current, elementRef.current)
Expand Down Expand Up @@ -115,10 +116,19 @@ export function useViewport(

if (!defaultViewport) return

// If multi frame, conditional statement to maintain with previous Viewport
if (imageSeriesKeyRef.current && imageSeriesKeyRef.current === image?._imageSeriesKey) return

const getInitialViewport = getInitialViewportRef.current

const initialViewport = getInitialViewport ? getInitialViewport(defaultViewport) : defaultViewport

/**
* Set multi frame key
* Since there is no single frame, assign undefined as it is
*/
imageSeriesKeyRef.current = image?._imageSeriesKey

setViewport((prevViewport) => ({
...prevViewport,
...initialViewport,
Expand Down

0 comments on commit ef2fc12

Please sign in to comment.