All files / packages/tools/src/eventListeners/annotations annotationModifiedListener.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

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                                67x 67x 67x        
import { getRenderingEngine } from '@cornerstonejs/core';
import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds';
 
/**
 * This is a callback function that is called when an annotation is modified.
 * Since we are throttling the cachedStats calculation for annotation tools,
 * we need to trigger a final render for the annotation. so that the annotation
 * textBox is updated.
 * Todo: This will trigger all the annotation tools to re-render, although DOM
 * will update those that have changed, but more efficient would be to only
 * update the changed annotation.
 * Todo: A better way is to extract the textBox render logic from the renderAnnotation
 * of all tools and just trigger a render for that (instead of the entire annotation., even if
 * no svg update happens since the attributes for handles are the same)
 */
function annotationModifiedListener(evt): void {
  const { viewportId, renderingEngineId } = evt.detail;
  const renderingEngine = getRenderingEngine(renderingEngineId);
  triggerAnnotationRenderForViewportIds(renderingEngine, [viewportId]);
}
 
export default annotationModifiedListener;