Skip to content

Commit 95e2658

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

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ 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.select(".links")
149147
.selectAll(".link")
150148
.data(tree.links(), (d: any) => d.source?.data?.id + d.target?.data?.id)
151149
.join("path")
@@ -155,7 +153,7 @@ export const TopologyView: React.FC<TopologyViewProps> = ({
155153
.attr("d", diagonal)
156154
.attr("stroke-width", 1.5);
157155

158-
gNodes
156+
group.select(".nodes")
159157
.selectAll(".node")
160158
.data(tree.descendants(), (d: any) => d.data.id)
161159
.join("circle")
@@ -165,6 +163,17 @@ export const TopologyView: React.FC<TopologyViewProps> = ({
165163
.attr("cy", (d: any) => d.y)
166164
.attr("r", d => getRadius(d.data.group))
167165
.attr("fill", d => colors.assign(d.data.group));
166+
167+
group.select(".texts")
168+
.selectAll(".text")
169+
.data(tree.descendants(), (d: any) => d.data.id)
170+
.join("text")
171+
.filter(d => d.data.group !== "room" && d.data.group !== "client")
172+
.attr("class", "text")
173+
.text(d => d.data.id.substring(0, 6))
174+
.attr("x", (d: any) => d.x)
175+
.attr("y", (d: any) => d.y)
176+
.attr("font-size", 10)
168177
});
169178
}
170179

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)