From 0791543be227e37763e0cc8302a2601552744cbb Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Fri, 1 Mar 2024 10:57:56 -0500 Subject: [PATCH] ott-vis-panel: add text to some nodes to differentiate them easier (#1432) --- .../src/components/ForceGraph.tsx | 22 ++++++++++++++++--- .../src/components/views/GlobalView.tsx | 2 ++ .../src/components/views/RegionView.tsx | 6 +++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/ott-vis-panel/src/components/ForceGraph.tsx b/packages/ott-vis-panel/src/components/ForceGraph.tsx index 1c2d74525..df3777943 100644 --- a/packages/ott-vis-panel/src/components/ForceGraph.tsx +++ b/packages/ott-vis-panel/src/components/ForceGraph.tsx @@ -21,6 +21,7 @@ export interface Node extends d3.SimulationNodeDatum { group: string; color: string; radius: number; + text?: string; } export interface Link extends d3.SimulationLinkDatum { @@ -82,12 +83,13 @@ const ForceGraph: React.FC = ({ ); useEffect(() => { - const svg = d3.select(svgRef.current).attr("style", "max-width: 100%; height: auto;"); + const svg = d3.select(svgRef.current); // Add a line for each link, and a circle for each node. const link = svg.select("g.links").selectAll("line").data(links); const node = svg.select("g.nodes").selectAll("circle").data(nodes); + const nodeText = svg.select("g.nodes").selectAll("text").data(nodes); // node.append("title").text(d => d.id); @@ -105,6 +107,7 @@ const ForceGraph: React.FC = ({ .attr("y2", d => (d.target as Node).y ?? 0); node.attr("cx", d => d.x).attr("cy", d => d.y); + nodeText.attr("x", d => d.x).attr("y", d => d.y + 4); }); // Reheat the simulation when drag starts, and fix the subject position. @@ -143,7 +146,7 @@ const ForceGraph: React.FC = ({ width={width} height={height} viewBox={`${-width / 2} ${-height / 2} ${width}, ${height}`} - style={{ height: "auto" }} + style={{ height: "auto", maxWidth: "100%" }} > {links.map((link, i) => ( @@ -152,7 +155,20 @@ const ForceGraph: React.FC = ({ {nodes.map((node, i) => ( - + <> + + + {node.text} + + ))} diff --git a/packages/ott-vis-panel/src/components/views/GlobalView.tsx b/packages/ott-vis-panel/src/components/views/GlobalView.tsx index b053bb891..64eb19608 100644 --- a/packages/ott-vis-panel/src/components/views/GlobalView.tsx +++ b/packages/ott-vis-panel/src/components/views/GlobalView.tsx @@ -19,6 +19,7 @@ function buildGraph(state: SystemState): [Node[], Link[]] { y: 0, group: "core", color: "Purple", // TODO: use color from grafana theme/panel options + text: "OTT", }; nodes.push(core); @@ -34,6 +35,7 @@ function buildGraph(state: SystemState): [Node[], Link[]] { y: 0, group: "monolith", color: "Red", // TODO: use color from grafana theme/panel options + text: monolith.substring(0, 6), }; nodes.push(monolithNode); monoliths.push(monolithNode); diff --git a/packages/ott-vis-panel/src/components/views/RegionView.tsx b/packages/ott-vis-panel/src/components/views/RegionView.tsx index 119a5c4ae..17a7f2745 100644 --- a/packages/ott-vis-panel/src/components/views/RegionView.tsx +++ b/packages/ott-vis-panel/src/components/views/RegionView.tsx @@ -34,6 +34,7 @@ function buildGraph(state: SystemState): [Node[], Link[]] { y: 0, group: "core", color: regionColors[region], + text: region, }; nodes.push(core); @@ -45,6 +46,7 @@ function buildGraph(state: SystemState): [Node[], Link[]] { y: 0, group: "monolith", color: regionColors[region], + text: monolith.substring(0, 6), }; nodes.push(monolithNode); @@ -72,6 +74,9 @@ function buildGraph(state: SystemState): [Node[], Link[]] { }); const clients = roomCounts[room]; + if (clients === 0) { + continue; + } const clientsNode: Node = { id: `${room}-clients`, radius: clients, @@ -79,6 +84,7 @@ function buildGraph(state: SystemState): [Node[], Link[]] { y: 0, group: "client", color: regionColors[region], + text: `${clients}`, }; nodes.push(clientsNode);