Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(diagram): reduce edge label typography

tianma-if86f6c9318332
diff --git a/apps/web/src/components/DiagramEditorPane.test.mjs b/apps/web/src/components/DiagramEditorPane.test.mjs
index b48e5be7..8091a32c 100644
--- a/apps/web/src/components/DiagramEditorPane.test.mjs
+++ b/apps/web/src/components/DiagramEditorPane.test.mjs
@@ -187,6 +187,12 @@ describe("diagram editor canvas surface", () => {
expect(source).toContain('{ fill: "none" }');
expect(source).toContain('if (kind !== "mind-map") edge.attr("line/fill", "none")');
expect(source).toContain("FLOWCHART_EDGE_ROUTER");
+ expect(source).toContain("fontSize: ARCHITECTURE_EDGE_LABEL_FONT_SIZE");
+ expect(source).toContain("lineHeight: ARCHITECTURE_EDGE_LABEL_LINE_HEIGHT");
+ expect(source).toContain("fontSize: FLOWCHART_EDGE_LABEL_FONT_SIZE");
+ expect(source).toContain("lineHeight: FLOWCHART_EDGE_LABEL_LINE_HEIGHT");
+ expect(source).toContain("fontSize: MIND_MAP_EDGE_LABEL_FONT_SIZE");
+ expect(source).toContain("lineHeight: MIND_MAP_EDGE_LABEL_LINE_HEIGHT");
expect(source).toContain("applyOrthogonalEdgePorts(graph, document.kind)");
expect(source).toContain("flowchartEdgeIsStraight");
expect(source).toContain('showTheme={document.kind !== "architecture"}');
diff --git a/apps/web/src/components/DiagramEditorPane.tsx b/apps/web/src/components/DiagramEditorPane.tsx
index a102a24b..313ed315 100644
--- a/apps/web/src/components/DiagramEditorPane.tsx
+++ b/apps/web/src/components/DiagramEditorPane.tsx
@@ -84,10 +84,14 @@ import {
import { useTranslation } from "react-i18next";
import {
ARCHITECTURE_DIAGRAM_SCHEMA_VERSION,
+ ARCHITECTURE_EDGE_LABEL_FONT_SIZE,
+ ARCHITECTURE_EDGE_LABEL_LINE_HEIGHT,
DIAGRAM_SCHEMA_VERSION,
diagramFallbackMarkdown,
markdownToDoc,
MIND_MAP_CONNECTOR_NAME,
+ MIND_MAP_EDGE_LABEL_FONT_SIZE,
+ MIND_MAP_EDGE_LABEL_LINE_HEIGHT,
MIND_MAP_HORIZONTAL_GAP,
mindMapTopicMarkup,
MIND_MAP_VERTICAL_GAP,
@@ -118,6 +122,8 @@ import {
isArchitectureNodeShape,
resolveArchitectureSurface,
diagramReaderFocusNode,
+ FLOWCHART_EDGE_LABEL_FONT_SIZE,
+ FLOWCHART_EDGE_LABEL_LINE_HEIGHT,
FLOWCHART_EDGE_ROUTER,
FLOWCHART_LABEL_FONT,
flowchartEdgeIsStraight,
@@ -1236,10 +1242,10 @@ const diagramEdgeLabel = (
label: {
text,
fill: appearance === "dark" ? "#E2E8F0" : "#334155",
- fontSize: 11,
+ fontSize: ARCHITECTURE_EDGE_LABEL_FONT_SIZE,
fontWeight: 500,
fontFamily: ARCHITECTURE_LABEL_FONT,
- lineHeight: 16,
+ lineHeight: ARCHITECTURE_EDGE_LABEL_LINE_HEIGHT,
textWrap: { width: 140, height: 512 },
},
body: {
@@ -1267,10 +1273,10 @@ const diagramEdgeLabel = (
label: {
text,
fill: appearance === "dark" ? "#E2E8F0" : "#475569",
- fontSize: 11,
+ fontSize: FLOWCHART_EDGE_LABEL_FONT_SIZE,
fontWeight: 500,
fontFamily: FLOWCHART_LABEL_FONT,
- lineHeight: 16,
+ lineHeight: FLOWCHART_EDGE_LABEL_LINE_HEIGHT,
textWrap: { width: 140, height: 512 },
},
body: {
@@ -1295,7 +1301,13 @@ const diagramEdgeLabel = (
return {
position: { distance: 0.5, offset: 0 },
attrs: {
- label: { text, fill: palette.nodeText, fontSize: 12, lineHeight: 16, textWrap: { width: 140, height: 512 } },
+ label: {
+ text,
+ fill: palette.nodeText,
+ fontSize: MIND_MAP_EDGE_LABEL_FONT_SIZE,
+ lineHeight: MIND_MAP_EDGE_LABEL_LINE_HEIGHT,
+ textWrap: { width: 140, height: 512 },
+ },
body: { ref: "label", refWidth: 1, refHeight: 1, refWidth2: 12, refHeight2: 8, refX: -6, refY: -4,
fill: palette.canvas,
stroke: palette.nodeStroke, strokeWidth: 1, rx: 4, ry: 4 },
diff --git a/packages/shared/src/diagram-architecture-style.test.mjs b/packages/shared/src/diagram-architecture-style.test.mjs
index 9da66d60..15cce1cc 100644
--- a/packages/shared/src/diagram-architecture-style.test.mjs
+++ b/packages/shared/src/diagram-architecture-style.test.mjs
@@ -3,6 +3,8 @@ import { ARCHITECTURE_RESOURCE_ICONS } from "./diagram.ts";
import { ARCHITECTURE_RESOURCE_ICON_ELEMENTS } from "./diagram-architecture-icons.ts";
import {
ARCHITECTURE_COMPONENT_SHAPES,
+ ARCHITECTURE_EDGE_LABEL_FONT_SIZE,
+ ARCHITECTURE_EDGE_LABEL_LINE_HEIGHT,
ARCHITECTURE_SURFACES,
architectureEdgePorts,
architectureEdgeVisual,
@@ -29,6 +31,11 @@ const contrast = (foreground, background) => {
};
describe("architecture semantic paint", () => {
+ test("keeps edge labels subordinate to component labels", () => {
+ expect(ARCHITECTURE_EDGE_LABEL_FONT_SIZE).toBeLessThan(12);
+ expect(ARCHITECTURE_EDGE_LABEL_LINE_HEIGHT).toBeLessThan(17);
+ });
+
test("routes forward diagonal edges between horizontal ports", () => {
const lowerLeft = { x: 194, y: 711, width: 170, height: 64 };
const upperRight = { x: 446, y: 658, width: 170, height: 68 };
diff --git a/packages/shared/src/diagram-architecture-style.ts b/packages/shared/src/diagram-architecture-style.ts
index 98a04040..a4f0d944 100644
--- a/packages/shared/src/diagram-architecture-style.ts
+++ b/packages/shared/src/diagram-architecture-style.ts
@@ -11,6 +11,8 @@ export const ARCHITECTURE_LABEL_FONT =
export const ARCHITECTURE_NODE_FONT_SIZE = 12;
export const ARCHITECTURE_NODE_FONT_WEIGHT = 550;
export const ARCHITECTURE_NODE_LINE_HEIGHT = 17;
+export const ARCHITECTURE_EDGE_LABEL_FONT_SIZE = 10;
+export const ARCHITECTURE_EDGE_LABEL_LINE_HEIGHT = 14;
export const ARCHITECTURE_ICON_SIZE = 24;
export const ARCHITECTURE_ICON_FRAME = 34;
diff --git a/packages/shared/src/diagram-flowchart-style.test.mjs b/packages/shared/src/diagram-flowchart-style.test.mjs
index 0742931d..fa9bf08a 100644
--- a/packages/shared/src/diagram-flowchart-style.test.mjs
+++ b/packages/shared/src/diagram-flowchart-style.test.mjs
@@ -2,6 +2,8 @@ import { describe, expect, test } from "bun:test";
import { flowchartNodePresentation } from "./diagram-node-presentation.ts";
import {
DIAGRAM_READABLE_MIN_SCALE,
+ FLOWCHART_EDGE_LABEL_FONT_SIZE,
+ FLOWCHART_EDGE_LABEL_LINE_HEIGHT,
FLOWCHART_SELECTABLE_THEMES,
FLOWCHART_SURFACES,
FLOWCHART_THEME_GROUPS,
@@ -29,6 +31,11 @@ const contrast = (foreground, background) => {
};
describe("flowchart semantic paint", () => {
+ test("keeps edge labels subordinate to process labels", () => {
+ expect(FLOWCHART_EDGE_LABEL_FONT_SIZE).toBeLessThan(13);
+ expect(FLOWCHART_EDGE_LABEL_LINE_HEIGHT).toBeLessThan(18);
+ });
+
test("keeps process, decision, and terminator visually distinct", () => {
for (const theme of FLOWCHART_SELECTABLE_THEMES) {
for (const appearance of ["light", "dark"]) {
diff --git a/packages/shared/src/diagram-flowchart-style.ts b/packages/shared/src/diagram-flowchart-style.ts
index 37ba1dba..5a2860c1 100644
--- a/packages/shared/src/diagram-flowchart-style.ts
+++ b/packages/shared/src/diagram-flowchart-style.ts
@@ -2,6 +2,8 @@ import type { DiagramNodeShape, DiagramTheme } from "./diagram";
export const FLOWCHART_LABEL_FONT =
'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
+export const FLOWCHART_EDGE_LABEL_FONT_SIZE = 10;
+export const FLOWCHART_EDGE_LABEL_LINE_HEIGHT = 14;
export const FLOWCHART_EDGE_ROUTER = {
name: "manhattan" as const,
diff --git a/packages/shared/src/diagram-mindmap-style.test.mjs b/packages/shared/src/diagram-mindmap-style.test.mjs
index 978679bf..3624dd93 100644
--- a/packages/shared/src/diagram-mindmap-style.test.mjs
+++ b/packages/shared/src/diagram-mindmap-style.test.mjs
@@ -20,6 +20,8 @@ import {
mindMapUsesUnderline,
resolveMindMapNodeStyle,
MIND_MAP_CONNECTOR_NAME,
+ MIND_MAP_EDGE_LABEL_FONT_SIZE,
+ MIND_MAP_EDGE_LABEL_LINE_HEIGHT,
MIND_MAP_VERTICAL_GAP,
} from "./diagram-mindmap-style.ts";
@@ -54,6 +56,15 @@ describe("mind map presentation", () => {
expect(MIND_MAP_VERTICAL_GAP).toBe(20);
});
+ test("keeps edge annotations visually subordinate to nested topics", () => {
+ const nestedPresentation = mindMapNodePresentation("分支主题", "nested");
+ const nestedVisual = mindMapNodeVisual("nested", palette);
+ expect(MIND_MAP_EDGE_LABEL_FONT_SIZE).toBe(10);
+ expect(MIND_MAP_EDGE_LABEL_LINE_HEIGHT).toBe(14);
+ expect(MIND_MAP_EDGE_LABEL_FONT_SIZE).toBeLessThan(nestedPresentation.fontSize);
+ expect(MIND_MAP_EDGE_LABEL_LINE_HEIGHT).toBeLessThan(nestedVisual.label.lineHeight);
+ });
+
test("uses a capsule root, rounded first-level topics, and lighter nested topics", () => {
const root = mindMapNodeVisual("root", palette);
const primary = mindMapNodeVisual("primary", palette);
diff --git a/packages/shared/src/diagram-mindmap-style.ts b/packages/shared/src/diagram-mindmap-style.ts
index 72e4f1ee..6b4a247b 100644
--- a/packages/shared/src/diagram-mindmap-style.ts
+++ b/packages/shared/src/diagram-mindmap-style.ts
@@ -32,6 +32,8 @@ export const MIND_MAP_HORIZONTAL_GAP = 72;
export const MIND_MAP_VERTICAL_GAP = 20;
export const MIND_MAP_LABEL_FONT =
'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
+export const MIND_MAP_EDGE_LABEL_FONT_SIZE = 10;
+export const MIND_MAP_EDGE_LABEL_LINE_HEIGHT = 14;
export const MIND_MAP_TOPIC_MARKUP = [
{ tagName: "rect", selector: "body" },
diff --git a/packages/shared/src/diagram-view.ts b/packages/shared/src/diagram-view.ts
index a92ad8ef..d2e80407 100644
--- a/packages/shared/src/diagram-view.ts
+++ b/packages/shared/src/diagram-view.ts
@@ -1,5 +1,7 @@
import { flowchartNodePresentation } from "./diagram-node-presentation";
import {
+ ARCHITECTURE_EDGE_LABEL_FONT_SIZE,
+ ARCHITECTURE_EDGE_LABEL_LINE_HEIGHT,
ARCHITECTURE_LABEL_FONT,
architectureEdgePorts,
architectureEdgeVisual,
@@ -7,6 +9,8 @@ import {
resolveArchitectureSurface,
} from "./diagram-architecture-style";
import {
+ FLOWCHART_EDGE_LABEL_FONT_SIZE,
+ FLOWCHART_EDGE_LABEL_LINE_HEIGHT,
FLOWCHART_EDGE_ROUTER,
FLOWCHART_LABEL_FONT,
flowchartEdgeIsStraight,
@@ -18,6 +22,8 @@ import type { DiagramDocument, DiagramTheme } from "./diagram";
import { buildDiagramPalette } from "./diagram-palette";
import {
MIND_MAP_CONNECTOR_NAME,
+ MIND_MAP_EDGE_LABEL_FONT_SIZE,
+ MIND_MAP_EDGE_LABEL_LINE_HEIGHT,
mindMapBranchSides,
mindMapEdgeLineAttrs,
mindMapEdgeTerminal,
@@ -219,9 +225,17 @@ export const diagramDocumentToX6Cells = (
: document.kind === "flowchart"
? (appearance === "dark" ? "#E2E8F0" : "#475569")
: (flowchartSurface?.process.text ?? architectureSurface?.nodes.service.text ?? palette.nodeText),
- fontSize: (document.kind === "architecture" || document.kind === "flowchart") ? 11 : 12,
+ fontSize: document.kind === "architecture"
+ ? ARCHITECTURE_EDGE_LABEL_FONT_SIZE
+ : document.kind === "flowchart"
+ ? FLOWCHART_EDGE_LABEL_FONT_SIZE
+ : MIND_MAP_EDGE_LABEL_FONT_SIZE,
fontWeight: (document.kind === "architecture" || document.kind === "flowchart") ? 500 : 400,
- lineHeight: 16,
+ lineHeight: document.kind === "architecture"
+ ? ARCHITECTURE_EDGE_LABEL_LINE_HEIGHT
+ : document.kind === "flowchart"
+ ? FLOWCHART_EDGE_LABEL_LINE_HEIGHT
+ : MIND_MAP_EDGE_LABEL_LINE_HEIGHT,
fontFamily: document.kind === "architecture" ? ARCHITECTURE_LABEL_FONT : FLOWCHART_LABEL_FONT,
textWrap: { width: 140, height: 512 },
},
diff --git a/packages/shared/src/diagram.test.mjs b/packages/shared/src/diagram.test.mjs
index cc3ff1fb..5431b049 100644
--- a/packages/shared/src/diagram.test.mjs
+++ b/packages/shared/src/diagram.test.mjs
@@ -177,6 +177,21 @@ describe("diagram document", () => {
expect(projectedEdge.target.port).toBe("left");
});
+ test("projects architecture edge labels below component typography", () => {
+ const document = createDefaultDiagramDocument("architecture");
+ const projectedLabel = diagramDocumentToX6Cells(document, "light").edges[0].labels[0].attrs.label;
+ expect(projectedLabel.fontSize).toBe(10);
+ expect(projectedLabel.lineHeight).toBe(14);
+ });
+
+ test("projects mind map edge labels below topic typography", () => {
+ const document = createDefaultDiagramDocument("mind-map");
+ document.edges[0].label = "补充说明";
+ const projectedLabel = diagramDocumentToX6Cells(document, "light").edges[0].labels[0].attrs.label;
+ expect(projectedLabel.fontSize).toBe(10);
+ expect(projectedLabel.lineHeight).toBe(14);
+ });
+
test("keeps legacy architecture nodes valid and projects resource-specific icons", () => {
const legacy = createDefaultDiagramDocument("architecture");
expect(legacy.nodes.every((node) => node.resourceIcon === undefined)).toBe(true);
@@ -248,6 +263,7 @@ describe("diagram document", () => {
test('native flowchart projection shares label sizing and obstacle routing without mutating content', () => {
const document = createDefaultDiagramDocument('flowchart');
document.nodes[1].label = 'Transformer 前向计算\n因果注意力以及前馈网络'.repeat(4);
+ document.edges[0].label = '是';
const original = structuredClone(document);
const projection = diagramDocumentToX6Cells(document, 'dark');
expect(projection.nodes[1].height).toBeGreaterThan(document.nodes[1].height);
@@ -255,6 +271,8 @@ test('native flowchart projection shares label sizing and obstacle routing witho
expect(projection.edges[0].router.name).toBe('normal');
expect(projection.edges[0].source.port).toBe('bottom');
expect(projection.edges[0].target.port).toBe('top');
+ expect(projection.edges[0].labels[0].attrs.label.fontSize).toBe(10);
+ expect(projection.edges[0].labels[0].attrs.label.lineHeight).toBe(14);
expect(projection.edges[0].attrs.line.fill).toBe('none');
expect(projection.nodes[0].attrs.body.fill).not.toBe('#16A06E');
expect(projection.nodes[0].attrs.label.fontFamily).toContain('Inter');