Skip to content

Commit a86edf8

Browse files
committed
checkpoint
1 parent c862122 commit a86edf8

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ Plot.plot({
200200
})
201201
```
202202

203+
All the scales are exposed as the *scales* property of the plot. We recommend using *scale*.copy if making any use of these scales that might mutate them.
204+
205+
```js
206+
color = Plot.plot({…}).scales.color;
207+
color.range() // ["red", "blue"]
208+
```
209+
210+
And, to reuse the scale in another plot:
211+
212+
```js
213+
Plot.plot({
214+
color: { domain: color.copy().domain(), range: color.copy().range() }
215+
})
216+
```
217+
218+
203219
### Position options
204220

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

src/plot.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,8 @@ export function plot(options = {}) {
8888
if (node != null) svg.appendChild(node);
8989
}
9090

91-
// Wrap the plot in a figure with a caption, if desired.
92-
if (caption == null) return svg;
93-
const figure = document.createElement("figure");
94-
figure.appendChild(svg);
95-
const figcaption = figure.appendChild(document.createElement("figcaption"));
96-
figcaption.appendChild(caption instanceof Node ? caption : document.createTextNode(caption));
91+
const figure = wrap(svg, {caption});
92+
figure.scales = scales;
9793
return figure;
9894
}
9995

@@ -143,3 +139,13 @@ function autoHeight({y, fy, fx}) {
143139
const ny = y ? (y.type === "ordinal" ? y.scale.domain().length : Math.max(7, 17 / nfy)) : 1;
144140
return !!(y || fy) * Math.max(1, Math.min(60, ny * nfy)) * 20 + !!fx * 30 + 60;
145141
}
142+
143+
// Wrap the plot in a figure with a caption, if desired.
144+
function wrap(svg, {caption}) {
145+
if (caption == null) return svg;
146+
const figure = document.createElement("figure");
147+
figure.appendChild(svg);
148+
const figcaption = figure.appendChild(document.createElement("figcaption"));
149+
figcaption.appendChild(caption instanceof Node ? caption : document.createTextNode(caption));
150+
return figure;
151+
}

0 commit comments

Comments
 (0)