Interface ScaleDiverging<Output, Unknown>

Diverging scales, like sequential scales, are similar to continuous scales in that they map a continuous, numeric input domain to a continuous output range. However, unlike continuous scales, the input domain and output range of a diverging scale always has exactly three elements, and the output range is typically specified as an interpolator rather than an array of values. These scales do not expose invert and interpolate methods.

The first generic corresponds to the data type of the interpolator return type.

The second generic corresponds to the data type of the unknown value.

interface ScaleDiverging {
    clamp(): boolean;
    clamp(clamp): ScaleDiverging<Output, Unknown>;
    copy(): ScaleDiverging<Output, Unknown>;
    domain(): [number, number, number];
    domain(domain): ScaleDiverging<Output, Unknown>;
    interpolator(): ((t) => Output);
    interpolator(interpolator?): ScaleDiverging<Output, Unknown>;
    range(): (() => [Output, Output, Output]);
    range(range): ScaleDiverging<Output, Unknown>;
    rangeRound(range): ScaleDiverging<Output, Unknown>;
    unknown(): UnknownReturnType<Unknown, undefined>;
    unknown<NewUnknown>(value): ScaleDiverging<Output, NewUnknown>;
    (value): Output | Unknown;
}

Type Parameters

  • Output

  • Unknown = never

  • Given a value from the domain, returns the corresponding value subject to interpolation.

    If the given value is outside the domain, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the range.

    Parameters

    Returns Output | Unknown

Methods

  • Returns whether or not the scale currently clamps values to within the range.

    Returns boolean

  • Enables or disables clamping, respectively. If clamping is disabled and the scale is passed a value outside the domain, the scale may return a value outside the range through extrapolation.

    If clamping is enabled, the return value of the scale is always within the interpolator scale’s range.

    Parameters

    • clamp: boolean

      A flag to enable (true) or disable (false) clamping.

    Returns ScaleDiverging<Output, Unknown>

  • Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.

    Returns ScaleDiverging<Output, Unknown>

  • Returns a copy of the scale’s current domain.

    Returns [number, number, number]

  • Sets the scale’s domain to the specified array of numbers. The domain must be numeric and must contain exactly three values. The default domain is [0, 0.5, 1]. If the elements in the given array are not numbers, they will be coerced to numbers

    Parameters

    • domain: Iterable<NumberValue>

      Array of three numeric domain values.

    Returns ScaleDiverging<Output, Unknown>

  • Returns the scale’s current interpolator.

    Returns ((t) => Output)

      • (t): Output
      • Returns the scale’s current interpolator.

        Parameters

        • t: number

        Returns Output

  • Sets the scale’s interpolator to the specified function.

    Parameters

    • Optional interpolator: ((t) => Output)

      The scale’s interpolator.

        • (t): Output
        • Parameters

          • t: number

          Returns Output

    Returns ScaleDiverging<Output, Unknown>

  • See continuous.range.

    Returns (() => [Output, Output, Output])

      • (): [Output, Output, Output]
      • See continuous.range.

        Returns [Output, Output, Output]

  • See continuous.range. The given two-element array is converted to an interpolator function using d3.interpolate and d3.piecewise.

    Parameters

    • range: Iterable<Output>

      Range values.

    Returns ScaleDiverging<Output, Unknown>

  • See continuous.rangeRound. If range is specified, implicitly uses d3.interpolateRound as the interpolator.

    Parameters

    Returns ScaleDiverging<Output, Unknown>

  • Returns the current unknown value, which defaults to undefined.

    Returns UnknownReturnType<Unknown, undefined>

  • Sets the output value of the scale for undefined (or NaN) input values and returns this scale.

    Type Parameters

    • NewUnknown

    Parameters

    • value: NewUnknown

      The output value of the scale for undefined (or NaN) input values.

    Returns ScaleDiverging<Output, NewUnknown>