Skip to content

Commit 40234e3

Browse files
committed
ott-vis-panel: add text to some nodes to differentiate them easier
1 parent a1336db commit 40234e3

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

packages/ott-vis-panel/src/components/ForceGraph.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface Node extends d3.SimulationNodeDatum {
2121
group: string;
2222
color: string;
2323
radius: number;
24+
text?: string;
2425
}
2526

2627
export interface Link extends d3.SimulationLinkDatum<Node> {
@@ -82,12 +83,13 @@ const ForceGraph: React.FC<ForceGraphProps> = ({
8283
);
8384

8485
useEffect(() => {
85-
const svg = d3.select(svgRef.current).attr("style", "max-width: 100%; height: auto;");
86+
const svg = d3.select(svgRef.current);
8687

8788
// Add a line for each link, and a circle for each node.
8889
const link = svg.select("g.links").selectAll("line").data(links);
8990

9091
const node = svg.select("g.nodes").selectAll("circle").data(nodes);
92+
const nodeText = svg.select("g.nodes").selectAll("text").data(nodes);
9193

9294
// node.append("title").text(d => d.id);
9395

@@ -105,6 +107,7 @@ const ForceGraph: React.FC<ForceGraphProps> = ({
105107
.attr("y2", d => (d.target as Node).y ?? 0);
106108

107109
node.attr("cx", d => d.x).attr("cy", d => d.y);
110+
nodeText.attr("x", d => d.x).attr("y", d => d.y + 4);
108111
});
109112

110113
// Reheat the simulation when drag starts, and fix the subject position.
@@ -143,7 +146,7 @@ const ForceGraph: React.FC<ForceGraphProps> = ({
143146
width={width}
144147
height={height}
145148
viewBox={`${-width / 2} ${-height / 2} ${width}, ${height}`}
146-
style={{ height: "auto" }}
149+
style={{ height: "auto", maxWidth: "100%" }}
147150
>
148151
<g className="links" stroke="#999" strokeOpacity={0.6}>
149152
{links.map((link, i) => (
@@ -152,7 +155,20 @@ const ForceGraph: React.FC<ForceGraphProps> = ({
152155
</g>
153156
<g className="nodes" stroke="#fff" strokeWidth={1.5}>
154157
{nodes.map((node, i) => (
155-
<circle key={i} r={radius(node.radius)} fill={color(node.group)} />
158+
<>
159+
<circle key={i} r={radius(node.radius)} fill={color(node.group)} />
160+
<text
161+
textAnchor="middle"
162+
alignmentBaseline="middle"
163+
style={{ userSelect: "none", cursor: "default", pointerEvents: "none" }}
164+
fontFamily="Inter, Helvetica, Arial, sans-serif"
165+
fontSize={10}
166+
strokeWidth={0}
167+
fill="#fff"
168+
>
169+
{node.text}
170+
</text>
171+
</>
156172
))}
157173
</g>
158174
</svg>

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

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function buildGraph(state: SystemState): [Node[], Link[]] {
1919
y: 0,
2020
group: "core",
2121
color: "Purple", // TODO: use color from grafana theme/panel options
22+
text: "OTT",
2223
};
2324
nodes.push(core);
2425

@@ -34,6 +35,7 @@ function buildGraph(state: SystemState): [Node[], Link[]] {
3435
y: 0,
3536
group: "monolith",
3637
color: "Red", // TODO: use color from grafana theme/panel options
38+
text: monolith.substring(0, 6),
3739
};
3840
nodes.push(monolithNode);
3941
monoliths.push(monolithNode);

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

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function buildGraph(state: SystemState): [Node[], Link[]] {
3434
y: 0,
3535
group: "core",
3636
color: regionColors[region],
37+
text: region,
3738
};
3839
nodes.push(core);
3940

@@ -45,6 +46,7 @@ function buildGraph(state: SystemState): [Node[], Link[]] {
4546
y: 0,
4647
group: "monolith",
4748
color: regionColors[region],
49+
text: monolith.substring(0, 6),
4850
};
4951
nodes.push(monolithNode);
5052

@@ -72,13 +74,17 @@ function buildGraph(state: SystemState): [Node[], Link[]] {
7274
});
7375

7476
const clients = roomCounts[room];
77+
if (clients === 0) {
78+
continue;
79+
}
7580
const clientsNode: Node = {
7681
id: `${room}-clients`,
7782
radius: clients,
7883
x: 0,
7984
y: 0,
8085
group: "client",
8186
color: regionColors[region],
87+
text: `${clients}`,
8288
};
8389
nodes.push(clientsNode);
8490

0 commit comments

Comments
 (0)