Skip to content

Commit aa0ba22

Browse files
claudeFil
authored andcommitted
fix: areaY dense interval without explicit y option (#2328)
Fixed areaY to work with dense intervals (interval + reduce) without requiring an explicit y option, matching lineY behavior. 🤖 Generated with [Claude Code](https://claude.ai/code) Total cost: $5.51 Total duration (API): 23m 31.3s Total duration (wall): 14h 30m 4.3s Total code changes: 208 lines added, 53 lines removed Token usage by model: claude-3-5-haiku: 204.7k input, 4.8k output, 0 cache read, 0 cache write claude-sonnet: 18.9k input, 28.4k output, 8.3m cache read, 629.5k cache write
1 parent 90a5689 commit aa0ba22

File tree

5 files changed

+158
-3
lines changed

5 files changed

+158
-3
lines changed

src/marks/area.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {area as shapeArea} from "d3";
22
import {create} from "../context.js";
33
import {maybeCurve} from "../curve.js";
44
import {Mark} from "../mark.js";
5-
import {first, indexOf, maybeZ, second} from "../options.js";
5+
import {first, identity, indexOf, maybeZ, second} from "../options.js";
66
import {
77
applyDirectStyles,
88
applyIndirectStyles,
@@ -77,11 +77,15 @@ export function area(data, options) {
7777
}
7878

7979
export function areaX(data, options) {
80-
const {y = indexOf, ...rest} = maybeDenseIntervalY(options);
80+
const {y = indexOf, ...rest} = maybeDenseIntervalY(
81+
options?.interval != null ? {...options, x: options.x ?? identity} : options
82+
);
8183
return new Area(data, maybeStackX(maybeIdentityX({...rest, y1: y, y2: undefined}, y === indexOf ? "x2" : "x")));
8284
}
8385

8486
export function areaY(data, options) {
85-
const {x = indexOf, ...rest} = maybeDenseIntervalX(options);
87+
const {x = indexOf, ...rest} = maybeDenseIntervalX(
88+
options?.interval != null ? {...options, y: options.y ?? identity} : options
89+
);
8690
return new Area(data, maybeStackY(maybeIdentityY({...rest, x1: x, x2: undefined}, x === indexOf ? "y2" : "y")));
8791
}

test/output/denseIntervalAreaY.svg

Lines changed: 64 additions & 0 deletions
Loading

test/output/denseIntervalLineY.svg

Lines changed: 70 additions & 0 deletions
Loading

test/plots/dense-interval.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as Plot from "@observablehq/plot";
2+
import * as d3 from "d3";
3+
4+
export async function denseIntervalAreaY() {
5+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
6+
return Plot.plot({
7+
marks: [Plot.areaY(aapl, {x: "Date", reduce: "count", interval: "month"})]
8+
});
9+
}
10+
11+
export async function denseIntervalLineY() {
12+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
13+
return Plot.plot({
14+
marks: [Plot.lineY(aapl, {x: "Date", reduce: "count", interval: "month"})]
15+
});
16+
}

test/plots/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export * from "./boxplot.js";
4848
export * from "./caltrain-direction.js";
4949
export * from "./caltrain.js";
5050
export * from "./cars-dodge.js";
51+
export * from "./dense-interval.js";
5152
export * from "./cars-hexbin.js";
5253
export * from "./cars-jitter.js";
5354
export * from "./cars-mpg.js";

0 commit comments

Comments
 (0)