@unovis/ts 1.4.0-beta.3 → 1.4.0-version.12

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 (113) hide show
  1. package/components/area/config.d.ts +1 -1
  2. package/components/area/config.js.map +1 -1
  3. package/components/area/index.js.map +1 -1
  4. package/components/bullet-legend/config.d.ts +2 -4
  5. package/components/bullet-legend/config.js +2 -1
  6. package/components/bullet-legend/config.js.map +1 -1
  7. package/components/bullet-legend/index.js +17 -15
  8. package/components/bullet-legend/index.js.map +1 -1
  9. package/components/bullet-legend/modules/shape.d.ts +2 -1
  10. package/components/bullet-legend/modules/shape.js +48 -39
  11. package/components/bullet-legend/modules/shape.js.map +1 -1
  12. package/components/bullet-legend/style.js +5 -2
  13. package/components/bullet-legend/style.js.map +1 -1
  14. package/components/bullet-legend/types.d.ts +5 -14
  15. package/components/bullet-legend/types.js +6 -4
  16. package/components/bullet-legend/types.js.map +1 -1
  17. package/components/chord-diagram/index.d.ts +3 -3
  18. package/components/chord-diagram/index.js +15 -24
  19. package/components/chord-diagram/index.js.map +1 -1
  20. package/components/chord-diagram/modules/label.js +18 -15
  21. package/components/chord-diagram/modules/label.js.map +1 -1
  22. package/components/chord-diagram/modules/layout.js +5 -9
  23. package/components/chord-diagram/modules/layout.js.map +1 -1
  24. package/components/chord-diagram/style.js +1 -1
  25. package/components/chord-diagram/style.js.map +1 -1
  26. package/components/graph/config.d.ts +22 -15
  27. package/components/graph/config.js +4 -2
  28. package/components/graph/config.js.map +1 -1
  29. package/components/graph/index.d.ts +7 -2
  30. package/components/graph/index.js +114 -110
  31. package/components/graph/index.js.map +1 -1
  32. package/components/graph/modules/layout.js +30 -19
  33. package/components/graph/modules/layout.js.map +1 -1
  34. package/components/graph/modules/link/helper.d.ts +4 -6
  35. package/components/graph/modules/link/helper.js +15 -25
  36. package/components/graph/modules/link/helper.js.map +1 -1
  37. package/components/graph/modules/link/index.d.ts +3 -3
  38. package/components/graph/modules/link/index.js +111 -89
  39. package/components/graph/modules/link/index.js.map +1 -1
  40. package/components/graph/modules/link/style.d.ts +5 -5
  41. package/components/graph/modules/link/style.js +26 -22
  42. package/components/graph/modules/link/style.js.map +1 -1
  43. package/components/graph/modules/node/helper.d.ts +1 -0
  44. package/components/graph/modules/node/helper.js +4 -1
  45. package/components/graph/modules/node/helper.js.map +1 -1
  46. package/components/graph/modules/node/index.js +28 -11
  47. package/components/graph/modules/node/index.js.map +1 -1
  48. package/components/graph/modules/node/style.d.ts +1 -1
  49. package/components/graph/modules/node/style.js +13 -6
  50. package/components/graph/modules/node/style.js.map +1 -1
  51. package/components/graph/modules/shape.d.ts +0 -2
  52. package/components/graph/modules/shape.js +7 -9
  53. package/components/graph/modules/shape.js.map +1 -1
  54. package/components/graph/types.d.ts +63 -5
  55. package/components/graph/types.js +1 -0
  56. package/components/graph/types.js.map +1 -1
  57. package/components/nested-donut/config.d.ts +0 -1
  58. package/components/nested-donut/config.js +1 -1
  59. package/components/nested-donut/config.js.map +1 -1
  60. package/components/nested-donut/index.js +10 -16
  61. package/components/nested-donut/index.js.map +1 -1
  62. package/components/stacked-bar/index.js.map +1 -1
  63. package/components/tooltip/config.d.ts +1 -1
  64. package/components/tooltip/config.js.map +1 -1
  65. package/components/tooltip/index.js +3 -1
  66. package/components/tooltip/index.js.map +1 -1
  67. package/components/vis-controls/index.d.ts +3 -0
  68. package/components/vis-controls/index.js +6 -1
  69. package/components/vis-controls/index.js.map +1 -1
  70. package/components.d.ts +0 -2
  71. package/components.js +0 -1
  72. package/components.js.map +1 -1
  73. package/containers/single-container/config.d.ts +0 -3
  74. package/containers/single-container/config.js.map +1 -1
  75. package/containers/single-container/index.js +1 -10
  76. package/containers/single-container/index.js.map +1 -1
  77. package/containers/xy-container/config.d.ts +0 -3
  78. package/containers/xy-container/config.js +1 -1
  79. package/containers/xy-container/config.js.map +1 -1
  80. package/containers/xy-container/index.js +5 -17
  81. package/containers/xy-container/index.js.map +1 -1
  82. package/core/component/index.d.ts +3 -3
  83. package/core/component/index.js +1 -1
  84. package/core/component/index.js.map +1 -1
  85. package/index.js +0 -2
  86. package/index.js.map +1 -1
  87. package/package.json +1 -1
  88. package/types/misc.d.ts +0 -1
  89. package/types/scale.d.ts +2 -3
  90. package/types/scale.js +1 -2
  91. package/types/scale.js.map +1 -1
  92. package/types.d.ts +0 -1
  93. package/types.js +0 -1
  94. package/types.js.map +1 -1
  95. package/utils/misc.d.ts +1 -2
  96. package/utils/misc.js +1 -13
  97. package/utils/misc.js.map +1 -1
  98. package/utils/svg.d.ts +3 -0
  99. package/utils/svg.js +61 -0
  100. package/utils/svg.js.map +1 -0
  101. package/utils/text.js.map +1 -1
  102. package/components/annotations/config.d.ts +0 -19
  103. package/components/annotations/config.js +0 -6
  104. package/components/annotations/config.js.map +0 -1
  105. package/components/annotations/index.d.ts +0 -24
  106. package/components/annotations/index.js +0 -117
  107. package/components/annotations/index.js.map +0 -1
  108. package/components/annotations/style.d.ts +0 -13
  109. package/components/annotations/style.js +0 -43
  110. package/components/annotations/style.js.map +0 -1
  111. package/components/annotations/types.d.ts +0 -43
  112. package/components/annotations/types.js +0 -8
  113. package/components/annotations/types.js.map +0 -1
