Skip to content

Commit 3ff9086

Browse files
Merge pull request #65 from FREELABEL/feat/unified-graph
feat(graph): board interiors fold into the IRIS graph — items, lists, legend/filter, ELON parity
2 parents ab0a764 + 37e4ea2 commit 3ff9086

12 files changed

Lines changed: 2100 additions & 72 deletions

File tree

‎bun.lock‎

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
import { describe, expect, test } from "bun:test"
2+
import {
3+
DEFAULT_EDGE_STRENGTH,
4+
edgeCaption,
5+
edgeLabelBox,
6+
labelScale,
7+
nodeLabelBox,
8+
placeLabels,
9+
DEFAULT_TYPE,
10+
edgeStrengthOf,
11+
isDragGesture,
12+
NODE_TYPES,
13+
nodeStyle,
14+
presentTypesOf,
15+
typeCountsOf,
16+
} from "./iris-force-graph"
17+
18+
/**
19+
* The graph folds Elon's 14-type vocabulary in beside the board-to-board view it already had.
20+
* These cover the parts where being wrong is SILENT — a graph that renders beautifully while
21+
* every node is the wrong colour, or whose nodes cannot be clicked, looks fine in a screenshot.
22+
*/
23+
24+
describe("the vocabulary is Elon's, not a parallel one", () => {
25+
test("bloq is #6366f1 — the colour this graph already hardcoded for every node", () => {
26+
// This is the whole reason the two graphs fold together rather than being reconciled:
27+
// NODE_COLOR was already Elon's bloq colour, so the old view was this table's bloq layer.
28+
expect(NODE_TYPES.bloq.color).toBe("#6366f1")
29+
})
30+
31+
const ELON_14 = ["atlas", "artist", "person", "venue", "event", "brand", "deal", "bloq", "agent", "workflow", "program", "leadcluster", "memory", "playbook"]
32+
33+
test("all 14 of Elon's types are present", () => {
34+
for (const t of ELON_14) expect(NODE_TYPES[t], t).toBeDefined()
35+
})
36+
37+
test("additions are DECLARED, not accidental", () => {
38+
// Asserting an exact count of 14 would fail the moment this product grows a type Elon
39+
// does not have, and the fix would be to bump a number — which is how a vocabulary drifts
40+
// without anyone deciding to. Naming the extras makes each one a decision on the record.
41+
const extras = Object.keys(NODE_TYPES).filter((t) => !ELON_14.includes(t))
42+
// Empty since #185584 ported the interior onto ELON's own rules: `page` and `list` were
43+
// desktop-only and nothing emits them now. Adding one back should fail here until someone
44+
// decides it on purpose.
45+
expect(extras).toEqual([])
46+
})
47+
48+
test("every type has an inline icon path, never a font glyph name", () => {
49+
for (const [name, t] of Object.entries(NODE_TYPES)) {
50+
// A FontAwesome class here would render nothing: there is no icon font, and the CSP
51+
// blocks webfont CDNs so it would fail silently rather than loudly.
52+
expect(t.icon, name).not.toContain("fa-")
53+
expect(t.icon, name).toMatch(/^[Mm]/)
54+
}
55+
})
56+
})
57+
58+
describe("an untyped payload still renders exactly as it did before", () => {
59+
test("a node with no type is a bloq", () => {
60+
expect(nodeStyle(undefined).color).toBe(NODE_TYPES[DEFAULT_TYPE].color)
61+
})
62+
63+
test("an UNKNOWN type falls back rather than rendering undefined", () => {
64+
// Reading .color off undefined throws inside a d3 tick, where the stack says nothing.
65+
expect(nodeStyle("not-a-real-type").color).toBe(NODE_TYPES[DEFAULT_TYPE].color)
66+
})
67+
68+
test("a board-only graph offers no legend, because one chip is not a choice", () => {
69+
const boards = [{ type: undefined }, { type: undefined }, { type: "bloq" }]
70+
expect(presentTypesOf(boards)).toEqual(["bloq"])
71+
})
72+
})
73+
74+
describe("the legend describes the data, not the vocabulary", () => {
75+
const mixed = [{ type: "bloq" }, { type: "agent" }, { type: "agent" }, { type: undefined }]
76+
77+
test("only types PRESENT get a chip", () => {
78+
// A fixed list of 14 would advertise Venues on a graph that has none, which reads as
79+
// "you have no venues" when the truth is "this view never shows them".
80+
expect(presentTypesOf(mixed)).toEqual(["bloq", "agent"])
81+
})
82+
83+
test("chips keep the vocabulary's order so the legend does not reshuffle", () => {
84+
const reordered = [{ type: "playbook" }, { type: "atlas" }, { type: "bloq" }]
85+
expect(presentTypesOf(reordered)).toEqual(["atlas", "bloq", "playbook"])
86+
})
87+
88+
test("counts fold untyped nodes into bloq", () => {
89+
expect(typeCountsOf(mixed)).toEqual({ bloq: 2, agent: 2 })
90+
})
91+
})
92+
93+
describe("edge strength is Elon's, not d3's", () => {
94+
test("an edge's own strength wins", () => {
95+
expect(edgeStrengthOf({ type: "parent", strength: 0.9 })).toBe(0.9)
96+
})
97+
98+
test("a hierarchy holds tighter than an affiliation", () => {
99+
// If these were equal, cluster tightness would carry no meaning.
100+
expect(edgeStrengthOf({ type: "parent" })).toBeGreaterThan(edgeStrengthOf({ type: "affiliated" }))
101+
})
102+
103+
test("an unknown type gets Elon's 0.3 fallback, NOT d3's 1/min(degree)", () => {
104+
// d3's default slackens hub links exactly where Elon's stay tight, which is why two
105+
// graphs built from identical data settled differently.
106+
expect(edgeStrengthOf({ type: "whatever" })).toBe(DEFAULT_EDGE_STRENGTH)
107+
})
108+
})
109+
110+
describe("clickDistance — the bug you could feel", () => {
111+
test("a dead-still tap is a click", () => {
112+
expect(isDragGesture({ x: 100, y: 100 }, { x: 100, y: 100 })).toBe(false)
113+
})
114+
115+
test("a 1px wobble is STILL a click", () => {
116+
// This is the actual reported symptom: aiming carefully made selection less reliable,
117+
// because holding steady enough to move one pixel still armed a drag and ate the click.
118+
expect(isDragGesture({ x: 100, y: 100 }, { x: 101, y: 100 })).toBe(false)
119+
})
120+
121+
test("5px is within tolerance, 7px is a drag", () => {
122+
expect(isDragGesture({ x: 0, y: 0 }, { x: 5, y: 0 })).toBe(false)
123+
expect(isDragGesture({ x: 0, y: 0 }, { x: 7, y: 0 })).toBe(true)
124+
})
125+
126+
test("distance is diagonal, not per-axis", () => {
127+
// 5,5 is 7.07 away. A per-axis check would call this a click on both axes and never drag.
128+
expect(isDragGesture({ x: 0, y: 0 }, { x: 5, y: 5 })).toBe(true)
129+
})
130+
131+
test("no pointer recorded is not a drag", () => {
132+
expect(isDragGesture(null, { x: 9, y: 9 })).toBe(false)
133+
expect(isDragGesture({ x: 0, y: 0 }, null)).toBe(false)
134+
})
135+
})
136+
137+
describe("label placement — decided, not all drawn", () => {
138+
const box = (id: string, x: number, priority: number, owner?: string) => ({ id, x, y: 0, w: 50, h: 10, priority, owner })
139+
140+
test("two overlapping labels: the more important one wins", () => {
141+
const v = placeLabels([box("small", 0, 12), box("hub", 10, 20)], [])
142+
expect([...v]).toEqual(["hub"])
143+
})
144+
145+
test("labels that do not touch are both drawn", () => {
146+
const v = placeLabels([box("a", 0, 12), box("b", 100, 12)], [])
147+
expect(v.has("a") && v.has("b")).toBe(true)
148+
})
149+
150+
test("the hovered label is drawn even when it loses on priority", () => {
151+
// Hovering a node and still not being able to read its name is worse than clutter.
152+
const v = placeLabels([box("small", 0, 12), box("hub", 10, 20)], [], new Set(["small"]))
153+
expect(v.has("small")).toBe(true)
154+
})
155+
156+
test("the hovered label is drawn even when it sits on ANOTHER node's circle", () => {
157+
// Priority sorting alone cannot guarantee this: an obstacle is not a placed label, so
158+
// going first does not clear it. The pin has to override the obstacle check itself.
159+
const otherCircle = { x: 0, y: 0, w: 50, h: 10, owner: "n:9" }
160+
expect(placeLabels([box("n:1", 0, 12, "n:1")], [otherCircle], new Set(["n:1"])).has("n:1")).toBe(true)
161+
})
162+
163+
test("a node's OWN circle does not hide its label; another node's does", () => {
164+
const circle = { x: 0, y: 0, w: 50, h: 10, owner: "n:1" }
165+
expect(placeLabels([box("n:1", 0, 12, "n:1")], [circle]).has("n:1")).toBe(true)
166+
expect(placeLabels([box("n:2", 0, 12, "n:2")], [circle]).has("n:2")).toBe(false)
167+
})
168+
169+
test("equal priorities resolve the same way every call — no per-frame flicker", () => {
170+
const run = () => [...placeLabels([box("b", 0, 12), box("a", 10, 12)], [])]
171+
expect(run()).toEqual(run())
172+
expect(run()).toEqual(["a"])
173+
})
174+
175+
test("ZOOMING IN reveals labels hidden at 1x", () => {
176+
// The reason labels are screen-constant: when text scaled with the zoom group, overlap
177+
// was identical at every zoom and zooming in — the gesture you use to read a cluster —
178+
// could never free a single label.
179+
const a = { id: 1, name: "Package Index v0.1", size: 12, x: 0, y: 0 }
180+
const b = { id: 2, name: "Dataset + Page SERVED", size: 12, x: 60, y: 0 }
181+
const at = (k: number) => placeLabels([nodeLabelBox(a, k), nodeLabelBox(b, k)], []).size
182+
expect(at(1)).toBe(1)
183+
expect(at(3)).toBe(2)
184+
})
185+
186+
test("labels stay screen-constant: 1x is unchanged, zoom is clamped", () => {
187+
expect(labelScale(1)).toBe(1)
188+
expect(labelScale(2)).toBe(0.5)
189+
expect(labelScale(100)).toBe(labelScale(4))
190+
expect(labelScale(0.01)).toBe(labelScale(0.3))
191+
})
192+
193+
test("a label already on screen keeps its place against a near-equal rival (hysteresis)", () => {
194+
const hub = { id: 1, name: "Agents", size: 14, x: 0, y: 0 }
195+
const item = { id: 2, name: "Agents", size: 12, x: 5, y: 0 }
196+
// Without hysteresis the bigger node takes it...
197+
expect([...placeLabels([nodeLabelBox(hub, 1), nodeLabelBox(item, 1)], [])]).toEqual(["n:1"])
198+
// ...but a label that was already showing is not displaced by a 2px size difference.
199+
expect([...placeLabels([nodeLabelBox(hub, 1), nodeLabelBox(item, 1, true)], [])]).toEqual(["n:2"])
200+
})
201+
202+
test("an edge caption never beats a node name", () => {
203+
const node = nodeLabelBox({ id: 1, name: "Memory", size: 12, x: 0, y: 0 }, 1)
204+
const edge = edgeLabelBox({ x1: -20, y1: node.y + 20, x2: 20, y2: node.y + 20, text: "parent" }, 0, 1, true)
205+
const v = placeLabels([edge, node], [])
206+
expect(v.has("n:1")).toBe(true)
207+
})
208+
})
209+
210+
describe("untyped edges — the crash an expanded board caused", () => {
211+
// Live on board 682: 20 of 52 edges carry no `type`, 19 carry neither type nor label. The
212+
// renderer called e.type.replace on them and the error boundary took the whole app down.
213+
test("an edge with neither label nor type has NO caption, and does not throw", () => {
214+
expect(() => edgeCaption({})).not.toThrow()
215+
expect(edgeCaption({})).toBeNull()
216+
})
217+
218+
test("ELON's labelled hub edge uses its label", () => {
219+
expect(edgeCaption({ label: "memory" })).toBe("memory")
220+
})
221+
222+
test("a board relation with only a type is still captioned by it", () => {
223+
expect(edgeCaption({ type: "feeds_into" })).toBe("feeds into")
224+
})
225+
226+
test("an untyped edge gets ELON's default strength, not undefined", () => {
227+
expect(edgeStrengthOf({})).toBe(DEFAULT_EDGE_STRENGTH)
228+
})
229+
})

0 commit comments

Comments
 (0)