Skip to content

Commit

Permalink
fix inversion when collapsed domain (#2027)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 21, 2024
1 parent 7e598e4 commit 4422636
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/scales/quantitative.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ export function createScaleQ(
const [min, max] = extent(domain);
if (min > 0 || max < 0) {
domain = slice(domain);
if (orderof(domain) !== Math.sign(min)) domain[domain.length - 1] = 0; // [2, 1] or [-2, -1]
else domain[0] = 0; // [1, 2] or [-1, -2]
const o = orderof(domain) || 1; // treat degenerate as ascending
if (o === Math.sign(min)) domain[0] = 0; // [1, 2] or [-1, -2]
else domain[domain.length - 1] = 0; // [2, 1] or [-2, -1]
}
}

Expand Down
75 changes: 75 additions & 0 deletions test/output/zeroNegativeDegenerateY.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions test/output/zeroNegativeY.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions test/output/zeroPositiveDegenerateY.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions test/output/zeroPositiveY.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/plots/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,4 @@ export * from "./yearly-requests-dot.js";
export * from "./yearly-requests-line.js";
export * from "./yearly-requests.js";
export * from "./young-adults.js";
export * from "./zero.js";
17 changes: 17 additions & 0 deletions test/plots/zero.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as Plot from "@observablehq/plot";

export async function zeroNegativeY() {
return Plot.lineY([-0.25, -0.15, -0.05]).plot({y: {zero: true}});
}

export async function zeroPositiveY() {
return Plot.lineY([0.25, 0.15, 0.05]).plot({y: {zero: true}});
}

export async function zeroPositiveDegenerateY() {
return Plot.lineY([0.25, 0.25, 0.25]).plot({y: {zero: true}});
}

export async function zeroNegativeDegenerateY() {
return Plot.lineY([-0.25, -0.25, -0.25]).plot({y: {zero: true}});
}

0 comments on commit 4422636

Please sign in to comment.