Interface Contours

A contour generator which computes contour polygons by applying marching squares to a rectangular array of numeric values.

For each threshold value, the contour generator constructs a GeoJSON MultiPolygon geometry object representing the area where the input values are greater than or equal to the threshold value. The geometry is in planar coordinates, where ⟨i + 0.5, j + 0.5⟩ corresponds to element i + jn in the input values array.

interface Contours {
    contour(values, threshold): ContourMultiPolygon;
    size(): [number, number];
    size(size): Contours;
    smooth(): boolean;
    smooth(smooth): Contours;
    thresholds(): ThresholdCountGenerator<number> | ThresholdNumberArrayGenerator<number>;
    thresholds(thresholds): Contours;
    (values): ContourMultiPolygon[];
}
  • Computes the contours for the given array of values, returning an array of GeoJSON MultiPolygon geometry objects. Each geometry object represents the area where the input values are greater than or equal to the corresponding threshold value; the threshold value for each geometry object is exposed as geometry.value.

    The returned geometry objects are typically passed to d3.geoPath to display, using null or d3.geoIdentity as the associated projection

    Parameters

    • values: number[]

      Array of input values. The input values must be an array of length n×m where [n, m] is the contour generator’s size; furthermore, each values[i + jn] must represent the value at the position ⟨i, j⟩.

    Returns ContourMultiPolygon[]

Methods

  • Computes a single contour, returning a GeoJSON MultiPolygon geometry object. This geometry object represents the area where the input values are greater than or equal to the given threshold value; the threshold value for the geometry object is exposed as geometry.value.

    Parameters

    • values: number[]

      Array of input values. The input values must be an array of length n×m where [n, m] is the contour generator’s size; furthermore, each values[i + jn] must represent the value at the position ⟨i, j⟩.

    • threshold: number

      Threshold value.

    Returns ContourMultiPolygon

  • Return the expected size of the input values grid, which defaults to [1,1].

    Returns [number, number]

  • Sets the expected size of the input values grid to the contour generator and returns the contour generator.

    Parameters

    • size: [number, number]

      Size of the input values grid specified as an array [n, m] where n is the number of columns in the grid and m is the number of rows; n and m must be positive integers.

    Returns Contours

  • Returns the current smoothing flag, which defaults to true.

    Returns boolean

  • Sets whether or not the generated contour polygons are smoothed using linear interpolation and returns the contour generator.

    Parameters

    • smooth: boolean

      Flag to enable linear interpolation. The default is "true".

    Returns Contours

  • Returns the current threshold generator, which by default implements Sturges’ formula.

    Returns ThresholdCountGenerator<number> | ThresholdNumberArrayGenerator<number>

  • Sets the threshold generator to the specified function or array and returns this contour generator. Thresholds are defined as an array of values [x0, x1, …]. The first generated contour corresponds to the area where the input values are greater than or equal to x0; the second contour corresponds to the area where the input values are greater than or equal to x1, and so on. Thus, there is exactly one generated MultiPolygon geometry object for each specified threshold value; the threshold value is exposed as geometry.value. If a count is specified instead of an array of thresholds, then the input values’ extent will be uniformly divided into approximately count bins; see d3.ticks.

    Parameters

    Returns Contours