Graph: optionales Grid-Snapping beim Ziehen von Nodes
Ein Toggle in der Graph-Kopfzeile lässt gezogene Nodes auf dem 24er-Raster einrasten – derselben Größe, die den Hintergrund zeichnet. Einschalten bewegt nichts; die Regel greift erst beim nächsten Zug. Bei Mehrfachauswahl richtet sich jeder Node für sich aus, statt einem gemeinsamen Versatz zu folgen, der die alten krummen Abstände mitschleppen würde. Die Entscheidung liegt als reine Funktion in framing.ts, wo die übrige Graph-Geometrie schon wohnt, und ist dort wie im Browser gepinnt.
This commit is contained in:
1 parent
10d030376a
commit
4b47741fac
9 files changed
+187
-14
No files matched your search
+24
-3
@@ -1,9 +1,30 @@
|
||||
/**
|
||||
* Geometry of the graph view: which nodes a rubber band caught, and what view frames them all.
|
||||
* Both are decisions about rectangles, so they live here rather than in the canvas – the "fit"
|
||||
* that left nodes hanging out of the view was a sum that no test could reach.
|
||||
* Geometry of the graph view: which nodes a rubber band caught, what view frames them all, and
|
||||
* where a drag puts them. All three are decisions about rectangles, so they live here rather than
|
||||
* in the canvas – the "fit" that left nodes hanging out of the view was a sum that no test could
|
||||
* reach.
|
||||
*/
|
||||
|
||||
import { snapToStep } from '../ui/math';
|
||||
|
||||
export interface Point {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* The offset a drag adds to one node that started at `start`. A positive `step` lands that node on
|
||||
* the grid – applied per node, so a whole selection lines up instead of carrying its old spacing
|
||||
* along. `step <= 0` is "no snapping". A node nobody drags never moves either way.
|
||||
*/
|
||||
export function dragOffset(start: Point, dx: number, dy: number, step: number): Point {
|
||||
if (!(step > 0)) return { x: Math.round(dx), y: Math.round(dy) };
|
||||
return {
|
||||
x: snapToStep(start.x + dx, step) - start.x,
|
||||
y: snapToStep(start.y + dy, step) - start.y,
|
||||
};
|
||||
}
|
||||
|
||||
export interface Box {
|
||||
id: string;
|
||||
x: number;
|
||||
|
||||
Reference in new issue
Block a user