@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
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// LOOP(反復)の描画クラス。
|
|
2
|
+
// 正規化済みデータ(datamodels/Loop.ts の出力)を、d3 のセレクション
|
|
3
|
+
// (place) に対して描画する。データの正規化には関知しない。
|
|
4
|
+
//
|
|
5
|
+
// 反復の条件のラベル(本体の先頭行に揃えて配置): 条件の箱の片側にブラケット(矩形、
|
|
6
|
+
// ラベルの高さぶんのみ)を添え、条件の箱とブラケットで二重線を成す。
|
|
7
|
+
// 前判定(test: 'pre'。既定)は二重線が条件の箱の左、後判定(test: 'post')は右。
|
|
8
|
+
// 二重線の外側の端から横線で内側セパレータへつなぐ。
|
|
9
|
+
// 内側セパレータ(縦線、本体全高)が本体の縦の連続性を表すため、ブラケット
|
|
10
|
+
// 自体はラベルの高さぶんだけでよい(SELECTIONの条件列のような「その場所自体が
|
|
11
|
+
// スパインの一部」ではなく、ブラケットの横に本体が続く構造のため)。
|
|
12
|
+
// 内側セパレータの右に本体(各行はregistry.tsで対応するクラスを引き、その
|
|
13
|
+
// painterでそのまま描画する。_class省略時はPROCESS扱い。これによりPARALLEL
|
|
14
|
+
// 等を本体の1行として入れ子にできる)を積み重ねる。本体が複数行のときは、
|
|
15
|
+
// Pad.ts本体の要素間と同じConnector要素で行間をつなぎ、処理の連続性を表す。
|
|
16
|
+
import { ELEMENTS } from '../registry.js';
|
|
17
|
+
import { attachClick } from './interactive.js';
|
|
18
|
+
|
|
19
|
+
const BRACKET_WIDTH = 12; // 条件ラベルに添えるブラケット(矩形)の幅
|
|
20
|
+
const LABEL_PADDING = 12; // 条件ラベル内の左右余白
|
|
21
|
+
const LABEL_HEIGHT = 44; // 条件ラベルの高さ(本体行の実際の高さに関わらず固定)
|
|
22
|
+
const INNER_GAP = 14; // 条件ラベルと内側セパレータの間隔
|
|
23
|
+
const BODY_GAP = 0; // 内側セパレータと本体の間隔
|
|
24
|
+
|
|
25
|
+
export default class Loop {
|
|
26
|
+
draw (place: any, data: any) {
|
|
27
|
+
const g = place.append('g').attr('class', 'pad-loop');
|
|
28
|
+
|
|
29
|
+
const rowGap = data.row_gap;
|
|
30
|
+
const connectorModel = new ELEMENTS.CONNECTOR.datamodel();
|
|
31
|
+
const connectorPainter = new ELEMENTS.CONNECTOR.painter();
|
|
32
|
+
|
|
33
|
+
// 前判定は [ブラケット][条件の箱]、後判定は [条件の箱][ブラケット](箱とブラケットで二重線)。
|
|
34
|
+
const isPost = data.test === 'post';
|
|
35
|
+
const varBoxX = isPost ? 0 : BRACKET_WIDTH;
|
|
36
|
+
const varBoxY = 0;
|
|
37
|
+
const varBoxHeight = LABEL_HEIGHT;
|
|
38
|
+
|
|
39
|
+
// 条件ラベルに添えるブラケット(矩形。ラベルの高さぶんのみ)。
|
|
40
|
+
// 後判定のときは、条件の箱の幅が分かってから x を決める(下)。
|
|
41
|
+
const bracket = g.append('rect')
|
|
42
|
+
.attr('x', 0).attr('y', varBoxY)
|
|
43
|
+
.attr('width', BRACKET_WIDTH).attr('height', varBoxHeight)
|
|
44
|
+
.attr('fill', 'none')
|
|
45
|
+
.attr('stroke', data.stroke.color)
|
|
46
|
+
.attr('stroke-width', data.stroke.width);
|
|
47
|
+
|
|
48
|
+
const varText = g.append('text')
|
|
49
|
+
.attr('x', varBoxX + LABEL_PADDING)
|
|
50
|
+
.attr('y', varBoxY + varBoxHeight / 2)
|
|
51
|
+
.attr('dominant-baseline', 'central')
|
|
52
|
+
.style('font-family', data.font.family)
|
|
53
|
+
.style('font-size', data.font.size)
|
|
54
|
+
.attr('fill', data.font.color)
|
|
55
|
+
.text(data.condition);
|
|
56
|
+
|
|
57
|
+
const varTextWidth = varText.node().getBBox().width;
|
|
58
|
+
const varBoxWidth = varTextWidth + LABEL_PADDING * 2;
|
|
59
|
+
// 条件の箱の右端から、二重線(後判定ならブラケットを含む)の外側の端まで
|
|
60
|
+
const labelRightX = varBoxX + varBoxWidth + (isPost ? BRACKET_WIDTH : 0);
|
|
61
|
+
const innerSeparatorX = (isPost ? labelRightX : varBoxX + varBoxWidth) + INNER_GAP;
|
|
62
|
+
if (isPost) bracket.attr('x', varBoxWidth);
|
|
63
|
+
const bodyX = innerSeparatorX + BODY_GAP;
|
|
64
|
+
|
|
65
|
+
// 条件ラベルの枠(ブラケットより上、テキストより下に挿入する)
|
|
66
|
+
g.insert('rect', 'text')
|
|
67
|
+
.attr('x', varBoxX).attr('y', varBoxY)
|
|
68
|
+
.attr('width', varBoxWidth).attr('height', varBoxHeight)
|
|
69
|
+
.attr('fill', '#fff')
|
|
70
|
+
.attr('stroke', data.stroke.color)
|
|
71
|
+
.attr('stroke-width', data.stroke.width);
|
|
72
|
+
|
|
73
|
+
// 本体(各行。_classごとにregistry.tsで対応するデータクラス/描画クラスを引く)
|
|
74
|
+
let y = 0;
|
|
75
|
+
let maxRowWidth = 0;
|
|
76
|
+
let prevRowData: any = null;
|
|
77
|
+
let drawnRows = 0; // 実際に描いた行の数(知らない _class の行は、数えない)
|
|
78
|
+
data.rows.forEach((row: any)=> {
|
|
79
|
+
const rowClass = row._class || 'PROCESS';
|
|
80
|
+
const entry = ELEMENTS[rowClass];
|
|
81
|
+
if (!entry) return;
|
|
82
|
+
|
|
83
|
+
const model = new entry.datamodel();
|
|
84
|
+
const painter = new entry.painter();
|
|
85
|
+
// center:trueにして、行のanchor(Connector計算に使う)を自身の
|
|
86
|
+
// 中心ではなく左端(=内側セパレータの位置)にする。「連続性のある
|
|
87
|
+
// 処理のベース」の規則(要素の左端を線上に配置する)に合わせる
|
|
88
|
+
// ことで、行同士を結ぶConnectorがまっすぐな縦線になる。
|
|
89
|
+
const rowData = model.normalize(row, { x: bodyX, y, width: 0, center: true });
|
|
90
|
+
rowData.redraw = data.redraw;
|
|
91
|
+
rowData.onElementClick = data.onElementClick;
|
|
92
|
+
painter.draw(g, rowData);
|
|
93
|
+
|
|
94
|
+
if (prevRowData) {
|
|
95
|
+
const connector = connectorModel.normalize(prevRowData.anchors.bottom, rowData.anchors.top);
|
|
96
|
+
connectorPainter.draw(g, connector);
|
|
97
|
+
}
|
|
98
|
+
prevRowData = rowData;
|
|
99
|
+
|
|
100
|
+
maxRowWidth = Math.max(maxRowWidth, rowData.size ? rowData.size.w : 0);
|
|
101
|
+
y = rowData.anchors.bottom.y + rowGap;
|
|
102
|
+
drawnRows++;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// 本体の高さ(描いた行だけ)。条件・ラベルの箱は、行が無くても描くので、それを最低の高さとする(datamodels と同じ式。#307)
|
|
106
|
+
const bodyHeight = drawnRows ? y - rowGap : 0;
|
|
107
|
+
const totalHeight = Math.max(varBoxHeight, bodyHeight);
|
|
108
|
+
const totalWidth = bodyX + maxRowWidth;
|
|
109
|
+
|
|
110
|
+
// 条件ラベルと内側セパレータをつなぐ横線(ラベルの高さの中央)
|
|
111
|
+
g.append('line')
|
|
112
|
+
.attr('x1', labelRightX).attr('y1', varBoxY + varBoxHeight / 2)
|
|
113
|
+
.attr('x2', innerSeparatorX).attr('y2', varBoxY + varBoxHeight / 2)
|
|
114
|
+
.attr('stroke', data.stroke.color)
|
|
115
|
+
.attr('stroke-width', data.stroke.width);
|
|
116
|
+
|
|
117
|
+
// 内側セパレータ(縦線、本体全高。「連続性のある処理のベース」=
|
|
118
|
+
// 複数の処理をつなぐための線のため、行が1つしかない場合はつなぐ
|
|
119
|
+
// 相手がおらず不要。ラベルからの横線が行自身の左端まで届いている
|
|
120
|
+
// ため、それだけで十分)。
|
|
121
|
+
if (drawnRows >= 2) {
|
|
122
|
+
g.append('line')
|
|
123
|
+
.attr('x1', innerSeparatorX).attr('y1', 0)
|
|
124
|
+
.attr('x2', innerSeparatorX).attr('y2', bodyHeight)
|
|
125
|
+
.attr('stroke', data.stroke.color)
|
|
126
|
+
.attr('stroke-width', data.stroke.width);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const x = data.position.x;
|
|
130
|
+
g.attr('transform', `translate(${x},${data.position.y})`);
|
|
131
|
+
|
|
132
|
+
data.size = { w: totalWidth, h: totalHeight };
|
|
133
|
+
|
|
134
|
+
const anchorX = data.anchor_at_spine ? x : x + totalWidth / 2;
|
|
135
|
+
data.anchors = {
|
|
136
|
+
top: { x: anchorX, y: data.position.y },
|
|
137
|
+
bottom: { x: anchorX, y: data.position.y + totalHeight },
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
attachClick(g, data);
|
|
141
|
+
|
|
142
|
+
return g;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Parallel(PARALLEL { TASK{...} TASK{...} })の描画クラス。
|
|
2
|
+
// 正規化済みデータ(datamodels/Parallel.ts の出力)を、d3 のセレクション
|
|
3
|
+
// (place) に対して描画する。データの正規化には関知しない。
|
|
4
|
+
//
|
|
5
|
+
// 各TASKは、{rows: [...]}を持つ場合はLOOP/SELECTIONの本体と同じくregistry.ts
|
|
6
|
+
// 経由で行ごとに描画し(複数の文が連続するTASKを表す)、持たない場合は
|
|
7
|
+
// 従来通りpainters/Process.tsのProcessクラスをそのまま流用して1行の矩形として
|
|
8
|
+
// 描画する(要素間・行間はrow_gapぶんの余白を空けて縦に並べる)。
|
|
9
|
+
// 左端には、並行実行であることを表す矩形のブラケット
|
|
10
|
+
// (元のPADには無い、このプロジェクト独自の拡張記号)を添える。
|
|
11
|
+
// {rows: [...]}を持つTASKで複数行を描画するときは、Pad.ts本体の要素間と
|
|
12
|
+
// 同じConnector要素で行間をつなぎ、処理の連続性を表す。
|
|
13
|
+
import Process from './Process.js';
|
|
14
|
+
import { ELEMENTS } from '../registry.js';
|
|
15
|
+
import { attachClick } from './interactive.js';
|
|
16
|
+
|
|
17
|
+
const processPainter = new Process();
|
|
18
|
+
|
|
19
|
+
export default class Parallel {
|
|
20
|
+
draw (place: any, data: any) {
|
|
21
|
+
// 幅がテキスト実測に依存するため、先にローカル座標(0,0起点)で内容を
|
|
22
|
+
// 描いてから、実測幅を使ってg全体の配置(x)とanchorsを確定する。
|
|
23
|
+
const g = place.append('g').attr('class', 'pad-parallel');
|
|
24
|
+
|
|
25
|
+
const bodyX = data.bracket.width + data.bracket.margin;
|
|
26
|
+
const rowHeight = data.row_height;
|
|
27
|
+
const rowGap = data.row_gap;
|
|
28
|
+
const connectorModel = new ELEMENTS.CONNECTOR.datamodel();
|
|
29
|
+
const connectorPainter = new ELEMENTS.CONNECTOR.painter();
|
|
30
|
+
|
|
31
|
+
let y = 0;
|
|
32
|
+
let maxWidth = 0;
|
|
33
|
+
|
|
34
|
+
data.tasks.forEach((task: any)=> {
|
|
35
|
+
if (task.rows) {
|
|
36
|
+
let rowY = y;
|
|
37
|
+
let drawnRows = 0; // 実際に描いた行の数(知らない _class の行は、数えない)
|
|
38
|
+
let prevRowData: any = null;
|
|
39
|
+
task.rows.forEach((row: any)=> {
|
|
40
|
+
const rowClass = row._class || 'PROCESS';
|
|
41
|
+
const entry = ELEMENTS[rowClass];
|
|
42
|
+
if (!entry) return;
|
|
43
|
+
|
|
44
|
+
const model = new entry.datamodel();
|
|
45
|
+
const painter = new entry.painter();
|
|
46
|
+
// center:trueにして、行のanchorを自身の中心ではなく左端
|
|
47
|
+
// (=bodyX)にする。「連続性のある処理のベース」の規則
|
|
48
|
+
// (要素の左端を線上に配置する)に合わせ、行同士を結ぶ
|
|
49
|
+
// Connectorがまっすぐな縦線になるようにする。
|
|
50
|
+
const rowData = model.normalize(row, { x: bodyX, y: rowY, width: 0, center: true });
|
|
51
|
+
rowData.redraw = data.redraw;
|
|
52
|
+
rowData.onElementClick = data.onElementClick;
|
|
53
|
+
painter.draw(g, rowData);
|
|
54
|
+
|
|
55
|
+
if (prevRowData) {
|
|
56
|
+
const connector = connectorModel.normalize(prevRowData.anchors.bottom, rowData.anchors.top);
|
|
57
|
+
connectorPainter.draw(g, connector);
|
|
58
|
+
}
|
|
59
|
+
prevRowData = rowData;
|
|
60
|
+
|
|
61
|
+
maxWidth = Math.max(maxWidth, rowData.size ? rowData.size.w : 0);
|
|
62
|
+
rowY = rowData.anchors.bottom.y + rowGap;
|
|
63
|
+
drawnRows++;
|
|
64
|
+
});
|
|
65
|
+
// 行の後ろに足したrowGapは、行間としては正しいが末尾の行の後ろ分は
|
|
66
|
+
// TASK自身の高さには含めない(直後の共通のy += rowGapと二重に
|
|
67
|
+
// なり、次のTASK/要素と重なってしまうため。datamodels/Parallel.ts
|
|
68
|
+
// のtaskHeight()と同じ考え方)。
|
|
69
|
+
// 描いた行が無いTASK(rows: []・知らない_classだけ)は、rowHeightぶん進める(datamodels/Parallel.tsと同じ。#307)
|
|
70
|
+
y = drawnRows ? rowY - rowGap : y + rowHeight;
|
|
71
|
+
} else {
|
|
72
|
+
const rowData = {
|
|
73
|
+
cells: task.cells,
|
|
74
|
+
dividers: task.dividers,
|
|
75
|
+
font: data.font,
|
|
76
|
+
stroke: data.stroke,
|
|
77
|
+
chevron_depth: data.chevron_depth,
|
|
78
|
+
position: { x: bodyX, y },
|
|
79
|
+
size: { w: 0, h: rowHeight },
|
|
80
|
+
onElementClick: data.onElementClick,
|
|
81
|
+
};
|
|
82
|
+
processPainter.draw(g, rowData);
|
|
83
|
+
maxWidth = Math.max(maxWidth, rowData.size.w);
|
|
84
|
+
y += rowHeight;
|
|
85
|
+
}
|
|
86
|
+
y += rowGap;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const totalHeight = data.tasks.length ? y - rowGap : 0;
|
|
90
|
+
const totalWidth = bodyX + maxWidth;
|
|
91
|
+
|
|
92
|
+
// 左端のブラケット(並行実行を表す矩形。先頭に挿入し、下に来るようにする)
|
|
93
|
+
g.insert('rect', ':first-child')
|
|
94
|
+
.attr('x', 0).attr('y', 0)
|
|
95
|
+
.attr('width', data.bracket.width).attr('height', totalHeight)
|
|
96
|
+
.attr('fill', 'none')
|
|
97
|
+
.attr('stroke', data.stroke.color)
|
|
98
|
+
.attr('stroke-width', data.stroke.width);
|
|
99
|
+
|
|
100
|
+
const x = data.position.x;
|
|
101
|
+
g.attr('transform', `translate(${x},${data.position.y})`);
|
|
102
|
+
|
|
103
|
+
data.size = { w: totalWidth, h: totalHeight };
|
|
104
|
+
|
|
105
|
+
const anchorX = data.anchor_at_spine ? x : x + totalWidth / 2;
|
|
106
|
+
data.anchors = {
|
|
107
|
+
top: { x: anchorX, y: data.position.y },
|
|
108
|
+
bottom: { x: anchorX, y: data.position.y + totalHeight },
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
attachClick(g, data);
|
|
112
|
+
|
|
113
|
+
return g;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// PROCESS(処理)の描画クラス。
|
|
2
|
+
// 正規化済みデータ(datamodels/Process.ts の出力)を、d3 のセレクション
|
|
3
|
+
// (place) に対して描画する。データの正規化には関知しない。
|
|
4
|
+
//
|
|
5
|
+
// 各セルの幅はテキスト量に合わせて可変にするため、まず全セルのテキストを
|
|
6
|
+
// 描画してから実測(getBBox)し、その幅を元にセル位置・区切り位置・
|
|
7
|
+
// 全体幅を決める(Assignmentと同じ考え方をセル数分に一般化したもの)。
|
|
8
|
+
//
|
|
9
|
+
// セルの描画ロジック(drawCells)は外枠(rect)を持たないため、
|
|
10
|
+
// painters/Parallel.ts から複数行をひとつの外枠にまとめる用途でも
|
|
11
|
+
// そのまま再利用できる。
|
|
12
|
+
import { attachClick } from './interactive.js';
|
|
13
|
+
|
|
14
|
+
const PADDING_LEFT = 12;
|
|
15
|
+
const PADDING_AFTER_TEXT = 14;
|
|
16
|
+
const DESCRIPTION_GAP = 16;
|
|
17
|
+
|
|
18
|
+
// g: セルを描画するd3セレクション(外枠は描かない)。
|
|
19
|
+
// spec: { cells, dividers, font, stroke, chevron_depth, height, links? }
|
|
20
|
+
// links(省略可): cellsと同じ数だけ並ぶ配列で、リンク先のURLまたはnull。
|
|
21
|
+
// 指定したセルのテキストを<a>で包み、WBSページ等へのリンクにする
|
|
22
|
+
// (CALL要素のファイル名のセル等。指定しなければリンクなし)。
|
|
23
|
+
// 戻り値: 全セルを描画した後の全体幅。
|
|
24
|
+
export function drawCells (g: any, spec: any) {
|
|
25
|
+
const h = spec.height;
|
|
26
|
+
const chevronDepth = spec.chevron_depth;
|
|
27
|
+
const links = spec.links || [];
|
|
28
|
+
|
|
29
|
+
const textEls = spec.cells.map((text: any, i: number)=> {
|
|
30
|
+
const href = links[i];
|
|
31
|
+
const container = href ? g.append('a').attr('xlink:href', href).attr('href', href) : g;
|
|
32
|
+
|
|
33
|
+
return container.append('text')
|
|
34
|
+
.attr('y', h / 2)
|
|
35
|
+
.attr('dominant-baseline', 'central')
|
|
36
|
+
.style('font-family', spec.font.family)
|
|
37
|
+
.style('font-size', spec.font.size)
|
|
38
|
+
.style('text-decoration', href ? 'underline' : null)
|
|
39
|
+
.style('cursor', href ? 'pointer' : null)
|
|
40
|
+
.attr('fill', spec.font.color)
|
|
41
|
+
.text(text);
|
|
42
|
+
});
|
|
43
|
+
const textWidths = textEls.map((t: any)=> t.node().getBBox().width);
|
|
44
|
+
|
|
45
|
+
const cellStartX: any[] = [];
|
|
46
|
+
const dividers = []; // { type, x, depth, direction }
|
|
47
|
+
let x = PADDING_LEFT;
|
|
48
|
+
|
|
49
|
+
for (let i=0; i<spec.cells.length; i++) {
|
|
50
|
+
cellStartX.push(x);
|
|
51
|
+
x += textWidths[i];
|
|
52
|
+
|
|
53
|
+
if (i < spec.dividers.length) {
|
|
54
|
+
x += PADDING_AFTER_TEXT;
|
|
55
|
+
const divider = spec.dividers[i];
|
|
56
|
+
const isChevron = divider && 'chevron'===divider.type;
|
|
57
|
+
const depth = isChevron ? chevronDepth : 0;
|
|
58
|
+
dividers.push({
|
|
59
|
+
type: isChevron ? 'chevron' : divider,
|
|
60
|
+
direction: isChevron ? (divider.direction || 'left') : null,
|
|
61
|
+
x,
|
|
62
|
+
depth,
|
|
63
|
+
});
|
|
64
|
+
x += depth + PADDING_LEFT;
|
|
65
|
+
} else {
|
|
66
|
+
x += PADDING_LEFT;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const totalWidth = x;
|
|
71
|
+
|
|
72
|
+
textEls.forEach((t: any, i: number)=> t.attr('x', cellStartX[i]));
|
|
73
|
+
|
|
74
|
+
dividers.forEach(d=> {
|
|
75
|
+
if ('chevron'===d.type) {
|
|
76
|
+
const apexX = 'right'===d.direction ? d.x + d.depth : d.x;
|
|
77
|
+
const openX = 'right'===d.direction ? d.x : d.x + d.depth;
|
|
78
|
+
g.append('path')
|
|
79
|
+
.attr('d', `M ${openX} 0 L ${apexX} ${h / 2} L ${openX} ${h}`)
|
|
80
|
+
.attr('fill', 'none')
|
|
81
|
+
.attr('stroke', spec.stroke.color)
|
|
82
|
+
.attr('stroke-width', spec.stroke.width);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const line = g.append('line')
|
|
87
|
+
.attr('x1', d.x).attr('y1', 0)
|
|
88
|
+
.attr('x2', d.x).attr('y2', h)
|
|
89
|
+
.attr('stroke', spec.stroke.color)
|
|
90
|
+
.attr('stroke-width', spec.stroke.width);
|
|
91
|
+
|
|
92
|
+
if ('dotted'===d.type)
|
|
93
|
+
line.attr('stroke-dasharray', '2,3');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return totalWidth;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default class Process {
|
|
100
|
+
draw (place: any, data: any) {
|
|
101
|
+
// 幅がテキスト実測に依存するため、先にローカル座標(0,0起点)で内容を
|
|
102
|
+
// 描いてから、実測幅を使ってanchorsを確定する。描画位置(x)は常に
|
|
103
|
+
// data.position.x からの左詰め(anchor_at_spineの有無で変わらない)。
|
|
104
|
+
const g = place.append('g').attr('class', 'pad-process');
|
|
105
|
+
|
|
106
|
+
const totalWidth = drawCells(g, {
|
|
107
|
+
cells: data.cells,
|
|
108
|
+
dividers: data.dividers,
|
|
109
|
+
links: data.links,
|
|
110
|
+
font: data.font,
|
|
111
|
+
stroke: data.stroke,
|
|
112
|
+
chevron_depth: data.chevron_depth,
|
|
113
|
+
height: data.size.h,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const x = data.position.x;
|
|
117
|
+
g.attr('transform', `translate(${x},${data.position.y})`);
|
|
118
|
+
|
|
119
|
+
// 外枠(テキストより先に挿入し、下に来るようにする)
|
|
120
|
+
g.insert('rect', ':first-child')
|
|
121
|
+
.attr('width', totalWidth)
|
|
122
|
+
.attr('height', data.size.h)
|
|
123
|
+
.attr('fill', '#fff')
|
|
124
|
+
.attr('stroke', data.stroke.color)
|
|
125
|
+
.attr('stroke-width', data.stroke.width);
|
|
126
|
+
|
|
127
|
+
if (data.description) {
|
|
128
|
+
g.append('text')
|
|
129
|
+
.attr('x', totalWidth + DESCRIPTION_GAP)
|
|
130
|
+
.attr('y', data.size.h / 2)
|
|
131
|
+
.attr('dominant-baseline', 'central')
|
|
132
|
+
.style('font-family', data.font.family)
|
|
133
|
+
.style('font-size', data.font.size)
|
|
134
|
+
.attr('fill', data.font.color)
|
|
135
|
+
.text(data.description);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
data.size.w = totalWidth;
|
|
139
|
+
|
|
140
|
+
// anchor_at_spine=true(PAD全体を1本の縦線でつなぐ用途)のときは
|
|
141
|
+
// 縦線の位置(=左端)をそのままanchorにする。falseのときは自分自身の
|
|
142
|
+
// 中央をanchorにする(単体表示ページ用)。
|
|
143
|
+
const anchorX = data.anchor_at_spine ? x : x + totalWidth / 2;
|
|
144
|
+
data.anchors = {
|
|
145
|
+
top: { x: anchorX, y: data.position.y },
|
|
146
|
+
bottom: { x: anchorX, y: data.position.y + data.size.h },
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
attachClick(g, data);
|
|
150
|
+
|
|
151
|
+
return g;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// SELECTION(選択)の描画クラス。
|
|
2
|
+
// 正規化済みデータ(datamodels/Selection.ts の出力)を、d3 のセレクション
|
|
3
|
+
// (place) に対して描画する。
|
|
4
|
+
//
|
|
5
|
+
// 左の「条件」列(WHENごとに1行、単純な1セルの箱)を積み重ね、条件列全体を
|
|
6
|
+
// 閉じた矩形のブラケット(条件ボックスへわずかに被る)で囲む。各条件からは
|
|
7
|
+
// 横線で対応する「本体」(registry.ts経由でクラスごとに描画。_class省略時は
|
|
8
|
+
// PROCESS扱い。LOOPのrowsと同じ考え方)へつなぐ。本体が複数行を持つ場合
|
|
9
|
+
// (例: ELSEで代入とSQLが連続する等)は、Pad.ts本体の要素間と同じConnector
|
|
10
|
+
// 要素で行間をつなぎ、処理の連続性を表す。
|
|
11
|
+
// NOTE: SELECTION自身の開始-終了の縦線は引かない。トップレベルで使われる場合は
|
|
12
|
+
// Pad.tsが最後に描く開始-終了の縦線(Pad.ts参照)で足り、LOOP等に入れ子に
|
|
13
|
+
// なる場合はブラケットより下に浮いた線になってしまうだけで不要なため。
|
|
14
|
+
import { ELEMENTS } from '../registry.js';
|
|
15
|
+
import { attachClick } from './interactive.js';
|
|
16
|
+
|
|
17
|
+
const CONDITION_HEIGHT = 44; // 条件ボックスの高さ(本体の実際の高さに関わらず固定)
|
|
18
|
+
const CONDITION_PADDING = 12; // 条件ボックス内の左右余白
|
|
19
|
+
const BRACKET_GAP = 12; // ブラケットと条件列の間隔
|
|
20
|
+
const BRACKET_OVERLAP = 20; // ブラケット(ベースの四角)が条件ボックスへ被る量
|
|
21
|
+
const BRACKET_MARGIN = 8; // ブラケットの上下が条件ボックスよりわずかに広がる量
|
|
22
|
+
const CONNECTOR_GAP = 14; // 条件ボックス右端から本体左端までの横線の長さ
|
|
23
|
+
|
|
24
|
+
export default class Selection {
|
|
25
|
+
draw (place: any, data: any) {
|
|
26
|
+
const g = place.append('g').attr('class', 'pad-selection');
|
|
27
|
+
|
|
28
|
+
const rowGap = data.row_gap;
|
|
29
|
+
const conditionX = BRACKET_GAP;
|
|
30
|
+
const connectorModel = new ELEMENTS.CONNECTOR.datamodel();
|
|
31
|
+
const connectorPainter = new ELEMENTS.CONNECTOR.painter();
|
|
32
|
+
|
|
33
|
+
// ブラケット(ベースの四角)は常に条件ボックスより下のレイヤーに置く
|
|
34
|
+
// (条件ボックスの白背景で被った部分を隠すため)。寸法(高さ)は
|
|
35
|
+
// 全行分の配置が確定した後に決まるため、ここでは仮の属性で追加して
|
|
36
|
+
// おき、末尾で最終的な値に更新する。
|
|
37
|
+
const bracket = g.append('rect')
|
|
38
|
+
.attr('fill', 'none')
|
|
39
|
+
.attr('stroke', data.stroke.color)
|
|
40
|
+
.attr('stroke-width', data.stroke.width);
|
|
41
|
+
|
|
42
|
+
// 1. 条件テキストをいったん描画して幅を測り、条件列の幅を揃える。
|
|
43
|
+
// when.else===trueの行はWHEN以外の場合(ELSE)を表し、条件式の
|
|
44
|
+
// かわりに固定ラベル「ELSE」を表示する。
|
|
45
|
+
const conditionTexts = data.whens.map((when: any)=>
|
|
46
|
+
g.append('text')
|
|
47
|
+
.attr('dominant-baseline', 'central')
|
|
48
|
+
.style('font-family', data.font.family)
|
|
49
|
+
.style('font-size', data.font.size)
|
|
50
|
+
.attr('fill', data.font.color)
|
|
51
|
+
.text(when.else ? 'ELSE' : when.condition)
|
|
52
|
+
);
|
|
53
|
+
const conditionWidths = conditionTexts.map((t: any)=> t.node().getBBox().width);
|
|
54
|
+
const conditionColumnWidth = (conditionWidths.length ? Math.max(...conditionWidths) : 0) + CONDITION_PADDING * 2;
|
|
55
|
+
const bodyX = conditionX + conditionColumnWidth + CONNECTOR_GAP;
|
|
56
|
+
|
|
57
|
+
// 2. WHENごとに、条件ボックス+本体行を配置する。
|
|
58
|
+
// ブラケットが条件ボックスの上下に BRACKET_MARGIN ずつはみ出すので、その分を自分の高さに含める
|
|
59
|
+
// (最初の条件ボックスを BRACKET_MARGIN だけ下げる。はみ出しが、自分の上端・下端の内側に収まる。#309)。
|
|
60
|
+
let y = BRACKET_MARGIN;
|
|
61
|
+
let maxBodyWidth = 0;
|
|
62
|
+
const rowTops: any[] = [];
|
|
63
|
+
|
|
64
|
+
data.whens.forEach((when: any, i: number)=> {
|
|
65
|
+
rowTops.push(y);
|
|
66
|
+
|
|
67
|
+
conditionTexts[i]
|
|
68
|
+
.attr('x', conditionX + CONDITION_PADDING)
|
|
69
|
+
.attr('y', y + CONDITION_HEIGHT / 2);
|
|
70
|
+
|
|
71
|
+
// ブラケットより上、条件テキストより下('text'要素の直前に挿入)に置く。
|
|
72
|
+
g.insert('rect', 'text')
|
|
73
|
+
.attr('x', conditionX).attr('y', y)
|
|
74
|
+
.attr('width', conditionColumnWidth).attr('height', CONDITION_HEIGHT)
|
|
75
|
+
.attr('fill', '#fff')
|
|
76
|
+
.attr('stroke', data.stroke.color)
|
|
77
|
+
.attr('stroke-width', data.stroke.width);
|
|
78
|
+
|
|
79
|
+
let rowY = y;
|
|
80
|
+
let rowMaxWidth = 0;
|
|
81
|
+
let prevRowData: any = null;
|
|
82
|
+
(when.body || []).forEach((bodyRow: any)=> {
|
|
83
|
+
const rowClass = bodyRow._class || 'PROCESS';
|
|
84
|
+
const entry = ELEMENTS[rowClass];
|
|
85
|
+
if (!entry) return;
|
|
86
|
+
|
|
87
|
+
const model = new entry.datamodel();
|
|
88
|
+
const painter = new entry.painter();
|
|
89
|
+
// center:trueにして、行のanchorを自身の中心ではなく左端
|
|
90
|
+
// (=bodyX)にする。「連続性のある処理のベース」の規則
|
|
91
|
+
// (要素の左端を線上に配置する)に合わせ、行同士を結ぶ
|
|
92
|
+
// Connectorがまっすぐな縦線になるようにする。
|
|
93
|
+
const rowData = model.normalize(bodyRow, { x: bodyX, y: rowY, width: 0, center: true });
|
|
94
|
+
rowData.redraw = data.redraw;
|
|
95
|
+
rowData.onElementClick = data.onElementClick;
|
|
96
|
+
painter.draw(g, rowData);
|
|
97
|
+
|
|
98
|
+
if (prevRowData) {
|
|
99
|
+
const connector = connectorModel.normalize(prevRowData.anchors.bottom, rowData.anchors.top);
|
|
100
|
+
connectorPainter.draw(g, connector);
|
|
101
|
+
}
|
|
102
|
+
prevRowData = rowData;
|
|
103
|
+
|
|
104
|
+
rowMaxWidth = Math.max(rowMaxWidth, rowData.size ? rowData.size.w : 0);
|
|
105
|
+
rowY = rowData.anchors.bottom.y + rowGap;
|
|
106
|
+
});
|
|
107
|
+
const bodyHeight = (when.body || []).length ? rowY - rowGap - y : 0;
|
|
108
|
+
maxBodyWidth = Math.max(maxBodyWidth, rowMaxWidth);
|
|
109
|
+
|
|
110
|
+
// 条件ボックスと本体をつなぐ横線(条件ボックスの高さの中央)
|
|
111
|
+
g.append('line')
|
|
112
|
+
.attr('x1', conditionX + conditionColumnWidth).attr('y1', y + CONDITION_HEIGHT / 2)
|
|
113
|
+
.attr('x2', bodyX).attr('y2', y + CONDITION_HEIGHT / 2)
|
|
114
|
+
.attr('stroke', data.stroke.color)
|
|
115
|
+
.attr('stroke-width', data.stroke.width);
|
|
116
|
+
|
|
117
|
+
const rowHeight = Math.max(CONDITION_HEIGHT, bodyHeight);
|
|
118
|
+
y += rowHeight + rowGap;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const totalHeight = data.whens.length ? y - rowGap + BRACKET_MARGIN : 0;
|
|
122
|
+
const totalWidth = bodyX + maxBodyWidth;
|
|
123
|
+
|
|
124
|
+
// 3. 条件列を囲むブラケット(LOOP/PARALLELと同様、閉じた矩形で表す)の
|
|
125
|
+
// 最終的な寸法を確定させる。条件ボックス自体の範囲より上下にわずかに
|
|
126
|
+
// 広げ、右辺は条件ボックスへ被せる(条件ボックスが上のレイヤーにある
|
|
127
|
+
// ため、被った部分はその白背景で隠れる)。
|
|
128
|
+
const bracketTop = (rowTops.length ? rowTops[0] : 0) - BRACKET_MARGIN;
|
|
129
|
+
const bracketBottom = (rowTops.length ? rowTops[rowTops.length - 1] + CONDITION_HEIGHT : 0) + BRACKET_MARGIN;
|
|
130
|
+
|
|
131
|
+
bracket
|
|
132
|
+
.attr('x', 0).attr('y', bracketTop)
|
|
133
|
+
.attr('width', BRACKET_GAP + BRACKET_OVERLAP).attr('height', bracketBottom - bracketTop);
|
|
134
|
+
|
|
135
|
+
const x = data.position.x;
|
|
136
|
+
g.attr('transform', `translate(${x},${data.position.y})`);
|
|
137
|
+
|
|
138
|
+
data.size = { w: totalWidth, h: totalHeight };
|
|
139
|
+
|
|
140
|
+
const anchorX = data.anchor_at_spine ? x : x + totalWidth / 2;
|
|
141
|
+
data.anchors = {
|
|
142
|
+
top: { x: anchorX, y: data.position.y },
|
|
143
|
+
bottom: { x: anchorX, y: data.position.y + totalHeight },
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
attachClick(g, data);
|
|
147
|
+
|
|
148
|
+
return g;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Terminal(開始/終了)の描画クラス。
|
|
2
|
+
// 正規化済みデータ(datamodels/Terminal.ts の出力)を、d3 のセレクション
|
|
3
|
+
// (place) に対して描画する。データの正規化には関知しない。
|
|
4
|
+
import { attachClick } from './interactive.js';
|
|
5
|
+
|
|
6
|
+
export default class Terminal {
|
|
7
|
+
draw (place: any, data: any) {
|
|
8
|
+
const g = place.append('g')
|
|
9
|
+
.attr('class', 'pad-terminal');
|
|
10
|
+
|
|
11
|
+
g.append('circle')
|
|
12
|
+
.attr('cx', data.center.x)
|
|
13
|
+
.attr('cy', data.center.y)
|
|
14
|
+
.attr('r', data.radius)
|
|
15
|
+
.attr('fill', data.background.color)
|
|
16
|
+
.attr('stroke', data.border.color)
|
|
17
|
+
.attr('stroke-width', data.border.width);
|
|
18
|
+
|
|
19
|
+
attachClick(g, data);
|
|
20
|
+
|
|
21
|
+
return g;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// PAD要素の<g>にクリックハンドラを付与する共通ヘルパー。
|
|
2
|
+
// data.onElementClick は Pad.ts の draw() が data.redraw と同じ仕組みで
|
|
3
|
+
// スタンプし、LOOP/SELECTION/PARALLEL/GROUPの各painterがdata.redrawと
|
|
4
|
+
// 同様に本体の行(rowData.onElementClick)へ伝播させるため、どれだけ
|
|
5
|
+
// 入れ子になっていても常に呼び出し元(PadDiagram.js)まで辿り着く。
|
|
6
|
+
// 未設定(インスペクタ機能を使わない呼び出し元)の場合は何もしない。
|
|
7
|
+
export function attachClick (g: any, data: any) {
|
|
8
|
+
if (!data.onElementClick) return;
|
|
9
|
+
|
|
10
|
+
g.style('cursor', 'pointer')
|
|
11
|
+
.on('click', (event: any)=> {
|
|
12
|
+
event.stopPropagation();
|
|
13
|
+
data.onElementClick(data);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// PAD 要素のレジストリ。要素の _class ごとに { datamodel, painter } のクラスを保持する。
|
|
2
|
+
// Pad.ts(本体の縦積みレイアウト)と、入れ子を持つ要素(LOOP / SELECTION / PARALLEL / GROUP。
|
|
3
|
+
// 本体の行を振り分けて描くので、Pad と同じ表を参照する)の両方から使う。
|
|
4
|
+
//
|
|
5
|
+
// 表は、モジュールに 1 つ(プロセスに 1 つ)。d3.pad が 9 つ(TERMINAL・CONNECTOR・PROCESS・CALL・ASSIGNMENT・
|
|
6
|
+
// LOOP・SELECTION・PARALLEL・GROUP。elements.ts)を最初から登録する。
|
|
7
|
+
// 利用側は registerElement で足せる。同じ _class を別の中身で足すと、あとのものが勝つ。
|
|
8
|
+
//
|
|
9
|
+
// 要素は Pad のインスタンスを知らず、この表をモジュールとして直接引く(new entry.datamodel() をその場で作る)。
|
|
10
|
+
// このモジュールは何も import しないので、要素との循環参照は無い(登録は elements.ts がする)。
|
|
11
|
+
|
|
12
|
+
// 型は動きを変えずにゆるめている(any)。元は JavaScript で、datamodel / painter の形は要素ごとに違う
|
|
13
|
+
// (normalize / draw の引数・戻り値が _class ごとに違う)ため、いまは型で縛らない。
|
|
14
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
15
|
+
export interface PadElementEntry {
|
|
16
|
+
datamodel: new () => any;
|
|
17
|
+
painter: new () => any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ELEMENTS: Record<string, PadElementEntry> = {};
|
|
21
|
+
|
|
22
|
+
/** 要素を足す(同じ _class があれば置き換える)。Pad は、作られたときに表を見るので、Pad を作る前に呼ぶ。 */
|
|
23
|
+
export function registerElement(_class: string, entry: PadElementEntry): void {
|
|
24
|
+
ELEMENTS[_class] = entry;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Pad のクラスを入れておく場所(1 つ)。Pad.ts が、読み込まれたときに自分を入れる。
|
|
28
|
+
// CALL(呼び出し先を別の Pad で描く要素)は、Pad.ts を import せず、ここから取り出す。
|
|
29
|
+
// こうすると、registry.ts が何も import しないまま、Pad.ts ↔ 要素の循環参照が無くなり、
|
|
30
|
+
// 要素のファイルを単独で先に読んでも落ちない(#290)。
|
|
31
|
+
export const PAD: { Pad: (new (params?: any) => any) | null } = { Pad: null };
|
|
32
|
+
|
|
33
|
+
/** Pad のクラスを登録する(Pad.ts が、読み込まれたときに呼ぶ)。 */
|
|
34
|
+
export function registerPad(PadClass: new (params?: any) => any): void {
|
|
35
|
+
PAD.Pad = PadClass;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default ELEMENTS;
|