Skip to content

Commit b9d7f9e

Browse files
committed
vis: TopologyView: add text labels to nodes
1 parent d4df97e commit b9d7f9e

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

packages/ott-vis-panel/src/components/views/TopologyView.tsx

+16-4
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ export const TopologyView: React.FC<TopologyViewProps> = ({
143143
.each(function (subtree) {
144144
const tree = subtree.tree;
145145
const group = d3.select(this);
146-
const gLinks = group.select(".links");
147-
const gNodes = group.select(".nodes");
148-
gLinks
146+
group
147+
.select(".links")
149148
.selectAll(".link")
150149
.data(tree.links(), (d: any) => d.source?.data?.id + d.target?.data?.id)
151150
.join("path")
@@ -155,7 +154,8 @@ export const TopologyView: React.FC<TopologyViewProps> = ({
155154
.attr("d", diagonal)
156155
.attr("stroke-width", 1.5);
157156

158-
gNodes
157+
group
158+
.select(".nodes")
159159
.selectAll(".node")
160160
.data(tree.descendants(), (d: any) => d.data.id)
161161
.join("circle")
@@ -165,6 +165,18 @@ export const TopologyView: React.FC<TopologyViewProps> = ({
165165
.attr("cy", (d: any) => d.y)
166166
.attr("r", d => getRadius(d.data.group))
167167
.attr("fill", d => colors.assign(d.data.group));
168+
169+
group
170+
.select(".texts")
171+
.selectAll(".text")
172+
.data(tree.descendants(), (d: any) => d.data.id)
173+
.join("text")
174+
.filter(d => d.data.group !== "room" && d.data.group !== "client")
175+
.attr("class", "text")
176+
.text(d => d.data.id.substring(0, 6))
177+
.attr("x", (d: any) => d.x)
178+
.attr("y", (d: any) => d.y)
179+
.attr("font-size", 10);
168180
});
169181
}
170182

packages/ott-vis-panel/src/components/views/topology-view.css

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
stroke-width: 1.5;
1010
}
1111

12+
.text {
13+
font-family: Inter, Helvetica, Arial, sans-serif;
14+
text-anchor: middle;
15+
alignment-baseline: middle;
16+
stroke-width: 0;
17+
fill: white;
18+
}
19+
1220
.region {
1321
fill: rgba(255, 255, 255, 0.1);
1422
stroke: white;

0 commit comments

Comments
 (0)