@yanqirenshi/d3.pad 0.3.0 → 0.4.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 (137) hide show
  1. package/README.md +107 -12
  2. package/dist/index.d.ts +7 -5
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +9 -6
  5. package/dist/pad/Pad.d.ts +4 -4
  6. package/dist/pad/Pad.d.ts.map +1 -1
  7. package/dist/pad/Pad.js +25 -29
  8. package/dist/pad/PadDiagram.js +1 -1
  9. package/dist/pad/builtins.d.ts +2 -0
  10. package/dist/pad/builtins.d.ts.map +1 -0
  11. package/dist/pad/builtins.js +24 -0
  12. package/dist/pad/{datamodels → elements}/Assignment.d.ts +3 -1
  13. package/dist/pad/elements/Assignment.d.ts.map +1 -0
  14. package/dist/pad/{painters → elements}/Assignment.js +51 -5
  15. package/dist/pad/{datamodels → elements}/Call.d.ts +7 -1
  16. package/dist/pad/elements/Call.d.ts.map +1 -0
  17. package/dist/pad/{painters → elements}/Call.js +115 -18
  18. package/dist/pad/{datamodels → elements}/Group.d.ts +9 -2
  19. package/dist/pad/elements/Group.d.ts.map +1 -0
  20. package/dist/pad/elements/Group.js +113 -0
  21. package/dist/pad/{datamodels → elements}/Loop.d.ts +9 -2
  22. package/dist/pad/elements/Loop.d.ts.map +1 -0
  23. package/dist/pad/{painters → elements}/Loop.js +73 -54
  24. package/dist/pad/elements/PadContainerBase.d.ts +56 -0
  25. package/dist/pad/elements/PadContainerBase.d.ts.map +1 -0
  26. package/dist/pad/elements/PadContainerBase.js +110 -0
  27. package/dist/pad/elements/PadElementBase.d.ts +12 -0
  28. package/dist/pad/elements/PadElementBase.d.ts.map +1 -0
  29. package/dist/pad/elements/PadElementBase.js +11 -0
  30. package/dist/pad/{datamodels → elements}/Parallel.d.ts +4 -1
  31. package/dist/pad/elements/Parallel.d.ts.map +1 -0
  32. package/dist/pad/elements/Parallel.js +125 -0
  33. package/dist/pad/elements/Predefined.d.ts +51 -0
  34. package/dist/pad/elements/Predefined.d.ts.map +1 -0
  35. package/dist/pad/elements/Predefined.js +48 -0
  36. package/dist/pad/{datamodels → elements}/Process.d.ts +4 -1
  37. package/dist/pad/elements/Process.d.ts.map +1 -0
  38. package/dist/pad/{painters → elements}/Process.js +75 -7
  39. package/dist/pad/{datamodels → elements}/Selection.d.ts +9 -2
  40. package/dist/pad/elements/Selection.d.ts.map +1 -0
  41. package/dist/pad/{painters → elements}/Selection.js +73 -47
  42. package/dist/pad/{datamodels → elements}/Terminal.d.ts +3 -1
  43. package/dist/pad/elements/Terminal.d.ts.map +1 -0
  44. package/dist/pad/{datamodels → elements}/Terminal.js +19 -6
  45. package/dist/pad/parts/connector.d.ts +3 -0
  46. package/dist/pad/parts/connector.d.ts.map +1 -0
  47. package/dist/pad/parts/connector.js +17 -0
  48. package/dist/pad/parts/interactive.d.ts.map +1 -0
  49. package/dist/pad/{painters → parts}/interactive.js +1 -1
  50. package/dist/pad/parts/underline.d.ts +9 -0
  51. package/dist/pad/parts/underline.d.ts.map +1 -0
  52. package/dist/pad/parts/underline.js +30 -0
  53. package/dist/pad/registry.d.ts +7 -5
  54. package/dist/pad/registry.d.ts.map +1 -1
  55. package/dist/pad/registry.js +19 -8
  56. package/dist/pad/types.d.ts +16 -0
  57. package/dist/pad/types.d.ts.map +1 -0
  58. package/dist/pad/types.js +1 -0
  59. package/package.json +3 -6
  60. package/src/index.ts +14 -9
  61. package/src/pad/Pad.ts +27 -30
  62. package/src/pad/PadDiagram.tsx +1 -1
  63. package/src/pad/builtins.ts +26 -0
  64. package/src/pad/{painters → elements}/Assignment.ts +56 -5
  65. package/src/pad/{painters → elements}/Call.ts +128 -17
  66. package/src/pad/elements/Group.ts +130 -0
  67. package/src/pad/{painters → elements}/Loop.ts +81 -62
  68. package/src/pad/elements/PadContainerBase.ts +145 -0
  69. package/src/pad/elements/PadElementBase.ts +22 -0
  70. package/src/pad/elements/Parallel.ts +140 -0
  71. package/src/pad/elements/Predefined.ts +55 -0
  72. package/src/pad/{painters → elements}/Process.ts +79 -7
  73. package/src/pad/{painters → elements}/Selection.ts +81 -54
  74. package/src/pad/{datamodels → elements}/Terminal.ts +24 -6
  75. package/src/pad/parts/connector.ts +19 -0
  76. package/src/pad/{painters → parts}/interactive.ts +1 -1
  77. package/src/pad/parts/underline.ts +33 -0
  78. package/src/pad/registry.ts +33 -14
  79. package/src/pad/types.ts +21 -0
  80. package/dist/pad/datamodels/Assignment.d.ts.map +0 -1
  81. package/dist/pad/datamodels/Assignment.js +0 -51
  82. package/dist/pad/datamodels/Call.d.ts.map +0 -1
  83. package/dist/pad/datamodels/Call.js +0 -83
  84. package/dist/pad/datamodels/Connector.d.ts +0 -35
  85. package/dist/pad/datamodels/Connector.d.ts.map +0 -1
  86. package/dist/pad/datamodels/Connector.js +0 -23
  87. package/dist/pad/datamodels/Group.d.ts.map +0 -1
  88. package/dist/pad/datamodels/Group.js +0 -71
  89. package/dist/pad/datamodels/Loop.d.ts.map +0 -1
  90. package/dist/pad/datamodels/Loop.js +0 -77
  91. package/dist/pad/datamodels/Parallel.d.ts.map +0 -1
  92. package/dist/pad/datamodels/Parallel.js +0 -80
  93. package/dist/pad/datamodels/Process.d.ts.map +0 -1
  94. package/dist/pad/datamodels/Process.js +0 -59
  95. package/dist/pad/datamodels/Selection.d.ts.map +0 -1
  96. package/dist/pad/datamodels/Selection.js +0 -81
  97. package/dist/pad/datamodels/Terminal.d.ts.map +0 -1
  98. package/dist/pad/elements.d.ts +0 -2
  99. package/dist/pad/elements.d.ts.map +0 -1
  100. package/dist/pad/elements.js +0 -32
  101. package/dist/pad/painters/Assignment.d.ts +0 -4
  102. package/dist/pad/painters/Assignment.d.ts.map +0 -1
  103. package/dist/pad/painters/Call.d.ts +0 -4
  104. package/dist/pad/painters/Call.d.ts.map +0 -1
  105. package/dist/pad/painters/Connector.d.ts +0 -4
  106. package/dist/pad/painters/Connector.d.ts.map +0 -1
  107. package/dist/pad/painters/Connector.js +0 -15
  108. package/dist/pad/painters/Group.d.ts +0 -4
  109. package/dist/pad/painters/Group.d.ts.map +0 -1
  110. package/dist/pad/painters/Group.js +0 -99
  111. package/dist/pad/painters/Loop.d.ts +0 -4
  112. package/dist/pad/painters/Loop.d.ts.map +0 -1
  113. package/dist/pad/painters/Parallel.d.ts +0 -4
  114. package/dist/pad/painters/Parallel.d.ts.map +0 -1
  115. package/dist/pad/painters/Parallel.js +0 -102
  116. package/dist/pad/painters/Process.d.ts +0 -5
  117. package/dist/pad/painters/Process.d.ts.map +0 -1
  118. package/dist/pad/painters/Selection.d.ts +0 -4
  119. package/dist/pad/painters/Selection.d.ts.map +0 -1
  120. package/dist/pad/painters/Terminal.d.ts +0 -4
  121. package/dist/pad/painters/Terminal.d.ts.map +0 -1
  122. package/dist/pad/painters/Terminal.js +0 -19
  123. package/dist/pad/painters/interactive.d.ts.map +0 -1
  124. package/src/pad/datamodels/Assignment.ts +0 -55
  125. package/src/pad/datamodels/Call.ts +0 -91
  126. package/src/pad/datamodels/Connector.ts +0 -25
  127. package/src/pad/datamodels/Group.ts +0 -76
  128. package/src/pad/datamodels/Loop.ts +0 -82
  129. package/src/pad/datamodels/Parallel.ts +0 -85
  130. package/src/pad/datamodels/Process.ts +0 -63
  131. package/src/pad/datamodels/Selection.ts +0 -87
  132. package/src/pad/elements.ts +0 -34
  133. package/src/pad/painters/Connector.ts +0 -15
  134. package/src/pad/painters/Group.ts +0 -116
  135. package/src/pad/painters/Parallel.ts +0 -115
  136. package/src/pad/painters/Terminal.ts +0 -23
  137. /package/dist/pad/{painters → parts}/interactive.d.ts +0 -0
