-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
133 lines (126 loc) · 2.4 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import {
ArrowHead,
Dir,
DirectedGraph,
EdgeStyle,
LabelPos,
RankDir,
Shape,
VertexStyle,
} from "@vizdom/vizdom-ts-node";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const graph = new DirectedGraph({
layout: {
// Change the direction of the ranked graph
edge_sep: 75,
rank_dir: RankDir.TB,
},
render: {
bg_color: "whitesmoke",
},
});
const v0 = graph.new_vertex({
render: {
label: "Foo",
color: "#ff2f8e",
fill_color: "#ff2f8eaa",
shape: Shape.Triangle,
style: VertexStyle.Dashed,
},
});
const v1 = graph.new_vertex({
render: {
label: "Bar",
pen_width: 2,
color: "#ff9e4c",
fill_color: "#ff9e4caa",
font_size: 20,
shape: Shape.Diamond,
},
});
const v2 = graph.new_vertex({
render: {
label: "Baz",
pen_width: 2,
color: "#ffd600",
fill_color: "#ffd600aa",
font_size: 20,
shape: Shape.Circle,
},
});
const v3 = graph.new_vertex({
render: {
label: "Qux",
color: "#66df48",
fill_color: "#66df48aa",
shape: Shape.Square,
},
});
graph.new_edge(v0, v1, {
layout: {
label_pos: LabelPos.R,
},
render: {
label: "An underlined edge",
shape: Shape.Underline,
pen_width: 2,
color: "#6a77dd",
font_color: "#6a77dd",
},
});
graph.new_edge(v1, v2, {
layout: {
label_pos: LabelPos.R,
},
render: {
label: "A backwards arrow",
dir: Dir.Back,
color: "#ffd600",
},
});
graph.new_edge(v0, v2, {
layout: {
label_pos: LabelPos.C,
},
render: {
label: "A boxed, centered,\nfilled, edge",
shape: Shape.Rectangle,
color: "#ff2f8e",
fill_color: "#ff2f8eaa",
font_color: "white",
style: EdgeStyle.Dotted,
},
});
graph.new_edge(v0, v3, {
layout: {
label_pos: LabelPos.R,
},
render: {
label: "A cycle!",
font_size: 20,
color: "#9803ce",
font_color: "#9803ceaa",
},
});
graph.new_edge(v3, v0, {
layout: {
label_pos: LabelPos.L,
},
render: {
label: "No arrowheads",
style: EdgeStyle.Dashed,
color: "#66df48",
font_color: "#66df48",
arrow_head: ArrowHead.None,
},
});
const positionted = graph.layout();
const svg = positionted.to_svg();
await fs.writeFile(
path.join(__dirname, "graph.svg"),
svg.with_width_and_height().to_string()
);