1.0.5 • Published 2 years ago
d3-custom-scale v1.0.5
d3-custom-scales
This library allows the user to define custom scales from mathematical functions. The first parameter is the actual transform function, while the second one is the inverse function, used to perform the invert() method.
const asinhScale = scaleCustom(x => Math.asinh(x), x => Math.sinh(x));scaleCustom() returns a d3 scale, so all scale methods are available
const customScale = scaleCustom(x => x, x => x).domain([0,1]).range([0,100]).clamp(true)scaleCustom() allows 3 more optional parameters:
ticksused to customize the ticks displayedtickFormatwhich define how a tick value is converted to stringniceto provide better control of how the domain is rounded
// full signature
export const scaleCustom: scaleFunction = (
transform: (x: number) => number,
untransform: (x: number) => number,
ticks?: (count: number) => number[],
tickFormat?: (count?: number, specifier?: string) => (d: number) => string,
nice?: (count?: number) => ContinuousScale,
) => {}