@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,52 +1,52 @@
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
+ 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 +1,48 @@
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
+ 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,5 +1,5 @@
1
- export interface EndRendererProps {
2
- x: number;
3
- y: number;
4
- label?: string;
5
- }
1
+ export interface EndRendererProps {
2
+ x: number;
3
+ y: number;
4
+ label?: string;
5
+ }
@@ -1,54 +1,54 @@
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
- }
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
+ }
@@ -1,62 +1,62 @@
1
- import * as d3 from 'd3';
2
- import { FunctionContainerGeometry } from './FunctionContainerGeometry';
3
-
4
- /**
5
- * D3.jsで関数コンテナ(ヘッダー+ボディ)を描画します
6
- * @param parent 親のD3セレクション (SVGGElement)
7
- * @param x X座標
8
- * @param y Y座標
9
- * @param width コンテナ幅
10
- * @param height コンテナ高さ
11
- * @param label 関数名ラベル
12
- * @returns 内部コンテンツを描画するためのグループセレクション
13
- */
14
- export function renderFunctionContainer(
15
- parent: d3.Selection<SVGGElement, unknown, null, undefined>,
16
- x: number,
17
- y: number,
18
- width: number,
19
- height: number,
20
- label: string
21
- ): d3.Selection<SVGGElement, unknown, null, undefined> {
22
- const geometry = new FunctionContainerGeometry(0, 0, width, height);
23
- const headerRect = geometry.getHeaderRect();
24
- const bodyRect = geometry.getBodyRect();
25
- const titlePos = geometry.getTitlePosition();
26
-
27
- const g = parent.append('g').attr('transform', `translate(${x},${y})`);
28
-
29
- // ヘッダー背景
30
- g.append('rect')
31
- .attr('x', headerRect.x)
32
- .attr('y', headerRect.y)
33
- .attr('width', headerRect.width)
34
- .attr('height', headerRect.height)
35
- .attr('fill', '#f0f0f0')
36
- .attr('stroke', 'black')
37
- .attr('stroke-width', 1);
38
-
39
- // ボディ背景/境界線
40
- g.append('rect')
41
- .attr('x', bodyRect.x)
42
- .attr('y', bodyRect.y)
43
- .attr('width', bodyRect.width)
44
- .attr('height', bodyRect.height)
45
- .attr('fill', 'none')
46
- .attr('stroke', 'black')
47
- .attr('stroke-width', 1);
48
-
49
- // タイトルテキスト
50
- g.append('text')
51
- .attr('x', titlePos.x)
52
- .attr('y', titlePos.y)
53
- .attr('text-anchor', 'start')
54
- .attr('alignment-baseline', 'middle')
55
- .attr('font-family', 'sans-serif')
56
- .attr('font-size', 14)
57
- .attr('font-weight', 'bold')
58
- .text(label);
59
-
60
- // 内部コンテンツ用グループを返す
61
- return g;
62
- }
1
+ import * as d3 from 'd3';
2
+ import { FunctionContainerGeometry } from './FunctionContainerGeometry';
3
+
4
+ /**
5
+ * D3.jsで関数コンテナ(ヘッダー+ボディ)を描画します
6
+ * @param parent 親のD3セレクション (SVGGElement)
7
+ * @param x X座標
8
+ * @param y Y座標
9
+ * @param width コンテナ幅
10
+ * @param height コンテナ高さ
11
+ * @param label 関数名ラベル
12
+ * @returns 内部コンテンツを描画するためのグループセレクション
13
+ */
14
+ export function renderFunctionContainer(
15
+ parent: d3.Selection<SVGGElement, unknown, null, undefined>,
16
+ x: number,
17
+ y: number,
18
+ width: number,
19
+ height: number,
20
+ label: string
21
+ ): d3.Selection<SVGGElement, unknown, null, undefined> {
22
+ const geometry = new FunctionContainerGeometry(0, 0, width, height);
23
+ const headerRect = geometry.getHeaderRect();
24
+ const bodyRect = geometry.getBodyRect();
25
+ const titlePos = geometry.getTitlePosition();
26
+
27
+ const g = parent.append('g').attr('transform', `translate(${x},${y})`);
28
+
29
+ // ヘッダー背景
30
+ g.append('rect')
31
+ .attr('x', headerRect.x)
32
+ .attr('y', headerRect.y)
33
+ .attr('width', headerRect.width)
34
+ .attr('height', headerRect.height)
35
+ .attr('fill', '#f0f0f0')
36
+ .attr('stroke', 'black')
37
+ .attr('stroke-width', 1);
38
+
39
+ // ボディ背景/境界線
40
+ g.append('rect')
41
+ .attr('x', bodyRect.x)
42
+ .attr('y', bodyRect.y)
43
+ .attr('width', bodyRect.width)
44
+ .attr('height', bodyRect.height)
45
+ .attr('fill', 'none')
46
+ .attr('stroke', 'black')
47
+ .attr('stroke-width', 1);
48
+
49
+ // タイトルテキスト
50
+ g.append('text')
51
+ .attr('x', titlePos.x)
52
+ .attr('y', titlePos.y)
53
+ .attr('text-anchor', 'start')
54
+ .attr('alignment-baseline', 'middle')
55
+ .attr('font-family', 'sans-serif')
56
+ .attr('font-size', 14)
57
+ .attr('font-weight', 'bold')
58
+ .text(label);
59
+
60
+ // 内部コンテンツ用グループを返す
61
+ return g;
62
+ }
@@ -1,43 +1,43 @@
1
- import type { Point } from './Point';
2
-
3
- /**
4
- * 関数ヘッダー(関数名表示部)の形状計算を行うクラス
5
- */
6
- export class FunctionHeaderGeometry {
7
- private readonly x: number;
8
- private readonly y: number;
9
- private readonly width: number;
10
- private readonly height: number = 30; // 固定高さ
11
-
12
- constructor(x: number, y: number, width: number) {
13
- this.x = x;
14
- this.y = y;
15
- this.width = width;
16
- }
17
-
18
- getX(): number {
19
- return this.x;
20
- }
21
-
22
- getY(): number {
23
- return this.y;
24
- }
25
-
26
- getWidth(): number {
27
- return this.width;
28
- }
29
-
30
- getHeight(): number {
31
- return this.height;
32
- }
33
-
34
- /**
35
- * テキストの配置位置(左寄せ、パディングあり)を取得
36
- */
37
- getTextPosition(): Point {
38
- return {
39
- x: this.x + 10, // 左パディング
40
- y: this.y + this.height / 2
41
- };
42
- }
43
- }
1
+ import type { Point } from './Point';
2
+
3
+ /**
4
+ * 関数ヘッダー(関数名表示部)の形状計算を行うクラス
5
+ */
6
+ export class FunctionHeaderGeometry {
7
+ private readonly x: number;
8
+ private readonly y: number;
9
+ private readonly width: number;
10
+ private readonly height: number = 30; // 固定高さ
11
+
12
+ constructor(x: number, y: number, width: number) {
13
+ this.x = x;
14
+ this.y = y;
15
+ this.width = width;
16
+ }
17
+
18
+ getX(): number {
19
+ return this.x;
20
+ }
21
+
22
+ getY(): number {
23
+ return this.y;
24
+ }
25
+
26
+ getWidth(): number {
27
+ return this.width;
28
+ }
29
+
30
+ getHeight(): number {
31
+ return this.height;
32
+ }
33
+
34
+ /**
35
+ * テキストの配置位置(左寄せ、パディングあり)を取得
36
+ */
37
+ getTextPosition(): Point {
38
+ return {
39
+ x: this.x + 10, // 左パディング
40
+ y: this.y + this.height / 2
41
+ };
42
+ }
43
+ }
@@ -1,6 +1,6 @@
1
- export interface FunctionHeaderProps {
2
- x: number;
3
- y: number;
4
- width: number;
5
- label: string;
6
- }
1
+ export interface FunctionHeaderProps {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ label: string;
6
+ }
@@ -1,47 +1,47 @@
1
- import * as d3 from 'd3';
2
- import { FunctionHeaderGeometry } from './FunctionHeaderGeometry';
3
-
4
- /**
5
- * D3.jsで関数ヘッダー(ラベル付きバー)を描画します
6
- * @param parent 親のD3セレクション (SVGGElement)
7
- * @param x X座標
8
- * @param y Y座標
9
- * @param width ヘッダー幅
10
- * @param label 関数名ラベル
11
- */
12
- export function renderFunctionHeader(
13
- parent: d3.Selection<SVGGElement, unknown, null, undefined>,
14
- x: number,
15
- y: number,
16
- width: number,
17
- label: string
18
- ) {
19
- const geometry = new FunctionHeaderGeometry(x, y, width);
20
- const textPos = geometry.getTextPosition();
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', geometry.getWidth())
29
- .attr('height', geometry.getHeight())
30
- .attr('fill', '#e8edf2')
31
- .attr('stroke', 'black')
32
- .attr('stroke-width', 1);
33
-
34
- // 関数名テキスト
35
- g.append('text')
36
- .attr('x', textPos.x)
37
- .attr('y', textPos.y)
38
- .attr('text-anchor', 'start')
39
- .attr('alignment-baseline', 'middle')
40
- .attr('font-family', 'sans-serif')
41
- .attr('font-size', 14)
42
- .attr('font-weight', 'bold')
43
- .attr('fill', '#000')
44
- .text(label);
45
-
46
- return g;
47
- }
1
+ import * as d3 from 'd3';
2
+ import { FunctionHeaderGeometry } from './FunctionHeaderGeometry';
3
+
4
+ /**
5
+ * D3.jsで関数ヘッダー(ラベル付きバー)を描画します
6
+ * @param parent 親のD3セレクション (SVGGElement)
7
+ * @param x X座標
8
+ * @param y Y座標
9
+ * @param width ヘッダー幅
10
+ * @param label 関数名ラベル
11
+ */
12
+ export function renderFunctionHeader(
13
+ parent: d3.Selection<SVGGElement, unknown, null, undefined>,
14
+ x: number,
15
+ y: number,
16
+ width: number,
17
+ label: string
18
+ ) {
19
+ const geometry = new FunctionHeaderGeometry(x, y, width);
20
+ const textPos = geometry.getTextPosition();
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', geometry.getWidth())
29
+ .attr('height', geometry.getHeight())
30
+ .attr('fill', '#e8edf2')
31
+ .attr('stroke', 'black')
32
+ .attr('stroke-width', 1);
33
+
34
+ // 関数名テキスト
35
+ g.append('text')
36
+ .attr('x', textPos.x)
37
+ .attr('y', textPos.y)
38
+ .attr('text-anchor', 'start')
39
+ .attr('alignment-baseline', 'middle')
40
+ .attr('font-family', 'sans-serif')
41
+ .attr('font-size', 14)
42
+ .attr('font-weight', 'bold')
43
+ .attr('fill', '#000')
44
+ .text(label);
45
+
46
+ return g;
47
+ }