ngx-relationship-visualiser 1.0.0

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 (22) hide show
  1. package/README.md +356 -0
  2. package/esm2022/ngx-relationship-visualiser.mjs +5 -0
  3. package/esm2022/projects/ngx-relationship-visualiser-lib/lib/db/graphDatabase.mjs +31 -0
  4. package/esm2022/projects/ngx-relationship-visualiser-lib/lib/models/data.interface.mjs +3 -0
  5. package/esm2022/projects/ngx-relationship-visualiser-lib/lib/ngx-relationship-visualiser.module.mjs +22 -0
  6. package/esm2022/projects/ngx-relationship-visualiser-lib/lib/visualiser/services/dagre-layout.service.mjs +153 -0
  7. package/esm2022/projects/ngx-relationship-visualiser-lib/lib/visualiser/services/visualiser-graph.service.mjs +900 -0
  8. package/esm2022/projects/ngx-relationship-visualiser-lib/lib/visualiser/visualiser-graph/visualiser-graph.component.mjs +119 -0
  9. package/esm2022/public_api.mjs +3 -0
  10. package/fesm2022/ngx-relationship-visualiser.mjs +1219 -0
  11. package/fesm2022/ngx-relationship-visualiser.mjs.map +1 -0
  12. package/index.d.ts +5 -0
  13. package/ngx-relationship-visualiser-1.0.0.tgz +0 -0
  14. package/package.json +59 -0
  15. package/projects/ngx-relationship-visualiser-lib/lib/db/graphDatabase.d.ts +12 -0
  16. package/projects/ngx-relationship-visualiser-lib/lib/models/data.interface.d.ts +30 -0
  17. package/projects/ngx-relationship-visualiser-lib/lib/ngx-relationship-visualiser.module.d.ts +8 -0
  18. package/projects/ngx-relationship-visualiser-lib/lib/visualiser/services/dagre-layout.service.d.ts +51 -0
  19. package/projects/ngx-relationship-visualiser-lib/lib/visualiser/services/visualiser-graph.service.d.ts +28 -0
  20. package/projects/ngx-relationship-visualiser-lib/lib/visualiser/visualiser-graph/visualiser-graph.component.d.ts +30 -0
  21. package/public_api.d.ts +2 -0
  22. package/src/styles.scss +8 -0
