@thewtex/vtk.js-esm
Version:
Visualization Toolkit for the Web
146 lines (108 loc) • 4.86 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function addVPropertyHandlingAPI(publicAPI, model) {
// --------------------------------------------------------------------------
// Property management
// --------------------------------------------------------------------------
publicAPI.getSections = function () {
var sections = [];
var source = publicAPI.getActiveSource();
if (!source) {
return [];
}
var view = publicAPI.getActiveView();
if (source) {
var section = source.getProxySection();
if (section.ui.length) {
sections.push(Object.assign(section, {
collapsed: model.collapseState[section.name]
}));
}
}
if (source && view) {
var representation = publicAPI.getRepresentation(source, view);
if (representation) {
var _section = representation.getProxySection();
if (_section.ui.length) {
sections.push(Object.assign(_section, {
collapsed: model.collapseState[_section.name]
}));
}
}
}
if (view) {
var _section2 = view.getProxySection();
if (_section2.ui.length) {
sections.push(Object.assign(_section2, {
collapsed: model.collapseState[_section2.name]
}));
}
}
return sections;
}; // --------------------------------------------------------------------------
publicAPI.updateCollapseState = function (name, state) {
model.collapseState[name] = state;
publicAPI.modified();
}; // --------------------------------------------------------------------------
publicAPI.applyChanges = function (changeSet) {
var groupBy = {};
var keys = Object.keys(changeSet);
var count = keys.length;
while (count--) {
var key = keys[count];
var _key$split = key.split(':'),
_key$split2 = _slicedToArray(_key$split, 2),
id = _key$split2[0],
prop = _key$split2[1];
if (!groupBy[id]) {
groupBy[id] = {};
}
if (changeSet[key] === '__command_execute__') {
var obj = publicAPI.getProxyById(id);
if (obj) {
obj[prop]();
}
} else {
groupBy[id][prop] = changeSet[key];
}
} // Apply changes
var objIds = Object.keys(groupBy);
count = objIds.length;
while (count--) {
var _id = objIds[count];
var _obj = publicAPI.getProxyById(_id);
if (_obj) {
_obj.set(groupBy[_id]);
}
}
publicAPI.modified();
publicAPI.renderAllViews();
}; // --------------------------------------------------------------------------
// Color Management
// --------------------------------------------------------------------------
publicAPI.getLookupTable = function (arrayName, options) {
if (!model.lookupTables[arrayName]) {
model.lookupTables[arrayName] = publicAPI.createProxy('Proxy', 'LookupTable', _objectSpread({
arrayName: arrayName
}, options));
}
return model.lookupTables[arrayName];
}; // --------------------------------------------------------------------------
publicAPI.getPiecewiseFunction = function (arrayName, options) {
if (!model.piecewiseFunctions[arrayName]) {
model.piecewiseFunctions[arrayName] = publicAPI.createProxy('Proxy', 'PiecewiseFunction', _objectSpread({
arrayName: arrayName
}, options));
}
return model.piecewiseFunctions[arrayName];
}; // --------------------------------------------------------------------------
publicAPI.rescaleTransferFunctionToDataRange = function (arrayName, dataRange) {
var lut = publicAPI.getLookupTable(arrayName);
var pwf = publicAPI.getPiecewiseFunction(arrayName);
lut.setDataRange(dataRange[0], dataRange[1]);
pwf.setDataRange(dataRange[0], dataRange[1]);
};
}
export default addVPropertyHandlingAPI;