From 15aba23f072dc92d5987a5f15554419c82357245 Mon Sep 17 00:00:00 2001 From: irof Date: Sat, 7 Feb 2026 14:53:43 +0900 Subject: [PATCH 1/2] Shorten nested subgraph labels --- .../src/main/resources/templates/assets/package.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jig-core/src/main/resources/templates/assets/package.js b/jig-core/src/main/resources/templates/assets/package.js index a4bba8784..9a3c584dd 100644 --- a/jig-core/src/main/resources/templates/assets/package.js +++ b/jig-core/src/main/resources/templates/assets/package.js @@ -820,6 +820,14 @@ function buildDiagramNodeLabel(displayLabel, fqn, parentSubgraphFqn) { return displayLabel ?? ''; } +function buildDiagramSubgraphLabel(subgraphFqn, parentSubgraphFqn) { + if (!subgraphFqn) return ''; + if (parentSubgraphFqn && subgraphFqn.startsWith(`${parentSubgraphFqn}.`)) { + return subgraphFqn.substring(parentSubgraphFqn.length + 1); + } + return subgraphFqn; +} + function buildDiagramNodeTooltip(fqn) { return fqn ?? ''; } @@ -863,7 +871,8 @@ function buildSubgraphLines(rootGroup, addNodeLines, escapeMermaidText) { return; } const groupId = `G${groupIndex++}`; - lines.push(`subgraph ${groupId}["${escapeMermaidText(child.key)}"]`); + const label = buildDiagramSubgraphLabel(child.key, parentSubgraphFqnForNodes); + lines.push(`subgraph ${groupId}["${escapeMermaidText(label)}"]`); renderGroup(child, false, child.key); lines.push('end'); }); From cfbf4c180b41417241eb195a736b3b9df9bca757 Mon Sep 17 00:00:00 2001 From: irof Date: Sat, 7 Feb 2026 14:55:46 +0900 Subject: [PATCH 2/2] Add tests for subgraph label shortening --- .../main/resources/templates/assets/package.js | 1 + jig-core/src/test/js/package.test.js | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/jig-core/src/main/resources/templates/assets/package.js b/jig-core/src/main/resources/templates/assets/package.js index 9a3c584dd..20aa980f0 100644 --- a/jig-core/src/main/resources/templates/assets/package.js +++ b/jig-core/src/main/resources/templates/assets/package.js @@ -1284,6 +1284,7 @@ if (typeof module !== 'undefined' && module.exports) { buildDiagramEdgeLines, buildDiagramNodeLines, buildDiagramNodeLabel, + buildDiagramSubgraphLabel, buildDiagramNodeTooltip, buildDiagramGroupTree, buildSubgraphLines, diff --git a/jig-core/src/test/js/package.test.js b/jig-core/src/test/js/package.test.js index c0303dc53..b5eb53172 100644 --- a/jig-core/src/test/js/package.test.js +++ b/jig-core/src/test/js/package.test.js @@ -788,6 +788,11 @@ test.describe('package.js', () => { assert.equal(label, 'model'); }); + test('buildDiagramSubgraphLabel: 親サブグラフ配下ならプレフィックスを省略する', () => { + const label = pkg.buildDiagramSubgraphLabel('com.example.domain', 'com.example'); + assert.equal(label, 'domain'); + }); + test('buildDiagramNodeTooltip: FQNを返す', () => { assert.equal(pkg.buildDiagramNodeTooltip('com.example.domain'), 'com.example.domain'); assert.equal(pkg.buildDiagramNodeTooltip(null), ''); @@ -808,9 +813,15 @@ test.describe('package.js', () => { test('buildSubgraphLines: サブグラフ行を生成する', () => { const rootGroup = { key: '', - nodes: [], + nodes: ['ROOT'], children: new Map([ - ['com.example', {key: 'com.example', nodes: ['P0', 'P1'], children: new Map()}], + ['com.example', { + key: 'com.example', + nodes: ['P0'], + children: new Map([ + ['com.example.domain', {key: 'com.example.domain', nodes: ['P1', 'P2'], children: new Map()}], + ]), + }], ]), }; const addNodeLines = (lines, nodeId) => { @@ -819,7 +830,10 @@ test.describe('package.js', () => { const lines = pkg.buildSubgraphLines(rootGroup, addNodeLines, text => text); + assert.equal(lines.some(line => line.includes('node ROOT')), true); assert.equal(lines.some(line => line.includes('node P0')), true); + assert.equal(lines.some(line => line.includes('subgraph') && line.includes('["com.example"]')), true); + assert.equal(lines.some(line => line.includes('subgraph') && line.includes('["domain"]')), true); }); test('buildAggregationDepthOptions: 集約オプションを組み立てる', () => {