Skip to content

document piecewise scales #2112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/features/scales.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ Plot.plot({x: {type: "pow", exponent: 1 / 3, domain: [0, 100], grid: true}})
```
:::

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.
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.

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*.

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* > 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_ − 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.

## Discrete scales

Expand Down