All files / src/stores viewer.store.ts

92.59% Statements 25/27
71.42% Branches 10/14
100% Functions 7/7
92% Lines 23/25

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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98              3x           12x                         1x           4x                       34x 30x 30x 30x 30x 30x 30x 30x 30x 30x   30x 3x     3x           3x       30x 1x     1x           1x       30x                            
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
import { AnchorPoint, PositionData, ScanView } from '@3cr/types-ts';
import { DataOverlay, ViewerOptions } from '@3cr/viewer-types-ts';
import { zip } from 'lodash';
 
function makeLayout2x2(views: ScanView[]): PositionData[] {
  const anchors = [
    AnchorPoint.TOP_LEFT,
    AnchorPoint.TOP_RIGHT,
    AnchorPoint.BOTTOM_LEFT,
    AnchorPoint.BOTTOM_RIGHT,
  ];
  return zip(views, anchors).map(([view, anchor], idx) => ({
    Version: '0.0.0',
    ActiveView: idx === 0,
    DefaultView: view!,
    Anchor: anchor!,
    Offset: { Version: '0.0.0', X: 0, Y: 0 },
    AspectRatio: -1,
    MaxSize: { Version: '0.0.0', X: 0.5, Y: 0.5 },
    Priority: 0,
  }));
}
 
function makeLayout1x3(views: ScanView[]): PositionData[] {
  const anchors = [
    AnchorPoint.CENTER,
    AnchorPoint.TOP_RIGHT,
    AnchorPoint.RIGHT,
    AnchorPoint.BOTTOM_RIGHT,
  ];
  return zip(views, anchors).map(([view, anchor], idx) => ({
    Version: '1.0.0',
    ActiveView: idx === 0,
    DefaultView: view!,
    Anchor: anchor!,
    Offset: { Version: '1.0.0', X: 0, Y: 0 },
    AspectRatio: idx === 0 ? -1 : 1,
    MaxSize: { Version: '1.0.0', X: 1, Y: idx === 0 ? 1 : 1 / 3 },
    Priority: idx === 0 ? 0 : 1,
  }));
}
 
export const useViewerStore = defineStore('viewer', () => {
  const activeView = ref<ScanView>();
  const enableMouse = ref<boolean>(false);
  const enableKeyboard = ref<boolean>(false);
  const inputOverride = ref<boolean>(false);
  const options = ref<ViewerOptions>({});
  const notifications = ref<boolean>(false);
  const measurementToDelete = ref<DataOverlay>();
  const s_annotationDelete = ref<boolean>(false);
  const s_measurementDelete = ref<boolean>(false);
 
  const defaultLayout2x2 = computed(() => {
    Iif (options.value.layout2x2 && options.value.layout2x2.length === 4) {
      return makeLayout2x2(options.value.layout2x2);
    } else {
      const defaults = [
        ScanView.Volume,
        ScanView.Sagittal,
        ScanView.Transverse,
        ScanView.Coronal,
      ];
      return makeLayout2x2(defaults);
    }
  });
 
  const defaultLayout1x3 = computed(() => {
    Iif (options.value.layout1x3 && options.value.layout1x3.length === 4) {
      return makeLayout1x3(options.value.layout1x3);
    } else {
      const defaults = [
        ScanView.Volume,
        ScanView.Transverse,
        ScanView.Coronal,
        ScanView.Sagittal,
      ];
      return makeLayout1x3(defaults);
    }
  });
 
  return {
    activeView,
    enableMouse,
    inputOverride,
    enableKeyboard,
    options,
    notifications,
    measurementToDelete,
    s_annotationDelete,
    s_measurementDelete,
    defaultLayout2x2,
    defaultLayout1x3,
  };
});