@kitware/vtk.js 26.0.0-beta.1 → 26.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Widgets/Core/WidgetManager.js +21 -256
- package/Widgets/Widgets3D/EllipseWidget.js +0 -7
- package/Widgets/Widgets3D/LabelWidget/behavior.js +0 -7
- package/Widgets/Widgets3D/LabelWidget.js +1 -18
- package/Widgets/Widgets3D/LineWidget/behavior.js +0 -44
- package/Widgets/Widgets3D/LineWidget.js +0 -11
- package/Widgets/Widgets3D/PolyLineWidget.js +0 -10
- package/Widgets/Widgets3D/RectangleWidget.js +0 -7
- package/Widgets/Widgets3D/ShapeWidget.js +1 -1
- package/package.json +2 -1
- package/Widgets/Core/WidgetManager/vdom.js +0 -172
- package/Widgets/SVG/SVGLandmarkRepresentation/Constants.js +0 -28
- package/Widgets/SVG/SVGLandmarkRepresentation.js +0 -167
- package/Widgets/SVG/SVGRepresentation.js +0 -163
|
@@ -4,19 +4,14 @@ import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
|
4
4
|
import { r as radiansFromDegrees } from '../../Common/Core/Math/index.js';
|
|
5
5
|
import { FieldAssociations } from '../../Common/DataModel/DataSet/Constants.js';
|
|
6
6
|
import macro from '../../macros.js';
|
|
7
|
-
import vtkSelectionNode from '../../Common/DataModel/SelectionNode.js';
|
|
8
7
|
import WidgetManagerConst from './WidgetManager/Constants.js';
|
|
9
|
-
import vtkSVGRepresentation from '../SVG/SVGRepresentation.js';
|
|
10
8
|
import { WIDGET_PRIORITY } from './AbstractWidget/Constants.js';
|
|
11
|
-
import { diff } from './WidgetManager/vdom.js';
|
|
12
9
|
|
|
13
10
|
var ViewTypes = WidgetManagerConst.ViewTypes,
|
|
14
11
|
RenderingTypes = WidgetManagerConst.RenderingTypes,
|
|
15
12
|
CaptureOn = WidgetManagerConst.CaptureOn;
|
|
16
13
|
var vtkErrorMacro = macro.vtkErrorMacro,
|
|
17
14
|
vtkWarningMacro = macro.vtkWarningMacro;
|
|
18
|
-
var createSvgElement = vtkSVGRepresentation.createSvgElement,
|
|
19
|
-
createSvgDomElement = vtkSVGRepresentation.createSvgDomElement;
|
|
20
15
|
var viewIdCount = 1; // ----------------------------------------------------------------------------
|
|
21
16
|
// Helper
|
|
22
17
|
// ----------------------------------------------------------------------------
|
|
@@ -34,17 +29,9 @@ function extractRenderingComponents(renderer) {
|
|
|
34
29
|
camera: camera
|
|
35
30
|
};
|
|
36
31
|
} // ----------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
function createSvgRoot(id) {
|
|
39
|
-
var svgRoot = createSvgDomElement('svg');
|
|
40
|
-
svgRoot.setAttribute('version', '1.1');
|
|
41
|
-
svgRoot.setAttribute('baseProfile', 'full');
|
|
42
|
-
return svgRoot;
|
|
43
|
-
} // ----------------------------------------------------------------------------
|
|
44
32
|
// vtkWidgetManager methods
|
|
45
33
|
// ----------------------------------------------------------------------------
|
|
46
34
|
|
|
47
|
-
|
|
48
35
|
function vtkWidgetManager(publicAPI, model) {
|
|
49
36
|
if (!model.viewId) {
|
|
50
37
|
model.viewId = "view-".concat(viewIdCount++);
|
|
@@ -52,13 +39,7 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
52
39
|
|
|
53
40
|
model.classHierarchy.push('vtkWidgetManager');
|
|
54
41
|
var propsWeakMap = new WeakMap();
|
|
55
|
-
var widgetToSvgMap = new WeakMap();
|
|
56
|
-
var svgVTrees = new WeakMap();
|
|
57
42
|
var subscriptions = []; // --------------------------------------------------------------------------
|
|
58
|
-
// Internal variable
|
|
59
|
-
// --------------------------------------------------------------------------
|
|
60
|
-
|
|
61
|
-
model.svgRoot = createSvgRoot(model.viewId); // --------------------------------------------------------------------------
|
|
62
43
|
// API internal
|
|
63
44
|
// --------------------------------------------------------------------------
|
|
64
45
|
|
|
@@ -85,142 +66,6 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
85
66
|
viewId: model.viewId
|
|
86
67
|
}));
|
|
87
68
|
} // --------------------------------------------------------------------------
|
|
88
|
-
// internal SVG API
|
|
89
|
-
// --------------------------------------------------------------------------
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
var pendingSvgRenders = new WeakMap();
|
|
93
|
-
|
|
94
|
-
function enableSvgLayer() {
|
|
95
|
-
var container = model._apiSpecificRenderWindow.getReferenceByName('el');
|
|
96
|
-
|
|
97
|
-
var canvas = model._apiSpecificRenderWindow.getCanvas();
|
|
98
|
-
|
|
99
|
-
container.insertBefore(model.svgRoot, canvas.nextSibling);
|
|
100
|
-
var containerStyles = window.getComputedStyle(container);
|
|
101
|
-
|
|
102
|
-
if (containerStyles.position === 'static') {
|
|
103
|
-
container.style.position = 'relative';
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function disableSvgLayer() {
|
|
108
|
-
var container = model._apiSpecificRenderWindow.getReferenceByName('el');
|
|
109
|
-
|
|
110
|
-
container.removeChild(model.svgRoot);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function removeFromSvgLayer(viewWidget) {
|
|
114
|
-
var group = widgetToSvgMap.get(viewWidget);
|
|
115
|
-
|
|
116
|
-
if (group) {
|
|
117
|
-
widgetToSvgMap.delete(viewWidget);
|
|
118
|
-
svgVTrees.delete(viewWidget);
|
|
119
|
-
model.svgRoot.removeChild(group);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function setSvgSize() {
|
|
124
|
-
var _model$_apiSpecificRe = model._apiSpecificRenderWindow.getViewportSize(model._renderer),
|
|
125
|
-
_model$_apiSpecificRe2 = _slicedToArray(_model$_apiSpecificRe, 2),
|
|
126
|
-
cwidth = _model$_apiSpecificRe2[0],
|
|
127
|
-
cheight = _model$_apiSpecificRe2[1];
|
|
128
|
-
|
|
129
|
-
var ratio = window.devicePixelRatio || 1;
|
|
130
|
-
var bwidth = String(cwidth / ratio);
|
|
131
|
-
var bheight = String(cheight / ratio);
|
|
132
|
-
var viewBox = "0 0 ".concat(cwidth, " ").concat(cheight);
|
|
133
|
-
var origWidth = model.svgRoot.getAttribute('width');
|
|
134
|
-
var origHeight = model.svgRoot.getAttribute('height');
|
|
135
|
-
var origViewBox = model.svgRoot.getAttribute('viewBox');
|
|
136
|
-
|
|
137
|
-
if (origWidth !== bwidth) {
|
|
138
|
-
model.svgRoot.setAttribute('width', bwidth);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (origHeight !== bheight) {
|
|
142
|
-
model.svgRoot.setAttribute('height', bheight);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (origViewBox !== viewBox) {
|
|
146
|
-
model.svgRoot.setAttribute('viewBox', viewBox);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function setSvgRootStyle() {
|
|
151
|
-
var viewport = model._renderer.getViewport().map(function (v) {
|
|
152
|
-
return v * 100;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
model.svgRoot.setAttribute('style', "position: absolute; left: ".concat(viewport[0], "%; top: ").concat(100 - viewport[3], "%; width: ").concat(viewport[2] - viewport[0], "%; height: ").concat(viewport[3] - viewport[1], "%;"));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function updateSvg() {
|
|
159
|
-
if (model.useSvgLayer) {
|
|
160
|
-
var _loop = function _loop(i) {
|
|
161
|
-
var widget = model.widgets[i];
|
|
162
|
-
var svgReps = widget.getRepresentations().filter(function (r) {
|
|
163
|
-
return r.isA('vtkSVGRepresentation');
|
|
164
|
-
});
|
|
165
|
-
var pendingContent = [];
|
|
166
|
-
|
|
167
|
-
if (widget.getVisibility()) {
|
|
168
|
-
pendingContent = svgReps.filter(function (r) {
|
|
169
|
-
return r.getVisibility();
|
|
170
|
-
}).map(function (r) {
|
|
171
|
-
return r.render();
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
var promise = Promise.all(pendingContent);
|
|
176
|
-
var renders = pendingSvgRenders.get(widget) || [];
|
|
177
|
-
renders.push(promise);
|
|
178
|
-
pendingSvgRenders.set(widget, renders);
|
|
179
|
-
promise.then(function (vnodes) {
|
|
180
|
-
var pendingRenders = pendingSvgRenders.get(widget) || [];
|
|
181
|
-
var idx = pendingRenders.indexOf(promise);
|
|
182
|
-
|
|
183
|
-
if (model.deleted || widget.isDeleted() || idx === -1) {
|
|
184
|
-
return;
|
|
185
|
-
} // throw away previous renders
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
pendingRenders = pendingRenders.slice(idx + 1);
|
|
189
|
-
pendingSvgRenders.set(widget, pendingRenders);
|
|
190
|
-
var oldVTree = svgVTrees.get(widget);
|
|
191
|
-
var newVTree = createSvgElement('g');
|
|
192
|
-
|
|
193
|
-
for (var ni = 0; ni < vnodes.length; ni++) {
|
|
194
|
-
newVTree.appendChild(vnodes[ni]);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
var widgetGroup = widgetToSvgMap.get(widget);
|
|
198
|
-
var node = widgetGroup;
|
|
199
|
-
var patchFns = diff(oldVTree, newVTree);
|
|
200
|
-
|
|
201
|
-
for (var j = 0; j < patchFns.length; j++) {
|
|
202
|
-
node = patchFns[j](node);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (!widgetGroup && node) {
|
|
206
|
-
// add
|
|
207
|
-
model.svgRoot.appendChild(node);
|
|
208
|
-
widgetToSvgMap.set(widget, node);
|
|
209
|
-
} else if (widgetGroup && !node) {
|
|
210
|
-
// delete
|
|
211
|
-
widgetGroup.remove();
|
|
212
|
-
widgetToSvgMap.delete(widget);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
svgVTrees.set(widget, newVTree);
|
|
216
|
-
});
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
for (var i = 0; i < model.widgets.length; i++) {
|
|
220
|
-
_loop(i);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
} // --------------------------------------------------------------------------
|
|
224
69
|
// Widget scaling
|
|
225
70
|
// --------------------------------------------------------------------------
|
|
226
71
|
|
|
@@ -451,10 +296,10 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
451
296
|
|
|
452
297
|
publicAPI.renderWidgets = function () {
|
|
453
298
|
if (model.pickingEnabled && model.captureOn === CaptureOn.MOUSE_RELEASE) {
|
|
454
|
-
var _model$
|
|
455
|
-
_model$
|
|
456
|
-
w = _model$
|
|
457
|
-
h = _model$
|
|
299
|
+
var _model$_apiSpecificRe = model._apiSpecificRenderWindow.getSize(),
|
|
300
|
+
_model$_apiSpecificRe2 = _slicedToArray(_model$_apiSpecificRe, 2),
|
|
301
|
+
w = _model$_apiSpecificRe2[0],
|
|
302
|
+
h = _model$_apiSpecificRe2[1];
|
|
458
303
|
|
|
459
304
|
captureBuffers(0, 0, w, h);
|
|
460
305
|
}
|
|
@@ -480,11 +325,6 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
480
325
|
|
|
481
326
|
model._selector.setFieldAssociation(FieldAssociations.FIELD_ASSOCIATION_POINTS);
|
|
482
327
|
|
|
483
|
-
subscriptions.push(model._interactor.onRenderEvent(updateSvg));
|
|
484
|
-
subscriptions.push(renderer.onModified(setSvgRootStyle));
|
|
485
|
-
setSvgRootStyle();
|
|
486
|
-
subscriptions.push(model._apiSpecificRenderWindow.onModified(setSvgSize));
|
|
487
|
-
setSvgSize();
|
|
488
328
|
subscriptions.push(model._apiSpecificRenderWindow.onModified(updateDisplayScaleParams));
|
|
489
329
|
subscriptions.push(model._camera.onModified(updateDisplayScaleParams));
|
|
490
330
|
updateDisplayScaleParams();
|
|
@@ -515,10 +355,6 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
515
355
|
if (model.pickingEnabled) {
|
|
516
356
|
publicAPI.enablePicking();
|
|
517
357
|
}
|
|
518
|
-
|
|
519
|
-
if (model.useSvgLayer) {
|
|
520
|
-
enableSvgLayer();
|
|
521
|
-
}
|
|
522
358
|
};
|
|
523
359
|
|
|
524
360
|
function addWidgetInternal(viewWidget) {
|
|
@@ -556,7 +392,6 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
556
392
|
function removeWidgetInternal(viewWidget) {
|
|
557
393
|
model._renderer.removeActor(viewWidget);
|
|
558
394
|
|
|
559
|
-
removeFromSvgLayer(viewWidget);
|
|
560
395
|
viewWidget.delete();
|
|
561
396
|
}
|
|
562
397
|
|
|
@@ -592,7 +427,7 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
592
427
|
|
|
593
428
|
publicAPI.getSelectedDataForXY = /*#__PURE__*/function () {
|
|
594
429
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(x, y) {
|
|
595
|
-
var
|
|
430
|
+
var capturedRegion;
|
|
596
431
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
597
432
|
while (1) {
|
|
598
433
|
switch (_context2.prev = _context2.next) {
|
|
@@ -600,68 +435,37 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
600
435
|
model.selections = null;
|
|
601
436
|
|
|
602
437
|
if (!model.pickingEnabled) {
|
|
603
|
-
_context2.next =
|
|
604
|
-
break;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
i = 0;
|
|
608
|
-
|
|
609
|
-
case 3:
|
|
610
|
-
if (!(i < model.widgets.length)) {
|
|
611
|
-
_context2.next = 16;
|
|
438
|
+
_context2.next = 10;
|
|
612
439
|
break;
|
|
613
440
|
}
|
|
614
441
|
|
|
615
|
-
widget = model.widgets[i];
|
|
616
|
-
hoveredSVGReps = widget.getRepresentations().filter(function (r) {
|
|
617
|
-
return r.isA('vtkSVGRepresentation') && r.getHover() != null;
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
if (!hoveredSVGReps.length) {
|
|
621
|
-
_context2.next = 13;
|
|
622
|
-
break;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
selection = vtkSelectionNode.newInstance();
|
|
626
|
-
selection.getProperties().compositeID = hoveredSVGReps[0].getHover();
|
|
627
|
-
selection.getProperties().widget = widget;
|
|
628
|
-
selection.getProperties().representation = hoveredSVGReps[0];
|
|
629
|
-
model.selections = [selection];
|
|
630
|
-
return _context2.abrupt("return", publicAPI.getSelectedData());
|
|
631
|
-
|
|
632
|
-
case 13:
|
|
633
|
-
++i;
|
|
634
|
-
_context2.next = 3;
|
|
635
|
-
break;
|
|
636
|
-
|
|
637
|
-
case 16:
|
|
638
442
|
if (!(!model._capturedBuffers || model.captureOn === CaptureOn.MOUSE_MOVE)) {
|
|
639
|
-
_context2.next =
|
|
443
|
+
_context2.next = 5;
|
|
640
444
|
break;
|
|
641
445
|
}
|
|
642
446
|
|
|
643
|
-
_context2.next =
|
|
447
|
+
_context2.next = 5;
|
|
644
448
|
return captureBuffers(x, y, x, y);
|
|
645
449
|
|
|
646
|
-
case
|
|
450
|
+
case 5:
|
|
647
451
|
// or do we need a pixel that is outside the last capture?
|
|
648
452
|
capturedRegion = model._capturedBuffers.area;
|
|
649
453
|
|
|
650
454
|
if (!(x < capturedRegion[0] || x > capturedRegion[2] || y < capturedRegion[1] || y > capturedRegion[3])) {
|
|
651
|
-
_context2.next =
|
|
455
|
+
_context2.next = 9;
|
|
652
456
|
break;
|
|
653
457
|
}
|
|
654
458
|
|
|
655
|
-
_context2.next =
|
|
459
|
+
_context2.next = 9;
|
|
656
460
|
return captureBuffers(x, y, x, y);
|
|
657
461
|
|
|
658
|
-
case
|
|
462
|
+
case 9:
|
|
659
463
|
model.selections = model._capturedBuffers.generateSelection(x, y, x, y);
|
|
660
464
|
|
|
661
|
-
case
|
|
465
|
+
case 10:
|
|
662
466
|
return _context2.abrupt("return", publicAPI.getSelectedData());
|
|
663
467
|
|
|
664
|
-
case
|
|
468
|
+
case 11:
|
|
665
469
|
case "end":
|
|
666
470
|
return _context2.stop();
|
|
667
471
|
}
|
|
@@ -678,24 +482,7 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
678
482
|
vtkWarningMacro('updateSelectionFromXY is deprecated, please use getSelectedDataForXY');
|
|
679
483
|
|
|
680
484
|
if (model.pickingEnabled) {
|
|
681
|
-
//
|
|
682
|
-
for (var i = 0; i < model.widgets.length; ++i) {
|
|
683
|
-
var widget = model.widgets[i];
|
|
684
|
-
var hoveredSVGReps = widget.getRepresentations().filter(function (r) {
|
|
685
|
-
return r.isA('vtkSVGRepresentation') && r.getHover() != null;
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
if (hoveredSVGReps.length) {
|
|
689
|
-
var selection = vtkSelectionNode.newInstance();
|
|
690
|
-
selection.getProperties().compositeID = hoveredSVGReps[0].getHover();
|
|
691
|
-
selection.getProperties().widget = widget;
|
|
692
|
-
selection.getProperties().representation = hoveredSVGReps[0];
|
|
693
|
-
model.selections = [selection];
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
} // Then pick regular representations.
|
|
697
|
-
|
|
698
|
-
|
|
485
|
+
// Then pick regular representations.
|
|
699
486
|
if (model.captureOn === CaptureOn.MOUSE_MOVE) {
|
|
700
487
|
captureBuffers(x, y, x, y);
|
|
701
488
|
}
|
|
@@ -707,10 +494,10 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
707
494
|
var pageX = event.pageX,
|
|
708
495
|
pageY = event.pageY;
|
|
709
496
|
|
|
710
|
-
var _model$
|
|
711
|
-
top = _model$
|
|
712
|
-
left = _model$
|
|
713
|
-
height = _model$
|
|
497
|
+
var _model$_apiSpecificRe3 = model._apiSpecificRenderWindow.getCanvas().getBoundingClientRect(),
|
|
498
|
+
top = _model$_apiSpecificRe3.top,
|
|
499
|
+
left = _model$_apiSpecificRe3.left,
|
|
500
|
+
height = _model$_apiSpecificRe3.height;
|
|
714
501
|
|
|
715
502
|
var x = pageX - left;
|
|
716
503
|
var y = height - (pageY - top);
|
|
@@ -730,8 +517,7 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
730
517
|
|
|
731
518
|
var _model$selections$0$g2 = model.selections[0].getProperties(),
|
|
732
519
|
widget = _model$selections$0$g2.widget,
|
|
733
|
-
representation = _model$selections$0$g2.representation; //
|
|
734
|
-
// representation.
|
|
520
|
+
representation = _model$selections$0$g2.representation; // widget is undefined for handle representation.
|
|
735
521
|
|
|
736
522
|
|
|
737
523
|
if (model.previousSelectedData && model.previousSelectedData.prop === prop && model.previousSelectedData.widget === widget && model.previousSelectedData.compositeID === compositeID) {
|
|
@@ -781,26 +567,6 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
781
567
|
return publicAPI.grabFocus(null);
|
|
782
568
|
};
|
|
783
569
|
|
|
784
|
-
publicAPI.setUseSvgLayer = function (useSvgLayer) {
|
|
785
|
-
if (useSvgLayer !== model.useSvgLayer) {
|
|
786
|
-
model.useSvgLayer = useSvgLayer;
|
|
787
|
-
|
|
788
|
-
if (model._renderer) {
|
|
789
|
-
if (useSvgLayer) {
|
|
790
|
-
enableSvgLayer(); // force a render so svg widgets can be drawn
|
|
791
|
-
|
|
792
|
-
updateSvg();
|
|
793
|
-
} else {
|
|
794
|
-
disableSvgLayer();
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
return true;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
return false;
|
|
802
|
-
};
|
|
803
|
-
|
|
804
570
|
var superDelete = publicAPI.delete;
|
|
805
571
|
|
|
806
572
|
publicAPI.delete = function () {
|
|
@@ -828,7 +594,6 @@ var DEFAULT_VALUES = {
|
|
|
828
594
|
selections: null,
|
|
829
595
|
previousSelectedData: null,
|
|
830
596
|
widgetInFocus: null,
|
|
831
|
-
useSvgLayer: true,
|
|
832
597
|
captureOn: CaptureOn.MOUSE_MOVE
|
|
833
598
|
}; // ----------------------------------------------------------------------------
|
|
834
599
|
|
|
@@ -841,7 +606,7 @@ function extend(publicAPI, model) {
|
|
|
841
606
|
name: 'viewType',
|
|
842
607
|
enum: ViewTypes
|
|
843
608
|
}]);
|
|
844
|
-
macro.get(publicAPI, model, ['selections', 'widgets', 'viewId', 'pickingEnabled'
|
|
609
|
+
macro.get(publicAPI, model, ['selections', 'widgets', 'viewId', 'pickingEnabled']); // Object specific methods
|
|
845
610
|
|
|
846
611
|
vtkWidgetManager(publicAPI, model);
|
|
847
612
|
} // ----------------------------------------------------------------------------
|
|
@@ -5,7 +5,6 @@ import vtkCircleContextRepresentation from '../Representations/CircleContextRepr
|
|
|
5
5
|
import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
|
|
6
6
|
import vtkShapeWidget from './ShapeWidget.js';
|
|
7
7
|
import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
|
|
8
|
-
import vtkSVGLandmarkRepresentation from '../SVG/SVGLandmarkRepresentation.js';
|
|
9
8
|
import widgetBehavior from './EllipseWidget/behavior.js';
|
|
10
9
|
import generateState from './EllipseWidget/state.js';
|
|
11
10
|
import { BehaviorCategory, ShapeBehavior } from './ShapeWidget/Constants.js';
|
|
@@ -35,12 +34,6 @@ function vtkEllipseWidget(publicAPI, model) {
|
|
|
35
34
|
}, {
|
|
36
35
|
builder: vtkCircleContextRepresentation,
|
|
37
36
|
labels: ['ellipseHandle']
|
|
38
|
-
}, {
|
|
39
|
-
builder: vtkSVGLandmarkRepresentation,
|
|
40
|
-
initialValues: {
|
|
41
|
-
text: ''
|
|
42
|
-
},
|
|
43
|
-
labels: ['SVGtext']
|
|
44
37
|
}];
|
|
45
38
|
}
|
|
46
39
|
}; // --------------------------------------------------------------------------
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
1
|
import macro from '../../../macros.js';
|
|
3
2
|
|
|
4
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
-
|
|
6
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
3
|
function widgetBehavior(publicAPI, model) {
|
|
8
4
|
model.classHierarchy.push('vtkLabelWidgetProp');
|
|
9
5
|
model._isDragging = false; // --------------------------------------------------------------------------
|
|
@@ -12,9 +8,6 @@ function widgetBehavior(publicAPI, model) {
|
|
|
12
8
|
|
|
13
9
|
publicAPI.setText = function (text) {
|
|
14
10
|
model.widgetState.getText().setText(text);
|
|
15
|
-
model.representations[1].setCircleProps(_objectSpread(_objectSpread({}, model.representations[1].getCircleProps()), {}, {
|
|
16
|
-
visible: !text
|
|
17
|
-
}));
|
|
18
11
|
|
|
19
12
|
model._interactor.render();
|
|
20
13
|
};
|
|
@@ -2,11 +2,9 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
|
2
2
|
import macro from '../../macros.js';
|
|
3
3
|
import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
|
|
4
4
|
import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
|
|
5
|
-
import vtkSVGLandmarkRepresentation from '../SVG/SVGLandmarkRepresentation.js';
|
|
6
5
|
import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
|
|
7
6
|
import widgetBehavior from './LabelWidget/behavior.js';
|
|
8
7
|
import generateState from './LabelWidget/state.js';
|
|
9
|
-
import { VerticalTextAlignment } from '../SVG/SVGLandmarkRepresentation/Constants.js';
|
|
10
8
|
import { ViewTypes } from '../Core/WidgetManager/Constants.js';
|
|
11
9
|
|
|
12
10
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -21,7 +19,7 @@ function vtkLabelWidget(publicAPI, model) {
|
|
|
21
19
|
var superClass = _objectSpread({}, publicAPI); // --- Widget Requirement ---------------------------------------------------
|
|
22
20
|
|
|
23
21
|
|
|
24
|
-
model.methodsToLink = ['
|
|
22
|
+
model.methodsToLink = ['scaleInPixels'];
|
|
25
23
|
|
|
26
24
|
publicAPI.getRepresentationsForViewType = function (viewType) {
|
|
27
25
|
switch (viewType) {
|
|
@@ -33,21 +31,6 @@ function vtkLabelWidget(publicAPI, model) {
|
|
|
33
31
|
return [{
|
|
34
32
|
builder: vtkSphereHandleRepresentation,
|
|
35
33
|
labels: ['moveHandle']
|
|
36
|
-
}, {
|
|
37
|
-
builder: vtkSVGLandmarkRepresentation,
|
|
38
|
-
initialValues: {
|
|
39
|
-
circleProps: {
|
|
40
|
-
visible: true
|
|
41
|
-
},
|
|
42
|
-
textProps: {
|
|
43
|
-
'text-anchor': 'middle',
|
|
44
|
-
verticalAlign: VerticalTextAlignment.MIDDLE
|
|
45
|
-
},
|
|
46
|
-
strokeFontProperties: {
|
|
47
|
-
fontStyle: 'bold'
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
labels: ['SVGtext']
|
|
51
34
|
}];
|
|
52
35
|
}
|
|
53
36
|
}; // --- Public methods -------------------------------------------------------
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
1
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
3
2
|
import Constants from './Constants.js';
|
|
4
3
|
import macro from '../../../macros.js';
|
|
5
4
|
import { s as subtract, l as add, m as normalize } from '../../../Common/Core/Math/index.js';
|
|
6
5
|
import { getNumberOfPlacedHandles, isHandlePlaced, calculateTextPosition, updateTextPosition, getPoint } from './helpers.js';
|
|
7
6
|
|
|
8
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
-
|
|
10
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
7
|
var ShapeType = Constants.ShapeType; // Total number of points to place
|
|
12
8
|
|
|
13
9
|
var MAX_POINTS = 2;
|
|
@@ -70,44 +66,6 @@ function widgetBehavior(publicAPI, model) {
|
|
|
70
66
|
// Text methods
|
|
71
67
|
// --------------------------------------------------------------------------
|
|
72
68
|
|
|
73
|
-
/**
|
|
74
|
-
* check for handle 2 position in comparison to handle 1 position
|
|
75
|
-
* and sets text offset to not overlap on the line representation
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
function getOffsetDirectionForTextPosition() {
|
|
80
|
-
var pos1 = publicAPI.getHandle(0).getOrigin();
|
|
81
|
-
var pos2 = publicAPI.getHandle(1).getOrigin();
|
|
82
|
-
var dySign = 1;
|
|
83
|
-
|
|
84
|
-
if (pos1 && pos2) {
|
|
85
|
-
if (pos1[0] <= pos2[0]) {
|
|
86
|
-
dySign = pos1[1] <= pos2[1] ? 1 : -1;
|
|
87
|
-
} else {
|
|
88
|
-
dySign = pos1[1] <= pos2[1] ? -1 : 1;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return dySign;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* place SVGText on line according to both handle positions
|
|
96
|
-
* which purpose is to never have text representation overlapping
|
|
97
|
-
* on PolyLine representation
|
|
98
|
-
* */
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
publicAPI.placeText = function () {
|
|
102
|
-
var dySign = getOffsetDirectionForTextPosition();
|
|
103
|
-
|
|
104
|
-
var textPropsCp = _objectSpread({}, model.representations[3].getTextProps());
|
|
105
|
-
|
|
106
|
-
textPropsCp.dy = dySign * Math.abs(textPropsCp.dy);
|
|
107
|
-
model.representations[3].setTextProps(textPropsCp);
|
|
108
|
-
|
|
109
|
-
model._interactor.render();
|
|
110
|
-
};
|
|
111
69
|
|
|
112
70
|
publicAPI.setText = function (text) {
|
|
113
71
|
model.widgetState.getText().setText(text);
|
|
@@ -211,7 +169,6 @@ function widgetBehavior(publicAPI, model) {
|
|
|
211
169
|
}
|
|
212
170
|
|
|
213
171
|
if (handleIndex === 1) {
|
|
214
|
-
publicAPI.placeText();
|
|
215
172
|
publicAPI.loseFocus();
|
|
216
173
|
}
|
|
217
174
|
}; // --------------------------------------------------------------------------
|
|
@@ -289,7 +246,6 @@ function widgetBehavior(publicAPI, model) {
|
|
|
289
246
|
if (model._isDragging && publicAPI.isPlaced()) {
|
|
290
247
|
var wasTextActive = model.widgetState.getText().getActive(); // Recompute offsets
|
|
291
248
|
|
|
292
|
-
publicAPI.placeText();
|
|
293
249
|
model.widgetState.deactivate();
|
|
294
250
|
model.activeState = null;
|
|
295
251
|
|
|
@@ -5,7 +5,6 @@ import generateState from './LineWidget/state.js';
|
|
|
5
5
|
import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
|
|
6
6
|
import vtkArrowHandleRepresentation from '../Representations/ArrowHandleRepresentation.js';
|
|
7
7
|
import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
|
|
8
|
-
import vtkSVGLandmarkRepresentation from '../SVG/SVGLandmarkRepresentation.js';
|
|
9
8
|
import vtkPolyLineRepresentation from '../Representations/PolyLineRepresentation.js';
|
|
10
9
|
import widgetBehavior from './LineWidget/behavior.js';
|
|
11
10
|
import { Behavior } from '../Representations/WidgetRepresentation/Constants.js';
|
|
@@ -107,16 +106,6 @@ function vtkLineWidget(publicAPI, model) {
|
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
|
-
}, {
|
|
111
|
-
builder: vtkSVGLandmarkRepresentation,
|
|
112
|
-
initialValues: {
|
|
113
|
-
text: '',
|
|
114
|
-
textProps: {
|
|
115
|
-
dx: 12,
|
|
116
|
-
dy: -12
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
labels: ['SVGtext']
|
|
120
109
|
}, {
|
|
121
110
|
builder: vtkPolyLineRepresentation,
|
|
122
111
|
labels: ['handle1', 'handle2', 'moveHandle'],
|
|
@@ -4,7 +4,6 @@ import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
|
|
|
4
4
|
import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
|
|
5
5
|
import vtkPolyLineRepresentation from '../Representations/PolyLineRepresentation.js';
|
|
6
6
|
import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
|
|
7
|
-
import vtkSVGLandmarkRepresentation from '../SVG/SVGLandmarkRepresentation.js';
|
|
8
7
|
import widgetBehavior from './PolyLineWidget/behavior.js';
|
|
9
8
|
import generateState from './PolyLineWidget/state.js';
|
|
10
9
|
import { ViewTypes } from '../Core/WidgetManager/Constants.js';
|
|
@@ -36,15 +35,6 @@ function vtkPolyLineWidget(publicAPI, model) {
|
|
|
36
35
|
}, {
|
|
37
36
|
builder: vtkSphereHandleRepresentation,
|
|
38
37
|
labels: ['moveHandle']
|
|
39
|
-
}, {
|
|
40
|
-
builder: vtkSVGLandmarkRepresentation,
|
|
41
|
-
initialValues: {
|
|
42
|
-
textProps: {
|
|
43
|
-
dx: 12,
|
|
44
|
-
dy: -12
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
labels: ['handles']
|
|
48
38
|
}, {
|
|
49
39
|
builder: vtkPolyLineRepresentation,
|
|
50
40
|
labels: ['handles', 'moveHandle']
|
|
@@ -5,7 +5,6 @@ import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
|
|
|
5
5
|
import vtkShapeWidget from './ShapeWidget.js';
|
|
6
6
|
import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
|
|
7
7
|
import vtkRectangleContextRepresentation from '../Representations/RectangleContextRepresentation.js';
|
|
8
|
-
import vtkSVGLandmarkRepresentation from '../SVG/SVGLandmarkRepresentation.js';
|
|
9
8
|
import widgetBehavior from './RectangleWidget/behavior.js';
|
|
10
9
|
import generateState from './RectangleWidget/state.js';
|
|
11
10
|
import { BehaviorCategory, ShapeBehavior } from './ShapeWidget/Constants.js';
|
|
@@ -34,12 +33,6 @@ function vtkRectangleWidget(publicAPI, model) {
|
|
|
34
33
|
}, {
|
|
35
34
|
builder: vtkRectangleContextRepresentation,
|
|
36
35
|
labels: ['rectangleHandle']
|
|
37
|
-
}, {
|
|
38
|
-
builder: vtkSVGLandmarkRepresentation,
|
|
39
|
-
initialValues: {
|
|
40
|
-
text: ''
|
|
41
|
-
},
|
|
42
|
-
labels: ['SVGtext']
|
|
43
36
|
}];
|
|
44
37
|
}
|
|
45
38
|
}; // --------------------------------------------------------------------------
|
|
@@ -12,7 +12,7 @@ function vtkShapeWidget(publicAPI, model) {
|
|
|
12
12
|
|
|
13
13
|
var superClass = _objectSpread({}, publicAPI);
|
|
14
14
|
|
|
15
|
-
model.methodsToLink = ['scaleInPixels'
|
|
15
|
+
model.methodsToLink = ['scaleInPixels'];
|
|
16
16
|
|
|
17
17
|
publicAPI.setManipulator = function (manipulator) {
|
|
18
18
|
superClass.setManipulator(manipulator);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitware/vtk.js",
|
|
3
|
-
"version": "26.0.0-beta.
|
|
3
|
+
"version": "26.0.0-beta.2",
|
|
4
4
|
"description": "Visualization Toolkit for the Web",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"3d",
|
|
@@ -112,6 +112,7 @@
|
|
|
112
112
|
"rollup-plugin-svgo": "1.1.0",
|
|
113
113
|
"rollup-plugin-web-worker-loader": "1.6.1",
|
|
114
114
|
"semantic-release": "19.0.3",
|
|
115
|
+
"snabbdom": "^3.5.1",
|
|
115
116
|
"string-replace-loader": "3.1.0",
|
|
116
117
|
"style-loader": "3.3.1",
|
|
117
118
|
"tape": "5.5.3",
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
-
|
|
3
|
-
var SVG_XMLNS = 'http://www.w3.org/2000/svg';
|
|
4
|
-
|
|
5
|
-
function attrDelta(oldObj, newObj) {
|
|
6
|
-
var set = [];
|
|
7
|
-
var remove = [];
|
|
8
|
-
var oldKeysArray = Object.keys(oldObj);
|
|
9
|
-
var newKeysArray = Object.keys(newObj);
|
|
10
|
-
var oldKeys = new Set(oldKeysArray);
|
|
11
|
-
var newKeys = new Set(newKeysArray);
|
|
12
|
-
|
|
13
|
-
for (var i = 0; i < oldKeysArray.length; i++) {
|
|
14
|
-
var key = oldKeysArray[i];
|
|
15
|
-
|
|
16
|
-
if (newKeys.has(key)) {
|
|
17
|
-
if (oldObj[key] !== newObj[key]) {
|
|
18
|
-
set.push([key, newObj[key]]);
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
remove.push(key);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
for (var _i = 0; _i < newKeysArray.length; _i++) {
|
|
26
|
-
var _key = newKeysArray[_i];
|
|
27
|
-
|
|
28
|
-
if (!oldKeys.has(_key)) {
|
|
29
|
-
set.push([_key, newObj[_key]]);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return [set, remove];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function render(vnode) {
|
|
37
|
-
var node = document.createElementNS(SVG_XMLNS, vnode.name);
|
|
38
|
-
var keys = Object.keys(vnode.attrs);
|
|
39
|
-
|
|
40
|
-
for (var i = 0; i < keys.length; i++) {
|
|
41
|
-
var key = keys[i];
|
|
42
|
-
node.setAttribute(key, vnode.attrs[key]);
|
|
43
|
-
} // TODO: support removing event listener (e.g. use snabbdom)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Object.keys(vnode.eventListeners).forEach(function (key) {
|
|
47
|
-
node.addEventListener(key, vnode.eventListeners[key]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
if (vnode.textContent) {
|
|
51
|
-
node.textContent = vnode.textContent;
|
|
52
|
-
} else {
|
|
53
|
-
for (var _i2 = 0; _i2 < vnode.children.length; _i2++) {
|
|
54
|
-
node.appendChild(render(vnode.children[_i2]));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return node;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Returns a set of patch functions to be applied to a document node.
|
|
62
|
-
*
|
|
63
|
-
* Patch functions must return the effective result node.
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
function diff(oldVTree, newVTree) {
|
|
67
|
-
if (newVTree.textContent !== null && newVTree.children.length) {
|
|
68
|
-
throw new Error('Tree cannot have both children and textContent!');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (!oldVTree) {
|
|
72
|
-
return [function () {
|
|
73
|
-
return render(newVTree);
|
|
74
|
-
}];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!newVTree) {
|
|
78
|
-
return [function (node) {
|
|
79
|
-
return node.remove();
|
|
80
|
-
}];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (oldVTree.name !== newVTree.name) {
|
|
84
|
-
return [function (node) {
|
|
85
|
-
var newNode = render(newVTree);
|
|
86
|
-
node.replaceWith(newNode);
|
|
87
|
-
return newNode;
|
|
88
|
-
}];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
var patchFns = [];
|
|
92
|
-
|
|
93
|
-
var _attrDelta = attrDelta(oldVTree.attrs, newVTree.attrs),
|
|
94
|
-
_attrDelta2 = _slicedToArray(_attrDelta, 2),
|
|
95
|
-
attrsSet = _attrDelta2[0],
|
|
96
|
-
attrsRemove = _attrDelta2[1];
|
|
97
|
-
|
|
98
|
-
if (attrsSet.length || attrsRemove.length) {
|
|
99
|
-
patchFns.push(function (node) {
|
|
100
|
-
for (var i = 0; i < attrsSet.length; i++) {
|
|
101
|
-
var _attrsSet$i = _slicedToArray(attrsSet[i], 2),
|
|
102
|
-
name = _attrsSet$i[0],
|
|
103
|
-
value = _attrsSet$i[1];
|
|
104
|
-
|
|
105
|
-
node.setAttribute(name, value);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
for (var _i3 = 0; _i3 < attrsRemove.length; _i3++) {
|
|
109
|
-
var _name = attrsRemove[_i3];
|
|
110
|
-
node.removeAttribute(_name);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return node;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (oldVTree.textContent !== newVTree.textContent && newVTree.textContent !== null) {
|
|
118
|
-
patchFns.push(function (node) {
|
|
119
|
-
node.textContent = newVTree.textContent;
|
|
120
|
-
return node;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (newVTree.textContent === null) {
|
|
125
|
-
var min = Math.min(oldVTree.children.length, newVTree.children.length);
|
|
126
|
-
|
|
127
|
-
var _loop = function _loop(i) {
|
|
128
|
-
var childPatches = diff(oldVTree.children[i], newVTree.children[i]);
|
|
129
|
-
patchFns.push(function (node) {
|
|
130
|
-
for (var p = 0; p < childPatches.length; p++) {
|
|
131
|
-
childPatches[p](node.children[i]);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return node;
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
for (var i = 0; i < min; i++) {
|
|
139
|
-
_loop(i);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (oldVTree.children.length < newVTree.children.length) {
|
|
143
|
-
var _loop2 = function _loop2(_i4) {
|
|
144
|
-
patchFns.push(function (node) {
|
|
145
|
-
node.appendChild(render(newVTree.children[_i4]));
|
|
146
|
-
return node;
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
for (var _i4 = min; _i4 < newVTree.children.length; _i4++) {
|
|
151
|
-
_loop2(_i4);
|
|
152
|
-
}
|
|
153
|
-
} else {
|
|
154
|
-
var _loop3 = function _loop3(_i5) {
|
|
155
|
-
patchFns.push(function (node) {
|
|
156
|
-
node.children[_i5].remove();
|
|
157
|
-
|
|
158
|
-
return node;
|
|
159
|
-
});
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// always delete nodes in reverse
|
|
163
|
-
for (var _i5 = oldVTree.children.length - 1; _i5 >= min; _i5--) {
|
|
164
|
-
_loop3(_i5);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return patchFns;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export { diff, render };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
var VerticalTextAlignment = {
|
|
2
|
-
TOP: 'TOP',
|
|
3
|
-
BOTTOM: 'BOTTOM',
|
|
4
|
-
MIDDLE: 'MIDDLE'
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* fontSize can be a number or a string representing a size in px
|
|
8
|
-
* @param {Number|String} fontSize
|
|
9
|
-
* @returns Number representing the fontSize in pixels
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
function fontSizeToPixels(fontProperties) {
|
|
13
|
-
var defaultFontSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 16;
|
|
14
|
-
|
|
15
|
-
if (fontProperties != null && fontProperties.fontSize) {
|
|
16
|
-
if (typeof fontProperties.fontSize === 'string') {
|
|
17
|
-
if (fontProperties.fontSize.slice(-2) === 'px') {
|
|
18
|
-
return window.devicePixelRatio * parseInt(fontProperties.fontSize, 10);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return window.devicePixelRatio * fontProperties.fontSize;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return window.devicePixelRatio * defaultFontSize;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { VerticalTextAlignment, VerticalTextAlignment as default, fontSizeToPixels };
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import macro from '../../macros.js';
|
|
3
|
-
import vtkSVGRepresentation from './SVGRepresentation.js';
|
|
4
|
-
import { fontSizeToPixels, VerticalTextAlignment } from './SVGLandmarkRepresentation/Constants.js';
|
|
5
|
-
|
|
6
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
-
|
|
8
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
9
|
-
var createSvgElement = vtkSVGRepresentation.createSvgElement; // ----------------------------------------------------------------------------
|
|
10
|
-
// vtkSVGLandmarkRepresentation
|
|
11
|
-
// ----------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
function vtkSVGLandmarkRepresentation(publicAPI, model) {
|
|
14
|
-
// Set our className
|
|
15
|
-
model.classHierarchy.push('vtkSVGLandmarkRepresentation');
|
|
16
|
-
|
|
17
|
-
publicAPI.render = function () {
|
|
18
|
-
var list = publicAPI.getRepresentationStates();
|
|
19
|
-
|
|
20
|
-
if (!list.length) {
|
|
21
|
-
return createSvgElement('g');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var coords = [];
|
|
25
|
-
var texts = [];
|
|
26
|
-
list.forEach(function (state, index) {
|
|
27
|
-
if (state.getOrigin && state.getOrigin() && state.getVisible && state.getVisible()) {
|
|
28
|
-
coords.push(state.getOrigin());
|
|
29
|
-
texts.push(state.getText ? state.getText() : "L".concat(index));
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
var state = list[0];
|
|
33
|
-
var isActive = state.getActive();
|
|
34
|
-
return publicAPI.worldPointsToPixelSpace(coords).then(function (pixelSpace) {
|
|
35
|
-
var points2d = pixelSpace.coords;
|
|
36
|
-
var winHeight = pixelSpace.windowSize[1];
|
|
37
|
-
var root = createSvgElement('g');
|
|
38
|
-
|
|
39
|
-
var _loop = function _loop(i) {
|
|
40
|
-
var xy = points2d[i];
|
|
41
|
-
|
|
42
|
-
if (Number.isNaN(xy[0]) || Number.isNaN(xy[1])) {
|
|
43
|
-
return "continue"; // eslint-disable-line
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var x = xy[0];
|
|
47
|
-
var y = winHeight - xy[1];
|
|
48
|
-
|
|
49
|
-
if (model.circleProps && model.circleProps.visible) {
|
|
50
|
-
var circle = publicAPI.createListenableSvgElement('circle', i);
|
|
51
|
-
Object.keys(model.circleProps || {}).forEach(function (prop) {
|
|
52
|
-
return circle.setAttribute(prop, model.circleProps[prop]);
|
|
53
|
-
});
|
|
54
|
-
circle.setAttribute('cx', x);
|
|
55
|
-
circle.setAttribute('cy', y);
|
|
56
|
-
root.appendChild(circle);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!texts[i]) {
|
|
60
|
-
texts[i] = '';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
var splitText = texts[i].split('\n');
|
|
64
|
-
var fontSize = fontSizeToPixels(model.fontProperties);
|
|
65
|
-
splitText.forEach(function (subText, j) {
|
|
66
|
-
var _model$textProps, _model$textProps2;
|
|
67
|
-
|
|
68
|
-
var text = publicAPI.createListenableSvgElement('text', i);
|
|
69
|
-
Object.keys(model.textProps || {}).forEach(function (prop) {
|
|
70
|
-
text.setAttribute(prop, model.textProps[prop]);
|
|
71
|
-
});
|
|
72
|
-
text.setAttribute('x', x);
|
|
73
|
-
text.setAttribute('y', y); // Vertical offset (dy) calculation based on VerticalTextAlignment
|
|
74
|
-
|
|
75
|
-
var dy = ((_model$textProps = model.textProps) === null || _model$textProps === void 0 ? void 0 : _model$textProps.dy) || 0;
|
|
76
|
-
|
|
77
|
-
switch ((_model$textProps2 = model.textProps) === null || _model$textProps2 === void 0 ? void 0 : _model$textProps2.verticalAlign) {
|
|
78
|
-
case VerticalTextAlignment.MIDDLE:
|
|
79
|
-
dy -= fontSize * (0.5 * splitText.length - j - 1);
|
|
80
|
-
break;
|
|
81
|
-
|
|
82
|
-
case VerticalTextAlignment.TOP:
|
|
83
|
-
dy += fontSize * (j + 1);
|
|
84
|
-
break;
|
|
85
|
-
|
|
86
|
-
case VerticalTextAlignment.BOTTOM:
|
|
87
|
-
default:
|
|
88
|
-
dy -= fontSize * (splitText.length - j - 1);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
text.setAttribute('dy', dy);
|
|
93
|
-
text.setAttribute('font-size', fontSize);
|
|
94
|
-
|
|
95
|
-
if (model.fontProperties && model.fontProperties.fontFamily) {
|
|
96
|
-
text.setAttribute('font-family', model.fontProperties.fontFamily);
|
|
97
|
-
} else if (isActive && model.strokeFontProperties && model.strokeFontProperties.fontFamily) {
|
|
98
|
-
text.setAttribute('font-family', model.strokeFontProperties.fontFamily);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (model.fontProperties && model.fontProperties.fontStyle) {
|
|
102
|
-
text.setAttribute('font-weight', model.fontProperties.fontStyle);
|
|
103
|
-
} else if (isActive && model.strokeFontProperties && model.strokeFontProperties.fontStyle) {
|
|
104
|
-
text.setAttribute('font-weight', model.strokeFontProperties.fontStyle);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (model.fontProperties && model.fontProperties.fontColor) {
|
|
108
|
-
text.setAttribute('fill', model.fontProperties.fontColor);
|
|
109
|
-
} else if (isActive && model.strokeFontProperties && model.strokeFontProperties.fontColor) {
|
|
110
|
-
text.setAttribute('fill', model.strokeFontProperties.fontColor);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
text.textContent = subText;
|
|
114
|
-
root.appendChild(text);
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
for (var i = 0; i < points2d.length; i++) {
|
|
119
|
-
var _ret = _loop(i);
|
|
120
|
-
|
|
121
|
-
if (_ret === "continue") continue;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return root;
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
} // ----------------------------------------------------------------------------
|
|
128
|
-
// Object factory
|
|
129
|
-
// ----------------------------------------------------------------------------
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* textProps can contain any "svg" attribute (e.g. text-anchor, text-align,
|
|
133
|
-
* alignment-baseline...)
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
function defaultValues(initialValues) {
|
|
138
|
-
return _objectSpread(_objectSpread({}, initialValues), {}, {
|
|
139
|
-
circleProps: _objectSpread({
|
|
140
|
-
visible: false,
|
|
141
|
-
r: 5,
|
|
142
|
-
stroke: 'red',
|
|
143
|
-
fill: 'red'
|
|
144
|
-
}, initialValues.circleProps),
|
|
145
|
-
fontProperties: _objectSpread({
|
|
146
|
-
fontColor: 'white'
|
|
147
|
-
}, initialValues.fontProperties)
|
|
148
|
-
});
|
|
149
|
-
} // ----------------------------------------------------------------------------
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
function extend(publicAPI, model) {
|
|
153
|
-
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
154
|
-
vtkSVGRepresentation.extend(publicAPI, model, defaultValues(initialValues));
|
|
155
|
-
macro.setGet(publicAPI, model, ['circleProps', 'fontProperties', 'strokeFontProperties', 'textProps']); // Object specific methods
|
|
156
|
-
|
|
157
|
-
vtkSVGLandmarkRepresentation(publicAPI, model);
|
|
158
|
-
} // ----------------------------------------------------------------------------
|
|
159
|
-
|
|
160
|
-
var newInstance = macro.newInstance(extend, 'vtkSVGLandmarkRepresentation'); // ----------------------------------------------------------------------------
|
|
161
|
-
|
|
162
|
-
var vtkSVGLandmarkRepresentation$1 = {
|
|
163
|
-
extend: extend,
|
|
164
|
-
newInstance: newInstance
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
export { vtkSVGLandmarkRepresentation$1 as default, extend, newInstance };
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import macro from '../../macros.js';
|
|
2
|
-
import vtkPolyData from '../../Common/DataModel/PolyData.js';
|
|
3
|
-
import vtkActor from '../../Rendering/Core/Actor.js';
|
|
4
|
-
import vtkPixelSpaceCallbackMapper from '../../Rendering/Core/PixelSpaceCallbackMapper.js';
|
|
5
|
-
import vtkWidgetRepresentation from '../Representations/WidgetRepresentation.js';
|
|
6
|
-
import { Behavior } from '../Representations/WidgetRepresentation/Constants.js';
|
|
7
|
-
import { RenderingTypes } from '../Core/WidgetManager/Constants.js';
|
|
8
|
-
|
|
9
|
-
var SVG_XMLNS = 'http://www.w3.org/2000/svg'; // ----------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
function createSvgElement(tag) {
|
|
12
|
-
return {
|
|
13
|
-
name: tag,
|
|
14
|
-
attrs: {},
|
|
15
|
-
eventListeners: {},
|
|
16
|
-
// implies no children if set
|
|
17
|
-
textContent: null,
|
|
18
|
-
children: [],
|
|
19
|
-
setAttribute: function setAttribute(attr, val) {
|
|
20
|
-
this.attrs[attr] = val;
|
|
21
|
-
},
|
|
22
|
-
removeAttribute: function removeAttribute(attr) {
|
|
23
|
-
delete this.attrs[attr];
|
|
24
|
-
},
|
|
25
|
-
appendChild: function appendChild(n) {
|
|
26
|
-
this.children.push(n);
|
|
27
|
-
},
|
|
28
|
-
addEventListeners: function addEventListeners(event, callback) {
|
|
29
|
-
this.eventListeners[event] = callback;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
} // ----------------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function createSvgDomElement(tag) {
|
|
36
|
-
return document.createElementNS(SVG_XMLNS, tag);
|
|
37
|
-
} // ----------------------------------------------------------------------------
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
function defer() {
|
|
41
|
-
var resolve;
|
|
42
|
-
var reject;
|
|
43
|
-
var promise = new Promise(function (res, rej) {
|
|
44
|
-
resolve = res;
|
|
45
|
-
reject = rej;
|
|
46
|
-
});
|
|
47
|
-
return {
|
|
48
|
-
promise: promise,
|
|
49
|
-
resolve: resolve,
|
|
50
|
-
reject: reject
|
|
51
|
-
};
|
|
52
|
-
} // ----------------------------------------------------------------------------
|
|
53
|
-
// vtkSVGRepresentation
|
|
54
|
-
// ----------------------------------------------------------------------------
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
function vtkSVGRepresentation(publicAPI, model) {
|
|
58
|
-
// Set our className
|
|
59
|
-
model.classHierarchy.push('vtkSVGRepresentation');
|
|
60
|
-
var deferred = null;
|
|
61
|
-
model.psActor = vtkActor.newInstance({
|
|
62
|
-
pickable: false,
|
|
63
|
-
_parentProp: publicAPI
|
|
64
|
-
});
|
|
65
|
-
model.psMapper = vtkPixelSpaceCallbackMapper.newInstance();
|
|
66
|
-
model.points = vtkPolyData.newInstance();
|
|
67
|
-
model.psMapper.setInputData(model.points);
|
|
68
|
-
model.psActor.setMapper(model.psMapper);
|
|
69
|
-
model.psMapper.setCallback(function () {
|
|
70
|
-
if (deferred) {
|
|
71
|
-
var d = deferred;
|
|
72
|
-
deferred = null;
|
|
73
|
-
d.resolve({
|
|
74
|
-
coords: arguments.length <= 0 ? undefined : arguments[0],
|
|
75
|
-
camera: arguments.length <= 1 ? undefined : arguments[1],
|
|
76
|
-
aspect: arguments.length <= 2 ? undefined : arguments[2],
|
|
77
|
-
depthValues: arguments.length <= 3 ? undefined : arguments[3],
|
|
78
|
-
windowSize: arguments.length <= 4 ? undefined : arguments[4]
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
publicAPI.addActor(model.psActor); // --------------------------------------------------------------------------
|
|
83
|
-
|
|
84
|
-
publicAPI.worldPointsToPixelSpace = function (points3d) {
|
|
85
|
-
var pts = new Float32Array(points3d.length * 3);
|
|
86
|
-
|
|
87
|
-
for (var i = 0; i < points3d.length; i++) {
|
|
88
|
-
pts[i * 3 + 0] = points3d[i][0];
|
|
89
|
-
pts[i * 3 + 1] = points3d[i][1];
|
|
90
|
-
pts[i * 3 + 2] = points3d[i][2];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
model.points.getPoints().setData(pts);
|
|
94
|
-
model.points.modified();
|
|
95
|
-
deferred = defer();
|
|
96
|
-
return deferred.promise;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
publicAPI.createListenableSvgElement = function (tag, id) {
|
|
100
|
-
var element = createSvgElement(tag);
|
|
101
|
-
|
|
102
|
-
if (model.pickable) {
|
|
103
|
-
element.addEventListeners('mouseenter', function () {
|
|
104
|
-
publicAPI.setHover(id);
|
|
105
|
-
});
|
|
106
|
-
element.addEventListeners('mouseleave', function () {
|
|
107
|
-
if (publicAPI.getHover() === id) {
|
|
108
|
-
publicAPI.setHover(null);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return element;
|
|
114
|
-
}; // --------------------------------------------------------------------------
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
publicAPI.updateActorVisibility = function () {
|
|
118
|
-
arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : RenderingTypes.FRONT_BUFFER;
|
|
119
|
-
var ctxVisible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
120
|
-
var handleVisible = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
121
|
-
|
|
122
|
-
if (model.behavior === Behavior.CONTEXT) {
|
|
123
|
-
publicAPI.setVisibility(ctxVisible);
|
|
124
|
-
} else if (model.behavior === Behavior.HANDLE) {
|
|
125
|
-
publicAPI.setVisibility(handleVisible);
|
|
126
|
-
}
|
|
127
|
-
}; // --------------------------------------------------------------------------
|
|
128
|
-
// Subclasses must implement this method
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
publicAPI.render = function () {
|
|
132
|
-
throw new Error('Not implemented');
|
|
133
|
-
};
|
|
134
|
-
} // ----------------------------------------------------------------------------
|
|
135
|
-
// Object factory
|
|
136
|
-
// ----------------------------------------------------------------------------
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* 'hover' is not null when a pickable SVG element is mouse hovered.
|
|
140
|
-
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
var DEFAULT_VALUES = {
|
|
144
|
-
visibility: true
|
|
145
|
-
}; // ----------------------------------------------------------------------------
|
|
146
|
-
|
|
147
|
-
function extend(publicAPI, model) {
|
|
148
|
-
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
149
|
-
Object.assign(model, DEFAULT_VALUES, initialValues); // Extend methods
|
|
150
|
-
|
|
151
|
-
vtkWidgetRepresentation.extend(publicAPI, model, initialValues);
|
|
152
|
-
macro.setGet(publicAPI, model, ['visibility', 'hover']); // Object specific methods
|
|
153
|
-
|
|
154
|
-
vtkSVGRepresentation(publicAPI, model);
|
|
155
|
-
} // ----------------------------------------------------------------------------
|
|
156
|
-
|
|
157
|
-
var vtkSVGRepresentation$1 = {
|
|
158
|
-
extend: extend,
|
|
159
|
-
createSvgElement: createSvgElement,
|
|
160
|
-
createSvgDomElement: createSvgDomElement
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
export { vtkSVGRepresentation$1 as default, extend };
|