All files / extensions/cornerstone/src/tools WindowLevelTool.ts

75% Statements 3/4
60% Branches 3/5
100% Functions 1/1
75% Lines 3/4

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                      30x   30x       30x          
import { getEnabledElement } from '@cornerstonejs/core';
import { WindowLevelTool as CornerstoneWindowLevelTool } from '@cornerstonejs/tools';
import { UNSUPPORTED_WINDOW_LEVEL_VIEWPORT_TYPES } from '../constants';
 
/**
 * Window/Level tool that ignores drags on viewports without a VOI range (e.g. ECG)
 * instead of throwing "Viewport is not a valid type". It keeps the same tool name,
 * so it is a drop-in replacement for the Cornerstone tool.
 */
class WindowLevelTool extends CornerstoneWindowLevelTool {
  mouseDragCallback(evt) {
    const { viewport } = getEnabledElement(evt.detail.element) ?? {};
 
    Iif (!viewport || UNSUPPORTED_WINDOW_LEVEL_VIEWPORT_TYPES.includes(viewport.type)) {
      return;
    }
 
    return super.mouseDragCallback(evt);
  }
}
 
export default WindowLevelTool;