All files / Sources/Proxy/Core/ProxyManager properties.js

10% Statements 6/60
0% Branches 0/30
14.28% Functions 1/7
10% Lines 6/60

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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129          3x                                                                                         3x             3x                                                                           3x                         3x                         3x              
export default function addVPropertyHandlingAPI(publicAPI, model) {
  // --------------------------------------------------------------------------
  // Property management
  // --------------------------------------------------------------------------
 
  publicAPI.getSections = () => {
    const sections = [];
    const source = publicAPI.getActiveSource();
    if (!source) {
      return [];
    }
    const view = publicAPI.getActiveView();
    if (source) {
      const section = source.getProxySection();
      if (section.ui.length) {
        sections.push(
          Object.assign(section, {
            collapsed: model.collapseState[section.name],
          })
        );
      }
    }
    if (source && view) {
      const representation = publicAPI.getRepresentation(source, view);
      if (representation) {
        const section = representation.getProxySection();
        if (section.ui.length) {
          sections.push(
            Object.assign(section, {
              collapsed: model.collapseState[section.name],
            })
          );
        }
      }
    }
    if (view) {
      const section = view.getProxySection();
      if (section.ui.length) {
        sections.push(
          Object.assign(section, {
            collapsed: model.collapseState[section.name],
          })
        );
      }
    }
    return sections;
  };
 
  // --------------------------------------------------------------------------
 
  publicAPI.updateCollapseState = (name, state) => {
    model.collapseState[name] = state;
    publicAPI.modified();
  };
 
  // --------------------------------------------------------------------------
 
  publicAPI.applyChanges = (changeSet) => {
    const groupBy = {};
    const keys = Object.keys(changeSet);
    let count = keys.length;
    while (count--) {
      const key = keys[count];
      const [id, prop] = key.split(':');
      if (!groupBy[id]) {
        groupBy[id] = {};
      }
      if (changeSet[key] === '__command_execute__') {
        const obj = publicAPI.getProxyById(id);
        if (obj) {
          obj[prop]();
        }
      } else {
        groupBy[id][prop] = changeSet[key];
      }
    }
 
    // Apply changes
    const objIds = Object.keys(groupBy);
    count = objIds.length;
    while (count--) {
      const id = objIds[count];
      const obj = publicAPI.getProxyById(id);
      if (obj) {
        obj.set(groupBy[id]);
      }
    }
    publicAPI.modified();
    publicAPI.renderAllViews();
  };
 
  // --------------------------------------------------------------------------
  // Color Management
  // --------------------------------------------------------------------------
 
  publicAPI.getLookupTable = (arrayName, options) => {
    if (!model.lookupTables[arrayName]) {
      model.lookupTables[arrayName] = publicAPI.createProxy(
        'Proxy',
        'LookupTable',
        { arrayName, ...options }
      );
    }
    return model.lookupTables[arrayName];
  };
 
  // --------------------------------------------------------------------------
 
  publicAPI.getPiecewiseFunction = (arrayName, options) => {
    if (!model.piecewiseFunctions[arrayName]) {
      model.piecewiseFunctions[arrayName] = publicAPI.createProxy(
        'Proxy',
        'PiecewiseFunction',
        { arrayName, ...options }
      );
    }
    return model.piecewiseFunctions[arrayName];
  };
 
  // --------------------------------------------------------------------------
 
  publicAPI.rescaleTransferFunctionToDataRange = (arrayName, dataRange) => {
    const lut = publicAPI.getLookupTable(arrayName);
    const pwf = publicAPI.getPiecewiseFunction(arrayName);
    lut.setDataRange(dataRange[0], dataRange[1]);
    pwf.setDataRange(dataRange[0], dataRange[1]);
  };
}