Skip to content

Commit d9bebd0

Browse files
committed
Update README
1 parent 47fb222 commit d9bebd0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,16 @@ Plot.plot({
213213

214214
#### *plot*.**scale**(*scaleName*)
215215

216-
Scale definitions can be exposed through the *plot*.**scale**(*scaleName*) function of a returned plot.
216+
Scale definitions can be exposed through the *plot*.**scale**(*scaleName*) function of a returned plot. The *scaleName* must be one of the known scale names: `"x"`, `"y"`, `"fx"`, `"fy"`, `"r"`, `"color"`, `"opacity"`, `"symbol"`, or `"length"`.
217217

218218
```js
219219
const plot = Plot.plot(…); // render a plot
220220
const color = plot.scale("color"); // retrieve the color scale object
221221
console.log(color.range); // inspect the color scale’s range, ["red", "blue"]
222222
```
223223

224+
If the associated *plot* has no scale with the given *scaleName*, returns undefined.
225+
224226
#### Plot.**scale**(*options*)
225227

226228
You can also create a standalone scale with Plot.**scale**(*options*). The *options* object must define at least one scale; see [Scale options](#scale-options) for how to define a scale.
@@ -229,19 +231,19 @@ You can also create a standalone scale with Plot.**scale**(*options*). The *opti
229231
const color = Plot.scale({color: {type: "linear"}});
230232
```
231233

234+
#### Scale objects
235+
236+
Both [*plot*.scale](#plotscalescalename) and [Plot.scale](#plotscaleoptions) return scale objects. These objects represent the actual (or “materialized”) values encountered in the plot, including the domain, range, interpolate function, *etc.* The scale’s label, if any, is also returned; however, note that other axis properties are not currently exposed. Point and band scales also expose their materialized bandwidth and step.
237+
232238
To reuse a scale across plots, pass the scale object into another plot specification:
233239

234240
```js
235241
const plot1 = Plot.plot(…);
236242
const plot2 = Plot.plot({…, color: plot1.scale("color")});
237243
```
238244

239-
The returned scale object represents the actual (or “materialized”) values encountered in the plot, including the domain, range, interpolate function, *etc.* The scale’s label, if any, is also returned; however, note that other axis properties are not currently exposed. Point and band scales also expose their materialized bandwidth and step.
240-
241245
For convenience, the returned *scale* exposes a *scale*.**apply**(*input*) method which returns the scale’s output for the given *input* value. When applicable, the *scale* object also exposes a *scale*.**invert**(*output*) method which returns the corresponding input value from the scale’s domain for the given *output* value.
242246

243-
The scale object is undefined if the associated plot has no scale with the given *scaleName*, and throws an error if the *scaleName* is invalid (*i.e.*, not one of the known scale names: *x*, *y*, *fx*, *fy*, *r*, *color*, or *opacity*).
244-
245247
### Position options
246248

247249
The position scales (*x*, *y*, *fx*, and *fy*) support additional options:

0 commit comments

Comments
 (0)