@yanqirenshi/d3.pad 0.1.2 → 0.2.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 (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/renderers/D3PadRenderer.d.ts +1 -1
  7. package/dist/renderers/D3PadRenderer.d.ts.map +1 -1
  8. package/dist/utils/layout.d.ts +1 -1
  9. package/dist/utils/layout.d.ts.map +1 -1
  10. package/package.json +15 -5
  11. package/src/index.ts +12 -12
  12. package/src/renderers/D3PadRenderer.tsx +145 -145
  13. package/src/renderers/PadNodeRenderer.ts +517 -517
  14. package/src/renderers/blocks/EndBlockGeometry.ts +52 -52
  15. package/src/renderers/blocks/EndRenderer.tsx +48 -48
  16. package/src/renderers/blocks/EndRendererProps.ts +5 -5
  17. package/src/renderers/blocks/FunctionContainerGeometry.ts +54 -54
  18. package/src/renderers/blocks/FunctionContainerRenderer.tsx +62 -62
  19. package/src/renderers/blocks/FunctionHeaderGeometry.ts +43 -43
  20. package/src/renderers/blocks/FunctionHeaderProps.ts +6 -6
  21. package/src/renderers/blocks/FunctionHeaderRenderer.tsx +47 -47
  22. package/src/renderers/blocks/IfBlockGeometry.ts +98 -98
  23. package/src/renderers/blocks/IfRenderer.tsx +88 -88
  24. package/src/renderers/blocks/IfRendererProps.ts +7 -7
  25. package/src/renderers/blocks/LoopRenderer.tsx +50 -50
  26. package/src/renderers/blocks/LoopRendererProps.ts +7 -7
  27. package/src/renderers/blocks/README.md +29 -29
  28. package/src/renderers/blocks/StartBlockGeometry.ts +66 -66
  29. package/src/renderers/blocks/StartRenderer.tsx +49 -49
  30. package/src/renderers/blocks/StartRendererProps.ts +5 -5
  31. package/src/utils/layout.ts +247 -247
  32. package/dist/parsers/jsParser.d.ts +0 -2
  33. package/dist/parsers/jsParser.d.ts.map +0 -1
  34. package/dist/parsers/jsParser.js +0 -101
  35. package/dist/types.d.ts +0 -24
  36. package/dist/types.d.ts.map +0 -1
  37. package/dist/types.js +0 -1
  38. package/src/parsers/jsParser.ts +0 -122
  39. package/src/types.ts +0 -7
@@ -1,98 +1,98 @@
1
- import type { LayoutNode } from '../../utils/layout';
2
- import type { Point } from './Point';
3
-
4
- /**
5
- * IFブロックの形状計算を行うクラス
6
- * 描画に必要な各頂点の座標を計算・管理する
7
- */
8
- export class IfBlockGeometry {
9
- private readonly layout: LayoutNode;
10
- private readonly config = {
11
- gap: 20,
12
- notch: 15,
13
- minWedgeHeight: 60
14
- };
15
-
16
- constructor(layout: LayoutNode) {
17
- this.layout = layout;
18
- }
19
-
20
- /**
21
- * 左上の頂点座標を取得
22
- * くさび形の上辺の左端 (Thenブロックの中央高さと一致)
23
- */
24
- getTopLeft(): Point {
25
- const thenLayout = this.layout.children[0];
26
- const y = thenLayout.height / 2;
27
- return { x: 0, y };
28
- }
29
-
30
- /**
31
- * 右上の頂点座標を取得
32
- * くさび形の上辺の右端
33
- */
34
- getTopRight(): Point {
35
- const thenLayout = this.layout.children[0];
36
- const x = thenLayout.x - this.config.gap;
37
- const y = thenLayout.height / 2;
38
- return { x, y };
39
- }
40
-
41
- /**
42
- * 右下の頂点座標を取得
43
- * くさび形の下辺の右端
44
- */
45
- getBottomRight(): Point {
46
- const thenLayout = this.layout.children[0];
47
- const elseLayout = this.layout.children.length > 1 ? this.layout.children[1] : null;
48
-
49
- const topVertexY = thenLayout.height / 2;
50
- const x = thenLayout.x - this.config.gap;
51
-
52
- let y;
53
- if (elseLayout) {
54
- y = elseLayout.y + elseLayout.height / 2;
55
- } else {
56
- y = Math.max(topVertexY + this.config.minWedgeHeight, this.layout.height - 20);
57
- }
58
-
59
- return { x, y };
60
- }
61
-
62
- /**
63
- * 左下の頂点座標を取得
64
- * くさび形の下辺の左端
65
- */
66
- getBottomLeft(): Point {
67
- const bottomRight = this.getBottomRight();
68
- return { x: 0, y: bottomRight.y };
69
- }
70
-
71
- /**
72
- * 右辺の窪み(ノッチ)の座標を取得
73
- * 右上頂点と右下頂点の垂直方向の中央
74
- */
75
- getNotch(): Point {
76
- const topRight = this.getTopRight();
77
- const bottomRight = this.getBottomRight();
78
-
79
- const x = topRight.x - this.config.notch;
80
- const y = (topRight.y + bottomRight.y) / 2;
81
-
82
- return { x, y };
83
- }
84
-
85
- /**
86
- * ポリゴンのpoints属性用の文字列を生成
87
- * 順序: 左上 -> 右上 -> ノッチ -> 右下 -> 左下
88
- */
89
- getPolygonPoints(): string {
90
- const tl = this.getTopLeft();
91
- const tr = this.getTopRight();
92
- const notch = this.getNotch();
93
- const br = this.getBottomRight();
94
- const bl = this.getBottomLeft();
95
-
96
- return `${tl.x},${tl.y} ${tr.x},${tr.y} ${notch.x},${notch.y} ${br.x},${br.y} ${bl.x},${bl.y}`;
97
- }
98
- }
1
+ import type { LayoutNode } from '../../utils/layout';
2
+ import type { Point } from './Point';
3
+
4
+ /**
5
+ * IFブロックの形状計算を行うクラス
6
+ * 描画に必要な各頂点の座標を計算・管理する
7
+ */
8
+ export class IfBlockGeometry {
9
+ private readonly layout: LayoutNode;
10
+ private readonly config = {
11
+ gap: 20,
12
+ notch: 15,
13
+ minWedgeHeight: 60
14
+ };
15
+
16
+ constructor(layout: LayoutNode) {
17
+ this.layout = layout;
18
+ }
19
+
20
+ /**
21
+ * 左上の頂点座標を取得
22
+ * くさび形の上辺の左端 (Thenブロックの中央高さと一致)
23
+ */
24
+ getTopLeft(): Point {
25
+ const thenLayout = this.layout.children[0];
26
+ const y = thenLayout.height / 2;
27
+ return { x: 0, y };
28
+ }
29
+
30
+ /**
31
+ * 右上の頂点座標を取得
32
+ * くさび形の上辺の右端
33
+ */
34
+ getTopRight(): Point {
35
+ const thenLayout = this.layout.children[0];
36
+ const x = thenLayout.x - this.config.gap;
37
+ const y = thenLayout.height / 2;
38
+ return { x, y };
39
+ }
40
+
41
+ /**
42
+ * 右下の頂点座標を取得
43
+ * くさび形の下辺の右端
44
+ */
45
+ getBottomRight(): Point {
46
+ const thenLayout = this.layout.children[0];
47
+ const elseLayout = this.layout.children.length > 1 ? this.layout.children[1] : null;
48
+
49
+ const topVertexY = thenLayout.height / 2;
50
+ const x = thenLayout.x - this.config.gap;
51
+
52
+ let y;
53
+ if (elseLayout) {
54
+ y = elseLayout.y + elseLayout.height / 2;
55
+ } else {
56
+ y = Math.max(topVertexY + this.config.minWedgeHeight, this.layout.height - 20);
57
+ }
58
+
59
+ return { x, y };
60
+ }
61
+
62
+ /**
63
+ * 左下の頂点座標を取得
64
+ * くさび形の下辺の左端
65
+ */
66
+ getBottomLeft(): Point {
67
+ const bottomRight = this.getBottomRight();
68
+ return { x: 0, y: bottomRight.y };
69
+ }
70
+
71
+ /**
72
+ * 右辺の窪み(ノッチ)の座標を取得
73
+ * 右上頂点と右下頂点の垂直方向の中央
74
+ */
75
+ getNotch(): Point {
76
+ const topRight = this.getTopRight();
77
+ const bottomRight = this.getBottomRight();
78
+
79
+ const x = topRight.x - this.config.notch;
80
+ const y = (topRight.y + bottomRight.y) / 2;
81
+
82
+ return { x, y };
83
+ }
84
+
85
+ /**
86
+ * ポリゴンのpoints属性用の文字列を生成
87
+ * 順序: 左上 -> 右上 -> ノッチ -> 右下 -> 左下
88
+ */
89
+ getPolygonPoints(): string {
90
+ const tl = this.getTopLeft();
91
+ const tr = this.getTopRight();
92
+ const notch = this.getNotch();
93
+ const br = this.getBottomRight();
94
+ const bl = this.getBottomLeft();
95
+
96
+ return `${tl.x},${tl.y} ${tr.x},${tr.y} ${notch.x},${notch.y} ${br.x},${br.y} ${bl.x},${bl.y}`;
97
+ }
98
+ }
@@ -1,88 +1,88 @@
1
- import * as d3 from 'd3';
2
- import { IfBlockGeometry } from './IfBlockGeometry';
3
- import type { LayoutNode } from '../../utils/layout';
4
-
5
- /**
6
- * D3.jsでIF条件ブロック(くさび形)を描画します
7
- * @param parent 親のD3セレクション (SVGGElement)
8
- * @param layout レイアウトノード
9
- * @param renderChildFn 子ノードを再帰描画するための関数
10
- */
11
- export function renderIfBlock(
12
- parent: d3.Selection<SVGGElement, unknown, null, undefined>,
13
- layout: LayoutNode,
14
- renderChildFn: (parent: d3.Selection<SVGGElement, unknown, null, undefined>, layout: LayoutNode) => void
15
- ) {
16
- const { x, y, children, condition } = layout;
17
-
18
- const geometry = new IfBlockGeometry(layout);
19
- const tr = geometry.getTopRight();
20
- const br = geometry.getBottomRight();
21
- const notch = geometry.getNotch();
22
- const points = geometry.getPolygonPoints();
23
-
24
- const thenLayout = children[0];
25
- const elseLayout = children.length > 1 ? children[1] : null;
26
-
27
- const textX = notch.x / 2;
28
- const textY = notch.y;
29
-
30
- const g = parent.append('g').attr('transform', `translate(${x},${y})`);
31
-
32
- // 条件の形状 (ポリゴン)
33
- g.append('polygon')
34
- .attr('points', points)
35
- .attr('stroke', 'black')
36
- .attr('fill', '#fff')
37
- .attr('stroke-width', 1.5);
38
-
39
- // 条件テキスト
40
- g.append('text')
41
- .attr('x', textX)
42
- .attr('y', textY)
43
- .attr('text-anchor', 'middle')
44
- .attr('alignment-baseline', 'middle')
45
- .attr('font-family', 'monospace')
46
- .attr('font-size', 14)
47
- .attr('font-weight', 'bold')
48
- .text(condition || '?');
49
-
50
- // True分岐の接続線
51
- g.append('line')
52
- .attr('x1', tr.x).attr('y1', tr.y)
53
- .attr('x2', thenLayout.x).attr('y2', tr.y)
54
- .attr('stroke', 'black');
55
-
56
- g.append('text')
57
- .attr('x', tr.x - 5)
58
- .attr('y', tr.y - 5)
59
- .attr('text-anchor', 'end')
60
- .attr('font-size', 12)
61
- .attr('font-family', 'monospace')
62
- .attr('font-weight', 'bold')
63
- .text('T');
64
-
65
- // Then子ノード描画
66
- renderChildFn(g, thenLayout);
67
-
68
- // False分岐(存在する場合)
69
- if (elseLayout) {
70
- g.append('line')
71
- .attr('x1', br.x).attr('y1', br.y)
72
- .attr('x2', elseLayout.x).attr('y2', br.y)
73
- .attr('stroke', 'black');
74
-
75
- g.append('text')
76
- .attr('x', br.x - 5)
77
- .attr('y', br.y - 5)
78
- .attr('text-anchor', 'end')
79
- .attr('font-size', 12)
80
- .attr('font-family', 'monospace')
81
- .attr('font-weight', 'bold')
82
- .text('F');
83
-
84
- renderChildFn(g, elseLayout);
85
- }
86
-
87
- return g;
88
- }
1
+ import * as d3 from 'd3';
2
+ import { IfBlockGeometry } from './IfBlockGeometry';
3
+ import type { LayoutNode } from '../../utils/layout';
4
+
5
+ /**
6
+ * D3.jsでIF条件ブロック(くさび形)を描画します
7
+ * @param parent 親のD3セレクション (SVGGElement)
8
+ * @param layout レイアウトノード
9
+ * @param renderChildFn 子ノードを再帰描画するための関数
10
+ */
11
+ export function renderIfBlock(
12
+ parent: d3.Selection<SVGGElement, unknown, null, undefined>,
13
+ layout: LayoutNode,
14
+ renderChildFn: (parent: d3.Selection<SVGGElement, unknown, null, undefined>, layout: LayoutNode) => void
15
+ ) {
16
+ const { x, y, children, condition } = layout;
17
+
18
+ const geometry = new IfBlockGeometry(layout);
19
+ const tr = geometry.getTopRight();
20
+ const br = geometry.getBottomRight();
21
+ const notch = geometry.getNotch();
22
+ const points = geometry.getPolygonPoints();
23
+
24
+ const thenLayout = children[0];
25
+ const elseLayout = children.length > 1 ? children[1] : null;
26
+
27
+ const textX = notch.x / 2;
28
+ const textY = notch.y;
29
+
30
+ const g = parent.append('g').attr('transform', `translate(${x},${y})`);
31
+
32
+ // 条件の形状 (ポリゴン)
33
+ g.append('polygon')
34
+ .attr('points', points)
35
+ .attr('stroke', 'black')
36
+ .attr('fill', '#fff')
37
+ .attr('stroke-width', 1.5);
38
+
39
+ // 条件テキスト
40
+ g.append('text')
41
+ .attr('x', textX)
42
+ .attr('y', textY)
43
+ .attr('text-anchor', 'middle')
44
+ .attr('alignment-baseline', 'middle')
45
+ .attr('font-family', 'monospace')
46
+ .attr('font-size', 14)
47
+ .attr('font-weight', 'bold')
48
+ .text(condition || '?');
49
+
50
+ // True分岐の接続線
51
+ g.append('line')
52
+ .attr('x1', tr.x).attr('y1', tr.y)
53
+ .attr('x2', thenLayout.x).attr('y2', tr.y)
54
+ .attr('stroke', 'black');
55
+
56
+ g.append('text')
57
+ .attr('x', tr.x - 5)
58
+ .attr('y', tr.y - 5)
59
+ .attr('text-anchor', 'end')
60
+ .attr('font-size', 12)
61
+ .attr('font-family', 'monospace')
62
+ .attr('font-weight', 'bold')
63
+ .text('T');
64
+
65
+ // Then子ノード描画
66
+ renderChildFn(g, thenLayout);
67
+
68
+ // False分岐(存在する場合)
69
+ if (elseLayout) {
70
+ g.append('line')
71
+ .attr('x1', br.x).attr('y1', br.y)
72
+ .attr('x2', elseLayout.x).attr('y2', br.y)
73
+ .attr('stroke', 'black');
74
+
75
+ g.append('text')
76
+ .attr('x', br.x - 5)
77
+ .attr('y', br.y - 5)
78
+ .attr('text-anchor', 'end')
79
+ .attr('font-size', 12)
80
+ .attr('font-family', 'monospace')
81
+ .attr('font-weight', 'bold')
82
+ .text('F');
83
+
84
+ renderChildFn(g, elseLayout);
85
+ }
86
+
87
+ return g;
88
+ }
@@ -1,7 +1,7 @@
1
- import React from 'react';
2
- import type { LayoutNode } from '../../utils/layout';
3
-
4
- export interface IfRendererProps {
5
- layout: LayoutNode;
6
- renderChild: (layout: LayoutNode) => React.ReactNode;
7
- }
1
+ import React from 'react';
2
+ import type { LayoutNode } from '../../utils/layout';
3
+
4
+ export interface IfRendererProps {
5
+ layout: LayoutNode;
6
+ renderChild: (layout: LayoutNode) => React.ReactNode;
7
+ }
@@ -1,50 +1,50 @@
1
- import * as d3 from 'd3';
2
-
3
- /**
4
- * D3.jsでLoopの条件ボックスを描画します
5
- * @param parent 親のD3セレクション (SVGGElement)
6
- * @param x X座標
7
- * @param y Y座標
8
- * @param width ボックスの幅
9
- * @param height ボックスの高さ
10
- * @param condition 条件テキスト
11
- */
12
- export function renderLoopCondition(
13
- parent: d3.Selection<SVGGElement, unknown, null, undefined>,
14
- x: number,
15
- y: number,
16
- width: number,
17
- height: number,
18
- condition: string
19
- ) {
20
- const stripeX = 10;
21
-
22
- const g = parent.append('g').attr('transform', `translate(${x},${y})`);
23
-
24
- // 条件ボックス
25
- g.append('rect')
26
- .attr('x', 0)
27
- .attr('y', 0)
28
- .attr('width', width)
29
- .attr('height', height)
30
- .attr('stroke', 'black')
31
- .attr('fill', 'white');
32
-
33
- // 左側の縦線(PADスタイル)
34
- g.append('line')
35
- .attr('x1', stripeX).attr('y1', 0)
36
- .attr('x2', stripeX).attr('y2', height)
37
- .attr('stroke', 'black')
38
- .attr('stroke-width', 1);
39
-
40
- // 条件テキスト
41
- g.append('text')
42
- .attr('x', width / 2)
43
- .attr('y', height / 2 + 5)
44
- .attr('text-anchor', 'middle')
45
- .attr('font-family', 'monospace')
46
- .attr('font-size', 14)
47
- .text(condition);
48
-
49
- return g;
50
- }
1
+ import * as d3 from 'd3';
2
+
3
+ /**
4
+ * D3.jsでLoopの条件ボックスを描画します
5
+ * @param parent 親のD3セレクション (SVGGElement)
6
+ * @param x X座標
7
+ * @param y Y座標
8
+ * @param width ボックスの幅
9
+ * @param height ボックスの高さ
10
+ * @param condition 条件テキスト
11
+ */
12
+ export function renderLoopCondition(
13
+ parent: d3.Selection<SVGGElement, unknown, null, undefined>,
14
+ x: number,
15
+ y: number,
16
+ width: number,
17
+ height: number,
18
+ condition: string
19
+ ) {
20
+ const stripeX = 10;
21
+
22
+ const g = parent.append('g').attr('transform', `translate(${x},${y})`);
23
+
24
+ // 条件ボックス
25
+ g.append('rect')
26
+ .attr('x', 0)
27
+ .attr('y', 0)
28
+ .attr('width', width)
29
+ .attr('height', height)
30
+ .attr('stroke', 'black')
31
+ .attr('fill', 'white');
32
+
33
+ // 左側の縦線(PADスタイル)
34
+ g.append('line')
35
+ .attr('x1', stripeX).attr('y1', 0)
36
+ .attr('x2', stripeX).attr('y2', height)
37
+ .attr('stroke', 'black')
38
+ .attr('stroke-width', 1);
39
+
40
+ // 条件テキスト
41
+ g.append('text')
42
+ .attr('x', width / 2)
43
+ .attr('y', height / 2 + 5)
44
+ .attr('text-anchor', 'middle')
45
+ .attr('font-family', 'monospace')
46
+ .attr('font-size', 14)
47
+ .text(condition);
48
+
49
+ return g;
50
+ }
@@ -1,7 +1,7 @@
1
- export interface LoopRendererProps {
2
- x: number;
3
- y: number;
4
- width: number;
5
- height: number;
6
- condition: string;
7
- }
1
+ export interface LoopRendererProps {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ condition: string;
7
+ }
@@ -1,29 +1,29 @@
1
- # Renderers
2
-
3
- このディレクトリには、PAD図の特定のノードを描画するためのコンポーネントと、それに関連するクラス・インターフェースが含まれています。
4
-
5
- ## ファイル構成
6
-
7
- ### [IfRenderer.tsx](./IfRenderer.tsx)
8
- IF文(条件分岐)を描画するためのReactコンポーネントです。
9
- - くさび形(燕尾型)の図形を描画します。
10
- - `IfBlockGeometry` を使用して頂点座標を計算します。
11
- - 子要素(True/False分岐)を配置し、適切な接続線を描画します。
12
-
13
- ### [IfBlockGeometry.ts](./IfBlockGeometry.ts)
14
- IFブロックの幾何学的計算を行うクラスです。
15
- - レイアウト情報を受け取り、描画に必要な各頂点(左上、右上、右下、左下、ノッチ)の座標を計算します。
16
- - 描画ロジックと計算ロジックを分離するために使用されます。
17
-
18
- ### [IfRendererProps.ts](./IfRendererProps.ts)
19
- `IfRenderer` コンポーネントのProps定義です。
20
- - `layout`: レイアウト計算済みのノード情報
21
- - `renderChild`: 子要素を再帰的に描画するためのコールバック関数
22
-
23
- ### [Point.ts](./Point.ts)
24
- 2次元座標を表すシンプルなインターフェース定義です。
25
- - `{ x: number, y: number }`
26
-
27
- ## 設計方針
28
- - **1クラス1ファイル**: 各クラスやインターフェースは独立したファイルで管理し、可読性と保守性を高めています。
29
- - **ロジックの分離**: 座標計算などの複雑なロジックはコンポーネントから切り出し(`Geometry`クラス)、コンポーネントは描画に専念するように設計されています。
1
+ # Renderers
2
+
3
+ このディレクトリには、PAD図の特定のノードを描画するためのコンポーネントと、それに関連するクラス・インターフェースが含まれています。
4
+
5
+ ## ファイル構成
6
+
7
+ ### [IfRenderer.tsx](./IfRenderer.tsx)
8
+ IF文(条件分岐)を描画するためのReactコンポーネントです。
9
+ - くさび形(燕尾型)の図形を描画します。
10
+ - `IfBlockGeometry` を使用して頂点座標を計算します。
11
+ - 子要素(True/False分岐)を配置し、適切な接続線を描画します。
12
+
13
+ ### [IfBlockGeometry.ts](./IfBlockGeometry.ts)
14
+ IFブロックの幾何学的計算を行うクラスです。
15
+ - レイアウト情報を受け取り、描画に必要な各頂点(左上、右上、右下、左下、ノッチ)の座標を計算します。
16
+ - 描画ロジックと計算ロジックを分離するために使用されます。
17
+
18
+ ### [IfRendererProps.ts](./IfRendererProps.ts)
19
+ `IfRenderer` コンポーネントのProps定義です。
20
+ - `layout`: レイアウト計算済みのノード情報
21
+ - `renderChild`: 子要素を再帰的に描画するためのコールバック関数
22
+
23
+ ### [Point.ts](./Point.ts)
24
+ 2次元座標を表すシンプルなインターフェース定義です。
25
+ - `{ x: number, y: number }`
26
+
27
+ ## 設計方針
28
+ - **1クラス1ファイル**: 各クラスやインターフェースは独立したファイルで管理し、可読性と保守性を高めています。
29
+ - **ロジックの分離**: 座標計算などの複雑なロジックはコンポーネントから切り出し(`Geometry`クラス)、コンポーネントは描画に専念するように設計されています。