Skip to content

Commit 3542325

Browse files
mbostockFil
andauthored
default z: null for redundant color encoding (#2379)
* defalt z: null for redundant color encoding * prettier * preddier * document z null default --------- Co-authored-by: Philippe Rivière <fil@rezo.net>
1 parent 729be1d commit 3542325

6 files changed

Lines changed: 2508 additions & 10 deletions

File tree

docs/marks/area.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ Plot.plot({
205205
```
206206
:::
207207

208-
To vary **fill** within a single series, set the **z** option to null.
208+
To vary **fill** within a single series, set the **z** option to null. For areaY, **z** defaults to null if the **fill** and **y** channels are strictly equal, as when the color encoding is redundant with position; for areaX, **z** defaults to null if **fill** and **x** are strictly equal. <VersionBadge pr="2379" />
209209

210210
:::plot defer https://observablehq.com/@observablehq/plot-variable-fill-area
211211
```js

docs/marks/line.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Plot.plot({
176176
Here the [normalize transform](../transforms/normalize.md) normalizes each time series (**z**) relative to its initial value, while the [select transform](../transforms/select.md) extracts the last point for labeling. A custom tick format converts multiples to percentage change (*e.g.*, 1.6× = +60%).
177177
:::
178178

179-
Varying-color lines are supported. If the **stroke** value varies within series, the line will be segmented by color. (The same behavior applies to other channels, such as **strokeWidth** and **title**.) Specifying the **z** channel (say to null for a single series) is recommended.
179+
Varying-color lines are supported. If the **stroke** value varies within series, the line will be segmented by color. (The same behavior applies to other channels, such as **strokeWidth** and **title**.) The **z** channel determines how data is grouped into series.
180180

181181
:::plot defer https://observablehq.com/@observablehq/plot-varying-stroke-line
182182
```js
@@ -201,6 +201,14 @@ Plot.plot({
201201
```
202202
:::
203203

204+
If the **stroke** and **y** channels are strictly equal, as when the color encoding is redundant with position, **z** defaults to null, producing a single varying-color line. <VersionBadge pr="2379" />
205+
206+
:::plot
207+
```js
208+
Plot.lineY(aapl, {x: "Date", y: "Close", stroke: "Close"}).plot({y: {grid: true}})
209+
```
210+
:::
211+
204212
Color encodings can also be used to highlight specific series, such as here to emphasize high unemployment in Michigan.
205213

206214
:::plot defer https://observablehq.com/@observablehq/plot-multiple-line-highlight

src/marks/area.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ export function area(data, options) {
7777
}
7878

7979
export function areaX(data, options) {
80-
const {y = indexOf, ...rest} = maybeDenseIntervalY(options);
81-
return new Area(data, maybeStackX(maybeIdentityX({...rest, y1: y, y2: undefined}, y === indexOf ? "x2" : "x")));
80+
const {x, y = indexOf, fill, z = x === fill ? null : undefined, ...rest} = maybeDenseIntervalY(options);
81+
return new Area(data, maybeStackX(maybeIdentityX({...rest, x, y1: y, y2: undefined, z, fill}, y === indexOf ? "x2" : "x"))); // prettier-ignore
8282
}
8383

8484
export function areaY(data, options) {
85-
const {x = indexOf, ...rest} = maybeDenseIntervalX(options);
86-
return new Area(data, maybeStackY(maybeIdentityY({...rest, x1: x, x2: undefined}, x === indexOf ? "y2" : "y")));
85+
const {x = indexOf, y, fill, z = y === fill ? null : undefined, ...rest} = maybeDenseIntervalX(options);
86+
return new Area(data, maybeStackY(maybeIdentityY({...rest, x1: x, x2: undefined, y, z, fill}, x === indexOf ? "y2" : "y"))); // prettier-ignore
8787
}

src/marks/line.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ export function line(data, {x, y, ...options} = {}) {
103103
return new Line(data, {...options, x, y});
104104
}
105105

106-
export function lineX(data, {x = identity, y = indexOf, ...options} = {}) {
107-
return new Line(data, maybeDenseIntervalY({...options, x, y}));
106+
export function lineX(data, {x = identity, y = indexOf, stroke, z = stroke === x ? null : undefined, ...options} = {}) {
107+
return new Line(data, maybeDenseIntervalY({...options, x, y, z, stroke}));
108108
}
109109

110-
export function lineY(data, {x = indexOf, y = identity, ...options} = {}) {
111-
return new Line(data, maybeDenseIntervalX({...options, x, y}));
110+
export function lineY(data, {x = indexOf, y = identity, stroke, z = stroke === y ? null : undefined, ...options} = {}) {
111+
return new Line(data, maybeDenseIntervalX({...options, x, y, z, stroke}));
112112
}

0 commit comments

Comments
 (0)