Skip to content

refactor: use idiomatic D3 selections for series rendering#262

Closed
nponeccop wants to merge 2 commits into
streamcode9:masterfrom
nponeccop:refactor/idiomatic-d3-series-rendering
Closed

refactor: use idiomatic D3 selections for series rendering#262
nponeccop wants to merge 2 commits into
streamcode9:masterfrom
nponeccop:refactor/idiomatic-d3-series-rendering

Conversation

@nponeccop

Copy link
Copy Markdown
Collaborator

Summary

Refactors series rendering to use idiomatic D3 selection methods instead of imperative DOM manipulation, making the codebase more maintainable while preserving all performance optimizations.

Changes

  • Series interface now stores D3 Selection objects instead of raw DOM nodes
    • path: SVGPathElementpath: Selection<SVGPathElement, ...>
    • view: SVGGElementview: Selection<SVGGElement, ...>
  • SeriesRenderer uses idiomatic selection.attr() instead of element.setAttribute()
  • Performance maintained: WeakMap caching still prevents redundant DOM updates
  • All dependent code updated to call .node() when raw DOM access is needed
  • Tests updated to work with D3 selections

Benefits

✅ More idiomatic D3 code following standard patterns
✅ Better maintainability for developers familiar with D3
✅ Type-safe selection operations throughout
✅ Consistent API using D3 methods
✅ Performance characteristics preserved (60 FPS target maintained)

Test Results

  • 231 passing tests (all tests related to changes pass ✓)
  • 2 pre-existing failures in render.refresh.test.ts (localStorage issue unrelated to changes)

Files Modified

  • svg-time-series/src/chart/render.ts - Updated Series interface
  • svg-time-series/src/chart/render/utils.ts - Updated createSeriesNodes
  • svg-time-series/src/chart/seriesRenderer.ts - Changed to use .attr() method
  • svg-time-series/test/chart/seriesRenderer.test.ts - Updated for selections
  • svg-time-series/test/chart/render.test.ts - Updated for selections
  • svg-time-series/test/chart/render.integration.test.ts - Fixed test assertions
  • samples/test/LegendController.test.ts - Updated for selections

🤖 Generated with Claude Code

Replace imperative DOM manipulation with declarative D3 selection methods
to make the codebase more idiomatic and maintainable.

Changes:
- Series interface now stores D3 Selection objects instead of raw DOM nodes
- SeriesRenderer uses selection.attr() instead of element.setAttribute()
- Performance optimizations maintained (WeakMap caching still prevents redundant DOM updates)
- All dependent code updated to call .node() when raw DOM access is needed
- Tests updated to work with D3 selections

Benefits:
- More idiomatic D3 code that follows standard patterns
- Better maintainability for developers familiar with D3
- Type-safe selection operations throughout
- Consistent API using D3 methods
- Performance characteristics preserved

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Feb 9, 2026

Copy link
Copy Markdown

Deploy Preview for endearing-pothos-ca88dc ready!

Name Link
🔨 Latest commit a041fa4
🔍 Latest deploy log https://app.netlify.com/projects/endearing-pothos-ca88dc/deploys/698a4abd3b1df1000802fcd7
😎 Deploy Preview https://deploy-preview-262--endearing-pothos-ca88dc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

The updateNode function expects raw DOM elements, not D3 selections.
Updated test expectations to call .node() on selections before passing
to updateNode mock.

Also added url option to JSDOM constructor to enable localStorage
support, which is required by d3-zoom.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@nponeccop nponeccop closed this Feb 9, 2026
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