@@ -0,0 +1,1219 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Injectable, EventEmitter, Component, ViewChild, Output, Input, NgModule } from '@angular/core';
3
+ import { BrowserModule } from '@angular/platform-browser';
4
+ import * as d3 from 'd3';
5
+ import { ReplaySubject } from 'rxjs';
6
+ import Dexie from 'dexie';
7
+ import * as dagre from '@dagrejs/dagre';
8
+ import * as i4 from '@angular/common';
9
+
10
+ class DexieService extends Dexie {
11
+ graphData;
12
+ constructor() {
13
+ super('GraphDatabase');
14
+ this.version(1).stores({
15
+ graphData: 'dataId'
16
+ });
17
+ this.graphData = this.table('graphData');
18
+ }
19
+ async saveGraphData(data) {
20
+ await this.graphData.put(data);
21
+ }
22
+ async getGraphData(dataId) {
23
+ return await this.graphData.get(dataId);
24
+ }
25
+ async deleteGraphData(dataId) {
26
+ await this.graphData.delete(dataId);
27
+ }
28
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DexieService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
29
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DexieService, providedIn: 'root' });
30
+ }
31
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DexieService, decorators: [{
32
+ type: Injectable,
33
+ args: [{
34
+ providedIn: 'root'
35
+ }]
36
+ }], ctorParameters: () => [] });
37
+
38
+ class VisualiserGraphService {
39
+ dexieService;
40
+ constructor(dexieService) {
41
+ this.dexieService = dexieService;
42
+ }
43
+ links = [];
44
+ nodes = [];
45
+ gBrush = null;
46
+ brushMode = false;
47
+ brushing = false;
48
+ shiftKey;
49
+ extent = null;
50
+ zoom = false;
51
+ zoomToFit = false;
52
+ saveGraphData = new ReplaySubject();
53
+ update(data, element, zoom, zoomToFit) {
54
+ const svg = d3.select(element);
55
+ this.zoom = zoom;
56
+ this.zoomToFit = zoomToFit;
57
+ return this._update(d3, svg, data);
58
+ }
59
+ ticked(link, node, edgepaths) {
60
+ link.each(function (d, i, n) {
61
+ // Total difference in x and y from source to target
62
+ let diffX = d.target.x - d.source.x;
63
+ let diffY = d.target.y - d.source.y;
64
+ // Length of path from center of source node to center of target node
65
+ let pathLength = Math.sqrt(diffX * diffX + diffY * diffY);
66
+ // x and y distances from center to outside edge of target node
67
+ let offsetX = (diffX * 40) / pathLength;
68
+ let offsetY = (diffY * 40) / pathLength;
69
+ d3.select(n[i])
70
+ .attr('x1', d.source.x + offsetX)
71
+ .attr('y1', d.source.y + offsetY)
72
+ .attr('x2', d.target.x - offsetX)
73
+ .attr('y2', d.target.y - offsetY);
74
+ });
75
+ node.attr('transform', function (d) {
76
+ return `translate(${d.x}, ${d.y + 50})`;
77
+ });
78
+ // Sets a boundry for the nodes
79
+ // node.attr('cx', function (d) {
80
+ // return (d.x = Math.max(40, Math.min(900 - 15, d.x)));
81
+ // });
82
+ // node.attr('cy', function (d) {
83
+ // return (d.y = Math.max(50, Math.min(600 - 40, d.y)));
84
+ // });
85
+ edgepaths.attr('d', function (d) {
86
+ return `M ${d.source.x} ${d.source.y} L ${d.target.x} ${d.target.y}`;
87
+ });
88
+ edgepaths.attr('transform', function (d) {
89
+ if (d.target.x < d.source.x) {
90
+ const bbox = this.getBBox();
91
+ const rx = bbox.x + bbox.width / 2;
92
+ const ry = bbox.y + bbox.height / 2;
93
+ return `rotate(180 ${rx} ${ry})`;
94
+ }
95
+ else {
96
+ return 'rotate(0)';
97
+ }
98
+ });
99
+ }
100
+ initDefinitions(svg) {
101
+ const defs = svg.append('defs');
102
+ function createMarker(id, refX, path) {
103
+ defs
104
+ .append('marker')
105
+ .attr('id', id)
106
+ .attr('viewBox', '-0 -5 10 10')
107
+ .attr('refX', refX)
108
+ .attr('refY', 0)
109
+ .attr('orient', 'auto')
110
+ .attr('markerWidth', 8)
111
+ .attr('markerHeight', 8)
112
+ .attr('xoverflow', 'visible')
113
+ .append('svg:path')
114
+ .attr('d', path)
115
+ .attr('fill', '#b4b4b4')
116
+ .style('stroke', 'none');
117
+ }
118
+ createMarker('arrowheadTarget', 0, 'M 0,-5 L 10 ,0 L 0,5');
119
+ createMarker('arrowheadSource', 2, 'M 10 -5 L 0 0 L 10 5');
120
+ return svg;
121
+ }
122
+ forceSimulation(_d3, { width, height }) {
123
+ return _d3
124
+ .forceSimulation()
125
+ .velocityDecay(0.1)
126
+ .force('link', _d3
127
+ .forceLink()
128
+ .id(function (d) {
129
+ return d.id;
130
+ })
131
+ .distance(500)
132
+ .strength(1))
133
+ .force('charge', _d3.forceManyBody().strength(0.1))
134
+ .force('center', _d3.forceCenter(width / 2, height / 2))
135
+ .force('collision', _d3.forceCollide().radius(15));
136
+ }
137
+ compareAndMarkNodesNew(nodes, old_nodes) {
138
+ // Create a map of ids to node objects for the old_nodes array
139
+ const oldMap = old_nodes.reduce((map, node) => {
140
+ map[node.id] = node;
141
+ return map;
142
+ }, {});
143
+ // Check each node in the nodes array to see if it's new or not
144
+ nodes.forEach((node) => {
145
+ if (!oldMap[node.id]) {
146
+ // Node is new, mark it with the newItem property
147
+ node.newItem = true;
148
+ // Remove the dagre coordinates from new nodes so we can set a random one in view
149
+ node.fx = null;
150
+ node.fy = null;
151
+ }
152
+ });
153
+ return nodes;
154
+ }
155
+ removeNewItem(nodes) {
156
+ for (const node of nodes) {
157
+ if (node.hasOwnProperty('newItem')) {
158
+ delete node.newItem;
159
+ }
160
+ }
161
+ return nodes;
162
+ }
163
+ randomiseNodePositions(nodeData, width, height) {
164
+ let minDistance = 100;
165
+ const availableSpace = width * height;
166
+ let adjustedRequiredSpace = nodeData.length * minDistance * minDistance;
167
+ if (adjustedRequiredSpace > availableSpace) {
168
+ while (adjustedRequiredSpace > availableSpace && minDistance > 0) {
169
+ minDistance -= 10;
170
+ adjustedRequiredSpace = nodeData.length * minDistance * minDistance;
171
+ }
172
+ if (adjustedRequiredSpace > availableSpace) {
173
+ throw new Error('Not enough space to accommodate all nodes without a fixed position.');
174
+ }
175
+ }
176
+ nodeData.forEach((node) => {
177
+ if (node.fx === null && node.fy === null) {
178
+ let currentMinDistance = minDistance;
179
+ let canPlaceNode = false;
180
+ while (!canPlaceNode && currentMinDistance > 0) {
181
+ node.fx = crypto.getRandomValues(new Uint32Array(1))[0] % width;
182
+ node.fy = crypto.getRandomValues(new Uint32Array(1))[0] % height;
183
+ canPlaceNode = !nodeData.some((otherNode) => {
184
+ if (otherNode.fx === null ||
185
+ otherNode.fy === null ||
186
+ otherNode === node) {
187
+ return false;
188
+ }
189
+ const dx = otherNode.fx - node.fx;
190
+ const dy = otherNode.fy - node.fy;
191
+ return Math.sqrt(dx * dx + dy * dy) < currentMinDistance;
192
+ });
193
+ if (!canPlaceNode) {
194
+ currentMinDistance--;
195
+ }
196
+ }
197
+ if (!canPlaceNode) {
198
+ throw new Error('Not enough space to accommodate all nodes without a fixed position.');
199
+ }
200
+ }
201
+ });
202
+ return nodeData;
203
+ }
204
+ async _update(_d3, svg, data) {
205
+ const { nodes, links } = data;
206
+ this.nodes = nodes || [];
207
+ this.links = links || [];
208
+ // Disable the reset btn
209
+ let saveBtn = document.getElementById('save_graph');
210
+ saveBtn.setAttribute('disabled', 'true');
211
+ // Width/Height of canvas
212
+ const parentWidth = _d3.select('svg').node().parentNode.clientWidth;
213
+ const parentHeight = _d3.select('svg').node().parentNode.clientHeight;
214
+ // Check to see if nodes are in Dexie
215
+ const oldData = await this.dexieService.getGraphData('nodes');
216
+ const oldNodes = oldData ? oldData.nodes : [];
217
+ if (Array.isArray(oldNodes)) {
218
+ // Compare and set property for new nodes
219
+ this.nodes = this.compareAndMarkNodesNew(nodes, oldNodes);
220
+ // Remove old nodes from Dexie
221
+ await this.dexieService.deleteGraphData('nodes');
222
+ // Add new nodes to Dexie
223
+ await this.dexieService.saveGraphData({ dataId: 'nodes', nodes: data.nodes, links: data.links });
224
+ }
225
+ else {
226
+ // Add first set of nodes to Dexie
227
+ await this.dexieService.saveGraphData({ dataId: 'nodes', nodes: data.nodes, links: data.links });
228
+ }
229
+ // If nodes don't have a fx/fy coordinate we generate a random one - dagre nodes without links and new nodes added to canvas have null coordinates by design
230
+ this.nodes = this.randomiseNodePositions(this.nodes, parentWidth, parentHeight);
231
+ // Getting parents lineStyle and adding it to child objects
232
+ const relationshipsArray = this.links.map(({ lineStyle, targetArrow, sourceArrow, relationships }) => relationships.map((r) => ({
233
+ parentLineStyle: lineStyle,
234
+ parentSourceArrow: sourceArrow,
235
+ parentTargetArrow: targetArrow,
236
+ ...r,
237
+ })));
238
+ // Adding dy value based on link number and position in parent
239
+ relationshipsArray.map((linkRelationship) => {
240
+ linkRelationship.map((linkObject, i) => {
241
+ // dy increments of 15px
242
+ linkObject['dy'] = 20 + i * 15;
243
+ });
244
+ });
245
+ // IE11 does not like .flat
246
+ this.links = relationshipsArray.reduce((acc, val) => acc.concat(val), []);
247
+ d3.select('svg').append('g');
248
+ // Zoom Start
249
+ const zoomContainer = _d3.select('svg g');
250
+ let currentZoom = d3.zoomTransform(d3.select('svg').node());
251
+ const updateZoomLevel = () => {
252
+ const currentScale = currentZoom.k;
253
+ const maxScale = zoom.scaleExtent()[1];
254
+ const zoomPercentage = ((currentScale - 0.5) / (maxScale - 0.5)) * 200;
255
+ const zoomLevelDisplay = document.getElementById('zoom_level');
256
+ const zoomLevelText = `Zoom: ${zoomPercentage.toFixed(0)}%`;
257
+ const zoomInBtn = document.getElementById('zoom_in');
258
+ const zoomOutBtn = document.getElementById('zoom_out');
259
+ const zoomResetBtn = document.getElementById('zoom_reset');
260
+ // It might not exist depending on the this.zoom boolean
261
+ if (zoomResetBtn) {
262
+ zoomResetBtn.setAttribute('disabled', 'true');
263
+ }
264
+ // Check if the zoom level has changed before updating the display / allows for panning without showing the zoom percentage
265
+ if (zoomLevelDisplay && zoomLevelDisplay.innerHTML !== zoomLevelText) {
266
+ zoomLevelDisplay.innerHTML = zoomLevelText;
267
+ zoomLevelDisplay.style.opacity = '1';
268
+ setTimeout(() => {
269
+ if (zoomLevelDisplay) {
270
+ zoomLevelDisplay.style.opacity = '0';
271
+ }
272
+ }, 2000);
273
+ }
274
+ // Disable the zoomInBtn if the zoom level is at 200%
275
+ if (zoomInBtn) {
276
+ if (zoomPercentage === 200) {
277
+ zoomInBtn.setAttribute('disabled', 'true');
278
+ }
279
+ else {
280
+ zoomInBtn.removeAttribute('disabled');
281
+ }
282
+ }
283
+ // Disable the zoomOutBtn if the zoom level is at 0%
284
+ if (zoomOutBtn) {
285
+ if (zoomPercentage === 0) {
286
+ zoomOutBtn.setAttribute('disabled', 'true');
287
+ }
288
+ else {
289
+ zoomOutBtn.removeAttribute('disabled');
290
+ }
291
+ }
292
+ // Disable the zoomResetBtn if the zoom level is at 100%
293
+ if (zoomResetBtn) {
294
+ if (zoomPercentage === 100) {
295
+ zoomResetBtn.setAttribute('disabled', 'true');
296
+ }
297
+ else {
298
+ zoomResetBtn.removeAttribute('disabled');
299
+ }
300
+ }
301
+ };
302
+ let zoomedInit;
303
+ const zoomed = () => {
304
+ const transform = d3.event.transform;
305
+ zoomContainer.attr('transform', `translate(${transform.x}, ${transform.y}) scale(${transform.k})`);
306
+ currentZoom = transform;
307
+ zoomedInit = true;
308
+ updateZoomLevel();
309
+ };
310
+ const zoom = d3
311
+ .zoom()
312
+ .scaleExtent([0.5, 1.5])
313
+ .on('start', function () {
314
+ d3.select(this).style('cursor', this.zoom ? null : 'grabbing');
315
+ })
316
+ .on('zoom', this.zoom ? zoomed : null)
317
+ .on('end', function () {
318
+ d3.select(this).style('cursor', 'grab');
319
+ });
320
+ svg
321
+ .call(zoom)
322
+ .style('cursor', 'grab')
323
+ .on(this.zoom ? null : 'wheel.zoom', null)
324
+ .on('dblclick.zoom', null);
325
+ zoom.filter(() => !d3.event.shiftKey);
326
+ // Zoom button controls
327
+ d3.select('#zoom_in').on('click', function () {
328
+ zoom.scaleBy(svg.transition().duration(750), 1.2);
329
+ updateZoomLevel();
330
+ });
331
+ d3.select('#zoom_out').on('click', function () {
332
+ zoom.scaleBy(svg.transition().duration(750), 0.8);
333
+ updateZoomLevel();
334
+ });
335
+ d3.select('#zoom_reset').on('click', function () {
336
+ zoom.scaleTo(svg.transition().duration(750), 1);
337
+ updateZoomLevel();
338
+ });
339
+ // Zoom to fit function and Button
340
+ const handleZoomToFit = () => {
341
+ const nodeBBox = zoomContainer.node().getBBox();
342
+ // Calculate scale and translate values to fit all nodes
343
+ const padding = 30;
344
+ const scaleX = (parentWidth - padding * 2) / nodeBBox.width;
345
+ const scaleY = (parentHeight - padding * 2) / nodeBBox.height;
346
+ const scale = Math.min(scaleX, scaleY, 1.0); // Restrict scale to a maximum of 1.0
347
+ const translateX = -nodeBBox.x * scale + (parentWidth - nodeBBox.width * scale) / 2;
348
+ const translateY = -nodeBBox.y * scale + (parentHeight - nodeBBox.height * scale) / 2;
349
+ // Get the bounding box of all nodes
350
+ const allNodes = zoomContainer.selectAll('.node-wrapper');
351
+ const allNodesBBox = allNodes.nodes().reduce((acc, node) => {
352
+ const nodeBBox = node.getBBox();
353
+ acc.x = Math.min(acc.x, nodeBBox.x);
354
+ acc.y = Math.min(acc.y, nodeBBox.y);
355
+ acc.width = Math.max(acc.width, nodeBBox.x + nodeBBox.width);
356
+ acc.height = Math.max(acc.height, nodeBBox.y + nodeBBox.height);
357
+ return acc;
358
+ }, { x: Infinity, y: Infinity, width: -Infinity, height: -Infinity });
359
+ // Check if all nodes are within the viewable container
360
+ if (allNodesBBox.x * scale >= 0 &&
361
+ allNodesBBox.y * scale >= 0 &&
362
+ allNodesBBox.width * scale <= parentWidth &&
363
+ allNodesBBox.height * scale <= parentHeight) {
364
+ // All nodes are within the viewable container, no need to apply zoom transform
365
+ return;
366
+ }
367
+ // Manually reset the zoom transform
368
+ zoomContainer
369
+ .transition()
370
+ .duration(750)
371
+ .attr('transform', 'translate(0, 0) scale(1)');
372
+ // Apply zoom transform to zoomContainer
373
+ zoomContainer
374
+ .transition()
375
+ .duration(750)
376
+ .attr('transform', `translate(${translateX}, ${translateY}) scale(${scale})`);
377
+ // Update the currentZoom variable with the new transform
378
+ // zoomedInit - created because if zoomToFit is called before anything else it screws up the base transform - e.g. showCurrentMatch
379
+ if (zoomedInit) {
380
+ currentZoom.x = translateX;
381
+ currentZoom.y = translateY;
382
+ currentZoom.k = scale;
383
+ }
384
+ updateZoomLevel();
385
+ };
386
+ d3.select('#zoom_to_fit').on('click', handleZoomToFit);
387
+ // Check if zoom level is at 0% or 100% before allowing mousewheel zoom - this stabilises the canvas when the limit is reached
388
+ svg.on('wheel', () => {
389
+ const currentScale = currentZoom.k;
390
+ const maxScale = zoom.scaleExtent()[1];
391
+ const minScale = zoom.scaleExtent()[0];
392
+ if (currentScale === maxScale || currentScale === minScale) {
393
+ d3.event.preventDefault();
394
+ }
395
+ });
396
+ // Zoom End
397
+ // For arrows
398
+ this.initDefinitions(svg);
399
+ const simulation = this.forceSimulation(_d3, {
400
+ width: +svg.attr('width'),
401
+ height: +svg.attr('height'),
402
+ });
403
+ // Brush Start
404
+ let gBrushHolder = svg.append('g');
405
+ let brush = d3
406
+ .brush()
407
+ .on('start', () => {
408
+ this.brushing = true;
409
+ nodeEnter.each((d) => {
410
+ d.previouslySelected = this.shiftKey && d.selected;
411
+ });
412
+ _d3
413
+ .selectAll('.edgelabel')
414
+ .style('font-weight', 400)
415
+ .style('fill', '#212529');
416
+ })
417
+ .on('brush', () => {
418
+ this.extent = d3.event.selection;
419
+ if (!d3.event.sourceEvent || !this.extent || !this.brushMode)
420
+ return;
421
+ if (!currentZoom)
422
+ return;
423
+ nodeEnter
424
+ .classed('selected', (d) => {
425
+ return (d.selected =
426
+ d.previouslySelected ^
427
+ ((d3.event.selection[0][0] <=
428
+ d.x * currentZoom.k + currentZoom.x &&
429
+ d.x * currentZoom.k + currentZoom.x <
430
+ d3.event.selection[1][0] &&
431
+ d3.event.selection[0][1] <=
432
+ d.y * currentZoom.k + currentZoom.y &&
433
+ d.y * currentZoom.k + currentZoom.y <
434
+ d3.event.selection[1][1])));
435
+ })
436
+ .select('.nodeText')
437
+ .classed('selected', (d) => d.selected)
438
+ .style('fill', (d) => (d.selected ? 'blue' : '#999'))
439
+ .style('font-weight', (d) => (d.selected ? 700 : 400));
440
+ this.extent = d3.event.selection;
441
+ })
442
+ .on('end', () => {
443
+ if (!d3.event.sourceEvent || !this.extent || !this.gBrush)
444
+ return;
445
+ this.gBrush.call(brush.move, null);
446
+ if (!this.brushMode) {
447
+ // the shift key has been release before we ended our brushing
448
+ this.gBrush.remove();
449
+ this.gBrush = null;
450
+ }
451
+ this.brushing = false;
452
+ nodeEnter
453
+ .select('.nodeText')
454
+ .filter(function () {
455
+ return !d3.select(this.parentNode).classed('selected');
456
+ })
457
+ .style('fill', '#212529')
458
+ .style('font-weight', 400);
459
+ });
460
+ let keyup = () => {
461
+ this.shiftKey = false;
462
+ this.brushMode = false;
463
+ if (this.gBrush && !this.brushing) {
464
+ // only remove the brush if we're not actively brushing
465
+ // otherwise it'll be removed when the brushing ends
466
+ this.gBrush.remove();
467
+ this.gBrush = null;
468
+ }
469
+ };
470
+ let keydown = () => {
471
+ // Allows us to turn off default listeners for keyModifiers(shift)
472
+ brush.filter(() => d3.event.shiftKey);
473
+ brush.keyModifiers(false);
474
+ // holding shift key
475
+ if (d3.event.keyCode === 16) {
476
+ this.shiftKey = true;
477
+ if (!this.gBrush) {
478
+ this.brushMode = true;
479
+ this.gBrush = gBrushHolder.append('g').attr('class', 'brush');
480
+ this.gBrush.call(brush);
481
+ }
482
+ }
483
+ };
484
+ d3.select('body').on('keydown', keydown).on('keyup', keyup);
485
+ // Brush End
486
+ const filteredLine = this.links.filter(({ source, target }, index, linksArray) => {
487
+ // Filter out any objects that have matching source and target property values
488
+ // To display only one line (parentLineStyle) - removes html bloat and a darkened line
489
+ return (index ===
490
+ linksArray.findIndex((obj) => obj.source === source && obj.target === target));
491
+ });
492
+ const link = zoomContainer.selectAll().data(filteredLine, function (d) {
493
+ return d.id;
494
+ });
495
+ zoomContainer.selectAll('line').data(link).exit().remove();
496
+ const linkEnter = link
497
+ .join('line')
498
+ .style('stroke', function (d) {
499
+ if (d.parentLineStyle === 'Solid') {
500
+ return '#777';
501
+ }
502
+ else {
503
+ return '#b4b4b4';
504
+ }
505
+ })
506
+ .style('stroke-opacity', '.6')
507
+ .style('stroke-dasharray', function (d) {
508
+ if (d.parentLineStyle === 'Dotted') {
509
+ return '8,5';
510
+ }
511
+ return null;
512
+ })
513
+ .style('stroke-width', '2px')
514
+ .attr('class', 'link')
515
+ .attr('id', function (d) {
516
+ const suffix = '_line';
517
+ const source = d.source ? d.source : '';
518
+ const target = d.target ? d.target : '';
519
+ return `${source}_${target}${suffix}`;
520
+ })
521
+ .attr('marker-end', function (d) {
522
+ if (d.parentTargetArrow === true) {
523
+ return 'url(#arrowheadTarget)';
524
+ }
525
+ return null;
526
+ })
527
+ .attr('marker-start', function (d) {
528
+ if (d.parentSourceArrow === true) {
529
+ return 'url(#arrowheadSource)';
530
+ }
531
+ return null;
532
+ });
533
+ link.append('title').text(function (d) {
534
+ return d.label;
535
+ });
536
+ const edgepaths = zoomContainer.selectAll().data(this.links, function (d) {
537
+ return d.id;
538
+ });
539
+ zoomContainer.selectAll('path').data(edgepaths).exit().remove();
540
+ const edgepathsEnter = edgepaths
541
+ .join('svg:path')
542
+ .attr('class', 'edgepath')
543
+ .attr('fill-opacity', 0)
544
+ .attr('stroke-opacity', 0)
545
+ .attr('id', function (d, i) {
546
+ return 'edgepath' + i;
547
+ });
548
+ const edgelabels = zoomContainer.selectAll().data(this.links, function (d) {
549
+ return d.id;
550
+ });
551
+ zoomContainer.selectAll('text').data(edgelabels).exit().remove();
552
+ const edgelabelsEnter = edgelabels
553
+ .enter()
554
+ .append('text')
555
+ .attr('class', 'edgelabel')
556
+ .attr('id', function (d) {
557
+ const suffix = '_text';
558
+ const source = d.source ? d.source : '';
559
+ const target = d.target ? d.target : '';
560
+ return `${source}_${target}${suffix}`;
561
+ })
562
+ .style('text-anchor', 'middle')
563
+ .attr('font-size', 14)
564
+ .attr('dy', function (d) {
565
+ return d.dy;
566
+ });
567
+ edgelabelsEnter
568
+ .append('textPath')
569
+ .attr('xlink:href', function (d, i) {
570
+ return '#edgepath' + i;
571
+ })
572
+ .style('cursor', 'pointer')
573
+ .attr('dominant-baseline', 'bottom')
574
+ .attr('startOffset', '50%')
575
+ .text(function (d) {
576
+ return d.label;
577
+ });
578
+ edgelabelsEnter
579
+ .selectAll('textPath')
580
+ .filter(function (d) {
581
+ return d.linkIcon;
582
+ })
583
+ .append('tspan')
584
+ .style('fill', '#856404')
585
+ .style('font-weight', '700')
586
+ .attr('class', 'fa')
587
+ .text(' \uf0c1');
588
+ // on normal label link click - highlight labels
589
+ svg.selectAll('.edgelabel').on('click', function (d) {
590
+ _d3.event.stopPropagation();
591
+ nodeEnter.each(function (d) {
592
+ d.selected = false;
593
+ d.previouslySelected = false;
594
+ });
595
+ node.classed('selected', false);
596
+ _d3
597
+ .selectAll('.nodeText')
598
+ .style('fill', '#212529')
599
+ .style('font-weight', 400);
600
+ _d3
601
+ .selectAll('.edgelabel')
602
+ .style('font-weight', 400)
603
+ .style('fill', '#212529');
604
+ _d3.select(this).style('fill', 'blue').style('font-weight', 700);
605
+ });
606
+ const node = zoomContainer.selectAll().data(this.nodes, function (d) {
607
+ return d.id;
608
+ });
609
+ zoomContainer.selectAll('g').data(node).exit().remove();
610
+ const nodeEnter = node
611
+ .join('g')
612
+ .call(_d3
613
+ .drag()
614
+ .on('start', function dragstarted(d) {
615
+ // Enable the save & reset btn
616
+ document.getElementById('save_graph').removeAttribute('disabled');
617
+ if (!_d3.event.active)
618
+ simulation.alphaTarget(0.9).restart();
619
+ if (!d.selected && !this.shiftKey) {
620
+ // if this node isn't selected, then we have to unselect every other node
621
+ nodeEnter.classed('selected', function (p) {
622
+ return (p.selected = p.previouslySelected = false);
623
+ });
624
+ // remove the selected styling on other nodes and labels when we drag a non-selected node
625
+ _d3
626
+ .selectAll('.edgelabel')
627
+ .style('fill', '#212529')
628
+ .style('font-weight', 400);
629
+ _d3
630
+ .selectAll('.nodeText')
631
+ .style('font-weight', 400)
632
+ .style('fill', '#212529');
633
+ }
634
+ _d3.select(this).classed('selected', function (p) {
635
+ d.previouslySelected = d.selected;
636
+ return (d.selected = true);
637
+ });
638
+ nodeEnter
639
+ .filter(function (d) {
640
+ return d.selected;
641
+ })
642
+ .each(function (d) {
643
+ d.fx = d.x;
644
+ d.fy = d.y;
645
+ });
646
+ })
647
+ .on('drag', function dragged(d) {
648
+ nodeEnter
649
+ .filter(function (d) {
650
+ return d.selected;
651
+ })
652
+ .each(function (d) {
653
+ d.fx += _d3.event.dx;
654
+ d.fy += _d3.event.dy;
655
+ });
656
+ })
657
+ .on('end', function dragended(d) {
658
+ if (!_d3.event.active) {
659
+ simulation.alphaTarget(0.3).restart();
660
+ }
661
+ d.fx = d.x;
662
+ d.fy = d.y;
663
+ // Subscribes to updated graph positions for save
664
+ self.saveGraphData.next(data);
665
+ }))
666
+ .attr('class', 'node-wrapper')
667
+ .attr('id', function (d) {
668
+ return d.id;
669
+ });
670
+ // no collision - already using this in statement
671
+ const self = this;
672
+ // node click and ctrl + click
673
+ svg.selectAll('.node-wrapper').on('click', function (d) {
674
+ // so we don't activate the canvas .click event
675
+ _d3.event.stopPropagation();
676
+ // setting the select attribute to the object on single select so we can drag them
677
+ d.selected = true;
678
+ svg.selectAll('.node-wrapper').classed('selected', false);
679
+ d3.select(this).classed('selected', true);
680
+ nodeEnter.each(function (d) {
681
+ d.selected = false;
682
+ d.previouslySelected = false;
683
+ });
684
+ // remove style from selected node before the class is removed
685
+ _d3
686
+ .selectAll('.selected')
687
+ .selectAll('.nodeText')
688
+ .style('fill', '#212529');
689
+ // Remove styles from all other nodes and labels on single left click
690
+ _d3.selectAll('.edgelabel').style('fill', '#212529');
691
+ _d3
692
+ .selectAll('.nodeText')
693
+ .style('fill', '#212529')
694
+ .style('font-weight', 400);
695
+ // Add style on single left click
696
+ _d3
697
+ .select(this)
698
+ .select('.nodeText')
699
+ .style('fill', 'blue')
700
+ .style('font-weight', 700);
701
+ return null;
702
+ });
703
+ //click on canvas to remove selected nodes
704
+ _d3.select('svg').on('click', () => {
705
+ nodeEnter.each(function (d) {
706
+ d.selected = false;
707
+ d.previouslySelected = false;
708
+ });
709
+ node.classed('selected', false);
710
+ _d3
711
+ .selectAll('.selected')
712
+ .selectAll('.nodeText')
713
+ .style('fill', '#212529')
714
+ .style('font-weight', 400);
715
+ _d3.selectAll('.selected').classed('selected', false);
716
+ _d3
717
+ .selectAll('.edgelabel')
718
+ .style('fill', '#212529')
719
+ .style('font-weight', 400);
720
+ });
721
+ nodeEnter
722
+ .filter(function (d) {
723
+ if (!d.imageUrl || d.imageUrl === '') {
724
+ return null;
725
+ }
726
+ return true;
727
+ })
728
+ .append('image')
729
+ .attr('xlink:href', function (d) {
730
+ return d.imageUrl;
731
+ })
732
+ .attr('x', -15)
733
+ .attr('y', -60)
734
+ .attr('class', function (d) {
735
+ const suffix = 'image';
736
+ const id = d.id ? d.id : '';
737
+ return `${id}_${suffix}`;
738
+ })
739
+ .attr('id', function (d) {
740
+ const id = d.id ? d.id : '';
741
+ return `${id}`;
742
+ })
743
+ .attr('width', 32)
744
+ .attr('height', 32)
745
+ .attr('class', 'image')
746
+ .style('cursor', 'pointer');
747
+ nodeEnter
748
+ .filter(function (d) {
749
+ if (!d.icon || d.icon === '') {
750
+ return null;
751
+ }
752
+ return true;
753
+ })
754
+ .append('text')
755
+ .text(function (d) {
756
+ return d.icon;
757
+ })
758
+ .attr('x', -18)
759
+ .attr('y', -30)
760
+ .attr('class', function (d) {
761
+ const suffix = 'icon';
762
+ const id = d.id ? d.id : '';
763
+ return `${id}_${suffix} fa`;
764
+ })
765
+ .attr('id', function (d) {
766
+ const id = d.id ? d.id : '';
767
+ return `${id}`;
768
+ })
769
+ .style('font-size', '35px')
770
+ .style('cursor', 'pointer');
771
+ const nodeText = nodeEnter
772
+ .append('text')
773
+ .attr('id', 'nodeText')
774
+ .attr('class', 'nodeText')
775
+ .style('text-anchor', 'middle')
776
+ .style('cursor', 'pointer')
777
+ .attr('dy', -3)
778
+ .attr('y', -25)
779
+ .attr('testhook', function (d) {
780
+ const suffix = 'text';
781
+ const id = d.id ? d.id : '';
782
+ return `${id}_${suffix}`;
783
+ });
784
+ nodeText
785
+ .selectAll('tspan.text')
786
+ .data((d) => d.label)
787
+ .enter()
788
+ .append('tspan')
789
+ .attr('class', 'nodeTextTspan')
790
+ .text((d) => d)
791
+ .style('font-size', '14px')
792
+ .attr('x', -10)
793
+ .attr('dx', 10)
794
+ .attr('dy', 15);
795
+ nodeEnter
796
+ .filter(function (d) {
797
+ if (!d.additionalIcon) {
798
+ return null;
799
+ }
800
+ return true;
801
+ })
802
+ .append('text')
803
+ .attr('id', function (d) {
804
+ const suffix = 'additionalIcon';
805
+ const id = d.id ? d.id : '';
806
+ return `${id}_${suffix}`;
807
+ })
808
+ .attr('width', 100)
809
+ .attr('height', 25)
810
+ .attr('x', 30)
811
+ .attr('y', -50)
812
+ .attr('class', 'fa')
813
+ .style('fill', '#856404')
814
+ .text(function (d) {
815
+ return d.additionalIcon;
816
+ });
817
+ // transition effects for new pulsating nodes
818
+ nodeEnter
819
+ .filter(function (d) {
820
+ if (!d.newItem) {
821
+ return null;
822
+ }
823
+ return true;
824
+ })
825
+ .select('text')
826
+ .transition()
827
+ .duration(1000)
828
+ .attr('fill', 'blue')
829
+ .attr('font-weight', 700)
830
+ .attr('fill-opacity', 1)
831
+ .transition()
832
+ .duration(1000)
833
+ .attr('fill', 'blue')
834
+ .attr('font-weight', 700)
835
+ .attr('fill-opacity', 0.1)
836
+ .transition()
837
+ .duration(1000)
838
+ .attr('fill', 'blue')
839
+ .attr('font-weight', 700)
840
+ .attr('fill-opacity', 1)
841
+ .transition()
842
+ .duration(1000)
843
+ .attr('fill', 'blue')
844
+ .attr('font-weight', 700)
845
+ .attr('fill-opacity', 0.1)
846
+ .transition()
847
+ .duration(1000)
848
+ .attr('fill', 'blue')
849
+ .attr('font-weight', 700)
850
+ .attr('fill-opacity', 1)
851
+ .transition()
852
+ .duration(1000)
853
+ .attr('fill', '#212529')
854
+ .attr('font-weight', 400)
855
+ .attr('fill-opacity', 1)
856
+ .on('end', function () {
857
+ return d3.select(this).call(_d3.transition);
858
+ });
859
+ nodeEnter
860
+ .filter(function (d) {
861
+ if (!d.newItem) {
862
+ return null;
863
+ }
864
+ return true;
865
+ })
866
+ .select('image')
867
+ .transition()
868
+ .duration(1000)
869
+ .attr('width', 45)
870
+ .attr('height', 45)
871
+ .transition()
872
+ .duration(1000)
873
+ .attr('width', 32)
874
+ .attr('height', 32)
875
+ .transition()
876
+ .duration(1000)
877
+ .attr('width', 45)
878
+ .attr('height', 45)
879
+ .transition()
880
+ .duration(1000)
881
+ .attr('width', 32)
882
+ .attr('height', 32)
883
+ .transition()
884
+ .duration(1000)
885
+ .attr('width', 45)
886
+ .attr('height', 45)
887
+ .transition()
888
+ .duration(1000)
889
+ .attr('width', 32)
890
+ .attr('height', 32)
891
+ .on('end', function () {
892
+ return d3.select(this).call(d3.transition);
893
+ });
894
+ // Remove the newClass so they don't animate next time
895
+ this.nodes = this.removeNewItem(this.nodes);
896
+ nodeEnter.append('title').text(function (d) {
897
+ return d.label;
898
+ });
899
+ const maxTicks = 30;
900
+ let tickCount = 0;
901
+ let zoomToFitCalled = false;
902
+ simulation.nodes(this.nodes).on('tick', () => {
903
+ if (this.zoomToFit && tickCount >= maxTicks && !zoomToFitCalled) {
904
+ simulation.stop();
905
+ handleZoomToFit();
906
+ zoomToFitCalled = true;
907
+ }
908
+ else {
909
+ this.ticked(linkEnter, nodeEnter, edgepathsEnter);
910
+ tickCount++;
911
+ }
912
+ });
913
+ simulation.force('link').links(this.links);
914
+ self.saveGraphData.next(data);
915
+ }
916
+ resetGraph(initialData, element, zoom, zoomToFit) {
917
+ // Reset the data to its initial state
918
+ this.nodes = [];
919
+ this.links = [];
920
+ // Call the update method again to re-simulate the graph with the new data
921
+ this.update(initialData, element, zoom, zoomToFit);
922
+ }
923
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VisualiserGraphService, deps: [{ token: DexieService }], target: i0.ɵɵFactoryTarget.Injectable });
924
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VisualiserGraphService, providedIn: 'root' });
925
+ }
926
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VisualiserGraphService, decorators: [{
927
+ type: Injectable,
928
+ args: [{
929
+ providedIn: 'root',
930
+ }]
931
+ }], ctorParameters: () => [{ type: DexieService }] });
932
+
933
+ var Orientation;
934
+ (function (Orientation) {
935
+ Orientation["LEFT_TO_RIGHT"] = "LR";
936
+ Orientation["RIGHT_TO_LEFT"] = "RL";
937
+ Orientation["TOP_TO_BOTTOM"] = "TB";
938
+ Orientation["BOTTOM_TO_TOP"] = "BT";
939
+ })(Orientation || (Orientation = {}));
940
+ var Alignment;
941
+ (function (Alignment) {
942
+ Alignment["CENTER"] = "C";
943
+ Alignment["UP_LEFT"] = "UL";
944
+ Alignment["UP_RIGHT"] = "UR";
945
+ Alignment["DOWN_LEFT"] = "DL";
946
+ Alignment["DOWN_RIGHT"] = "DR";
947
+ })(Alignment || (Alignment = {}));
948
+ class DagreNodesOnlyLayout {
949
+ defaultSettings = {
950
+ orientation: Orientation.LEFT_TO_RIGHT,
951
+ marginX: 70,
952
+ marginY: 70,
953
+ edgePadding: 200,
954
+ rankPadding: 300,
955
+ nodePadding: 100,
956
+ curveDistance: 20,
957
+ multigraph: true,
958
+ compound: true,
959
+ align: Alignment.UP_RIGHT,
960
+ acyclicer: undefined,
961
+ ranker: 'network-simplex',
962
+ };
963
+ dagreGraph;
964
+ dagreNodes;
965
+ dagreEdges;
966
+ renderLayout(graph) {
967
+ this.createDagreGraph(graph);
968
+ dagre.layout(this.dagreGraph);
969
+ for (const dagreNodeId in this.dagreGraph._nodes) {
970
+ const dagreNode = this.dagreGraph._nodes[dagreNodeId];
971
+ const node = graph.nodes.find((n) => n.id === dagreNode.id);
972
+ if (node.fx === null && node.fy === null) {
973
+ // Check if the node has any associated edges
974
+ const hasAssociatedEdges = graph.links.some((link) => link.source === dagreNode.id || link.target === dagreNode.id);
975
+ if (hasAssociatedEdges) {
976
+ node.fx = dagreNode.x;
977
+ node.fy = dagreNode.y;
978
+ }
979
+ }
980
+ node.dimension = {
981
+ width: dagreNode.width,
982
+ height: dagreNode.height,
983
+ };
984
+ }
985
+ return graph;
986
+ }
987
+ initRenderLayout(graph) {
988
+ this.createDagreGraph(graph);
989
+ dagre.layout(this.dagreGraph);
990
+ let minFy = Infinity;
991
+ for (const dagreNodeId in this.dagreGraph._nodes) {
992
+ const dagreNode = this.dagreGraph._nodes[dagreNodeId];
993
+ const node = graph.nodes.find((n) => n.id === dagreNode.id);
994
+ // Check if the node has any associated edges
995
+ const hasAssociatedEdges = graph.links.some((link) => link.source === dagreNode.id || link.target === dagreNode.id);
996
+ if (hasAssociatedEdges) {
997
+ node.fx = dagreNode.x;
998
+ node.fy = dagreNode.y;
999
+ minFy = Math.min(minFy, dagreNode.y - this.defaultSettings.marginY);
1000
+ }
1001
+ else {
1002
+ // Give them a null value to later random position them only when the layout button is pressed so they come into view
1003
+ node.fx = null;
1004
+ node.fy = null;
1005
+ }
1006
+ node.dimension = {
1007
+ width: dagreNode.width,
1008
+ height: dagreNode.height,
1009
+ };
1010
+ }
1011
+ // Adjust the fy values to start from 0 if there are associated edges
1012
+ if (minFy !== Infinity) {
1013
+ for (const node of graph.nodes) {
1014
+ if (node.fy !== null) {
1015
+ node.fy -= minFy;
1016
+ }
1017
+ }
1018
+ }
1019
+ return graph;
1020
+ }
1021
+ createDagreGraph(graph) {
1022
+ const settings = Object.assign({}, this.defaultSettings);
1023
+ this.dagreGraph = new dagre.graphlib.Graph({
1024
+ compound: settings.compound,
1025
+ multigraph: settings.multigraph,
1026
+ });
1027
+ this.dagreGraph.setGraph({
1028
+ rankdir: settings.orientation,
1029
+ marginx: settings.marginX,
1030
+ marginy: settings.marginY,
1031
+ edgesep: settings.edgePadding,
1032
+ ranksep: settings.rankPadding,
1033
+ nodesep: settings.nodePadding,
1034
+ align: settings.align,
1035
+ acyclicer: settings.acyclicer,
1036
+ ranker: settings.ranker,
1037
+ multigraph: settings.multigraph,
1038
+ compound: settings.compound,
1039
+ });
1040
+ this.dagreNodes = graph.nodes.map((n) => {
1041
+ const node = Object.assign({}, n);
1042
+ node.width = 20;
1043
+ node.height = 20;
1044
+ node.x = n.fx;
1045
+ node.y = n.fy;
1046
+ return node;
1047
+ });
1048
+ this.dagreEdges = graph.links.map((l) => {
1049
+ const newLink = Object.assign({}, l);
1050
+ return newLink;
1051
+ });
1052
+ for (const node of this.dagreNodes) {
1053
+ if (!node.width) {
1054
+ node.width = 20;
1055
+ }
1056
+ if (!node.height) {
1057
+ node.height = 30;
1058
+ }
1059
+ // update dagre
1060
+ this.dagreGraph.setNode(node.id, node);
1061
+ }
1062
+ // update dagre
1063
+ for (const edge of this.dagreEdges) {
1064
+ if (settings.multigraph) {
1065
+ this.dagreGraph.setEdge(edge.source, edge.target, edge, edge.linkId);
1066
+ }
1067
+ else {
1068
+ this.dagreGraph.setEdge(edge.source, edge.target);
1069
+ }
1070
+ }
1071
+ return this.dagreGraph;
1072
+ }
1073
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DagreNodesOnlyLayout, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1074
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DagreNodesOnlyLayout, providedIn: 'root' });
1075
+ }
1076
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DagreNodesOnlyLayout, decorators: [{
1077
+ type: Injectable,
1078
+ args: [{
1079
+ providedIn: 'root',
1080
+ }]
1081
+ }] });
1082
+
1083
+ class VisualiserGraphComponent {
1084
+ visualiserGraphService;
1085
+ dagreNodesOnlyLayout;
1086
+ dexieService;
1087
+ graphElement;
1088
+ saveGraphDataEvent = new EventEmitter();
1089
+ saveGraphData;
1090
+ width;
1091
+ savedGraphData;
1092
+ showConfirmation = false;
1093
+ buttonBarRightPosition;
1094
+ zoom = true;
1095
+ zoomToFit = false;
1096
+ constructor(visualiserGraphService, dagreNodesOnlyLayout, dexieService) {
1097
+ this.visualiserGraphService = visualiserGraphService;
1098
+ this.dagreNodesOnlyLayout = dagreNodesOnlyLayout;
1099
+ this.dexieService = dexieService;
1100
+ }
1101
+ set data(data) {
1102
+ if (!data || !data.dataId) {
1103
+ console.error('Invalid data input');
1104
+ return;
1105
+ }
1106
+ this.savedGraphData = data;
1107
+ // Timeout: The input arrives before the svg is rendered, therefore the nativeElement does not exist
1108
+ setTimeout(async () => {
1109
+ this.dagreNodesOnlyLayout.renderLayout(data);
1110
+ // Take a copy of input for reset
1111
+ await this.dexieService.saveGraphData(data);
1112
+ this.visualiserGraphService.update(data, this.graphElement.nativeElement, this.zoom, this.zoomToFit);
1113
+ }, 500);
1114
+ }
1115
+ ngOnInit() {
1116
+ this.updateWidth();
1117
+ this.buttonBarRightPosition = '0';
1118
+ // Initialize with default empty data if no data is provided
1119
+ if (!this.savedGraphData) {
1120
+ console.warn('No data provided, using empty data set');
1121
+ this.data = {
1122
+ dataId: '1',
1123
+ nodes: [],
1124
+ links: [],
1125
+ };
1126
+ }
1127
+ }
1128
+ onResize(event) {
1129
+ this.updateWidth();
1130
+ }
1131
+ updateWidth() {
1132
+ this.width = document.getElementById('pageId').offsetWidth;
1133
+ }
1134
+ async onConfirmSave() {
1135
+ if (!this.savedGraphData) {
1136
+ console.error('savedGraphData is not set');
1137
+ return;
1138
+ }
1139
+ bootbox.confirm({
1140
+ title: "Save Graph",
1141
+ centerVertical: true,
1142
+ message: "Are you sure you want to save the graph?",
1143
+ buttons: {
1144
+ confirm: {
1145
+ label: 'Yes',
1146
+ className: 'btn-success'
1147
+ },
1148
+ cancel: {
1149
+ label: 'No',
1150
+ className: 'btn-danger'
1151
+ }
1152
+ },
1153
+ callback: async (result) => {
1154
+ if (result) {
1155
+ this.visualiserGraphService.saveGraphData.subscribe((saveGraphData) => {
1156
+ this.saveGraphData = saveGraphData;
1157
+ });
1158
+ this.saveGraphDataEvent.emit(this.saveGraphData);
1159
+ this.disableButtons(true);
1160
+ this.data = this.saveGraphData;
1161
+ this.showConfirmationMessage();
1162
+ }
1163
+ }
1164
+ });
1165
+ }
1166
+ disableButtons(disabled) {
1167
+ document.querySelectorAll('#save_graph, #reset_graph').forEach(btn => {
1168
+ btn.setAttribute('disabled', String(disabled));
1169
+ });
1170
+ }
1171
+ showConfirmationMessage() {
1172
+ this.showConfirmation = true;
1173
+ setTimeout(() => {
1174
+ this.showConfirmation = false;
1175
+ }, 3000);
1176
+ }
1177
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VisualiserGraphComponent, deps: [{ token: VisualiserGraphService }, { token: DagreNodesOnlyLayout }, { token: DexieService }], target: i0.ɵɵFactoryTarget.Component });
1178
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: VisualiserGraphComponent, selector: "visualiser-graph", inputs: { zoom: "zoom", zoomToFit: "zoomToFit", data: "data" }, outputs: { saveGraphDataEvent: "saveGraphDataEvent" }, viewQueries: [{ propertyName: "graphElement", first: true, predicate: ["svgId"], descendants: true }], ngImport: i0, template: "<div class=\"page\" id=\"pageId\" (window:resize)=\"onResize($event)\">\n <div class=\"buttonBar\" [style.right]=\"buttonBarRightPosition\">\n <div class=\"d-flex justify-content-end\">\n <div class=\"btn-group\" role=\"group\" aria-label=\"Controls\">\n <button type=\"button\" id=\"save_graph\" class=\"m-3 btn btn-secondary\" data-toggle=\"tooltip\" data-placement=\"top\"\n title=\"Save data\" (click)=\"onConfirmSave()\">\n <i class=\"bi bi-save\"></i>\n </button>\n </div>\n </div>\n </div>\n <!-- Zoom indicator-->\n <div *ngIf=\"zoom\" class=\"zoomIndicator\">\n <span id=\"zoom_level\"></span>\n </div>\n <!-- Save confirmation-->\n <div *ngIf=\"showConfirmation\" class=\"confirmation-message-container\">\n <div class=\"alert alert-success confirmation-message\" role=\"alert\" [ngClass]=\"{ 'fade-out': !showConfirmation }\">\n Saved <i class=\"bi bi-check-circle\"></i>\n </div>\n </div>\n <svg #svgId [attr.width]=\"width\" height=\"780\"></svg>\n</div>", styles: ["#zoom_level{position:relative;background-color:#000c;color:#fff;padding:5px;border-radius:5px;opacity:0;transition:opacity 1s ease-in-out}.zoomIndicator{position:absolute;left:0;padding:10px}.buttonBar{position:absolute;padding:10px}.confirmation-message-container{position:absolute;left:50%;transform:translate(-50%)}.confirmation-message{position:relative;top:60px;opacity:0;animation:fade-in .5s ease-in-out forwards}@keyframes fade-in{0%{opacity:0}to{opacity:1}}.fade-out{animation:fade-out .5s ease-in-out forwards}@keyframes fade-out{0%{opacity:1}to{opacity:0}}\n"], dependencies: [{ kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
1179
+ }
1180
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: VisualiserGraphComponent, decorators: [{
1181
+ type: Component,
1182
+ args: [{ selector: 'visualiser-graph', template: "<div class=\"page\" id=\"pageId\" (window:resize)=\"onResize($event)\">\n <div class=\"buttonBar\" [style.right]=\"buttonBarRightPosition\">\n <div class=\"d-flex justify-content-end\">\n <div class=\"btn-group\" role=\"group\" aria-label=\"Controls\">\n <button type=\"button\" id=\"save_graph\" class=\"m-3 btn btn-secondary\" data-toggle=\"tooltip\" data-placement=\"top\"\n title=\"Save data\" (click)=\"onConfirmSave()\">\n <i class=\"bi bi-save\"></i>\n </button>\n </div>\n </div>\n </div>\n <!-- Zoom indicator-->\n <div *ngIf=\"zoom\" class=\"zoomIndicator\">\n <span id=\"zoom_level\"></span>\n </div>\n <!-- Save confirmation-->\n <div *ngIf=\"showConfirmation\" class=\"confirmation-message-container\">\n <div class=\"alert alert-success confirmation-message\" role=\"alert\" [ngClass]=\"{ 'fade-out': !showConfirmation }\">\n Saved <i class=\"bi bi-check-circle\"></i>\n </div>\n </div>\n <svg #svgId [attr.width]=\"width\" height=\"780\"></svg>\n</div>", styles: ["#zoom_level{position:relative;background-color:#000c;color:#fff;padding:5px;border-radius:5px;opacity:0;transition:opacity 1s ease-in-out}.zoomIndicator{position:absolute;left:0;padding:10px}.buttonBar{position:absolute;padding:10px}.confirmation-message-container{position:absolute;left:50%;transform:translate(-50%)}.confirmation-message{position:relative;top:60px;opacity:0;animation:fade-in .5s ease-in-out forwards}@keyframes fade-in{0%{opacity:0}to{opacity:1}}.fade-out{animation:fade-out .5s ease-in-out forwards}@keyframes fade-out{0%{opacity:1}to{opacity:0}}\n"] }]
1183
+ }], ctorParameters: () => [{ type: VisualiserGraphService }, { type: DagreNodesOnlyLayout }, { type: DexieService }], propDecorators: { graphElement: [{
1184
+ type: ViewChild,
1185
+ args: ['svgId']
1186
+ }], saveGraphDataEvent: [{
1187
+ type: Output
1188
+ }], zoom: [{
1189
+ type: Input
1190
+ }], zoomToFit: [{
1191
+ type: Input
1192
+ }], data: [{
1193
+ type: Input
1194
+ }] } });
1195
+
1196
+ class NgxRelationshipVisualiserModule {
1197
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxRelationshipVisualiserModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1198
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: NgxRelationshipVisualiserModule, declarations: [VisualiserGraphComponent], imports: [BrowserModule], exports: [VisualiserGraphComponent] });
1199
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxRelationshipVisualiserModule, imports: [BrowserModule] });
1200
+ }
1201
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxRelationshipVisualiserModule, decorators: [{
1202
+ type: NgModule,
1203
+ args: [{
1204
+ declarations: [
1205
+ VisualiserGraphComponent
1206
+ ],
1207
+ imports: [
1208
+ BrowserModule
1209
+ ],
1210
+ exports: [VisualiserGraphComponent]
1211
+ }]
1212
+ }] });
1213
+
1214
+ /**
1215
+ * Generated bundle index. Do not edit.
1216
+ */
1217
+
1218
+ export { NgxRelationshipVisualiserModule, VisualiserGraphComponent };
1219
+ //# sourceMappingURL=ngx-relationship-visualiser.mjs.map