liveBook · Manning

Point scale

As explained in D3.js in Action, Third Edition

A point scale maps discrete domain values to evenly distributed positions in a continuous range with zero bandwidth.

A point scale places discrete values at evenly spaced positions in a continuous range. Unlike a band scale, it has zero bandwidth: it gives each category a position, not a strip of space. Use it when categories mark the centers of box plots, violin plots, or other chart elements. section 6.4.3

Position two box plots

Set the domain to the category names and the range to the chart’s inner width: `const xScale = d3.scalePoint().domain(["Female", "Male"]).range([0, innerWidth]).padding(0.5);` Calling `xScale("Female")` or `xScale("Male")` gives the corresponding horizontal position. Pass the same scale to `d3.axisBottom(xScale)` so the labels align with the plots. section 6.4.3

The `padding()` value controls blank space at both ends of the range. It is a fraction of the step—the distance between adjacent points—rather than a fixed number of pixels. For the two box plots, `0.5` leaves outer padding equal to half a step. section 6.4.3

For violin plots, a point scale spreads roles across the x-axis while linear scales position salaries vertically and determine each violin’s width. The available half-step, `xScale.step() / 2`, can set the maximum width on either side of a role’s center. section 6.5

Place points beyond a horizontal axis

A rankings chart uses one point scale for years across its width and another for ranks down its height. A radial chart maps the twelve months to angles from `0` through `2 * Math.PI - (2 * Math.PI) / 12`; sine and cosine then turn each month’s angle into an axis endpoint. section 8.6.3 section 14.5.1

How D3.js in Action, Third Edition covers it

How deep it goes
Defines zero bandwidth and step-relative padding, then configures scales in working charts without exploring scale internals.
Examples
Uses gender box plots, salary violin plots, framework rankings, and month-based radial axes.
What it assumes
Introduces `d3.scalePoint()` through configured examples while building on chart dimensions, discrete values, and a comparison with band scales.
What you can do after
Apply it via D3 to place discrete values on chart axes or at evenly spaced angles.
How it connects
Connects point scales to band scales, axes, linear scales, violin plots, and trigonometry.

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.