feat(graph): adjust node width calculation for layout
This commit is contained in:
parent
0464501dd4
commit
979f804623
@ -10,12 +10,15 @@ interface CfgGraphProps {
|
||||
onHighlightRange: (start: string, end: string) => void;
|
||||
}
|
||||
|
||||
const NODE_W = 220;
|
||||
const MIN_NODE_W = 180;
|
||||
const HEADER_H = 18;
|
||||
const LINE_H = 13;
|
||||
const LINE_H = 14;
|
||||
const FOOTER_H = 11;
|
||||
const PAD_V = 12;
|
||||
const GRAPH_PAD = 32;
|
||||
const CHAR_W_10 = 6.0;
|
||||
const CHAR_W_11 = 6.6;
|
||||
const H_PAD = 20;
|
||||
|
||||
const BLOCK_DEFS: Record<number, { stroke: string; fill: string; label: string }> = {
|
||||
0: { stroke: "#2563eb", fill: "#bfdbfe", label: "Normal" },
|
||||
@ -79,8 +82,15 @@ export function CfgGraph({ blocks, assembly, onHighlightRange }: CfgGraphProps)
|
||||
|
||||
for (const b of blocks) {
|
||||
const lines = blockLines.get(b.id ?? -1) ?? [];
|
||||
const maxLineLen = lines.reduce((max, l) => Math.max(max, l.text.length), 0);
|
||||
const addrStr = `${b.start ?? ""}-${b.end ?? ""}`;
|
||||
const w = Math.max(
|
||||
MIN_NODE_W,
|
||||
maxLineLen * CHAR_W_10 + H_PAD,
|
||||
addrStr.length * CHAR_W_11 + H_PAD
|
||||
);
|
||||
const h = HEADER_H + lines.length * LINE_H + FOOTER_H + PAD_V;
|
||||
g.setNode(String(b.id), { width: NODE_W, height: h });
|
||||
g.setNode(String(b.id), { width: w, height: h });
|
||||
}
|
||||
for (const b of blocks) {
|
||||
for (const t of b.succs ?? []) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user