@transitrix/diagrams 1.6.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activities/layout.js +7 -7
- package/dist/activities/types.d.ts +4 -0
- package/dist/capability-map/dsm-schema.d.ts +1 -1
- package/dist/capability-map/dsm-schema.js +1 -1
- package/dist/capability-map/layout-tree.d.ts +5 -1
- package/dist/capability-map/layout-tree.js +11 -9
- package/dist/capability-map/render-capability-tree.d.ts +2 -9
- package/dist/capability-map/render-capability-tree.js +16 -28
- package/dist/codex/__tests__/example.test.d.ts +1 -0
- package/dist/codex/__tests__/example.test.js +33 -0
- package/dist/codex/__tests__/validate.test.d.ts +1 -0
- package/dist/codex/__tests__/validate.test.js +68 -0
- package/dist/codex/index.d.ts +4 -0
- package/dist/codex/index.js +2 -0
- package/dist/codex/types.d.ts +7 -0
- package/dist/codex/types.js +8 -0
- package/dist/codex/validate.d.ts +11 -0
- package/dist/codex/validate.js +103 -0
- package/dist/compliance/__tests__/canon-catalog.test.d.ts +1 -0
- package/dist/compliance/__tests__/canon-catalog.test.js +60 -0
- package/dist/compliance/__tests__/view-resolution.test.d.ts +1 -0
- package/dist/compliance/__tests__/view-resolution.test.js +59 -0
- package/dist/compliance/canon-catalog.d.ts +19 -0
- package/dist/compliance/canon-catalog.js +59 -0
- package/dist/compliance/coverage-metric.d.ts +12 -0
- package/dist/compliance/coverage-metric.js +35 -0
- package/dist/compliance/impact.d.ts +7 -1
- package/dist/compliance/impact.js +53 -0
- package/dist/compliance/index.d.ts +6 -4
- package/dist/compliance/index.js +3 -2
- package/dist/constraint/__tests__/example.test.d.ts +1 -0
- package/dist/constraint/__tests__/example.test.js +14 -0
- package/dist/constraint/__tests__/validate.test.d.ts +1 -0
- package/dist/constraint/__tests__/validate.test.js +58 -0
- package/dist/constraint/index.d.ts +4 -0
- package/dist/constraint/index.js +2 -0
- package/dist/constraint/types.d.ts +4 -0
- package/dist/constraint/types.js +2 -0
- package/dist/constraint/validate.d.ts +7 -0
- package/dist/constraint/validate.js +115 -0
- package/dist/fgca/__tests__/parse-canonical.test.js +31 -0
- package/dist/fgca/parse-canonical.d.ts +1 -1
- package/dist/fgca/parse-canonical.js +18 -4
- package/dist/fgca/preview-layout.d.ts +8 -4
- package/dist/fgca/preview-layout.js +13 -13
- package/dist/goals/GoalNode.d.ts +2 -1
- package/dist/goals/GoalNode.js +7 -2
- package/dist/goals/GoalTreeView.d.ts +3 -1
- package/dist/goals/GoalTreeView.js +31 -14
- package/dist/goals/__tests__/GoalTreeView.test.js +41 -0
- package/dist/goals/__tests__/mutations.test.js +39 -0
- package/dist/goals/__tests__/parse-canonical.test.js +2 -0
- package/dist/goals/layout.js +2 -1
- package/dist/goals/mutations.js +6 -6
- package/dist/goals/parse-canonical.d.ts +5 -0
- package/dist/goals/parse-canonical.js +5 -0
- package/dist/goals/types.d.ts +2 -0
- package/dist/node-size-presets.d.ts +50 -0
- package/dist/node-size-presets.js +103 -0
- package/dist/process-blueprint/layout.js +4 -47
- package/dist/repo-validate/types.js +2 -3
- package/dist/webview/__tests__/entity-text-layout.test.d.ts +1 -0
- package/dist/webview/__tests__/entity-text-layout.test.js +43 -0
- package/dist/webview/__tests__/entry.test.js +3 -3
- package/dist/webview/__tests__/render-blocks.test.js +1 -7
- package/dist/webview/__tests__/render-goals.test.js +17 -3
- package/dist/webview/entity-text-layout.d.ts +95 -0
- package/dist/webview/entity-text-layout.js +279 -0
- package/dist/webview/entry.js +7 -3
- package/dist/webview/notation-style.d.ts +1 -1
- package/dist/webview/notation-style.js +1 -1
- package/dist/webview/render-activities.d.ts +3 -1
- package/dist/webview/render-activities.js +29 -32
- package/dist/webview/render-blocks.d.ts +4 -1
- package/dist/webview/render-blocks.js +27 -108
- package/dist/webview/render-fgca.d.ts +15 -8
- package/dist/webview/render-fgca.js +41 -44
- package/dist/webview/render-goals.d.ts +2 -0
- package/dist/webview/render-goals.js +23 -37
- package/dist/webview/render-process-blueprint.d.ts +4 -10
- package/dist/webview/render-process-blueprint.js +18 -64
- package/package.json +1 -1
- package/src/activities/layout.ts +12 -7
- package/src/activities/types.ts +4 -0
- package/src/capability-map/dsm-schema.ts +1 -1
- package/src/capability-map/index.ts +1 -1
- package/src/capability-map/layout-tree.ts +16 -8
- package/src/capability-map/render-capability-tree.ts +18 -30
- package/src/codex/__tests__/example.test.ts +40 -0
- package/src/codex/__tests__/validate.test.ts +84 -0
- package/src/codex/index.ts +4 -0
- package/src/codex/types.ts +13 -0
- package/src/codex/validate.ts +125 -0
- package/src/compliance/__tests__/canon-catalog.test.ts +68 -0
- package/src/compliance/__tests__/view-resolution.test.ts +80 -0
- package/src/compliance/canon-catalog.ts +76 -0
- package/src/compliance/coverage-metric.ts +50 -0
- package/src/compliance/impact.ts +67 -1
- package/src/compliance/index.ts +10 -1
- package/src/constraint/__tests__/example.test.ts +19 -0
- package/src/constraint/__tests__/validate.test.ts +68 -0
- package/src/constraint/index.ts +4 -0
- package/src/constraint/types.ts +5 -0
- package/src/constraint/validate.ts +131 -0
- package/src/fgca/__tests__/parse-canonical.test.ts +34 -0
- package/src/fgca/parse-canonical.ts +17 -4
- package/src/fgca/preview-layout.ts +21 -15
- package/src/goals/GoalNode.tsx +8 -1
- package/src/goals/GoalTreeView.tsx +61 -27
- package/src/goals/__tests__/GoalTreeView.test.tsx +48 -0
- package/src/goals/__tests__/mutations.test.ts +42 -0
- package/src/goals/__tests__/parse-canonical.test.ts +2 -0
- package/src/goals/layout.ts +2 -1
- package/src/goals/mutations.ts +6 -6
- package/src/goals/parse-canonical.ts +6 -0
- package/src/goals/types.ts +2 -0
- package/src/node-size-presets.ts +157 -0
- package/src/process-blueprint/layout.ts +4 -48
- package/src/repo-validate/types.ts +2 -3
- package/src/webview/__tests__/entity-text-layout.test.ts +52 -0
- package/src/webview/__tests__/entry.test.ts +3 -3
- package/src/webview/__tests__/render-blocks.test.ts +1 -9
- package/src/webview/__tests__/render-goals.test.ts +17 -3
- package/src/webview/entity-text-layout.ts +355 -0
- package/src/webview/entry.ts +8 -4
- package/src/webview/notation-style.ts +1 -1
- package/src/webview/render-activities.ts +38 -27
- package/src/webview/render-blocks.ts +35 -118
- package/src/webview/render-fgca.ts +59 -44
- package/src/webview/render-goals.ts +24 -35
- package/src/webview/render-process-blueprint.ts +30 -65
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { layoutCenteredEntityText, maxCharsForInnerWidth, wrapWords, wrapTextLines, } from '../entity-text-layout.js';
|
|
3
|
+
describe('entity-text-layout', () => {
|
|
4
|
+
it('wrapWords respects max lines and truncates with ellipsis', () => {
|
|
5
|
+
const long = 'one two three four five six seven eight nine ten eleven twelve';
|
|
6
|
+
const lines = wrapWords(long, 12, 2);
|
|
7
|
+
expect(lines.length).toBeLessThanOrEqual(2);
|
|
8
|
+
expect(lines[lines.length - 1]).toMatch(/…$/);
|
|
9
|
+
});
|
|
10
|
+
it('maxCharsForInnerWidth scales with inner width', () => {
|
|
11
|
+
expect(maxCharsForInnerWidth(160, 7)).toBeGreaterThan(maxCharsForInnerWidth(120, 7));
|
|
12
|
+
});
|
|
13
|
+
it('layoutCenteredEntityText emits more name capacity on wide boxes', () => {
|
|
14
|
+
const narrow = layoutCenteredEntityText({
|
|
15
|
+
boxX: 0,
|
|
16
|
+
boxY: 0,
|
|
17
|
+
boxWidth: 200,
|
|
18
|
+
boxHeight: 72,
|
|
19
|
+
name: 'Improve customer onboarding experience across regions',
|
|
20
|
+
id: 'GOAL-001',
|
|
21
|
+
nameMaxLines: 2,
|
|
22
|
+
idMaxLines: 1,
|
|
23
|
+
});
|
|
24
|
+
const wide = layoutCenteredEntityText({
|
|
25
|
+
boxX: 0,
|
|
26
|
+
boxY: 0,
|
|
27
|
+
boxWidth: 320,
|
|
28
|
+
boxHeight: 72,
|
|
29
|
+
name: 'Improve customer onboarding experience across regions',
|
|
30
|
+
id: 'GOAL-001',
|
|
31
|
+
nameMaxLines: 2,
|
|
32
|
+
idMaxLines: 1,
|
|
33
|
+
});
|
|
34
|
+
const narrowPrimary = narrow.filter((l) => l.cls === 'text-primary').map((l) => l.text).join(' ');
|
|
35
|
+
const widePrimary = wide.filter((l) => l.cls === 'text-primary').map((l) => l.text).join(' ');
|
|
36
|
+
expect(widePrimary.replace(/…/g, '').length).toBeGreaterThanOrEqual(narrowPrimary.replace(/…/g, '').length);
|
|
37
|
+
});
|
|
38
|
+
it('wrapTextLines hard-breaks oversized tokens (blueprint cells)', () => {
|
|
39
|
+
const lines = wrapTextLines('supercalifragilisticexpialidocious word', 10, 3);
|
|
40
|
+
expect(lines.length).toBeGreaterThan(1);
|
|
41
|
+
expect(lines.every((l) => l.length <= 10)).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -40,9 +40,9 @@ describe('webview/entry — Step 2 host API', () => {
|
|
|
40
40
|
});
|
|
41
41
|
it('routes non-goals kinds to their validator after Step 4 (no NOTATION-NOT-WIRED)', () => {
|
|
42
42
|
// Every supported kind is now wired to its validator + renderer. A
|
|
43
|
-
// malformed
|
|
44
|
-
// the
|
|
45
|
-
const r = render('
|
|
43
|
+
// malformed dgca document must surface a structured validation error from
|
|
44
|
+
// the dgca validator — never the Step-2/3 "not wired" placeholder.
|
|
45
|
+
const r = render('dgca', 'changes: []\n');
|
|
46
46
|
expect(r.status).toBe('error');
|
|
47
47
|
expect(r.errors.length).toBeGreaterThan(0);
|
|
48
48
|
expect(r.errors.every((e) => e.code !== 'NOTATION-NOT-WIRED')).toBe(true);
|
|
@@ -8,13 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { describe, expect, it } from 'vitest';
|
|
10
10
|
import { renderBlocksSvg } from '../render-blocks.js';
|
|
11
|
-
|
|
12
|
-
// Kept in sync with `CHAR_W` / `CHAR_W_ID` in render-blocks.ts so the test
|
|
13
|
-
// can compute the same overflow bounds the renderer uses.
|
|
14
|
-
const CHAR_W = 7;
|
|
15
|
-
const CHAR_W_ID = 6;
|
|
16
|
-
// Same horizontal margin the renderer reserves so text never abuts the rect.
|
|
17
|
-
const TEXT_MARGIN_X = 8;
|
|
11
|
+
import { CHAR_W_PRIMARY as CHAR_W, CHAR_W_ID, TEXT_MARGIN_X } from '../entity-text-layout.js';
|
|
18
12
|
function leafDoc(name, id) {
|
|
19
13
|
return {
|
|
20
14
|
notation: 'blocks',
|
|
@@ -58,8 +58,22 @@ describe('renderGoalsSvg', () => {
|
|
|
58
58
|
expect(svg).toContain('width="0"');
|
|
59
59
|
expect(svg).toContain('height="0"');
|
|
60
60
|
});
|
|
61
|
-
it('
|
|
62
|
-
const
|
|
63
|
-
|
|
61
|
+
it('shows canonical goal ids in node labels when present', () => {
|
|
62
|
+
const tree = {
|
|
63
|
+
goal_types: [{ name: 'Strategy', level: 0 }],
|
|
64
|
+
goals: [
|
|
65
|
+
{
|
|
66
|
+
id: 1,
|
|
67
|
+
canonical_id: 'GOAL-REVENUE-1',
|
|
68
|
+
name: 'Triple revenue',
|
|
69
|
+
type: 'Strategy',
|
|
70
|
+
level: 0,
|
|
71
|
+
parent_id: 0,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
const svg = renderGoalsSvg(tree);
|
|
76
|
+
expect(svg).toContain('GOAL-REVENUE-1');
|
|
77
|
+
expect(svg).not.toMatch(/>\s*1\s*</);
|
|
64
78
|
});
|
|
65
79
|
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared text-in-block layout for Transitrix diagram renderers.
|
|
3
|
+
*
|
|
4
|
+
* Consolidates wrapping, truncation, and vertical placement patterns previously
|
|
5
|
+
* duplicated across Blocks, Goals, DGCA/DGA, Activities, Process Blueprint, and
|
|
6
|
+
* Capability Map renderers.
|
|
7
|
+
*/
|
|
8
|
+
export declare const TEXT_MARGIN_X = 8;
|
|
9
|
+
/** Approximate character width (px) at text-primary size (12px/600). */
|
|
10
|
+
export declare const CHAR_W_PRIMARY = 7;
|
|
11
|
+
/** Approximate character width (px) at text-id size (10px/600). */
|
|
12
|
+
export declare const CHAR_W_ID = 6;
|
|
13
|
+
/** Approximate character width (px) at text-secondary size. */
|
|
14
|
+
export declare const CHAR_W_SECONDARY = 7;
|
|
15
|
+
/** Vertical advance between name line centres (text-primary). */
|
|
16
|
+
export declare const LINE_H_PRIMARY = 14;
|
|
17
|
+
/** Vertical advance between secondary line centres. */
|
|
18
|
+
export declare const LINE_H_SECONDARY = 14;
|
|
19
|
+
/** Vertical advance between id line centres (text-id). */
|
|
20
|
+
export declare const LINE_H_ID = 12;
|
|
21
|
+
/** Gap between the name block and the id block in leaf-style layouts. */
|
|
22
|
+
export declare const NAME_ID_GAP = 14;
|
|
23
|
+
/** Gap between stacked row groups (name → type → id). */
|
|
24
|
+
export declare const ROW_GROUP_GAP = 9;
|
|
25
|
+
export declare function maxCharsForInnerWidth(innerWidth: number, charWidth: number): number;
|
|
26
|
+
/** Word-wrap `text` to at most `maxLines` lines of `maxChars` each. */
|
|
27
|
+
export declare function wrapWords(text: string, maxChars: number, maxLines: number): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Greedy word-wrap with hard-break for tokens wider than the budget. When the
|
|
30
|
+
* result exceeds `maxLines`, the last kept line is truncated with an ellipsis.
|
|
31
|
+
* Used by Process Blueprint goal/result cells and aspect pill names.
|
|
32
|
+
*/
|
|
33
|
+
export declare function wrapTextLines(text: string, maxChars: number, maxLines: number): string[];
|
|
34
|
+
/** Split an ID (no spaces) across lines, breaking at `_` or `-`. */
|
|
35
|
+
export declare function wrapId(id: string, maxChars: number, maxLines?: number): string[];
|
|
36
|
+
/** Truncate `text` to at most `maxChars` characters, at a word boundary when possible. */
|
|
37
|
+
export declare function truncateLine(text: string, maxChars: number): string;
|
|
38
|
+
/** Single-line ID truncation that prefers `_`/`-` separators before a hard cut. */
|
|
39
|
+
export declare function truncateId(id: string, maxChars: number): string;
|
|
40
|
+
export interface TextLineSpec {
|
|
41
|
+
cls: string;
|
|
42
|
+
text: string;
|
|
43
|
+
y: number;
|
|
44
|
+
/** When set, use this x; otherwise callers supply a shared anchor (e.g. box centre). */
|
|
45
|
+
x?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface LayoutCenteredEntityOptions {
|
|
48
|
+
boxX: number;
|
|
49
|
+
boxY: number;
|
|
50
|
+
boxWidth: number;
|
|
51
|
+
boxHeight: number;
|
|
52
|
+
name: string;
|
|
53
|
+
type?: string;
|
|
54
|
+
id: string;
|
|
55
|
+
nameMaxLines?: number;
|
|
56
|
+
idMaxLines?: number;
|
|
57
|
+
marginX?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Layout centred entity text (name → optional type → id) inside a fixed box.
|
|
61
|
+
* Returns absolute SVG y-positions (line centres) for each rendered row.
|
|
62
|
+
*/
|
|
63
|
+
export declare function layoutCenteredEntityText(opts: LayoutCenteredEntityOptions): TextLineSpec[];
|
|
64
|
+
/** Emit centred `<text>` elements from {@link layoutCenteredEntityText} specs. */
|
|
65
|
+
export declare function emitCenteredTextSvg(specs: TextLineSpec[], centerX: number, esc: (s: string) => string): string;
|
|
66
|
+
export interface LayoutLeafBlockTextOptions {
|
|
67
|
+
boxX: number;
|
|
68
|
+
boxY: number;
|
|
69
|
+
boxWidth: number;
|
|
70
|
+
boxHeight: number;
|
|
71
|
+
name: string;
|
|
72
|
+
id: string;
|
|
73
|
+
nameMaxLines?: number;
|
|
74
|
+
marginX?: number;
|
|
75
|
+
}
|
|
76
|
+
/** Leaf nested-block layout: name (up to 3 lines) + id (up to 2 lines), centred. */
|
|
77
|
+
export declare function layoutLeafBlockText(opts: LayoutLeafBlockTextOptions): TextLineSpec[];
|
|
78
|
+
export interface LayoutHeaderBlockTextOptions {
|
|
79
|
+
boxX: number;
|
|
80
|
+
boxY: number;
|
|
81
|
+
boxWidth: number;
|
|
82
|
+
headerHeight: number;
|
|
83
|
+
name: string;
|
|
84
|
+
id: string;
|
|
85
|
+
marginX?: number;
|
|
86
|
+
}
|
|
87
|
+
/** Container header: single-line name + id stacked in the header strip. */
|
|
88
|
+
export declare function layoutHeaderBlockText(opts: LayoutHeaderBlockTextOptions): TextLineSpec[];
|
|
89
|
+
/**
|
|
90
|
+
* Left-anchored multi-line cell text, vertically centred (Process Blueprint cells).
|
|
91
|
+
* Returns one spec per line with absolute x baked into caller via anchorX.
|
|
92
|
+
*/
|
|
93
|
+
export declare function layoutLeftCellLines(lines: string[], anchorX: number, cellTop: number, cellHeight: number, lineHeight: number, cls: string): TextLineSpec[];
|
|
94
|
+
/** Centred pill text: name lines + optional id line below. */
|
|
95
|
+
export declare function layoutCenteredPillText(pillX: number, pillY: number, pillWidth: number, pillHeight: number, nameLines: string[], idLine: string | undefined, nameLineHeight?: number): TextLineSpec[];
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared text-in-block layout for Transitrix diagram renderers.
|
|
3
|
+
*
|
|
4
|
+
* Consolidates wrapping, truncation, and vertical placement patterns previously
|
|
5
|
+
* duplicated across Blocks, Goals, DGCA/DGA, Activities, Process Blueprint, and
|
|
6
|
+
* Capability Map renderers.
|
|
7
|
+
*/
|
|
8
|
+
export const TEXT_MARGIN_X = 8;
|
|
9
|
+
/** Approximate character width (px) at text-primary size (12px/600). */
|
|
10
|
+
export const CHAR_W_PRIMARY = 7;
|
|
11
|
+
/** Approximate character width (px) at text-id size (10px/600). */
|
|
12
|
+
export const CHAR_W_ID = 6;
|
|
13
|
+
/** Approximate character width (px) at text-secondary size. */
|
|
14
|
+
export const CHAR_W_SECONDARY = 7;
|
|
15
|
+
/** Vertical advance between name line centres (text-primary). */
|
|
16
|
+
export const LINE_H_PRIMARY = 14;
|
|
17
|
+
/** Vertical advance between secondary line centres. */
|
|
18
|
+
export const LINE_H_SECONDARY = 14;
|
|
19
|
+
/** Vertical advance between id line centres (text-id). */
|
|
20
|
+
export const LINE_H_ID = 12;
|
|
21
|
+
/** Gap between the name block and the id block in leaf-style layouts. */
|
|
22
|
+
export const NAME_ID_GAP = 14;
|
|
23
|
+
/** Gap between stacked row groups (name → type → id). */
|
|
24
|
+
export const ROW_GROUP_GAP = 9;
|
|
25
|
+
export function maxCharsForInnerWidth(innerWidth, charWidth) {
|
|
26
|
+
return Math.max(4, Math.floor(Math.max(0, innerWidth) / charWidth));
|
|
27
|
+
}
|
|
28
|
+
/** Word-wrap `text` to at most `maxLines` lines of `maxChars` each. */
|
|
29
|
+
export function wrapWords(text, maxChars, maxLines) {
|
|
30
|
+
const safeMax = Math.max(2, maxChars);
|
|
31
|
+
const words = text.split(' ');
|
|
32
|
+
const lines = [];
|
|
33
|
+
let cur = '';
|
|
34
|
+
for (let i = 0; i < words.length; i++) {
|
|
35
|
+
const w = words[i];
|
|
36
|
+
const next = cur ? `${cur} ${w}` : w;
|
|
37
|
+
if (next.length <= safeMax) {
|
|
38
|
+
cur = next;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (cur)
|
|
42
|
+
lines.push(cur);
|
|
43
|
+
cur = '';
|
|
44
|
+
if (lines.length >= maxLines)
|
|
45
|
+
break;
|
|
46
|
+
if (lines.length === maxLines - 1) {
|
|
47
|
+
const rest = words.slice(i).join(' ');
|
|
48
|
+
lines.push(rest.length <= safeMax ? rest : `${rest.slice(0, safeMax - 1)}…`);
|
|
49
|
+
return lines;
|
|
50
|
+
}
|
|
51
|
+
cur = w.length <= safeMax ? w : `${w.slice(0, safeMax - 1)}…`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (cur && lines.length < maxLines)
|
|
55
|
+
lines.push(cur);
|
|
56
|
+
return lines.length ? lines : [`${text.slice(0, safeMax - 1)}…`];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Greedy word-wrap with hard-break for tokens wider than the budget. When the
|
|
60
|
+
* result exceeds `maxLines`, the last kept line is truncated with an ellipsis.
|
|
61
|
+
* Used by Process Blueprint goal/result cells and aspect pill names.
|
|
62
|
+
*/
|
|
63
|
+
export function wrapTextLines(text, maxChars, maxLines) {
|
|
64
|
+
const trimmed = (text ?? '').trim();
|
|
65
|
+
if (trimmed.length === 0)
|
|
66
|
+
return [];
|
|
67
|
+
const budget = Math.max(1, maxChars);
|
|
68
|
+
const words = trimmed.split(/\s+/);
|
|
69
|
+
const lines = [];
|
|
70
|
+
let cur = '';
|
|
71
|
+
const flush = () => {
|
|
72
|
+
if (cur.length > 0) {
|
|
73
|
+
lines.push(cur);
|
|
74
|
+
cur = '';
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
for (const word of words) {
|
|
78
|
+
if (word.length > budget) {
|
|
79
|
+
flush();
|
|
80
|
+
let rest = word;
|
|
81
|
+
while (rest.length > budget) {
|
|
82
|
+
lines.push(rest.slice(0, budget));
|
|
83
|
+
rest = rest.slice(budget);
|
|
84
|
+
}
|
|
85
|
+
cur = rest;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const candidate = cur.length > 0 ? `${cur} ${word}` : word;
|
|
89
|
+
if (candidate.length > budget) {
|
|
90
|
+
flush();
|
|
91
|
+
cur = word;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
cur = candidate;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
flush();
|
|
98
|
+
if (lines.length > maxLines) {
|
|
99
|
+
const capped = lines.slice(0, maxLines);
|
|
100
|
+
const last = capped[maxLines - 1];
|
|
101
|
+
const clipped = last.length > budget - 1 ? last.slice(0, budget - 1) : last;
|
|
102
|
+
capped[maxLines - 1] = `${clipped.replace(/…$/, '')}…`;
|
|
103
|
+
return capped;
|
|
104
|
+
}
|
|
105
|
+
return lines;
|
|
106
|
+
}
|
|
107
|
+
/** Split an ID (no spaces) across lines, breaking at `_` or `-`. */
|
|
108
|
+
export function wrapId(id, maxChars, maxLines = 2) {
|
|
109
|
+
if (maxLines <= 1)
|
|
110
|
+
return [truncateId(id, maxChars)];
|
|
111
|
+
if (id.length <= maxChars)
|
|
112
|
+
return [id];
|
|
113
|
+
const seg = id.slice(0, maxChars);
|
|
114
|
+
const sepIdx = Math.max(seg.lastIndexOf('_'), seg.lastIndexOf('-'));
|
|
115
|
+
const cut = sepIdx > Math.floor(maxChars / 3) ? sepIdx : maxChars - 1;
|
|
116
|
+
const isSep = id[cut] === '_' || id[cut] === '-';
|
|
117
|
+
const line1 = id.slice(0, cut);
|
|
118
|
+
const rest = id.slice(cut + (isSep ? 1 : 0));
|
|
119
|
+
return [line1, rest.length <= maxChars ? rest : `${rest.slice(0, maxChars - 1)}…`];
|
|
120
|
+
}
|
|
121
|
+
/** Truncate `text` to at most `maxChars` characters, at a word boundary when possible. */
|
|
122
|
+
export function truncateLine(text, maxChars) {
|
|
123
|
+
const safeMax = Math.max(2, maxChars);
|
|
124
|
+
if (text.length <= safeMax)
|
|
125
|
+
return text;
|
|
126
|
+
const cut = text.slice(0, safeMax - 1);
|
|
127
|
+
const lastSpace = cut.lastIndexOf(' ');
|
|
128
|
+
return `${lastSpace > safeMax / 2 ? cut.slice(0, lastSpace) : cut}…`;
|
|
129
|
+
}
|
|
130
|
+
/** Single-line ID truncation that prefers `_`/`-` separators before a hard cut. */
|
|
131
|
+
export function truncateId(id, maxChars) {
|
|
132
|
+
const safeMax = Math.max(2, maxChars);
|
|
133
|
+
if (id.length <= safeMax)
|
|
134
|
+
return id;
|
|
135
|
+
const cut = id.slice(0, safeMax - 1);
|
|
136
|
+
const sepIdx = Math.max(cut.lastIndexOf('_'), cut.lastIndexOf('-'));
|
|
137
|
+
return `${sepIdx > safeMax / 3 ? cut.slice(0, sepIdx) : cut}…`;
|
|
138
|
+
}
|
|
139
|
+
function totalVerticalSpan(groups) {
|
|
140
|
+
let span = 0;
|
|
141
|
+
for (let i = 0; i < groups.length; i++) {
|
|
142
|
+
const g = groups[i];
|
|
143
|
+
if (g.lines.length > 1)
|
|
144
|
+
span += (g.lines.length - 1) * g.lineHeight;
|
|
145
|
+
if (i < groups.length - 1)
|
|
146
|
+
span += g.gapAfter;
|
|
147
|
+
}
|
|
148
|
+
return span;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Layout centred entity text (name → optional type → id) inside a fixed box.
|
|
152
|
+
* Returns absolute SVG y-positions (line centres) for each rendered row.
|
|
153
|
+
*/
|
|
154
|
+
export function layoutCenteredEntityText(opts) {
|
|
155
|
+
const marginX = opts.marginX ?? TEXT_MARGIN_X;
|
|
156
|
+
const innerW = Math.max(0, opts.boxWidth - marginX * 2);
|
|
157
|
+
const cx = opts.boxX + opts.boxWidth / 2;
|
|
158
|
+
const maxCharsName = maxCharsForInnerWidth(innerW, CHAR_W_PRIMARY);
|
|
159
|
+
const maxCharsType = maxCharsForInnerWidth(innerW, CHAR_W_SECONDARY);
|
|
160
|
+
const maxCharsId = maxCharsForInnerWidth(innerW, CHAR_W_ID);
|
|
161
|
+
const nameLines = wrapWords(opts.name, maxCharsName, opts.nameMaxLines ?? 2);
|
|
162
|
+
const typeLine = opts.type?.trim() ? truncateLine(opts.type, maxCharsType) : undefined;
|
|
163
|
+
const idMaxLines = opts.idMaxLines ?? 1;
|
|
164
|
+
const idLines = idMaxLines <= 1 ? [truncateId(opts.id, maxCharsId)] : wrapId(opts.id, maxCharsId, idMaxLines);
|
|
165
|
+
const groups = [
|
|
166
|
+
{
|
|
167
|
+
cls: 'text-primary',
|
|
168
|
+
lines: nameLines,
|
|
169
|
+
lineHeight: LINE_H_PRIMARY,
|
|
170
|
+
gapAfter: typeLine ? ROW_GROUP_GAP : NAME_ID_GAP,
|
|
171
|
+
},
|
|
172
|
+
];
|
|
173
|
+
if (typeLine) {
|
|
174
|
+
groups.push({
|
|
175
|
+
cls: 'text-secondary',
|
|
176
|
+
lines: [typeLine],
|
|
177
|
+
lineHeight: LINE_H_SECONDARY,
|
|
178
|
+
gapAfter: NAME_ID_GAP,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
groups.push({
|
|
182
|
+
cls: 'text-id',
|
|
183
|
+
lines: idLines,
|
|
184
|
+
lineHeight: LINE_H_ID,
|
|
185
|
+
gapAfter: 0,
|
|
186
|
+
});
|
|
187
|
+
const span = totalVerticalSpan(groups);
|
|
188
|
+
const firstY = Math.round(opts.boxY + (opts.boxHeight - span) / 2);
|
|
189
|
+
const out = [];
|
|
190
|
+
let y = firstY;
|
|
191
|
+
for (let gi = 0; gi < groups.length; gi++) {
|
|
192
|
+
const g = groups[gi];
|
|
193
|
+
for (let li = 0; li < g.lines.length; li++) {
|
|
194
|
+
out.push({ cls: g.cls, text: g.lines[li], y });
|
|
195
|
+
if (li < g.lines.length - 1)
|
|
196
|
+
y += g.lineHeight;
|
|
197
|
+
}
|
|
198
|
+
if (gi < groups.length - 1)
|
|
199
|
+
y += g.gapAfter;
|
|
200
|
+
}
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
203
|
+
/** Emit centred `<text>` elements from {@link layoutCenteredEntityText} specs. */
|
|
204
|
+
export function emitCenteredTextSvg(specs, centerX, esc) {
|
|
205
|
+
return specs
|
|
206
|
+
.map((spec) => {
|
|
207
|
+
const x = spec.x ?? centerX;
|
|
208
|
+
const anchor = spec.x != null && spec.cls === 'text-pill' ? ' text-anchor="middle"' : ' text-anchor="middle"';
|
|
209
|
+
return `<text class="${spec.cls}" x="${x}" y="${spec.y}"${anchor} dominant-baseline="central">${esc(spec.text)}</text>`;
|
|
210
|
+
})
|
|
211
|
+
.join('\n');
|
|
212
|
+
}
|
|
213
|
+
/** Leaf nested-block layout: name (up to 3 lines) + id (up to 2 lines), centred. */
|
|
214
|
+
export function layoutLeafBlockText(opts) {
|
|
215
|
+
const marginX = opts.marginX ?? TEXT_MARGIN_X;
|
|
216
|
+
const innerW = Math.max(0, opts.boxWidth - marginX * 2);
|
|
217
|
+
const maxCharsName = maxCharsForInnerWidth(innerW, CHAR_W_PRIMARY);
|
|
218
|
+
const maxCharsId = maxCharsForInnerWidth(innerW, CHAR_W_ID);
|
|
219
|
+
const nameLines = wrapWords(opts.name, maxCharsName, opts.nameMaxLines ?? 3);
|
|
220
|
+
const idLines = wrapId(opts.id, maxCharsId, 2);
|
|
221
|
+
const nameSpan = (nameLines.length - 1) * LINE_H_PRIMARY;
|
|
222
|
+
const idSpan = (idLines.length - 1) * LINE_H_ID;
|
|
223
|
+
const totalSpan = nameSpan + NAME_ID_GAP + idSpan;
|
|
224
|
+
const firstY = Math.round(opts.boxY + (opts.boxHeight - totalSpan) / 2);
|
|
225
|
+
const out = [];
|
|
226
|
+
for (let i = 0; i < nameLines.length; i++) {
|
|
227
|
+
out.push({ cls: 'text-primary', text: nameLines[i], y: firstY + i * LINE_H_PRIMARY });
|
|
228
|
+
}
|
|
229
|
+
const idFirstY = firstY + nameSpan + NAME_ID_GAP;
|
|
230
|
+
for (let i = 0; i < idLines.length; i++) {
|
|
231
|
+
out.push({ cls: 'text-id', text: idLines[i], y: idFirstY + i * LINE_H_ID });
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
/** Container header: single-line name + id stacked in the header strip. */
|
|
236
|
+
export function layoutHeaderBlockText(opts) {
|
|
237
|
+
const marginX = opts.marginX ?? TEXT_MARGIN_X;
|
|
238
|
+
const innerW = Math.max(0, opts.boxWidth - marginX * 2);
|
|
239
|
+
const maxCharsName = maxCharsForInnerWidth(innerW, CHAR_W_PRIMARY);
|
|
240
|
+
const maxCharsId = maxCharsForInnerWidth(innerW, CHAR_W_ID);
|
|
241
|
+
const nameText = truncateLine(opts.name, maxCharsName);
|
|
242
|
+
const idText = truncateId(opts.id, maxCharsId);
|
|
243
|
+
const headerMid = opts.boxY + opts.headerHeight / 2;
|
|
244
|
+
const halfSpan = (LINE_H_PRIMARY + LINE_H_ID) / 4;
|
|
245
|
+
return [
|
|
246
|
+
{ cls: 'text-primary', text: nameText, y: Math.round(headerMid - halfSpan) },
|
|
247
|
+
{ cls: 'text-id', text: idText, y: Math.round(headerMid + halfSpan) },
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Left-anchored multi-line cell text, vertically centred (Process Blueprint cells).
|
|
252
|
+
* Returns one spec per line with absolute x baked into caller via anchorX.
|
|
253
|
+
*/
|
|
254
|
+
export function layoutLeftCellLines(lines, anchorX, cellTop, cellHeight, lineHeight, cls) {
|
|
255
|
+
const ls = lines.length > 0 ? lines : [''];
|
|
256
|
+
const firstY = cellTop + cellHeight / 2 - ((ls.length - 1) / 2) * lineHeight;
|
|
257
|
+
return ls.map((text, i) => ({ cls, text, y: firstY + i * lineHeight, x: anchorX }));
|
|
258
|
+
}
|
|
259
|
+
/** Centred pill text: name lines + optional id line below. */
|
|
260
|
+
export function layoutCenteredPillText(pillX, pillY, pillWidth, pillHeight, nameLines, idLine, nameLineHeight = 15) {
|
|
261
|
+
const cx = pillX + pillWidth / 2;
|
|
262
|
+
const lineCount = nameLines.length + (idLine ? 1 : 0);
|
|
263
|
+
const firstY = pillY + pillHeight / 2 - ((lineCount - 1) / 2) * nameLineHeight;
|
|
264
|
+
const out = nameLines.map((text, i) => ({
|
|
265
|
+
cls: 'text-pill',
|
|
266
|
+
text,
|
|
267
|
+
y: firstY + i * nameLineHeight,
|
|
268
|
+
x: cx,
|
|
269
|
+
}));
|
|
270
|
+
if (idLine) {
|
|
271
|
+
out.push({
|
|
272
|
+
cls: 'text-secondary',
|
|
273
|
+
text: idLine,
|
|
274
|
+
y: firstY + nameLines.length * nameLineHeight,
|
|
275
|
+
x: cx,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return out;
|
|
279
|
+
}
|
package/dist/webview/entry.js
CHANGED
|
@@ -19,13 +19,17 @@
|
|
|
19
19
|
* (SVG for the diagram notations, an HTML fragment for the catalogue
|
|
20
20
|
* notations). The JVM host drops whatever `svg` carries into the DOM, so the
|
|
21
21
|
* field name is historical — it transports any self-contained markup.
|
|
22
|
+
*
|
|
23
|
+
* Import validators/types from leaf modules (e.g. `capability-map/validate.js`),
|
|
24
|
+
* never from package `index.ts` barrels that also re-export React views —
|
|
25
|
+
* esbuild cannot tree-shake those and the JCEF bundle would pull in React.
|
|
22
26
|
*/
|
|
23
27
|
import yaml from 'js-yaml';
|
|
24
28
|
import { validateActivities } from '../activities/index.js';
|
|
25
29
|
import { validateActivityCard } from '../activity-card/index.js';
|
|
26
30
|
import { validateApplicationsCatalogue } from '../applications/index.js';
|
|
27
31
|
import { validateNestedBlocks } from '../blocks/index.js';
|
|
28
|
-
import { validateCapabilityMap } from '../capability-map/
|
|
32
|
+
import { validateCapabilityMap } from '../capability-map/validate.js';
|
|
29
33
|
import { parseCanonicalFGCA, parseCanonicalFGA } from '../fgca/parse-canonical.js';
|
|
30
34
|
import { parseCanonicalGoals } from '../goals/parse-canonical.js';
|
|
31
35
|
import { validateProcessBlueprint } from '../process-blueprint/index.js';
|
|
@@ -114,7 +118,7 @@ function dispatchValidate(kind, doc) {
|
|
|
114
118
|
r.errors.push(...v.errors);
|
|
115
119
|
r.warnings.push(...v.warnings);
|
|
116
120
|
if (v.valid && v.parsed) {
|
|
117
|
-
r.svg = renderFgcaSvg(v.parsed, { variant: '
|
|
121
|
+
r.svg = renderFgcaSvg(v.parsed, { variant: 'dgca' });
|
|
118
122
|
}
|
|
119
123
|
return r;
|
|
120
124
|
}
|
|
@@ -124,7 +128,7 @@ function dispatchValidate(kind, doc) {
|
|
|
124
128
|
r.errors.push(...v.errors);
|
|
125
129
|
r.warnings.push(...v.warnings);
|
|
126
130
|
if (v.valid && v.parsed) {
|
|
127
|
-
r.svg = renderFgcaSvg(v.parsed, { variant: '
|
|
131
|
+
r.svg = renderFgcaSvg(v.parsed, { variant: 'dga' });
|
|
128
132
|
}
|
|
129
133
|
return r;
|
|
130
134
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared visual constants for entity-box (block-style) notation renderers.
|
|
3
3
|
*
|
|
4
|
-
* Goals, Nested Blocks,
|
|
4
|
+
* Goals, Nested Blocks, DGCA/DGA, and any future notation using the same
|
|
5
5
|
* entity-box visual language import their shared style tokens from here.
|
|
6
6
|
* Centralising them prevents the per-renderer drift that caused the Goals/Blocks
|
|
7
7
|
* style mismatch (border radius diverged to rx=6 in Blocks vs rx=8 everywhere
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared visual constants for entity-box (block-style) notation renderers.
|
|
3
3
|
*
|
|
4
|
-
* Goals, Nested Blocks,
|
|
4
|
+
* Goals, Nested Blocks, DGCA/DGA, and any future notation using the same
|
|
5
5
|
* entity-box visual language import their shared style tokens from here.
|
|
6
6
|
* Centralising them prevents the per-renderer drift that caused the Goals/Blocks
|
|
7
7
|
* style mismatch (border radius diverged to rx=6 in Blocks vs rx=8 everywhere
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computeCpm } from '../activities/cpm.js';
|
|
2
2
|
import type { ActivityDoc, ActivitiesLayout, ActivitiesLayoutOptions } from '../activities/types.js';
|
|
3
|
+
import { type NodeSizePreset } from '../node-size-presets.js';
|
|
3
4
|
/**
|
|
4
5
|
* Network-view diagram CSS (critical path, milestones, edge colours) — the
|
|
5
6
|
* canonical rules shared with the VS Code preview's `ACTIVITIES_DIAGRAM_CSS`
|
|
@@ -22,8 +23,9 @@ export declare function renderActivitiesNetworkBody(layout: ActivitiesLayout, cp
|
|
|
22
23
|
export interface RenderActivitiesOptions {
|
|
23
24
|
/** Optional heading rendered as a `text-header` above the diagram. */
|
|
24
25
|
title?: string;
|
|
25
|
-
/** Network column / row gaps. Defaults match `layoutActivities`. */
|
|
26
|
+
/** Network column / row gaps and node size. Defaults match `layoutActivities`. */
|
|
26
27
|
gaps?: ActivitiesLayoutOptions;
|
|
28
|
+
nodeSizePreset?: NodeSizePreset;
|
|
27
29
|
/** Exit edge curvature; 1 = default, 0 = straight, higher = stronger arc. */
|
|
28
30
|
curvature?: number;
|
|
29
31
|
/** Entry curvature at the target node; defaults to `curvature` when omitted. */
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
import { layoutActivities } from '../activities/layout.js';
|
|
20
20
|
import { computeCpm } from '../activities/cpm.js';
|
|
21
21
|
import { horizontalCubicEdgePath, DEFAULT_EDGE_CURVATURE } from '../edge-path.js';
|
|
22
|
+
import { parseNodeSizePreset, resolveActionNodeSize } from '../node-size-presets.js';
|
|
22
23
|
import { generateSvgEmbedCss } from '../theme/index.js';
|
|
24
|
+
import { emitCenteredTextSvg, layoutCenteredEntityText } from './entity-text-layout.js';
|
|
23
25
|
import { escXml } from './render-util.js';
|
|
24
|
-
const N_NODE_W = 200;
|
|
25
|
-
const N_NODE_H = 80;
|
|
26
26
|
const N_PAD = 24;
|
|
27
27
|
/**
|
|
28
28
|
* Network-view diagram CSS (critical path, milestones, edge colours) — the
|
|
@@ -46,8 +46,24 @@ export const ACTIVITIES_NETWORK_DEFS = `<defs>
|
|
|
46
46
|
<path d="M0,0 L0,6 L8,3 z" class="arrow-fill-critical"/>
|
|
47
47
|
</marker>
|
|
48
48
|
</defs>`;
|
|
49
|
-
function
|
|
50
|
-
|
|
49
|
+
function activityNodeSvg(n, x, y, isCritical, isMilestone, durLabel) {
|
|
50
|
+
const cls = `diagram-node act-node ${isCritical ? 'critical-node' : ''} ${isMilestone ? 'milestone-node' : ''}`.trim();
|
|
51
|
+
const specs = layoutCenteredEntityText({
|
|
52
|
+
boxX: x,
|
|
53
|
+
boxY: y,
|
|
54
|
+
boxWidth: n.width,
|
|
55
|
+
boxHeight: n.height,
|
|
56
|
+
name: n.data.name,
|
|
57
|
+
id: n.id,
|
|
58
|
+
nameMaxLines: 2,
|
|
59
|
+
idMaxLines: 1,
|
|
60
|
+
});
|
|
61
|
+
const textSvg = emitCenteredTextSvg(specs, x + n.width / 2, escXml);
|
|
62
|
+
return [
|
|
63
|
+
`<rect class="${cls}" x="${x}" y="${y}" width="${n.width}" height="${n.height}" rx="8"/>`,
|
|
64
|
+
textSvg,
|
|
65
|
+
durLabel ? `<text class="text-secondary" x="${x + n.width - 8}" y="${y + n.height - 8}" text-anchor="end">${durLabel}</text>` : '',
|
|
66
|
+
].filter(Boolean).join('\n');
|
|
51
67
|
}
|
|
52
68
|
/**
|
|
53
69
|
* Canonical Network (PSND) body — the node rects and edge paths that go inside
|
|
@@ -86,33 +102,8 @@ export function renderActivitiesNetworkBody(layout, cpm, ox, oy, curvature, entr
|
|
|
86
102
|
const isCritical = cpm.get(n.id)?.isCritical ?? false;
|
|
87
103
|
const durVal = n.data.duration;
|
|
88
104
|
const isMilestone = (durVal ?? -1) === 0;
|
|
89
|
-
const cls = `diagram-node act-node ${isCritical ? 'critical-node' : ''} ${isMilestone ? 'milestone-node' : ''}`.trim();
|
|
90
|
-
const idLabel = escXml(n.id);
|
|
91
|
-
const words = n.data.name.split(' ');
|
|
92
|
-
let line1 = '';
|
|
93
|
-
let line2 = '';
|
|
94
|
-
for (const w of words) {
|
|
95
|
-
if ((line1 + ' ' + w).trim().length <= 24)
|
|
96
|
-
line1 = (line1 + ' ' + w).trim();
|
|
97
|
-
else if ((line2 + ' ' + w).trim().length <= 24)
|
|
98
|
-
line2 = (line2 + ' ' + w).trim();
|
|
99
|
-
else if (!line2) {
|
|
100
|
-
line2 = w.slice(0, 22) + '…';
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const twoLines = line2.length > 0;
|
|
105
|
-
const nameY1 = twoLines ? y + 18 : y + 28;
|
|
106
|
-
const nameY2 = y + 34;
|
|
107
|
-
const idY = twoLines ? y + 54 : y + 50;
|
|
108
105
|
const durLabel = (durVal !== undefined && durVal > 0) ? `${durVal}d` : '';
|
|
109
|
-
return
|
|
110
|
-
`<rect class="${cls}" x="${x}" y="${y}" width="${N_NODE_W}" height="${N_NODE_H}" rx="8"/>`,
|
|
111
|
-
`<text class="text-primary" x="${x + N_NODE_W / 2}" y="${nameY1}" text-anchor="middle" dominant-baseline="central">${escXml(line1)}</text>`,
|
|
112
|
-
twoLines ? `<text class="text-primary" x="${x + N_NODE_W / 2}" y="${nameY2}" text-anchor="middle" dominant-baseline="central">${escXml(line2)}</text>` : '',
|
|
113
|
-
`<text class="text-id" x="${x + N_NODE_W / 2}" y="${idY}" text-anchor="middle" dominant-baseline="central">${idLabel}</text>`,
|
|
114
|
-
durLabel ? `<text class="text-secondary" x="${x + N_NODE_W - 8}" y="${y + N_NODE_H - 8}" text-anchor="end">${durLabel}</text>` : '',
|
|
115
|
-
].filter(Boolean).join('\n');
|
|
106
|
+
return activityNodeSvg(n, x, y, isCritical, isMilestone, durLabel);
|
|
116
107
|
})
|
|
117
108
|
.join('\n');
|
|
118
109
|
return `${nodeSvg}\n${edgeSvg}`;
|
|
@@ -132,14 +123,20 @@ export function renderActivitiesNetworkBody(layout, cpm, ox, oy, curvature, entr
|
|
|
132
123
|
* than short-circuiting.
|
|
133
124
|
*/
|
|
134
125
|
export function renderActivitiesSvg(doc, options = {}) {
|
|
135
|
-
const { title = '', gaps = {}, curvature = DEFAULT_EDGE_CURVATURE, entryCurvature, suppressProjectNodes = true, } = options;
|
|
126
|
+
const { title = '', gaps = {}, nodeSizePreset = 'normal', curvature = DEFAULT_EDGE_CURVATURE, entryCurvature, suppressProjectNodes = true, } = options;
|
|
127
|
+
const nodeSize = resolveActionNodeSize(parseNodeSizePreset(nodeSizePreset));
|
|
128
|
+
const layoutGaps = {
|
|
129
|
+
...gaps,
|
|
130
|
+
nodeWidth: gaps.nodeWidth ?? nodeSize.width,
|
|
131
|
+
nodeHeight: gaps.nodeHeight ?? nodeSize.height,
|
|
132
|
+
};
|
|
136
133
|
// #421: Suppress project-type container nodes in the network layout by
|
|
137
134
|
// default (see suppressProjectNodes JSDoc). A shallow copy avoids mutating
|
|
138
135
|
// the caller's doc.
|
|
139
136
|
const renderDoc = suppressProjectNodes
|
|
140
137
|
? { ...doc, activities: (doc.activities ?? []).filter((a) => a.activity_type?.toLowerCase() !== 'project') }
|
|
141
138
|
: doc;
|
|
142
|
-
const layout = layoutActivities(renderDoc,
|
|
139
|
+
const layout = layoutActivities(renderDoc, layoutGaps);
|
|
143
140
|
if (layout.nodes.length === 0) {
|
|
144
141
|
return `<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0" viewBox="0 0 0 0"></svg>`;
|
|
145
142
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { BlocksFile, BlocksLayout } from '../blocks/types.js';
|
|
1
|
+
import type { BlocksFile, BlocksLayout, BlocksLayoutOptions } from '../blocks/types.js';
|
|
2
|
+
import { type NodeSizePreset } from '../node-size-presets.js';
|
|
2
3
|
import { type ThemeId } from '../theme/index.js';
|
|
3
4
|
export interface RenderBlocksOptions {
|
|
4
5
|
title?: string;
|
|
6
|
+
nodeSizePreset?: NodeSizePreset;
|
|
7
|
+
layoutOptions?: BlocksLayoutOptions;
|
|
5
8
|
}
|
|
6
9
|
export interface RenderBlocksLayoutOptions {
|
|
7
10
|
/** Extra vertical space reserved at the top of the canvas (e.g. for a title block). */
|