Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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}});
}