Skip to content

Commit 53d757e

Browse files
Filmbostock
andauthored
document piecewise scales (#2112)
* document piecewise scales closes #2107 * Update scales.md * Update scales.md --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent 203bd4c commit 53d757e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

docs/features/scales.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ Plot.plot({x: {type: "pow", exponent: 1 / 3, domain: [0, 100], grid: true}})
213213
```
214214
:::
215215

216-
Continuous scales also support a **clamp** option, which if true, clamps input values to the scale’s domain before scaling. This is useful for preventing marks from escaping the chart area.
216+
Continuous scales also support a **clamp** option which, if true, clamps input values to the scale’s domain before scaling. This is useful for preventing marks from escaping the chart area.
217+
218+
Continuous scales support an **interpolate** option specified either as a function that takes a single argument *t* in [0, 1] and returns the corresponding value from the **range**, or as a two-argument function that takes a pair of values [*start*, *end*] from the range and returns the corresponding interpolator from [0, 1], typically mapping 0 to *start*, and 1 to *end*.
219+
220+
Continuous scales support a piecewise **domain** specified as an array of _n_ domain values (with _n_ greater than or equal to two), with a corresponding **range** having the same number of values; each segment of the domain is mapped to the matching segment of the range using the scale’s interpolator. When the domain has *n*&nbsp;&gt;&nbsp;2 elements and the range has two elements (for example, when using the default range on a *x* or *y* scale), the latter is automatically split into _n_&nbsp;&minus;&nbsp;1 segments of equal size. Note that in addition to the domain, you must specify the scale’s continuous **type** since a scale specified with a domain having more than two elements otherwise defaults to an ordinal scale. (You will often have to specify the **ticks** manually, too.) For an example, see the [Polylinear axis](https://observablehq.com/@observablehq/polylinear-axis) notebook.
217221

218222
## Discrete scales
219223

0 commit comments

Comments
 (0)