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
8 changes: 6 additions & 2 deletions src/defined.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ export function filter(index, ...channels) {
return index;
}

export function finite(x) {
return isFinite(x) ? x : NaN;
}

export function positive(x) {
return x > 0 ? x : NaN;
return x > 0 && isFinite(x) ? x : NaN;
}

export function negative(x) {
return x < 0 ? x : NaN;
return x < 0 && isFinite(x) ? x : NaN;
}

export function firstof(...values) {
Expand Down
6 changes: 3 additions & 3 deletions src/scales/quantitative.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from "d3";
import {ordinalRange, quantitativeScheme} from "./schemes.js";
import {registry, radius, opacity, color} from "./index.js";
import {positive, negative} from "../defined.js";
import {positive, negative, finite} from "../defined.js";
import {constant} from "../mark.js";
import {order} from "../scales.js";

Expand Down Expand Up @@ -159,15 +159,15 @@ export function ScaleIdentity() {
return {type: "identity", scale: scaleIdentity()};
}

export function inferDomain(channels, f) {
export function inferDomain(channels, f = finite) {
return channels.length ? [
min(channels, ({value}) => value === undefined ? value : min(value, f)),
max(channels, ({value}) => value === undefined ? value : max(value, f))
] : [0, 1];
}

function inferZeroDomain(channels) {
return [0, channels.length ? max(channels, ({value}) => value === undefined ? value : max(value)) : 1];
return [0, channels.length ? max(channels, ({value}) => value === undefined ? value : max(value, finite)) : 1];
}

// We don’t want the upper bound of the radial domain to be zero, as this would
Expand Down
52 changes: 52 additions & 0 deletions test/output/infinityLog.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.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export {default as identityScale} from "./identity-scale.js";
export {default as industryUnemployment} from "./industry-unemployment.js";
export {default as industryUnemploymentShare} from "./industry-unemployment-share.js";
export {default as industryUnemploymentStream} from "./industry-unemployment-stream.js";
export {default as infinityLog} from "./infinity-log.js";
export {default as learningPoverty} from "./learning-poverty.js";
export {default as letterFrequencyBar} from "./letter-frequency-bar.js";
export {default as letterFrequencyCloud} from "./letter-frequency-cloud.js";
Expand Down
5 changes: 5 additions & 0 deletions test/plots/infinity-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as Plot from "@observablehq/plot";

export default function() {
return Plot.dotX([NaN, 0.2, 0, 1, 2, 1 / 0]).plot({x: {type: "log", tickFormat: "f"}});
}