@hpcc-js/common 2.65.0 → 2.66.1

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.
Files changed (93) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +59 -59
  3. package/dist/index.es6.js +7098 -7070
  4. package/dist/index.es6.js.map +1 -1
  5. package/dist/index.js +7141 -7107
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.min.js +1 -1
  8. package/dist/index.min.js.map +1 -1
  9. package/package.json +21 -38
  10. package/src/CanvasWidget.ts +31 -31
  11. package/src/Class.ts +67 -67
  12. package/src/Database.ts +856 -856
  13. package/src/Entity.ts +235 -235
  14. package/src/EntityCard.ts +66 -66
  15. package/src/EntityPin.ts +103 -103
  16. package/src/EntityRect.css +15 -15
  17. package/src/EntityRect.ts +236 -236
  18. package/src/EntityVertex.ts +86 -86
  19. package/src/FAChar.css +2 -2
  20. package/src/FAChar.ts +82 -82
  21. package/src/HTMLWidget.ts +191 -191
  22. package/src/IList.ts +4 -4
  23. package/src/IMenu.ts +5 -5
  24. package/src/Icon.css +9 -9
  25. package/src/Icon.ts +164 -164
  26. package/src/Image.ts +95 -95
  27. package/src/List.css +13 -13
  28. package/src/List.ts +99 -99
  29. package/src/Menu.css +23 -23
  30. package/src/Menu.ts +138 -138
  31. package/src/Palette.ts +341 -341
  32. package/src/Platform.ts +125 -125
  33. package/src/ProgressBar.ts +105 -105
  34. package/src/PropertyExt.ts +793 -793
  35. package/src/ResizeSurface.css +39 -39
  36. package/src/ResizeSurface.ts +221 -221
  37. package/src/SVGWidget.ts +567 -567
  38. package/src/SVGZoomWidget.css +12 -12
  39. package/src/SVGZoomWidget.ts +416 -416
  40. package/src/Shape.css +3 -3
  41. package/src/Shape.ts +186 -186
  42. package/src/Surface.css +35 -35
  43. package/src/Surface.ts +350 -350
  44. package/src/Text.css +4 -4
  45. package/src/Text.ts +131 -131
  46. package/src/TextBox.css +4 -4
  47. package/src/TextBox.ts +168 -168
  48. package/src/TitleBar.css +99 -99
  49. package/src/TitleBar.ts +401 -401
  50. package/src/Transition.ts +45 -45
  51. package/src/Utility.ts +820 -820
  52. package/src/Widget.css +8 -8
  53. package/src/Widget.ts +712 -712
  54. package/src/WidgetArray.ts +13 -13
  55. package/src/__package__.ts +2 -2
  56. package/src/index.ts +55 -55
  57. package/types/CanvasWidget.d.ts +8 -8
  58. package/types/Class.d.ts +12 -12
  59. package/types/Database.d.ts +136 -136
  60. package/types/Entity.d.ts +88 -88
  61. package/types/EntityCard.d.ts +13 -13
  62. package/types/EntityPin.d.ts +22 -22
  63. package/types/EntityRect.d.ts +45 -45
  64. package/types/EntityVertex.d.ts +30 -30
  65. package/types/FAChar.d.ts +29 -29
  66. package/types/HTMLWidget.d.ts +27 -27
  67. package/types/IList.d.ts +4 -4
  68. package/types/IMenu.d.ts +5 -5
  69. package/types/Icon.d.ts +62 -62
  70. package/types/Image.d.ts +33 -33
  71. package/types/List.d.ts +15 -15
  72. package/types/Menu.d.ts +28 -28
  73. package/types/Palette.d.ts +19 -19
  74. package/types/Platform.d.ts +5 -5
  75. package/types/ProgressBar.d.ts +21 -21
  76. package/types/PropertyExt.d.ts +114 -114
  77. package/types/ResizeSurface.d.ts +23 -23
  78. package/types/SVGWidget.d.ts +77 -77
  79. package/types/SVGZoomWidget.d.ts +68 -68
  80. package/types/Shape.d.ts +34 -34
  81. package/types/Surface.d.ts +69 -69
  82. package/types/Text.d.ts +37 -37
  83. package/types/TextBox.d.ts +76 -76
  84. package/types/TitleBar.d.ts +117 -117
  85. package/types/Transition.d.ts +11 -11
  86. package/types/Utility.d.ts +100 -100
  87. package/types/Utility.d.ts.map +1 -1
  88. package/types/Widget.d.ts +149 -149
  89. package/types/WidgetArray.d.ts +6 -6
  90. package/types/__package__.d.ts +3 -3
  91. package/types/index.d.ts +52 -52
  92. package/types-3.4/Utility.d.ts +1 -1
  93. package/types-3.4/__package__.d.ts +2 -2
