Similar to linear scales, except an logarithmic transform is applied to the input domain value before the output range value is computed. Each range value y can be expressed as a function of the domain value x: y = log(x) + b
. (online demo)
import { Log, LogOptions } from '@antv/scale';
const options: LogOptions = {
domain: [1, 10],
range: [0, 1],
base: 10
};
const x = new Log(options);
x.map(1); // 0
x.map(2); // 0.301
x.invert(0.301); // 2
More usages reference linear scale.
Key | Description | Type | Default |
---|---|---|---|
domain | Sets the scale’s domain to the specified array of values. A log scale domain must be strictly-positive or strictly-negative; the domain must not include or cross zero. | number[] |
[0, 1] |
range | Sets the scale’s range to the specified array of values. | <code>number[] | string[]</code> |
[0, 1] |
unknown | Sets the output value of the scale for undefined (or NaN ) input values. |
any |
undefined |
tickCount | Sets approximately count representative values from the scale’s domain. The specified tickCount in options is only a hint: the scale may return more or fewer values depending on the domain. |
number |
5 |
tickMethod | Sets the method for computing representative values from the scale’s domain. | (min: number, max: number, count: number, base: number) => number[] |
d3-ticks |
round | Rounds the output of map or invert if it is true. | boolean |
false |
clamp | Constrains the return value of map within the scale’s range if it is true. | boolean |
false |
nice | Extends the domain so that it starts and ends on nice round values if it is true. | boolean |
false |
interpolate | Sets the scale’s range interpolator factory if it is specified. | (a: number, b: number) => (t: number) => number |
(a, b) => (t) => a * (1 - t) + b * t |
base | Sets the base for this logarithmic scale if it is specified. | number |
10 |
# map(x: number): number
Given a value in the input domain, returns the corresponding value in the output range if it is not undefined
(or NaN
), otherwise options.unknown
# invert(x: number): number
Given a value from the range, returns the corresponding value from the domain.
# update(options: LogOptions): void
Updates the scale's options and rescale.
# getOptions(): LogOptions
Returns the scale's current options.
# clone(): Log
Returns a new Log scale with the independent and same options as the original one.
# getTicks(): number[]
Returns representative values from the scale’s domain computed by specified options.tickMethod
with options.tickCount
.