All files / packages/tools/src/store filterToolsWithAnnotationsForElement.ts

86.66% Statements 13/15
75% Branches 6/8
100% Functions 1/1
85.71% Lines 12/14

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 48 49 50 51                                  210x 210x 112x   112x         112x         112x 68x     44x   44x           44x 43x       210x    
import { getAnnotations } from '../stateManagement/annotation/annotationState';
import { ToolAnnotationsPair } from '../types/InternalToolTypes';
import type AnnotationTool from '../tools/base/AnnotationTool';
import BaseTool from '../tools/base/BaseTool';
 
/**
 * Filters an array of tools, returning only tools which have annotation.
 *
 * @param element - The cornerstone3D enabled element.
 * @param tools - The array of tools to check.
 *
 * @returns The array of tools with their found annotations.
 */
export default function filterToolsWithAnnotationsForElement(
  element: HTMLDivElement,
  tools: AnnotationTool[]
): ToolAnnotationsPair[] {
  const result = [];
  for (let i = 0; i < tools.length; i++) {
    const tool = tools[i];
 
    Iif (!tool) {
      console.warn('undefined tool in filterToolsWithAnnotationsForElement');
      continue;
    }
 
    let annotations = getAnnotations(
      (tool.constructor as typeof BaseTool).toolName,
      element
    );
 
    if (!annotations?.length) {
      continue;
    }
 
    Eif (typeof tool.filterInteractableAnnotationsForElement === 'function') {
      // If the tool has a annotations filter (e.g. with in-plane-annotations-only filtering), use it.
      annotations = tool.filterInteractableAnnotationsForElement(
        element,
        annotations
      );
    }
 
    if (annotations.length > 0) {
      result.push({ tool, annotations });
    }
  }
 
  return result;
}