Skip to content

Commit 340ab0c

Browse files
committed
Revert "(feat): Rendering of Labels and Arguments."
This reverts commit f705832.
1 parent 8ae8bd5 commit 340ab0c

File tree

10 files changed

+10
-157
lines changed

10 files changed

+10
-157
lines changed

modules/code-builder/src/@types/brick.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ export interface IBrick extends IBrickStyle {
107107
/** glyph icon associated with the brick */
108108
get glyph(): string;
109109

110-
get labelWidth(): number;
111-
set labelWidth(value: number);
112110
// states
113111
/** whether brick is highlighted */
114112
highlighted: boolean;

modules/code-builder/src/brick/design0/BrickBlock.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ export default class BrickBlock extends BrickModelBlock {
4848

4949
const path = generatePath({
5050
hasNest: true,
51+
hasNotchNest: true,
5152
hasNotchArg: true,
5253
hasNotchInsTop: this._connectAbove,
5354
hasNotchInsBot: this._connectBelow,
5455
scale: this._scale,
5556
nestLengthY: 30,
56-
innerLengthX: this.labelWidth,
57+
innerLengthX: 100,
5758
argHeights: Array.from({ length: argsLength }, () => 17),
5859
}).path;
5960

modules/code-builder/src/brick/design0/BrickData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class BrickData extends BrickModelData {
4141
hasNotchInsTop: false,
4242
hasNotchInsBot: false,
4343
scale: this._scale,
44-
innerLengthX: this.labelWidth,
44+
innerLengthX: 100,
4545
argHeights: [],
4646
}).path;
4747

modules/code-builder/src/brick/design0/BrickExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class BrickExpression extends BrickModelExpression {
5151
hasNotchInsTop: false,
5252
hasNotchInsBot: false,
5353
scale: this._scale,
54-
innerLengthX: this.labelWidth,
54+
innerLengthX: 100,
5555
argHeights: Array.from({ length: argsLength }, () => 17),
5656
}).path;
5757

modules/code-builder/src/brick/design0/BrickStatement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class BrickStatement extends BrickModelStatement {
5252
hasNotchInsTop: true,
5353
hasNotchInsBot: true,
5454
scale: this._scale,
55-
innerLengthX: this.labelWidth,
55+
innerLengthX: 100,
5656
argHeights: Array.from({ length: argsLength }, () => 17),
5757
}).path;
5858

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
import type { IBrickBlock } from '@/@types/brick';
2-
import { useEffect, useRef, useState } from 'react';
32

43
// -------------------------------------------------------------------------------------------------
54

