@ts-graphviz/core 0.0.0-next-20240301111950
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/CHANGELOG.md +301 -0
- package/LICENSE +22 -0
- package/README.md +47 -0
- package/lib/AttributeList.cjs +14 -0
- package/lib/AttributeList.d.ts +43 -0
- package/lib/AttributeList.js +14 -0
- package/lib/AttributesBase.cjs +40 -0
- package/lib/AttributesBase.d.ts +30 -0
- package/lib/AttributesBase.js +40 -0
- package/lib/AttributesGroup.cjs +7 -0
- package/lib/AttributesGroup.d.ts +39 -0
- package/lib/AttributesGroup.js +7 -0
- package/lib/Digraph.cjs +9 -0
- package/lib/Digraph.d.ts +107 -0
- package/lib/Digraph.js +9 -0
- package/lib/DotObject.cjs +5 -0
- package/lib/DotObject.d.ts +8 -0
- package/lib/DotObject.js +5 -0
- package/lib/Edge.cjs +23 -0
- package/lib/Edge.d.ts +26 -0
- package/lib/Edge.js +23 -0
- package/lib/Graph.cjs +9 -0
- package/lib/Graph.d.ts +107 -0
- package/lib/Graph.js +9 -0
- package/lib/GraphBase.cjs +152 -0
- package/lib/GraphBase.d.ts +81 -0
- package/lib/GraphBase.js +152 -0
- package/lib/Node.cjs +23 -0
- package/lib/Node.d.ts +64 -0
- package/lib/Node.js +23 -0
- package/lib/RootGraph.cjs +22 -0
- package/lib/RootGraph.d.ts +99 -0
- package/lib/RootGraph.js +22 -0
- package/lib/Subgraph.cjs +26 -0
- package/lib/Subgraph.d.ts +95 -0
- package/lib/Subgraph.js +26 -0
- package/lib/core.cjs +26 -0
- package/lib/core.d.ts +590 -0
- package/lib/core.js +26 -0
- package/lib/register-default.cjs +18 -0
- package/lib/register-default.d.ts +3 -0
- package/lib/register-default.js +18 -0
- package/package.json +76 -0
package/lib/GraphBase.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { RootModelsContext, createModelsContext, isNodeRefGroupLike, toNodeRefGroup, toNodeRef } from "@ts-graphviz/common";
|
|
2
|
+
import { AttributeList } from "./AttributeList.js";
|
|
3
|
+
import { AttributesBase } from "./AttributesBase.js";
|
|
4
|
+
class GraphBase extends AttributesBase {
|
|
5
|
+
/** @hidden */
|
|
6
|
+
#models = RootModelsContext;
|
|
7
|
+
id;
|
|
8
|
+
comment;
|
|
9
|
+
attributes = Object.freeze({
|
|
10
|
+
graph: new AttributeList("Graph"),
|
|
11
|
+
edge: new AttributeList("Edge"),
|
|
12
|
+
node: new AttributeList("Node")
|
|
13
|
+
});
|
|
14
|
+
get nodes() {
|
|
15
|
+
return Array.from(this.#objects.nodes.values());
|
|
16
|
+
}
|
|
17
|
+
get edges() {
|
|
18
|
+
return Array.from(this.#objects.edges.values());
|
|
19
|
+
}
|
|
20
|
+
get subgraphs() {
|
|
21
|
+
return Array.from(this.#objects.subgraphs.values());
|
|
22
|
+
}
|
|
23
|
+
/** @hidden */
|
|
24
|
+
#objects = {
|
|
25
|
+
nodes: /* @__PURE__ */ new Map(),
|
|
26
|
+
edges: /* @__PURE__ */ new Set(),
|
|
27
|
+
subgraphs: /* @__PURE__ */ new Set()
|
|
28
|
+
};
|
|
29
|
+
with(models) {
|
|
30
|
+
this.#models = createModelsContext(models);
|
|
31
|
+
}
|
|
32
|
+
addNode(node) {
|
|
33
|
+
this.#objects.nodes.set(node.id, node);
|
|
34
|
+
}
|
|
35
|
+
addEdge(edge) {
|
|
36
|
+
this.#objects.edges.add(edge);
|
|
37
|
+
}
|
|
38
|
+
addSubgraph(subgraph) {
|
|
39
|
+
this.#objects.subgraphs.add(subgraph);
|
|
40
|
+
}
|
|
41
|
+
existNode(nodeId) {
|
|
42
|
+
return this.#objects.nodes.has(nodeId);
|
|
43
|
+
}
|
|
44
|
+
existEdge(edge) {
|
|
45
|
+
return this.#objects.edges.has(edge);
|
|
46
|
+
}
|
|
47
|
+
existSubgraph(subgraph) {
|
|
48
|
+
return this.#objects.subgraphs.has(subgraph);
|
|
49
|
+
}
|
|
50
|
+
createSubgraph(...args) {
|
|
51
|
+
const subgraph = new this.#models.Subgraph(...args);
|
|
52
|
+
subgraph.with(this.#models);
|
|
53
|
+
this.addSubgraph(subgraph);
|
|
54
|
+
return subgraph;
|
|
55
|
+
}
|
|
56
|
+
removeNode(node) {
|
|
57
|
+
this.#objects.nodes.delete(typeof node === "string" ? node : node.id);
|
|
58
|
+
}
|
|
59
|
+
removeEdge(edge) {
|
|
60
|
+
this.#objects.edges.delete(edge);
|
|
61
|
+
}
|
|
62
|
+
removeSubgraph(subgraph) {
|
|
63
|
+
this.#objects.subgraphs.delete(subgraph);
|
|
64
|
+
}
|
|
65
|
+
createNode(id, attributes) {
|
|
66
|
+
const node = new this.#models.Node(id, attributes);
|
|
67
|
+
this.addNode(node);
|
|
68
|
+
return node;
|
|
69
|
+
}
|
|
70
|
+
getSubgraph(id) {
|
|
71
|
+
return Array.from(this.#objects.subgraphs.values()).find(
|
|
72
|
+
(subgraph) => subgraph.id === id
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
getNode(id) {
|
|
76
|
+
return this.#objects.nodes.get(id);
|
|
77
|
+
}
|
|
78
|
+
createEdge(targets, attributes) {
|
|
79
|
+
const ts = targets.map(
|
|
80
|
+
(t) => isNodeRefGroupLike(t) ? toNodeRefGroup(t) : toNodeRef(t)
|
|
81
|
+
);
|
|
82
|
+
const edge = new this.#models.Edge(ts, attributes);
|
|
83
|
+
this.addEdge(edge);
|
|
84
|
+
return edge;
|
|
85
|
+
}
|
|
86
|
+
subgraph(...args) {
|
|
87
|
+
const id = args.find(
|
|
88
|
+
(arg) => typeof arg === "string"
|
|
89
|
+
);
|
|
90
|
+
const attributes = args.find(
|
|
91
|
+
(arg) => typeof arg === "object" && arg !== null
|
|
92
|
+
);
|
|
93
|
+
const callback = args.find(
|
|
94
|
+
(arg) => typeof arg === "function"
|
|
95
|
+
);
|
|
96
|
+
const subgraph = id ? this.getSubgraph(id) ?? this.createSubgraph(id) : this.createSubgraph();
|
|
97
|
+
if (attributes !== void 0) {
|
|
98
|
+
subgraph.apply(attributes);
|
|
99
|
+
}
|
|
100
|
+
if (callback !== void 0) {
|
|
101
|
+
callback(subgraph);
|
|
102
|
+
}
|
|
103
|
+
return subgraph;
|
|
104
|
+
}
|
|
105
|
+
node(firstArg, ...args) {
|
|
106
|
+
if (typeof firstArg === "string") {
|
|
107
|
+
const id = firstArg;
|
|
108
|
+
const attributes = args.find(
|
|
109
|
+
(arg) => typeof arg === "object" && arg !== null
|
|
110
|
+
);
|
|
111
|
+
const callback = args.find(
|
|
112
|
+
(arg) => typeof arg === "function"
|
|
113
|
+
);
|
|
114
|
+
const node = this.getNode(id) ?? this.createNode(id);
|
|
115
|
+
if (attributes !== void 0) {
|
|
116
|
+
node.attributes.apply(attributes);
|
|
117
|
+
}
|
|
118
|
+
if (callback !== void 0) {
|
|
119
|
+
callback(node);
|
|
120
|
+
}
|
|
121
|
+
return node;
|
|
122
|
+
}
|
|
123
|
+
if (typeof firstArg === "object" && firstArg !== null) {
|
|
124
|
+
this.attributes.node.apply(firstArg);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
edge(firstArg, ...args) {
|
|
128
|
+
if (Array.isArray(firstArg)) {
|
|
129
|
+
const targets = firstArg;
|
|
130
|
+
const attributes = args.find(
|
|
131
|
+
(arg) => typeof arg === "object"
|
|
132
|
+
);
|
|
133
|
+
const callback = args.find(
|
|
134
|
+
(arg) => typeof arg === "function"
|
|
135
|
+
);
|
|
136
|
+
const edge = this.createEdge(targets, attributes);
|
|
137
|
+
if (callback !== void 0) {
|
|
138
|
+
callback(edge);
|
|
139
|
+
}
|
|
140
|
+
return edge;
|
|
141
|
+
}
|
|
142
|
+
if (typeof firstArg === "object" && firstArg !== null) {
|
|
143
|
+
this.attributes.edge.apply(firstArg);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
graph(attributes) {
|
|
147
|
+
this.attributes.graph.apply(attributes);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export {
|
|
151
|
+
GraphBase
|
|
152
|
+
};
|
package/lib/Node.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const AttributesGroup = require("./AttributesGroup.cjs");
|
|
4
|
+
const DotObject = require("./DotObject.cjs");
|
|
5
|
+
class Node extends DotObject.DotObject {
|
|
6
|
+
constructor(id, attributes) {
|
|
7
|
+
super();
|
|
8
|
+
this.id = id;
|
|
9
|
+
this.attributes = new AttributesGroup.AttributesGroup(attributes);
|
|
10
|
+
}
|
|
11
|
+
get $$type() {
|
|
12
|
+
return "Node";
|
|
13
|
+
}
|
|
14
|
+
comment;
|
|
15
|
+
attributes;
|
|
16
|
+
port(port) {
|
|
17
|
+
if (typeof port === "string") {
|
|
18
|
+
return { id: this.id, port };
|
|
19
|
+
}
|
|
20
|
+
return { id: this.id, ...port };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.Node = Node;
|
package/lib/Node.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Attribute } from '@ts-graphviz/common';
|
|
2
|
+
import { AttributeKey } from '@ts-graphviz/common';
|
|
3
|
+
import { Attributes } from '@ts-graphviz/common';
|
|
4
|
+
import { AttributesEntities } from '@ts-graphviz/common';
|
|
5
|
+
import { AttributesGroupModel } from '@ts-graphviz/common';
|
|
6
|
+
import { AttributesObject } from '@ts-graphviz/common';
|
|
7
|
+
import { ForwardRefNode } from '@ts-graphviz/common';
|
|
8
|
+
import { NodeAttributeKey } from '@ts-graphviz/common';
|
|
9
|
+
import { NodeAttributesObject } from '@ts-graphviz/common';
|
|
10
|
+
import { NodeModel } from '@ts-graphviz/common';
|
|
11
|
+
import { Port } from '@ts-graphviz/common';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Base class for DOT objects with attributes.
|
|
15
|
+
* @group Models
|
|
16
|
+
*/
|
|
17
|
+
declare abstract class AttributesBase<T extends AttributeKey> extends DotObject_2 implements Attributes<T> {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(attributes?: AttributesObject<T>);
|
|
20
|
+
get values(): ReadonlyArray<[T, Attribute<T>]>;
|
|
21
|
+
get size(): number;
|
|
22
|
+
get<K extends T>(key: K): Attribute<K> | undefined;
|
|
23
|
+
set<K extends T>(key: K, value: Attribute<K>): void;
|
|
24
|
+
delete(key: T): void;
|
|
25
|
+
apply(attributes: AttributesObject<T> | AttributesEntities<T>): void;
|
|
26
|
+
clear(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A set of attribute values for any object.
|
|
31
|
+
* @group Models
|
|
32
|
+
*/
|
|
33
|
+
declare class AttributesGroup<T extends AttributeKey = AttributeKey> extends AttributesBase<T> implements AttributesGroupModel<T> {
|
|
34
|
+
comment?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Base class for DOT objects.
|
|
39
|
+
* @group Models
|
|
40
|
+
*/
|
|
41
|
+
declare abstract class DotObject {
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Base class for DOT objects.
|
|
46
|
+
* @group Models
|
|
47
|
+
*/
|
|
48
|
+
declare abstract class DotObject_2 {
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* DOT object class representing a node.
|
|
53
|
+
* @group Models
|
|
54
|
+
*/
|
|
55
|
+
export declare class Node extends DotObject implements NodeModel {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
get $$type(): 'Node';
|
|
58
|
+
comment?: string;
|
|
59
|
+
readonly attributes: AttributesGroup<NodeAttributeKey>;
|
|
60
|
+
constructor(id: string, attributes?: NodeAttributesObject);
|
|
61
|
+
port(port: string | Partial<Port>): ForwardRefNode;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { }
|
package/lib/Node.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AttributesGroup } from "./AttributesGroup.js";
|
|
2
|
+
import { DotObject } from "./DotObject.js";
|
|
3
|
+
class Node extends DotObject {
|
|
4
|
+
constructor(id, attributes) {
|
|
5
|
+
super();
|
|
6
|
+
this.id = id;
|
|
7
|
+
this.attributes = new AttributesGroup(attributes);
|
|
8
|
+
}
|
|
9
|
+
get $$type() {
|
|
10
|
+
return "Node";
|
|
11
|
+
}
|
|
12
|
+
comment;
|
|
13
|
+
attributes;
|
|
14
|
+
port(port) {
|
|
15
|
+
if (typeof port === "string") {
|
|
16
|
+
return { id: this.id, port };
|
|
17
|
+
}
|
|
18
|
+
return { id: this.id, ...port };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
Node
|
|
23
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const GraphBase = require("./GraphBase.cjs");
|
|
4
|
+
class RootGraph extends GraphBase.GraphBase {
|
|
5
|
+
get $$type() {
|
|
6
|
+
return "Graph";
|
|
7
|
+
}
|
|
8
|
+
id;
|
|
9
|
+
strict;
|
|
10
|
+
constructor(...args) {
|
|
11
|
+
super();
|
|
12
|
+
this.id = args.find((arg) => typeof arg === "string");
|
|
13
|
+
this.strict = args.find((arg) => typeof arg === "boolean") ?? false;
|
|
14
|
+
const attributes = args.find(
|
|
15
|
+
(arg) => typeof arg === "object" && arg !== null
|
|
16
|
+
);
|
|
17
|
+
if (attributes !== void 0) {
|
|
18
|
+
this.apply(attributes);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.RootGraph = RootGraph;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Attribute } from '@ts-graphviz/common';
|
|
2
|
+
import { AttributeKey } from '@ts-graphviz/common';
|
|
3
|
+
import { Attributes } from '@ts-graphviz/common';
|
|
4
|
+
import { AttributesEntities } from '@ts-graphviz/common';
|
|
5
|
+
import { AttributesObject } from '@ts-graphviz/common';
|
|
6
|
+
import { EdgeAttributesObject } from '@ts-graphviz/common';
|
|
7
|
+
import { EdgeModel } from '@ts-graphviz/common';
|
|
8
|
+
import { EdgeTargetLikeTuple } from '@ts-graphviz/common';
|
|
9
|
+
import { GraphAttributeKey } from '@ts-graphviz/common';
|
|
10
|
+
import { GraphAttributesObject } from '@ts-graphviz/common';
|
|
11
|
+
import { GraphBaseModel } from '@ts-graphviz/common';
|
|
12
|
+
import { GraphCommonAttributes } from '@ts-graphviz/common';
|
|
13
|
+
import { ModelsContext } from '@ts-graphviz/common';
|
|
14
|
+
import { NodeAttributesObject } from '@ts-graphviz/common';
|
|
15
|
+
import { NodeModel } from '@ts-graphviz/common';
|
|
16
|
+
import { RootGraphModel } from '@ts-graphviz/common';
|
|
17
|
+
import { SubgraphAttributesObject } from '@ts-graphviz/common';
|
|
18
|
+
import { SubgraphModel } from '@ts-graphviz/common';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Base class for DOT objects with attributes.
|
|
22
|
+
* @group Models
|
|
23
|
+
*/
|
|
24
|
+
declare abstract class AttributesBase<T extends AttributeKey> extends DotObject implements Attributes<T> {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(attributes?: AttributesObject<T>);
|
|
27
|
+
get values(): ReadonlyArray<[T, Attribute<T>]>;
|
|
28
|
+
get size(): number;
|
|
29
|
+
get<K extends T>(key: K): Attribute<K> | undefined;
|
|
30
|
+
set<K extends T>(key: K, value: Attribute<K>): void;
|
|
31
|
+
delete(key: T): void;
|
|
32
|
+
apply(attributes: AttributesObject<T> | AttributesEntities<T>): void;
|
|
33
|
+
clear(): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Base class for DOT objects.
|
|
38
|
+
* @group Models
|
|
39
|
+
*/
|
|
40
|
+
declare abstract class DotObject {
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Base class for Graph objects.
|
|
45
|
+
* @group Models
|
|
46
|
+
*/
|
|
47
|
+
declare abstract class GraphBase<T extends AttributeKey> extends AttributesBase<T> implements GraphBaseModel<T> {
|
|
48
|
+
#private;
|
|
49
|
+
readonly id?: string;
|
|
50
|
+
comment?: string;
|
|
51
|
+
readonly attributes: Readonly<GraphCommonAttributes>;
|
|
52
|
+
get nodes(): ReadonlyArray<NodeModel>;
|
|
53
|
+
get edges(): ReadonlyArray<EdgeModel>;
|
|
54
|
+
get subgraphs(): ReadonlyArray<SubgraphModel>;
|
|
55
|
+
with(models: Partial<ModelsContext>): void;
|
|
56
|
+
addNode(node: NodeModel): void;
|
|
57
|
+
addEdge(edge: EdgeModel): void;
|
|
58
|
+
addSubgraph(subgraph: SubgraphModel): void;
|
|
59
|
+
existNode(nodeId: string): boolean;
|
|
60
|
+
existEdge(edge: EdgeModel): boolean;
|
|
61
|
+
existSubgraph(subgraph: SubgraphModel): boolean;
|
|
62
|
+
createSubgraph(id?: string, attributes?: SubgraphAttributesObject): SubgraphModel;
|
|
63
|
+
createSubgraph(attributes?: SubgraphAttributesObject): SubgraphModel;
|
|
64
|
+
removeNode(node: NodeModel | string): void;
|
|
65
|
+
removeEdge(edge: EdgeModel): void;
|
|
66
|
+
removeSubgraph(subgraph: SubgraphModel): void;
|
|
67
|
+
createNode(id: string, attributes?: NodeAttributesObject): NodeModel;
|
|
68
|
+
getSubgraph(id: string): SubgraphModel | undefined;
|
|
69
|
+
getNode(id: string): NodeModel | undefined;
|
|
70
|
+
createEdge(targets: EdgeTargetLikeTuple, attributes?: EdgeAttributesObject): EdgeModel;
|
|
71
|
+
subgraph(id: string, callback?: (subgraph: SubgraphModel) => void): SubgraphModel;
|
|
72
|
+
subgraph(id: string, attributes: SubgraphAttributesObject, callback?: (subgraph: SubgraphModel) => void): SubgraphModel;
|
|
73
|
+
subgraph(attributes: SubgraphAttributesObject, callback?: (subgraph: SubgraphModel) => void): SubgraphModel;
|
|
74
|
+
subgraph(callback?: (subgraph: SubgraphModel) => void): SubgraphModel;
|
|
75
|
+
node(id: string, callback?: (node: NodeModel) => void): NodeModel;
|
|
76
|
+
node(id: string, attributes: NodeAttributesObject, callback?: (node: NodeModel) => void): NodeModel;
|
|
77
|
+
node(attributes: NodeAttributesObject): void;
|
|
78
|
+
edge(targets: EdgeTargetLikeTuple, callback?: (edge: EdgeModel) => void): EdgeModel;
|
|
79
|
+
edge(targets: EdgeTargetLikeTuple, attributes: EdgeAttributesObject, callback?: (edge: EdgeModel) => void): EdgeModel;
|
|
80
|
+
edge(attributes: EdgeAttributesObject): void;
|
|
81
|
+
graph(attributes: SubgraphAttributesObject): void;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Base class representing a root graph(digraph, graph).
|
|
86
|
+
* @group Models
|
|
87
|
+
*/
|
|
88
|
+
export declare abstract class RootGraph extends GraphBase<GraphAttributeKey> implements RootGraphModel {
|
|
89
|
+
get $$type(): 'Graph';
|
|
90
|
+
readonly id?: string;
|
|
91
|
+
abstract readonly directed: boolean;
|
|
92
|
+
strict: boolean;
|
|
93
|
+
constructor(id?: string, attributes?: GraphAttributesObject);
|
|
94
|
+
constructor(id?: string, strict?: boolean, attributes?: GraphAttributesObject);
|
|
95
|
+
constructor(strict?: boolean, attributes?: GraphAttributesObject);
|
|
96
|
+
constructor(attributes?: GraphAttributesObject);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { }
|
package/lib/RootGraph.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GraphBase } from "./GraphBase.js";
|
|
2
|
+
class RootGraph extends GraphBase {
|
|
3
|
+
get $$type() {
|
|
4
|
+
return "Graph";
|
|
5
|
+
}
|
|
6
|
+
id;
|
|
7
|
+
strict;
|
|
8
|
+
constructor(...args) {
|
|
9
|
+
super();
|
|
10
|
+
this.id = args.find((arg) => typeof arg === "string");
|
|
11
|
+
this.strict = args.find((arg) => typeof arg === "boolean") ?? false;
|
|
12
|
+
const attributes = args.find(
|
|
13
|
+
(arg) => typeof arg === "object" && arg !== null
|
|
14
|
+
);
|
|
15
|
+
if (attributes !== void 0) {
|
|
16
|
+
this.apply(attributes);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
RootGraph
|
|
22
|
+
};
|
package/lib/Subgraph.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const GraphBase = require("./GraphBase.cjs");
|
|
4
|
+
class Subgraph extends GraphBase.GraphBase {
|
|
5
|
+
get $$type() {
|
|
6
|
+
return "Subgraph";
|
|
7
|
+
}
|
|
8
|
+
id;
|
|
9
|
+
constructor(...args) {
|
|
10
|
+
super();
|
|
11
|
+
this.id = args.find((arg) => typeof arg === "string");
|
|
12
|
+
const attributes = args.find(
|
|
13
|
+
(arg) => typeof arg === "object" && arg !== null
|
|
14
|
+
);
|
|
15
|
+
if (attributes !== void 0) {
|
|
16
|
+
this.apply(attributes);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
isSubgraphCluster() {
|
|
20
|
+
if (typeof this.id === "string") {
|
|
21
|
+
return this.id.startsWith("cluster");
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.Subgraph = Subgraph;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Attribute } from '@ts-graphviz/common';
|
|
2
|
+
import { AttributeKey } from '@ts-graphviz/common';
|
|
3
|
+
import { Attributes } from '@ts-graphviz/common';
|
|
4
|
+
import { AttributesEntities } from '@ts-graphviz/common';
|
|
5
|
+
import { AttributesObject } from '@ts-graphviz/common';
|
|
6
|
+
import { ClusterSubgraphAttributeKey } from '@ts-graphviz/common';
|
|
7
|
+
import { EdgeAttributesObject } from '@ts-graphviz/common';
|
|
8
|
+
import { EdgeModel } from '@ts-graphviz/common';
|
|
9
|
+
import { EdgeTargetLikeTuple } from '@ts-graphviz/common';
|
|
10
|
+
import { GraphBaseModel } from '@ts-graphviz/common';
|
|
11
|
+
import { GraphCommonAttributes } from '@ts-graphviz/common';
|
|
12
|
+
import { ModelsContext } from '@ts-graphviz/common';
|
|
13
|
+
import { NodeAttributesObject } from '@ts-graphviz/common';
|
|
14
|
+
import { NodeModel } from '@ts-graphviz/common';
|
|
15
|
+
import { SubgraphAttributeKey } from '@ts-graphviz/common';
|
|
16
|
+
import { SubgraphAttributesObject } from '@ts-graphviz/common';
|
|
17
|
+
import { SubgraphModel } from '@ts-graphviz/common';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Base class for DOT objects with attributes.
|
|
21
|
+
* @group Models
|
|
22
|
+
*/
|
|
23
|
+
declare abstract class AttributesBase<T extends AttributeKey> extends DotObject implements Attributes<T> {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(attributes?: AttributesObject<T>);
|
|
26
|
+
get values(): ReadonlyArray<[T, Attribute<T>]>;
|
|
27
|
+
get size(): number;
|
|
28
|
+
get<K extends T>(key: K): Attribute<K> | undefined;
|
|
29
|
+
set<K extends T>(key: K, value: Attribute<K>): void;
|
|
30
|
+
delete(key: T): void;
|
|
31
|
+
apply(attributes: AttributesObject<T> | AttributesEntities<T>): void;
|
|
32
|
+
clear(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Base class for DOT objects.
|
|
37
|
+
* @group Models
|
|
38
|
+
*/
|
|
39
|
+
declare abstract class DotObject {
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Base class for Graph objects.
|
|
44
|
+
* @group Models
|
|
45
|
+
*/
|
|
46
|
+
declare abstract class GraphBase<T extends AttributeKey> extends AttributesBase<T> implements GraphBaseModel<T> {
|
|
47
|
+
#private;
|
|
48
|
+
readonly id?: string;
|
|
49
|
+
comment?: string;
|
|
50
|
+
readonly attributes: Readonly<GraphCommonAttributes>;
|
|
51
|
+
get nodes(): ReadonlyArray<NodeModel>;
|
|
52
|
+
get edges(): ReadonlyArray<EdgeModel>;
|
|
53
|
+
get subgraphs(): ReadonlyArray<SubgraphModel>;
|
|
54
|
+
with(models: Partial<ModelsContext>): void;
|
|
55
|
+
addNode(node: NodeModel): void;
|
|
56
|
+
addEdge(edge: EdgeModel): void;
|
|
57
|
+
addSubgraph(subgraph: SubgraphModel): void;
|
|
58
|
+
existNode(nodeId: string): boolean;
|
|
59
|
+
existEdge(edge: EdgeModel): boolean;
|
|
60
|
+
existSubgraph(subgraph: SubgraphModel): boolean;
|
|
61
|
+
createSubgraph(id?: string, attributes?: SubgraphAttributesObject): SubgraphModel;
|
|
62
|
+
createSubgraph(attributes?: SubgraphAttributesObject): SubgraphModel;
|
|
63
|
+
removeNode(node: NodeModel | string): void;
|
|
64
|
+
removeEdge(edge: EdgeModel): void;
|
|
65
|
+
removeSubgraph(subgraph: SubgraphModel): void;
|
|
66
|
+
createNode(id: string, attributes?: NodeAttributesObject): NodeModel;
|
|
67
|
+
getSubgraph(id: string): SubgraphModel | undefined;
|
|
68
|
+
getNode(id: string): NodeModel | undefined;
|
|
69
|
+
createEdge(targets: EdgeTargetLikeTuple, attributes?: EdgeAttributesObject): EdgeModel;
|
|
70
|
+
subgraph(id: string, callback?: (subgraph: SubgraphModel) => void): SubgraphModel;
|
|
71
|
+
subgraph(id: string, attributes: SubgraphAttributesObject, callback?: (subgraph: SubgraphModel) => void): SubgraphModel;
|
|
72
|
+
subgraph(attributes: SubgraphAttributesObject, callback?: (subgraph: SubgraphModel) => void): SubgraphModel;
|
|
73
|
+
subgraph(callback?: (subgraph: SubgraphModel) => void): SubgraphModel;
|
|
74
|
+
node(id: string, callback?: (node: NodeModel) => void): NodeModel;
|
|
75
|
+
node(id: string, attributes: NodeAttributesObject, callback?: (node: NodeModel) => void): NodeModel;
|
|
76
|
+
node(attributes: NodeAttributesObject): void;
|
|
77
|
+
edge(targets: EdgeTargetLikeTuple, callback?: (edge: EdgeModel) => void): EdgeModel;
|
|
78
|
+
edge(targets: EdgeTargetLikeTuple, attributes: EdgeAttributesObject, callback?: (edge: EdgeModel) => void): EdgeModel;
|
|
79
|
+
edge(attributes: EdgeAttributesObject): void;
|
|
80
|
+
graph(attributes: SubgraphAttributesObject): void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* DOT object class representing a subgraph.
|
|
85
|
+
* @group Models
|
|
86
|
+
*/
|
|
87
|
+
export declare class Subgraph extends GraphBase<SubgraphAttributeKey | ClusterSubgraphAttributeKey> implements SubgraphModel {
|
|
88
|
+
get $$type(): 'Subgraph';
|
|
89
|
+
readonly id?: string;
|
|
90
|
+
constructor(id?: string, attributes?: SubgraphAttributesObject);
|
|
91
|
+
constructor(attributes?: SubgraphAttributesObject);
|
|
92
|
+
isSubgraphCluster(): boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { }
|
package/lib/Subgraph.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { GraphBase } from "./GraphBase.js";
|
|
2
|
+
class Subgraph extends GraphBase {
|
|
3
|
+
get $$type() {
|
|
4
|
+
return "Subgraph";
|
|
5
|
+
}
|
|
6
|
+
id;
|
|
7
|
+
constructor(...args) {
|
|
8
|
+
super();
|
|
9
|
+
this.id = args.find((arg) => typeof arg === "string");
|
|
10
|
+
const attributes = args.find(
|
|
11
|
+
(arg) => typeof arg === "object" && arg !== null
|
|
12
|
+
);
|
|
13
|
+
if (attributes !== void 0) {
|
|
14
|
+
this.apply(attributes);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
isSubgraphCluster() {
|
|
18
|
+
if (typeof this.id === "string") {
|
|
19
|
+
return this.id.startsWith("cluster");
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
Subgraph
|
|
26
|
+
};
|
package/lib/core.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const registerDefault = require("./register-default.cjs");
|
|
4
|
+
const AttributeList = require("./AttributeList.cjs");
|
|
5
|
+
const AttributesBase = require("./AttributesBase.cjs");
|
|
6
|
+
const AttributesGroup = require("./AttributesGroup.cjs");
|
|
7
|
+
const Digraph = require("./Digraph.cjs");
|
|
8
|
+
const DotObject = require("./DotObject.cjs");
|
|
9
|
+
const Edge = require("./Edge.cjs");
|
|
10
|
+
const Graph = require("./Graph.cjs");
|
|
11
|
+
const GraphBase = require("./GraphBase.cjs");
|
|
12
|
+
const Node = require("./Node.cjs");
|
|
13
|
+
const RootGraph = require("./RootGraph.cjs");
|
|
14
|
+
const Subgraph = require("./Subgraph.cjs");
|
|
15
|
+
exports.registerDefault = registerDefault.registerDefault;
|
|
16
|
+
exports.AttributeList = AttributeList.AttributeList;
|
|
17
|
+
exports.AttributesBase = AttributesBase.AttributesBase;
|
|
18
|
+
exports.AttributesGroup = AttributesGroup.AttributesGroup;
|
|
19
|
+
exports.Digraph = Digraph.Digraph;
|
|
20
|
+
exports.DotObject = DotObject.DotObject;
|
|
21
|
+
exports.Edge = Edge.Edge;
|
|
22
|
+
exports.Graph = Graph.Graph;
|
|
23
|
+
exports.GraphBase = GraphBase.GraphBase;
|
|
24
|
+
exports.Node = Node.Node;
|
|
25
|
+
exports.RootGraph = RootGraph.RootGraph;
|
|
26
|
+
exports.Subgraph = Subgraph.Subgraph;
|