Interface ScaleQuantize<Range, Unknown>

Quantize scales are similar to linear scales, except they use a discrete rather than continuous range. The continuous input domain is divided into uniform segments based on the number of values in (i.e., the cardinality of) the output range.

Each range value y can be expressed as a quantized linear function of the domain value x: y = m round(x) + b.

The first generic corresponds to the data type of the range elements.

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

interface ScaleQuantize {
    copy(): ScaleQuantize<Range, Unknown>;
    domain(): [number, number];
    domain(domain): ScaleQuantize<Range, Unknown>;
    invertExtent(value): [number, number];
    nice(count?): ScaleQuantize<Range, Unknown>;
    range(): Range[];
    range(range): ScaleQuantize<Range, Unknown>;
    thresholds(): number[];
    tickFormat(count?, specifier?): ((d) => string);
    ticks(count?): number[];
    unknown(): UnknownReturnType<Unknown, undefined>;
    unknown<NewUnknown>(value): ScaleQuantize<Range, NewUnknown>;
    (value): Range | Unknown;
}

Type Parameters

  • Range

  • Unknown = never

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

    Parameters

    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 ScaleQuantize<Range, Unknown>

  • Returns the scale’s current domain.

    Returns [number, number]

  • Sets the scale’s domain to the specified two-element array of numbers. If the elements in the given array are not numbers, they will be coerced to numbers.

    Parameters

    • domain: Iterable<NumberValue>

      A two-element array of numeric values defining the domain.

    Returns ScaleQuantize<Range, Unknown>

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

    If an invalid range value is entered, returns [NaN, NaN].

    Parameters

    • value: Range

      A value from the range.

    Returns [number, number]

  • Extends the domain so that it starts and ends on nice round values. This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value.

    Nicing is useful if the domain is computed from data, say using extent, and may be irregular. For example, for a domain of [0.201479…, 0.996679…], a nice domain might be [0.2, 1.0].

    Nicing a scale only modifies the current domain; it does not automatically nice domains that are subsequently set using continuous.domain. You must re-nice the scale after setting the new domain, if desired.

    Parameters

    • Optional count: number

      An optional number of ticks expected to be used.

    Returns ScaleQuantize<Range, Unknown>

  • Returns the scale’s current range.

    Returns Range[]

  • Sets the scale’s range to the specified array of values. The array may contain any number of discrete values.

    Parameters

    • range: Iterable<Range>

      Array of range values.

    Returns ScaleQuantize<Range, Unknown>

  • Returns the array of computed thresholds within the domain.

    Returns number[]

  • Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values. The specified count should have the same value as the count that is used to generate the tick values.

    Parameters

    • Optional count: number

      Approximate number of ticks to be used when calculating precision for the number format function.

    • Optional specifier: string

      An optional valid format specifier string which allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval. If specifier uses the format type "s", the scale will return a SI-prefix format based on the largest value in the domain. If the specifier already specifies a precision, this method is equivalent to locale.format.

    Returns ((d) => string)

      • (d): string
      • Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values. The specified count should have the same value as the count that is used to generate the tick values.

        Parameters

        Returns string

  • Returns approximately count representative values from the scale’s domain.

    If count is not specified, it defaults to 10.

    The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10), and are guaranteed to be within the extent of the domain. Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data. The specified count is only a hint; the scale may return more or fewer values depending on the domain. See also d3-array’s ticks.

    Parameters

    • Optional count: number

      Optional approximate number of ticks to be returned. If count is not specified, it defaults to 10.

    Returns number[]

  • 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 ScaleQuantize<Range, NewUnknown>