Squiggle logoSquiggle
API

Scale

Scales for plots.

Chart axes in plots can be scaled using the following functions. Each scale function accepts optional min and max value. Power scale accepts an extra exponent parameter.

Squiggle uses D3 for the tick formats. You can read about d3 tick formats here.

Numeric Scales

linear

Signatures
Scale.linear({min?: Number, max?: Number, tickFormat?: String, title?: String}) => Scale
Scale.linear() => Scale
Examples
Scale.linear({ min: 3, max: 10 })

log

Signatures
Scale.log({min?: Number, max?: Number, tickFormat?: String, title?: String}) => Scale
Scale.log() => Scale
Examples
Scale.log({ min: 1, max: 100 })

symlog

Symmetric log scale. Useful for plotting data that includes zero or negative values.

The function accepts an additional constant parameter, used as follows: Scale.symlog(\{constant: 0.1\}). This parameter allows you to allocate more pixel space to data with lower or higher absolute values. By adjusting this constant, you effectively control the scale's focus, shifting it between smaller and larger values. For more detailed information on this parameter, refer to the D3 Documentation.

The default value for constant is 0.0001.

Signatures
Scale.symlog({min?: Number, max?: Number, tickFormat?: String, title?: String, constant?: Number}) => Scale
Scale.symlog() => Scale
Examples
Scale.symlog({ min: -10, max: 10 })

power

Power scale. Accepts an extra exponent parameter, like, Scale.power(\{exponent: 2, min: 0, max: 100\}).

The default value for exponent is 0.1.

Signatures
Scale.power({min?: Number, max?: Number, tickFormat?: String, title?: String, exponent?: Number}) => Scale
Scale.power() => Scale
Examples
Scale.power({ min: 1, max: 100, exponent: 0.1 })

Date Scales

date

Only works on Date values. Is a linear scale under the hood.

Signatures
Scale.date({min?: Date, max?: Date, tickFormat?: String, title?: String}) => Scale
Scale.date() => Scale
Examples
Scale.date({ min: Date(2022), max: Date(2025) })

On this page