Skip to content

Fix to_canvas: place node cards in the same sqrt(n)-column grid the group box is sized for - #1459

Closed
TPAteeq wants to merge 2 commits into
Graphify-Labs:v8from
TPAteeq:fix-canvas-group-box-columns
Closed

TPAteeq wants to merge 2 commits into
Graphify-Labs:v8from
TPAteeq:fix-canvas-group-box-columns

Conversation

@TPAteeq

@TPAteeq TPAteeq commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1452.

to_canvas() sizes each community's group box for a ceil(sqrt(n))-column
grid (w = 220 * ceil(sqrt(n))), but the node-placement loop that fills the
box hardcoded exactly 3 columns (col = m_idx % 3). So the cards span
only ~600px (3 cards wide) no matter how large the community, while the box
keeps widening with sqrt(n) — for any community larger than ~9 members the
result is a cramped 3-wide strip squeezed into the left of an over-wide,
mostly-empty box. (The height term was inconsistent in the other direction:
it used ceil(n / 3) while the width used sqrt(n), so the two dimensions
didn't even agree on a column count — the height happened to track the
3-wide layout's rows, so it's the width that's left empty.)

Concretely, a 25-member community:

box size card grid result
before 1100×1020 3 cols × 9 rows ~600px strip in a 1100px-wide, half-empty box
after 1100×620 5 cols × 5 rows cards fill the box in a ~square grid

Purely cosmetic (no data loss), but it makes the canvas effectively
unreadable for any non-trivial community — the primary use case for the
canvas output is visually browsing graph structure.

Fix

Compute the column count once per community
(inner_cols = max(1, ceil(sqrt(n)))) and reuse that single value for both
the box dimensions and the placement loop, instead of recomputing sqrt(n)
in one place and hardcoding 3 in the other:

  • w = max(600, 220 * inner_cols)
  • h = max(400, 100 * ceil(n / inner_cols) + 120) — now divides by the same
    inner_cols the width uses, so the two dimensions agree.
  • col = m_idx % inner_cols, row = m_idx // inner_cols.

inner_cols floors at 1, so empty / single-node communities keep their
existing 600×400 minimum and there's no divide-by-zero. This matches the
reporter's suggested fix.

Testing

  • New regression test test_to_canvas_node_grid_matches_box_columns in
    tests/test_export.py, over a perfect-square (25 → 5×5) and a non-square
    (10 → 4 cols with a partial last row) member count. It pins the column
    and row counts
    (the load-bearing checks: distinct card x/y positions must
    equal ceil(sqrt(n)) and ceil(n / cols)) and that every card sits inside
    its box. Both counts are red on the pre-fix code for both n
    (n=25: cols 3≠5, rows 9≠5), green after.
  • Full tests/test_export.py (28) plus the canvas/obsidian-adjacent suites pass.
  • Verified visually in Obsidian Canvas: a 25-node community now renders as a
    filled 5×5 grid inside a 1100×620 box instead of a 3-wide strip occupying
    ~600px of an 1100×1020 box.

TPAteeq and others added 2 commits June 25, 2026 15:10
… grid

to_canvas sized each community's group box for a ceil(sqrt(n))-column grid
(w = 220*ceil(sqrt(n))) but the node-placement loop hardcoded 3 columns, so
the cards spanned only ~600px no matter how large the community while the box
kept widening. Any community larger than ~9 members rendered as a cramped
3-wide strip squeezed into the left of an over-wide, mostly-empty box: for 25
members the cards filled ~600px of an 1100px-wide box and wrapped into 9 rows
where 5 would do.

Compute the column count (inner_cols = ceil(sqrt(n))) once per community and
reuse it for both the box dimensions (w/h) and the placement loop, so the
cards fill the box. The height now divides by inner_cols too (it had used
ceil(n/3)), matching the width. inner_cols floors at 1, so empty/size-1
communities keep their 600x400 minimum with no divide-by-zero.

Purely cosmetic, no data change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
safishamsi pushed a commit that referenced this pull request Jun 25, 2026
…id (#1452)

to_canvas sized each community group box for a ceil(sqrt(n))-column grid but the
placement loop hardcoded 3 columns, so any community bigger than ~9 members
rendered as a cramped 3-wide strip in an over-wide, mostly-empty box (and the box
width/height didn't even agree — w used sqrt(n), h used /3). The column count is
now computed once per community (inner_cols) and reused for box width, box height,
and card placement, so the cards fill the box. Cosmetic, no data change.

Ported from PR #1459 by @TPAteeq onto current v8 (clean: only the grid math
changed, the #1457 dedup helper is untouched). Verified the geometry on a real
canvas: n=25 -> 5x5 grid with every card inside its box; n=10 -> 4 columns.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Thanks @TPAteeq — this is a real bug and the fix is right. The group box was sized for a ceil(sqrt(n))-column grid but the placement loop hardcoded 3 columns, so any community larger than ~9 members wrapped into a narrow 3-wide strip inside an over-wide, mostly-empty box.

Landed on v8 in 7278e24 with your authorship preserved. I ported it onto current v8 rather than merging the branch directly (it had drifted from the base), computing the column count once per community and reusing it for the box width, box height, and card placement so the cards fill the box. Added a regression test pinning the geometry (n=25 -> 5x5, n=10 -> 4 columns) and verified on a real canvas that every card lands inside its box.

Closing as merged-by-port. Appreciate the contribution.

@safishamsi safishamsi closed this Jun 25, 2026
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
…id (Graphify-Labs#1452)

to_canvas sized each community group box for a ceil(sqrt(n))-column grid but the
placement loop hardcoded 3 columns, so any community bigger than ~9 members
rendered as a cramped 3-wide strip in an over-wide, mostly-empty box (and the box
width/height didn't even agree — w used sqrt(n), h used /3). The column count is
now computed once per community (inner_cols) and reused for box width, box height,
and card placement, so the cards fill the box. Cosmetic, no data change.

Ported from PR Graphify-Labs#1459 by @TPAteeq onto current v8 (clean: only the grid math
changed, the Graphify-Labs#1457 dedup helper is untouched). Verified the geometry on a real
canvas: n=25 -> 5x5 grid with every card inside its box; n=10 -> 4 columns.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_canvas(): group box sizing uses ceil(sqrt(n)) columns but node placement hardcodes 3

2 participants