@yanqirenshi/d3.pad 0.2.0 → 0.3.0

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.
Files changed (183) hide show
  1. package/README.md +86 -18
  2. package/dist/index.d.ts +7 -3
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +15 -6
  5. package/dist/pad/Pad.d.ts +21 -0
  6. package/dist/pad/Pad.d.ts.map +1 -0
  7. package/dist/pad/Pad.js +139 -0
  8. package/dist/pad/PadDiagram.d.ts +19 -0
  9. package/dist/pad/PadDiagram.d.ts.map +1 -0
  10. package/dist/pad/PadDiagram.js +64 -0
  11. package/dist/pad/Theme.d.ts +7 -0
  12. package/dist/pad/Theme.d.ts.map +1 -0
  13. package/dist/pad/Theme.js +10 -0
  14. package/dist/pad/datamodels/Assignment.d.ts +81 -0
  15. package/dist/pad/datamodels/Assignment.d.ts.map +1 -0
  16. package/dist/pad/datamodels/Assignment.js +51 -0
  17. package/dist/pad/datamodels/Call.d.ts +95 -0
  18. package/dist/pad/datamodels/Call.d.ts.map +1 -0
  19. package/dist/pad/datamodels/Call.js +83 -0
  20. package/dist/pad/datamodels/Connector.d.ts +35 -0
  21. package/dist/pad/datamodels/Connector.d.ts.map +1 -0
  22. package/dist/pad/datamodels/Connector.js +23 -0
  23. package/dist/pad/datamodels/Group.d.ts +78 -0
  24. package/dist/pad/datamodels/Group.d.ts.map +1 -0
  25. package/dist/pad/datamodels/Group.js +71 -0
  26. package/dist/pad/datamodels/Loop.d.ts +80 -0
  27. package/dist/pad/datamodels/Loop.d.ts.map +1 -0
  28. package/dist/pad/datamodels/Loop.js +77 -0
  29. package/dist/pad/datamodels/Parallel.d.ts +85 -0
  30. package/dist/pad/datamodels/Parallel.d.ts.map +1 -0
  31. package/dist/pad/datamodels/Parallel.js +80 -0
  32. package/dist/pad/datamodels/Process.d.ts +79 -0
  33. package/dist/pad/datamodels/Process.d.ts.map +1 -0
  34. package/dist/pad/datamodels/Process.js +59 -0
  35. package/dist/pad/datamodels/Selection.d.ts +76 -0
  36. package/dist/pad/datamodels/Selection.d.ts.map +1 -0
  37. package/dist/pad/datamodels/Selection.js +81 -0
  38. package/dist/pad/datamodels/Terminal.d.ts +61 -0
  39. package/dist/pad/datamodels/Terminal.d.ts.map +1 -0
  40. package/dist/pad/datamodels/Terminal.js +50 -0
  41. package/dist/pad/elements.d.ts +2 -0
  42. package/dist/pad/elements.d.ts.map +1 -0
  43. package/dist/pad/elements.js +32 -0
  44. package/dist/pad/painters/Assignment.d.ts +4 -0
  45. package/dist/pad/painters/Assignment.d.ts.map +1 -0
  46. package/dist/pad/painters/Assignment.js +72 -0
  47. package/dist/pad/painters/Call.d.ts +4 -0
  48. package/dist/pad/painters/Call.d.ts.map +1 -0
  49. package/dist/pad/painters/Call.js +134 -0
  50. package/dist/pad/painters/Connector.d.ts +4 -0
  51. package/dist/pad/painters/Connector.d.ts.map +1 -0
  52. package/dist/pad/painters/Connector.js +15 -0
  53. package/dist/pad/painters/Group.d.ts +4 -0
  54. package/dist/pad/painters/Group.d.ts.map +1 -0
  55. package/dist/pad/painters/Group.js +99 -0
  56. package/dist/pad/painters/Loop.d.ts +4 -0
  57. package/dist/pad/painters/Loop.d.ts.map +1 -0
  58. package/dist/pad/painters/Loop.js +126 -0
  59. package/dist/pad/painters/Parallel.d.ts +4 -0
  60. package/dist/pad/painters/Parallel.d.ts.map +1 -0
  61. package/dist/pad/painters/Parallel.js +102 -0
  62. package/dist/pad/painters/Process.d.ts +5 -0
  63. package/dist/pad/painters/Process.d.ts.map +1 -0
  64. package/dist/pad/painters/Process.js +132 -0
  65. package/dist/pad/painters/Selection.d.ts +4 -0
  66. package/dist/pad/painters/Selection.d.ts.map +1 -0
  67. package/dist/pad/painters/Selection.js +126 -0
  68. package/dist/pad/painters/Terminal.d.ts +4 -0
  69. package/dist/pad/painters/Terminal.d.ts.map +1 -0
  70. package/dist/pad/painters/Terminal.js +19 -0
  71. package/dist/pad/painters/interactive.d.ts +2 -0
  72. package/dist/pad/painters/interactive.d.ts.map +1 -0
  73. package/dist/pad/painters/interactive.js +15 -0
  74. package/dist/pad/registry.d.ts +14 -0
  75. package/dist/pad/registry.d.ts.map +1 -0
  76. package/dist/pad/registry.js +25 -0
  77. package/package.json +7 -5
  78. package/src/index.ts +15 -7
  79. package/src/pad/Pad.ts +157 -0
  80. package/src/pad/PadDiagram.tsx +126 -0
  81. package/src/pad/Theme.ts +11 -0
  82. package/src/pad/datamodels/Assignment.ts +55 -0
  83. package/src/pad/datamodels/Call.ts +91 -0
  84. package/src/pad/datamodels/Connector.ts +25 -0
  85. package/src/pad/datamodels/Group.ts +76 -0
  86. package/src/pad/datamodels/Loop.ts +82 -0
  87. package/src/pad/datamodels/Parallel.ts +85 -0
  88. package/src/pad/datamodels/Process.ts +63 -0
  89. package/src/pad/datamodels/Selection.ts +87 -0
  90. package/src/pad/datamodels/Terminal.ts +57 -0
  91. package/src/pad/elements.ts +34 -0
  92. package/src/pad/painters/Assignment.ts +87 -0
  93. package/src/pad/painters/Call.ts +152 -0
  94. package/src/pad/painters/Connector.ts +15 -0
  95. package/src/pad/painters/Group.ts +116 -0
  96. package/src/pad/painters/Loop.ts +144 -0
  97. package/src/pad/painters/Parallel.ts +115 -0
  98. package/src/pad/painters/Process.ts +153 -0
  99. package/src/pad/painters/Selection.ts +150 -0
  100. package/src/pad/painters/Terminal.ts +23 -0
  101. package/src/pad/painters/interactive.ts +15 -0
  102. package/src/pad/registry.ts +38 -0
  103. package/dist/renderers/D3PadRenderer.d.ts +0 -34
  104. package/dist/renderers/D3PadRenderer.d.ts.map +0 -1
  105. package/dist/renderers/D3PadRenderer.js +0 -112
  106. package/dist/renderers/PadNodeRenderer.d.ts +0 -145
  107. package/dist/renderers/PadNodeRenderer.d.ts.map +0 -1
  108. package/dist/renderers/PadNodeRenderer.js +0 -440
  109. package/dist/renderers/blocks/EndBlockGeometry.d.ts +0 -33
  110. package/dist/renderers/blocks/EndBlockGeometry.d.ts.map +0 -1
  111. package/dist/renderers/blocks/EndBlockGeometry.js +0 -44
  112. package/dist/renderers/blocks/EndRenderer.d.ts +0 -10
  113. package/dist/renderers/blocks/EndRenderer.d.ts.map +0 -1
  114. package/dist/renderers/blocks/EndRenderer.js +0 -38
  115. package/dist/renderers/blocks/EndRendererProps.d.ts +0 -6
  116. package/dist/renderers/blocks/EndRendererProps.d.ts.map +0 -1
  117. package/dist/renderers/blocks/EndRendererProps.js +0 -1
  118. package/dist/renderers/blocks/FunctionContainerGeometry.d.ts +0 -29
  119. package/dist/renderers/blocks/FunctionContainerGeometry.d.ts.map +0 -1
  120. package/dist/renderers/blocks/FunctionContainerGeometry.js +0 -46
  121. package/dist/renderers/blocks/FunctionContainerRenderer.d.ts +0 -13
  122. package/dist/renderers/blocks/FunctionContainerRenderer.d.ts.map +0 -1
  123. package/dist/renderers/blocks/FunctionContainerRenderer.js +0 -49
  124. package/dist/renderers/blocks/FunctionHeaderGeometry.d.ts +0 -20
  125. package/dist/renderers/blocks/FunctionHeaderGeometry.d.ts.map +0 -1
  126. package/dist/renderers/blocks/FunctionHeaderGeometry.js +0 -35
  127. package/dist/renderers/blocks/FunctionHeaderProps.d.ts +0 -7
  128. package/dist/renderers/blocks/FunctionHeaderProps.d.ts.map +0 -1
  129. package/dist/renderers/blocks/FunctionHeaderProps.js +0 -1
  130. package/dist/renderers/blocks/FunctionHeaderRenderer.d.ts +0 -11
  131. package/dist/renderers/blocks/FunctionHeaderRenderer.d.ts.map +0 -1
  132. package/dist/renderers/blocks/FunctionHeaderRenderer.js +0 -36
  133. package/dist/renderers/blocks/IfBlockGeometry.d.ts +0 -42
  134. package/dist/renderers/blocks/IfBlockGeometry.d.ts.map +0 -1
  135. package/dist/renderers/blocks/IfBlockGeometry.js +0 -83
  136. package/dist/renderers/blocks/IfRenderer.d.ts +0 -10
  137. package/dist/renderers/blocks/IfRenderer.d.ts.map +0 -1
  138. package/dist/renderers/blocks/IfRenderer.js +0 -69
  139. package/dist/renderers/blocks/IfRendererProps.d.ts +0 -7
  140. package/dist/renderers/blocks/IfRendererProps.d.ts.map +0 -1
  141. package/dist/renderers/blocks/IfRendererProps.js +0 -1
  142. package/dist/renderers/blocks/LoopRenderer.d.ts +0 -12
  143. package/dist/renderers/blocks/LoopRenderer.d.ts.map +0 -1
  144. package/dist/renderers/blocks/LoopRenderer.js +0 -37
  145. package/dist/renderers/blocks/LoopRendererProps.d.ts +0 -8
  146. package/dist/renderers/blocks/LoopRendererProps.d.ts.map +0 -1
  147. package/dist/renderers/blocks/LoopRendererProps.js +0 -1
  148. package/dist/renderers/blocks/Point.d.ts +0 -2
  149. package/dist/renderers/blocks/Point.d.ts.map +0 -1
  150. package/dist/renderers/blocks/Point.js +0 -1
  151. package/dist/renderers/blocks/StartBlockGeometry.d.ts +0 -38
  152. package/dist/renderers/blocks/StartBlockGeometry.d.ts.map +0 -1
  153. package/dist/renderers/blocks/StartBlockGeometry.js +0 -56
  154. package/dist/renderers/blocks/StartRenderer.d.ts +0 -10
  155. package/dist/renderers/blocks/StartRenderer.d.ts.map +0 -1
  156. package/dist/renderers/blocks/StartRenderer.js +0 -39
  157. package/dist/renderers/blocks/StartRendererProps.d.ts +0 -6
  158. package/dist/renderers/blocks/StartRendererProps.d.ts.map +0 -1
  159. package/dist/renderers/blocks/StartRendererProps.js +0 -1
  160. package/dist/utils/layout.d.ts +0 -14
  161. package/dist/utils/layout.d.ts.map +0 -1
  162. package/dist/utils/layout.js +0 -186
  163. package/src/renderers/D3PadRenderer.tsx +0 -145
  164. package/src/renderers/PadNodeRenderer.ts +0 -517
  165. package/src/renderers/blocks/EndBlockGeometry.ts +0 -52
  166. package/src/renderers/blocks/EndRenderer.tsx +0 -48
  167. package/src/renderers/blocks/EndRendererProps.ts +0 -5
  168. package/src/renderers/blocks/FunctionContainerGeometry.ts +0 -54
  169. package/src/renderers/blocks/FunctionContainerRenderer.tsx +0 -62
  170. package/src/renderers/blocks/FunctionHeaderGeometry.ts +0 -43
  171. package/src/renderers/blocks/FunctionHeaderProps.ts +0 -6
  172. package/src/renderers/blocks/FunctionHeaderRenderer.tsx +0 -47
  173. package/src/renderers/blocks/IfBlockGeometry.ts +0 -98
  174. package/src/renderers/blocks/IfRenderer.tsx +0 -88
  175. package/src/renderers/blocks/IfRendererProps.ts +0 -7
  176. package/src/renderers/blocks/LoopRenderer.tsx +0 -50
  177. package/src/renderers/blocks/LoopRendererProps.ts +0 -7
  178. package/src/renderers/blocks/Point.ts +0 -4
  179. package/src/renderers/blocks/README.md +0 -29
  180. package/src/renderers/blocks/StartBlockGeometry.ts +0 -66
  181. package/src/renderers/blocks/StartRenderer.tsx +0 -49
  182. package/src/renderers/blocks/StartRendererProps.ts +0 -5
  183. package/src/utils/layout.ts +0 -247
