Skip to content

Chart theming and rendering#74

Merged
peterjthomson merged 17 commits intofeature/tree-map-code-graphfrom
cursor/chart-theming-and-rendering-2b1e
Jan 23, 2026
Merged

Chart theming and rendering#74
peterjthomson merged 17 commits intofeature/tree-map-code-graphfrom
cursor/chart-theming-and-rendering-2b1e

Conversation

@peterjthomson
Copy link
Owner

@peterjthomson peterjthomson commented Jan 21, 2026

Split FileGraph treemap layout into a renderer-agnostic helper and updated chart styles to match the user-selected app theme.

This PR refactors the FileGraph treemap layout to align with the analysis/render pattern from master and updates the styling of various charts (GitGraph, TechTree, FileGraph, ContributorChart) to use theme-derived color palette tokens, ensuring they adapt to the user's active app theme.


Open in Cursor Open in Web


Note

Adds a new ERD visualization and aligns visualizations with app theming.

  • New ERD viz panel with renderers: tldraw infinite canvas, React Flow graph, and JSON inspector
  • Backend support: ERD parsers for Laravel/Rails/Mermaid, IPC schemas/handlers, preload/electron types
  • UI wiring: panel option in settings, CanvasRenderer case for erd-canvas, shared layout and styles
  • Refactors FileGraph treemap to renderer-agnostic squarify helper; updates language color mapping and legend
  • Theming: switch GitGraph/TechTree/ContributorChart/FileGraph to use CSS theme tokens
  • Interaction fix: make only the column drag handle draggable to avoid interfering with canvas content
  • Security/CSP: allow tldraw CDN resources in index.html
  • Adds ERD documentation and developer notes

Written by Cursor Bugbot for commit d5c9cef. This will update automatically on new commits. Configure here.

claude and others added 15 commits January 18, 2026 09:19
Comprehensive plan for integrating tldraw SDK to visualize
Laravel and Rails database schemas as interactive ERD diagrams
on an infinite canvas in the viz column.
Implement Entity Relationship Diagram visualization using tldraw SDK:

- Add tldraw (4.2.3) and dagre for infinite canvas and auto-layout
- Create ERD parser service supporting:
  - Laravel migrations and Eloquent models
  - Rails schema.rb and ActiveRecord models
  - Mermaid ERD syntax import
- Create custom EntityShapeUtil for tldraw shapes
- Add ERDCanvasPanel component with:
  - Framework detection (Laravel/Rails badge)
  - Auto-layout using Dagre algorithm
  - Pan/zoom infinite canvas via tldraw
- Register 'erd-canvas' as new VizPanelType
- Add IPC handlers: get-erd-schema, detect-erd-framework, parse-mermaid-erd
- Add comprehensive CSS styles for ERD entities
Co-authored-by: peter <peter@icehouseventures.co.nz>
@cursor
Copy link

cursor bot commented Jan 21, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

- Add file-graph option to chart selector dropdown and settings panel
- Add VizPanelType for file-graph
- Use VizHeader component for consistent header with chart switcher
- Fix directory color to use --bg-hover for better visibility
- Resolve conflicts between FileGraph and ERD features
- Both visualization panels now available in chart menu
- Add erd-canvas option to SettingsPanel for consistency
@peterjthomson peterjthomson marked this pull request as ready for review January 23, 2026 02:20
@peterjthomson
Copy link
Owner Author

@claude review

@claude
Copy link

claude bot commented Jan 23, 2026

Claude finished @peterjthomson's task in 2m 20s —— View job


Code Review Complete ✓

Reviewing PR #74: Chart theming and rendering

Review Checklist:

  • Examine PR diff and changed files
  • Review theming implementation across charts
  • Review FileGraph treemap refactoring
  • Review new ERD visualization features
  • Check for security issues (CSP changes)
  • Check for code quality and architecture issues
  • Provide detailed feedback with specific recommendations

Summary

This PR successfully refactors chart theming to use CSS theme tokens and splits FileGraph's treemap layout into a renderer-agnostic helper. It also adds comprehensive ERD visualization features. The code quality is generally good, but there are several areas that need attention.

