Skip to content

Commit a6cf57c

Browse files
authored
Merge pull request #233 from pathsim/fix/node-width-type-name
fix node width from type name
2 parents 4460d80 + adcd1a2 commit a6cf57c

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/lib/components/FlowCanvas.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@
392392
graphNode.inputs.length,
393393
graphNode.outputs.length,
394394
pinnedParamCount,
395-
rotation
395+
rotation,
396+
typeDef?.name
396397
);
397398
398399
// If node exists, update data but don't preserve selection here

src/lib/components/nodes/BaseNode.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@
142142
data.inputs.length,
143143
data.outputs.length,
144144
pinnedCount,
145-
rotation
145+
rotation,
146+
typeDef?.name
146147
));
147148
const nodeWidth = $derived(nodeDimensions.width);
148149
const nodeHeight = $derived(nodeDimensions.height);

src/lib/constants/dimensions.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { GRID_SIZE, G } from './grid';
99

1010
/** Node dimension constants (grid-aligned) */
1111
export const NODE = {
12-
/** Base width: 10 grid units = 100px */
13-
baseWidth: G.x10,
12+
/** Base width: 8 grid units = 80px */
13+
baseWidth: G.px(8),
1414
/** Base height: 4 grid units = 40px */
1515
baseHeight: G.x4,
1616
/** Spacing between ports: 2 grid units = 20px */
@@ -81,7 +81,8 @@ export function calculateNodeDimensions(
8181
inputCount: number,
8282
outputCount: number,
8383
pinnedParamCount: number,
84-
rotation: number
84+
rotation: number,
85+
typeName?: string
8586
): { width: number; height: number } {
8687
const isVertical = rotation === 1 || rotation === 3;
8788
const maxPortsOnSide = Math.max(inputCount, outputCount);
@@ -90,12 +91,15 @@ export function calculateNodeDimensions(
9091
// Pinned params height: border(1) + padding(10) + rows(20 each) + gaps(4 between)
9192
const pinnedParamsHeight = pinnedParamCount > 0 ? 7 + 24 * pinnedParamCount : 0;
9293

93-
// Width: base, name estimate, pinned params minimum, port dimension (if vertical)
94-
const nameWidth = name.length * 6 + 24;
94+
// Width: base, name estimate, type name estimate, pinned params minimum, port dimension (if vertical)
95+
// Name uses 10px font (~5px per char), type uses 8px font (~4px per char), plus padding for node margins
96+
const nameWidth = name.length * 5 + 20;
97+
const typeWidth = typeName ? typeName.length * 4 + 20 : 0;
9598
const pinnedParamsWidth = pinnedParamCount > 0 ? 160 : 0;
9699
const width = snapTo2G(Math.max(
97100
NODE.baseWidth,
98101
nameWidth,
102+
typeWidth,
99103
pinnedParamsWidth,
100104
isVertical ? minPortDimension : 0
101105
));

0 commit comments

Comments
 (0)