All files / tools/src/eventDispatchers annotationModifiedEventDispatcher.ts

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

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                                                                                   
import { eventTarget, getRenderingEngine } from '@cornerstonejs/core';
import Events from '../enums/Events';
import triggerAnnotationRenderForViewportIds from '../utilities/triggerAnnotationRenderForViewportIds';
import type { AnnotationModifiedEventType } from '../types/EventTypes';
 
/**
 * 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)
 */
const onAnnotationModified = function (evt: AnnotationModifiedEventType) {
  const { viewportId, renderingEngineId } = evt.detail;
  const renderingEngine = getRenderingEngine(renderingEngineId);
  triggerAnnotationRenderForViewportIds([viewportId]);
};
 
const enable = function () {
  eventTarget.addEventListener(
    Events.ANNOTATION_MODIFIED,
    onAnnotationModified
  );
};
 
const disable = function () {
  eventTarget.removeEventListener(
    Events.ANNOTATION_MODIFIED,
    onAnnotationModified
  );
};
 
export default {
  enable,
  disable,
};