liveBook · Manning

D3.scalePoint()

As explained in D3.js in Action, Third Edition

d3.scalePoint() is a D3-scale constructor that creates a point scale for distributing discrete values across a continuous range.

d3.scalePoint() creates a point scale for placing discrete values across a continuous range. Unlike a band scale, it has zero bandwidth: each domain value maps to a position rather than an interval. section 6.4.3 section 6.6

Configure a point scale by defining its categories, available space, and edge spacing:

  • Pass a discrete array to domain(), such as ["Female", "Male"] or the role identifiers from a dataset. section 6.4.3 section 6.5
  • Set range([0, innerWidth]) to distribute the points across the chart’s horizontal space. section 6.4.3 section 6.5
  • Use padding() with a factor between 0 and 1 to add blank space at both ends; the factor multiplies the scale step. section 6.4.3

Place categories on a chart

const genders = ["Female", "Male"]; const xScale = d3.scalePoint() .domain(genders) .range([0, innerWidth]) .padding(0.5); const bottomAxis = d3.axisBottom(xScale) .tickSizeOuter(0); innerChart.append("g") .attr("transform", `translate(0, ${innerHeight})`) .call(bottomAxis);

Use the returned scale as a function: xScale(category) supplies the category’s horizontal position. In violin plots, roles occupy these positions while separate linear scales handle salary values and violin widths. section 6.5

How D3.js in Action, Third Edition covers it

How deep it goes
Defines zero bandwidth, domain, range, and padding with working chart code, but defers deeper scale internals.
Examples
Uses Female/Male box plots and data-visualization roles in violin plots as concrete discrete domains.
What it assumes
Assumes basic D3 chart construction and familiarity with band scales, while demonstrating the point-scale setup directly.
What you can do after
Build it from scratch by mapping category arrays to chart positions, adding edge padding, and attaching an axis.
How it connects
Connects point scales to band scales, linear scales, axes, box plots, histograms, and violin plots.

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.