@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.
- package/README.md +86 -18
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -6
- package/dist/pad/Pad.d.ts +21 -0
- package/dist/pad/Pad.d.ts.map +1 -0
- package/dist/pad/Pad.js +139 -0
- package/dist/pad/PadDiagram.d.ts +19 -0
- package/dist/pad/PadDiagram.d.ts.map +1 -0
- package/dist/pad/PadDiagram.js +64 -0
- package/dist/pad/Theme.d.ts +7 -0
- package/dist/pad/Theme.d.ts.map +1 -0
- package/dist/pad/Theme.js +10 -0
- package/dist/pad/datamodels/Assignment.d.ts +81 -0
- package/dist/pad/datamodels/Assignment.d.ts.map +1 -0
- package/dist/pad/datamodels/Assignment.js +51 -0
- package/dist/pad/datamodels/Call.d.ts +95 -0
- package/dist/pad/datamodels/Call.d.ts.map +1 -0
- package/dist/pad/datamodels/Call.js +83 -0
- package/dist/pad/datamodels/Connector.d.ts +35 -0
- package/dist/pad/datamodels/Connector.d.ts.map +1 -0
- package/dist/pad/datamodels/Connector.js +23 -0
- package/dist/pad/datamodels/Group.d.ts +78 -0
- package/dist/pad/datamodels/Group.d.ts.map +1 -0
- package/dist/pad/datamodels/Group.js +71 -0
- package/dist/pad/datamodels/Loop.d.ts +80 -0
- package/dist/pad/datamodels/Loop.d.ts.map +1 -0
- package/dist/pad/datamodels/Loop.js +77 -0
- package/dist/pad/datamodels/Parallel.d.ts +85 -0
- package/dist/pad/datamodels/Parallel.d.ts.map +1 -0
- package/dist/pad/datamodels/Parallel.js +80 -0
- package/dist/pad/datamodels/Process.d.ts +79 -0
- package/dist/pad/datamodels/Process.d.ts.map +1 -0
- package/dist/pad/datamodels/Process.js +59 -0
- package/dist/pad/datamodels/Selection.d.ts +76 -0
- package/dist/pad/datamodels/Selection.d.ts.map +1 -0
- package/dist/pad/datamodels/Selection.js +81 -0
- package/dist/pad/datamodels/Terminal.d.ts +61 -0
- package/dist/pad/datamodels/Terminal.d.ts.map +1 -0
- package/dist/pad/datamodels/Terminal.js +50 -0
- package/dist/pad/elements.d.ts +2 -0
- package/dist/pad/elements.d.ts.map +1 -0
- package/dist/pad/elements.js +32 -0
- package/dist/pad/painters/Assignment.d.ts +4 -0
- package/dist/pad/painters/Assignment.d.ts.map +1 -0
- package/dist/pad/painters/Assignment.js +72 -0
- package/dist/pad/painters/Call.d.ts +4 -0
- package/dist/pad/painters/Call.d.ts.map +1 -0
- package/dist/pad/painters/Call.js +134 -0
- package/dist/pad/painters/Connector.d.ts +4 -0
- package/dist/pad/painters/Connector.d.ts.map +1 -0
- package/dist/pad/painters/Connector.js +15 -0
- package/dist/pad/painters/Group.d.ts +4 -0
- package/dist/pad/painters/Group.d.ts.map +1 -0
- package/dist/pad/painters/Group.js +99 -0
- package/dist/pad/painters/Loop.d.ts +4 -0
- package/dist/pad/painters/Loop.d.ts.map +1 -0
- package/dist/pad/painters/Loop.js +126 -0
- package/dist/pad/painters/Parallel.d.ts +4 -0
- package/dist/pad/painters/Parallel.d.ts.map +1 -0
- package/dist/pad/painters/Parallel.js +102 -0
- package/dist/pad/painters/Process.d.ts +5 -0
- package/dist/pad/painters/Process.d.ts.map +1 -0
- package/dist/pad/painters/Process.js +132 -0
- package/dist/pad/painters/Selection.d.ts +4 -0
- package/dist/pad/painters/Selection.d.ts.map +1 -0
- package/dist/pad/painters/Selection.js +126 -0
- package/dist/pad/painters/Terminal.d.ts +4 -0
- package/dist/pad/painters/Terminal.d.ts.map +1 -0
- package/dist/pad/painters/Terminal.js +19 -0
- package/dist/pad/painters/interactive.d.ts +2 -0
- package/dist/pad/painters/interactive.d.ts.map +1 -0
- package/dist/pad/painters/interactive.js +15 -0
- package/dist/pad/registry.d.ts +14 -0
- package/dist/pad/registry.d.ts.map +1 -0
- package/dist/pad/registry.js +25 -0
- package/package.json +7 -5
- package/src/index.ts +15 -7
- package/src/pad/Pad.ts +157 -0
- package/src/pad/PadDiagram.tsx +126 -0
- package/src/pad/Theme.ts +11 -0
- package/src/pad/datamodels/Assignment.ts +55 -0
- package/src/pad/datamodels/Call.ts +91 -0
- package/src/pad/datamodels/Connector.ts +25 -0
- package/src/pad/datamodels/Group.ts +76 -0
- package/src/pad/datamodels/Loop.ts +82 -0
- package/src/pad/datamodels/Parallel.ts +85 -0
- package/src/pad/datamodels/Process.ts +63 -0
- package/src/pad/datamodels/Selection.ts +87 -0
- package/src/pad/datamodels/Terminal.ts +57 -0
- package/src/pad/elements.ts +34 -0
- package/src/pad/painters/Assignment.ts +87 -0
- package/src/pad/painters/Call.ts +152 -0
- package/src/pad/painters/Connector.ts +15 -0
- package/src/pad/painters/Group.ts +116 -0
- package/src/pad/painters/Loop.ts +144 -0
- package/src/pad/painters/Parallel.ts +115 -0
- package/src/pad/painters/Process.ts +153 -0
- package/src/pad/painters/Selection.ts +150 -0
- package/src/pad/painters/Terminal.ts +23 -0
- package/src/pad/painters/interactive.ts +15 -0
- package/src/pad/registry.ts +38 -0
- package/dist/renderers/D3PadRenderer.d.ts +0 -34
- package/dist/renderers/D3PadRenderer.d.ts.map +0 -1
- package/dist/renderers/D3PadRenderer.js +0 -112
- package/dist/renderers/PadNodeRenderer.d.ts +0 -145
- package/dist/renderers/PadNodeRenderer.d.ts.map +0 -1
- package/dist/renderers/PadNodeRenderer.js +0 -440
- package/dist/renderers/blocks/EndBlockGeometry.d.ts +0 -33
- package/dist/renderers/blocks/EndBlockGeometry.d.ts.map +0 -1
- package/dist/renderers/blocks/EndBlockGeometry.js +0 -44
- package/dist/renderers/blocks/EndRenderer.d.ts +0 -10
- package/dist/renderers/blocks/EndRenderer.d.ts.map +0 -1
- package/dist/renderers/blocks/EndRenderer.js +0 -38
- package/dist/renderers/blocks/EndRendererProps.d.ts +0 -6
- package/dist/renderers/blocks/EndRendererProps.d.ts.map +0 -1
- package/dist/renderers/blocks/EndRendererProps.js +0 -1
- package/dist/renderers/blocks/FunctionContainerGeometry.d.ts +0 -29
- package/dist/renderers/blocks/FunctionContainerGeometry.d.ts.map +0 -1
- package/dist/renderers/blocks/FunctionContainerGeometry.js +0 -46
- package/dist/renderers/blocks/FunctionContainerRenderer.d.ts +0 -13
- package/dist/renderers/blocks/FunctionContainerRenderer.d.ts.map +0 -1
- package/dist/renderers/blocks/FunctionContainerRenderer.js +0 -49
- package/dist/renderers/blocks/FunctionHeaderGeometry.d.ts +0 -20
- package/dist/renderers/blocks/FunctionHeaderGeometry.d.ts.map +0 -1
- package/dist/renderers/blocks/FunctionHeaderGeometry.js +0 -35
- package/dist/renderers/blocks/FunctionHeaderProps.d.ts +0 -7
- package/dist/renderers/blocks/FunctionHeaderProps.d.ts.map +0 -1
- package/dist/renderers/blocks/FunctionHeaderProps.js +0 -1
- package/dist/renderers/blocks/FunctionHeaderRenderer.d.ts +0 -11
- package/dist/renderers/blocks/FunctionHeaderRenderer.d.ts.map +0 -1
- package/dist/renderers/blocks/FunctionHeaderRenderer.js +0 -36
- package/dist/renderers/blocks/IfBlockGeometry.d.ts +0 -42
- package/dist/renderers/blocks/IfBlockGeometry.d.ts.map +0 -1
- package/dist/renderers/blocks/IfBlockGeometry.js +0 -83
- package/dist/renderers/blocks/IfRenderer.d.ts +0 -10
- package/dist/renderers/blocks/IfRenderer.d.ts.map +0 -1
- package/dist/renderers/blocks/IfRenderer.js +0 -69
- package/dist/renderers/blocks/IfRendererProps.d.ts +0 -7
- package/dist/renderers/blocks/IfRendererProps.d.ts.map +0 -1
- package/dist/renderers/blocks/IfRendererProps.js +0 -1
- package/dist/renderers/blocks/LoopRenderer.d.ts +0 -12
- package/dist/renderers/blocks/LoopRenderer.d.ts.map +0 -1
- package/dist/renderers/blocks/LoopRenderer.js +0 -37
- package/dist/renderers/blocks/LoopRendererProps.d.ts +0 -8
- package/dist/renderers/blocks/LoopRendererProps.d.ts.map +0 -1
- package/dist/renderers/blocks/LoopRendererProps.js +0 -1
- package/dist/renderers/blocks/Point.d.ts +0 -2
- package/dist/renderers/blocks/Point.d.ts.map +0 -1
- package/dist/renderers/blocks/Point.js +0 -1
- package/dist/renderers/blocks/StartBlockGeometry.d.ts +0 -38
- package/dist/renderers/blocks/StartBlockGeometry.d.ts.map +0 -1
- package/dist/renderers/blocks/StartBlockGeometry.js +0 -56
- package/dist/renderers/blocks/StartRenderer.d.ts +0 -10
- package/dist/renderers/blocks/StartRenderer.d.ts.map +0 -1
- package/dist/renderers/blocks/StartRenderer.js +0 -39
- package/dist/renderers/blocks/StartRendererProps.d.ts +0 -6
- package/dist/renderers/blocks/StartRendererProps.d.ts.map +0 -1
- package/dist/renderers/blocks/StartRendererProps.js +0 -1
- package/dist/utils/layout.d.ts +0 -14
- package/dist/utils/layout.d.ts.map +0 -1
- package/dist/utils/layout.js +0 -186
- package/src/renderers/D3PadRenderer.tsx +0 -145
- package/src/renderers/PadNodeRenderer.ts +0 -517
- package/src/renderers/blocks/EndBlockGeometry.ts +0 -52
- package/src/renderers/blocks/EndRenderer.tsx +0 -48
- package/src/renderers/blocks/EndRendererProps.ts +0 -5
- package/src/renderers/blocks/FunctionContainerGeometry.ts +0 -54
- package/src/renderers/blocks/FunctionContainerRenderer.tsx +0 -62
- package/src/renderers/blocks/FunctionHeaderGeometry.ts +0 -43
- package/src/renderers/blocks/FunctionHeaderProps.ts +0 -6
- package/src/renderers/blocks/FunctionHeaderRenderer.tsx +0 -47
- package/src/renderers/blocks/IfBlockGeometry.ts +0 -98
- package/src/renderers/blocks/IfRenderer.tsx +0 -88
- package/src/renderers/blocks/IfRendererProps.ts +0 -7
- package/src/renderers/blocks/LoopRenderer.tsx +0 -50
- package/src/renderers/blocks/LoopRendererProps.ts +0 -7
- package/src/renderers/blocks/Point.ts +0 -4
- package/src/renderers/blocks/README.md +0 -29
- package/src/renderers/blocks/StartBlockGeometry.ts +0 -66
- package/src/renderers/blocks/StartRenderer.tsx +0 -49
- package/src/renderers/blocks/StartRendererProps.ts +0 -5
- package/src/utils/layout.ts +0 -247
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
* PADノードをD3.jsデータ結合パターンでレンダリングするモジュール
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import * as d3 from 'd3';
|
|
7
|
-
import type { LayoutNode } from '../utils/layout';
|
|
8
|
-
import { renderStart } from './blocks/StartRenderer';
|
|
9
|
-
import { renderEnd } from './blocks/EndRenderer';
|
|
10
|
-
import { renderLoopCondition } from './blocks/LoopRenderer';
|
|
11
|
-
import { renderIfBlock } from './blocks/IfRenderer';
|
|
12
|
-
import { StartBlockGeometry } from './blocks/StartBlockGeometry';
|
|
13
|
-
import { FunctionContainerGeometry } from './blocks/FunctionContainerGeometry';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* D3セレクションの型エイリアス
|
|
17
|
-
*/
|
|
18
|
-
type D3Selection = d3.Selection<SVGGElement, unknown, null, undefined>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* LayoutNodeを持つD3セレクションの型エイリアス
|
|
22
|
-
*/
|
|
23
|
-
type D3SelectionWithLayout = d3.Selection<SVGGElement, LayoutNode, null, undefined>;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* PADノードをD3.jsデータ結合パターンでレンダリングするクラス
|
|
27
|
-
*
|
|
28
|
-
* @remarks
|
|
29
|
-
* このクラスは以下のD3.jsデータ結合パターンを実装しています:
|
|
30
|
-
* - **Enter**: 新しいノードをDOMに追加
|
|
31
|
-
* - **Update**: 既存ノードの位置やプロパティを更新
|
|
32
|
-
* - **Exit**: 削除されたノードをDOMから除去
|
|
33
|
-
*
|
|
34
|
-
* これにより、コードの変更時に最小限のDOM操作で効率的に再描画できます。
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* const svg = d3.select('svg');
|
|
39
|
-
* const rootG = svg.append('g');
|
|
40
|
-
* const renderer = new PadNodeRenderer(rootG);
|
|
41
|
-
*
|
|
42
|
-
* // 初回レンダリング
|
|
43
|
-
* renderer.render([layout]);
|
|
44
|
-
*
|
|
45
|
-
* // 更新時(変更があった部分のみ再描画)
|
|
46
|
-
* renderer.render([updatedLayout]);
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export class PadNodeRenderer {
|
|
50
|
-
/** ルートSVGグループ要素 */
|
|
51
|
-
private rootG: D3Selection;
|
|
52
|
-
|
|
53
|
-
/** ノードごとのユーザードラッグオフセット(id -> {x, y}) */
|
|
54
|
-
private nodeOffsets: Map<string, { x: number; y: number }> = new Map();
|
|
55
|
-
|
|
56
|
-
/** 現在ドラッグ中のノードID(ドラッグ中はトランジションを無効化) */
|
|
57
|
-
private draggingNodeId: string | null = null;
|
|
58
|
-
|
|
59
|
-
/** ドラッグ開始時に呼ばれるコールバック(SVGズームを無効化するため) */
|
|
60
|
-
public onDragStart?: () => void;
|
|
61
|
-
|
|
62
|
-
/** ドラッグ終了時に呼ばれるコールバック(SVGズームを再有効化するため) */
|
|
63
|
-
public onDragEnd?: () => void;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* PadNodeRendererのコンストラクタ
|
|
67
|
-
* @param rootG - ルートとなるSVGグループ要素のD3セレクション
|
|
68
|
-
*/
|
|
69
|
-
constructor(rootG: D3Selection) {
|
|
70
|
-
this.rootG = rootG;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* レイアウトノードの配列をレンダリング
|
|
75
|
-
*
|
|
76
|
-
* @remarks
|
|
77
|
-
* D3のデータ結合パターンを使用して、効率的にSVG要素を追加・更新・削除します。
|
|
78
|
-
*
|
|
79
|
-
* @param layouts - レンダリングするレイアウトノードの配列
|
|
80
|
-
*/
|
|
81
|
-
public render(layouts: LayoutNode[]): void {
|
|
82
|
-
this.renderWithDataJoin(this.rootG, layouts);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* D3データ結合パターンによる再帰的レンダリング
|
|
87
|
-
*
|
|
88
|
-
* @remarks
|
|
89
|
-
* 各ノードタイプ(sequence, block, command, if, loop)に応じて
|
|
90
|
-
* 適切なレンダリング処理を行います。
|
|
91
|
-
*
|
|
92
|
-
* @param parent - 親SVGグループ要素
|
|
93
|
-
* @param layouts - レンダリングするレイアウトノードの配列
|
|
94
|
-
*/
|
|
95
|
-
private renderWithDataJoin(parent: D3Selection, layouts: LayoutNode[]): void {
|
|
96
|
-
// データ結合: IDをキーとして使用
|
|
97
|
-
const nodes = parent
|
|
98
|
-
.selectAll<SVGGElement, LayoutNode>(':scope > g.pad-node')
|
|
99
|
-
.data(layouts, d => d.id);
|
|
100
|
-
|
|
101
|
-
// EXIT: 削除されたノード(フェードアウトアニメーション)
|
|
102
|
-
nodes.exit()
|
|
103
|
-
.transition()
|
|
104
|
-
.duration(200)
|
|
105
|
-
.style('opacity', 0)
|
|
106
|
-
.remove();
|
|
107
|
-
|
|
108
|
-
// ENTER: 新規ノード(初期状態は透明)
|
|
109
|
-
const enterNodes = nodes.enter()
|
|
110
|
-
.append('g')
|
|
111
|
-
.attr('class', 'pad-node')
|
|
112
|
-
.style('opacity', 0);
|
|
113
|
-
|
|
114
|
-
// ENTER + UPDATE: マージして更新
|
|
115
|
-
const allNodes = enterNodes.merge(nodes);
|
|
116
|
-
|
|
117
|
-
// 各ノードを処理
|
|
118
|
-
allNodes.each((d, i, nodeElements) => {
|
|
119
|
-
const g = d3.select(nodeElements[i]);
|
|
120
|
-
|
|
121
|
-
// ユーザードラッグオフセットを取得(関数ブロックのみ)
|
|
122
|
-
const offset = this.nodeOffsets.get(d.id) || { x: 0, y: 0 };
|
|
123
|
-
const finalX = d.x + offset.x;
|
|
124
|
-
const finalY = d.y + offset.y;
|
|
125
|
-
|
|
126
|
-
// ドラッグ中のノードはトランジションをスキップ(競合防止)
|
|
127
|
-
if (this.draggingNodeId === d.id) {
|
|
128
|
-
// ドラッグ中は直接位置設定(ドラッグハンドラが管理)
|
|
129
|
-
g.style('opacity', 1);
|
|
130
|
-
} else {
|
|
131
|
-
// 位置を更新(アニメーション付き)
|
|
132
|
-
g.transition()
|
|
133
|
-
.duration(200)
|
|
134
|
-
.attr('transform', `translate(${finalX},${finalY})`)
|
|
135
|
-
.style('opacity', 1);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// ノードタイプに応じてコンテンツを更新
|
|
139
|
-
this.updateNodeContent(g as D3SelectionWithLayout, d);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* ノードコンテンツの更新(enter/update共通)
|
|
145
|
-
*
|
|
146
|
-
* @remarks
|
|
147
|
-
* ノードタイプに応じて適切な更新メソッドを呼び出します。
|
|
148
|
-
* 新規ノード(isNew=true)の場合はDOM要素を作成し、
|
|
149
|
-
* 既存ノードの場合は属性のみを更新します。
|
|
150
|
-
*
|
|
151
|
-
* @param g - ノードのD3セレクション
|
|
152
|
-
* @param layout - レイアウト情報
|
|
153
|
-
*/
|
|
154
|
-
private updateNodeContent(g: D3SelectionWithLayout, layout: LayoutNode): void {
|
|
155
|
-
const { padNode } = layout;
|
|
156
|
-
|
|
157
|
-
// 既存の内部コンテンツを保持/更新するため、クラス名でチェック
|
|
158
|
-
const existingContent = g.select('.node-content');
|
|
159
|
-
const isNew = existingContent.empty();
|
|
160
|
-
|
|
161
|
-
switch (padNode.type) {
|
|
162
|
-
case 'sequence':
|
|
163
|
-
this.updateSequence(g, layout, isNew);
|
|
164
|
-
break;
|
|
165
|
-
case 'block':
|
|
166
|
-
this.updateBlock(g, layout, isNew);
|
|
167
|
-
break;
|
|
168
|
-
case 'command':
|
|
169
|
-
this.updateCommand(g, layout, isNew);
|
|
170
|
-
break;
|
|
171
|
-
case 'if':
|
|
172
|
-
this.updateIf(g, layout, isNew);
|
|
173
|
-
break;
|
|
174
|
-
case 'loop':
|
|
175
|
-
this.updateLoop(g, layout, isNew);
|
|
176
|
-
break;
|
|
177
|
-
default:
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Sequenceノードの更新
|
|
184
|
-
*
|
|
185
|
-
* @remarks
|
|
186
|
-
* 子ノードを順番に配置するコンテナを描画します。
|
|
187
|
-
*
|
|
188
|
-
* @param g - ノードのD3セレクション
|
|
189
|
-
* @param layout - レイアウト情報
|
|
190
|
-
* @param isNew - 新規ノードかどうか
|
|
191
|
-
*/
|
|
192
|
-
private updateSequence(g: D3SelectionWithLayout, layout: LayoutNode, isNew: boolean): void {
|
|
193
|
-
if (isNew) {
|
|
194
|
-
g.append('g').attr('class', 'node-content sequence-content');
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const contentG = g.select<SVGGElement>('.node-content') as D3Selection;
|
|
198
|
-
this.renderWithDataJoin(contentG, layout.children);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Block(関数)ノードの更新
|
|
203
|
-
*
|
|
204
|
-
* @remarks
|
|
205
|
-
* 関数コンテナを描画します。以下の要素を含みます:
|
|
206
|
-
* - ヘッダー(関数名)
|
|
207
|
-
* - STARTノード
|
|
208
|
-
* - 子ノード(関数本体)
|
|
209
|
-
* - ENDノード
|
|
210
|
-
* - 垂直接続線
|
|
211
|
-
*
|
|
212
|
-
* @param g - ノードのD3セレクション
|
|
213
|
-
* @param layout - レイアウト情報
|
|
214
|
-
* @param isNew - 新規ノードかどうか
|
|
215
|
-
*/
|
|
216
|
-
private updateBlock(g: D3SelectionWithLayout, layout: LayoutNode, isNew: boolean): void {
|
|
217
|
-
const { width, height, children, label } = layout;
|
|
218
|
-
|
|
219
|
-
const containerW = width;
|
|
220
|
-
const containerH = height;
|
|
221
|
-
const containerPadding = FunctionContainerGeometry.PADDING;
|
|
222
|
-
const headerHeight = FunctionContainerGeometry.HEADER_HEIGHT;
|
|
223
|
-
|
|
224
|
-
if (isNew) {
|
|
225
|
-
// 新規作成: Function Container
|
|
226
|
-
const contentG = g.append('g').attr('class', 'node-content block-content');
|
|
227
|
-
|
|
228
|
-
// コンテナ背景
|
|
229
|
-
contentG.append('rect')
|
|
230
|
-
.attr('class', 'container-bg')
|
|
231
|
-
.attr('rx', 5);
|
|
232
|
-
|
|
233
|
-
// ヘッダー背景
|
|
234
|
-
contentG.append('rect')
|
|
235
|
-
.attr('class', 'header-bg')
|
|
236
|
-
.attr('rx', 5);
|
|
237
|
-
|
|
238
|
-
// ヘッダーテキスト
|
|
239
|
-
contentG.append('text')
|
|
240
|
-
.attr('class', 'header-text')
|
|
241
|
-
.attr('font-family', 'monospace')
|
|
242
|
-
.attr('font-size', 14)
|
|
243
|
-
.attr('font-weight', 'bold');
|
|
244
|
-
|
|
245
|
-
// START ノード
|
|
246
|
-
contentG.append('g').attr('class', 'start-node');
|
|
247
|
-
|
|
248
|
-
// 垂直線
|
|
249
|
-
contentG.append('line').attr('class', 'vertical-line');
|
|
250
|
-
|
|
251
|
-
// 子ノード用グループ
|
|
252
|
-
contentG.append('g').attr('class', 'children-container');
|
|
253
|
-
|
|
254
|
-
// END ノード
|
|
255
|
-
contentG.append('g').attr('class', 'end-node');
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const contentG = g.select<SVGGElement>('.node-content');
|
|
259
|
-
|
|
260
|
-
// コンテナ背景を更新
|
|
261
|
-
contentG.select('.container-bg')
|
|
262
|
-
.attr('x', 0).attr('y', 0)
|
|
263
|
-
.attr('width', containerW)
|
|
264
|
-
.attr('height', containerH)
|
|
265
|
-
.attr('stroke', '#333')
|
|
266
|
-
.attr('fill', '#f9f9f9');
|
|
267
|
-
|
|
268
|
-
// ヘッダー背景を更新(ドラッグ可能)
|
|
269
|
-
const headerBg = contentG.select<SVGRectElement>('.header-bg')
|
|
270
|
-
.attr('x', 0).attr('y', 0)
|
|
271
|
-
.attr('width', containerW)
|
|
272
|
-
.attr('height', headerHeight)
|
|
273
|
-
.attr('fill', '#e0e0e0')
|
|
274
|
-
.style('cursor', 'grab');
|
|
275
|
-
|
|
276
|
-
// ドラッグ動作を設定
|
|
277
|
-
const nodeId = layout.id;
|
|
278
|
-
// 現在のオフセットを累積
|
|
279
|
-
let currentOffsetX = 0;
|
|
280
|
-
let currentOffsetY = 0;
|
|
281
|
-
|
|
282
|
-
const drag = d3.drag<SVGRectElement, unknown>()
|
|
283
|
-
.on('start', () => {
|
|
284
|
-
// 現在のオフセットを取得
|
|
285
|
-
const currentOffset = this.nodeOffsets.get(nodeId) || { x: 0, y: 0 };
|
|
286
|
-
currentOffsetX = currentOffset.x;
|
|
287
|
-
currentOffsetY = currentOffset.y;
|
|
288
|
-
|
|
289
|
-
// ドラッグ中フラグを設定
|
|
290
|
-
this.draggingNodeId = nodeId;
|
|
291
|
-
|
|
292
|
-
// ドラッグ開始時にコールバック呼び出し
|
|
293
|
-
this.onDragStart?.();
|
|
294
|
-
headerBg.style('cursor', 'grabbing');
|
|
295
|
-
})
|
|
296
|
-
.on('drag', (event: d3.D3DragEvent<SVGRectElement, unknown, unknown>) => {
|
|
297
|
-
// マウスの生の移動量を取得
|
|
298
|
-
const sourceEvent = event.sourceEvent as MouseEvent;
|
|
299
|
-
const movementX = sourceEvent.movementX;
|
|
300
|
-
const movementY = sourceEvent.movementY;
|
|
301
|
-
|
|
302
|
-
// 現在のズームスケールを取得(SVGのtransformから)
|
|
303
|
-
const svg = g.node()?.ownerSVGElement;
|
|
304
|
-
let scale = 1;
|
|
305
|
-
if (svg) {
|
|
306
|
-
const rootG = svg.querySelector('g');
|
|
307
|
-
if (rootG) {
|
|
308
|
-
const transform = rootG.getAttribute('transform');
|
|
309
|
-
if (transform) {
|
|
310
|
-
// scale(N) を抽出
|
|
311
|
-
const scaleMatch = transform.match(/scale\(([^)]+)\)/);
|
|
312
|
-
if (scaleMatch) {
|
|
313
|
-
scale = parseFloat(scaleMatch[1]);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// ズームスケールで補正(ズームしている場合、移動量を逆スケール)
|
|
320
|
-
currentOffsetX += movementX / scale;
|
|
321
|
-
currentOffsetY += movementY / scale;
|
|
322
|
-
|
|
323
|
-
// オフセットを保存
|
|
324
|
-
const newOffset = { x: currentOffsetX, y: currentOffsetY };
|
|
325
|
-
this.nodeOffsets.set(nodeId, newOffset);
|
|
326
|
-
|
|
327
|
-
// 即座に位置を更新(レイアウトの基本位置 + ユーザーオフセット)
|
|
328
|
-
g.attr('transform', `translate(${layout.x + newOffset.x},${layout.y + newOffset.y})`);
|
|
329
|
-
})
|
|
330
|
-
.on('end', () => {
|
|
331
|
-
// ドラッグ中フラグをクリア
|
|
332
|
-
this.draggingNodeId = null;
|
|
333
|
-
|
|
334
|
-
// ドラッグ終了時にコールバック呼び出し
|
|
335
|
-
this.onDragEnd?.();
|
|
336
|
-
headerBg.style('cursor', 'grab');
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
// ドラッグ動作をヘッダーに適用
|
|
340
|
-
headerBg.call(drag as any);
|
|
341
|
-
|
|
342
|
-
// ヘッダーテキストを更新
|
|
343
|
-
contentG.select('.header-text')
|
|
344
|
-
.attr('x', 10)
|
|
345
|
-
.attr('y', headerHeight / 2 + 5)
|
|
346
|
-
.attr('pointer-events', 'none') // テキストはクリック不可(ドラッグの邪魔にならないように)
|
|
347
|
-
.text(label || 'Unknown Function');
|
|
348
|
-
|
|
349
|
-
// START ノード
|
|
350
|
-
const startLabel = 'START';
|
|
351
|
-
const startX = containerPadding;
|
|
352
|
-
const startY = headerHeight + containerPadding;
|
|
353
|
-
const startW = StartBlockGeometry.calculateWidth(startLabel);
|
|
354
|
-
const startH = 30;
|
|
355
|
-
|
|
356
|
-
const startG = contentG.select<SVGGElement>('.start-node');
|
|
357
|
-
if (startG.select('rect').empty()) {
|
|
358
|
-
renderStart(startG as any, startX, startY, startLabel);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// 垂直線を更新
|
|
362
|
-
const centerX = startW / 2;
|
|
363
|
-
const endH = 30;
|
|
364
|
-
const endY = containerH - containerPadding - endH;
|
|
365
|
-
|
|
366
|
-
contentG.select('.vertical-line')
|
|
367
|
-
.attr('x1', startX + centerX)
|
|
368
|
-
.attr('y1', startY + startH)
|
|
369
|
-
.attr('x2', startX + centerX)
|
|
370
|
-
.attr('y2', endY)
|
|
371
|
-
.attr('stroke', 'black')
|
|
372
|
-
.attr('stroke-width', 1.5);
|
|
373
|
-
|
|
374
|
-
// 子ノードを更新
|
|
375
|
-
const childrenG = contentG.select<SVGGElement>('.children-container') as D3Selection;
|
|
376
|
-
this.renderWithDataJoin(childrenG, children);
|
|
377
|
-
|
|
378
|
-
// END ノード
|
|
379
|
-
const endW = 60;
|
|
380
|
-
const endX = startX + centerX - (endW / 2);
|
|
381
|
-
const endG = contentG.select<SVGGElement>('.end-node');
|
|
382
|
-
if (endG.select('rect').empty()) {
|
|
383
|
-
renderEnd(endG as any, endX, endY, 'END');
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Commandノードの更新
|
|
389
|
-
*
|
|
390
|
-
* @remarks
|
|
391
|
-
* 単一の処理ステップを表す矩形ブロックを描画します。
|
|
392
|
-
*
|
|
393
|
-
* @param g - ノードのD3セレクション
|
|
394
|
-
* @param layout - レイアウト情報
|
|
395
|
-
* @param isNew - 新規ノードかどうか
|
|
396
|
-
*/
|
|
397
|
-
private updateCommand(g: D3SelectionWithLayout, layout: LayoutNode, isNew: boolean): void {
|
|
398
|
-
const { width, height, label } = layout;
|
|
399
|
-
|
|
400
|
-
if (isNew) {
|
|
401
|
-
const contentG = g.append('g').attr('class', 'node-content command-content');
|
|
402
|
-
contentG.append('rect').attr('class', 'command-rect');
|
|
403
|
-
contentG.append('text').attr('class', 'command-text');
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
const contentG = g.select<SVGGElement>('.node-content');
|
|
407
|
-
|
|
408
|
-
// 矩形を更新
|
|
409
|
-
contentG.select('.command-rect')
|
|
410
|
-
.attr('x', 0).attr('y', 0)
|
|
411
|
-
.attr('width', width)
|
|
412
|
-
.attr('height', height)
|
|
413
|
-
.attr('stroke', 'black')
|
|
414
|
-
.attr('fill', 'white');
|
|
415
|
-
|
|
416
|
-
// テキストを更新
|
|
417
|
-
contentG.select('.command-text')
|
|
418
|
-
.attr('x', 5)
|
|
419
|
-
.attr('y', 25)
|
|
420
|
-
.attr('font-family', 'monospace')
|
|
421
|
-
.attr('font-size', 14)
|
|
422
|
-
.text(label || '');
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Ifノードの更新
|
|
427
|
-
*
|
|
428
|
-
* @remarks
|
|
429
|
-
* 条件分岐(If-Then-Else)を表すくさび形ブロックを描画します。
|
|
430
|
-
*
|
|
431
|
-
* @param g - ノードのD3セレクション
|
|
432
|
-
* @param layout - レイアウト情報
|
|
433
|
-
* @param isNew - 新規ノードかどうか
|
|
434
|
-
*/
|
|
435
|
-
private updateIf(g: D3SelectionWithLayout, layout: LayoutNode, isNew: boolean): void {
|
|
436
|
-
// IF ブロックは既存のrenderIfBlockを使用(複雑なため)
|
|
437
|
-
if (isNew) {
|
|
438
|
-
const contentG = g.append('g').attr('class', 'node-content if-content');
|
|
439
|
-
renderIfBlock(contentG as any, layout, (parent, childLayout) => {
|
|
440
|
-
this.renderWithDataJoin(parent as D3Selection, [childLayout]);
|
|
441
|
-
});
|
|
442
|
-
} else {
|
|
443
|
-
// 更新: 子ノードのみ更新
|
|
444
|
-
const contentG = g.select<SVGGElement>('.node-content');
|
|
445
|
-
layout.children.forEach((child, index) => {
|
|
446
|
-
const childContainer = contentG.select<SVGGElement>(`.if-child-${index}`);
|
|
447
|
-
if (!childContainer.empty()) {
|
|
448
|
-
this.renderWithDataJoin(childContainer as D3Selection, [child]);
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Loopノードの更新
|
|
456
|
-
*
|
|
457
|
-
* @remarks
|
|
458
|
-
* 繰り返し処理(while/for)を表す二重線ボックスを描画します。
|
|
459
|
-
*
|
|
460
|
-
* @param g - ノードのD3セレクション
|
|
461
|
-
* @param layout - レイアウト情報
|
|
462
|
-
* @param isNew - 新規ノードかどうか
|
|
463
|
-
*/
|
|
464
|
-
private updateLoop(g: D3SelectionWithLayout, layout: LayoutNode, isNew: boolean): void {
|
|
465
|
-
const { children, condition } = layout;
|
|
466
|
-
const bodyLayout = children[0];
|
|
467
|
-
const gap = 20;
|
|
468
|
-
const boxWidth = bodyLayout.x - gap;
|
|
469
|
-
const boxHeight = 40;
|
|
470
|
-
|
|
471
|
-
if (isNew) {
|
|
472
|
-
const contentG = g.append('g').attr('class', 'node-content loop-content');
|
|
473
|
-
|
|
474
|
-
// 条件ボックス
|
|
475
|
-
contentG.append('g').attr('class', 'condition-box');
|
|
476
|
-
|
|
477
|
-
// 水平接続線
|
|
478
|
-
contentG.append('line').attr('class', 'h-line');
|
|
479
|
-
|
|
480
|
-
// 垂直線
|
|
481
|
-
contentG.append('line').attr('class', 'v-line');
|
|
482
|
-
|
|
483
|
-
// ボディ用グループ
|
|
484
|
-
contentG.append('g').attr('class', 'loop-body');
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
const contentG = g.select<SVGGElement>('.node-content');
|
|
488
|
-
|
|
489
|
-
// 条件ボックスを更新
|
|
490
|
-
const condBoxG = contentG.select<SVGGElement>('.condition-box');
|
|
491
|
-
if (condBoxG.select('rect').empty()) {
|
|
492
|
-
renderLoopCondition(condBoxG as any, 0, 0, boxWidth, boxHeight, condition || '');
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// 水平接続線を更新
|
|
496
|
-
contentG.select('.h-line')
|
|
497
|
-
.attr('x1', boxWidth)
|
|
498
|
-
.attr('y1', boxHeight / 2)
|
|
499
|
-
.attr('x2', bodyLayout.x)
|
|
500
|
-
.attr('y2', boxHeight / 2)
|
|
501
|
-
.attr('stroke', 'black')
|
|
502
|
-
.attr('stroke-width', 1.5);
|
|
503
|
-
|
|
504
|
-
// 垂直線を更新
|
|
505
|
-
contentG.select('.v-line')
|
|
506
|
-
.attr('x1', bodyLayout.x)
|
|
507
|
-
.attr('y1', 0)
|
|
508
|
-
.attr('x2', bodyLayout.x)
|
|
509
|
-
.attr('y2', bodyLayout.height)
|
|
510
|
-
.attr('stroke', 'black')
|
|
511
|
-
.attr('stroke-width', 1.5);
|
|
512
|
-
|
|
513
|
-
// ボディを更新
|
|
514
|
-
const bodyG = contentG.select<SVGGElement>('.loop-body') as D3Selection;
|
|
515
|
-
this.renderWithDataJoin(bodyG, [bodyLayout]);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { Point } from './Point';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ENDブロックの形状計算を行うクラス
|
|
5
|
-
*/
|
|
6
|
-
export class EndBlockGeometry {
|
|
7
|
-
private readonly x: number;
|
|
8
|
-
private readonly y: number;
|
|
9
|
-
private readonly width: number = 60;
|
|
10
|
-
private readonly height: number = 30;
|
|
11
|
-
|
|
12
|
-
constructor(x: number, y: number) {
|
|
13
|
-
this.x = x;
|
|
14
|
-
this.y = y;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 上辺の中央座標を取得
|
|
19
|
-
* ここへ垂直線が繋がる
|
|
20
|
-
*/
|
|
21
|
-
getTopCenter(): Point {
|
|
22
|
-
return { x: this.x + this.width / 2, y: this.y };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* ブロックの幅を取得
|
|
27
|
-
*/
|
|
28
|
-
getWidth(): number {
|
|
29
|
-
return this.width;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* ブロックの高さを取得
|
|
34
|
-
*/
|
|
35
|
-
getHeight(): number {
|
|
36
|
-
return this.height;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 描画開始位置(左上)のX座標
|
|
41
|
-
*/
|
|
42
|
-
getX(): number {
|
|
43
|
-
return this.x;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 描画開始位置(左上)のY座標
|
|
48
|
-
*/
|
|
49
|
-
getY(): number {
|
|
50
|
-
return this.y;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import * as d3 from 'd3';
|
|
2
|
-
import { EndBlockGeometry } from './EndBlockGeometry';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* D3.jsでEndブロック(楕円/カプセル型)を描画します
|
|
6
|
-
* @param parent 親のD3セレクション (SVGGElement)
|
|
7
|
-
* @param x X座標
|
|
8
|
-
* @param y Y座標
|
|
9
|
-
* @param label ラベルテキスト (デフォルト: "End")
|
|
10
|
-
*/
|
|
11
|
-
export function renderEnd(
|
|
12
|
-
parent: d3.Selection<SVGGElement, unknown, null, undefined>,
|
|
13
|
-
x: number,
|
|
14
|
-
y: number,
|
|
15
|
-
label: string = "End"
|
|
16
|
-
) {
|
|
17
|
-
const geometry = new EndBlockGeometry(x, y);
|
|
18
|
-
const width = geometry.getWidth();
|
|
19
|
-
const height = geometry.getHeight();
|
|
20
|
-
const rx = height / 2;
|
|
21
|
-
|
|
22
|
-
const g = parent.append('g');
|
|
23
|
-
|
|
24
|
-
// 楕円/カプセル型の矩形
|
|
25
|
-
g.append('rect')
|
|
26
|
-
.attr('x', geometry.getX())
|
|
27
|
-
.attr('y', geometry.getY())
|
|
28
|
-
.attr('width', width)
|
|
29
|
-
.attr('height', height)
|
|
30
|
-
.attr('rx', rx)
|
|
31
|
-
.attr('ry', rx)
|
|
32
|
-
.attr('stroke', 'black')
|
|
33
|
-
.attr('fill', 'white')
|
|
34
|
-
.attr('stroke-width', 1.5);
|
|
35
|
-
|
|
36
|
-
// ラベルテキスト
|
|
37
|
-
g.append('text')
|
|
38
|
-
.attr('x', geometry.getX() + width / 2)
|
|
39
|
-
.attr('y', geometry.getY() + height / 2)
|
|
40
|
-
.attr('text-anchor', 'middle')
|
|
41
|
-
.attr('alignment-baseline', 'middle')
|
|
42
|
-
.attr('font-family', 'monospace')
|
|
43
|
-
.attr('font-size', 14)
|
|
44
|
-
.attr('font-weight', 'bold')
|
|
45
|
-
.text(label);
|
|
46
|
-
|
|
47
|
-
return g;
|
|
48
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { Point } from './Point';
|
|
2
|
-
|
|
3
|
-
export class FunctionContainerGeometry {
|
|
4
|
-
static readonly HEADER_HEIGHT = 30;
|
|
5
|
-
static readonly PADDING = 20;
|
|
6
|
-
|
|
7
|
-
private readonly x: number;
|
|
8
|
-
private readonly y: number;
|
|
9
|
-
private readonly width: number;
|
|
10
|
-
private readonly height: number;
|
|
11
|
-
|
|
12
|
-
constructor(x: number, y: number, width: number, height: number) {
|
|
13
|
-
this.x = x;
|
|
14
|
-
this.y = y;
|
|
15
|
-
this.width = width;
|
|
16
|
-
this.height = height;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getHeaderRect(): { x: number, y: number, width: number, height: number } {
|
|
20
|
-
return {
|
|
21
|
-
x: this.x,
|
|
22
|
-
y: this.y,
|
|
23
|
-
width: this.width,
|
|
24
|
-
height: FunctionContainerGeometry.HEADER_HEIGHT
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getBodyRect(): { x: number, y: number, width: number, height: number } {
|
|
29
|
-
return {
|
|
30
|
-
x: this.x,
|
|
31
|
-
y: this.y + FunctionContainerGeometry.HEADER_HEIGHT,
|
|
32
|
-
width: this.width,
|
|
33
|
-
height: this.height - FunctionContainerGeometry.HEADER_HEIGHT
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getTitlePosition(): Point {
|
|
38
|
-
return {
|
|
39
|
-
x: this.x + 10, // Padding for text
|
|
40
|
-
y: this.y + FunctionContainerGeometry.HEADER_HEIGHT / 2
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Calculates the offset for the inner content (PAD graph).
|
|
46
|
-
* This puts the content inside the body area, respecting padding.
|
|
47
|
-
*/
|
|
48
|
-
getContentOffset(): Point {
|
|
49
|
-
return {
|
|
50
|
-
x: FunctionContainerGeometry.PADDING,
|
|
51
|
-
y: FunctionContainerGeometry.HEADER_HEIGHT + FunctionContainerGeometry.PADDING
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
}
|