Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

D3 Margin Convention - forked from responsive starter

Public visualization

D3 Margin Convention - forked from responsive starter

0 stars0🌍 Public
JJasmine Ye Han
Last edited Feb 19, 2023
Created on Feb 18, 2023

This example demonstrates the D3 margin convention, a reusable pattern for structuring SVG charts with explicit padding around the plotting area. A component function applies the margin to an SVG, translating a container `g` element and returning the computed inner dimensions. It then renders a single rounded rectangle that fills this inner space, resizing dynamically on window resize events. The code uses D3 v5’s selection methods, including `merge` for efficient updates, and a custom `marginConvention` helper for managing layout.

AI-generated description

Jumping off point for creating your own responsive visualizations.

Comments

Sign in to join the discussion.

MIT Licensed