* checkpoint vitepress docs * edits * edits * hero drop shadow * d3-array edits * resolve d3 * split d3-array * move d3-array stuff around * d3-array is collapsed: true * italicize parameter names * searching edits * update dependencies * d3-array edits * array edits * array edits * array edits * array edits * array edits * move files * array edits * array edits * array edits * getting started edits * modules page * array edits * more structure * live example * dsv edits * fetch edits * dsv edits * random edits * time format edits * time edits * time edits * modules edits * color edits * color edits * interpolate edits * scale-chromatic edits * selection edits * break up d3-interpolate * scale edits * time scale edits * scale edits * scale edits * band edits * band edits * more descriptive titles * band and point edits * sequential edits * diverging edits * quantize edits * quantile edits * threshold edits * doc edits * fix titles * sequential edits * axis edits * axis edits * axis edits * shape edits * shape edits * dark mode chart * dark mode chart * curve edits * interpolate edits * line edits * link edits * radial edits * pie edits * symbol edits * stack edits * stack examples * path edits * polygon edits * quadtree edits * random examples * ease edits * ease edits * ease edits * timer edits * delaunay edits * quadtree find example * voronoi edits * dispatch edits * contour edits * chord edits * chord edits * fix find highlight * quadtree animation * transition edits * transition edits * transition edits * zoom edits * drag edits * brush edits * force edits * voronoi neighbors example * hierarchy edits * api edits * community edits * getting started edits * geo edits * Add short "D3 in React" section (#3659) * Add short "D3 in React" section I know you removed the TODO but I was already trying to fill it in! I think just making the distinction of modules that touch the DOM and those that don't was super clarifying for me personally when I figured that out. And I always forget the most basic ref pattern (and still might've messed it up here). I don't think we should get into updating or interactivity or whatever, but I think just this much goes a long way toward demystifying (and showing just the most basic best practices). * forgot i made data generic, rm reference to normal distribution * useEffect cleans up after itself Co-authored-by: Mike Bostock <mbostock@gmail.com> * Update getting-started.md --------- Co-authored-by: Mike Bostock <mbostock@gmail.com> * build fixes * index edits --------- Co-authored-by: Toph Tucker <tophtucker@gmail.com>
4.7 KiB
Sequential scales
Sequential scales are similar to linear scales in that they map a continuous, numeric input domain to a continuous output range. Unlike linear scales, the input domain and output range of a sequential scale always has exactly two elements, and the output range is typically specified as an interpolator rather than an array of values. Sequential scales are typically used for a color encoding; see also d3-scale-chromatic. These scales do not expose invert and interpolate methods. There are also log, pow, symlog, and quantile variants of sequential scales.
scaleSequential(domain, interpolator)
Examples · Source · Constructs a new sequential scale with the specified domain and interpolator function or array.
const color = d3.scaleSequential([0, 100], d3.interpolateBlues);
If domain is not specified, it defaults to [0, 1].
const color = d3.scaleSequential(d3.interpolateBlues);
If interpolator is not specified, it defaults to the identity function.
const identity = d3.scaleSequential();
When the scale is applied, the interpolator will be invoked with a value typically in the range [0, 1], where 0 represents the minimum value and 1 represents the maximum value. For example, to implement the ill-advised angry rainbow scale (please use interpolateRainbow instead):
const rainbow = d3.scaleSequential((t) => d3.hsl(t * 360, 1, 0.5) + "");
If interpolator is an array, it represents the scale’s two-element output range and is converted to an interpolator function using interpolate.
const color = d3.scaleSequential(["red", "blue"]);
A sequential scale’s domain must be numeric and must contain exactly two values.
sequential.interpolator(interpolator)
If interpolator is specified, sets the scale’s interpolator to the specified function.
const color = d3.scaleSequential().interpolator(d3.interpolateBlues);
If interpolator is not specified, returns the scale’s current interpolator.
color.interpolator() // d3.interpolateBlues
sequential.range(range)
See linear.range. If range is specified, the given two-element array is converted to an interpolator function using interpolate.
const color = d3.scaleSequential().range(["red", "blue"]);
The above is equivalent to:
const color = d3.scaleSequential(d3.interpolate("red", "blue"));
sequential.rangeRound(range)
See linear.rangeRound. If range is specified, implicitly uses interpolateRound as the interpolator.
scaleSequentialLog(domain, range)
Returns a new sequential scale with a logarithmic transform, analogous to a log scale.
scaleSequentialPow(domain, range)
Returns a new sequential scale with an exponential transform, analogous to a power scale.
scaleSequentialSqrt(domain, range)
Returns a new sequential scale with a square-root transform, analogous to a sqrt scale.
scaleSequentialSymlog(domain, range)
Returns a new sequential scale with a symmetric logarithmic transform, analogous to a symlog scale.
scaleSequentialQuantile(domain, range)
Source · Returns a new sequential scale with a p-quantile transform, analogous to a quantile scale.
sequentialQuantile.quantiles(n)
Source · Returns an array of n + 1 quantiles.
const color = d3.scaleSequentialQuantile()
.domain(penguins.map((d) => d.body_mass_g))
.interpolator(d3.interpolateBlues);
color.quantiles(4); // [2700, 3550, 4050, 4750, 6300]
For example, if n = 4, returns an array of five numbers: the minimum value, the first quartile, the median, the third quartile, and the maximum.