You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -213,14 +213,16 @@ Plot.plot({
213
213
214
214
#### *plot*.**scale**(*scaleName*)
215
215
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"`.
217
217
218
218
```js
219
219
constplot=Plot.plot(…); // render a plot
220
220
constcolor=plot.scale("color"); // retrieve the color scale object
221
221
console.log(color.range); // inspect the color scale’s range, ["red", "blue"]
222
222
```
223
223
224
+
If the associated *plot* has no scale with the given *scaleName*, returns undefined.
225
+
224
226
#### Plot.**scale**(*options*)
225
227
226
228
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
229
231
constcolor=Plot.scale({color: {type:"linear"}});
230
232
```
231
233
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
+
232
238
To reuse a scale across plots, pass the scale object into another plot specification:
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
-
241
245
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.
242
246
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
-
245
247
### Position options
246
248
247
249
The position scales (*x*, *y*, *fx*, and *fy*) support additional options:
0 commit comments