@@ -0,0 +1,126 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import * as d3 from 'd3';
3
+
4
+ import type Pad from './Pad.js';
5
+
6
+ const ZOOM_EXTENT: [number, number] = [0.2, 5];
7
+
8
+ // libs/pad/js/Pad.js(データ+描画オーケストレータ)を d3 で SVG にマウントする
9
+ // 薄いReactラッパー。@yanqirenshi/d3.deployment の components/D3Deployment.js
10
+ // に倣い、実際の描画処理そのものはここには書かない。
11
+ //
12
+ // responsiveがtrueのときは、pad.canvasWidthを固定値ではなく実際の描画先
13
+ // コンテナの幅に合わせて描き直す(画面幅いっぱいに使う実スクリプトのPAD用)。
14
+ // 未指定(false)のときは、これまで通りpad.canvasWidthを固定幅として使う
15
+ // (PAD要素定義ページ側の見た目は変えない)。
16
+ //
17
+ // zoomableがtrueのときは、マウスホイールでの拡大縮小・ドラッグでの視点移動
18
+ // (d3.zoom)を有効にする。内容はsvg直下のg(layer)に描画し、zoomイベントは
19
+ // そのgのtransformだけを書き換える(Pad側の座標計算には影響しない)。
20
+ //
21
+ // heightを指定すると、その値でSVGの高さを固定する(内容が長い場合は
22
+ // zoomable併用でズーム/パンして見る想定)。未指定時はこれまで通り
23
+ // pad.draw()が返す内容の高さをそのまま使う(PAD要素定義ページ側の
24
+ // 見た目は変えない)。
25
+ // fillHeightがtrueのときは、固定値ではなく実際の描画先コンテナの高さ
26
+ // (親要素からflex/height:100%で渡された縦幅)に合わせてSVGの高さを
27
+ // 決める。コンテナ自身の高さをCSSで確保するため、この場合はコンテナ
28
+ // div自体にheight:100%を与える(SVGの内容量で高さを決めると循環して
29
+ // しまうため)。
30
+ export interface PadDiagramProps {
31
+ pad: Pad;
32
+ /** true なら、描画先コンテナの幅に合わせて描き直す */
33
+ responsive?: boolean;
34
+ /** true なら、ホイールで拡大縮小・ドラッグで視点移動できる */
35
+ zoomable?: boolean;
36
+ /** SVG の高さを固定する */
37
+ height?: number;
38
+ /** true なら、描画先コンテナの高さに合わせる */
39
+ fillHeight?: boolean;
40
+ /**
41
+ * 要素のクリックの通知(クリックされた要素の data を受け取る)。渡さなければ、クリックは何もしない。
42
+ * インスペクタ(たとえば colonoscope)をつなぐ口。ショーケースの .dhn のデモは、ここへインスペクタをつないでいる。
43
+ */
44
+ onElementClick?: ((data: any) => void) | null;
45
+ }
46
+
47
+ // もとは d3.pad.dhn にあった(#284 で移した)。元の PadDiagram は useElementInspector() を直接呼んでいたが、
48
+ // インスペクタへの依存を外し、onElementClick を props で受ける形にした(渡されなければ null = 何もしない)。
49
+ // 型は動きを変えずにゆるめている(any)。
50
+ /* eslint-disable @typescript-eslint/no-explicit-any */
51
+ export default function PadDiagram (props: PadDiagramProps) {
52
+ const pad = props.pad;
53
+ const responsive = props.responsive;
54
+ const zoomable = props.zoomable;
55
+ const fixedHeight = props.height;
56
+ const fillHeight = props.fillHeight;
57
+ const containerRef = useRef<HTMLDivElement>(null);
58
+ const svgRef = useRef<SVGSVGElement>(null);
59
+ const layerRef = useRef<SVGGElement>(null);
60
+ const [size, setSize] = useState({ width: pad.canvasWidth, height: fixedHeight || 80 });
61
+
62
+ const selectElement = props.onElementClick || null;
63
+
64
+ useEffect(()=> {
65
+ if (!zoomable || !svgRef.current) return;
66
+
67
+ const svg = d3.select(svgRef.current);
68
+ const layer = d3.select(layerRef.current);
69
+
70
+ const zoom = d3.zoom<SVGSVGElement, unknown>()
71
+ .scaleExtent(ZOOM_EXTENT)
72
+ .on('zoom', (event)=> layer.attr('transform', event.transform));
73
+
74
+ svg.call(zoom);
75
+
76
+ return ()=> { svg.on('.zoom', null); };
77
+ }, [zoomable]);
78
+
79
+ useEffect(()=> {
80
+ if (!layerRef.current) return;
81
+
82
+ // アンマウント後(タブ切替等でこのcomponentが外れた後)に
83
+ // ResizeObserverの通知が遅れて届くと、既にDOMから外れた
84
+ // layerRef.current にpad.draw()しようとしてnull参照になる
85
+ // (Group等のpainterがgroupへのappend直後にnode()を
86
+ // 使うため)。activeフラグで、片付け後の再描画を防ぐ。
87
+ let active = true;
88
+
89
+ const redraw = ()=> {
90
+ if (!active || !layerRef.current) return;
91
+
92
+ if (responsive && containerRef.current) {
93
+ const width = containerRef.current.clientWidth;
94
+ if (width > 0) pad.canvasWidth = width;
95
+ }
96
+
97
+ pad.onElementClick(selectElement);
98
+
99
+ const place = d3.select(layerRef.current);
100
+ const contentHeight = pad.draw(place);
101
+
102
+ let height = fixedHeight || contentHeight;
103
+ if (fillHeight && containerRef.current && containerRef.current.clientHeight > 0)
104
+ height = containerRef.current.clientHeight;
105
+
106
+ setSize({ width: pad.canvasWidth, height });
107
+ };
108
+
109
+ redraw();
110
+
111
+ if ((!responsive && !fillHeight) || !containerRef.current) return ()=> { active = false; };
112
+
113
+ const observer = new ResizeObserver(redraw);
114
+ observer.observe(containerRef.current);
115
+ return ()=> { active = false; observer.disconnect(); };
116
+ }, [pad, responsive, fillHeight, fixedHeight, selectElement]);
117
+
118
+ return (
119
+ <div ref={containerRef} style={{width: responsive ? '100%' : size.width, height: fillHeight ? '100%' : undefined}}>
120
+ <svg id="pad-canvas" ref={svgRef} width={size.width} height={size.height}
121
+ style={{display: 'block', background: '#fff', cursor: zoomable ? 'grab' : undefined}}>
122
+ <g ref={layerRef}></g>
123
+ </svg>
124
+ </div>
125
+ );
126
+ }
@@ -0,0 +1,11 @@
1
+ // PAD全体の配色ルール。
2
+ // 文字(ラベル等)は視認性を優先して黒(#000)固定。
3
+ // それ以外(線・枠線・塗り)は統一感を出すためグレー(#888)で揃える
4
+ // (開始の白抜きのように、意図的に変える場合は個別に上書きする)。
5
+ const Theme = {
6
+ text: '#000',
7
+ stroke: '#888',
8
+ fill: '#888',
9
+ };
10
+
11
+ export default Theme;
@@ -0,0 +1,55 @@
1
+ // Assignment(代入文)のデータクラス。
2
+ // 代入先(targets)と値(value_text)を「代入先 ← 値」の形で可視化する要素。
3
+ // 値がSQLでもリテラルでも、同じ形で表す。
4
+ // 入力データの正規化のみを担当し、描画は painters/Assignment.ts が担当する
5
+ // (@yanqirenshi/d3.deployment の datamodels/painters 分離に倣う)。
6
+ import Theme from '../Theme.js';
7
+
8
+ const HEIGHT = 44;
9
+ const NOTCH_WIDTH = 12; // 代入先と値を区切る「<」の横幅(浅め)
10
+
11
+ export default class Assignment {
12
+ dataTemplate () {
13
+ return {
14
+ targets_text: '',
15
+ value_text: '',
16
+ description: null, // 説明。無ければnull
17
+ size: { w: 0, h: HEIGHT }, // 幅はテキスト実測後に painter が確定する
18
+ position: { x: 0, y: 0 },
19
+ font: { family: '"Courier New", monospace', size: 14, color: Theme.text },
20
+ stroke: { color: Theme.stroke, width: 1 },
21
+ notch: { width: NOTCH_WIDTH },
22
+ // trueのときConnector用のanchorをbox.x(PADの縦線位置)にする。
23
+ // 見た目(描画位置)は常にbox.xからの左詰め=変わらない。
24
+ anchor_at_spine: false,
25
+ // NOTE: 幅がテキスト実測依存のため、x座標は暫定値(yのみ確定)。
26
+ // painters/Assignment.ts が実測後に確定値へ更新する。
27
+ anchors: { top: { x: 0, y: 0 }, bottom: { x: 0, y: HEIGHT } },
28
+ _id: null,
29
+ _core: null,
30
+ _class: 'ASSIGNMENT',
31
+ };
32
+ }
33
+
34
+ // core: { id, targets: string[], value_text: string, description?: string }
35
+ // box: { x, y, width, center } 配置先の左上座標。widthはこの要素では
36
+ // 使わない(テキストにちょうど収まる幅で描画するため)。
37
+ normalize (core: any, box: any) {
38
+ if (!core) return null;
39
+
40
+ const data = this.dataTemplate();
41
+ data._core = core;
42
+ data._id = core.id;
43
+ data.targets_text = (core.targets || []).join(', ');
44
+ data.value_text = core.value_text || '';
45
+ data.description = core.description || null;
46
+ data.position = { x: box.x, y: box.y };
47
+ data.anchor_at_spine = !!box.center;
48
+ data.anchors = {
49
+ top: { x: box.x, y: box.y },
50
+ bottom: { x: box.x, y: box.y + HEIGHT },
51
+ };
52
+
53
+ return data;
54
+ }
55
+ }
@@ -0,0 +1,91 @@
1
+ // CALL(呼び出し)のデータクラス。
2
+ // 箱の中身(cells・dividers・links)は PROCESS と同じ形で、箱自体の見た目も PROCESS と同じ
3
+ // (painters/Process.ts の drawCells をそのまま使う)。違うのは、呼び出し先(callee)を持てることだけ。
4
+ // callee は、呼び出し先のノードの配列(PROCESS などの入力の配列。Pad に渡すものと同じ)。
5
+ // 無ければ(または空なら)箱だけを描く。callee の中にさらに CALL があれば、同じ規則で入れ子に開く。
6
+ // 入れ子の CALL の開閉は、いちばん外の Pad から描き直す(painters/Call.ts が data.redraw を呼び出し先の Pad に渡す)。
7
+ // 入力データの正規化のみを担当し、描画は painters/Call.ts が担当する。
8
+ //
9
+ // 箱の中身の文言(たとえば 'execute' とファイル名)は、要素の中に固定しない。使う側が cells に入れる。
10
+ // (もとは d3.pad.dhn の EXECUTE が持っていた動きを、固有の言葉を抜いて汎用にしたもの。#290)
11
+ import Theme from '../Theme.js';
12
+ import { PAD } from '../registry.js';
13
+
14
+ const HEIGHT = 44;
15
+ const CHEVRON_DEPTH = 12;
16
+ const CALLEE_PAD_WIDTH = 750;
17
+ const CALLEE_PAD_GAP = 24;
18
+
19
+ /** 「開く」「閉じる」の文言の既定 */
20
+ export const DEFAULT_CALL_LABELS = { open: '開く', close: '閉じる' };
21
+
22
+ /* eslint-disable @typescript-eslint/no-explicit-any */
23
+
24
+ // 呼び出し先のノードの配列から、実際に描画・高さ計測に使う Pad インスタンスを組み立てる。
25
+ // datamodel 側の事前の高さ計算(後続要素と重ならないためのスペース確保)と、painter 側の実描画とで
26
+ // 同じジオメトリになるよう、生成方法をここに 1 箇所だけ持つ。
27
+ // Pad は Pad.ts を import せず、registry.ts の PAD から取り出す(Pad.ts が読み込まれたときに入れる)。
28
+ // Pad.ts ↔ このファイルの循環参照を避けるため。Pad.ts を読まずにここだけ読んでも、読み込みでは落ちない。
29
+ export function buildCalleePad (nodes: any[]) {
30
+ const PadClass = PAD.Pad;
31
+ if (!PadClass) throw new Error('Pad が登録されていません(Pad.ts を先に読み込むこと)');
32
+ return new PadClass({ width: CALLEE_PAD_WIDTH, gap: CALLEE_PAD_GAP, center: true }).data(nodes);
33
+ }
34
+
35
+ export default class Call {
36
+ dataTemplate () {
37
+ return {
38
+ cells: [] as any[],
39
+ dividers: [] as any[],
40
+ links: [] as any[],
41
+ callee: null as any[] | null, // 呼び出し先のノードの配列(あれば、その箱の右に開く)
42
+ expanded: true, // false なら呼び出し先を畳んで隠す(painters/Call.ts の「開く/閉じる」)
43
+ labels: { ...DEFAULT_CALL_LABELS }, // 開閉の文言
44
+ font: { family: '"Courier New", monospace', size: 14, color: Theme.text },
45
+ stroke: { color: Theme.stroke, width: 1 },
46
+ chevron_depth: CHEVRON_DEPTH,
47
+ size: { w: 0, h: HEIGHT }, // 幅はテキスト実測後に painter が確定する
48
+ position: { x: 0, y: 0 },
49
+ // true のとき Connector 用の anchor を box.x(PAD の縦線位置)にする。
50
+ // 見た目(描画位置)は常に box.x からの左詰め=変わらない。
51
+ anchor_at_spine: false,
52
+ anchors: { top: { x: 0, y: 0 }, bottom: { x: 0, y: HEIGHT } },
53
+ _id: null as any,
54
+ _core: null as any,
55
+ _class: 'CALL',
56
+ };
57
+ }
58
+
59
+ normalize (core: any, box: any) {
60
+ if (!core) return null;
61
+
62
+ const data = this.dataTemplate();
63
+ data._core = core;
64
+ data._id = core.id;
65
+ data.cells = core.cells || [];
66
+ data.dividers = core.dividers || [];
67
+ data.links = core.links || [];
68
+ data.callee = core.callee || null;
69
+ data.expanded = core.expanded !== false;
70
+ data.labels = { ...DEFAULT_CALL_LABELS, ...(core.labels || {}) };
71
+ data.position = { x: box.x, y: box.y };
72
+ data.anchor_at_spine = !!box.center;
73
+
74
+ // 呼び出し先(あれば、かつ「開く」状態のときだけ)は自分の箱の上端に揃えて(下方向にだけ)
75
+ // 配置する(painters/Call.ts 参照)。上方向には広がらないため、前の行との間で重なることはない。
76
+ // その全高が自分の箱の高さより大きい分だけ、後続の要素と重ならないよう自分の高さ
77
+ // (anchors.bottom.y)を広げておく。「閉じる」状態では呼び出し先ぶんの高さを確保しない。
78
+ let height = HEIGHT;
79
+ if (data.expanded && data.callee && data.callee.length) {
80
+ const calleeHeight = buildCalleePad(data.callee).layout().height;
81
+ height = Math.max(HEIGHT, calleeHeight);
82
+ }
83
+
84
+ data.anchors = {
85
+ top: { x: box.x, y: box.y },
86
+ bottom: { x: box.x, y: box.y + height },
87
+ };
88
+
89
+ return data;
90
+ }
91
+ }
@@ -0,0 +1,25 @@
1
+ // Connector(要素間をつなぐ縦線)のデータクラス。
2
+ // PADは要素を上から下へ積み重ねた「幹」の上に並べる構造のため、隣接する
3
+ // 要素同士は必ずこの線でつながる。Pad.ts が要素を並べる際に、直前の要素の
4
+ // anchors.bottom と直後の要素の anchors.top から自動的に生成する
5
+ // (データ側で個別に指定する要素ではない)。
6
+ import Theme from '../Theme.js';
7
+
8
+ export default class Connector {
9
+ dataTemplate () {
10
+ return {
11
+ from: { x: 0, y: 0 },
12
+ to: { x: 0, y: 0 },
13
+ stroke: { color: Theme.stroke, width: 1 },
14
+ _id: null,
15
+ _class: 'CONNECTOR',
16
+ };
17
+ }
18
+
19
+ normalize (from: any, to: any) {
20
+ const data = this.dataTemplate();
21
+ data.from = from;
22
+ data.to = to;
23
+ return data;
24
+ }
25
+ }
@@ -0,0 +1,76 @@
1
+ // GROUP(まとまり)のデータクラス。
2
+ // 「連続性のある処理のベース」+「複数処理の実行」の考え方に基づき、まとまりの名前
3
+ // (label、例:'SET'。省略すると空)を左側に表示し、右側に本体(rows、まとまりに
4
+ // 含める要素を1行ずつ積み重ねる)を並べる。LOOPと同じくPad本体のレジストリ
5
+ // (registry.ts)で対応するデータクラスに振り分ける(_class省略時はPROCESS扱い)。
6
+ // 入力データの正規化のみを担当し、描画は painters/Group.ts が担当する
7
+ // (@yanqirenshi/d3.deployment の datamodels/painters 分離に倣う)。
8
+ import Theme from '../Theme.js';
9
+ import { ELEMENTS } from '../registry.js';
10
+
11
+ const ROW_GAP = 11;
12
+ const LABEL_HEIGHT = 44; // 名前の箱の高さ(painters/Group.ts の LABEL_HEIGHT と同じ)
13
+
14
+ export default class Group {
15
+ dataTemplate () {
16
+ return {
17
+ label: '', // まとまりの名前(例:'SET'。左側のボックスに表示する)
18
+ rows: [], // { _class?: string, ... }[](_class省略時はPROCESS扱い)
19
+ font: { family: '"Courier New", monospace', size: 14, color: Theme.text },
20
+ stroke: { color: Theme.stroke, width: 1 },
21
+ row_gap: ROW_GAP,
22
+ chevron_depth: 12,
23
+ size: { w: 0, h: 0 }, // 幅・高さともに描画時(実測後)に確定する
24
+ position: { x: 0, y: 0 },
25
+ // trueのときConnector用のanchorをbox.x(PADの縦線位置)にする。
26
+ // 見た目(描画位置)は常にbox.xからの左詰め=変わらない。
27
+ anchor_at_spine: false,
28
+ // NOTE: 幅がテキスト実測依存のため、x座標は暫定値(yのみ確定)。
29
+ // painters/Group.ts が実測後に確定値へ更新する。
30
+ anchors: { top: { x: 0, y: 0 }, bottom: { x: 0, y: 0 } },
31
+ _id: null,
32
+ _core: null,
33
+ _class: 'GROUP',
34
+ };
35
+ }
36
+
37
+ // 各行のデータクラスにnormalizeさせて高さだけを求める(LOOPと同じ
38
+ // 考え方。高さは常にデータから確定できるためDOM計測を伴わない)。
39
+ // 数えるのは、実際に描く行だけ(知らない _class の行は、painter が飛ばす)。行が無くても、条件・ラベルの箱
40
+ // (LABEL_HEIGHT)は描かれるので、それを最低の高さとする(painter の totalHeight と同じ式にそろえる。#307)。
41
+ measureRowsHeight (rows: any, rowGap: any) {
42
+ let y = 0;
43
+ let drawn = 0;
44
+ for (const row of rows) {
45
+ const rowClass = row._class || 'PROCESS';
46
+ const entry = ELEMENTS[rowClass];
47
+ if (!entry) continue;
48
+ const model = new entry.datamodel();
49
+ const rowData = model.normalize(row, { x: 0, y, width: 0, center: false });
50
+ y = rowData.anchors.bottom.y + rowGap;
51
+ drawn++;
52
+ }
53
+ return Math.max(LABEL_HEIGHT, drawn ? y - rowGap : 0);
54
+ }
55
+
56
+ // core: { id, label?: string, rows: ({_class?, ...})[] }
57
+ normalize (core: any, box: any) {
58
+ if (!core) return null;
59
+
60
+ const data = this.dataTemplate();
61
+ data._core = core;
62
+ data._id = core.id;
63
+ data.label = core.label || '';
64
+ data.rows = core.rows || [];
65
+ data.position = { x: box.x, y: box.y };
66
+ data.anchor_at_spine = !!box.center;
67
+
68
+ const height = this.measureRowsHeight(data.rows, data.row_gap);
69
+ data.anchors = {
70
+ top: { x: box.x, y: box.y },
71
+ bottom: { x: box.x, y: box.y + height },
72
+ };
73
+
74
+ return data;
75
+ }
76
+ }
@@ -0,0 +1,82 @@
1
+ // LOOP(反復)のデータクラス。
2
+ // 元のPAD(Problem Analysis Diagram)が持つ「反復」記号に相当する
3
+ // (PARALLEL等とは異なり、拡張ではなく本来のPAD要素)。
4
+ // 反復の条件(condition、例:'@CALENDAR' や 'i < 10')を左側に固定表示し、右側に
5
+ // 本体(rows)を積み重ねる。test: 'pre'(前判定。既定)は条件の箱の左に二重線、
6
+ // test: 'post'(後判定)は右に二重線を描く。各行は { _class, ...そのクラスの入力形式 } を
7
+ // 持ち、Pad本体と同じレジストリ(registry.ts)で対応するデータクラスに
8
+ // 振り分ける(_class省略時はPROCESS扱い)。これにより、本体の1行として
9
+ // PARALLEL等を入れ子にできる。
10
+ // 入力データの正規化のみを担当し、描画は painters/Loop.ts が担当する
11
+ import Theme from '../Theme.js';
12
+ import { ELEMENTS } from '../registry.js';
13
+
14
+ const ROW_GAP = 11;
15
+ const LABEL_HEIGHT = 44; // 条件の箱の高さ(painters/Loop.ts の LABEL_HEIGHT と同じ)
16
+
17
+ export default class Loop {
18
+ dataTemplate () {
19
+ return {
20
+ condition: '', // 反復の条件(例:'@CALENDAR')
21
+ test: 'pre' as 'pre' | 'post', // 前判定(二重線が左)か後判定(二重線が右)か
22
+ rows: [], // { _class?: string, ... }[](_class省略時はPROCESS扱い)
23
+ font: { family: '"Courier New", monospace', size: 14, color: Theme.text },
24
+ stroke: { color: Theme.stroke, width: 1 },
25
+ row_gap: ROW_GAP,
26
+ chevron_depth: 12,
27
+ size: { w: 0, h: 0 }, // 幅・高さともに描画時(実測後)に確定する
28
+ position: { x: 0, y: 0 },
29
+ // trueのときConnector用のanchorをbox.x(PADの縦線位置)にする。
30
+ // 見た目(描画位置)は常にbox.xからの左詰め=変わらない。
31
+ anchor_at_spine: false,
32
+ // NOTE: 幅がテキスト実測依存のため、x座標は暫定値(yのみ確定)。
33
+ // painters/Loop.ts が実測後に確定値へ更新する。
34
+ anchors: { top: { x: 0, y: 0 }, bottom: { x: 0, y: 0 } },
35
+ _id: null,
36
+ _core: null,
37
+ _class: 'LOOP',
38
+ };
39
+ }
40
+
41
+ // 各行のデータクラスにnormalizeさせて高さだけを求める。PROCESS/PARALLEL
42
+ // 等どの要素も高さは常にデータ(引数の個数・PARALLELならtasksの数)から
43
+ // 確定できるため、ここではDOM計測を伴わない(幅の実測は描画時のみ必要)。
44
+ // 数えるのは、実際に描く行だけ(知らない _class の行は、painter が飛ばす)。行が無くても、条件・ラベルの箱
45
+ // (LABEL_HEIGHT)は描かれるので、それを最低の高さとする(painter の totalHeight と同じ式にそろえる。#307)。
46
+ measureRowsHeight (rows: any, rowGap: any) {
47
+ let y = 0;
48
+ let drawn = 0;
49
+ for (const row of rows) {
50
+ const rowClass = row._class || 'PROCESS';
51
+ const entry = ELEMENTS[rowClass];
52
+ if (!entry) continue;
53
+ const model = new entry.datamodel();
54
+ const rowData = model.normalize(row, { x: 0, y, width: 0, center: false });
55
+ y = rowData.anchors.bottom.y + rowGap;
56
+ drawn++;
57
+ }
58
+ return Math.max(LABEL_HEIGHT, drawn ? y - rowGap : 0);
59
+ }
60
+
61
+ // core: { id, condition: string, test?: 'pre' | 'post', rows: ({_class?, ...})[] }
62
+ normalize (core: any, box: any) {
63
+ if (!core) return null;
64
+
65
+ const data = this.dataTemplate();
66
+ data._core = core;
67
+ data._id = core.id;
68
+ data.condition = core.condition || '';
69
+ data.test = core.test === 'post' ? 'post' : 'pre';
70
+ data.rows = core.rows || [];
71
+ data.position = { x: box.x, y: box.y };
72
+ data.anchor_at_spine = !!box.center;
73
+
74
+ const height = this.measureRowsHeight(data.rows, data.row_gap);
75
+ data.anchors = {
76
+ top: { x: box.x, y: box.y },
77
+ bottom: { x: box.x, y: box.y + height },
78
+ };
79
+
80
+ return data;
81
+ }
82
+ }
@@ -0,0 +1,85 @@
1
+ // Parallel(PARALLEL { TASK{...} TASK{...} })のデータクラス。
2
+ // 元のPAD(Problem Analysis Diagram)には無い記号だが、複数の処理が並行して
3
+ // 走ることを図示するためにこのプロジェクト独自に追加する。
4
+ // 各TASKは、従来通りPROCESS要素そのもの({cells, dividers})1行として
5
+ // 描画するか、あるいは複数の文が連続するTASK(例: 同じ処理を続けて2回
6
+ // 呼ぶ等)を表すために{rows: [...]}として複数行を持てる
7
+ // (rowsはLOOP/SELECTIONの本体と同じくregistry.ts経由で_classごとに描画する。
8
+ // _class省略時はPROCESS扱い)。
9
+ // 入力データの正規化のみを担当し、描画は painters/Parallel.ts が担当する
10
+ // (@yanqirenshi/d3.deployment の datamodels/painters 分離に倣う)。
11
+ import Theme from '../Theme.js';
12
+ import { ELEMENTS } from '../registry.js';
13
+
14
+ const ROW_HEIGHT = 44;
15
+ const ROW_GAP = 11; // TASK同士(要素間)・TASK内の行同士の余白
16
+ const BRACKET_WIDTH = 12; // 左のブラケット(矩形)の幅
17
+ const BRACKET_MARGIN = 0; // ブラケットと本体(行)の間隔
18
+
19
+ // 1つのTASKの高さを求める。{rows: [...]}を持つTASKは本体(LOOP/SELECTIONの
20
+ // bodyと同じ考え方)としてregistry.ts経由で各行の高さを積み上げる。
21
+ // 持たないTASK(従来通りの{cells, dividers})は固定のROW_HEIGHTとする。
22
+ // {rows: [...]}を持っても、描ける行が無い(空・知らない_classだけ)TASKは、painters/Parallel.tsと同じく
23
+ // ROW_HEIGHTとする(数えるのは、実際に描く行だけ。#307)。
24
+ function taskHeight (task: any, rowGap: any) {
25
+ if (!task.rows) return ROW_HEIGHT;
26
+
27
+ let y = 0;
28
+ let drawn = 0;
29
+ for (const row of task.rows) {
30
+ const rowClass = row._class || 'PROCESS';
31
+ const entry = ELEMENTS[rowClass];
32
+ if (!entry) continue;
33
+ const model = new entry.datamodel();
34
+ const rowData = model.normalize(row, { x: 0, y, width: 0, center: false });
35
+ y = rowData.anchors.bottom.y + rowGap;
36
+ drawn++;
37
+ }
38
+ return drawn ? y - rowGap : ROW_HEIGHT;
39
+ }
40
+
41
+ export default class Parallel {
42
+ dataTemplate () {
43
+ return {
44
+ // tasks: ({ cells: string[], dividers: (...)[] } | { rows: ({_class?, ...})[] })[]
45
+ tasks: [],
46
+ font: { family: '"Courier New", monospace', size: 14, color: Theme.text },
47
+ stroke: { color: Theme.stroke, width: 1 },
48
+ row_height: ROW_HEIGHT,
49
+ row_gap: ROW_GAP,
50
+ bracket: { width: BRACKET_WIDTH, margin: BRACKET_MARGIN },
51
+ chevron_depth: 12,
52
+ size: { w: 0, h: 0 }, // 幅・高さともに描画時(実測後)に確定する
53
+ position: { x: 0, y: 0 },
54
+ // trueのときConnector用のanchorをbox.x(PADの縦線位置)にする。
55
+ // 見た目(描画位置)は常にbox.xからの左詰め=変わらない。
56
+ anchor_at_spine: false,
57
+ // NOTE: 幅がテキスト実測依存のため、x座標は暫定値(yのみ確定)。
58
+ // painters/Parallel.ts が実測後に確定値へ更新する。
59
+ anchors: { top: { x: 0, y: 0 }, bottom: { x: 0, y: 0 } },
60
+ _id: null,
61
+ _core: null,
62
+ _class: 'PARALLEL',
63
+ };
64
+ }
65
+
66
+ normalize (core: any, box: any) {
67
+ if (!core) return null;
68
+
69
+ const data = this.dataTemplate();
70
+ data._core = core;
71
+ data._id = core.id;
72
+ data.tasks = core.tasks || [];
73
+ data.position = { x: box.x, y: box.y };
74
+ data.anchor_at_spine = !!box.center;
75
+
76
+ const n = data.tasks.length;
77
+ const h = data.tasks.reduce((sum, task)=> sum + taskHeight(task, ROW_GAP) + ROW_GAP, 0) - (n ? ROW_GAP : 0);
78
+ data.anchors = {
79
+ top: { x: box.x, y: box.y },
80
+ bottom: { x: box.x, y: box.y + h },
81
+ };
82
+
83
+ return data;
84
+ }
85
+ }
@@ -0,0 +1,63 @@
1
+ // PROCESS(処理)のデータクラス。
2
+ // 1つの処理を、四角い箱の中の「ラベル+引数」の並び(cells)として表す。
3
+ // セルの区切り(dividers)は点線・実線・山形、セルごとにリンク(links)も付けられる。
4
+ // 何をセルに入れるかは、使う側が決める(要素は文言を固定しない)。
5
+ // 入力データの正規化のみを担当し、描画は painters/Process.ts が担当する
6
+ // (@yanqirenshi/d3.deployment の datamodels/painters 分離に倣う)。
7
+ import Theme from '../Theme.js';
8
+
9
+ const HEIGHT = 44;
10
+ const CHEVRON_DEPTH = 12;
11
+
12
+ export default class Process {
13
+ dataTemplate () {
14
+ return {
15
+ // cells: string[](先頭はラベル。以降は表示する引数)
16
+ // dividers: ('dotted'|'solid'|{type:'chevron', direction:'left'|'right'})[]
17
+ // 要素数は cells.length - 1。dotted=ラベルと最初の引数の区切り、
18
+ // solid=引数同士の区切り、chevron=前の値が次の値へ流れ込む
19
+ // (Assignmentの「<」と同じ役割)ことを表す。
20
+ cells: [],
21
+ dividers: [],
22
+ // cellsと同じ長さの配列(省略可)。リンクさせたいセルの位置に
23
+ // URL文字列、それ以外はnullを入れる(例: dwmem_load/dwtab_rebuild
24
+ // が対象とするテーブル名セルをWBSページへのリンクにする)。
25
+ links: [],
26
+ description: null, // 箱の右に添える説明。無ければnull
27
+ font: { family: '"Courier New", monospace', size: 14, color: Theme.text },
28
+ stroke: { color: Theme.stroke, width: 1 },
29
+ chevron_depth: CHEVRON_DEPTH,
30
+ size: { w: 0, h: HEIGHT }, // 幅はテキスト実測後に painter が確定する
31
+ position: { x: 0, y: 0 },
32
+ // trueのときConnector用のanchorをbox.x(PADの縦線位置)にする。
33
+ // 見た目(描画位置)は常にbox.xからの左詰め=変わらない。
34
+ anchor_at_spine: false,
35
+ // NOTE: 幅がテキスト実測依存のため、x座標は暫定値(yのみ確定)。
36
+ // painters/Process.ts が実測後に確定値へ更新する。
37
+ anchors: { top: { x: 0, y: 0 }, bottom: { x: 0, y: HEIGHT } },
38
+ _id: null,
39
+ _core: null,
40
+ _class: 'PROCESS',
41
+ };
42
+ }
43
+
44
+ normalize (core: any, box: any) {
45
+ if (!core) return null;
46
+
47
+ const data = this.dataTemplate();
48
+ data._core = core;
49
+ data._id = core.id;
50
+ data.cells = core.cells || [];
51
+ data.dividers = core.dividers || [];
52
+ data.links = core.links || [];
53
+ data.description = core.description || null;
54
+ data.position = { x: box.x, y: box.y };
55
+ data.anchor_at_spine = !!box.center;
56
+ data.anchors = {
57
+ top: { x: box.x, y: box.y },
58
+ bottom: { x: box.x, y: box.y + HEIGHT },
59
+ };
60
+
61
+ return data;
62
+ }
63
+ }