Skip to content

Commit d1dcb6e

Browse files
committed
Update README
1 parent bfd2254 commit d1dcb6e

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

README.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -225,61 +225,6 @@ For convenience, an apply method is exposed, which returns the scale’s output
225225

226226
The scale object is undefined if the associated plot has no scale with the given *name*, and throws an error if the *name* is invalid (*i.e.*, not one of the known scale names: *x*, *y*, *fx*, *fy*, *r*, *color*, or *opacity*).
227227

228-
### Legends
229-
230-
Given a scale definition, Plot can generate a legend.
231-
232-
For an inline legend, use the *scale*.**legend** option:
233-
234-
* *scale*.**legend** - if truthy, generate a legend for the specified scale
235-
236-
Currently only *color* and *opacity* scales are supported. If the *scale*.**legend** option is true, the default legend will be produced for the scale; otherwise, the meaning of the *legend* option depends on the scale type. For quantitative color scales, it defaults to *ramp* but may be set to *swatches* for a discrete scale (most commonly for *threshold* color scales); for ordinal color scales, only the *swatches* value is supported.
237-
238-
#### *plot*.legend(*name*, *options*)
239-
240-
Given an existing *plot* returned by [Plot.plot](#plotplotoptions), returns a suitable legend for the *plot*’s scale with the given *name*. For example:
241-
242-
```js
243-
myplot = Plot.plot(…)
244-
```
245-
```js
246-
mylegend = myplot.legend("color")
247-
```
248-
249-
Currently only *color* and *opacity* scales are supported. An opacity scale is treated as a color scale with varying transparency.
250-
251-
Categorical and ordinal color legends are rendered as swatches, unless *options*.**legend** is set to *ramp*. The swatches can be configured with the following options:
252-
253-
* *options*.**tickFormat** - a format function for the labels
254-
* *options*.**swatchSize** - the size of the swatch (if square)
255-
* *options*.**swatchWidth** - the swatches’ width
256-
* *options*.**swatchHeight** - the swatches’ height
257-
* *options*.**columns** - the number of swatches per row
258-
* *options*.**marginLeft** - the legend’s left margin
259-
* *options*.**className** - a class name, that defaults to a randomly generated string scoping the styles
260-
261-
Continuous color legends are rendered as a ramp, and can be configured with the following options:
262-
263-
* *options*.**label** - the scale’s label
264-
* *options*.**ticks** - the desired number of ticks, or an array of tick values
265-
* *options*.**tickFormat** - a format function for the legend’s ticks
266-
* *options*.**tickSize** - the tick size
267-
* *options*.**round** - if true (default), round tick positions to pixels
268-
* *options*.**width** - the legend’s width
269-
* *options*.**height** - the legend’s height
270-
* *options*.**marginTop** - the legend’s top margin
271-
* *options*.**marginRight** - the legend’s right margin
272-
* *options*.**marginBottom** - the legend’s bottom margin
273-
* *options*.**marginLeft** - the legend’s left margin
274-
275-
#### Plot.legend(*options*)
276-
277-
Returns a standalone legend for the given *scale* definition, passing the *options* described in the previous section. For example:
278-
279-
```js
280-
Plot.legend({color: {type: "linear"}})
281-
```
282-
283228
### Position options
284229

285230
The position scales (*x*, *y*, *fx*, and *fy*) support additional options:
@@ -542,6 +487,61 @@ Plot.plot({
542487

543488
When the *include* or *exclude* facet mode is chosen, the mark data must be parallel to the facet data: the mark data must have the same length and order as the facet data. If the data are not parallel, then the wrong data may be shown in each facet. The default *auto* therefore requires strict equality (`===`) for safety, and using the facet data as mark data is recommended when using the *exclude* facet mode. (To construct parallel data safely, consider using [*array*.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on the facet data.)
544489

490+
## Legends
491+
492+
Given a scale definition, Plot can generate a legend.
493+
494+
For an inline legend, use the *scale*.**legend** option:
495+
496+
* *scale*.**legend** - if truthy, generate a legend for the specified scale
497+
498+
Currently only *color* and *opacity* scales are supported. If the *scale*.**legend** option is true, the default legend will be produced for the scale; otherwise, the meaning of the *legend* option depends on the scale type. For quantitative color scales, it defaults to *ramp* but may be set to *swatches* for a discrete scale (most commonly for *threshold* color scales); for ordinal color scales, only the *swatches* value is supported.
499+
500+
### *plot*.legend(*name*, *options*)
501+
502+
Given an existing *plot* returned by [Plot.plot](#plotplotoptions), returns a suitable legend for the *plot*’s scale with the given *name*. For example:
503+
504+
```js
505+
myplot = Plot.plot(…)
506+
```
507+
```js
508+
mylegend = myplot.legend("color")
509+
```
510+
511+
Currently only *color* and *opacity* scales are supported. An opacity scale is treated as a color scale with varying transparency.
512+
513+
Categorical and ordinal color legends are rendered as swatches, unless *options*.**legend** is set to *ramp*. The swatches can be configured with the following options:
514+
515+
* *options*.**tickFormat** - a format function for the labels
516+
* *options*.**swatchSize** - the size of the swatch (if square)
517+
* *options*.**swatchWidth** - the swatches’ width
518+
* *options*.**swatchHeight** - the swatches’ height
519+
* *options*.**columns** - the number of swatches per row
520+
* *options*.**marginLeft** - the legend’s left margin
521+
* *options*.**className** - a class name, that defaults to a randomly generated string scoping the styles
522+
523+
Continuous color legends are rendered as a ramp, and can be configured with the following options:
524+
525+
* *options*.**label** - the scale’s label
526+
* *options*.**ticks** - the desired number of ticks, or an array of tick values
527+
* *options*.**tickFormat** - a format function for the legend’s ticks
528+
* *options*.**tickSize** - the tick size
529+
* *options*.**round** - if true (default), round tick positions to pixels
530+
* *options*.**width** - the legend’s width
531+
* *options*.**height** - the legend’s height
532+
* *options*.**marginTop** - the legend’s top margin
533+
* *options*.**marginRight** - the legend’s right margin
534+
* *options*.**marginBottom** - the legend’s bottom margin
535+
* *options*.**marginLeft** - the legend’s left margin
536+
537+
### Plot.legend(*options*)
538+
539+
Returns a standalone legend for the given *scale* definition, passing the *options* described in the previous section. For example:
540+
541+
```js
542+
Plot.legend({color: {type: "linear"}})
543+
```
544+
545545
## Marks
546546

547547
[Marks](https://observablehq.com/@observablehq/plot-marks) visualize data as geometric shapes such as bars, dots, and lines. An single mark can generate multiple shapes: for example, passing a [Plot.barY](#plotbarydata-options) to [Plot.plot](#plotplotoptions) will produce a bar for each element in the associated data. Multiple marks can be layered into [plots](#plotplotoptions).

0 commit comments

Comments
 (0)