@@ -6,22 +6,21 @@ import { drag } from 'd3-drag';
6
6
  import { interval } from 'd3-timer';
7
7
  import { ComponentCore } from '../../core/component/index.js';
8
8
  import { GraphDataModel } from '../../data-models/graph.js';
9
- import { isNumber, clamp, getBoolean, isFunction, shallowDiff, unique, clean } from '../../utils/data.js';
10
- import { stringToHtmlId } from '../../utils/misc.js';
9
+ import { isNumber, clamp, getBoolean, isFunction, shallowDiff } from '../../utils/data.js';
11
10
  import { smartTransition } from '../../utils/d3.js';
12
11
  import { GraphLayoutType, GraphLinkArrowStyle } from './types.js';
13
12
  import { GraphDefaultConfig } from './config.js';
14
13
  import { background, graphGroup, root } from './style.js';
15
14
  import * as style from './modules/node/style.js';
16
- import { nodes, gNode, gNodeExit, node, nodeGauge, sideLabelGroup, label } from './modules/node/style.js';
17
- import { links, gLink, gLinkExit, link } from './modules/link/style.js';
15
+ import { nodes, gNode, gNodeExit, node, nodeGauge, sideLabelGroup, label, greyedOutNode } from './modules/node/style.js';
16
+ import { links, gLink, gLinkExit, link, greyedOutLink } from './modules/link/style.js';
18
17
  import { panels, gPanel, panel, panelSelection, label as label$1, labelText, sideIconGroup, sideIconShape, sideIconSymbol } from './modules/panel/style.js';
