mirror of
https://github.com/d3/d3.git
synced 2026-02-01 16:41:44 +00:00
* 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>
49 lines
1.7 KiB
Markdown
49 lines
1.7 KiB
Markdown
<script setup>
|
||
|
||
import * as d3 from "d3";
|
||
import ColorRamp from "./components/ColorRamp.vue";
|
||
|
||
</script>
|
||
|
||
# d3-interpolate
|
||
|
||
This module provides a variety of interpolation methods for blending between two values. Values may be numbers, colors, strings, arrays, or even deeply-nested objects. For example:
|
||
|
||
```js
|
||
const i = d3.interpolateNumber(10, 20);
|
||
i(0.0); // 10
|
||
i(0.2); // 12
|
||
i(0.5); // 15
|
||
i(1.0); // 20
|
||
```
|
||
|
||
The returned function `i` is an *interpolator*. Given a starting value *a* and an ending value *b*, it takes a parameter *t* typically in [0, 1] and returns the corresponding interpolated value. An interpolator typically returns a value equivalent to *a* at *t* = 0 and a value equivalent to *b* at *t* = 1.
|
||
|
||
You can interpolate more than just numbers. To find the perceptual midpoint between steelblue and brown:
|
||
|
||
```js
|
||
d3.interpolateLab("steelblue", "brown")(0.5); // "rgb(142, 92, 109)"
|
||
```
|
||
|
||
Or, as a color ramp from *t* = 0 to *t* = 1:
|
||
|
||
<ColorRamp :color='d3.interpolateLab("steelblue", "brown")' />
|
||
|
||
Here’s a more elaborate example demonstrating type inference used by [interpolate](./d3-interpolate/value.md#interpolate):
|
||
|
||
```js
|
||
const i = d3.interpolate({colors: ["red", "blue"]}, {colors: ["white", "black"]});
|
||
i(0.0); // {colors: ["rgb(255, 0, 0)", "rgb(0, 0, 255)"]}
|
||
i(0.5); // {colors: ["rgb(255, 128, 128)", "rgb(0, 0, 128)"]}
|
||
i(1.0); // {colors: ["rgb(255, 255, 255)", "rgb(0, 0, 0)"]}
|
||
```
|
||
|
||
Note that the generic value interpolator detects not only nested objects and arrays, but also color strings and numbers embedded in strings!
|
||
|
||
See one of:
|
||
|
||
* [Value interpolation](./d3-interpolate/value.md)
|
||
* [Color interpolation](./d3-interpolate/color.md)
|
||
* [Transform interpolation](./d3-interpolate/transform.md)
|
||
* [Zoom interpolation](./d3-interpolate/zoom.md)
|