@esfaenza/es-diagrams 11.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +1 -0
  2. package/bundles/esfaenza-es-diagrams.umd.js +1748 -0
  3. package/bundles/esfaenza-es-diagrams.umd.js.map +1 -0
  4. package/esfaenza-es-diagrams.d.ts +9 -0
  5. package/esfaenza-es-diagrams.metadata.json +1 -0
  6. package/esm2015/esfaenza-es-diagrams.js +10 -0
  7. package/esm2015/lib/components/es-diagram.component.js +396 -0
  8. package/esm2015/lib/esdiagram.module.js +28 -0
  9. package/esm2015/lib/extensions/ReactiveExtensions.js +34 -0
  10. package/esm2015/lib/extensions/ResizeSensor.js +71 -0
  11. package/esm2015/lib/models/EsDiagramModuleConfig.js +6 -0
  12. package/esm2015/lib/models/component/contextmenu/ContextMenuCommand.js +6 -0
  13. package/esm2015/lib/models/component/contextmenu/ContextMenuOptions.js +7 -0
  14. package/esm2015/lib/models/component/grouping/ExpandCollapseOptions.js +6 -0
  15. package/esm2015/lib/models/component/nodes/NodeHTMLTemplate.js +6 -0
  16. package/esm2015/lib/models/component/nodes/NodeTemplate.js +6 -0
  17. package/esm2015/lib/models/component/nodes/ZoomLevelBasedTemplate.js +6 -0
  18. package/esm2015/lib/models/layouts/BreadthFirstLayoutOptionsImpl.js +35 -0
  19. package/esm2015/lib/models/layouts/CircleLayoutOptionsImpl.js +27 -0
  20. package/esm2015/lib/models/layouts/ConcentricLayoutOptionsImpl.js +64 -0
  21. package/esm2015/lib/models/layouts/CoseLayoutOptionsImpl.js +83 -0
  22. package/esm2015/lib/models/layouts/DagreLayoutOptionsImpl.js +52 -0
  23. package/esm2015/lib/models/layouts/GridLayoutOptionsImpl.js +38 -0
  24. package/esm2015/lib/models/layouts/NullLayoutOptionsImpl.js +15 -0
  25. package/esm2015/lib/models/layouts/PresetLayoutOptionsImpl.js +24 -0
  26. package/esm2015/lib/models/layouts/RandomLayoutOptionsImpl.js +36 -0
  27. package/esm2015/lib/models/layouts/base/AnimateLayoutOptionsImpl.js +42 -0
  28. package/esm2015/lib/models/layouts/base/BaseLayoutOptionsImpl.js +18 -0
  29. package/esm2015/lib/models/layouts/base/ShapedLayoutOptionsImpl.js +48 -0
  30. package/esm2015/lib/services/es-diagram.dispatcher.js +86 -0
  31. package/esm2015/lib/services/es-diagram.loc.js +17 -0
  32. package/esm2015/lib/services/es-diagram.service.js +106 -0
  33. package/esm2015/lib/tokens.js +10 -0
  34. package/esm2015/public-api.js +24 -0
  35. package/fesm2015/esfaenza-es-diagrams.js +1254 -0
  36. package/fesm2015/esfaenza-es-diagrams.js.map +1 -0
  37. package/lib/components/es-diagram.component.d.ts +243 -0
  38. package/lib/esdiagram.module.d.ts +5 -0
  39. package/lib/extensions/ReactiveExtensions.d.ts +17 -0
  40. package/lib/extensions/ResizeSensor.d.ts +43 -0
  41. package/lib/models/EsDiagramModuleConfig.d.ts +13 -0
  42. package/lib/models/component/contextmenu/ContextMenuCommand.d.ts +27 -0
  43. package/lib/models/component/contextmenu/ContextMenuOptions.d.ts +71 -0
  44. package/lib/models/component/grouping/ExpandCollapseOptions.d.ts +22 -0
  45. package/lib/models/component/nodes/NodeHTMLTemplate.d.ts +14 -0
  46. package/lib/models/component/nodes/NodeTemplate.d.ts +13 -0
  47. package/lib/models/component/nodes/ZoomLevelBasedTemplate.d.ts +14 -0
  48. package/lib/models/layouts/BreadthFirstLayoutOptionsImpl.d.ts +40 -0
  49. package/lib/models/layouts/CircleLayoutOptionsImpl.d.ts +28 -0
  50. package/lib/models/layouts/ConcentricLayoutOptionsImpl.d.ts +74 -0
  51. package/lib/models/layouts/CoseLayoutOptionsImpl.d.ts +80 -0
  52. package/lib/models/layouts/DagreLayoutOptionsImpl.d.ts +48 -0
  53. package/lib/models/layouts/GridLayoutOptionsImpl.d.ts +39 -0
  54. package/lib/models/layouts/NullLayoutOptionsImpl.d.ts +12 -0
  55. package/lib/models/layouts/PresetLayoutOptionsImpl.d.ts +37 -0
  56. package/lib/models/layouts/RandomLayoutOptionsImpl.d.ts +33 -0
  57. package/lib/models/layouts/base/AnimateLayoutOptionsImpl.d.ts +40 -0
  58. package/lib/models/layouts/base/BaseLayoutOptionsImpl.d.ts +15 -0
  59. package/lib/models/layouts/base/ShapedLayoutOptionsImpl.d.ts +46 -0
  60. package/lib/services/es-diagram.dispatcher.d.ts +41 -0
  61. package/lib/services/es-diagram.loc.d.ts +49 -0
  62. package/lib/services/es-diagram.service.d.ts +49 -0
  63. package/lib/tokens.d.ts +9 -0
  64. package/package.json +25 -0
  65. package/public-api.d.ts +20 -0