19
18
  import { createNodes, updateNodes, removeNodes, updateSelectedNodes, zoomNodesThrottled, zoomNodes } from './modules/node/index.js';
20
19
  import { getMaxNodeSize, getX, getY, getNodeSize } from './modules/node/helper.js';
21
20
  import { createLinks, updateLinks, removeLinks, updateSelectedLinks, animateLinkFlow, zoomLinksThrottled, zoomLinks } from './modules/link/index.js';
22
- import { getLinkColor, getLinkArrow, LINK_MARKER_WIDTH, LINK_MARKER_HEIGHT, getDoubleArrowPath, getArrowPath } from './modules/link/helper.js';
21
+ import { getArrowPath, getDoubleArrowPath } from './modules/link/helper.js';
23
22
  import { removePanels, createPanels, updatePanels } from './modules/panel/index.js';
24
- import { initPanels, setPanelForNodes, updatePanelNumNodes, updatePanelBBoxSize } from './modules/panel/helper.js';
23
+ import { updatePanelNumNodes, updatePanelBBoxSize, initPanels, setPanelForNodes } from './modules/panel/helper.js';
25
24
  import { applyLayoutCircular, applyELKLayout, applyLayoutConcentric, applyLayoutForce, applyLayoutDagre, applyLayoutParallel } from './modules/layout.js';
26
25
 
