All files / extensions/cornerstone/src/Viewport/Overlays/ViewportSliceProgressScrollbar helpers.ts

100% Statements 19/19
87.5% Branches 14/16
100% Functions 4/4
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47          835x 835x       1101x 464x     637x 637x 637x   637x       964x 133x             831x 831x 831x 508x   323x 322x     1x       41988x 41988x    
import { ViewportData } from './types';
import { isVolume3DViewportType } from '../../../utils/getLegacyViewportType';
import { getViewportAdapter } from '../../../services/ViewportService/adapter';
 
export function getImageIndexFromEvent(event): number | undefined {
  const { imageIndex, newImageIdIndex = imageIndex, imageIdIndex } = event.detail;
  return newImageIdIndex ?? imageIdIndex;
}
 
export function getViewportImageIds(viewportData: ViewportData): string[] {
  if (!viewportData?.data?.length) {
    return [];
  }
 
  const firstData = viewportData.data[0];
  const volumeImageIds = (firstData as any).volume?.imageIds as string[] | undefined;
  const datumImageIds = (firstData as any).imageIds as string[] | undefined;
 
  return volumeImageIds || datumImageIds || [];
}
 
export function isProgressFullMode(viewportData: ViewportData, viewport): boolean {
  if (!viewportData || !viewport || isVolume3DViewportType(viewport)) {
    return false;
  }
 
  // A stack renders the full progress UI; an acquisition-plane volume is the
  // volume-mode equivalent. The adapter classifies both lanes (legacy by
  // viewport type / isInAcquisitionPlane; native by content mode + view-state
  // orientation, since PLANAR_NEXT collapses the runtime type).
  const adapter = getViewportAdapter(viewport);
  const shape = adapter.getShape();
  if (shape === 'stack') {
    return true;
  }
  if (shape === 'volume') {
    return adapter.isInAcquisitionPlane();
  }
 
  return false;
}
 
export function getImageIdFromCacheEvent(event): string | undefined {
  const detail = event?.detail;
  return detail?.imageId || detail?.image?.imageId || detail?.cachedImage?.imageId;
}