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