Skip to content

功率尺度

¥Power scales

幂级数 (“pow”) 比例与 线性比例尺 类似,但在计算输出范围值之前,会对输入域值应用指数变换。每个范围值 y 可以表示为定义域值 x 的函数:y = mx^k + b,其中 k 是 exponent 的值。幂级数比例也支持负域值,在这种情况下,输入值和结果输出值会乘以 -1。

¥Power (“pow”) scales are similar to linear scales, except an exponential 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 = mx^k + b, where k is the exponent value. Power scales also support negative domain values, in which case the input value and the resulting output value are multiplied by -1.

scalePow(domain, range)

示例 · 源代码 · 使用指定的 domainrange 构造一个新的 pow 比例尺,exponent 为 1,defaultinterpolatorclamping 被禁用。

¥Examples · Source · Constructs a new pow scale with the specified domain and range, the exponent 1, the default interpolator and clamping disabled.

js
const x = d3.scalePow([0, 100], ["red", "blue"]).exponent(2);

如果未指定域或范围,则每个值默认为 [0, 1]。

¥If either domain or range are not specified, each defaults to [0, 1].

scaleSqrt(domain, range)

示例 · 源代码 · 使用指定的 domainrange 构造一个新的 pow 比例尺,exponent 为 0.5,defaultinterpolatorclamping 被禁用。

¥Examples · Source · Constructs a new pow scale with the specified domain and range, the exponent 0.5, the default interpolator and clamping disabled.

js
const x = d3.scaleSqrt([0, 100], ["red", "blue"]);

如果未指定域或范围,则每个值默认为 [0, 1]。这是一种与 d3.scalePow(…).exponent(0.5) 等效的便捷方法。

¥If either domain or range are not specified, each defaults to [0, 1]. This is a convenience method equivalent to d3.scalePow(…).exponent(0.5).

pow.exponent(exponent) {#pow_exponent}

示例 · 源代码 · 如果指定了 exponent,则将当前 exponent 设置为给定的数值并返回此比例尺。

¥Examples · Source · If exponent is specified, sets the current exponent to the given numeric value and returns this scale.

js
const x = d3.scalePow([0, 100], ["red", "blue"]).exponent(2);

如果未指定 exponent,则返回当前 exponent,默认为 1。

¥If exponent is not specified, returns the current exponent, which defaults to 1.

js
x.exponent() // 2

如果指数为 1,则 pow 比例实际上是 linear 比例。

¥If the exponent is 1, the pow scale is effectively a linear scale.