Skip to main content
100%

D3 Margin Convention - forked from responsive starter

✓ Published0🌍 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.

MIT Licensed

Similar vizzes