liveBook · Manning

SVG path data attribute

As explained in D3.js in Action, Third Edition

The SVG d attribute is a sequence of commands and coordinates that defines the geometry of a path.

The SVG path d attribute, meaning “draw,” defines a path’s geometry as a sequence of commands and coordinates. It tells the browser where drawing starts, how the path changes direction, and whether it remains open or closes. Paths handle complex shapes and curves that SVG primitives such as lines, rectangles, circles, and ellipses cannot express directly. section 1.2.2 section 4.0

A path string can become long quickly because it must encode endpoints and curve instructions. In D3 visualizations, shape generators usually produce this value instead of requiring manual path writing. section 4.0

A curved path

This path starts with M at 680,150, then uses C and S curve commands to create a flowing purple line. Setting fill to none leaves only the stroked curve visible. <path d="M680 150 C 710 80, 725 80, 755 150 S 810 220, 840 150" fill="none" stroke="#773b9a" stroke-width="3" /> section 1.2.2

Path data is especially useful for visualization shapes such as:

Figure 4.1 Project that we’ll build in this chapter: a line chart of the temperature evolution in New York City in 2021 and a set of arcs showing the percentage of days with precipitation
figure

A temperature line chart and precipitation arcs show two common results of generating SVG path data for a visualization. section 4.0

How D3.js in Action, Third Edition covers it

How deep it goes
Explains commands as start, endpoint, curve, and open-or-closed instructions, while deferring detailed manual path construction to generators.
Examples
Uses a manually written curved path plus a temperature line chart and precipitation-arc visualization project.
What it assumes
Assumes familiarity with SVG lines, rectangles, and circles before moving to complex paths.
What you can do after
Apply it via D3 shape generators to create line-chart curves and donut-chart arcs.
How it connects
Connects SVG paths with D3 shape generators, line charts, donut charts, curves, and arcs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.