Skip to content

Commit ca0bfd9

Browse files
authored
Merge pull request #232 from pathsim/feature/grid-aligned-routing
fix annotation with new grid
2 parents 81e6b3e + d603597 commit ca0bfd9

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/lib/components/canvas/flowConverters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export function toAnnotationNode(annotation: Annotation): Node<Annotation> {
4949
data: annotation,
5050
width: annotation.width,
5151
height: annotation.height,
52+
// Annotations use top-left origin (overrides global nodeOrigin)
53+
origin: [0, 0] as [number, number],
5254
selectable: true,
5355
draggable: true,
5456
connectable: false,

src/lib/components/nodes/AnnotationNode.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { renderMarkdown } from '$lib/utils/markdownRenderer';
77
import { getKatexCssUrl } from '$lib/utils/katexLoader';
88
import { DEFAULT_NODE_COLOR } from '$lib/utils/colors';
9+
import { GRID_SIZE } from '$lib/constants/grid';
910
import { tooltip } from '$lib/components/Tooltip.svelte';
1011
import ColorPicker from '$lib/components/dialogs/shared/ColorPicker.svelte';
1112
import Icon from '$lib/components/icons/Icon.svelte';
@@ -129,6 +130,15 @@
129130
}
130131
}
131132
133+
// Snap resize dimensions to grid
134+
function handleResizeEnd(_event: unknown, params: { width: number; height: number }) {
135+
const snappedWidth = Math.round(params.width / GRID_SIZE) * GRID_SIZE;
136+
const snappedHeight = Math.round(params.height / GRID_SIZE) * GRID_SIZE;
137+
graphStore.updateAnnotation(id, {
138+
width: Math.max(100, snappedWidth),
139+
height: Math.max(50, snappedHeight)
140+
});
141+
}
132142
</script>
133143

134144
<svelte:head>
@@ -141,6 +151,7 @@
141151
minWidth={100}
142152
minHeight={50}
143153
isVisible={selected}
154+
onResizeEnd={handleResizeEnd}
144155
/>
145156

146157
<!-- svelte-ignore a11y_no_static_element_interactions -->

0 commit comments

Comments
 (0)