发散尺度
🌐 Diverging scales
发散刻度类似于线性刻度,因为它们将连续的数字输入域映射到连续的输出范围。不同于线性刻度,发散刻度的输入域和输出范围总是恰好有三个元素,且输出范围通常以插值器的形式指定,而不是值数组。发散刻度通常用于颜色编码;另请参见d3-scale-chromatic。这些刻度不公开invert和interpolate方法。发散刻度也有对数、幂和符号对数变体。
🌐 Diverging scales are similar to linear scales in that they map a continuous, numeric input domain to a continuous output range. Unlike linear scales, the input domain and output range of a diverging scale always have exactly three elements, and the output range is typically specified as an interpolator rather than an array of values. Diverging scales are typically used for a color encoding; see also d3-scale-chromatic. These scales do not expose invert and interpolate methods. There are also log, pow, and symlog variants of diverging scales.
scaleDiverging(domain, interpolator)
示例 · 来源 · 使用指定的 域 和 插值器 函数或数组构建一个新的发散比例。
const color = d3.scaleDiverging([-1, 0, 1], d3.interpolateRdBu);如果未指定 domain,则默认为 [0, 0.5, 1]。
🌐 If domain is not specified, it defaults to [0, 0.5, 1].
const color = d3.scaleDiverging(d3.interpolateRdBu);如果未指定 interpolator,则默认为恒等函数。
🌐 If interpolator is not specified, it defaults to the identity function.
const identity = d3.scaleDiverging();应用比例时,将使用通常在 [0, 1] 范围内的值调用插值器,其中 0 表示极负值,0.5 表示中性值,1 表示极正值。
🌐 When the scale is applied, the interpolator will be invoked with a value typically in the range [0, 1], where 0 represents the extreme negative value, 0.5 represents the neutral value, and 1 represents the extreme positive value.
如果 interpolator 是一个数组,它表示刻度的三个元素的输出范围,并使用 d3.interpolate 和 d3.piecewise 转换为一个插值函数。
🌐 If interpolator is an array, it represents the scale’s three-element output range and is converted to an interpolator function using d3.interpolate and d3.piecewise.
const color = d3.scaleDiverging(["blue", "white", "red"]);发散尺度的域必须是数字,并且必须恰好包含三个值。
🌐 A diverging scale’s domain must be numeric and must contain exactly three values.
diverging.interpolator(interpolator)
如果指定了 interpolator,则将比例的插值器设置为指定的函数。
🌐 If interpolator is specified, sets the scale’s interpolator to the specified function.
const color = d3.scaleDiverging().interpolator(d3.interpolateRdBu);如果未指定 interpolator,则返回比例当前的插值器。
🌐 If interpolator is not specified, returns the scale’s current interpolator.
color.interpolator() // d3.interpolateRdBudiverging.range(range)
请参见 linear.range。如果指定了 range,给定的三元素数组将使用 piecewise 转换为插值函数。
🌐 See linear.range. If range is specified, the given three-element array is converted to an interpolator function using piecewise.
const color = d3.scaleDiverging().range(["blue", "white", "red"]);以上内容等同于:
🌐 The above is equivalent to:
const color = d3.scaleDiverging(d3.piecewise(["blue", "white", "red"]));diverging.rangeRound(range)
参见 linear.range。如果指定了 range,则隐式使用 interpolateRound 作为插值器。
🌐 See linear.range. If range is specified, implicitly uses interpolateRound as the interpolator.
scaleDivergingLog(domain, range)
返回一个新的分歧刻度,并使用对数变换,类似于 对数刻度。
🌐 Returns a new diverging scale with a logarithmic transform, analogous to a log scale.
scaleDivergingPow(domain, range)
返回一个具有指数变换的新发散尺度,类似于幂尺度。
🌐 Returns a new diverging scale with an exponential transform, analogous to a power scale.
scaleDivergingSqrt(domain, range)
返回一个新的分歧刻度,使用平方根变换,类似于sqrt 刻度。
🌐 Returns a new diverging scale with a square-root transform, analogous to a sqrt scale.
scaleDivergingSymlog(域, 范围)
🌐 scaleDivergingSymlog(domain, range)
返回一个具有对称对数变换的新发散刻度,类似于 symlog 刻度。
🌐 Returns a new diverging scale with a symmetric logarithmic transform, analogous to a symlog scale.