@@ -0,0 +1,1254 @@
1
+ import { __awaiter } from 'tslib';
2
+ import * as i0 from '@angular/core';
3
+ import { InjectionToken, Injectable, Optional, Inject, EventEmitter, Component, ViewChild, Input, Output, NgModule } from '@angular/core';
4
+ import * as cy_ from 'cytoscape';
5
+ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
6
+ import { CommonModule } from '@angular/common';
7
+
8
+ /**
9
+ * Definizione di un comando del Context menù
10
+ */
11
+ class ContextMenuCommand {
12
+ }
13
+
14
+ /**
15
+ * Opzioni che gestiscono il context menu. Quando una di queste opzioni non viene assegnata viene mantenuto il default, assicurarsi quindi di modificare solo
16
+ * le proprietà che si vogliono effettivamente cambiare rispetto ai default
17
+ */
18
+ class ContextMenuOptions {
19
+ }
20
+
21
+ /**
22
+ * Opzioni native per l'estensione expand-collapse di cytoscape
23
+ */
24
+ class ExpandCollapseOptions {
25
+ }
26
+
27
+ /**
28
+ * Classe che indica per una data query quali template applicare
29
+ */
30
+ class NodeHTMLTemplate {
31
+ }
32
+
33
+ /**
34
+ * Classe che rappresenta un template HTML applicabile ad un nodo
35
+ */
36
+ class NodeTemplate {
37
+ }
38
+
39
+ /**
40
+ * Classe che rappresenta il template HTML di un nodo da utilizzare per un certo livello di zoom
41
+ */
42
+ class ZoomLevelBasedTemplate {
43
+ }
44
+
45
+ /**
46
+ * Opzioni di layout di base che si collegano al **ready** e allo **stop** eventualmente per aggiungere del log addizionale
47
+ */
48
+ class BaseLayoutOptionsImpl {
49
+ /**
50
+ * Per ora ignoro lato documentale dato che sono placholder
51
+ * @ignore
52
+ */
53
+ ready(e) {
54
+ }
55
+ /**
56
+ * Per ora ignoro lato documentale dato che sono placholder
57
+ * @ignore
58
+ */
59
+ stop(e) {
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Classe base con le opzioni di layout valide per tutti i layout animati
65
+ */
66
+ class AnimateLayoutOptionsImpl extends BaseLayoutOptionsImpl {
67
+ /** @ignore */
68
+ constructor() {
69
+ super();
70
+ /**
71
+ * Livello di zoom da impostare (si consiglia fit = **false** se viene impostato)
72
+ */
73
+ this.zoom = null;
74
+ /**
75
+ * Livello di pan da impostare (si consiglia fit = **false** se viene impostato)
76
+ */
77
+ this.pan = null;
78
+ /**
79
+ * Indica se animare il cambio di posizione dei nodi
80
+ */
81
+ this.animate = false;
82
+ /**
83
+ * Con **animate** a true indica la durata dell'animazione
84
+ */
85
+ this.animationDuration = 500;
86
+ /**
87
+ * Abilita o no l'easing dell'animazione, può essere una stringa come ad esempio "ease-in-out-cubic" o altre funzioni scritte allo stesso modo prese da https://easings.net/
88
+ */
89
+ this.animationEasing = undefined;
90
+ /**
91
+ * Funzione che indica se un nodo dev'essere animato o no.
92
+ * Tutti i nodi sono animati di default.
93
+ * Tutti i nodi che non vengono animati verranno posizionati appena inizia l'animazione
94
+ *
95
+ * @param {any} node Nodo per cui decidere se abilitare l'animazione o no
96
+ * @param {number} i Indice del nodo corrente
97
+ *
98
+ * @returns {boolean} **true** se il nodo dev'essere animato, **false** altrimenti
99
+ */
100
+ this.animateFilter = (node, i) => true;
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Classe base per gli algoritmi "Shaped"
106
+ */
107
+ class ShapedLayoutOptionsImpl extends AnimateLayoutOptionsImpl {
108
+ /** @ignore */
109
+ constructor() {
110
+ super();
111
+ /**
112
+ * Indica se adattare al contenitore
113
+ */
114
+ this.fit = true;
115
+ /**
116
+ * Padding rispetto al contenitore
117
+ */
118
+ this.padding = 30;
119
+ /**
120
+ * Specifica le dimensioni esatte al cui interno effettuare il layouting, specificato come **{ x1, y1, x2, y2 }** o **{ x1, y1, w, h }**
121
+ */
122
+ this.boundingBox = null;
123
+ /**
124
+ * Fa in modo che i nodi non si accavallino, ma se il contenitore non ha abbastanza spazio potrebbero andare in overflow
125
+ */
126
+ this.avoidOverlap = true;
127
+ /**
128
+ * Include o esclude le dimensioni delle label dei nodi nel calcolo delle posizioni
129
+ */
130
+ this.nodeDimensionsIncludeLabels = false;
131
+ /**
132
+ * Moltiplicatore delle dimensioni per espandere/restringere le dimensioni globali del diagramma
133
+ */
134
+ this.spacingFactor = 1;
135
+ /**
136
+ * Funzione di ordinamento per ordinare i nodi
137
+ */
138
+ this.sort = null;
139
+ /**
140
+ * Funzione per la trasformazione delle posizioni dei nodi
141
+ *
142
+ * @param {any} node Nodo
143
+ * @param {any} position Posizione iniziale
144
+ *
145
+ * @returns {any} Posizione finale
146
+ */
147
+ this.transform = (node, position) => position;
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Default per l'implementazione dell'algoritmo Breadth First
153
+ */
154
+ class BreadthFirstLayoutOptionsImpl extends ShapedLayoutOptionsImpl {
155
+ /** @ignore */
156
+ constructor() {
157
+ super();
158
+ /**
159
+ * Nome dell'algoritmo di layouting
160
+ */
161
+ this.name = 'breadthfirst';
162
+ /**
163
+ * Indica se l'albero è diretto in basso. Se false i collegamenti fra i nodi possono andare in qualsiasi direzione
164
+ */
165
+ this.directed = false;
166
+ /**
167
+ * Se **true** i livelli vengono ordinati in cerchi concentrici, se **false** vengono oridnati dall'alto al basso
168
+ */
169
+ this.circle = false;
170
+ /**
171
+ * Indica che i nodi verranno shiftati in base al proprio livello in modo da evitare collegamenti inversi (solo per i DAG)
172
+ */
173
+ this.maximal = false;
174
+ /**
175
+ * Indica se creare una griglia in cui ordinare i nodi del DAG (Solo quando la proprietà **circle** è a **false**)
176
+ */
177
+ this.grid = false;
178
+ /**
179
+ * Indica se escludere le label dei nodi quando vengono calcolati i limiti del layout
180
+ */
181
+ this.nodeDimensionsIncludeLabels = false;
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Default per l'implementazione dell'algoritmo Circle
187
+ */
188
+ class CircleLayoutOptionsImpl extends ShapedLayoutOptionsImpl {
189
+ /** @ignore */
190
+ constructor() {
191
+ super();
192
+ /**
193
+ * Nome dell'algoritmo di layouting
194
+ */
195
+ this.name = 'circle';
196
+ /**
197
+ * Angolo da cui i nodi partono, in radianti (Default: **3 / 2 * Math.PI**)
198
+ */
199
+ this.startAngle = 3 / 2 * Math.PI;
200
+ /**
201
+ * Numero di radianti fra il primo e l'ultimo nodo. Di default viene utilizzata l'intera circonferenza
202
+ */
203
+ this.sweep = null;
204
+ /**
205
+ * Indica se andare in senso orario (**true**) o antiorario (**false**)
206
+ */
207
+ this.clockwise = true; // whether the layout should go clockwise (true) or counterclockwise/anticlockwise (false)
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Default per l'implementazione dell'algoritmo Concentric
213
+ */
214
+ class ConcentricLayoutOptionsImpl {
215
+ constructor() {
216
+ /**
217
+ * Nome dell'algoritmo di layouting
218
+ */
219
+ this.name = 'concentric';
220
+ /**
221
+ * Angolo da cui i nodi partono, in radianti (Default: **3 / 2 * Math.PI**)
222
+ */
223
+ this.startAngle = 3 / 2 * Math.PI;
224
+ /**
225
+ * Include o esclude le dimensioni delle label dei nodi nel calcolo delle posizioni
226
+ */
227
+ this.nodeDimensionsIncludeLabels = true;
228
+ /**
229
+ * Indica se i livelli devono essere o non essere equidistanti, potrebbe causare overflow dal contenitore
230
+ */
231
+ this.equidistant = false;
232
+ /**
233
+ * Distanza minima dall'esterno dei nodi, utilizzato per aggiustare il raggio
234
+ */
235
+ this.minNodeSpacingnumber = 10;
236
+ /**
237
+ * Specifica le dimensioni esatte al cui interno effettuare il layouting, specificato come **{ x1, y1, x2, y2 }** o **{ x1, y1, w, h }**
238
+ */
239
+ this.boundingBox = null;
240
+ /**
241
+ * Altezza dell'area di layout (sovrascrive quella del contenitore)
242
+ */
243
+ this.height = null;
244
+ /**
245
+ * Larghezza dell'area di layout (sovrascrive quella del contenitore)
246
+ */
247
+ this.width = null;
248
+ /**
249
+ * Moltiplicatore delle dimensioni per espandere/restringere le dimensioni globali del diagramma
250
+ */
251
+ this.spacingFactor = 1;
252
+ }
253
+ /**
254
+ * Funzione di cui si può fare override per assegnare un valore ad ogni nodo. I nodi con valore più alto saranno piazzati verso il centro
255
+ *
256
+ * @param {any} node Nodo
257
+ *
258
+ * @returns {number} Valore su cui ordinare i nodi verso il centro
259
+ */
260
+ concentric(node) {
261
+ return node.degree();
262
+ }
263
+ /**
264
+ * Funzione di cui si può fare override per calcolare la variazione dei valori concentrici per ogni livello
265
+ *
266
+ * @param {any} nodes Gruppo di nodi del livello
267
+ *
268
+ * @returns {number} Variazione dei valori concentrici
269
+ */
270
+ levelWidth(nodes) {
271
+ return nodes.maxDegree() / 4;
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Default per l'implementazione dell'algoritmo Cose
277
+ */
278
+ class CoseLayoutOptionsImpl extends ShapedLayoutOptionsImpl {
279
+ /** @ignore */
280
+ constructor() {
281
+ super();
282
+ /**
283
+ * Nome dell'algoritmo di layouting
284
+ */
285
+ this.name = 'cose';
286
+ /**
287
+ * Se **animate** è **true**, l'animazione parte solo dopo questo numero di millisecondi (Evita flickering su animazioni veloci)
288
+ */
289
+ this.animationThreshold = 250;
290
+ /**
291
+ * Numero di iterazioni fra aggiornamenti consecutivi della posizione a schermo
292
+ */
293
+ this.refresh = 20;
294
+ /**
295
+ * Se **true** la posizione iniziale dei nodi è casuale, se **false** utilizza la posizione originale
296
+ */
297
+ this.randomize = false;
298
+ /**
299
+ * Spazio extra fra i componenti di un grafo non-compound
300
+ */
301
+ this.componentSpacing = 40;
302
+ /**
303
+ * Moltiplicatore della repulsione fra nodi in caso di overlap
304
+ */
305
+ this.nodeOverlap = 4;
306
+ /**
307
+ * Moltiplicatore di nesting per il calcolo della lunghezza ideale dei collegamenti nested
308
+ */
309
+ this.nestingFactor = 1.2;
310
+ /**
311
+ * Costante di gravità
312
+ */
313
+ this.gravity = 1;
314
+ /**
315
+ * Numero massimo di iterazioni da eseguire
316
+ */
317
+ this.numIter = 1000;
318
+ /**
319
+ * Temperatura iniziale (massima distanza fra i nodi)
320
+ */
321
+ this.initialTemp = 1000;
322
+ /**
323
+ * Fattore di raffreddamento. Ad ogni iterazione verrà sottratto ad **initialTemp**
324
+ */
325
+ this.coolingFactor = 0.99;
326
+ /**
327
+ * Soglia minima di temperatura. Una volta raggiunta il layout si considera terminato
328
+ */
329
+ this.minTemp = 1.0;
330
+ /**
331
+ * Moltiplicatore della repulsione fra nodi in caso di assenza di overlap. Funzione overrideabile per ogni node
332
+ *
333
+ * @param {any} node Nodo
334
+ *
335
+ * @returns {number} Moltiplicazione di repulsione
336
+ */
337
+ this.nodeRepulsion = (node) => 2048;
338
+ /**
339
+ * Lunghezza ideale dei collegamenti non nested. Funzione overrideabile per ogni collegamento
340
+ *
341
+ * @param {any} edge Collegamento
342
+ *
343
+ * @returns {number} Lunghezza ideale
344
+ */
345
+ this.idealEdgeLength = (edge) => 32;
346
+ /**
347
+ * Divisore per calcolare le forze applicate ad un collegamento. Funzione overrideabile per ogni collegamento
348
+ *
349
+ * @param {any} edge Collegamento
350
+ *
351
+ * @returns {number} Indice di elasticità
352
+ */
353
+ this.edgeElasticity = (edge) => 32;
354
+ }
355
+ }
356
+
357
+ /**
358
+ * Default per l'implementazione dell'algoritmo Dagre
359
+ */
360
+ class DagreLayoutOptionsImpl extends ShapedLayoutOptionsImpl {
361
+ /** @ignore */
362
+ constructor() {
363
+ super();
364
+ /**
365
+ * Nome dell'algoritmo di layouting
366
+ */
367
+ this.name = 'dagre';
368
+ /**
369
+ * Distanza fra nodi adiacenti dello stesso rango
370
+ */
371
+ this.nodeSep = null;
372
+ /**
373
+ * Distanza fra collegamenti adiacenti nello stesso rango
374
+ */
375
+ this.edgeSep = null;
376
+ /**
377
+ * Distanza fra ogni rango
378
+ */
379
+ this.rankSep = null;
380
+ // TB for top to bottom flow, 'LR' for left to right
381
+ /**
382
+ * Direzione di disegno: LR = Sinistra a Destra, TB = Sopra a Sotto
383
+ */
384
+ this.rankDir = 'TB';
385
+ /**
386
+ * Algoritmo che si occupa di assegnare un rango ad ogni nodo
387
+ */
388
+ this.ranker = null;
389
+ /**
390
+ * Numero di ranghi fra la sorgente e la destinazione di un collegamento
391
+ *
392
+ * @param {any} edge Collegamento di cui calcolare la differenza di rango
393
+ *
394
+ * @returns {number} Differenza di rango
395
+ */
396
+ this.minLen = (edge) => 1;
397
+ /**
398
+ * Peso del collegamento, più è alto più generalmente risulterà corto
399
+ *
400
+ * @param {any} edge Collegamento di cui calcolare il peso
401
+ *
402
+ * @returns {number} Peso
403
+ */
404
+ this.edgeWeight = (edge) => 1;
405
+ }
406
+ }
407
+
408
+ /**
409
+ * Default per l'implementazione dell'algoritmo Grid
410
+ */
411
+ class GridLayoutOptionsImpl extends ShapedLayoutOptionsImpl {
412
+ /** @ignore */
413
+ constructor() {
414
+ super();
415
+ /**
416
+ * Nome dell'algoritmo di layouting
417
+ */
418
+ this.name = 'grid';
419
+ /**
420
+ * Spazio extra attorno ai nodi quando **avoidOverlap** è **true**
421
+ */
422
+ this.avoidOverlapPadding = 10;
423
+ /**
424
+ * Se **true** cerca di utilizzare il minor spazio possibile, se **false** usa tutto lo spazio che ha a disposizione
425
+ */
426
+ this.condense = false;
427
+ /**
428
+ * Forzatura del numero di righe della griglia
429
+ */
430
+ this.rows = null;
431
+ /**
432
+ * Forzatura del numero di colonne della griglia
433
+ */
434
+ this.cols = null;
435
+ /**
436
+ * Dato un nodo restituisce un indice di riga e di colonna della griglia in cui metterlo
437
+ *
438
+ * @param {NodeSingular} node Nodo
439
+ * @returns {{ row: number, col: number }} Oggetto che identifica una posizione della griglia
440
+ */
441
+ this.position = null;
442
+ }
443
+ }
444
+
445
+ /**
446
+ * Pseudo implementazione di un algoritmo vuoto che non fa nulla
447
+ */
448
+ class NullLayoutOptionsImpl extends BaseLayoutOptionsImpl {
449
+ /** @ignore */
450
+ constructor() {
451
+ super();
452
+ /**
453
+ * Nome dell'algoritmo di layouting
454
+ */
455
+ this.name = 'null';
456
+ }
457
+ }
458
+
459
+ /**
460
+ * Default per l'implementazione dell'algoritmo Preset (Posiziona i nodi in base alla loro proprietà **position**)
461
+ */
462
+ class PresetLayoutOptionsImpl extends AnimateLayoutOptionsImpl {
463
+ /** @ignore */
464
+ constructor() {
465
+ super();
466
+ /**
467
+ * Nome dell'algoritmo di layouting
468
+ */
469
+ this.name = 'preset';
470
+ /**
471
+ * Funzione per la trasformazione delle posizioni dei nodi
472
+ *
473
+ * @param {any} node Nodo
474
+ * @param {any} position Posizione iniziale
475
+ *
476
+ * @returns {any} Posizione finale
477
+ */
478
+ this.transform = (node, position) => position;
479
+ }
480
+ }
481
+
482
+ /**
483
+ * Default per l'implementazione dell'algoritmo Random
484
+ */
485
+ class RandomLayoutOptionsImpl extends AnimateLayoutOptionsImpl {
486
+ /** @ignore */
487
+ constructor() {
488
+ super();
489
+ /**
490
+ * Nome dell'algoritmo di layouting
491
+ */
492
+ this.name = 'random';
493
+ /**
494
+ * Indica se adattare al contenitore
495
+ */
496
+ this.fit = true;
497
+ /**
498
+ * Padding rispetto al contenitore
499
+ */
500
+ this.padding = 20;
501
+ /**
502
+ * Specifica le dimensioni esatte al cui interno effettuare il layouting, specificato come **{ x1, y1, x2, y2 }** o **{ x1, y1, w, h }**
503
+ */
504
+ this.boundingBox = null;
505
+ /**
506
+ * Funzione per la trasformazione delle posizioni dei nodi
507
+ *
508
+ * @param {any} node Nodo
509
+ * @param {any} position Posizione iniziale
510
+ *
511
+ * @returns {any} Posizione finale
512
+ */
513
+ this.transform = (node, position) => position;
514
+ }
515
+ }
516
+
517
+ /**
518
+ * Classe di configurazione per il Modulo
519
+ */
520
+ class EsDiagramModuleConfig {
521
+ }
522
+
523
+ /**
524
+ * Token che indica la lingua da utilizzare, sono supportate "it-IT" ed "en-US"
525
+ */
526
+ const DIA_LOCALE = new InjectionToken('DIA_LOCALE');
527
+ /**
528
+ * Token che indica se attivare la modalità di debug (messaggi a console)
529
+ */
530
+ const DIA_DEBUG_MODE = new InjectionToken('DIA_DEBUG_MODE');
531
+
532
+ /**
533
+ * Oggetto statico di localizzazione per i messaggi
534
+ */
535
+ const Loc = {
536
+ "Module": { "en-US": "Module", "it-IT": "Il Modulo" },
537
+ "Received an undefined module. Make sure you are correctly loading it": { "en-US": "Received an undefined module. Make sure you are correctly loading it", "it-IT": "Ricevuto modulo non definito. Assicurati di caricarlo correttamente" },
538
+ "Module not available. Loading it now": { "en-US": "Module not available. Loading it now", "it-IT": "Modulo non disponibile. Lo carico ora" },
539
+ "Module already loaded": { "en-US": "Module already loaded", "it-IT": "Modulo già caricato" },
540
+ "Diagram container size has changed, redrawing": { "en-US": "Diagram container size has changed, redrawing", "it-IT": "La dimensione del contenitore del diagramma è cambiata, ridisegno" },
541
+ "Module cannot be loaded": { "en-US": "Module cannot be loaded", "it-IT": "Impossibile caricare il modulo" },
542
+ "Redraw based on dynamic Input change is supported only for 'Elements' and 'Layout' inputs, please destroy the component and recreate it with the new settings": { "en-US": "Redraw based on dynamic Input change is supported only for 'Elements' and 'Layout' inputs, please destroy the component and recreate it with the new settings", "it-IT": "Il cambio e aggiornamento dinamico degli Input è supportato solo per gli Input 'Elements' e 'Layout', distruggi il componente e ricrealo con le nuove impostazioni", },
543
+ "is loaded and managed directly by this library. You don't need to import it or use it directly, just be sure to set the relative options": { "en-US": "is loaded and managed directly by this library. You don't need to import it or use it directly, just be sure to set the relative options", "it-IT": "viene caricato e gestito nativamente dalla libreria. Non c'è bisogno di reimportarlo, né di configurarlo (usare le opzioni specifiche)" },
544
+ "If you don't specify a source and a target for an edge you have to write its id in the format {source}-{target}": { "en-US": "If you don't specify a source and a target for an edge you have to write its id in the format {source}-{target}", "it-IT": "Se non è specificata una sorgente e una destinazione per il collegamento è opportuno scriverne l'id nel formato {sorgente}-{destinazione}" },
545
+ "Elements have been changed after diagram initialization": { "en-US": "Elements have been changed after diagram initialization", "it-IT": "Rilevato un cambio di Elementi dopo l'inizializzazione del Diagramma" },
546
+ "Layout have been changed after diagram initialization": { "en-US": "Layout have been changed after diagram initialization", "it-IT": "Rilevato un cambio di Layout dopo l'inizializzazione del Diagramma" }
547
+ };
548
+
549
+ /** @ignore */ const cytoscape$1 = cy_;
550
+ /**
551
+ * Loader dei moduli di Cytoscape. Utilizza una cache per tenerseli in memoria a livello di applicazione
552
+ * in modo da non dover ricaricare nulla dopo avere usato un modulo almeno una volta
553
+ */
554
+ class EsDiagramService {
555
+ /**
556
+ * Costruttore
557
+ *
558
+ * @ignore
559
+ */
560
+ constructor(DIA_LOCALE, DIA_DEBUG_MODE) {
561
+ this.DIA_LOCALE = DIA_LOCALE;
562
+ this.DIA_DEBUG_MODE = DIA_DEBUG_MODE;
563
+ /**
564
+ * Cache dei moduli caricati
565
+ */
566
+ this.modulesCache = {};
567
+ }
568
+ /**
569
+ * Permette di importare, se serve un dato tema o localizzazione
570
+ *
571
+ * @param {'cytoscape-expand-collapse' | 'cytoscape-cxtmenu' | 'cytoscape-html-node' | 'cytoscape-dagre'} moduleId Nome del modulo di Cytoscape da importare (dev'essere il nome della cartella in node_modules)
572
+ *
573
+ * @returns {Promise<void | cytoscape.Ext>} Funzione di estensione per Cytoscape presa dal modulo richiesto
574
+ */
575
+ importIfNeeded(moduleId) {
576
+ return __awaiter(this, void 0, void 0, function* () {
577
+ // Ognuno esporta il modulo un po' come cazzo gli pare quindi ocio.
578
+ // Notare che tutti i "moudle" dopo lo then sono castati ad <any> e che l'oggetto recuperato ogni tanto è "default", altre volte è il "register", altre è l'"ext", eccetera...
579
+ if (!this.modulesCache[moduleId]) {
580
+ this.log("I", this.loc("Module not available. Loading it now") + ": " + moduleId, false);
581
+ switch (moduleId) {
582
+ case "cytoscape-cxtmenu": return import('cytoscape-cxtmenu').then((module) => this.modulesCache[moduleId] = module.default).catch(err => this.handleError(moduleId, err));
583
+ case "cytoscape-expand-collapse": return import('cytoscape-expand-collapse').then((module) => this.modulesCache[moduleId] = module.default).catch(err => this.handleError(moduleId, err));
584
+ case "cytoscape-html-node": return import('@esfaenza/cytoscape-html-node').then((module) => this.modulesCache[moduleId] = module.register).catch(err => this.handleError(moduleId, err));
585
+ case "cytoscape-dagre":
586
+ yield import('dagre').catch(err => this.handleError("dagre", err));
587
+ return import('cytoscape-dagre').then((module) => this.modulesCache[moduleId] = module.default).catch(err => this.handleError(moduleId, err));
588
+ }
589
+ }
590
+ else {
591
+ // I moduli non devono mai essere ricaricati nel globale, quindi invece che restituire la copia della cache restituisco vuoto
592
+ this.log("I", this.loc("Module already loaded") + ": " + moduleId, false);
593
+ return new Promise((resolve) => { resolve(null); });
594
+ }
595
+ });
596
+ }
597
+ /**
598
+ * Gestione degli errori di caricamento dei moduli qualora qualcuno utilizzasse un modulo non installato
599
+ *
600
+ * @param {string} moduleId Nome del modulo che si è cercato di caricare
601
+ * @param {any} err Errore restituito dalla promise di caricamento
602
+ */
603
+ handleError(moduleId, err) {
604
+ this.log("E", this.loc("Module cannot be loaded") + ": " + moduleId + " - " + err, false);
605
+ }
606
+ /**
607
+ * Scrittore di log a console. Attivo solo quando la libreria è in modalità di Debug
608
+ *
609
+ * @param {'E' | 'I' | 'W'} severity Tipo di messaggio (Errore, Info, Warning)
610
+ * @param {string} text Testo da tradurre
611
+ * @param {boolean} requiresTranslation Indica se **text** è una frase già tradotta o se è da tradurre
612
+ */
613
+ log(severity, text, requiresTranslation = true) {
614
+ if (!this.DIA_DEBUG_MODE)
615
+ return;
616
+ var message = "@esfaenza/diagrams: " + (requiresTranslation ? this.loc(text) : text);
617
+ switch (severity) {
618
+ case 'E':
619
+ console.error(message);
620
+ break;
621
+ case 'I':
622
+ console.info(message);
623
+ break;
624
+ case 'W':
625
+ console.warn(message);
626
+ break;
627
+ }
628
+ }
629
+ /**
630
+ * Metodo di localizzazione dei messaggi
631
+ *
632
+ * @param {string} text Messaggio da tradurre
633
+ *
634
+ * @returns {string} Messaggio tradotto
635
+ */
636
+ loc(text) {
637
+ return Loc[text][this.DIA_LOCALE];
638
+ }
639
+ }
640
+ EsDiagramService.decorators = [
641
+ { type: Injectable }
642
+ ];
643
+ EsDiagramService.ctorParameters = () => [
644
+ { type: String, decorators: [{ type: Optional }, { type: Inject, args: [DIA_LOCALE,] }] },
645
+ { type: String, decorators: [{ type: Optional }, { type: Inject, args: [DIA_DEBUG_MODE,] }] }
646
+ ];
647
+
648
+ /**
649
+ * Classe che si occupa del dispatch delle operazioni di rendering degli oggetti utilizzando una coda
650
+ */
651
+ class EsDiagramDispatcher {
652
+ /**
653
+ * @ignore
654
+ */
655
+ constructor(logs) {
656
+ this.logs = logs;
657
+ /**
658
+ * Coda di inizializzazioni ancora da eseguire. Quando questa è vuota significa che nessuno sta creando oggetti
659
+ */
660
+ this.Initializations = [];
661
+ /**
662
+ * Lista degli oggetti inizializzati e attivi in un dato momento (viene registrata la proprietà **name**). Non è possibile registrare due grafici con lo stesso identificativo
663
+ */
664
+ this.Initialized = [];
665
+ }
666
+ /**
667
+ * Registra un oggetto da visualizzare insieme alla propria funzione di creazione. Quest'ultima sarà differita fino a che tutti gli oggetti
668
+ * precedentemente registati non hanno finito la fase di inizializzazione
669
+ *
670
+ * @param {string} name Identificativo dell'oggetto da registrare
671
+ * @param {Function} creationFunction Funzione che fisicamente dovrà occuparsi della creazione dell'oggetto
672
+ */
673
+ register(name, creationFunction) {
674
+ if (this.Initialized.indexOf(name) != -1)
675
+ throw "Attempting to register a duplicate object '" + name + "'. Make sure the 'name' properties of your diagram are univoque";
676
+ this.log("DISPATCHER: Registering diagram creation function execution for " + name);
677
+ this.Initializations.push({ name: name, function: creationFunction });
678
+ if (this.Initializations.length == 1) {
679
+ this.log("DISPATCHER: Initial drain started");
680
+ this.drainInitQueues();
681
+ }
682
+ }
683
+ /**
684
+ * Deregistra un oggetto presente. Chiamata generalmente al dispose dell'oggetto in questione quando non dev'essere più mostrato nella pagina corrente
685
+ *
686
+ * @param {string} name Identificativo dell'oggetto da deregistrare
687
+ */
688
+ deregister(name) {
689
+ let index = this.Initialized.indexOf(name);
690
+ if (index == -1) {
691
+ //Questo succede quando si cerca di distruggere l'oggetto mentre sta venendo graficato
692
+ this.log("DISPATCHER: Registration missing for object " + name + " it was probably destroyed during load");
693
+ return;
694
+ }
695
+ this.log("DISPATCHER: Object deregistered " + name);
696
+ this.Initialized.splice(index, 1);
697
+ }
698
+ /**
699
+ * Metodo che esegue in maniera sequenziale le funzioni di inizializzazione degli oggetti finché presenti
700
+ * in modo che nessun oggetto possa essere inizializzato contemporaneamente ad un altro
701
+ */
702
+ drainInitQueues() {
703
+ let toExecute = this.Initializations[0];
704
+ this.log("DISPATCHER: Executing initialization function for object " + toExecute.name);
705
+ toExecute.function().then(() => {
706
+ this.log("DISPATCHER: initialization for object " + toExecute.name + " is done");
707
+ this.Initialized.push(toExecute.name);
708
+ this.Initializations.splice(0, 1);
709
+ if (this.Initializations.length >= 1) {
710
+ this.log("DISPATCHER: Found queued initializations. Continuing");
711
+ this.drainInitQueues();
712
+ }
713
+ else
714
+ this.log("DISPATCHER: queue is over, nothing more to do");
715
+ });
716
+ }
717
+ /**
718
+ * @ignore
719
+ */
720
+ log(text) {
721
+ if (this.logs)
722
+ console.log("@esfaenza/es-diagrams: " + text);
723
+ }
724
+ }
725
+ EsDiagramDispatcher.decorators = [
726
+ { type: Injectable }
727
+ ];
728
+ EsDiagramDispatcher.ctorParameters = () => [
729
+ { type: Boolean, decorators: [{ type: Inject, args: [DIA_DEBUG_MODE,] }] }
730
+ ];
731
+
732
+ // Grabbata felicemente da amcharts, rimuovendo helper interni, cose strane e instupidendola un po':
733
+ // https://github.com/amcharts/amcharts4/blob/7fbb61e90363a2373e6130800dee06b8a62f3aab/src/.internal/core/utils/ResizeSensor.ts
734
+ /**
735
+ * Classe di utilità che tiene d'occhio i cambiamenti di dimensione di un elemento. Un **ResizeSensor** può controllare al massimo un elemento
736
+ */
737
+ class ResizeSensor {
738
+ /**
739
+ * Costruttore
740
+ *
741
+ * @param {HTMLElement} element Elemento HTML da controllare
742
+ * @param {Function} callback Callback da chiamare quando le dimensioni di **element** cambiano
743
+ */
744
+ constructor(element, callback) {
745
+ /**
746
+ * Riferimento all'observer nativo
747
+ */
748
+ this.observer = null;
749
+ /**
750
+ * Indica se questo oggetto è stato distrutto o no
751
+ */
752
+ this.Disposed = false;
753
+ /**
754
+ * Elemento da controllare e callback da chiamare quando le dimensioni dell'elemento cambiano
755
+ */
756
+ this.target = null;
757
+ this.makeSensor();
758
+ this.addTarget(element, callback);
759
+ }
760
+ /**
761
+ * Distruttore
762
+ */
763
+ dispose() {
764
+ if (!this.Disposed) {
765
+ this.Disposed = true;
766
+ this.removeTarget();
767
+ }
768
+ }
769
+ /**
770
+ * Creazione del sensore che sarà collegato all'elemento da osservare dal metodo **addTarget**
771
+ */
772
+ makeSensor() {
773
+ if (typeof ResizeObserver == "undefined")
774
+ throw "Resize Observer non è definito. Si prega di utilizzare un browser vero";
775
+ this.observer = new ResizeObserver((entries) => {
776
+ for (let i = 0; i < entries.length; ++i) {
777
+ if (this.target && this.target.targetEl === entries[i].target)
778
+ this.target.callback();
779
+ }
780
+ });
781
+ }
782
+ /**
783
+ * Dice al sensore di osservare l'elemento **targetEl**, richiamando **callback** qualora le dimensioni cambino
784
+ *
785
+ * @param {HTMLElement} targetEl Elemento HTML da controllare
786
+ * @param {Function} callback Callback da chiamare quando le dimensioni di **element** cambiano
787
+ */
788
+ addTarget(targetEl, callback) {
789
+ this.observer.observe(targetEl, { box: "content-box" });
790
+ this.target = { targetEl, callback };
791
+ }
792
+ /**
793
+ * Rimuove l'elemento HTML attuale dall'osservazione del **ResizeObserver**
794
+ */
795
+ removeTarget() {
796
+ if (!this.target)
797
+ return;
798
+ this.observer.unobserve(this.target.targetEl);
799
+ this.target = null;
800
+ }
801
+ }
802
+
803
+ /**
804
+ * Classe che fornisce metodi reattivi di estensione. Per ora implementato solo uno pseudo-throttle
805
+ */
806
+ class ReactiveExtensions {
807
+ constructor() {
808
+ /**
809
+ * Cache di tutti i timer in esecuzione
810
+ */
811
+ this.executionTimers = {};
812
+ }
813
+ /**
814
+ * Esecuzione deleyata di una funzione. Se viene richiamata nuovamente prima di venire eseguita dopo il delay, il delay viene resettato
815
+ *
816
+ * @param {string} id Id per aiutare il servizio a distinguere funzioni con nome uguale chiamate da componenti diversi
817
+ * @param {Function} func Funzione da chiamare al termine del throttle
818
+ * @param {number} throttleTime Tempo di throttling in millisecondi
819
+ */
820
+ throttle(id, func, throttleTime = 0) {
821
+ let key = func.name + "_" + id;
822
+ //Se ho la funzione che vuole eseguire ripulisco quel timeout
823
+ if (this.executionTimers[key])
824
+ clearTimeout(this.executionTimers[key]);
825
+ //Ricreo il timeout per eseguire quella funzione dopo throttleTime millisecondi
826
+ var executionTimer = setTimeout(() => { func(); this.executionTimers[key] = null; }, throttleTime);
827
+ this.executionTimers[key] = executionTimer;
828
+ }
829
+ }
830
+ ReactiveExtensions.ɵprov = i0.ɵɵdefineInjectable({ factory: function ReactiveExtensions_Factory() { return new ReactiveExtensions(); }, token: ReactiveExtensions, providedIn: "root" });
831
+ ReactiveExtensions.decorators = [
832
+ { type: Injectable, args: [{ providedIn: "root" },] }
833
+ ];
834
+
835
+ /** @ignore */ const cytoscape = cy_;
836
+ /**
837
+ * Componente che si occupa di graficare un diagramma e di gestirne il ciclo di vita
838
+ */
839
+ class EsDiagramComponent {
840
+ /**
841
+ * Costruttore
842
+ *
843
+ * @ignore
844
+ */
845
+ constructor(service, dispatcher, exts) {
846
+ this.service = service;
847
+ this.dispatcher = dispatcher;
848
+ this.exts = exts;
849
+ /**
850
+ * Nome del diagramma, fondamentale assegnarlo per permettere alla libreria di schedularne la creazione
851
+ */
852
+ this.name = "";
853
+ /**
854
+ * Indica se utilizzare il menù contestuale a ruota attorno ad ogni nodo
855
+ */
856
+ this.UseContextMenu = false;
857
+ /**
858
+ * Dice al componente se il diagramma deve utilizzare il sistema di estensione per l'expand e collapse dei gruppi
859
+ */
860
+ this.UseExpandCollapse = false;
861
+ /**
862
+ * Blocco completo delle opzioni, alternativo all'assegnazione di **Elements**, **NodeStyles**, **EdgeStyles**, e **Layout**.
863
+ *
864
+ * Qualora entrambe venissero specificate verrà effettuata un'unione fra queste opzioni e quelle specificate, dando priorità alle specificate
865
+ */
866
+ this.NativeOptions = {};
867
+ /**
868
+ * Aggiorna automaticamente le dimensioni del diagramma quando cambiano le dimensioni della finestra
869
+ */
870
+ this.AutoupdateSize = true;
871
+ /**
872
+ * Indica di mantenere la posizione dei nodi qualora venissero cambiati dall'Input **Elements**.
873
+ *
874
+ * Se l'ID di un nodo è uguale all'ID di un nodo presente in precedenza, il nuovo nodo ne erediterà la posizione
875
+ */
876
+ this.PreserveElementsPosition = true;
877
+ /**
878
+ * Qualora venisse modificato l'Input **Elements**, piuttosto che mettere semplicemente il nuovo Elemento in base al Layout precedente, applica anche un'animazione
879
+ *
880
+ * Funziona solamente se il **Layout** corrente del diagramma supporta le animazioni
881
+ */
882
+ this.AnimateLayoutChanges = true;
883
+ /**
884
+ * Periodo di throttle da quando viene effettuato un resize a quando ricalcolare le dimensioni del diagramma.
885
+ *
886
+ * Può essere tenuto a 0 (redraw istantaneo) finché non ci sono problemi di prestazioni con eventualmente tanti resize a poca distanza l'uno dall'altro.
887
+ */
888
+ this.ResizeThrottleTime = 0;
889
+ /**
890
+ * Fornisce il global della libreria (namespace **cytoscape**) e si aspetta che dopo operazioni di importazione
891
+ * lasciate all'utente vengano aggiunti tutti i moduli desiderati.
892
+ *
893
+ * È **fondamentale** che il primo parametro (il nome del modulo) sia uguale a ciò di cui viene fatto il require in modo che la libreria
894
+ * possa controllare che il modulo importato non sia già stato importato in precedenza
895
+ *
896
+ * ## Esempio:
897
+ *
898
+ * ```typescript
899
+ * (global) => {
900
+ * return import("cytoscape-extension-library").then(module => global.use("cytoscape-extension-library", module.default));
901
+ *
902
+ * ...
903
+ * }
904
+ * ```
905
+ */
906
+ this.ExtensionModulesImporter = null;
907
+ /**
908
+ * Fornisce l'istanza attuale di Cytoscape da cui è possibile prendere le librerie di estensione caricate in **ExtensionModulesImporter**
909
+ * e configurarle in base ai comportamenti specifici
910
+ *
911
+ * ## Esempio:
912
+ *
913
+ * ```typescript
914
+ * (cytoscapeCore) => {
915
+ * // Fare questo lavoro per ogni estensione caricata
916
+ * let extensionConfiguration = { ... };
917
+ * let extensionInstance = cytoscapeCore.extensionLibrary(extensionConfiguration);
918
+ * extensionInstance.doSomethingSpecificToThisExtension();
919
+ *
920
+ * ...
921
+ * }
922
+ * ```
923
+ */
924
+ this.ExtensionModulesApplyer = null;
925
+ /**
926
+ * Evento lanciato al click di un nodo, contiene l'oggetto **data** del nodo in questione
927
+ */
928
+ this.onNodeClick = new EventEmitter();
929
+ /**
930
+ * Indica se il rendering del diagramma è terminato
931
+ */
932
+ this.Rendered = false;
933
+ /**
934
+ * Api dell'estensione expand-collapse per permettere di effettuare operazioni dall'esterno del diagramma. Vengono valorizzate se **UseExpandCollapse** è **true**
935
+ */
936
+ this.ExpandCollapseApi = null;
937
+ }
938
+ /**
939
+ * @ignore
940
+ *
941
+ * Angular Pipeline
942
+ */
943
+ ngAfterViewInit() {
944
+ if (!this.service || !this.dispatcher)
945
+ throw "Il modulo @esfaenza/diagrams non è stato importato con il forRoot();";
946
+ this.dispatchLoadChart();
947
+ }
948
+ /**
949
+ * All'onDestroy ripulisco la memoria dal diagramma
950
+ */
951
+ ngOnDestroy() {
952
+ this.resizeObserver.dispose();
953
+ this.resizeObserver = null;
954
+ if (this.cy) {
955
+ this.service.log("I", "Diagram" + " " + this.name + ": Unloading destroyed diagram", false);
956
+ this.cy.destroy();
957
+ this.dispatcher.deregister(this.name);
958
+ }
959
+ else
960
+ this.service.log("I", "Chart " + this.name + ": Unloading uncreated chart component. It probably was a duplicated", false);
961
+ }
962
+ /**
963
+ * Registra il diagramma attuale nel Dispatcher in modo che venga caricato appena possibile
964
+ */
965
+ dispatchLoadChart() {
966
+ this.dispatcher.register(this.name, () => { return this.render(); });
967
+ }
968
+ /**
969
+ * @ignore
970
+ *
971
+ * Angular Pipeline: Gestione ri-graficazione del diagramma, se possibile
972
+ */
973
+ ngOnChanges(changes) {
974
+ let toCheck = ["Templates", "UseContextMenu", "ContextMenuOptions", "UseExpandCollapse", "ExpandCollapseOptions", "NodeStyles", "EdgeStyles", "NativeOptions"];
975
+ if (this.Rendered && toCheck.some(t => changes[t]))
976
+ this.service.log("W", "Redraw based on dynamic Input change is supported only for 'Elements' and 'Layout' inputs, please destroy the component and recreate it with the new settings");
977
+ let elementChanges = changes["Elements"];
978
+ let layoutChanges = changes["Layout"];
979
+ if (elementChanges && !elementChanges.firstChange) {
980
+ this.service.log("I", "Elements have been changed after diagram initialization");
981
+ // Cambiamento agli Elementi: ripulisco gli elementi vecchi, prendo i nuovi, li sistemo e li riassegno.
982
+ // Se il nuovo Input Elements è roba strana mi limito a ripulire il diagramma
983
+ // Se cytoscape aveva già degli elementi precedentemente ne prendo le posizioni in modo da ridisegnarli partendo dallo stesso punto (carino per le animazioni)
984
+ let elements = elementChanges === null || elementChanges === void 0 ? void 0 : elementChanges.currentValue;
985
+ let previous_elements = this.PreserveElementsPosition ? this.cy.nodes() : null;
986
+ this.cy.elements().remove();
987
+ if (elements && elements.length && elements.length > 0) {
988
+ this.reviewCytoscapeElements(elements, previous_elements);
989
+ this.cy.add(elements);
990
+ // Se solo gli elementi cambiano, riapplico il Layout precedente
991
+ if (!layoutChanges && this.LastLayout) {
992
+ // Se devo animare le modifche al layout forzo il parametro relativo
993
+ if (this.AnimateLayoutChanges)
994
+ this.LastLayout.animate = true;
995
+ this.cy.layout(this.LastLayout).run();
996
+ }
997
+ }
998
+ }
999
+ // Se il layout cambia lo applico e me lo salvo come layout precedente per il futuro
1000
+ if (layoutChanges && !layoutChanges.firstChange) {
1001
+ this.service.log("I", "Layout have been changed after diagram initialization");
1002
+ this.LastLayout = JSON.parse(JSON.stringify(layoutChanges.currentValue));
1003
+ this.cy.layout(this.LastLayout).run();
1004
+ }
1005
+ }
1006
+ /**
1007
+ * Effettua il rendering del diagramma
1008
+ */
1009
+ render() {
1010
+ return __awaiter(this, void 0, void 0, function* () {
1011
+ // Tiro fuori le opzioni con cui generare il diagramma
1012
+ let cyOptions = this.getCompletedOptions();
1013
+ this.NodesHierarchy = cyOptions.elements && cyOptions.elements.some(t => t.data.parent);
1014
+ // Carico eventuali classi di estensione che servono
1015
+ yield this.performModulesLoading();
1016
+ // Genero il diagramma
1017
+ this.cy = cytoscape(cyOptions);
1018
+ // Collego gli eventi al componente
1019
+ this.bindCytoscapeEvents();
1020
+ // Utilizzo le classi di estensione caricate precedentemente per fare il resto delle mie operazioni
1021
+ this.performOperationsWithLoadedModules();
1022
+ // Imposto la variabile Rendered a true in modo che se da adesso vengono fatte modifiche che dovrebbero causare un redraw posso accorgermene
1023
+ // e mandare a cagare lo stronzo di turno
1024
+ this.Rendered = true;
1025
+ // Se devo aggiornare in automatico in base alla dimensione del contenitore collego il ResizeObserver
1026
+ if (this.AutoupdateSize)
1027
+ this.listenOnChanges();
1028
+ });
1029
+ }
1030
+ /**
1031
+ * Registra l'ascolto al contenitore del grafico e in caso di modifiche alla dimensione, al massimo una volta ogni 500 millisecondi, lo ridisegna
1032
+ */
1033
+ listenOnChanges() {
1034
+ this.resizeObserver = new ResizeSensor(this.cyGraph.nativeElement, () => {
1035
+ this.exts.throttle(this.name, this.onContainerSizeChanged.bind(this), this.ResizeThrottleTime);
1036
+ });
1037
+ }
1038
+ /**
1039
+ * Funzione che si occupa di gestire il repaint del diagramma
1040
+ */
1041
+ onContainerSizeChanged() {
1042
+ this.service.log("I", "Diagram container size has changed, redrawing");
1043
+ this.cy.resize();
1044
+ this.cy.fit();
1045
+ }
1046
+ /**
1047
+ * Collega tutti gli eventi che mi possono servire e li espone in output
1048
+ */
1049
+ bindCytoscapeEvents() {
1050
+ this.cy.bind('click', 'node', (event) => {
1051
+ this.onNodeClick.emit({ data: event.target.data() });
1052
+ });
1053
+ // Altri eventi...
1054
+ }
1055
+ /**
1056
+ * Metodo che serve per caricare tutte le estensioni della libreria in base a ciò che viene utilizzato
1057
+ */
1058
+ performModulesLoading() {
1059
+ return __awaiter(this, void 0, void 0, function* () {
1060
+ if (this.Layout.name == 'dagre')
1061
+ yield this.loadInternal("cytoscape-dagre");
1062
+ if (this.NodeHTMLTemplates && this.NodeHTMLTemplates.length > 0)
1063
+ yield this.loadInternal("cytoscape-html-node");
1064
+ if (this.UseContextMenu)
1065
+ yield this.loadInternal("cytoscape-cxtmenu");
1066
+ if (this.NodesHierarchy && this.UseExpandCollapse)
1067
+ yield this.loadInternal("cytoscape-expand-collapse");
1068
+ if (this.ExtensionModulesImporter) {
1069
+ // Wrappo il namespace in modo che possa dire la mia sul fatto che l'utente aggiunga un modulo o meno :D
1070
+ var wrappedCytoscape = {
1071
+ use: (moduleName, module) => {
1072
+ if (!module)
1073
+ this.service.log("E", this.service.loc("Received an undefined module. Make sure you are correctly loading it") + ": " + moduleName, false);
1074
+ if (["cytoscape-dagre", "cytoscape-html-node", "cytoscape-cxtmenu", "cytoscape-expand-collapse"].includes(moduleName))
1075
+ this.service.log("W", this.service.loc("Module") + " " + moduleName + " " + this.service.loc("is loaded and managed directly by this library. You don't need to import it or use it directly, just be sure to set the relative options"), false);
1076
+ else
1077
+ cytoscape.use(module);
1078
+ }
1079
+ };
1080
+ yield this.ExtensionModulesImporter(wrappedCytoscape);
1081
+ }
1082
+ });
1083
+ }
1084
+ /**
1085
+ * Metodo che serve per caricare tutte le estensioni della libreria in base a ciò che viene utilizzato con le opzioni definite dagli Input
1086
+ */
1087
+ performOperationsWithLoadedModules() {
1088
+ let anyCy = this.cy;
1089
+ // Utilizzo del layout, lo salvo per poterlo riutilizzare in futuro
1090
+ if (this.Layout) {
1091
+ this.LastLayout = JSON.parse(JSON.stringify(this.Layout));
1092
+ this.cy.layout(this.LastLayout).run();
1093
+ }
1094
+ // Utilizzo dell'HTML node
1095
+ if (this.NodeHTMLTemplates && this.NodeHTMLTemplates.length > 0) {
1096
+ let htmlnode = anyCy.htmlnode();
1097
+ htmlnode.createHtmlNode(cytoscape, this.cy, this.NodeHTMLTemplates);
1098
+ }
1099
+ // Utilizzo del Context Menu
1100
+ if (this.UseContextMenu)
1101
+ anyCy.cxtmenu(this.ContextMenuOptions);
1102
+ // Utilizzo dell'expand collapse solo quando c'è una gerarchia di nodi
1103
+ if (this.NodesHierarchy && this.UseExpandCollapse)
1104
+ this.ExpandCollapseApi = anyCy.expandCollapse(this.ExpandCollapseOptions);
1105
+ // Utilizzo di estensioni extra, implementazione affidata al programmatore
1106
+ if (this.ExtensionModulesApplyer)
1107
+ this.ExtensionModulesApplyer(this.cy);
1108
+ }
1109
+ /**
1110
+ * Metodo interno per il caricamento dei moduli di estensione
1111
+ *
1112
+ * @param {'cytoscape-expand-collapse' | 'cytoscape-cxtmenu' | 'cytoscape-html-node' | 'cytoscape-dagre'} moduleId Modulo da caricare
1113
+ */
1114
+ loadInternal(moduleId) {
1115
+ return __awaiter(this, void 0, void 0, function* () {
1116
+ let toLoad = yield this.service.importIfNeeded(moduleId);
1117
+ if (toLoad)
1118
+ cytoscape.use(toLoad);
1119
+ });
1120
+ }
1121
+ /**
1122
+ * Metodo che basandosi sulle opzioni native eventualmente assegnate le completa con gli Input addizionali
1123
+ *
1124
+ * @returns {cy_.CytoscapeOptions} Opzioni finali unite da Input ed opzioni native
1125
+ */
1126
+ getCompletedOptions() {
1127
+ var opts = this.NativeOptions || {};
1128
+ opts.container = this.cyGraph.nativeElement;
1129
+ opts.style = opts.style || [];
1130
+ // Per tutte le cose per cui gli Input hanno priorità sovrascrivo gli originali delle opzioni
1131
+ if (this.NodeStyles || this.EdgeStyles) {
1132
+ opts.style = [];
1133
+ if (this.NodeStyles)
1134
+ opts.style.push({ selector: 'node', css: this.NodeStyles });
1135
+ if (this.EdgeStyles)
1136
+ opts.style.push({ selector: 'edge', css: this.EdgeStyles });
1137
+ }
1138
+ if (this.Elements)
1139
+ opts.elements = this.Elements;
1140
+ this.reviewCytoscapeElements(opts.elements);
1141
+ if (this.Layout)
1142
+ opts.layout = this.Layout;
1143
+ if (this.Readonly) {
1144
+ // Questo coso fa effetti strani....
1145
+ //opts.autolock = true;
1146
+ opts.autoungrabify = true;
1147
+ opts.autounselectify = true;
1148
+ opts.boxSelectionEnabled = false;
1149
+ opts.userZoomingEnabled = false;
1150
+ opts.userPanningEnabled = false;
1151
+ }
1152
+ return opts;
1153
+ }
1154
+ /**
1155
+ * Aggiustamenti degli elementi di Cytoscape.
1156
+ *
1157
+ * I nodi non vengono toccati.
1158
+ *
1159
+ * Per ogni edge viene controllato se è specificata una sorgente ed una destinazione, in caso contrario si cerca di dedurli dall'ID
1160
+ *
1161
+ * @param {cytoscape.ElementDefinition[]} elements Elementi da sistemare
1162
+ */
1163
+ reviewCytoscapeElements(elements, prevPositions) {
1164
+ let hasPreviousPositions = prevPositions && prevPositions.length > 0;
1165
+ let positionCache = {};
1166
+ if (hasPreviousPositions) {
1167
+ for (let i = 0; i < prevPositions.length; i++) {
1168
+ let item = prevPositions[i];
1169
+ if (!positionCache[item.data().id])
1170
+ positionCache[item.data().id] = item.position();
1171
+ }
1172
+ }
1173
+ for (let i = 0; i < elements.length; i++) {
1174
+ let el = elements[i];
1175
+ if (el.group == "edges" && (!el.data.source && !el.data.target)) {
1176
+ if (!el.data.id.includes("-"))
1177
+ this.service.log("E", "If you don't specify a source and a target for an edge you have to write its id in the format {source}-{target}");
1178
+ else {
1179
+ var sourceTarget = el.data.id.split('-');
1180
+ el.data.source = sourceTarget[0].trim();
1181
+ el.data.target = sourceTarget[1].trim();
1182
+ }
1183
+ }
1184
+ if (hasPreviousPositions && el.group == "nodes")
1185
+ el.position = positionCache[el.data.id];
1186
+ }
1187
+ }
1188
+ }
1189
+ EsDiagramComponent.decorators = [
1190
+ { type: Component, args: [{
1191
+ selector: 'es-diagram',
1192
+ template: "<div #graph class=\"graph-wrapper {{name}}\"></div>",
1193
+ styles: [".graph-wrapper{height:100%;width:100%}.html-node-notransition{transition:none!important;transform:none!important}\n"]
1194
+ },] }
1195
+ ];
1196
+ EsDiagramComponent.ctorParameters = () => [
1197
+ { type: EsDiagramService, decorators: [{ type: Optional }] },
1198
+ { type: EsDiagramDispatcher, decorators: [{ type: Optional }] },
1199
+ { type: ReactiveExtensions }
1200
+ ];
1201
+ EsDiagramComponent.propDecorators = {
1202
+ cyGraph: [{ type: ViewChild, args: ['graph',] }],
1203
+ name: [{ type: Input }],
1204
+ UseContextMenu: [{ type: Input }],
1205
+ ContextMenuOptions: [{ type: Input }],
1206
+ UseExpandCollapse: [{ type: Input }],
1207
+ ExpandCollapseOptions: [{ type: Input }],
1208
+ NativeOptions: [{ type: Input }],
1209
+ Elements: [{ type: Input }],
1210
+ NodeStyles: [{ type: Input }],
1211
+ EdgeStyles: [{ type: Input }],
1212
+ Readonly: [{ type: Input }],
1213
+ AutoupdateSize: [{ type: Input }],
1214
+ PreserveElementsPosition: [{ type: Input }],
1215
+ AnimateLayoutChanges: [{ type: Input }],
1216
+ ResizeThrottleTime: [{ type: Input }],
1217
+ Layout: [{ type: Input }],
1218
+ NodeHTMLTemplates: [{ type: Input }],
1219
+ ExtensionModulesImporter: [{ type: Input }],
1220
+ ExtensionModulesApplyer: [{ type: Input }],
1221
+ onNodeClick: [{ type: Output }]
1222
+ };
1223
+
1224
+ class EsDiagramModule {
1225
+ static forRoot(config) {
1226
+ return {
1227
+ ngModule: EsDiagramModule,
1228
+ providers: [
1229
+ EsDiagramService,
1230
+ EsDiagramDispatcher,
1231
+ { provide: DIA_LOCALE, useValue: (config === null || config === void 0 ? void 0 : config.locale) || 'it-IT' },
1232
+ { provide: DIA_DEBUG_MODE, useValue: (config === null || config === void 0 ? void 0 : config.debugMode) || false },
1233
+ ]
1234
+ };
1235
+ }
1236
+ }
1237
+ EsDiagramModule.decorators = [
1238
+ { type: NgModule, args: [{
1239
+ declarations: [EsDiagramComponent],
1240
+ imports: [CommonModule, FormsModule, ReactiveFormsModule, CommonModule],
1241
+ exports: [EsDiagramComponent]
1242
+ },] }
1243
+ ];
1244
+
1245
+ /*
1246
+ * Public API Surface of cytoscape-angular
1247
+ */
1248
+
1249
+ /**
1250
+ * Generated bundle index. Do not edit.
1251
+ */
1252
+
1253
+ export { BaseLayoutOptionsImpl, BreadthFirstLayoutOptionsImpl, CircleLayoutOptionsImpl, ConcentricLayoutOptionsImpl, ContextMenuCommand, ContextMenuOptions, CoseLayoutOptionsImpl, DagreLayoutOptionsImpl, EsDiagramComponent, EsDiagramModule, EsDiagramModuleConfig, ExpandCollapseOptions, GridLayoutOptionsImpl, NodeHTMLTemplate, NodeTemplate, NullLayoutOptionsImpl, PresetLayoutOptionsImpl, RandomLayoutOptionsImpl, ShapedLayoutOptionsImpl, ZoomLevelBasedTemplate, AnimateLayoutOptionsImpl as ɵa, EsDiagramService as ɵb, DIA_LOCALE as ɵc, DIA_DEBUG_MODE as ɵd, EsDiagramDispatcher as ɵe, ReactiveExtensions as ɵf };
1254
+ //# sourceMappingURL=esfaenza-es-diagrams.js.map