65
export default function (props: { instance: IBrickBlock }): JSX.Element {
76
const { instance } = props;
8-
const [svgString, setSvgString] = useState<string>('');
9-
const label = useRef<SVGTextElement>(null);
10-
const [argLabels, setArgLabels] = useState<string[]>([]);
11-
12-
useEffect(() => {
13-
const labelWidth = label.current?.getBBox();
14-
const args = instance.args;
15-
let argMaxWidth = 0;
16-
for (let arg in args) {
17-
setArgLabels((argLabels) => [...argLabels, args[arg].label]);
18-
argMaxWidth = Math.max(argMaxWidth, args[arg].label.length);
19-
}
20-
const width = (labelWidth?.width as number) + argMaxWidth * 12.8 + 40;
21-
instance.labelWidth = width;
22-
setSvgString(instance.SVGpaths[0]);
23-
}, []);
247

258
return (
26-
<g transform={`scale(${instance.scale})`} id="svg1">
9+
<g transform={`scale(${instance.scale})`}>
2710
<path
28-
d={svgString}
11+
d={instance.SVGpaths[0]}
2912
style={{
3013
fill: instance.colorBg as string,
3114
fillOpacity: 1,
@@ -35,30 +18,6 @@ export default function (props: { instance: IBrickBlock }): JSX.Element {
3518
strokeOpacity: 1,
3619
}}
3720
/>
38-
<text
39-
ref={label}
40-
x="12%"
41-
y="8%"
42-
dominantBaseline="middle"
43-
style={{
44-
fontSize: '0.8em',
45-
}}
46-
>
47-
{instance.label}
48-
</text>
49-
{argLabels.map((argLabel, index) => (
50-
<text
51-
key={index}
52-
x={`${(label.current?.getBBox().width as number) + (index + 1)}%`}
53-
y="8%"
54-
dominantBaseline="middle"
55-
style={{
56-
fontSize: '0.8em',
57-
}}
58-
>
59-
{argLabel}
60-
</text>
61-
))}
6221
</g>
6322
);
6423
}
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
import type { IBrickData } from '@/@types/brick';
2-
import { useEffect, useRef, useState } from 'react';
32

43
export default function (props: { instance: IBrickData }): JSX.Element {
54
const { instance } = props;
6-
const [svgString, setSvgString] = useState<string>('');
7-
const label = useRef<SVGTextElement>(null);
8-
9-
useEffect(() => {
10-
const labelWidth = label.current?.getBBox();
11-
const width = (labelWidth?.width as number) + 20;
12-
instance.labelWidth = width;
13-
setSvgString(instance.SVGpaths[0]);
14-
}, []);
155

166
return (
177
<g transform={`scale(${instance.scale})`}>
188
<path
19-
d={svgString}
9+
d={instance.SVGpaths[0]}
2010
style={{
2111
fill: instance.colorBg as string,
2212
fillOpacity: 1,
@@ -26,17 +16,6 @@ export default function (props: { instance: IBrickData }): JSX.Element {
2616
strokeOpacity: 1,
2717
}}
2818
/>
29-
<text
30-
ref={label}
31-
x="5%"
32-
y="8%"
33-
dominantBaseline="middle"
34-
style={{
35-
fontSize: '0.8em',
36-
}}
37-
>
38-
{instance.label}
39-
</text>
4019
</g>
4120
);
4221
}
Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
import type { IBrickExpression } from '@/@types/brick';
2-
import { useEffect, useRef, useState } from 'react';
32

43
// -------------------------------------------------------------------------------------------------
54

65
export default function (props: { instance: IBrickExpression }): JSX.Element {
76
const { instance } = props;
8-
const [svgString, setSvgString] = useState<string>('');
9-
const label = useRef<SVGTextElement>(null);
10-
const [argLabels, setArgLabels] = useState<string[]>([]);
11-
12-
useEffect(() => {
13-
const labelWidth = label.current?.getBBox();
14-
const args = instance.args;
15-
let argMaxWidth = 0;
16-
for (let arg in args) {
17-
setArgLabels((argLabels) => [...argLabels, args[arg].label]);
18-
argMaxWidth = Math.max(argMaxWidth, args[arg].label.length);
19-
}
20-
const width = (labelWidth?.width as number) + argMaxWidth * 12.8 + 40;
21-
instance.labelWidth = width;
22-
setSvgString(instance.SVGpaths[0]);
23-
}, []);
247

258
return (
269
<g transform={`scale(${instance.scale})`}>
2710
<path
28-
d={svgString}
11+
d={instance.SVGpaths[0]}
2912
style={{
3013
fill: instance.colorBg as string,
3114
fillOpacity: 1,
@@ -35,30 +18,6 @@ export default function (props: { instance: IBrickExpression }): JSX.Element {
3518
strokeOpacity: 1,
3619
}}
3720
/>
38-
<text
39-
ref={label}
40-
x="5%"
41-
y="8%"
42-
dominantBaseline="middle"
43-
style={{
44-
fontSize: '0.8em',
45-
}}
46-
>
47-
{instance.label}
48-
</text>
49-
{argLabels.map((argLabel, index) => (
50-
<text
51-
key={index}
52-
x={`${(label.current?.getBBox().width as number) - 18}%`}
53-
y="8%"
54-
dominantBaseline="middle"
55-
style={{
56-
fontSize: '0.8em',
57-
}}
58-
>
59-
{argLabel}
60-
</text>
61-
))}
6221
</g>
6322
);
6423
}
Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
import type { IBrickStatement } from '@/@types/brick';
2-
import { useEffect, useRef, useState } from 'react';
32

43
// -------------------------------------------------------------------------------------------------
54

65
export default function (props: { instance: IBrickStatement }): JSX.Element {
76
const { instance } = props;
8-
const [svgString, setSvgString] = useState<string>('');
9-
const label = useRef<SVGTextElement>(null);
10-
const [argLabels, setArgLabels] = useState<string[]>([]);
11-
12-
useEffect(() => {
13-
const labelWidth = label.current?.getBBox();
14-
const args = instance.args;
15-
let argMaxWidth = 0;
16-
for (let arg in args) {
17-
setArgLabels((argLabels) => [...argLabels, args[arg].label]);
18-
argMaxWidth = Math.max(argMaxWidth, args[arg].label.length);
19-
}
20-
const width = (labelWidth?.width as number) + argMaxWidth * 12.8 + 40;
21-
instance.labelWidth = width;
22-
setSvgString(instance.SVGpaths[0]);
23-
}, []);
247

258
return (
269
<g transform={`scale(${instance.scale})`}>
2710
<path
28-
d={svgString}
11+
d={instance.SVGpaths[0]}
2912
style={{
3013
fill: instance.colorBg as string,
3114
fillOpacity: 1,
@@ -35,30 +18,6 @@ export default function (props: { instance: IBrickStatement }): JSX.Element {
3518
strokeOpacity: 1,
3619
}}
3720
/>
38-
<text
39-
ref={label}
40-
x="8%"
41-
y="8%"
42-
dominantBaseline="middle"
43-
style={{
44-
fontSize: '0.8em',
45-
}}
46-
>
47-
{instance.label}
48-
</text>
49-
{argLabels.map((argLabel, index) => (
50-
<text
51-
key={index}
52-
x={`${(label.current?.getBBox().width as number) - 18}%`}
53-
y="8%"
54-
dominantBaseline="middle"
55-
style={{
56-
fontSize: '0.8em',
57-
}}
58-
>
59-
{argLabel}
60-
</text>
61-
))}
6221
</g>
6322
);
6423
}

modules/code-builder/src/brick/model.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ abstract class BrickModel implements IBrick {
3434
protected _outline: TBrickColor;
3535
protected _scale: number;
3636

37-
public labelWidth = 0;
38-
3937
public highlighted = false;
4038

4139
constructor(params: {

0 commit comments

Comments
 (0)