Skip to content

Commit

Permalink
vis: TopologyView: add text labels to nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Apr 5, 2024
1 parent d2123fc commit 02532b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/ott-vis-panel/src/components/views/TopologyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ export const TopologyView: React.FC<TopologyViewProps> = ({
.each(function (subtree) {
const tree = subtree.tree;
const group = d3.select(this);
const gLinks = group.select(".links");
const gNodes = group.select(".nodes");
gLinks
group.select(".links")
.selectAll(".link")
.data(tree.links(), (d: any) => d.source?.data?.id + d.target?.data?.id)
.join("path")
Expand All @@ -155,7 +153,7 @@ export const TopologyView: React.FC<TopologyViewProps> = ({
.attr("d", diagonal)
.attr("stroke-width", 1.5);

gNodes
group.select(".nodes")
.selectAll(".node")
.data(tree.descendants(), (d: any) => d.data.id)
.join("circle")
Expand All @@ -165,6 +163,17 @@ export const TopologyView: React.FC<TopologyViewProps> = ({
.attr("cy", (d: any) => d.y)
.attr("r", d => getRadius(d.data.group))
.attr("fill", d => colors.assign(d.data.group));

group.select(".texts")
.selectAll(".text")
.data(tree.descendants(), (d: any) => d.data.id)
.join("text")
.filter(d => d.data.group !== "room" && d.data.group !== "client")
.attr("class", "text")
.text(d => d.data.id.substring(0, 6))
.attr("x", (d: any) => d.x)
.attr("y", (d: any) => d.y)
.attr("font-size", 10)
});
}

Expand Down
8 changes: 8 additions & 0 deletions packages/ott-vis-panel/src/components/views/topology-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
stroke-width: 1.5;
}

.text {
font-family: Inter, Helvetica, Arial, sans-serif;
text-anchor: middle;
alignment-baseline: middle;
stroke-width: 0;
fill: white;
}

.region {
fill: rgba(255, 255, 255, 0.1);
stroke: white;
Expand Down

0 comments on commit 02532b0

Please sign in to comment.