@@ -1,116 +0,0 @@
1
- // GROUP(まとまり)の描画クラス。
2
- // 正規化済みデータ(datamodels/Group.ts の出力)を、d3 のセレクション
3
- // (place) に対して描画する。データの正規化には関知しない。
4
- //
5
- // 「複数処理の実行」の基本形そのもの: まとまりの名前(labelを表示する単純な1つの
6
- // ボックス。LOOPのようなブラケット装飾は付けない)から横線を「連続性の
7
- // ある処理のベース」(縦線)まで引き、その線の上に本体(rows)の左端を
8
- // 揃えて積み重ねる。本体が複数行のときは、Pad.ts本体の要素間と同じ
9
- // Connector要素で行間をつなぐ。行が1つしかない場合はベースの縦線・行間の
10
- // Connectorのどちらも不要(つなぐ相手がいないため)。
11
- import { ELEMENTS } from '../registry.js';
12
- import { attachClick } from './interactive.js';
13
-
14
- const LABEL_HEIGHT = 44; // 実行元ボックスの高さ
15
- const LABEL_PADDING = 12; // 実行元ボックス内の左右余白
16
- const CONNECTOR_GAP = 14; // 実行元ボックス右端から本体(ベースの線)までの横線の長さ
17
-
18
- export default class Group {
19
- draw (place: any, data: any) {
20
- const g = place.append('g').attr('class', 'pad-group');
21
-
22
- const rowGap = data.row_gap;
23
- const connectorModel = new ELEMENTS.CONNECTOR.datamodel();
24
- const connectorPainter = new ELEMENTS.CONNECTOR.painter();
25
-
26
- const labelText = g.append('text')
27
- .attr('x', LABEL_PADDING)
28
- .attr('y', LABEL_HEIGHT / 2)
29
- .attr('dominant-baseline', 'central')
30
- .style('font-family', data.font.family)
31
- .style('font-size', data.font.size)
32
- .attr('fill', data.font.color)
33
- .text(data.label);
34
-
35
- const labelTextWidth = labelText.node().getBBox().width;
36
- const labelBoxWidth = labelTextWidth + LABEL_PADDING * 2;
37
- const bodyX = labelBoxWidth + CONNECTOR_GAP;
38
-
39
- // 実行元ボックスの枠(テキストより先に挿入し、下に来るようにする)
40
- g.insert('rect', 'text')
41
- .attr('x', 0).attr('y', 0)
42
- .attr('width', labelBoxWidth).attr('height', LABEL_HEIGHT)
43
- .attr('fill', '#fff')
44
- .attr('stroke', data.stroke.color)
45
- .attr('stroke-width', data.stroke.width);
46
-
47
- // 本体(各行。_classごとにregistry.tsで対応するデータクラス/描画クラスを引く)
48
- let y = 0;
49
- let maxRowWidth = 0;
50
- let prevRowData: any = null;
51
- let drawnRows = 0; // 実際に描いた行の数(知らない _class の行は、数えない)
52
- data.rows.forEach((row: any)=> {
53
- const rowClass = row._class || 'PROCESS';
54
- const entry = ELEMENTS[rowClass];
55
- if (!entry) return;
56
-
57
- const model = new entry.datamodel();
58
- const painter = new entry.painter();
59
- // center:trueにして、行のanchorを自身の中心ではなく左端(=bodyX)に
60
- // する。「連続性のある処理のベース」の規則(要素の左端を線上に
61
- // 配置する)に合わせ、行同士を結ぶConnectorがまっすぐな縦線になる
62
- // ようにする。
63
- const rowData = model.normalize(row, { x: bodyX, y, width: 0, center: true });
64
- rowData.redraw = data.redraw;
65
- rowData.onElementClick = data.onElementClick;
66
- painter.draw(g, rowData);
67
-
68
- if (prevRowData) {
69
- const connector = connectorModel.normalize(prevRowData.anchors.bottom, rowData.anchors.top);
70
- connectorPainter.draw(g, connector);
71
- }
72
- prevRowData = rowData;
73
-
74
- maxRowWidth = Math.max(maxRowWidth, rowData.size ? rowData.size.w : 0);
75
- y = rowData.anchors.bottom.y + rowGap;
76
- drawnRows++;
77
- });
78
-
79
- // 本体の高さ(描いた行だけ)。条件・ラベルの箱は、行が無くても描くので、それを最低の高さとする(datamodels と同じ式。#307)
80
- const bodyHeight = drawnRows ? y - rowGap : 0;
81
- const totalHeight = Math.max(LABEL_HEIGHT, bodyHeight);
82
- const totalWidth = bodyX + maxRowWidth;
83
-
84
- // 実行元ボックスとベースの線をつなぐ横線(ボックスの高さの中央)
85
- g.append('line')
86
- .attr('x1', labelBoxWidth).attr('y1', LABEL_HEIGHT / 2)
87
- .attr('x2', bodyX).attr('y2', LABEL_HEIGHT / 2)
88
- .attr('stroke', data.stroke.color)
89
- .attr('stroke-width', data.stroke.width);
90
-
91
- // 「連続性のある処理のベース」(縦線、本体全高)。行が1つしかない
92
- // 場合はつなぐ相手がいないため描画しない。
93
- if (drawnRows >= 2) {
94
- g.append('line')
95
- .attr('x1', bodyX).attr('y1', 0)
96
- .attr('x2', bodyX).attr('y2', bodyHeight)
97
- .attr('stroke', data.stroke.color)
98
- .attr('stroke-width', data.stroke.width);
99
- }
100
-
101
- const x = data.position.x;
102
- g.attr('transform', `translate(${x},${data.position.y})`);
103
-
104
- data.size = { w: totalWidth, h: totalHeight };
105
-
106
- const anchorX = data.anchor_at_spine ? x : x + totalWidth / 2;
107
- data.anchors = {
108
- top: { x: anchorX, y: data.position.y },
109
- bottom: { x: anchorX, y: data.position.y + totalHeight },
110
- };
111
-
112
- attachClick(g, data);
113
-
114
- return g;
115
- }
116
- }
@@ -1,115 +0,0 @@
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
- }
@@ -1,23 +0,0 @@
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
- }
File without changes