Skip to content

fix: combine graph visualization fixes — populate ArchData, fix double-encoding, fix len()#11

Merged
jonathanpopham merged 1 commit intomainfrom
claude/issue-10-20260228-0212
Feb 28, 2026
Merged

fix: combine graph visualization fixes — populate ArchData, fix double-encoding, fix len()#11
jonathanpopham merged 1 commit intomainfrom
claude/issue-10-20260228-0212

Conversation

@jonathanpopham
Copy link
Contributor

@jonathanpopham jonathanpopham commented Feb 28, 2026

Fixes #10, fixes #8

Summary

Combines all fixes from the three previous branches into a single complete fix. Neither previous branch alone was sufficient — the first populated the data but double-encoded it, the second fixed the encoding but didn't populate ArchData.

Root Cause

The consolidation in 8f1470b (Feb 17) moved pssg from text/template to html/template. Go's html/template applies JS-context escaping inside <script> tags, which double-encoded all JSON data (ChartData, ArchData) — wrapping valid JSON in quotes and escaping internal quotes. This broke graph rendering on all 6 repos built after the consolidation, while the 27 repos built before remained working.

Changes

  • ArchData population: Generate domain/subdomain force graph data in renderHomepage
  • Entity ChartData: Populate profile chart data in renderEntityPage
  • Chart JSON field fix: label/topEntriesname/count/slug to match JS treemap expectations
  • template.HTML → template.JS: 7 fields across 6 render context structs, preventing double-encoding in <script> tags
  • len() reflect fix: Replace brittle type-switch with reflect.ValueOf(v).Len() so []taxonomy.Entry doesn't return 0
  • Graph node enrichment: Add lc, lang, cc, cbc fields for node sizing/tooltips
  • SourceDir config: Add SourceDir to PathsConfig for source code display
  • Regression tests: 13 test cases verifying correct JSON encoding and length function

Verified

  • All 13 tests pass
  • Locally rebuilt a fresh repo (toolate-tv) — ArchData and ChartData both render as clean JSON, graphs display correctly
  • Matches the working output format from pre-consolidation builds (e.g. react)

Test plan

  • go test ./... passes (13 render tests)
  • Local site build produces valid JSON in <script> tags (no double-encoding)
  • Architecture overview force graph renders with domain/subdomain nodes
  • Homepage chart data renders with correct field names

Summary by CodeRabbit

  • New Features

    • Added source code display on entity pages with language detection
    • Introduced architecture overview graph visualization on homepage
    • Enhanced profiling data charts across entity hubs, taxonomy pages, and entity listings
  • Improvements

    • Improved chart rendering consistency across multiple page types
    • Extended configuration to support source directory paths
  • Tests

    • Added regression and behavior tests for template rendering and chart data formatting

…e-encoding, fix len()

Combines changes from both fix branches to fully resolve graph rendering:

1. Populate ArchData (domain/subdomain force graph) in renderHomepage
2. Populate entity ChartData (profile chart) in renderEntityPage
3. Fix homepage chart JSON field names (label/topEntries → name/count/slug)
4. Change template.HTML → template.JS for all JSON in <script> tags to
   prevent double-encoding by html/template's JS context escaper
5. Fix len() template function to use reflect.ValueOf().Len() so it works
   with any slice/map/array/string type (fixes #8)
6. Add graph node enrichment fields (lc, lang, cc, cbc) in graph2md
7. Add SourceDir to PathsConfig for source code display
8. Add regression tests for double-encoding and length function

Fixes #10

Co-authored-by: Jonathan Popham <jonathanpopham@users.noreply.github.com>
@jonathanpopham jonathanpopham merged commit 35fb113 into main Feb 28, 2026
1 check passed
@jonathanpopham jonathanpopham deleted the claude/issue-10-20260228-0212 branch February 28, 2026 02:28
@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b9ddc46 and 88b261d.

📒 Files selected for processing (6)
  • internal/graph2md/graph2md.go
  • internal/pssg/build/build.go
  • internal/pssg/config/types.go
  • internal/pssg/render/funcs.go
  • internal/pssg/render/render.go
  • internal/pssg/render/render_test.go

Walkthrough

This PR enriches graph nodes with metadata (line counts, language, call counts), converts template chart data from HTML to JavaScript representation, adds source code extraction from workspace, builds architecture overview graphs for homepages, and fixes the custom template length function to handle any slice/map type via reflection rather than brittle type switches.

Changes

Cohort / File(s) Summary
Graph Data Enrichment
internal/graph2md/graph2md.go
Added LC (line count), Lang (language), CC (call count), and CBC (called-by count) fields to graphNode struct with JSON tags; computes these values during graph generation from source analysis.
Template Data Structure Updates
internal/pssg/render/render.go
Changed ChartData field type from template.HTML to template.JS across six context structs (EntityPageContext, HomepageContext, HubPageContext, TaxonomyIndexContext, LetterPageContext, AllEntitiesPageContext) to prevent double-encoding of JSON in script tags.
Build & Data Population
internal/pssg/build/build.go
Constructs per-entity profiling data as compact JSON; extracts source code snippets with language detection; builds architecture overview graph with domain/subdomain nodes; wires ChartData, SourceCode, SourceLang, and ArchData into template contexts; limits chart embedding to page 1 where appropriate.
Configuration Extension
internal/pssg/config/types.go
Added SourceDir field to PathsConfig struct to expose a configurable source directory path.
Template Function Improvement
internal/pssg/render/funcs.go
Replaced brittle type switch in length() function with reflection-based approach using reflect.Value.Len(), now handles any slice, map, array, or string type; fixes bug where {{len .Entries}} returned 0 for []taxonomy.Entry.
Test Coverage
internal/pssg/render/render_test.go
New test suite validating template.JS prevents JSON double-encoding in script tags, demonstrating template.HTML double-encoding behavior, and verifying reflect-based length function across diverse types (nil, strings, slices, maps, custom structs).

Sequence Diagram(s)

sequenceDiagram
    participant Source as Source Code<br/>(Workspace)
    participant Graph as Graph Data<br/>Generation
    participant Build as Build &<br/>Data Population
    participant Template as Template<br/>Rendering
    participant Output as HTML Output

    Source->>Graph: Extract entities, calls, imports
    Graph->>Graph: Compute LC, Lang, CC, CBC
    Graph->>Build: Pass enriched graph nodes
    
    Source->>Build: Read source snippets (start_line:end_line)
    Build->>Build: Detect language from field/extension
    Build->>Build: Build profileData JSON (counts + edge breakdown)
    Build->>Build: Build ArchData JSON (domains/subdomains graph)
    
    Build->>Template: Pass ChartData as template.JS
    Build->>Template: Pass SourceCode & SourceLang
    Build->>Template: Pass ArchData as template.JS
    
    Template->>Template: Render with reflect-based length()
    Template->>Output: Generate valid JSON in script tags (no double-encoding)
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🎨 Graphs now bloom with data bright—
Lang, counts, and calls shine in light.
JavaScript flows, no encoding woes,
Source code extracted where data goes.
Reflection fixes what switches broke,
Homepages render—the silence spoke! 📊✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/issue-10-20260228-0212

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant