Interface Area<Datum>

The area generator produces an area, as in an area chart. An area is defined by two bounding lines, either splines or polylines. Typically, the two lines share the same x-values (x0 = x1), differing only in y-value (y0 and y1); most commonly, y0 is defined as a constant representing zero. The first line (the topline) is defined by x1 and y1 and is rendered first; the second line (the baseline) is defined by x0 and y0 and is rendered second, with the points in reverse order. With a curveLinear curve, this produces a clockwise polygon.

The generic refers to the data type of an element in the input array passed into the area generator.

interface Area {
    context(): CanvasRenderingContext2D;
    context(context): Area<Datum>;
    curve(): CurveFactory;
    curve<C>(): C;
    curve(curve): Area<Datum>;
    defined(): ((d, index, data) => boolean);
    defined(defined): Area<Datum>;
    defined(defined): Area<Datum>;
    lineX0(): Line<Datum>;
    lineX1(): Line<Datum>;
    lineY0(): Line<Datum>;
    lineY1(): Line<Datum>;
    x(): ((d, index, data) => number);
    x(x): Area<Datum>;
    x(x): Area<Datum>;
    x0(): ((d, index, data) => number);
    x0(x): Area<Datum>;
    x0(x): Area<Datum>;
    x1(): ((d, index, data) => number);
    x1(x): Area<Datum>;
    x1(x): Area<Datum>;
    y(): ((d, index, data) => number);
    y(y): Area<Datum>;
    y(y): Area<Datum>;
    y0(): ((d, index, data) => number);
    y0(y): Area<Datum>;
    y0(y): Area<Datum>;
    y1(): ((d, index, data) => number);
    y1(y): Area<Datum>;
    y1(y): Area<Datum>;
    (data): string;
    (data): void;
}

Type Parameters

  • Datum

  • Generates an area for the given array of data. Depending on this area generator’s associated curve, the given input data may need to be sorted by x-value before being passed to the area generator.

    IMPORTANT: If the rendering context of the area generator is null, then the area is returned as a path data string.

    Parameters

    • data: Datum[] | Iterable<Datum>

      Array of data elements.

    Returns string

  • Generates an area for the given array of data. Depending on this area generator’s associated curve, the given input data may need to be sorted by x-value before being passed to the area generator.

    IMPORTANT: If the area generator has been configured with a rendering context, then the area is rendered to this context as a sequence of path method calls and this function returns void.

    Parameters

    • data: Datum[] | Iterable<Datum>

      Array of data elements.

    Returns void

Methods

  • Returns the current curve factory, which defaults to curveLinear.

    Returns CurveFactory

  • Returns the current curve factory, which defaults to curveLinear.

    The generic allows to cast the curve factory to a specific type, if known.

    Type Parameters

    Returns C

  • Sets the curve factory and returns this area generator.

    Parameters

    Returns Area<Datum>

  • Returns the current defined accessor, which defaults to a function returning a constant boolean value of true.

    Returns ((d, index, data) => boolean)

      • (d, index, data): boolean
      • Returns the current defined accessor, which defaults to a function returning a constant boolean value of true.

        Parameters

        • d: Datum
        • index: number
        • data: Datum[]

        Returns boolean

  • Sets the defined accessor to the specified boolean and returns this area generator.

    The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined. When an area is generated, the defined accessor will be invoked for each element in the input data array, being passed the element d, the index i, and the array data as three arguments. If the given element is defined (i.e., if the defined accessor returns a truthy value for this element), the x0, x1, y0 and y1 accessors will subsequently be evaluated and the point will be added to the current area segment. Otherwise, the element will be skipped, the current area segment will be ended, and a new area segment will be generated for the next defined point. As a result, the generated area may have several discrete segments.

    Note that if an area segment consists of only a single point, it may appear invisible unless rendered with rounded or square line caps. In addition, some curves such as curveCardinalOpen only render a visible segment if it contains multiple points.

    Parameters

    • defined: boolean

      A boolean constant.

    Returns Area<Datum>

  • Sets the defined accessor to the specified function and returns this area generator.

    The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined.

    The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined. When an area is generated, the defined accessor will be invoked for each element in the input data array, being passed the element d, the index i, and the array data as three arguments. If the given element is defined (i.e., if the defined accessor returns a truthy value for this element), the x0, x1, y0 and y1 accessors will subsequently be evaluated and the point will be added to the current area segment. Otherwise, the element will be skipped, the current area segment will be ended, and a new area segment will be generated for the next defined point. As a result, the generated area may have several discrete segments.

    Note that if an area segment consists of only a single point, it may appear invisible unless rendered with rounded or square line caps. In addition, some curves such as curveCardinalOpen only render a visible segment if it contains multiple points.

    Parameters

    • defined: ((d, index, data) => boolean)

      An accessor function which returns a boolean value. The accessor will be invoked for each defined element in the input data array, being passed the element d, the index i, and the array data as three arguments.

        • (d, index, data): boolean
        • Parameters

          • d: Datum
          • index: number
          • data: Datum[]

          Returns boolean

    Returns Area<Datum>

  • Returns a new line generator that has this area generator’s current defined accessor, curve and context. The line’s x-accessor is this area’s x0-accessor, and the line’s y-accessor is this area’s y0-accessor.

    Returns Line<Datum>

  • Returns a new line generator that has this area generator’s current defined accessor, curve and context. The line’s x-accessor is this area’s x1-accessor, and the line’s y-accessor is this area’s y0-accessor.

    Returns Line<Datum>

  • Returns a new line generator that has this area generator’s current defined accessor, curve and context. The line’s x-accessor is this area’s x0-accessor, and the line’s y-accessor is this area’s y0-accessor.

    Returns Line<Datum>

  • Returns a new line generator that has this area generator’s current defined accessor, curve and context. The line’s x-accessor is this area’s x0-accessor, and the line’s y-accessor is this area’s y1-accessor.

    Returns Line<Datum>

  • Returns the current x0 accessor. The default x0 accessor is a function returning the first element of a two-element array of numbers.

    Returns ((d, index, data) => number)

      • (d, index, data): number
      • Returns the current x0 accessor. The default x0 accessor is a function returning the first element of a two-element array of numbers.

        Parameters

        • d: Datum
        • index: number
        • data: Datum[]

        Returns number

  • Sets x0 to a constant number x and x1 to null and returns this area generator.

    Setting x1 to null indicates that the previously-computed x0 value should be reused for the x1 value.

    Parameters

    • x: number

      A constant value to be used for x0.

    Returns Area<Datum>

  • Sets x0 to the specified function x and x1 to null and returns this area generator.

    The default x0 accessor assumes that the input data are two-element arrays of numbers and returns the first element. If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.

    Parameters

    • x: ((d, index, data) => number)

      An accessor function returning a value to be used for x0. The accessor will be invoked for each defined element in the input data array, being passed the element d, the index i, and the array data as three arguments.

        • (d, index, data): number
        • Parameters

          • d: Datum
          • index: number
          • data: Datum[]

          Returns number

    Returns Area<Datum>

  • Returns the current x0 accessor. The default x0 accessor is a function returning the first element of a two-element array of numbers.

    Returns ((d, index, data) => number)

      • (d, index, data): number
      • Returns the current x0 accessor. The default x0 accessor is a function returning the first element of a two-element array of numbers.

        Parameters

        • d: Datum
        • index: number
        • data: Datum[]

        Returns number

  • Sets x0 to a constant number and returns this area generator.

    Parameters

    • x: number

      A constant value.

    Returns Area<Datum>

  • Sets x0 to the specified function and returns this area generator.

    The default x0 accessor assumes that the input data are two-element arrays of numbers and returns the first element. If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.

    Parameters

    • x: ((d, index, data) => number)

      An accessor function returning a value to be used for x0. The accessor will be invoked for each defined element in the input data array, being passed the element d, the index i, and the array data as three arguments.

        • (d, index, data): number
        • Parameters

          • d: Datum
          • index: number
          • data: Datum[]

          Returns number

    Returns Area<Datum>

  • Returns the current x1 accessor, which defaults to null, indicating that the previously-computed x0 value should be reused for the x1 value.

    Returns ((d, index, data) => number)

      • (d, index, data): number
      • Parameters

        • d: Datum
        • index: number
        • data: Datum[]

        Returns number

  • Sets the x1 accessor to the specified number and returns this area generator.

    Parameters

    • x: number

    Returns Area<Datum>

  • Sets x1 to the specified function and returns this area generator.

    The default x1 accessor is null, indicating that the previously-computed x0 value should be reused for the x1 value. If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.

    Parameters

    • x: ((d, index, data) => number)

      An accessor function returning a value to be used for x1. The accessor will be invoked for each defined element in the input data array, being passed the element d, the index i, and the array data as three arguments.

        • (d, index, data): number
        • Parameters

          • d: Datum
          • index: number
          • data: Datum[]

          Returns number

    Returns Area<Datum>

  • Returns the current y0 accessor. The default y0 accessor is a function returning a constant value of zero.

    Returns ((d, index, data) => number)

      • (d, index, data): number
      • Returns the current y0 accessor. The default y0 accessor is a function returning a constant value of zero.

        Parameters

        • d: Datum
        • index: number
        • data: Datum[]

        Returns number

  • Sets y0 to a constant number y and y1 to null and returns this area generator.

    Setting y1 to null indicates that the previously-computed y0 value should be reused for the y1 value.

    Parameters

    • y: number

      A constant value to be used for y0.

    Returns Area<Datum>

  • Sets y0 to the accessor function y and y1 to null and returns this area generator.

    The default y0 accessor returns a constant value of zero. If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.

    Parameters

    • y: ((d, index, data) => number)

      An accessor function returning a value to be used for y0. The accessor will be invoked for each defined element in the input data array, being passed the element d, the index i, and the array data as three arguments.

        • (d, index, data): number
        • Parameters

          • d: Datum
          • index: number
          • data: Datum[]

          Returns number

    Returns Area<Datum>

  • Returns the current y0 accessor. The default y0 accessor is a function a constant value of zero.

    Returns ((d, index, data) => number)

      • (d, index, data): number
      • Returns the current y0 accessor. The default y0 accessor is a function a constant value of zero.

        Parameters

        • d: Datum
        • index: number
        • data: Datum[]

        Returns number

  • Sets y0 to a constant number and returns this area generator.

    Parameters

    • y: number

      A constant value.

    Returns Area<Datum>

  • Sets y0 to the specified function and returns this area generator.

    The default y0 accessor is a function which returns a constant value of zero. If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.

    Parameters

    • y: ((d, index, data) => number)

      An accessor function returning a value to be used for y0. The accessor will be invoked for each defined element in the input data array, being passed the element d, the index i, and the array data as three arguments.

        • (d, index, data): number
        • Parameters

          • d: Datum
          • index: number
          • data: Datum[]

          Returns number

    Returns Area<Datum>

  • Returns the current y1 accessor or null. The default y1 accessor is a function returning the second element of a two-element array of numbers.

    If the y1 accessor is null, the previously-computed y0 value is reused for the y1 value.

    Returns ((d, index, data) => number)

      • (d, index, data): number
      • Parameters

        • d: Datum
        • index: number
        • data: Datum[]

        Returns number

  • sets the y1 accessor to the specified number and returns this area generator.

    Parameters

    • y: number

    Returns Area<Datum>

  • Sets y1 to the specified function and returns this area generator.

    The default y1 accessor assumes that the input data are two-element arrays of numbers and returns the second element. If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.

    Parameters

    • y: ((d, index, data) => number)

      An accessor function returning a value to be used for y1. The accessor will be invoked for each defined element in the input data array, being passed the element d, the index i, and the array data as three arguments.

        • (d, index, data): number
        • Parameters

          • d: Datum
          • index: number
          • data: Datum[]

          Returns number

    Returns Area<Datum>