@html-graph/html-graph 0.0.56 → 0.0.57

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 CHANGED
@@ -6,11 +6,11 @@
6
6
 
7
7
  ![CI](https://github.com/html-graph/html-graph/actions/workflows/ci.yml/badge.svg?branch=master)
8
8
 
9
- <a target="_blank" href="https://html-graph.github.io/">
9
+ <a target="_blank" href="https://html-graph.github.io/use-cases/20-advanced-demo/index.html">
10
10
  <img width="100%" src="https://raw.githubusercontent.com/html-graph/html-graph/master/media/full-demo.gif"/>
11
11
  </a>
12
12
 
13
- Visit <a target="_blank" href="https://html-graph.github.io">live demo</a>.
13
+ Visit <a target="_blank" href="https://html-graph.github.io">use cases</a> and [use cases implementation](use-cases).
14
14
 
15
15
  Instead of connecting nodes directly this library uses concept of ports, which provide greater fexibility at managing edges.
16
16
  Port is an entity of a node to which edge can be attached to.
@@ -20,7 +20,7 @@ Port is an entity of a node to which edge can be attached to.
20
20
  - easy nodes customization using HTML
21
21
  - wide configuration options out of the box
22
22
  - draggable and scalable canvas with draggable nodes
23
- - exhaustive set of examples
23
+ - exhaustive set of use cases
24
24
  - typescript support
25
25
  - mobile devices support
26
26
 
@@ -30,8 +30,8 @@ Port is an entity of a node to which edge can be attached to.
30
30
  npm i @html-graph/html-graph
31
31
  ```
32
32
 
33
- ```typescript
34
- import { HtmlGraphBuilder, AddNodeRequest } from "@html-graph/html-graph";
33
+ ```javascript
34
+ import { HtmlGraphBuilder } from "@html-graph/html-graph";
35
35
 
36
36
  const canvas = new HtmlGraphBuilder()
37
37
  .setOptions({
@@ -48,27 +48,20 @@ const canvas = new HtmlGraphBuilder()
48
48
  .setUserTransformableCanvas()
49
49
  .build();
50
50
 
51
- function createNode(
52
- name: string,
53
- x: number,
54
- y: number,
55
- frontPortId: string,
56
- backPortId: string,
57
- ): AddNodeRequest {
51
+ function createNode({ name, x, y, frontPortId, backPortId }) {
58
52
  const node = document.createElement("div");
59
- node.classList.add("node");
60
-
53
+ const text = document.createElement("div");
61
54
  const frontPort = document.createElement("div");
62
- frontPort.classList.add("port");
63
- node.appendChild(frontPort);
55
+ const backPort = document.createElement("div");
64
56
 
65
- const text = document.createElement("div");
57
+ node.classList.add("node");
58
+ frontPort.classList.add("port");
59
+ backPort.classList.add("port");
66
60
  text.innerText = name;
67
- node.appendChild(text);
68
61
 
69
- const backPort = document.createElement("div");
70
- backPort.classList.add("port");
71
62
  node.appendChild(backPort);
63
+ node.appendChild(text);
64
+ node.appendChild(frontPort);
72
65
 
73
66
  return {
74
67
  element: node,
@@ -81,10 +74,23 @@ function createNode(
81
74
  };
82
75
  }
83
76
 
84
- const node1 = createNode("Node 1", 200, 400, "port-1-1", "port-1-2");
85
- const node2 = createNode("Node 2", 600, 500, "port-2-1", "port-2-2");
77
+ const node1 = createNode({
78
+ name: "Node 1",
79
+ x: 200,
80
+ y: 400,
81
+ frontPortId: "port-1-1",
82
+ backPortId: "port-1-2",
83
+ });
86
84
 
87
- const canvasElement = document.getElementById("canvas")!;
85
+ const node2 = createNode({
86
+ name: "Node 2",
87
+ x: 600,
88
+ y: 500,
89
+ frontPortId: "port-2-1",
90
+ backPortId: "port-2-2",
91
+ });
92
+
93
+ const canvasElement = document.getElementById("canvas");
88
94
 
89
95
  canvas
90
96
  .attach(canvasElement)
@@ -93,9 +99,7 @@ canvas
93
99
  .addEdge({ from: "port-1-2", to: "port-2-1" });
94
100
  ```
95
101
 
96
- Refer to [Use cases](use-cases) for more.
97
-
98
- ## Run examples
102
+ ## Run use cases
99
103
 
100
104
  ```
101
105
  npm install
package/dist/main.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ declare interface AbstractViewportTransformer {
2
+ getViewportMatrix(): TransformState;
3
+ getContentMatrix(): TransformState;
4
+ patchViewportMatrix(scale: number | null, x: number | null, y: number | null): void;
5
+ patchContentMatrix(scale: number | null, dx: number | null, dy: number | null): void;
6
+ }
7
+
1
8
  export declare interface AddEdgeRequest {
2
9
  readonly id?: unknown;
3
10
  readonly from: string;
@@ -28,14 +35,13 @@ declare type BackgroundOptions = {
28
35
  readonly dotGap?: number;
29
36
  readonly dotRadius?: number;
30
37
  readonly color?: string;
38
+ readonly limit?: number;
31
39
  } | {
32
40
  readonly type: "custom";
33
41
  readonly drawingFn: BackgroundDrawingFn;
34
42
  };
35
43
 
36
44
  export declare class BezierEdgeShape implements EdgeShape {
37
- private readonly color;
38
- private readonly width;
39
45
  private readonly curvature;
40
46
  private readonly arrowLength;
41
47
  private readonly arrowWidth;
@@ -45,7 +51,7 @@ export declare class BezierEdgeShape implements EdgeShape {
45
51
  private readonly sourceArrow;
46
52
  private readonly targetArrow;
47
53
  constructor(color: string, width: number, curvature: number, arrowLength: number, arrowWidth: number, hasSourceArrow: boolean, hasTargetArrow: boolean);
48
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
54
+ update(x: number, y: number, width: number, height: number, from: GraphPort, to: GraphPort): void;
49
55
  }
50
56
 
51
57
  declare interface BezierEdgeShape_2 {
@@ -284,8 +290,6 @@ declare interface CustomEdgeShape {
284
290
  declare type CustomPriority = PriorityFn;
285
291
 
286
292
  export declare class CycleCircleEdgeShape implements EdgeShape {
287
- private readonly color;
288
- private readonly width;
289
293
  private readonly arrowLength;
290
294
  private readonly arrowWidth;
291
295
  private readonly radius;
@@ -295,12 +299,10 @@ export declare class CycleCircleEdgeShape implements EdgeShape {
295
299
  private readonly line;
296
300
  private readonly arrow;
297
301
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, hasArrow: boolean, radius: number, smallRadius: number);
298
- update(x: number, y: number, _width: number, _height: number, from: PortPayload): void;
302
+ update(x: number, y: number, _width: number, _height: number, from: GraphPort): void;
299
303
  }
300
304
 
301
305
  export declare class CycleSquareEdgeShape implements EdgeShape {
302
- private readonly color;
303
- private readonly width;
304
306
  private readonly arrowLength;
305
307
  private readonly arrowWidth;
306
308
  private readonly side;
@@ -312,12 +314,10 @@ export declare class CycleSquareEdgeShape implements EdgeShape {
312
314
  private readonly roundness;
313
315
  private readonly linePoints;
314
316
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, hasArrow: boolean, side: number, minPortOffset: number, roundness: number);
315
- update(x: number, y: number, _width: number, _height: number, from: PortPayload): void;
317
+ update(x: number, y: number, _width: number, _height: number, from: GraphPort): void;
316
318
  }
317
319
 
318
320
  export declare class DetourStraightEdgeShape implements EdgeShape {
319
- private readonly color;
320
- private readonly width;
321
321
  private readonly arrowLength;
322
322
  private readonly arrowWidth;
323
323
  private readonly arrowOffset;
@@ -330,11 +330,12 @@ export declare class DetourStraightEdgeShape implements EdgeShape {
330
330
  private readonly detourX;
331
331
  private readonly detourY;
332
332
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, arrowOffset: number, hasSourceArrow: boolean, hasTargetArrow: boolean, roundness: number, detourDistance: number, detourDirection: number);
333
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
333
+ update(x: number, y: number, width: number, height: number, from: GraphPort, to: GraphPort): void;
334
334
  }
335
335
 
336
336
  export declare interface DragOptions {
337
337
  grabPriorityStrategy?: "freeze" | "move-on-top";
338
+ dragCursor?: string | null;
338
339
  events?: {
339
340
  onNodeDrag?: (payload: NodeDragPayload) => void;
340
341
  onBeforeNodeDrag?: (payload: NodeDragPayload) => boolean;
@@ -342,15 +343,15 @@ export declare interface DragOptions {
342
343
  }
343
344
 
344
345
  declare interface EdgePayload {
345
- from: string;
346
- to: string;
346
+ readonly from: unknown;
347
+ readonly to: unknown;
347
348
  shape: EdgeShape;
348
349
  priority: number;
349
350
  }
350
351
 
351
352
  export declare interface EdgeShape {
352
353
  readonly svg: SVGSVGElement;
353
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
354
+ update(x: number, y: number, width: number, height: number, from: GraphPort, to: GraphPort): void;
354
355
  }
355
356
 
356
357
  declare type EdgeShape_2 = BezierEdgeShape_2 | StraightEdgeShape_2 | CustomEdgeShape | HorizontalEdgeShape_2 | VerticalEdgeShape_2;
@@ -393,33 +394,31 @@ declare class GraphStore {
393
394
  private readonly outcommingEdges;
394
395
  private readonly cycleEdges;
395
396
  addNode(nodeId: unknown, element: HTMLElement, x: number, y: number, centerFn: CenterFn, priority: number): void;
396
- getAllNodes(): readonly unknown[];
397
+ getAllNodeIds(): readonly unknown[];
397
398
  getNode(nodeId: unknown): NodePayload | undefined;
398
- getNodePorts(nodeId: unknown): readonly unknown[] | undefined;
399
399
  removeNode(nodeId: unknown): void;
400
400
  addPort(portId: unknown, element: HTMLElement, nodeId: unknown, centerFn: CenterFn, dir: number): void;
401
- getAllPorts(): readonly unknown[];
402
401
  getPort(portId: unknown): PortPayload | undefined;
403
- getPortNode(portId: unknown): unknown | undefined;
402
+ getAllPortIds(): readonly unknown[];
403
+ getNodePortIds(nodeId: unknown): readonly unknown[] | undefined;
404
+ getPortNodeId(portId: unknown): unknown | undefined;
404
405
  removePort(portId: unknown): void;
405
- addEdge(edgeId: unknown, fromPortId: string, toPortId: string, shape: EdgeShape, priority: number): void;
406
- getAllEdges(): readonly unknown[];
406
+ addEdge(edgeId: unknown, fromPortId: unknown, toPortId: unknown, shape: EdgeShape, priority: number): void;
407
+ getAllEdgeIds(): readonly unknown[];
407
408
  getEdge(edgeId: unknown): EdgePayload | undefined;
408
409
  removeEdge(edgeId: unknown): void;
409
- getPortAdjacentEdges(portId: string): readonly unknown[];
410
- getNodeAdjacentEdges(nodeId: unknown): readonly unknown[];
411
410
  clear(): void;
412
- getPortIncomingEdges(portId: unknown): readonly unknown[];
413
- getPortOutcomingEdges(portId: unknown): readonly unknown[];
414
- getPortCycleEdges(portId: unknown): readonly unknown[];
415
- getNodeIncomingEdges(nodeId: unknown): readonly unknown[];
416
- getNodeOutcomingEdges(nodeId: unknown): readonly unknown[];
417
- getNodeCycleEdges(nodeId: unknown): readonly unknown[];
411
+ getPortIncomingEdgeIds(portId: unknown): readonly unknown[];
412
+ getPortOutcomingEdgeIds(portId: unknown): readonly unknown[];
413
+ getPortCycleEdgeIds(portId: unknown): readonly unknown[];
414
+ getPortAdjacentEdgeIds(portId: unknown): readonly unknown[];
415
+ getNodeIncomingEdgeIds(nodeId: unknown): readonly unknown[];
416
+ getNodeOutcomingEdgeIds(nodeId: unknown): readonly unknown[];
417
+ getNodeCycleEdgeIds(nodeId: unknown): readonly unknown[];
418
+ getNodeAdjacentEdgeIds(nodeId: unknown): readonly unknown[];
418
419
  }
419
420
 
420
421
  export declare class HorizontalEdgeShape implements EdgeShape {
421
- private readonly color;
422
- private readonly width;
423
422
  private readonly arrowLength;
424
423
  private readonly arrowWidth;
425
424
  private readonly arrowOffset;
@@ -430,7 +429,7 @@ export declare class HorizontalEdgeShape implements EdgeShape {
430
429
  private readonly sourceArrow;
431
430
  private readonly targetArrow;
432
431
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, arrowOffset: number, hasSourceArrow: boolean, hasTargetArrow: boolean, roundness: number);
433
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
432
+ update(x: number, y: number, width: number, height: number, from: GraphPort, to: GraphPort): void;
434
433
  }
435
434
 
436
435
  declare interface HorizontalEdgeShape_2 {
@@ -460,6 +459,10 @@ export declare class HtmlGraphBuilder {
460
459
  build(): Canvas;
461
460
  }
462
461
 
462
+ export declare class HtmlGraphError extends Error {
463
+ readonly name = "HtmlGraphError";
464
+ }
465
+
463
466
  declare type IncrementalPriority = "incremental";
464
467
 
465
468
  export declare type MarkNodePortRequest = {
@@ -503,7 +506,7 @@ export declare interface Point {
503
506
  readonly y: number;
504
507
  }
505
508
 
506
- export declare interface PortPayload {
509
+ declare interface PortPayload {
507
510
  readonly element: HTMLElement;
508
511
  centerFn: CenterFn;
509
512
  direction: number;
@@ -516,27 +519,27 @@ export declare type PriorityFn = () => number;
516
519
  declare class PublicGraphStore {
517
520
  private readonly graphStore;
518
521
  constructor(graphStore: GraphStore);
519
- getAllNodes(): readonly unknown[];
520
- getAllPorts(): readonly unknown[];
522
+ getAllNodeIds(): readonly unknown[];
523
+ getAllPortIds(): readonly unknown[];
521
524
  getNode(nodeId: unknown): GraphNode | null;
522
- getNodePorts(nodeId: unknown): readonly unknown[] | undefined;
525
+ getNodePortIds(nodeId: unknown): readonly unknown[] | undefined;
523
526
  getPort(portId: unknown): GraphPort | null;
524
- getPortNode(portId: string): unknown | null;
525
- getAllEdges(): readonly unknown[];
527
+ getPortNodeId(portId: string): unknown | null;
528
+ getAllEdgeIds(): readonly unknown[];
526
529
  getEdge(edgeId: unknown): GraphEdge | null;
527
- getPortAdjacentEdges(portId: string): readonly unknown[];
528
- getNodeAdjacentEdges(nodeId: unknown): readonly unknown[];
529
- getPortIncomingEdges(portId: unknown): readonly unknown[];
530
- getPortOutcomingEdges(portId: unknown): readonly unknown[];
531
- getPortCycleEdges(portId: unknown): readonly unknown[];
532
- getNodeIncomingEdges(nodeId: unknown): readonly unknown[];
533
- getNodeOutcomingEdges(nodeId: unknown): readonly unknown[];
534
- getNodeCycleEdges(nodeId: unknown): readonly unknown[];
530
+ getPortAdjacentEdgeIds(portId: string): readonly unknown[];
531
+ getNodeAdjacentEdgeIds(nodeId: unknown): readonly unknown[];
532
+ getPortIncomingEdgeIds(portId: unknown): readonly unknown[];
533
+ getPortOutcomingEdgeIds(portId: unknown): readonly unknown[];
534
+ getPortCycleEdgeIds(portId: unknown): readonly unknown[];
535
+ getNodeIncomingEdgeIds(nodeId: unknown): readonly unknown[];
536
+ getNodeOutcomingEdgeIds(nodeId: unknown): readonly unknown[];
537
+ getNodeCycleEdgeIds(nodeId: unknown): readonly unknown[];
535
538
  }
536
539
 
537
540
  export declare class PublicViewportTransformer {
538
541
  private readonly transformer;
539
- constructor(transformer: ViewportTransformer);
542
+ constructor(transformer: AbstractViewportTransformer);
540
543
  getViewportMatrix(): TransformState;
541
544
  getContentMatrix(): TransformState;
542
545
  }
@@ -544,8 +547,6 @@ export declare class PublicViewportTransformer {
544
547
  declare type SharedIncrementalPriority = "shared-incremental";
545
548
 
546
549
  export declare class StraightEdgeShape implements EdgeShape {
547
- private readonly color;
548
- private readonly width;
549
550
  private readonly arrowLength;
550
551
  private readonly arrowWidth;
551
552
  private readonly arrowOffset;
@@ -556,7 +557,7 @@ export declare class StraightEdgeShape implements EdgeShape {
556
557
  private readonly sourceArrow;
557
558
  private readonly targetArrow;
558
559
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, arrowOffset: number, hasSourceArrow: boolean, hasTargetArrow: boolean, roundness: number);
559
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
560
+ update(x: number, y: number, width: number, height: number, from: GraphPort, to: GraphPort): void;
560
561
  }
561
562
 
562
563
  declare interface StraightEdgeShape_2 {
@@ -583,6 +584,7 @@ export declare interface TransformOptions {
583
584
  };
584
585
  readonly shift?: {
585
586
  readonly enabled?: boolean;
587
+ readonly cursor?: string | null;
586
588
  };
587
589
  readonly transformPreprocessor?: TransformPreprocessorOption | TransformPreprocessorOption[];
588
590
  readonly events?: {
@@ -655,6 +657,7 @@ export declare class UserDraggableNodesCanvas implements Canvas {
655
657
  private previousTouchCoords;
656
658
  private readonly freezePriority;
657
659
  private readonly window;
660
+ private readonly dragCursor;
658
661
  constructor(canvas: Canvas, dragOptions?: DragOptions);
659
662
  addNode(request: AddNodeRequest): UserDraggableNodesCanvas;
660
663
  updateNode(nodeId: unknown, request: UpdateNodeRequest): UserDraggableNodesCanvas;
@@ -701,6 +704,7 @@ export declare class UserTransformableCanvas implements Canvas {
701
704
  private readonly onTouchMove;
702
705
  private readonly onTouchEnd;
703
706
  private readonly observer;
707
+ private readonly shiftCursor;
704
708
  constructor(canvas: Canvas, options?: TransformOptions | undefined);
705
709
  addNode(node: AddNodeRequest): UserTransformableCanvas;
706
710
  updateNode(nodeId: unknown, request: UpdateNodeRequest): UserTransformableCanvas;
@@ -727,8 +731,6 @@ export declare class UserTransformableCanvas implements Canvas {
727
731
  }
728
732
 
729
733
  export declare class VerticalEdgeShape implements EdgeShape {
730
- private readonly color;
731
- private readonly width;
732
734
  private readonly arrowLength;
733
735
  private readonly arrowWidth;
734
736
  private readonly arrowOffset;
@@ -739,7 +741,7 @@ export declare class VerticalEdgeShape implements EdgeShape {
739
741
  private readonly sourceArrow;
740
742
  private readonly targetArrow;
741
743
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, arrowOffset: number, hasSourceArrow: boolean, hasTargetArrow: boolean, roundness: number);
742
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
744
+ update(x: number, y: number, width: number, height: number, from: GraphPort, to: GraphPort): void;
743
745
  }
744
746
 
745
747
  declare interface VerticalEdgeShape_2 {
@@ -757,14 +759,4 @@ declare interface VerticalEdgeShape_2 {
757
759
  readonly detourDirection?: number;
758
760
  }
759
761
 
760
- declare class ViewportTransformer {
761
- private viewportMatrix;
762
- private contentMatrix;
763
- getViewportMatrix(): TransformState;
764
- getContentMatrix(): TransformState;
765
- patchViewportMatrix(scale: number | null, x: number | null, y: number | null): void;
766
- patchContentMatrix(scale: number | null, dx: number | null, dy: number | null): void;
767
- private calculateReverseMatrix;
768
- }
769
-
770
762
  export { }