|
11 | 11 | import { showTooltip, hideTooltip } from '$lib/components/Tooltip.svelte'; |
12 | 12 | import { paramInput } from '$lib/actions/paramInput'; |
13 | 13 | import { plotDataStore } from '$lib/plotting/processing/plotDataStore'; |
14 | | - import { NODE, snapTo2G, getPortPositionCalc } from '$lib/constants/dimensions'; |
| 14 | + import { NODE, getPortPositionCalc, calculateNodeDimensions } from '$lib/constants/dimensions'; |
15 | 15 | import PlotPreview from './PlotPreview.svelte'; |
16 | 16 |
|
17 | 17 | interface Props { |
|
136 | 136 | const maxPortsOnSide = $derived(Math.max(data.inputs.length, data.outputs.length)); |
137 | 137 | const pinnedCount = $derived(validPinnedParams().length); |
138 | 138 |
|
139 | | - // Node dimensions - calculated from data, always grid-snapped |
140 | | - // Port dimension: space needed for ports on one side |
141 | | - const minPortDimension = $derived(Math.max(1, maxPortsOnSide) * NODE.portSpacing); |
142 | | -
|
143 | | - // Pinned params height: border(1) + padding(10) + rows(20 each) + gaps(4 between) |
144 | | - // = 11 + 20*N + 4*(N-1) = 7 + 24*N for N > 0 |
145 | | - const pinnedParamsHeight = $derived(pinnedCount > 0 ? 7 + 24 * pinnedCount : 0); |
146 | | -
|
147 | | - // Width calculation: |
148 | | - // - Base width: 100px |
149 | | - // - Name width: ~6px per char + 24px padding, estimate from name length |
150 | | - // - Pinned params: need ~120px minimum for label + input |
151 | | - // - Vertical orientation: also consider port count |
152 | | - const nameWidth = $derived(data.name.length * 6 + 24); |
153 | | - const pinnedParamsWidth = $derived(pinnedCount > 0 ? 160 : 0); |
154 | | - const nodeWidth = $derived( |
155 | | - snapTo2G(Math.max( |
156 | | - NODE.baseWidth, |
157 | | - nameWidth, |
158 | | - pinnedParamsWidth, |
159 | | - isVertical ? minPortDimension : 0 |
160 | | - )) |
161 | | - ); |
162 | | -
|
163 | | - // Height: total content height vs port requirements (they share vertical space) |
164 | | - const contentHeight = $derived(NODE.baseHeight + pinnedParamsHeight); |
165 | | - const nodeHeight = $derived( |
166 | | - isVertical |
167 | | - ? snapTo2G(contentHeight) |
168 | | - : snapTo2G(Math.max(contentHeight, minPortDimension)) |
169 | | - ); |
| 139 | + // Node dimensions - calculated from shared utility (same as SvelteFlow bounds) |
| 140 | + const nodeDimensions = $derived(calculateNodeDimensions( |
| 141 | + data.name, |
| 142 | + data.inputs.length, |
| 143 | + data.outputs.length, |
| 144 | + pinnedCount, |
| 145 | + rotation |
| 146 | + )); |
| 147 | + const nodeWidth = $derived(nodeDimensions.width); |
| 148 | + const nodeHeight = $derived(nodeDimensions.height); |
170 | 149 |
|
171 | 150 | // Check if this is a Subsystem or Interface node (using shapes utility) |
172 | 151 | const isSubsystemNode = $derived(isSubsystem(data)); |
|
0 commit comments