Skip to content

Commit 4422636

Browse files
authored
fix inversion when collapsed domain (#2027)
1 parent 7e598e4 commit 4422636

File tree

7 files changed

+321
-2
lines changed

7 files changed

+321
-2
lines changed

src/scales/quantitative.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ export function createScaleQ(
123123
const [min, max] = extent(domain);
124124
if (min > 0 || max < 0) {
125125
domain = slice(domain);
126-
if (orderof(domain) !== Math.sign(min)) domain[domain.length - 1] = 0; // [2, 1] or [-2, -1]
127-
else domain[0] = 0; // [1, 2] or [-1, -2]
126+
const o = orderof(domain) || 1; // treat degenerate as ascending
127+
if (o === Math.sign(min)) domain[0] = 0; // [1, 2] or [-1, -2]
128+
else domain[domain.length - 1] = 0; // [2, 1] or [-2, -1]
128129
}
129130
}
130131

+75
Loading

test/output/zeroNegativeY.svg

+75
Loading
+75
Loading

test/output/zeroPositiveY.svg

+75
Loading

test/plots/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,4 @@ export * from "./yearly-requests-dot.js";
340340
export * from "./yearly-requests-line.js";
341341
export * from "./yearly-requests.js";
342342
export * from "./young-adults.js";
343+
export * from "./zero.js";

test/plots/zero.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as Plot from "@observablehq/plot";
2+
3+
export async function zeroNegativeY() {
4+
return Plot.lineY([-0.25, -0.15, -0.05]).plot({y: {zero: true}});
5+
}
6+
7+
export async function zeroPositiveY() {
8+
return Plot.lineY([0.25, 0.15, 0.05]).plot({y: {zero: true}});
9+
}
10+
11+
export async function zeroPositiveDegenerateY() {
12+
return Plot.lineY([0.25, 0.25, 0.25]).plot({y: {zero: true}});
13+
}
14+
15+
export async function zeroNegativeDegenerateY() {
16+
return Plot.lineY([-0.25, -0.25, -0.25]).plot({y: {zero: true}});
17+
}

0 commit comments

Comments
 (0)