Skip to content

Commit 0629168

Browse files
committed
Merge branch 'main' into claude/2328
2 parents f68f877 + 3542325 commit 0629168

33 files changed

Lines changed: 3085 additions & 81 deletions

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/interactions/pointer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {isArray} from "../options.js";
44
import {applyFrameAnchor} from "../style.js";
55

66
const states = new WeakMap();
7+
const handledEvents = new WeakSet();
78

89
function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...options} = {}) {
910
maxRadius = +maxRadius;
@@ -162,12 +163,13 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...op
162163
}
163164

164165
function pointerdown(event) {
166+
if (handledEvents.has(event)) return; // ignore same event on a shared pointer
167+
handledEvents.add(event);
165168
if (event.pointerType !== "mouse") return;
166169
if (i == null) return; // not pointing
167170
if (state.sticky && state.roots.some((r) => r?.contains(event.target))) return; // stay sticky
168171
if (state.sticky) (state.sticky = false), state.renders.forEach((r) => r(null)); // clear all pointers
169172
else (state.sticky = true), render(i);
170-
event.stopImmediatePropagation(); // suppress other pointers
171173
}
172174

173175
function pointerleave(event) {

src/marker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function markerArrow(orient) {
4545
.attr("orient", orient)
4646
.attr("fill", "none")
4747
.attr("stroke", color)
48+
.attr("stroke-dasharray", "none")
4849
.attr("stroke-width", 1.5)
4950
.attr("stroke-linecap", "round")
5051
.attr("stroke-linejoin", "round")
@@ -70,6 +71,7 @@ function markerCircleFill(color, context) {
7071
.attr("markerHeight", 6.67)
7172
.attr("fill", color)
7273
.attr("stroke", "var(--plot-background)")
74+
.attr("stroke-dasharray", "none")
7375
.attr("stroke-width", 1.5)
7476
.call((marker) => marker.append("circle").attr("r", 3))
7577
.node();
@@ -82,6 +84,7 @@ function markerCircleStroke(color, context) {
8284
.attr("markerHeight", 6.67)
8385
.attr("fill", "var(--plot-background)")
8486
.attr("stroke", color)
87+
.attr("stroke-dasharray", "none")
8588
.attr("stroke-width", 1.5)
8689
.call((marker) => marker.append("circle").attr("r", 3))
8790
.node();
@@ -95,6 +98,7 @@ function markerTick(orient) {
9598
.attr("markerHeight", 6)
9699
.attr("orient", orient)
97100
.attr("stroke", color)
101+
.attr("stroke-dasharray", "none")
98102
.call((marker) => marker.append("path").attr("d", "M0,-3v6"))
99103
.node();
100104
}

src/marks/area.js

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

7373
export function areaX(data, options) {
74-
const {y, ...rest} = maybeDenseIntervalY(options);
75-
return new Area(data, maybeStackX({...rest, y1: y, y2: undefined}));
74+
const {x, y, fill, z = x === fill ? null : undefined, ...rest} = maybeDenseIntervalY(options);
75+
return new Area(data, maybeStackX({...rest, x, y1: y, y2: undefined, z, fill}));
7676
}
7777

7878
export function areaY(data, options) {
79-
const {x, ...rest} = maybeDenseIntervalX(options);
80-
return new Area(data, maybeStackY({...rest, x1: x, x2: undefined}));
79+
const {x, y, fill, z = y === fill ? null : undefined, ...rest} = maybeDenseIntervalX(options);
80+
return new Area(data, maybeStackY({...rest, x1: x, x2: undefined, y, z, fill}));
8181
}

src/marks/line.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {create} from "../context.js";
33
import {curveAuto, maybeCurveAuto} from "../curve.js";
44
import {Mark} from "../mark.js";
55
import {applyGroupedMarkers, markers} from "../marker.js";
6-
import {coerceNumbers, maybeTuple, maybeZ} from "../options.js";
6+
import {coerceNumbers, identity, indexOf, maybeTuple, maybeZ} from "../options.js";
77
import {applyDirectStyles, applyIndirectStyles, applyTransform, applyGroupedChannelStyles} from "../style.js";
88
import {groupIndex} from "../style.js";
99
import {maybeDenseIntervalX, maybeDenseIntervalY} from "../transforms/bin.js";
@@ -98,10 +98,10 @@ export function line(data, {x, y, ...options} = {}) {
9898
return new Line(data, {...options, x, y});
9999
}
100100

101-
export function lineX(data, options) {
102-
return new Line(data, maybeDenseIntervalY(options));
101+
export function lineX(data, {x = identity, y = indexOf, stroke, z = stroke === x ? null : undefined, ...options} = {}) {
102+
return new Line(data, maybeDenseIntervalY({...options, x, y, z, stroke}));
103103
}
104104

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

src/marks/tip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ function getSourceChannels(channels, scales) {
347347
if ((key === "x" || key === "y") && channels.geometry) continue; // ignore x & y on geo
348348
const source = getSource(channels, key);
349349
if (source) {
350-
// Ignore color channels if the values are all literal colors.
351-
if (source.scale == null && source.defaultScale === "color") continue;
350+
// Ignore (e.g., color) channels if the values are all literal.
351+
if (source.scale == null && source.defaultScale) continue;
352352
sources[key] = source;
353353
}
354354
}

src/transforms/dodge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function dodge(y, x, anchor, padding, r, options) {
7878
const radius = R ? (i) => R[i] : () => cr;
7979
for (let I of facets) {
8080
const tree = IntervalTree();
81-
I = I.filter(R ? (i) => finite(X[i]) && positive(R[i]) : (i) => finite(X[i]));
81+
I = I.filter(R ? (i) => finite(X[i]) && positive(R[i]) : cr > 0 ? (i) => finite(X[i]) : () => false);
8282
const intervals = new Float64Array(2 * I.length + 2);
8383
for (const i of I) {
8484
const ri = radius(i);

0 commit comments

Comments
 (0)