@html-graph/html-graph 3.6.0 → 3.8.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.
- package/README.md +63 -54
- package/dist/html-graph.d.ts +130 -12
- package/dist/html-graph.js +1525 -1440
- package/dist/html-graph.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,65 +23,74 @@ npm i @html-graph/html-graph
|
|
|
23
23
|
```javascript
|
|
24
24
|
import { CanvasBuilder } from "@html-graph/html-graph";
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
class Application {
|
|
27
|
+
constructor(element) {
|
|
28
|
+
this.canvas = new CanvasBuilder(element)
|
|
29
|
+
.setDefaults({
|
|
30
|
+
edges: {
|
|
31
|
+
shape: {
|
|
32
|
+
hasTargetArrow: true,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
.enableUserDraggableNodes()
|
|
37
|
+
.enableUserTransformableViewport()
|
|
38
|
+
.enableBackground()
|
|
39
|
+
.build();
|
|
40
|
+
}
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
initGraph() {
|
|
43
|
+
this.canvas
|
|
44
|
+
.addNode(
|
|
45
|
+
this.createNode({
|
|
46
|
+
name: "Node 1",
|
|
47
|
+
x: 200,
|
|
48
|
+
y: 400,
|
|
49
|
+
frontPortId: "node-1-in",
|
|
50
|
+
backPortId: "node-1-out",
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
53
|
+
.addNode(
|
|
54
|
+
this.createNode({
|
|
55
|
+
name: "Node 2",
|
|
56
|
+
x: 600,
|
|
57
|
+
y: 500,
|
|
58
|
+
frontPortId: "node-2-in",
|
|
59
|
+
backPortId: "node-2-out",
|
|
60
|
+
}),
|
|
61
|
+
)
|
|
62
|
+
.addEdge({ from: "node-1-out", to: "node-2-in" });
|
|
63
|
+
}
|
|
36
64
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
65
|
+
createNode({ name, x, y, frontPortId, backPortId }) {
|
|
66
|
+
const node = document.createElement("div");
|
|
67
|
+
const text = document.createElement("div");
|
|
68
|
+
const frontPort = document.createElement("div");
|
|
69
|
+
const backPort = document.createElement("div");
|
|
40
70
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
71
|
+
node.classList.add("node");
|
|
72
|
+
frontPort.classList.add("port");
|
|
73
|
+
backPort.classList.add("port");
|
|
74
|
+
text.innerText = name;
|
|
75
|
+
|
|
76
|
+
node.appendChild(frontPort);
|
|
77
|
+
node.appendChild(text);
|
|
78
|
+
node.appendChild(backPort);
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
element: node,
|
|
82
|
+
x: x,
|
|
83
|
+
y: y,
|
|
84
|
+
ports: [
|
|
85
|
+
{ id: frontPortId, element: frontPort },
|
|
86
|
+
{ id: backPortId, element: backPort },
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
50
90
|
}
|
|
51
91
|
|
|
52
92
|
const element = document.getElementById("canvas");
|
|
93
|
+
const app = new Application(element);
|
|
53
94
|
|
|
54
|
-
|
|
55
|
-
.setDefaults({
|
|
56
|
-
edges: {
|
|
57
|
-
shape: {
|
|
58
|
-
hasTargetArrow: true,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
})
|
|
62
|
-
.enableUserDraggableNodes()
|
|
63
|
-
.enableUserTransformableViewport()
|
|
64
|
-
.enableBackground()
|
|
65
|
-
.build();
|
|
66
|
-
|
|
67
|
-
canvas
|
|
68
|
-
.addNode(
|
|
69
|
-
createNode({
|
|
70
|
-
name: "Node 1",
|
|
71
|
-
x: 200,
|
|
72
|
-
y: 400,
|
|
73
|
-
frontPortId: "node-1-in",
|
|
74
|
-
backPortId: "node-1-out",
|
|
75
|
-
}),
|
|
76
|
-
)
|
|
77
|
-
.addNode(
|
|
78
|
-
createNode({
|
|
79
|
-
name: "Node 2",
|
|
80
|
-
x: 600,
|
|
81
|
-
y: 500,
|
|
82
|
-
frontPortId: "node-2-in",
|
|
83
|
-
backPortId: "node-2-out",
|
|
84
|
-
}),
|
|
85
|
-
)
|
|
86
|
-
.addEdge({ from: "node-1-out", to: "node-2-in" });
|
|
95
|
+
app.initGraph();
|
|
87
96
|
```
|
package/dist/html-graph.d.ts
CHANGED
|
@@ -65,8 +65,15 @@ export declare interface BezierEdgeParams {
|
|
|
65
65
|
readonly detourDirection?: number | undefined;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Responsibility: Providing edge shape connecting ports with bezier line
|
|
70
|
+
*/
|
|
71
|
+
export declare class BezierEdgeShape implements StructuredEdgeShape {
|
|
69
72
|
readonly svg: SVGSVGElement;
|
|
73
|
+
readonly group: SVGGElement;
|
|
74
|
+
readonly line: SVGPathElement;
|
|
75
|
+
readonly sourceArrow: SVGPathElement | null;
|
|
76
|
+
readonly targetArrow: SVGPathElement | null;
|
|
70
77
|
private readonly arrowLength;
|
|
71
78
|
private readonly arrowWidth;
|
|
72
79
|
private readonly curvature;
|
|
@@ -76,7 +83,7 @@ export declare class BezierEdgeShape implements EdgeShape {
|
|
|
76
83
|
private readonly detourDistance;
|
|
77
84
|
private readonly hasSourceArrow;
|
|
78
85
|
private readonly hasTargetArrow;
|
|
79
|
-
private readonly
|
|
86
|
+
private readonly lineShape;
|
|
80
87
|
private readonly createCyclePath;
|
|
81
88
|
private readonly createDetourPath;
|
|
82
89
|
private readonly createLinePath;
|
|
@@ -99,6 +106,7 @@ export declare class Canvas {
|
|
|
99
106
|
private readonly graphStore;
|
|
100
107
|
private readonly viewportStore;
|
|
101
108
|
private readonly htmlView;
|
|
109
|
+
private readonly defaults;
|
|
102
110
|
/**
|
|
103
111
|
* provides api for accessing model of rendered graph
|
|
104
112
|
*/
|
|
@@ -107,7 +115,6 @@ export declare class Canvas {
|
|
|
107
115
|
* provides api for accessing viewport state
|
|
108
116
|
*/
|
|
109
117
|
readonly viewport: Viewport;
|
|
110
|
-
private readonly defaults;
|
|
111
118
|
private readonly nodeIdGenerator;
|
|
112
119
|
private readonly portIdGenerator;
|
|
113
120
|
private readonly edgeIdGenerator;
|
|
@@ -132,7 +139,7 @@ export declare class Canvas {
|
|
|
132
139
|
/**
|
|
133
140
|
* @deprecated access element directly instead
|
|
134
141
|
*/
|
|
135
|
-
element: HTMLElement, graphStore: GraphStore, viewportStore: ViewportStore, htmlView: HtmlView, defaults:
|
|
142
|
+
element: HTMLElement, graphStore: GraphStore, viewportStore: ViewportStore, htmlView: HtmlView, defaults: Defaults);
|
|
136
143
|
/**
|
|
137
144
|
* adds new node
|
|
138
145
|
*/
|
|
@@ -322,8 +329,24 @@ export declare type ConnectionTypeResolver = (portId: unknown) => "direct" | "re
|
|
|
322
329
|
|
|
323
330
|
declare type ConstantPriority = number;
|
|
324
331
|
|
|
332
|
+
export declare type CreatePathFn = (sourceDirection: Point, targetDirection: Point, to: Point, flipX: number, flipY: number) => string;
|
|
333
|
+
|
|
325
334
|
declare type CustomPriority = PriorityFn;
|
|
326
335
|
|
|
336
|
+
declare interface Defaults {
|
|
337
|
+
readonly nodes: {
|
|
338
|
+
readonly centerFn: CenterFn;
|
|
339
|
+
readonly priorityFn: PriorityFn;
|
|
340
|
+
};
|
|
341
|
+
readonly ports: {
|
|
342
|
+
readonly direction: number;
|
|
343
|
+
};
|
|
344
|
+
readonly edges: {
|
|
345
|
+
readonly shapeFactory: EdgeShapeFactory;
|
|
346
|
+
readonly priorityFn: PriorityFn;
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
327
350
|
declare interface DotsRenderer {
|
|
328
351
|
readonly radius?: number;
|
|
329
352
|
readonly color?: string;
|
|
@@ -377,7 +400,7 @@ export declare interface EdgeShape {
|
|
|
377
400
|
|
|
378
401
|
declare type EdgeShapeConfig = BezierEdgeShapeConfig | StraightEdgeShapeConfig | HorizontalEdgeShapeConfig | VerticalEdgeShapeConfig | EdgeShapeFactory;
|
|
379
402
|
|
|
380
|
-
declare type EdgeShapeFactory = () => EdgeShape;
|
|
403
|
+
declare type EdgeShapeFactory = (edgeId: unknown) => EdgeShape;
|
|
381
404
|
|
|
382
405
|
/**
|
|
383
406
|
* Responsibility: Provides a way to trigger events
|
|
@@ -424,10 +447,12 @@ export declare class Graph {
|
|
|
424
447
|
readonly onBeforeClear: EventHandler<void>;
|
|
425
448
|
constructor(graphStore: GraphStore);
|
|
426
449
|
getNode(nodeId: unknown): GraphNode | null;
|
|
450
|
+
getElementNodeId(element: HTMLElement): unknown | null;
|
|
427
451
|
getAllNodeIds(): readonly unknown[];
|
|
428
452
|
getPort(portId: unknown): GraphPort | null;
|
|
429
453
|
getAllPortIds(): readonly unknown[];
|
|
430
454
|
getNodePortIds(nodeId: unknown): readonly unknown[] | null;
|
|
455
|
+
getElementPortsIds(element: HTMLElement): readonly unknown[];
|
|
431
456
|
getAllEdgeIds(): readonly unknown[];
|
|
432
457
|
getEdge(edgeId: unknown): GraphEdge | null;
|
|
433
458
|
getPortIncomingEdgeIds(portId: unknown): readonly unknown[] | null;
|
|
@@ -461,15 +486,17 @@ export declare interface GraphPort {
|
|
|
461
486
|
}
|
|
462
487
|
|
|
463
488
|
/**
|
|
464
|
-
* Responsibility:
|
|
489
|
+
* Responsibility: Store state of graph
|
|
465
490
|
*/
|
|
466
491
|
declare class GraphStore {
|
|
467
492
|
private readonly nodes;
|
|
468
493
|
private readonly ports;
|
|
469
494
|
private readonly edges;
|
|
495
|
+
private readonly nodesElementsMap;
|
|
470
496
|
private readonly incomingEdges;
|
|
471
497
|
private readonly outcomingEdges;
|
|
472
498
|
private readonly cycleEdges;
|
|
499
|
+
private readonly elementPorts;
|
|
473
500
|
private readonly afterNodeAddedEmitter;
|
|
474
501
|
readonly onAfterNodeAdded: EventHandler<unknown>;
|
|
475
502
|
private readonly afterNodeUpdatedEmitter;
|
|
@@ -500,12 +527,14 @@ declare class GraphStore {
|
|
|
500
527
|
addNode(request: AddNodeRequest_2): void;
|
|
501
528
|
getAllNodeIds(): readonly unknown[];
|
|
502
529
|
getNode(nodeId: unknown): NodePayload | undefined;
|
|
530
|
+
getElementNodeId(element: HTMLElement): unknown | undefined;
|
|
503
531
|
updateNode(nodeId: unknown, request: UpdateNodeRequest_2): void;
|
|
504
532
|
removeNode(nodeId: unknown): void;
|
|
505
533
|
addPort(request: AddPortRequest): void;
|
|
506
534
|
getPort(portId: unknown): PortPayload | undefined;
|
|
507
535
|
updatePort(portId: unknown, request: UpdatePortRequest_2): void;
|
|
508
536
|
getAllPortIds(): readonly unknown[];
|
|
537
|
+
getElementPortsIds(element: HTMLElement): readonly unknown[];
|
|
509
538
|
getNodePortIds(nodeId: unknown): readonly unknown[] | undefined;
|
|
510
539
|
removePort(portId: unknown): void;
|
|
511
540
|
addEdge(request: AddEdgeRequest_2): void;
|
|
@@ -540,8 +569,16 @@ export declare interface HorizontalEdgeParams {
|
|
|
540
569
|
readonly detourDirection?: number | undefined;
|
|
541
570
|
}
|
|
542
571
|
|
|
543
|
-
|
|
572
|
+
/**
|
|
573
|
+
* Responsibility: Providing edge shape connecting ports with horizontal angled
|
|
574
|
+
* line
|
|
575
|
+
*/
|
|
576
|
+
export declare class HorizontalEdgeShape implements StructuredEdgeShape {
|
|
544
577
|
readonly svg: SVGSVGElement;
|
|
578
|
+
readonly group: SVGGElement;
|
|
579
|
+
readonly line: SVGPathElement;
|
|
580
|
+
readonly sourceArrow: SVGPathElement | null;
|
|
581
|
+
readonly targetArrow: SVGPathElement | null;
|
|
545
582
|
private readonly arrowLength;
|
|
546
583
|
private readonly arrowWidth;
|
|
547
584
|
private readonly arrowOffset;
|
|
@@ -551,7 +588,7 @@ export declare class HorizontalEdgeShape implements EdgeShape {
|
|
|
551
588
|
private readonly detourDistance;
|
|
552
589
|
private readonly hasSourceArrow;
|
|
553
590
|
private readonly hasTargetArrow;
|
|
554
|
-
private readonly
|
|
591
|
+
private readonly lineShape;
|
|
555
592
|
private readonly createCyclePath;
|
|
556
593
|
private readonly createDetourPath;
|
|
557
594
|
private readonly createLinePath;
|
|
@@ -590,6 +627,62 @@ declare interface HtmlView {
|
|
|
590
627
|
|
|
591
628
|
declare type IncrementalPriority = "incremental";
|
|
592
629
|
|
|
630
|
+
export declare class InteractiveEdgeError extends Error {
|
|
631
|
+
constructor(message: string);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export declare interface InteractiveEdgeParams {
|
|
635
|
+
/**
|
|
636
|
+
* TODO: rename to 'radius'
|
|
637
|
+
*/
|
|
638
|
+
readonly width?: number;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Responsibility: Providing handle for attaching interactive behavior to an
|
|
643
|
+
* edge
|
|
644
|
+
*/
|
|
645
|
+
export declare class InteractiveEdgeShape implements StructuredEdgeShape {
|
|
646
|
+
private readonly structuredEdge;
|
|
647
|
+
readonly svg: SVGSVGElement;
|
|
648
|
+
readonly group: SVGGElement;
|
|
649
|
+
readonly line: SVGPathElement;
|
|
650
|
+
readonly sourceArrow: SVGPathElement | null;
|
|
651
|
+
readonly targetArrow: SVGPathElement | null;
|
|
652
|
+
readonly handle: SVGGElement;
|
|
653
|
+
private readonly interactiveLine;
|
|
654
|
+
private readonly interactiveSourceArrow;
|
|
655
|
+
private readonly interactiveTargetArrow;
|
|
656
|
+
constructor(structuredEdge: StructuredEdgeShape, params?: InteractiveEdgeParams);
|
|
657
|
+
render(params: EdgeRenderParams): void;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
export declare interface LineEdgeParams {
|
|
661
|
+
readonly width: number;
|
|
662
|
+
readonly color: string;
|
|
663
|
+
readonly arrowLength: number;
|
|
664
|
+
readonly arrowWidth: number;
|
|
665
|
+
readonly hasSourceArrow: boolean;
|
|
666
|
+
readonly hasTargetArrow: boolean;
|
|
667
|
+
readonly createCyclePath: CreatePathFn;
|
|
668
|
+
readonly createDetourPath: CreatePathFn;
|
|
669
|
+
readonly createLinePath: CreatePathFn;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Responsibility: Providing low level core for single line structured edges
|
|
674
|
+
*/
|
|
675
|
+
export declare class LineEdgeShape implements StructuredEdgeShape {
|
|
676
|
+
private readonly params;
|
|
677
|
+
readonly svg: SVGSVGElement;
|
|
678
|
+
readonly group: SVGGElement;
|
|
679
|
+
readonly line: SVGPathElement;
|
|
680
|
+
readonly sourceArrow: SVGPathElement | null;
|
|
681
|
+
readonly targetArrow: SVGPathElement | null;
|
|
682
|
+
constructor(params: LineEdgeParams);
|
|
683
|
+
render(params: EdgeRenderParams): void;
|
|
684
|
+
}
|
|
685
|
+
|
|
593
686
|
export declare type MarkNodePortRequest = {
|
|
594
687
|
readonly id?: unknown | undefined;
|
|
595
688
|
readonly element: HTMLElement;
|
|
@@ -687,8 +780,15 @@ export declare interface StraightEdgeParams {
|
|
|
687
780
|
readonly detourDirection?: number | undefined;
|
|
688
781
|
}
|
|
689
782
|
|
|
690
|
-
|
|
783
|
+
/**
|
|
784
|
+
* Responsibility: Providing edge shape connecting ports with straight line
|
|
785
|
+
*/
|
|
786
|
+
export declare class StraightEdgeShape implements StructuredEdgeShape {
|
|
691
787
|
readonly svg: SVGSVGElement;
|
|
788
|
+
readonly group: SVGGElement;
|
|
789
|
+
readonly line: SVGPathElement;
|
|
790
|
+
readonly sourceArrow: SVGPathElement | null;
|
|
791
|
+
readonly targetArrow: SVGPathElement | null;
|
|
692
792
|
private readonly arrowLength;
|
|
693
793
|
private readonly arrowWidth;
|
|
694
794
|
private readonly arrowOffset;
|
|
@@ -698,7 +798,7 @@ export declare class StraightEdgeShape implements EdgeShape {
|
|
|
698
798
|
private readonly detourDistance;
|
|
699
799
|
private readonly hasSourceArrow;
|
|
700
800
|
private readonly hasTargetArrow;
|
|
701
|
-
private readonly
|
|
801
|
+
private readonly lineShape;
|
|
702
802
|
private readonly createCyclePath;
|
|
703
803
|
private readonly createDetourPath;
|
|
704
804
|
private readonly createLinePath;
|
|
@@ -710,6 +810,16 @@ declare type StraightEdgeShapeConfig = {
|
|
|
710
810
|
readonly type: "straight";
|
|
711
811
|
} & StraightEdgeParams;
|
|
712
812
|
|
|
813
|
+
/**
|
|
814
|
+
* Responsibility: Specifying EdgeShape with a standard visual structure
|
|
815
|
+
*/
|
|
816
|
+
export declare interface StructuredEdgeShape extends EdgeShape {
|
|
817
|
+
readonly group: SVGGElement;
|
|
818
|
+
readonly line: SVGPathElement;
|
|
819
|
+
readonly sourceArrow: SVGPathElement | null;
|
|
820
|
+
readonly targetArrow: SVGPathElement | null;
|
|
821
|
+
}
|
|
822
|
+
|
|
713
823
|
export declare interface TransformPayload {
|
|
714
824
|
readonly scale: number;
|
|
715
825
|
readonly x: number;
|
|
@@ -793,8 +903,16 @@ export declare interface VerticalEdgeParams {
|
|
|
793
903
|
readonly detourDirection?: number | undefined;
|
|
794
904
|
}
|
|
795
905
|
|
|
796
|
-
|
|
906
|
+
/**
|
|
907
|
+
* Responsibility: Providing edge shape connecting ports with vertical angled
|
|
908
|
+
* line
|
|
909
|
+
*/
|
|
910
|
+
export declare class VerticalEdgeShape implements StructuredEdgeShape {
|
|
797
911
|
readonly svg: SVGSVGElement;
|
|
912
|
+
readonly group: SVGGElement;
|
|
913
|
+
readonly line: SVGPathElement;
|
|
914
|
+
readonly sourceArrow: SVGPathElement | null;
|
|
915
|
+
readonly targetArrow: SVGPathElement | null;
|
|
798
916
|
private readonly arrowLength;
|
|
799
917
|
private readonly arrowWidth;
|
|
800
918
|
private readonly arrowOffset;
|
|
@@ -804,7 +922,7 @@ export declare class VerticalEdgeShape implements EdgeShape {
|
|
|
804
922
|
private readonly detourDistance;
|
|
805
923
|
private readonly hasSourceArrow;
|
|
806
924
|
private readonly hasTargetArrow;
|
|
807
|
-
private readonly
|
|
925
|
+
private readonly lineShape;
|
|
808
926
|
private readonly createCyclePath;
|
|
809
927
|
private readonly createDetourPath;
|
|
810
928
|
private readonly createLinePath;
|