Skip to content

Export the dashboard map as SVG - #278

Merged
coryodaniel merged 7 commits into
dashboardfrom
dashboard-export
Nov 30, 2026
Merged

coryodaniel merged 7 commits into
dashboardfrom
dashboard-export

Conversation

@coryodaniel

@coryodaniel coryodaniel commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Stacked on #277.

e on the Constellation tab saves the map as an SVG, constellation-<org>-<YYYYMMDD-HHMM>.svg, for decks and incident write-ups.

  • It uses the map's own layout and the current theme and palette. Constellation draws curved links, metro routed tracks and radar its scope rings. The backdrop follows the palette.
  • Rings are colored by instance status. It draws alarm pulses, the blast-radius halo of the selection, deploy arcs, app satellites, traffic labels, and ▲ ↑ ⚑ badges.
  • A title line names the organization, the focus and the time, and a color key runs along the bottom.
  • Names are XML-escaped, and the file uses no new dependencies.

The updateFeed split in model.go keeps update under the funlen limit after this PR added its message.

🤖 Generated with Claude Code

coryodaniel and others added 2 commits November 27, 2026 22:24
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coryodaniel

Copy link
Copy Markdown
Member Author

@claude please review.

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 34s —— View job


Review of #278: Export the dashboard map as SVG

I read the whole diff against dashboard-incidents and traced the e key path in model.go. I did not run make check or make docs. This is a read-only review and I pushed no changes.

Overall: The change is sound and follows the CLAUDE.md layering. The logic lives in internal/commands/dashboard and the file write is injected through Config.WriteFile. There are no new cmd/ tests, the tests are table-driven, and there is one test file per source file. I found nothing blocking. The items below are minor.

  • Read the diff
  • Checked the e key wiring and its conflicts
  • Posted the review

Things to consider

  1. Legend can overflow narrow exports (export.go:131-145). Legend entries advance by an estimated text width (runewidth × fs × 0.62). The canvas width is dotW·k, and k is clamped to between 4 and 10. For a narrow terminal (say 40 cells, so dotW=80) the six entries need roughly 100+ k-units against 80 available, so the key runs off the right edge. Wrapping to a second row, or shrinking fs when the total exceeds the width, would fix it. The heading text in heading() has the same unbounded-width issue with a long org or env name.

  2. Export runs synchronously in Update (export.go:514). ExportSVG builds the whole document, including the star field, inside exportMap() before the tea.Cmd is returned. At 200×48 that is about 77k hash calls, which is cheap, but a wide terminal would block the UI. Moving the ExportSVG call inside the returned closure is a one-line change. The scene fields it captures are value copies or read-only, so this should be safe. The one exception is m.graph, which is a pointer. I'd confirm the graph is never mutated in place on reload before doing this.

  3. Hidden global dependency (export.go:68). backdrop() switches on the package-level paletteName, and the colors come from package globals too. Scene doesn't carry the palette, so ExportSVG(scene, …) isn't a pure function of its arguments. That's consistent with how the rest of the package works, and the tests handle it with UsePalette plus t.Cleanup. It does mean those subtests can't use t.Parallel(). It's fine to leave as is, but Scene could carry the palette if you want a pure function later.

  4. Filename edge cases (export.go:483-491).

    • An empty org gives constellation--20261126-0905.svg.
    • Non-ASCII org names collapse to - per rune.
    • The name is always constellation-… even on metro or radar. The PR description and docs say this is intended, but a theme in the name might help someone who exports all three.
    • Two exports in the same minute silently overwrite each other. That seems acceptable, and the docs say "named for the organization and the minute".
  5. Metro and radar don't draw everything constellation does. The PR says "▲ ↑ ⚑ badges", and those are present through stationBadges. Alarm pulses, the blast-radius halo, satellites and traffic labels are drawn only in constellation()/node(). In metro and radar, the blast radius shows only through linkColor. The docs say export "keeps … the selection, and its blast radius", which holds for constellation only. This is worth a sentence in the help doc, or confirm it's intentional.

  6. Test coverage gaps (export_test.go).

    • TestExportSVG checks that each env name appears and that the XML is valid, which is a good guard against the escaping and structure regressions this code is prone to. It doesn't assert that the theme-specific features exist, for example <ellipse for radar or <polyline for metro.
    • It doesn't check that a selected node produces the dashed highlight.
    • TestModelExports only covers the constellation and metro themes through the model. Radar goes through ExportSVG directly.
    • Adding a couple of want substrings per theme would catch a theme silently falling through to the default: branch.

Nits

  • model.go:675: the case "e" falls out of the switch with return m, nil when not on the constellation tab. That is correct. The only other case "e" in the package is this one, so there's no key conflict.
  • The updateFeed split in model.go isn't part of this feature (presumably it satisfies a complexity lint). It reads fine and the behavior is identical, but note it in the PR description so reviewers don't wonder.
  • esc() returns "" on an EscapeText error. That can't happen with a strings.Builder writer, so the branch is dead, though a silent empty string is harmless.
  • Comments follow the CLAUDE.md "default to none" rule well. textOn's comment explains a real why.

@coryodaniel

Copy link
Copy Markdown
Member Author

Fixed in 8122c87:

  • 1: the color key shrinks to fit the map's width, and a title wider than the map is squeezed with textLength. TestExportSVGFitsANarrowMap covers it.
  • 5: the helpdoc says that only the constellation draws the blast-radius halo, alarm pulses and traffic, while metro and radar show the blast radius in their links.
  • 6: TestExportSVG checks each theme draws its own elements: paths for the constellation, polylines for metro, ellipses for radar.
  • The PR description mentions the updateFeed split.