@@ -1,416 +1,416 @@
1
- import { event as d3Event, mouse as d3Mouse } from "d3-selection";
2
- import { zoom as d3Zoom, zoomIdentity as d3ZoomIdentity } from "d3-zoom";
3
- import { SVGWidget } from "./SVGWidget";
4
- import { safeRaise } from "./Utility";
5
- import { Button, IconBar, Spacer, ToggleButton } from "./TitleBar";
6
-
7
- import "../src/SVGZoomWidget.css";
8
-
9
- export type MouseMode = "zoom" | "marqueeSelection";
10
-
11
- export class SVGZoomWidget extends SVGWidget {
12
-
13
- protected _renderElement;
14
-
15
- private _currZoom;
16
- protected _zoomScale = 1;
17
- protected _zoomTranslate = [0, 0];
18
- protected _zoomRoot;
19
- protected _zoomGrab;
20
- protected _zoomG;
21
- private _prevZoomable;
22
-
23
- protected _marqueeSelectionRoot;
24
- protected _marqueeSelection;
25
-
26
- protected _autoSelectionMode = false;
27
-
28
- protected _toggleMarqueeSelection = new ToggleButton().faChar("fa-square-o").tooltip("Marquee Selection")
29
- .on("click", () => {
30
- if (this._toggleMarqueeSelection.selected()) {
31
- this.mouseMode("marqueeSelection");
32
- }
33
- this.updateIconBar();
34
- })
35
- ;
36
-
37
- protected _toggleZoom = new ToggleButton().faChar("fa-mouse-pointer").tooltip("Zoom")
38
- .on("click", () => {
39
- if (this._toggleZoom.selected()) {
40
- this.mouseMode("zoom");
41
- }
42
- this.updateIconBar();
43
- })
44
- ;
45
-
46
- _iconBar = new IconBar()
47
- .buttons([
48
- this._toggleMarqueeSelection,
49
- this._toggleZoom,
50
- new Spacer().vline(false),
51
- new Button().faChar("fa-arrows-alt").tooltip("Zoom to fit")
52
- .on("click", () => {
53
- this.zoomToFit();
54
- }),
55
- new Spacer().vline(false),
56
- new Button().faChar("fa-plus").tooltip("Zoom in")
57
- .on("click", () => {
58
- this.zoomPlus();
59
- }),
60
- new Button().faChar("fa-minus").tooltip("Zoom out")
61
- .on("click", () => {
62
- this.zoomMinus();
63
- })
64
- ])
65
- ;
66
-
67
- constructor() {
68
- super();
69
-
70
- this._currZoom = d3Zoom()
71
- .scaleExtent([0.05, 20])
72
- .on("zoom end", (evt) => {
73
- this.onZoomed();
74
- })
75
- ;
76
- }
77
-
78
- getScreenBBox(target: any) {
79
- let targetel = target;
80
-
81
- while (targetel.getScreenCTM == null && targetel.parentNode == null) {
82
- targetel = targetel.parentNode;
83
- }
84
-
85
- const bbox: any = {};
86
- const matrix = targetel.getScreenCTM();
87
- const tbbox = targetel.getBBox();
88
- const width = tbbox.width;
89
- const height = tbbox.height;
90
- const x = tbbox.x;
91
- const y = tbbox.y;
92
- const point = this._placeholderElement.node().createSVGPoint();
93
- point.x = x;
94
- point.y = y;
95
-
96
- bbox.nw = point.matrixTransform(matrix);
97
- point.x += width;
98
- bbox.ne = point.matrixTransform(matrix);
99
- point.y += height;
100
- bbox.se = point.matrixTransform(matrix);
101
- point.x -= width;
102
- bbox.sw = point.matrixTransform(matrix);
103
- point.y -= height / 2;
104
- bbox.w = point.matrixTransform(matrix);
105
- point.x += width;
106
- bbox.e = point.matrixTransform(matrix);
107
- point.x -= width / 2;
108
- point.y -= height / 2;
109
- bbox.n = point.matrixTransform(matrix);
110
- point.y += height;
111
- bbox.s = point.matrixTransform(matrix);
112
-
113
- return {
114
- x: bbox.nw.x,
115
- y: bbox.nw.y,
116
- width: bbox.se.x - bbox.nw.x,
117
- height: bbox.se.y - bbox.nw.y
118
- };
119
- }
120
-
121
- zoomScale(): number {
122
- return this._zoomScale;
123
- }
124
-
125
- zoomTranslate(): number[] {
126
- return this._zoomTranslate;
127
- }
128
-
129
- zoomExtent(range): void {
130
- this._currZoom.scaleExtent(range);
131
- }
132
-
133
- zoomTo(translate?, scale?, transitionDuration = 250) {
134
- translate = translate || this._zoomTranslate;
135
- scale = scale || this._zoomScale;
136
- transitionDuration = transitionDuration === undefined ? this.zoomDuration() : transitionDuration;
137
-
138
- this._zoomRoot.transition().duration(transitionDuration)
139
- .call(this._currZoom.transform, d3ZoomIdentity.translate(translate[0], translate[1]).scale(scale))
140
- ;
141
- }
142
-
143
- zoomPlus() {
144
- this._zoomRoot.transition()
145
- .call(this._currZoom.scaleBy, 1.33)
146
- ;
147
- }
148
-
149
- zoomMinus() {
150
- this._zoomRoot.transition()
151
- .call(this._currZoom.scaleBy, 1 / 1.33)
152
- ;
153
- }
154
-
155
- centerOnBBox(bbox, transitionDuration?) {
156
- if (bbox.width && bbox.height) {
157
- const x = bbox.x + bbox.width / 2;
158
- const y = bbox.y + bbox.height / 2;
159
- const width = this.width();
160
- const height = this.height();
161
-
162
- const scale = this.zoomScale();
163
- const translate = [width / 2 - scale * x, height / 2 - scale * y];
164
- this.zoomTo(translate, scale, transitionDuration);
165
- }
166
- }
167
-
168
- zoomToBBox(bbox, transitionDuration?, widthOnly: boolean = false, scale?: number) {
169
- if (bbox.width && bbox.height) {
170
- const x = bbox.x + bbox.width / 2;
171
- const y = bbox.y + bbox.height / 2;
172
- const dx = bbox.width;
173
- const dy = bbox.height;
174
- const width = this.width();
175
- const height = this.height();
176
-
177
- let newScale = scale || 1 / (widthOnly ? dx / width : Math.max(dx / width, dy / height));
178
- if (this.zoomToFitLimit_exists() && newScale > this.zoomToFitLimit()) {
179
- newScale = this.zoomToFitLimit();
180
- }
181
- const translate = [width / 2 - newScale * x, height / 2 - newScale * y];
182
- this.zoomTo(translate, newScale, transitionDuration);
183
- }
184
- }
185
-
186
- zoomToScale(scale, transitionDuration?) {
187
- if (this._renderElement) {
188
- const bbox = this._renderElement.node().getBBox();
189
- this.zoomToBBox(bbox, transitionDuration, undefined, scale);
190
- }
191
- }
192
-
193
- zoomToWidth(transitionDuration?) {
194
- if (this._renderElement) {
195
- const bbox = this._renderElement.node().getBBox();
196
- this.zoomToBBox(bbox, transitionDuration, true);
197
- }
198
- }
199
-
200
- zoomToFit(transitionDuration?) {
201
- if (this._renderElement) {
202
- const bbox = this._renderElement.node().getBBox();
203
- this.zoomToBBox(bbox, transitionDuration);
204
- }
205
- }
206
-
207
- onZoomed() {
208
- if (d3Event && d3Event.transform && this.mouseMode() === "zoom") {
209
- this.zoomed(d3Event.transform);
210
- }
211
- }
212
-
213
- zoomed(transform) {
214
- this._zoomScale = transform.k;
215
- this._zoomTranslate = [transform.x, transform.y];
216
- this._zoomG.attr("transform", transform);
217
- }
218
-
219
- updateIconBar() {
220
- this._toggleMarqueeSelection.selected(this.mouseMode() === "marqueeSelection").render();
221
- this._toggleZoom.selected(this.mouseMode() === "zoom").render();
222
- }
223
-
224
- mousedownMarqueeSelection() {
225
- const p = d3Mouse(this._marqueeSelectionRoot.node());
226
- this._marqueeSelection = this.element().append("rect")
227
- .attr("class", "marqueeSelection")
228
- .attr("rx", 6)
229
- .attr("ry", 6)
230
- .attr("x", p[0])
231
- .attr("y", p[1])
232
- .attr("width", 0)
233
- .attr("height", 0)
234
- ;
235
- this.startMarqueeSelection();
236
- }
237
-
238
- mousemoveMarqueeSelection() {
239
- if (this._marqueeSelection) {
240
- const p = d3Mouse(this._marqueeSelectionRoot.node());
241
- const d = {
242
- x: parseInt(this._marqueeSelection.attr("x"), 10),
243
- y: parseInt(this._marqueeSelection.attr("y"), 10),
244
- width: parseInt(this._marqueeSelection.attr("width"), 10),
245
- height: parseInt(this._marqueeSelection.attr("height"), 10)
246
- };
247
- const move = {
248
- x: p[0] - d.x,
249
- y: p[1] - d.y
250
- };
251
-
252
- if (move.x < 1 || (move.x * 2 < d.width)) {
253
- d.x = p[0];
254
- d.width -= move.x;
255
- } else {
256
- d.width = move.x;
257
- }
258
-
259
- if (move.y < 1 || (move.y * 2 < d.height)) {
260
- d.y = p[1];
261
- d.height -= move.y;
262
- } else {
263
- d.height = move.y;
264
- }
265
-
266
- this._marqueeSelection
267
- .attr("x", d.x)
268
- .attr("y", d.y)
269
- .attr("width", d.width)
270
- .attr("height", d.height)
271
- ;
272
-
273
- this.updateMarqueeSelection({
274
- x: (d.x - this._zoomTranslate[0]) / this._zoomScale,
275
- y: (d.y - this._zoomTranslate[1]) / this._zoomScale,
276
- width: d.width / this._zoomScale,
277
- height: d.height / this._zoomScale
278
- });
279
- }
280
- }
281
-
282
- mouseupMarqueeSelection() {
283
- if (this._marqueeSelection) {
284
- this._marqueeSelection.remove();
285
- delete this._marqueeSelection;
286
- if (this._autoSelectionMode) {
287
- this._autoSelectionMode = false;
288
- this.mouseMode("zoom");
289
- this.updateIconBar();
290
- }
291
- this.endMarqueeSelection();
292
- }
293
- }
294
-
295
- enter(domNode, _element) {
296
- super.enter(domNode, _element);
297
- _element.style("user-select", "none");
298
-
299
- this._marqueeSelectionRoot = _element.append("rect")
300
- .attr("class", "zoomBackground")
301
- .attr("width", this.width())
302
- .attr("height", this.height())
303
- .style("fill", "transparent")
304
- .style("cursor", "crosshair")
305
- .on("mousedown", () => {
306
- this.mousedownMarqueeSelection();
307
- })
308
- .on("mousemove", () => {
309
- this.mousemoveMarqueeSelection();
310
- })
311
- .on("mouseup mouseout", () => {
312
- this.mouseupMarqueeSelection();
313
- })
314
- ;
315
-
316
- this._zoomRoot = _element.append("g");
317
-
318
- this._zoomGrab = this._zoomRoot.append("rect")
319
- .attr("class", "zoomBackground")
320
- .attr("width", this.width())
321
- .attr("height", this.height())
322
- .on("mousedown", () => {
323
- if (d3Event.shiftKey && this.mouseMode() === "zoom") {
324
- d3Event.stopPropagation();
325
- this.mouseMode("marqueeSelection");
326
- this._autoSelectionMode = true;
327
- this.mousedownMarqueeSelection();
328
- }
329
- })
330
- ;
331
- this._zoomG = this._zoomRoot.append("g");
332
- this._renderElement = this._zoomG.append("g");
333
-
334
- if (this._prevZoomable !== this.zoomable()) {
335
- if (this.zoomable()) {
336
- this._zoomRoot.call(this._currZoom);
337
- } else {
338
- this._zoomRoot.on(".zoom", null);
339
- }
340
- this._prevZoomable = this.zoomable();
341
- }
342
-
343
- this._iconBar.target(this._zoomRoot.node());
344
- }
345
-
346
- update(domNode, element) {
347
- super.update(domNode, element);
348
-
349
- this._zoomGrab
350
- .attr("width", this.width())
351
- .attr("height", this.height())
352
- ;
353
-
354
- this._marqueeSelectionRoot
355
- .attr("width", this.width())
356
- .attr("height", this.height())
357
- ;
358
-
359
- this._iconBar
360
- .visible(this.zoomable() && this.showToolbar())
361
- .render((w: IconBar) => {
362
- const bbox = w.getBBox();
363
- w.reposition({ x: this.width() - bbox.width - 4, y: -4 });
364
- })
365
- ;
366
- }
367
-
368
- exit(domNode, element) {
369
- this._iconBar.target(null);
370
- super.exit(domNode, element);
371
- }
372
-
373
- // Events
374
- startMarqueeSelection() {
375
- }
376
-
377
- updateMarqueeSelection(rect: { x: number, y: number, width: number, height: number }) {
378
- }
379
-
380
- endMarqueeSelection() {
381
- }
382
- }
383
- SVGZoomWidget.prototype._class += " common_SVGZoomWidget";
384
-
385
- export interface SVGZoomWidget {
386
- showToolbar(): boolean;
387
- showToolbar(_: boolean): this;
388
- zoomable(): boolean;
389
- zoomable(_: boolean): this;
390
- zoomDuration(): number;
391
- zoomDuration(_: number): this;
392
- zoomToFitLimit(): number;
393
- zoomToFitLimit(_: number): this;
394
- zoomToFitLimit_exists(): boolean;
395
- mouseMode(_: MouseMode): this;
396
- mouseMode(): MouseMode;
397
- }
398
- SVGZoomWidget.prototype.publish("showToolbar", true, "boolean", "Show Toolbar");
399
- SVGZoomWidget.prototype.publish("zoomable", true, "boolean", "Enable/Disable Zooming");
400
- SVGZoomWidget.prototype.publish("zoomDuration", 250, "number", "Transition Duration");
401
- SVGZoomWidget.prototype.publish("zoomToFitLimit", undefined, "number", "Zoom to fit limit", undefined, { optional: true });
402
- SVGZoomWidget.prototype.publish("mouseMode", "zoom", "set", "Mouse Mode (zoom | marqueeSelection)", ["zoom", "marqueeSelection"]);
403
-
404
- const _origMouseMode = SVGZoomWidget.prototype.mouseMode;
405
- SVGZoomWidget.prototype.mouseMode = function (_?, transitionDuration?) {
406
- const retVal = _origMouseMode.apply(this, arguments);
407
- if (arguments.length) {
408
- if (_ === "zoom") {
409
- safeRaise(this._zoomRoot.node());
410
- } else {
411
- safeRaise(this._marqueeSelectionRoot.node());
412
- }
413
- this.updateIconBar();
414
- }
415
- return retVal;
416
- };
1
+ import { event as d3Event, mouse as d3Mouse } from "d3-selection";
2
+ import { zoom as d3Zoom, zoomIdentity as d3ZoomIdentity } from "d3-zoom";
3
+ import { SVGWidget } from "./SVGWidget";
4
+ import { safeRaise } from "./Utility";
5
+ import { Button, IconBar, Spacer, ToggleButton } from "./TitleBar";
6
+
7
+ import "../src/SVGZoomWidget.css";
8
+
9
+ export type MouseMode = "zoom" | "marqueeSelection";
10
+
11
+ export class SVGZoomWidget extends SVGWidget {
12
+
13
+ protected _renderElement;
14
+
15
+ private _currZoom;
16
+ protected _zoomScale = 1;
17
+ protected _zoomTranslate = [0, 0];
18
+ protected _zoomRoot;
19
+ protected _zoomGrab;
20
+ protected _zoomG;
21
+ private _prevZoomable;
22
+
23
+ protected _marqueeSelectionRoot;
24
+ protected _marqueeSelection;
25
+
26
+ protected _autoSelectionMode = false;
27
+
28
+ protected _toggleMarqueeSelection = new ToggleButton().faChar("fa-square-o").tooltip("Marquee Selection")
29
+ .on("click", () => {
30
+ if (this._toggleMarqueeSelection.selected()) {
31
+ this.mouseMode("marqueeSelection");
32
+ }
33
+ this.updateIconBar();
34
+ })
35
+ ;
36
+
37
+ protected _toggleZoom = new ToggleButton().faChar("fa-mouse-pointer").tooltip("Zoom")
38
+ .on("click", () => {
39
+ if (this._toggleZoom.selected()) {
40
+ this.mouseMode("zoom");
41
+ }
42
+ this.updateIconBar();
43
+ })
44
+ ;
45
+
46
+ _iconBar = new IconBar()
47
+ .buttons([
48
+ this._toggleMarqueeSelection,
49
+ this._toggleZoom,
50
+ new Spacer().vline(false),
51
+ new Button().faChar("fa-arrows-alt").tooltip("Zoom to fit")
52
+ .on("click", () => {
53
+ this.zoomToFit();
54
+ }),
55
+ new Spacer().vline(false),
56
+ new Button().faChar("fa-plus").tooltip("Zoom in")
57
+ .on("click", () => {
58
+ this.zoomPlus();
59
+ }),
60
+ new Button().faChar("fa-minus").tooltip("Zoom out")
61
+ .on("click", () => {
62
+ this.zoomMinus();
63
+ })
64
+ ])
65
+ ;
66
+
67
+ constructor() {
68
+ super();
69
+
70
+ this._currZoom = d3Zoom()
71
+ .scaleExtent([0.05, 20])
72
+ .on("zoom end", (evt) => {
73
+ this.onZoomed();
74
+ })
75
+ ;
76
+ }
77
+
78
+ getScreenBBox(target: any) {
79
+ let targetel = target;
80
+
81
+ while (targetel.getScreenCTM == null && targetel.parentNode == null) {
82
+ targetel = targetel.parentNode;
83
+ }
84
+
85
+ const bbox: any = {};
86
+ const matrix = targetel.getScreenCTM();
87
+ const tbbox = targetel.getBBox();
88
+ const width = tbbox.width;
89
+ const height = tbbox.height;
90
+ const x = tbbox.x;
91
+ const y = tbbox.y;
92
+ const point = this._placeholderElement.node().createSVGPoint();
93
+ point.x = x;
94
+ point.y = y;
95
+
96
+ bbox.nw = point.matrixTransform(matrix);
97
+ point.x += width;
98
+ bbox.ne = point.matrixTransform(matrix);
99
+ point.y += height;
100
+ bbox.se = point.matrixTransform(matrix);
101
+ point.x -= width;
102
+ bbox.sw = point.matrixTransform(matrix);
103
+ point.y -= height / 2;
104
+ bbox.w = point.matrixTransform(matrix);
105
+ point.x += width;
106
+ bbox.e = point.matrixTransform(matrix);
107
+ point.x -= width / 2;
108
+ point.y -= height / 2;
109
+ bbox.n = point.matrixTransform(matrix);
110
+ point.y += height;
111
+ bbox.s = point.matrixTransform(matrix);
112
+
113
+ return {
114
+ x: bbox.nw.x,
115
+ y: bbox.nw.y,
116
+ width: bbox.se.x - bbox.nw.x,
117
+ height: bbox.se.y - bbox.nw.y
118
+ };
119
+ }
120
+
121
+ zoomScale(): number {
122
+ return this._zoomScale;
123
+ }
124
+
125
+ zoomTranslate(): number[] {
126
+ return this._zoomTranslate;
127
+ }
128
+
129
+ zoomExtent(range): void {
130
+ this._currZoom.scaleExtent(range);
131
+ }
132
+
133
+ zoomTo(translate?, scale?, transitionDuration = 250) {
134
+ translate = translate || this._zoomTranslate;
135
+ scale = scale || this._zoomScale;
136
+ transitionDuration = transitionDuration === undefined ? this.zoomDuration() : transitionDuration;
137
+
138
+ this._zoomRoot.transition().duration(transitionDuration)
139
+ .call(this._currZoom.transform, d3ZoomIdentity.translate(translate[0], translate[1]).scale(scale))
140
+ ;
141
+ }
142
+
143
+ zoomPlus() {
144
+ this._zoomRoot.transition()
145
+ .call(this._currZoom.scaleBy, 1.33)
146
+ ;
147
+ }
148
+
149
+ zoomMinus() {
150
+ this._zoomRoot.transition()
151
+ .call(this._currZoom.scaleBy, 1 / 1.33)
152
+ ;
153
+ }
154
+
155
+ centerOnBBox(bbox, transitionDuration?) {
156
+ if (bbox.width && bbox.height) {
157
+ const x = bbox.x + bbox.width / 2;
158
+ const y = bbox.y + bbox.height / 2;
159
+ const width = this.width();
160
+ const height = this.height();
161
+
162
+ const scale = this.zoomScale();
163
+ const translate = [width / 2 - scale * x, height / 2 - scale * y];
164
+ this.zoomTo(translate, scale, transitionDuration);
165
+ }
166
+ }
167
+
168
+ zoomToBBox(bbox, transitionDuration?, widthOnly: boolean = false, scale?: number) {
169
+ if (bbox.width && bbox.height) {
170
+ const x = bbox.x + bbox.width / 2;
171
+ const y = bbox.y + bbox.height / 2;
172
+ const dx = bbox.width;
173
+ const dy = bbox.height;
174
+ const width = this.width();
175
+ const height = this.height();
176
+
177
+ let newScale = scale || 1 / (widthOnly ? dx / width : Math.max(dx / width, dy / height));
178
+ if (this.zoomToFitLimit_exists() && newScale > this.zoomToFitLimit()) {
179
+ newScale = this.zoomToFitLimit();
180
+ }
181
+ const translate = [width / 2 - newScale * x, height / 2 - newScale * y];
182
+ this.zoomTo(translate, newScale, transitionDuration);
183
+ }
184
+ }
185
+
186
+ zoomToScale(scale, transitionDuration?) {
187
+ if (this._renderElement) {
188
+ const bbox = this._renderElement.node().getBBox();
189
+ this.zoomToBBox(bbox, transitionDuration, undefined, scale);
190
+ }
191
+ }
192
+
193
+ zoomToWidth(transitionDuration?) {
194
+ if (this._renderElement) {
195
+ const bbox = this._renderElement.node().getBBox();
196
+ this.zoomToBBox(bbox, transitionDuration, true);
197
+ }
198
+ }
199
+
200
+ zoomToFit(transitionDuration?) {
201
+ if (this._renderElement) {
202
+ const bbox = this._renderElement.node().getBBox();
203
+ this.zoomToBBox(bbox, transitionDuration);
204
+ }
205
+ }
206
+
207
+ onZoomed() {
208
+ if (d3Event && d3Event.transform && this.mouseMode() === "zoom") {
209
+ this.zoomed(d3Event.transform);
210
+ }
211
+ }
212
+
213
+ zoomed(transform) {
214
+ this._zoomScale = transform.k;
215
+ this._zoomTranslate = [transform.x, transform.y];
216
+ this._zoomG.attr("transform", transform);
217
+ }
218
+
219
+ updateIconBar() {
220
+ this._toggleMarqueeSelection.selected(this.mouseMode() === "marqueeSelection").render();
221
+ this._toggleZoom.selected(this.mouseMode() === "zoom").render();
222
+ }
223
+
224
+ mousedownMarqueeSelection() {
225
+ const p = d3Mouse(this._marqueeSelectionRoot.node());
226
+ this._marqueeSelection = this.element().append("rect")
227
+ .attr("class", "marqueeSelection")
228
+ .attr("rx", 6)
229
+ .attr("ry", 6)
230
+ .attr("x", p[0])
231
+ .attr("y", p[1])
232
+ .attr("width", 0)
233
+ .attr("height", 0)
234
+ ;
235
+ this.startMarqueeSelection();
236
+ }
237
+
238
+ mousemoveMarqueeSelection() {
239
+ if (this._marqueeSelection) {
240
+ const p = d3Mouse(this._marqueeSelectionRoot.node());
241
+ const d = {
242
+ x: parseInt(this._marqueeSelection.attr("x"), 10),
243
+ y: parseInt(this._marqueeSelection.attr("y"), 10),
244
+ width: parseInt(this._marqueeSelection.attr("width"), 10),
245
+ height: parseInt(this._marqueeSelection.attr("height"), 10)
246
+ };
247
+ const move = {
248
+ x: p[0] - d.x,
249
+ y: p[1] - d.y
250
+ };
251
+
252
+ if (move.x < 1 || (move.x * 2 < d.width)) {
253
+ d.x = p[0];
254
+ d.width -= move.x;
255
+ } else {
256
+ d.width = move.x;
257
+ }
258
+
259
+ if (move.y < 1 || (move.y * 2 < d.height)) {
260
+ d.y = p[1];
261
+ d.height -= move.y;
262
+ } else {
263
+ d.height = move.y;
264
+ }
265
+
266
+ this._marqueeSelection
267
+ .attr("x", d.x)
268
+ .attr("y", d.y)
269
+ .attr("width", d.width)
270
+ .attr("height", d.height)
271
+ ;
272
+
273
+ this.updateMarqueeSelection({
274
+ x: (d.x - this._zoomTranslate[0]) / this._zoomScale,
275
+ y: (d.y - this._zoomTranslate[1]) / this._zoomScale,
276
+ width: d.width / this._zoomScale,
277
+ height: d.height / this._zoomScale
278
+ });
279
+ }
280
+ }
281
+
282
+ mouseupMarqueeSelection() {
283
+ if (this._marqueeSelection) {
284
+ this._marqueeSelection.remove();
285
+ delete this._marqueeSelection;
286
+ if (this._autoSelectionMode) {
287
+ this._autoSelectionMode = false;
288
+ this.mouseMode("zoom");
289
+ this.updateIconBar();
290
+ }
291
+ this.endMarqueeSelection();
292
+ }
293
+ }
294
+
295
+ enter(domNode, _element) {
296
+ super.enter(domNode, _element);
297
+ _element.style("user-select", "none");
298
+
299
+ this._marqueeSelectionRoot = _element.append("rect")
300
+ .attr("class", "zoomBackground")
301
+ .attr("width", this.width())
302
+ .attr("height", this.height())
303
+ .style("fill", "transparent")
304
+ .style("cursor", "crosshair")
305
+ .on("mousedown", () => {
306
+ this.mousedownMarqueeSelection();
307
+ })
308
+ .on("mousemove", () => {
309
+ this.mousemoveMarqueeSelection();
310
+ })
311
+ .on("mouseup mouseout", () => {
312
+ this.mouseupMarqueeSelection();
313
+ })
314
+ ;
315
+
316
+ this._zoomRoot = _element.append("g");
317
+
318
+ this._zoomGrab = this._zoomRoot.append("rect")
319
+ .attr("class", "zoomBackground")
320
+ .attr("width", this.width())
321
+ .attr("height", this.height())
322
+ .on("mousedown", () => {
323
+ if (d3Event.shiftKey && this.mouseMode() === "zoom") {
324
+ d3Event.stopPropagation();
325
+ this.mouseMode("marqueeSelection");
326
+ this._autoSelectionMode = true;
327
+ this.mousedownMarqueeSelection();
328
+ }
329
+ })
330
+ ;
331
+ this._zoomG = this._zoomRoot.append("g");
332
+ this._renderElement = this._zoomG.append("g");
333
+
334
+ if (this._prevZoomable !== this.zoomable()) {
335
+ if (this.zoomable()) {
336
+ this._zoomRoot.call(this._currZoom);
337
+ } else {
338
+ this._zoomRoot.on(".zoom", null);
339
+ }
340
+ this._prevZoomable = this.zoomable();
341
+ }
342
+
343
+ this._iconBar.target(this._zoomRoot.node());
344
+ }
345
+
346
+ update(domNode, element) {
347
+ super.update(domNode, element);
348
+
349
+ this._zoomGrab
350
+ .attr("width", this.width())
351
+ .attr("height", this.height())
352
+ ;
353
+
354
+ this._marqueeSelectionRoot
355
+ .attr("width", this.width())
356
+ .attr("height", this.height())
357
+ ;
358
+
359
+ this._iconBar
360
+ .visible(this.zoomable() && this.showToolbar())
361
+ .render((w: IconBar) => {
362
+ const bbox = w.getBBox();
363
+ w.reposition({ x: this.width() - bbox.width - 4, y: -4 });
364
+ })
365
+ ;
366
+ }
367
+
368
+ exit(domNode, element) {
369
+ this._iconBar.target(null);
370
+ super.exit(domNode, element);
371
+ }
372
+
373
+ // Events
374
+ startMarqueeSelection() {
375
+ }
376
+
377
+ updateMarqueeSelection(rect: { x: number, y: number, width: number, height: number }) {
378
+ }
379
+
380
+ endMarqueeSelection() {
381
+ }
382
+ }
383
+ SVGZoomWidget.prototype._class += " common_SVGZoomWidget";
384
+
385
+ export interface SVGZoomWidget {
386
+ showToolbar(): boolean;
387
+ showToolbar(_: boolean): this;
388
+ zoomable(): boolean;
389
+ zoomable(_: boolean): this;
390
+ zoomDuration(): number;
391
+ zoomDuration(_: number): this;
392
+ zoomToFitLimit(): number;
393
+ zoomToFitLimit(_: number): this;
394
+ zoomToFitLimit_exists(): boolean;
395
+ mouseMode(_: MouseMode): this;
396
+ mouseMode(): MouseMode;
397
+ }
398
+ SVGZoomWidget.prototype.publish("showToolbar", true, "boolean", "Show Toolbar");
399
+ SVGZoomWidget.prototype.publish("zoomable", true, "boolean", "Enable/Disable Zooming");
400
+ SVGZoomWidget.prototype.publish("zoomDuration", 250, "number", "Transition Duration");
401
+ SVGZoomWidget.prototype.publish("zoomToFitLimit", undefined, "number", "Zoom to fit limit", undefined, { optional: true });
402
+ SVGZoomWidget.prototype.publish("mouseMode", "zoom", "set", "Mouse Mode (zoom | marqueeSelection)", ["zoom", "marqueeSelection"]);
403
+
404
+ const _origMouseMode = SVGZoomWidget.prototype.mouseMode;
405
+ SVGZoomWidget.prototype.mouseMode = function (_?, transitionDuration?) {
406
+ const retVal = _origMouseMode.apply(this, arguments);
407
+ if (arguments.length) {
408
+ if (_ === "zoom") {
409
+ safeRaise(this._zoomRoot.node());
410
+ } else {
411
+ safeRaise(this._marqueeSelectionRoot.node());
412
+ }
413
+ this.updateIconBar();
414
+ }
415
+ return retVal;
416
+ };