Skip to content

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

Closed

Description

@zachary-zae

Summary

to_canvas() in graphify/export.py computes each community's group-box width from a ceil(sqrt(n))-column grid, but the node-placement loop that fills that box hardcodes exactly 3 columns. For any community larger than ~9-12 members, the box is sized for a roughly-square grid while the actual node cards render as a narrow 3-wide column that wraps far past the box's intended height — producing a tall, mostly-empty box with a cramped 3-wide strip of nodes squeezed into one side.

Environment

  • graphifyy 0.8.47 (current PyPI/pipx, confirmed via pyproject.toml on main)
  • macOS (but this is a pure layout-math bug, not platform-specific)

Relevant code

graphify/export.py, to_canvas():

Box sizing (line ~1169) explicitly targets a ceil(sqrt(n))-column layout:

w = max(600, 220 * math.ceil(math.sqrt(n)) if n > 0 else 600)
h = max(400, 100 * math.ceil(n / 3) + 120 if n > 0 else 400)

(note: h here is already inconsistently using /3, not sqrt(n), while w uses sqrt(n) — the two dimensions don't even agree with each other on an assumed column count.)

Node placement (line ~1238) hardcodes 3 columns regardless of n:

col = m_idx % 3
row = m_idx // 3
nx_x = gx + 20 + col * (180 + 20)
nx_y = gy + 80 + row * (60 + 20)

Repro

graphify .                 # any repo with a community of ~20+ members
graphify export obsidian
# open graphify-out/obsidian/graph.canvas in Obsidian's Canvas viewer

A community with, say, 25 members gets a box width sized for ceil(sqrt(25)) = 5 columns (1100px wide), but the node cards are placed 3-per-row, occupying only ~600px of that 1100px width and wrapping into 9 rows instead of the 5 the box height was sized for. The visual result is a wide, half-empty box with a narrow, tall stack of cards on the left edge.

Impact

Purely cosmetic (no data loss), but it makes the canvas effectively unreadable for any non-trivial community — which is the primary use case for export obsidian's canvas output (visually browsing graph structure). Communities over ~12 members render as illegible, wrapped 3-wide strips inside oversized boxes.

Suggested fix

Compute the column count once per community and reuse it for both box sizing and placement, e.g.:

inner_cols = max(1, math.ceil(math.sqrt(n)))
...
col = m_idx % inner_cols
row = m_idx // inner_cols

and use that same inner_cols value in both the w/h box-sizing calc and the placement loop, rather than recomputing sqrt(n) in one place and hardcoding 3 in the other.

Activity

  1. safishamsi commented on Jun 25, 2026

    @safishamsi
    Member

    Fixed on v8 in 7278e24 (via #1459, thanks @TPAteeq). Community node cards now lay out in the same ceil(sqrt(n))-column grid the group box is sized for, so they fill the box instead of wrapping into a narrow strip. Will ship in the next release.

  2. added a commit that references this issue on Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions