Skip to main content
100%

Threshold Key

✓ Published0🌍 Public
Mmbostock
Last edited Jan 23, 2017
Created on Jan 19, 2013

This example builds a color key for a threshold scale, styled after Ford Fessenden’s map of police stops involving force. It shows rectangles for each range color, with tick marks placed at the domain boundaries, spanning 0 to 100%. The key uses `d3.scaleThreshold` to map percentages to colors and a `d3.scaleLinear` for x-positions, while `d3.axisBottom` with custom tick values and formats renders the labels. The `invertExtent` method calculates each rectangle’s width, and SVG rendering is used.

AI-generated description

This example demonstrates how to construct a key from a threshold scale, in the style of Ford Fessenden’s map of police stops involving force. A linear scale is used to set the x-position of each colored rectangle in the key. There is one rectangle per color in the threshold scale’s range, and one tick per value in the threshold scale’s domain. The linear scale’s domain sets the implied extent of the key, here spanning 0 to 100%.

gpl-3.0 Licensed

Similar vizzes