27
26
  class Graph extends ComponentCore {
@@ -61,7 +60,7 @@ class Graph extends ComponentCore {
61
60
  this._linksGroup = this._graphGroup.append('g').attr('class', links);
62
61
  this._nodesGroup = this._graphGroup.append('g').attr('class', nodes);
63
62
  this._defs = this._graphGroup.append('defs');
64
- this._getMarkerId = this._getMarkerId.bind(this);
63
+ this._getLinkArrowDefId = this._getLinkArrowDefId.bind(this);
65
64
  }
66
65
  get selectedNode() {
67
66
  return this._selectedNode;
@@ -80,9 +79,9 @@ class Graph extends ComponentCore {
80
79
  this._addSVGDefs();
81
80
  }
82
81
  setConfig(config) {
83
- this._shouldRecalculateLayout = this._shouldRecalculateLayout || this._shouldLayoutRecalculate(config);
84
- this._shouldFitLayout = this._shouldFitLayout || this._shouldRecalculateLayout;
85
82
  super.setConfig(config);
83
+ this._shouldRecalculateLayout = this._shouldRecalculateLayout || this._shouldLayoutRecalculate();
84
+ this._shouldFitLayout = this._shouldFitLayout || this._shouldRecalculateLayout;
86
85
  this._shouldSetPanels = true;
87
86
  }
88
87
  get bleed() {
@@ -90,7 +89,7 @@ class Graph extends ComponentCore {
90
89
  return { top: extraPadding, bottom: extraPadding, left: extraPadding, right: extraPadding };
91
90
  }
92
91
  _render(customDuration) {
93
- const { config: { disableZoom, duration, layoutAutofit, panels }, datamodel } = this;
92
+ const { config: { disableZoom, duration, layoutAutofit }, datamodel } = this;
94
93
  if (!datamodel.nodes && !datamodel.links)
95
94
  return;
96
95
  const animDuration = isNumber(customDuration) ? customDuration : duration;
@@ -105,18 +104,16 @@ class Graph extends ComponentCore {
105
104
  this._prevHeight = this._height;
106
105
  }
107
106
  // Apply layout and render
108
- this._calculateLayout().then((isFirstRender) => {
107
+ if (this._shouldRecalculateLayout || !this._layoutCalculationPromise) {
108
+ this._layoutCalculationPromise = this._calculateLayout();
109
+ }
110
+ this._layoutCalculationPromise.then((isFirstRender) => {
109
111
  // If the component has been destroyed while the layout calculation
110
112
  // was in progress, we cancel the render
111
113
  if (this.isDestroyed())
112
114
  return;
113
- if (this._shouldSetPanels) {
114
- smartTransition(this._panelsGroup, duration / 2)
115
- .style('opacity', (panels === null || panels === void 0 ? void 0 : panels.length) ? 1 : 0);
116
- this._panels = initPanels(panels);
117
- setPanelForNodes(this._panels, datamodel.nodes, this.config);
118
- this._shouldSetPanels = false;
119
- }
115
+ this._initPanelsData();
116
+ // Fit the view
120
117
  if (isFirstRender) {
121
118
  this._fit();
122
119
  this._shouldFitLayout = false;
@@ -205,14 +202,17 @@ class Graph extends ComponentCore {
205
202
  .attr('class', gLink)
206
203
  .call(createLinks, config, duration);
207
204
  const linkGroupsMerged = linkGroups.merge(linkGroupsEnter);
208
- linkGroupsMerged.call(updateLinks, config, duration, this._scale, this._getMarkerId);
205
+ linkGroupsMerged.call(updateLinks, config, duration, this._scale, this._getLinkArrowDefId);
209
206
  const linkGroupsExit = linkGroups.exit();
210
207
  linkGroupsExit
211
208
  .attr('class', gLinkExit)
212
209
  .call(removeLinks, config, duration);
213
210
  }
214
211
  _drawPanels(nodeUpdateSelection, duration) {
212
+ var _a;
215
213
  const { config } = this;
214
+ smartTransition(this._panelsGroup, duration / 2)
215
+ .style('opacity', ((_a = config.panels) === null || _a === void 0 ? void 0 : _a.length) ? 1 : 0);
216
216
  if (!this._panels)
217
217
  return;
218
218
  const selection = (nodeUpdateSelection.duration)
@@ -239,51 +239,58 @@ class Graph extends ComponentCore {
239
239
  panelToUpdate.call(updatePanels, config, duration);
240
240
  }
241
241
  _calculateLayout() {
242
+ var _a, _b;
242
243
  return __awaiter(this, void 0, void 0, function* () {
243
244
  const { config, datamodel } = this;
244
245
  const firstRender = this._isFirstRender;
245
- if (this._shouldRecalculateLayout) {
246
- switch (config.layoutType) {
247
- case GraphLayoutType.Parallel:
248
- applyLayoutParallel(datamodel, config, this._width, this._height);
249
- break;
250
- case GraphLayoutType.ParallelHorizontal:
251
- applyLayoutParallel(datamodel, config, this._width, this._height, 'horizontal');
252
- break;
253
- case GraphLayoutType.Dagre:
254
- yield applyLayoutDagre(datamodel, config, this._width);
255
- break;
256
- case GraphLayoutType.Force:
257
- yield applyLayoutForce(datamodel, config, this._width);
258
- break;
259
- case GraphLayoutType.Concentric:
260
- applyLayoutConcentric(datamodel, config, this._width, this._height);
261
- break;
262
- case GraphLayoutType.Elk:
263
- yield applyELKLayout(datamodel, config, this._width);
264
- break;
265
- case GraphLayoutType.Circular:
266
- default:
267
- applyLayoutCircular(datamodel, config, this._width, this._height);
268
- break;
269
- }
270
- this._shouldRecalculateLayout = false;
246
+ switch (config.layoutType) {
247
+ case GraphLayoutType.Precalculated:
248
+ break;
249
+ case GraphLayoutType.Parallel:
250
+ applyLayoutParallel(datamodel, config, this._width, this._height);
251
+ break;
252
+ case GraphLayoutType.ParallelHorizontal:
253
+ applyLayoutParallel(datamodel, config, this._width, this._height, 'horizontal');
254
+ break;
255
+ case GraphLayoutType.Dagre:
256
+ yield applyLayoutDagre(datamodel, config, this._width);
257
+ break;
258
+ case GraphLayoutType.Force:
259
+ yield applyLayoutForce(datamodel, config, this._width);
260
+ break;
261
+ case GraphLayoutType.Concentric:
262
+ applyLayoutConcentric(datamodel, config, this._width, this._height);
263
+ break;
264
+ case GraphLayoutType.Elk:
265
+ yield applyELKLayout(datamodel, config, this._width);
266
+ break;
267
+ case GraphLayoutType.Circular:
268
+ default:
269
+ applyLayoutCircular(datamodel, config, this._width, this._height);
270
+ break;
271
271
  }
272
+ // We need to update the panels data right after the layout calculation
273
+ // because we want to have the latest coordinates before calling `onLayoutCalculated`
274
+ this._initPanelsData();
275
+ (_b = (_a = this.config).onLayoutCalculated) === null || _b === void 0 ? void 0 : _b.call(_a, datamodel.nodes, datamodel.links);
276
+ this._shouldRecalculateLayout = false;
272
277
  return firstRender;
273
278
  });
274
279
  }
280
+ _initPanelsData() {
281
+ const { config, datamodel } = this;
282
+ if (this._shouldSetPanels) {
283
+ this._panels = initPanels(config.panels);
284
+ setPanelForNodes(this._panels, datamodel.nodes, this.config);
285
+ this._shouldSetPanels = false;
286
+ }
287
+ }
275
288
  _fit(duration = 0) {
276
- var _a;
277
289
  const { datamodel: { nodes } } = this;
278
- if ((nodes === null || nodes === void 0 ? void 0 : nodes.length) && ((_a = this.g) === null || _a === void 0 ? void 0 : _a.size())) {
279
- const transform = this._getTransform(nodes);
280
- smartTransition(this.g, duration)
281
- .call(this._zoomBehavior.transform, transform);
282
- this._onZoom(transform);
283
- }
284
- else {
285
- console.warn('Unovis | Graph: Node data is not defined. Check if the component has been initialized.');
286
- }
290
+ const transform = this._getTransform(nodes);
291
+ smartTransition(this.g, duration)
292
+ .call(this._zoomBehavior.transform, transform);
293
+ this._onZoom(transform);
287
294
  }
288
295
  _getTransform(nodes) {
289
296
  const { nodeSize, zoomScaleExtent } = this.config;
@@ -292,13 +299,17 @@ class Graph extends ComponentCore {
292
299
  const w = this._width;
293
300
  const h = this._height;
294
301
  const xExtent = [
295
- min(nodes, d => { var _a; return getX(d) - maxNodeSize / 2 - (max((_a = d._panels) === null || _a === void 0 ? void 0 : _a.map(p => p._padding.left)) || 0); }),
296
- max(nodes, d => { var _a; return getX(d) + maxNodeSize / 2 + (max((_a = d._panels) === null || _a === void 0 ? void 0 : _a.map(p => p._padding.right)) || 0); }),
302
+ min(nodes, d => getX(d) - maxNodeSize / 2 - (max((d._panels || []).map(p => p._padding.left)) || 0)),
303
+ max(nodes, d => getX(d) + maxNodeSize / 2 + (max((d._panels || []).map(p => p._padding.right)) || 0)),
297
304
  ];
298
305
  const yExtent = [
299
- min(nodes, d => { var _a; return getY(d) - maxNodeSize / 2 - (max((_a = d._panels) === null || _a === void 0 ? void 0 : _a.map(p => p._padding.top)) || 0); }),
300
- max(nodes, d => { var _a; return getY(d) + maxNodeSize / 2 + (max((_a = d._panels) === null || _a === void 0 ? void 0 : _a.map(p => p._padding.bottom)) || 0); }),
306
+ min(nodes, d => getY(d) - maxNodeSize / 2 - (max((d._panels || []).map(p => p._padding.top)) || 0)),
307
+ max(nodes, d => getY(d) + maxNodeSize / 2 + (max((d._panels || []).map(p => p._padding.bottom)) || 0)),
301
308
  ];
309
+ if (xExtent.some(item => item === undefined) || yExtent.some(item => item === undefined)) {
310
+ console.warn('Unovis | Graph: Some of the node coordinates are undefined. This can happen if you try to fit the graph before the layout has been calculated.');
311
+ return zoomIdentity;
312
+ }
302
313
  const xScale = w / (xExtent[1] - xExtent[0] + left + right);
303
314
  const yScale = h / (yExtent[1] - yExtent[0] + top + bottom);
304
315
  const clampedScale = clamp(min([xScale, yScale]), zoomScaleExtent[0], zoomScaleExtent[1]);
@@ -441,7 +452,8 @@ class Graph extends ComponentCore {
441
452
  this._scale = transform.k;
442
453
  this._graphGroup.attr('transform', transform.toString());
443
454
  if (isFunction(config.onZoom))
444
- config.onZoom(this._scale, config.zoomScaleExtent);
455
+ config.onZoom(this._scale, config.zoomScaleExtent, event);
456
+ // console.warn('Unovis | Graph: Zoom: ', transform)
445
457
  if (!this._initialTransform)
446
458
  this._initialTransform = transform;
447
459
  // If the event was triggered by a mouse interaction (pan or zoom) we don't
@@ -451,7 +463,9 @@ class Graph extends ComponentCore {
451
463
  const propVal = transform[prop];
452
464
  const initialPropVal = this._initialTransform[prop];
453
465
  const dVal = Math.abs(propVal - initialPropVal);
454
- return prop === 'k' ? 2 * dVal : dVal / 50;
466
+ const scaledDVal = prop === 'k' ? 20 * dVal : dVal / 15;
467
+ acc += scaledDVal;
468
+ return acc;
455
469
  }, 0);
456
470
  if (diff > config.layoutAutofitTolerance)
457
471
  this._isAutoFitDisabled = true;
@@ -461,16 +475,18 @@ class Graph extends ComponentCore {
461
475
  this._nodesGroup.selectAll(`.${gNode}`)
462
476
  .call((nodes.length > config.zoomThrottledUpdateNodeThreshold ? zoomNodesThrottled : zoomNodes), config, this._scale);
463
477
  this._linksGroup.selectAll(`.${gLink}`)
464
- .call((nodes.length > config.zoomThrottledUpdateNodeThreshold ? zoomLinksThrottled : zoomLinks), config, this._scale, this._getMarkerId);
478
+ .call((nodes.length > config.zoomThrottledUpdateNodeThreshold ? zoomLinksThrottled : zoomLinks), config, this._scale, this._getLinkArrowDefId);
465
479
  }
466
480
  _onDragStarted(d, event, nodeSelection) {
481
+ var _a;
467
482
  const { config } = this;
468
483
  this._isDragging = true;
469
484
  d._state.isDragged = true;
470
485
  nodeSelection.call(updateNodes, config, 0, this._scale);
486
+ (_a = config.onNodeDragStart) === null || _a === void 0 ? void 0 : _a.call(config, d, event);
471
487
  }
472
488
  _onDragged(d, event, allNodesSelection) {
473
- var _a, _b;
489
+ var _a, _b, _c;
474
490
  const { config } = this;
475
491
  const transform = zoomTransform(this.g.node());
476
492
  const scale = transform.k;
@@ -512,79 +528,60 @@ class Graph extends ComponentCore {
512
528
  const target = l.target;
513
529
  return source._id === d._id || target._id === d._id;
514
530
  });
515
- linksToUpdate.call(updateLinks, config, 0, scale, this._getMarkerId);
531
+ linksToUpdate.call(updateLinks, config, 0, scale, this._getLinkArrowDefId);
516
532
  const linksToAnimate = linksToUpdate.filter(d => d._state.greyout);
517
533
  if (linksToAnimate.size())
518
534
  animateLinkFlow(linksToAnimate, config, this._scale);
535
+ (_c = config.onNodeDrag) === null || _c === void 0 ? void 0 : _c.call(config, d, event);
519
536
  }
520
537
  _onDragEnded(d, event, nodeSelection) {
538
+ var _a;
521
539
  const { config } = this;
522
540
  this._isDragging = false;
523
541
  d._state.isDragged = false;
524
542
  nodeSelection.call(updateNodes, config, 0, this._scale);
543
+ (_a = config.onNodeDragEnd) === null || _a === void 0 ? void 0 : _a.call(config, d, event);
525
544
  }
526
- _shouldLayoutRecalculate(nextConfig) {
527
- const { config } = this;
528
- if (config.layoutType !== nextConfig.layoutType)
545
+ _shouldLayoutRecalculate() {
546
+ const { prevConfig, config } = this;
547
+ if (prevConfig.layoutType !== config.layoutType)
529
548
  return true;
530
- if (config.layoutNonConnectedAside !== nextConfig.layoutNonConnectedAside)
549
+ if (prevConfig.layoutNonConnectedAside !== config.layoutNonConnectedAside)
531
550
  return true;
532
- if (config.layoutType === GraphLayoutType.Force) {
533
- const forceSettingsDiff = shallowDiff(config.forceLayoutSettings, nextConfig.forceLayoutSettings);
551
+ if (prevConfig.layoutType === GraphLayoutType.Force) {
552
+ const forceSettingsDiff = shallowDiff(prevConfig.forceLayoutSettings, config.forceLayoutSettings);
534
553
  if (Object.keys(forceSettingsDiff).length)
535
554
  return true;
536
555
  }
537
- if (config.layoutType === GraphLayoutType.Dagre) {
538
- const dagreSettingsDiff = shallowDiff(config.dagreLayoutSettings, nextConfig.dagreLayoutSettings);
556
+ if (prevConfig.layoutType === GraphLayoutType.Dagre) {
557
+ const dagreSettingsDiff = shallowDiff(prevConfig.dagreLayoutSettings, config.dagreLayoutSettings);
539
558
  if (Object.keys(dagreSettingsDiff).length)
540
559
  return true;
541
560
  }
542
- if (config.layoutType === GraphLayoutType.Parallel ||
543
- config.layoutType === GraphLayoutType.ParallelHorizontal ||
544
- config.layoutType === GraphLayoutType.Concentric) {
545
- if (config.layoutGroupOrder !== nextConfig.layoutGroupOrder)
561
+ if (prevConfig.layoutType === GraphLayoutType.Parallel ||
562
+ prevConfig.layoutType === GraphLayoutType.ParallelHorizontal ||
563
+ prevConfig.layoutType === GraphLayoutType.Concentric) {
564
+ if (prevConfig.layoutGroupOrder !== config.layoutGroupOrder)
546
565
  return true;
547
- if (config.layoutParallelNodesPerColumn !== nextConfig.layoutParallelNodesPerColumn)
566
+ if (prevConfig.layoutParallelNodesPerColumn !== config.layoutParallelNodesPerColumn)
548
567
  return true;
549
- if (config.layoutParallelSortConnectionsByGroup !== nextConfig.layoutParallelSortConnectionsByGroup)
568
+ if (prevConfig.layoutParallelSortConnectionsByGroup !== config.layoutParallelSortConnectionsByGroup)
550
569
  return true;
551
570
  }
552
571
  return false;
553
572
  }
554
- _getMarkerId(d, color, arrow) {
555
- const { config } = this;
556
- const c = color !== null && color !== void 0 ? color : getLinkColor(d, config);
557
- const a = arrow !== null && arrow !== void 0 ? arrow : getLinkArrow(d, this._scale, config);
558
- return a && c ? `${this.uid}-${stringToHtmlId(c)}-${a}` : null;
573
+ _getLinkArrowDefId(arrow) {
574
+ return arrow ? `${this.uid}-${arrow}` : null;
559
575
  }
560
576
  _addSVGDefs() {
561
- const { datamodel: { links } } = this;
562
577
  // Clean up old defs
563
578
  this._defs.selectAll('*').remove();
564
- // Get all variations of link colors to create markers
565
- const linkColors = unique(clean(links.map(d => getLinkColor(d, this.config))));
566
- this._defs.selectAll('marker')
567
- .data([
568
- ...linkColors.map(d => ({ color: d, arrow: GraphLinkArrowStyle.Single })),
569
- ...linkColors.map(d => ({ color: d, arrow: GraphLinkArrowStyle.Double })), // Double-sided arrows
570
- ]).enter()
571
- .append('marker')
572
- .attr('id', d => this._getMarkerId(null, d.color, d.arrow))
573
- .attr('orient', 'auto')
574
- .attr('markerWidth', d => d.arrow === GraphLinkArrowStyle.Double ? LINK_MARKER_WIDTH * 2 : LINK_MARKER_WIDTH)
575
- .attr('markerHeight', d => d.arrow === GraphLinkArrowStyle.Double ? LINK_MARKER_HEIGHT * 2 : LINK_MARKER_HEIGHT)
576
- .attr('markerUnits', 'userSpaceOnUse')
577
- .attr('refX', LINK_MARKER_WIDTH - LINK_MARKER_HEIGHT / 2)
578
- .attr('refY', LINK_MARKER_HEIGHT - LINK_MARKER_HEIGHT / 2)
579
- .html(d => {
580
- var _a;
581
- return `
582
- <path
583
- d="${d.arrow === GraphLinkArrowStyle.Double ? getDoubleArrowPath() : getArrowPath()}"
584
- fill="${(_a = d.color) !== null && _a !== void 0 ? _a : null}"
585
- />
586
- `;
587
- });
579
+ // Single Arrow
580
+ this._defs.append('path').attr('d', getArrowPath())
581
+ .attr('id', this._getLinkArrowDefId(GraphLinkArrowStyle.Single));
582
+ // Double Arrow
583
+ this._defs.append('path').attr('d', getDoubleArrowPath())
584
+ .attr('id', this._getLinkArrowDefId(GraphLinkArrowStyle.Double));
588
585
  }
589
586
  zoomIn(increment = 0.3) {
590
587
  const scaleBy = 1 + increment;
@@ -600,8 +597,13 @@ class Graph extends ComponentCore {
600
597
  smartTransition(this.g, this.config.duration / 2)
601
598
  .call(this._zoomBehavior.scaleTo, zoomLevel);
602
599
  }
603
- fitView() {
604
- this._fit(this.config.duration / 2);
600
+ getZoom() {
601
+ return zoomTransform(this.g.node()).k;
602
+ }
603
+ fitView(duration = this.config.duration) {
604
+ this._layoutCalculationPromise.then(() => {
605
+ this._fit(duration);
606
+ });
605
607
  }
606
608
  /** Enable automatic fitting to container if it was disabled due to previous zoom / pan interactions */
607
609
  resetAutofitState() {
@@ -641,8 +643,10 @@ Graph.selectors = {
641
643
  nodeGauge: nodeGauge,
642
644
  nodeSideLabel: sideLabelGroup,
643
645
  nodeLabel: label,
646
+ dimmedNode: greyedOutNode,
644
647
  link: gLink,
645
648
  linkLine: link,
649
+ dimmedLink: greyedOutLink,
646
650
  panel: gPanel,
647
651
  panelRect: panel,
648
652
  panelSelection: panelSelection,