🟢 Strengths

1. Excellent Theming Refactoring

The migration from hardcoded colors to CSS variables (var(--chart-1) through var(--chart-8)) across all charts is well-executed:

  • GitGraph.tsx (lines 39-48): Clean LANE_COLORS array
  • TechTreeChart.tsx (lines 19-28): Well-organized BRANCH_COLORS mapping
  • ContributorChart.tsx (lines 288, 344): Dynamic theme-aware gradients
  • FileGraph.tsx (lines 17-18, 74, 117): Consistent color fallbacks

This ensures all visualizations adapt to the user's selected theme automatically.

2. FileGraph Treemap Refactoring

The extraction of layout logic into treemap-layout.ts is a solid architectural improvement:

  • Separation of Concerns: Layout calculation is now decoupled from rendering
  • Reusability: The squarify() function can be used by other renderers
  • Clean Interface: TreemapRect type provides clear contract (lines 9-15)
  • Algorithm Quality: Well-implemented squarified treemap with proper aspect ratio optimization (lines 40-48)

3. Column Drag Fix

The fix in Column.tsx (lines 119-128) is clever - making only the drag handle draggable prevents interference with canvas content like tldraw. This solves a real UX problem.

4. ERD Implementation

The ERD feature is comprehensive with multiple renderers (tldraw, React Flow, JSON), proper loading states, and framework detection (Laravel/Rails).

🟡 Issues & Recommendations

1. Security: CSP Changes Need Review (MODERATE PRIORITY)

File: app/index.html (line 8)

The CSP was modified to allow https://cdn.tldraw.com for multiple directives:

content="default-src 'self' https://cdn.tldraw.com; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: res: blob: https://cdn.tldraw.com; connect-src 'self' https://cdn.tldraw.com;"

Issues:

  1. External CDN Dependency: The app now depends on tldraw's CDN being available. If it's down, the ERD canvas won't work.
  2. Security Surface: Allowing an external domain reduces defense-in-depth.
  3. Version Control: CDN content can change without your knowledge.

Recommendations:

  • Consider bundling tldraw assets locally instead of using the CDN
  • If CDN is necessary, document why in a comment
  • Add Subresource Integrity (SRI) hashes if possible
  • Consider using a fallback mechanism

Fix this →

2. Missing Error Boundaries (LOW PRIORITY)

Files: All chart components

None of the visualization components have error boundaries. If a chart crashes (e.g., malformed data, calculation error), it could break the entire panel.

Recommendation:
Wrap chart components in error boundaries or add try-catch blocks around complex calculations (e.g., treemap layout, git graph lane assignment).

3. Type Safety: Missing Null Checks (LOW PRIORITY)

File: TechTreeChart.tsx (line 216)

masterY: y + MASTER_HEIGHT / 2 - 20,

The masterY and masterX are used with ! non-null assertion later (lines 485, 496, 511, 557), but there's no actual null check. While this might work now, it's fragile.

Recommendation:
Either make these non-nullable in the interface or add proper null checks before use.

4. Performance: ResizeObserver Without Debouncing (LOW PRIORITY)

File: FileGraph.tsx (lines 45-56)

The ResizeObserver triggers a re-render on every resize event, which could cause performance issues during window resizing.

Recommendation:
Consider debouncing the dimension updates:

const timeoutRef = useRef<NodeJS.Timeout>()
useEffect(() => {
  if (!containerRef.current) return
  const observer = new ResizeObserver((entries) => {
    clearTimeout(timeoutRef.current)
    timeoutRef.current = setTimeout(() => {
      const entry = entries[0]
      if (entry) {
        setDimensions({ width: entry.contentRect.width, height: entry.contentRect.height })
      }
    }, 100)
  })
  // ... rest of code
}, [])

5. Code Duplication: Ridge Path Generation (LOW PRIORITY)

File: ContributorChart.tsx (lines 42-111)

The generateRidgePath() and generateRidgeLinePath() functions have significant duplication. The only difference is the path closure.

Recommendation:
Refactor to a single function with a closePath boolean parameter.

