Skip to main content
100%

Viewport and viewBox

✓ Published0🌍 Public
GGiuliaPassoni
Last edited Jan 11, 2023
Created on Jan 10, 2023
Forked from D3 Starter

This example demonstrates how the SVG `viewBox` attribute changes the visible portion of a fixed-size canvas while using D3.js v7 to construct the scene. It draws a single blue circle inside a red-bordered `<svg>` element, then applies a `viewBox` with negative offsets and scaling to translate and zoom the coordinate system. The code uses `d3.select` to append the SVG and its child `<g>` element, and it utilizes the SVG API to inspect the geometry. The fixed width and height remain constant while the viewport shifts, showing how coordinates map differently in the rendered output.

AI-generated description

A demonstration of how to start using D3 version 6.

MIT Licensed

Similar vizzes