Skip to content

Commit 0678e73

Browse files
Filmbostock
andauthored
fix regression (#1244)
* fix a regression where scales defined by a domain or a type (with default domain) where considered absent * adopt isScaleOptions --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent 9d52de3 commit 0678e73

File tree

8 files changed

+178
-11
lines changed

8 files changed

+178
-11
lines changed

src/plot.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,15 +474,15 @@ function inferAxes(marks, channelsByScale, options) {
474474
grid,
475475
facet = {},
476476
facet: {axis: facetAxis = axis, grid: facetGrid} = facet,
477-
x: {type: xType = hasScale(marks, "x"), axis: xAxis = axis, grid: xGrid = xAxis === null ? null : grid} = x,
478-
y: {type: yType = hasScale(marks, "y"), axis: yAxis = axis, grid: yGrid = yAxis === null ? null : grid} = y,
477+
x: {axis: xAxis = axis, grid: xGrid = xAxis === null ? null : grid} = x,
478+
y: {axis: yAxis = axis, grid: yGrid = yAxis === null ? null : grid} = y,
479479
fx: {axis: fxAxis = facetAxis, grid: fxGrid = fxAxis === null ? null : facetGrid} = fx,
480480
fy: {axis: fyAxis = facetAxis, grid: fyGrid = fyAxis === null ? null : facetGrid} = fy
481481
} = options;
482482

483483
// Disable axes if the corresponding scale is not present.
484-
if (projection || !xType) xAxis = xGrid = null;
485-
if (projection || !yType) yAxis = yGrid = null;
484+
if (projection || (!isScaleOptions(x) && !hasScaleChannel("x", marks))) xAxis = xGrid = null;
485+
if (projection || (!isScaleOptions(y) && !hasScaleChannel("y", marks))) yAxis = yGrid = null;
486486
if (!channelsByScale.has("fx")) fxAxis = fxGrid = null;
487487
if (!channelsByScale.has("fy")) fyAxis = fyGrid = null;
488488

@@ -608,7 +608,7 @@ function hasAxis(marks, k) {
608608
return marks.some((m) => m.ariaLabel?.startsWith(prefix));
609609
}
610610

611-
function hasScale(marks, k) {
611+
function hasScaleChannel(k, marks) {
612612
for (const mark of marks) {
613613
for (const key in mark.channels) {
614614
if (mark.channels[key].scale === k) {

test/output/frameSides.svg

Lines changed: 20 additions & 0 deletions
Loading

test/output/frameSidesX.svg

Lines changed: 36 additions & 0 deletions
Loading

test/output/frameSidesXY.svg

Lines changed: 52 additions & 0 deletions
Loading

test/output/frameSidesY.svg

Lines changed: 36 additions & 0 deletions
Loading

test/plots/frame-corners.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/plots/frame.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as Plot from "@observablehq/plot";
2+
3+
export async function frameCorners() {
4+
return Plot.frame({rx: 16, ry: 10}).plot();
5+
}
6+
7+
const marks = [
8+
Plot.frame({anchor: "left", stroke: "red", strokeWidth: 4}),
9+
Plot.frame({anchor: "right", stroke: "green", strokeWidth: 4}),
10+
Plot.frame({anchor: "top", stroke: "blue", strokeWidth: 4}),
11+
Plot.frame({anchor: "bottom", stroke: "black", strokeWidth: 4})
12+
];
13+
14+
export async function frameSides() {
15+
return Plot.plot({width: 350, height: 250, margin: 2, marks});
16+
}
17+
18+
export async function frameSidesXY() {
19+
return Plot.plot({width: 350, height: 250, x: {domain: [0, 1]}, y: {domain: [0, 1]}, marks});
20+
}
21+
22+
export async function frameSidesX() {
23+
return Plot.plot({width: 350, height: 250, x: {domain: [0, 1]}, marks});
24+
}
25+
26+
export async function frameSidesY() {
27+
return Plot.plot({width: 350, height: 250, y: {domain: [0, 1]}, marks});
28+
}

test/plots/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export {default as flareCluster} from "./flare-cluster.js";
7474
export {default as flareIndent} from "./flare-indent.js";
7575
export {default as flareTree} from "./flare-tree.js";
7676
export {default as footballCoverage} from "./football-coverage.js";
77-
export {default as frameCorners} from "./frame-corners.js";
7877
export {default as fruitSales} from "./fruit-sales.js";
7978
export {default as fruitSalesDate} from "./fruit-sales-date.js";
8079
export {default as gistempAnomaly} from "./gistemp-anomaly.js";
@@ -285,6 +284,7 @@ export * from "./axis-labels.js";
285284
export * from "./bin-1m.js";
286285
export * from "./electricity-demand.js";
287286
export * from "./federal-funds.js";
287+
export * from "./frame.js";
288288
export * from "./function-contour.js";
289289
export * from "./heatmap.js";
290290
export * from "./legend-color.js";

0 commit comments

Comments
 (0)