Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix inversion when collapsed domain #2027

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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
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
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}});
}