Interface ScaleThreshold<Domain, Range, Unknown>

Threshold scales are similar to quantize scales, except they allow you to map arbitrary subsets of the domain to discrete values in the range. The input domain is still continuous, and divided into slices based on a set of threshold values.

If the number of values in the scale’s range is N+1, the number of values in the scale’s domain must be N. If there are fewer than N elements in the domain, the additional values in the range are ignored. If there are more than N elements in the domain, the scale may return undefined for some inputs.

The first generic corresponds to the data type of domain values. The second generic corresponds to the data type of range values. The third generic corresponds to the data type of the unknown value.

interface ScaleThreshold {
    copy(): ScaleThreshold<Domain, Range, Unknown>;
    domain(): Domain[];
    domain(domain): ScaleThreshold<Domain, Range, Unknown>;
    invertExtent(value): [Domain, Domain];
    range(): Range[];
    range(range): ScaleThreshold<Domain, Range, Unknown>;
    unknown(): UnknownReturnType<Unknown, undefined>;
    unknown<NewUnknown>(value): ScaleThreshold<Domain, Range, NewUnknown>;
    (value): Range | Unknown;
}

Type Parameters

  • Domain extends number | string | Date

  • Range

  • Unknown = never

  • Given a value in the input domain, returns the corresponding value in the output range.

    Parameters

    • value: Domain

      A domain value.

    Returns Range | Unknown

Methods

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

    Returns ScaleThreshold<Domain, Range, Unknown>

  • Returns the scale’s current domain.

    Returns Domain[]

  • Sets the scale’s domain to the specified array of values. The values must be in sorted ascending order, or the behavior of the scale is undefined. The values are typically numbers, but any naturally ordered values (such as strings) will work; a threshold scale can be used to encode any type that is ordered. If the number of values in the scale’s range is N+1, the number of values in the scale’s domain must be N. If there are fewer than N elements in the domain, the additional values in the range are ignored. If there are more than N elements in the domain, the scale may return undefined for some inputs.

    Parameters

    • domain: Iterable<Domain>

      Array of domain values.

    Returns ScaleThreshold<Domain, Range, Unknown>

  • Returns the extent of values in the domain [x0, x1] for the corresponding value in the range, representing the inverse mapping from range to domain. This method is useful for interaction, say to determine the value in the domain that corresponds to the pixel location under the mouse.

    Parameters

    • value: Range

      A range value.

    Returns [Domain, Domain]

  • Returns the scale’s current range.

    Returns Range[]

  • Sets the scale’s range to the specified array of values. If the number of values in the scale’s domain is N, the number of values in the scale’s range must be N+1. If there are fewer than N+1 elements in the range, the scale may return undefined for some inputs. If there are more than N+1 elements in the range, the additional values are ignored.

    Parameters

    • range: Iterable<Range>

      Array of range values.

    Returns ScaleThreshold<Domain, Range, 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 ScaleThreshold<Domain, Range, NewUnknown>