No change:

  • 2: the export stays in Update. ApplyStash changes the graph in place, so building the SVG in a command would read the graph while the model writes it. It takes milliseconds.
  • 3: the palette is package state, like the rest of the renderer. Moving it onto Scene is a separate change.
  • 4: the file name is meant to be stable and say what it is: the constellation of an organization at a minute.

@claude please review.

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 21s —— View job


Re-review of #278 after 8122c87

I re-read export.go, export_test.go and the helpdoc diff. I did not run make check or make docs. I pushed no changes.

  • Read the diff
  • Checked each reply against the code
  • Posted the review

Your replies

  • 2, 3, 4 (no change): I agree. ApplyStash mutates the graph in place, so building the SVG in a command would race the model. Package-level palette state matches the rest of the renderer. A stable file name is a reasonable choice.
  • 5 (helpdoc): The wording now matches what the code draws.
  • 6 (theme tests): The per-theme <path, <polyline and <ellipse checks are in place.
  • 1 (title): The textLength squeeze in heading() looks right.

One issue: the legend fix doesn't fully fit

export.go:131-145, legend().

The shrink factor scales the whole width, but only the text part of it depends on fs. The 7*k per entry (circle, gap and spacing) is fixed. Scaling fs by room/width therefore leaves the total still wider than room.

Worked example for w=40, so dotW=80 and k=10:

  • room is 720.
  • The fixed part is 6 × 7 × 10 = 420.
  • The text part is about 65 characters × 2.8 × 10 × 0.62 ≈ 1128, so width ≈ 1548.
  • fs is scaled by 0.465, so the new total is 420 + 1128 × 0.465 ≈ 945, against 720 available.

The key still runs about 225 px (about 30%) past the right edge at 40 columns. It only fits when the overshoot is small.

The fix is to scale only the text part:

fixed := 7 * x.k * float64(len(entries))
text := width - fixed
if room := x.dotW*x.k - 8*x.k; width > room && room > fixed {
    fs *= (room - fixed) / text
}

For very small maps (w=10, room 120) the fixed part alone exceeds the room, so there is nothing to shrink. Wrapping to a second row would be the only fix there, and that is probably not worth doing.

Test gap

TestExportSVGFitsANarrowMap asserts only that the title gets textLength. It never checks the legend, so it passes with the bug above. A cheap assertion is to parse the last legend <text x=…> and its font-size, then check that x plus the estimated width stays within the canvas width. Alternatively, export at width 40 and check that the legend's font-size is below the default x.font(2.8) by the right amount.

Nits

  • TestExportSVG runs 9 subtests, one per theme and palette pair. Each one calls UsePalette and resets it in t.Cleanup, which is fine while they stay serial.
  • TestModelExports still covers only constellation and metro through the model. Radar goes through ExportSVG directly in TestExportSVG, so this is acceptable.

Summary

Everything else from the first round is addressed. The legend overflow is only partly fixed and needs the change above. I found nothing else blocking.
· branch dashboard-export

@coryodaniel

Copy link
Copy Markdown
Member Author

Fixed in ac2e41a, with #277's latest merged in since:

  • Only the text of the color key shrinks now; the fixed spacing per entry stays put. TestExportSVGFitsANarrowMap reads the last label's position and font size and checks it ends inside the map's width.

@claude please review.

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 19s —— View job


Re-review of #278 after ac2e41a

I read legend() in export.go and TestExportSVGFitsANarrowMap. I did not run make check or make docs, and I pushed no changes.

The legend fix is correct. The per-entry advance is 3k + text + 4k, so the fixed part is 7k per entry. Only the text scales with fs. After fs *= (room - fixed) / text, the total extent is fixed + text', which equals room. The last label then ends at or before W - 8k + 4k, inside the canvas.

For w=40 (dotW=80, k=10):

  • Room is 720 and the fixed part is 420.
  • Text goes from about 1128 to 300, which is a scale of about 0.27.
  • The key now ends within the map. In my previous review I estimated about 945 px with the old formula, so this closes that gap.

Guards: room > fixed also prevents a negative or zero fs, and text is non-zero whenever the branch runs, so there is no divide-by-zero.

Test: The test would have failed on the old code, where the key overshot by about 225 px, so it does guard the regression.

Nits (non-blocking)

  • export_test.go:166 uses len("↑ upgrades"), which counts bytes. ↑ is 3 bytes, so it gives 12, not the display width of 10. The check is therefore slightly conservative and still passes. runewidth.StringWidth would match the production estimate. It's a small change and only worth making if you're already in the file.
  • The test bound is root.Width, while legend() aims for Width - 4k. The test is looser than the code intends, so it could miss a regression of up to 4k. This is fine as a guard.
  • Below roughly dotW ≈ 42/k·… (when fixed alone exceeds room, e.g. w=10), the key still overflows. That's the case I mentioned last round, and I agree wrapping isn't worth it.

Summary

Both open items from the last round are resolved. I found nothing blocking, so this looks good to merge from my side.
· branch dashboard-export

Base automatically changed from dashboard-incidents to dashboard November 30, 2026 06:12
@coryodaniel
coryodaniel merged commit e91c916 into dashboard Nov 30, 2026
2 checks passed
@coryodaniel
coryodaniel deleted the dashboard-export branch November 30, 2026 06:13
@coryodaniel

Copy link
Copy Markdown
Member Author

Folded into #272.

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.

1 participant