A graph that grew past one screen needs somewhere to say what a part of it is for (#38)
game-maker / suite (push) Successful in 6m13s
game-maker / suite (push) Successful in 6m13s
The graph could hold any number of nodes and said nothing about which of them belonged together. Groups and comments are two separate things, as decided in the issue: a group is a titled box that carries the nodes it encloses, a comment is free text that carries nothing. Both live as optional arrays on Graph, not as registry nodes. A comment that were a real node would run through the interpreter, show up in the drop palettes and be compiled into a shader — the wrong place for a piece of text. As arrays on Graph they exist in all four graph kinds at once, and a document without them means exactly "no groups", so no format bump. Membership is computed when the box is grabbed, never stored: the center of a node inside the box travels with it, and a node dragged out is simply out. A box inside a box travels with the outer one, its own nodes included. A group is grabbed by its title bar only — its body stays transparent to the pointer, or a rubber band could never be drawn across the nodes it holds. Deleting a box deletes the box; the nodes stay where they are, because a box that silently took ten nodes with it would be the most expensive surprise in the feature. The color is a free picker, and the title color follows from it: relative luminance per WCAG, threshold at 0.179 where the two contrast ratios meet — not 0.5, which would pick white on mid grey where black reads better. Resizing snaps the far edge to the grid, not the width, so the corner that is not being dragged stays put. The minimum size rises in whole steps for that reason: 80 is no multiple of 24, so a box squeezed to the stop would have sat off-grid in exactly the mode meant to keep it on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1135205d69
commit
b9f1a9d319
21 files changed
+1473
-22
No files matched your search
@@ -28,6 +28,33 @@ export interface Box {
|
||||
h: number;
|
||||
}
|
||||
|
||||
/** Grows a snapped size by whole steps until it clears `min`, so the far edge stays on the grid. */
|
||||
function growToMin(size: number, min: number, step: number): number {
|
||||
return size >= min ? size : size + Math.ceil((min - size) / step) * step;
|
||||
}
|
||||
|
||||
/**
|
||||
* The size a resize drag gives a box that started as `start`. With a positive `step` the corner
|
||||
* being dragged – the far one, since the near one stays put – lands on the grid, the same way
|
||||
* `dragOffset` puts a dragged node's own corner there. `step <= 0` is "no snapping". `min` is
|
||||
* honoured in whole steps, so a box that hits its minimum is still grid-aligned.
|
||||
*/
|
||||
export function resizeSize(
|
||||
start: Omit<Box, 'id'>,
|
||||
dx: number,
|
||||
dy: number,
|
||||
step: number,
|
||||
min: { w: number; h: number },
|
||||
): { w: number; h: number } {
|
||||
const w = start.w + dx;
|
||||
const h = start.h + dy;
|
||||
if (!(step > 0)) return { w, h };
|
||||
return {
|
||||
w: growToMin(snapToStep(start.x + w, step) - start.x, min.w, step),
|
||||
h: growToMin(snapToStep(start.y + h, step) - start.y, min.h, step),
|
||||
};
|
||||
}
|
||||
|
||||
export interface Band {
|
||||
x1: number;
|
||||
y1: number;
|
||||
@@ -56,6 +83,22 @@ export function boxesInBand(boxes: readonly Box[], band: Band): string[] {
|
||||
.map((b) => b.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ids of the boxes a group carries: those whose centre lies inside it. The centre, not an overlap,
|
||||
* because a group and the node next to it always touch a little – and because the answer must be
|
||||
* the one the eye gives. Computed fresh whenever the group is grabbed, so nothing is remembered
|
||||
* about a node that has been dragged out.
|
||||
*/
|
||||
export function boxesCentredIn(boxes: readonly Box[], rect: Box | Omit<Box, 'id'>): string[] {
|
||||
return boxes
|
||||
.filter((b) => {
|
||||
const cx = b.x + b.w / 2;
|
||||
const cy = b.y + b.h / 2;
|
||||
return cx >= rect.x && cx <= rect.x + rect.w && cy >= rect.y && cy <= rect.y + rect.h;
|
||||
})
|
||||
.map((b) => b.id);
|
||||
}
|
||||
|
||||
export interface Bounds {
|
||||
minX: number;
|
||||
minY: number;
|
||||
|
||||
Reference in new issue
Block a user