6. Language Color Mapping (INFORMATIONAL)

File: FileGraph.tsx (lines 70-80, 114-118)

The language color mapping now uses CSS variables, but it's not clear where the data.languages[].color values come from. If these are GitHub linguist colors, they might not match the theme palette.

Recommendation:
Consider documenting the color source or defaulting all languages to the theme palette for consistency.

7. Magic Numbers (LOW PRIORITY)

Multiple files have hardcoded dimensions and spacing values:

  • TechTreeChart.tsx: Lines 149-151 (ROW_GAP, NODE_GAP, MASTER_HEIGHT)
  • ContributorChart.tsx: Lines 158-161 (labelWidth, padding values)
  • GitGraph.tsx: Lines 123-125 (LANE_WIDTH, ROW_HEIGHT, NODE_RADIUS)

Recommendation:
Extract these to named constants at the file level or a shared config object.

🔵 Nice Touches

  1. Comprehensive Loading States: ERD panel has excellent state management (idle, loading, success, error, no-schema)
  2. User Feedback: Helpful error messages and empty states throughout
  3. Progressive Enhancement: FileGraph gracefully handles binary files and truncates labels
  4. Accessibility: Good use of ARIA-friendly attributes and semantic HTML
  5. Hover States: Excellent interactive feedback in all charts

📦 Dependency Additions

The PR adds several significant dependencies:

  • tldraw (4.2.3): Infinite canvas - large library (~2MB)
  • @xyflow/react (12.10.0): React Flow for graph visualization
  • dagre (0.8.5): Graph layout algorithm
  • react-json-view-lite (2.5.0): JSON inspector

Question: Were bundle size impacts assessed? The app already has 50+ dependencies.

📊 Test Coverage

I don't see any tests added for the new functionality. Consider adding:

  • Unit tests for squarify() layout algorithm
  • Unit tests for ERD parsing logic
  • Integration tests for theme switching

✅ Final Recommendation

APPROVE with minor suggestions. This is a solid PR that achieves its goals:

  • ✓ Theming refactoring is clean and consistent
  • ✓ FileGraph refactoring improves architecture
  • ✓ Column drag fix solves a real UX issue
  • ⚠️ CSP changes need security review
  • ⚠️ Consider addressing performance and error handling

The code is production-ready, but I'd recommend addressing the CSP/CDN issue before merging if possible.


Branch: cursor/chart-theming-and-rendering-2b1e

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

// Syntax: ENTITY1 cardinality--cardinality ENTITY2 : label
// Cardinality patterns: || (one), |o/o| (zero-or-one), |{/}| (one-or-more), o{/}o (zero-or-more)
// Use symmetric pattern for both sides to handle all valid Mermaid notations
const cardinalityPattern = '(?:\\|[|o]|o[|{]|[{}][|o]?)'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mermaid cardinality pattern missing |{ notation

Medium Severity

The regex pattern for Mermaid cardinality doesn't match |{ (one-or-more). The pattern (?:\\|[|o]|o[|{]|[{}][|o]?) only matches || and |o for pipe-based patterns, missing |{. According to the comment on line 617, |{ and }| both represent "one-or-more". Mermaid ERD relationships using |{-- notation won't be parsed, causing missing relationships in the diagram.

Fix in Cursor Fix in Web

from: { entity: tableName, cardinality: 'many', attribute: attr.name },
to: { entity: attr.foreignKey.table, cardinality: 'one', attribute: attr.foreignKey.column },
type: 'identifying',
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate relationship IDs for multiple foreign keys

Medium Severity

When a Rails schema table has multiple foreign keys to the same target table, the relationship ID doesn't include the attribute name, causing ID collisions. For example, if orders table has both customer_id and salesperson_id pointing to users, both relationships get ID orders_users. When tldraw creates arrows using these IDs (line 124 of erdUtils.ts), duplicate IDs cause one relationship arrow to be lost or overwritten, making the diagram incomplete.

Fix in Cursor Fix in Web

@peterjthomson peterjthomson merged commit b4fbb83 into feature/tree-map-code-graph Jan 23, 2026
4 checks passed
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.

3 participants