Interface Line<Datum>

The line generator produces a spline or polyline, as in a line chart. Lines also appear in many other visualization types, such as the links in hierarchical edge bundling.

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

interface Line {
    context(): CanvasRenderingContext2D;
    context(context): Line<Datum>;
    curve(): CurveFactory | CurveFactoryLineOnly;
    curve<C>(): C;
    curve(curve): Line<Datum>;
    defined(): ((d, index, data) => boolean);
    defined(defined): Line<Datum>;
    defined(defined): Line<Datum>;
    x(): ((d, index, data) => number);
    x(x): Line<Datum>;
    x(x): Line<Datum>;
    y(): ((d, index, data) => number);
    y(y): Line<Datum>;
    y(y): Line<Datum>;
    (data): string;
    (data): void;
}

Type Parameters

  • Datum

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

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

    Parameters

    • data: Datum[] | Iterable<Datum>

      Array of data elements.

    Returns string

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

    IMPORTANT: If the line generator has been configured with a rendering context, then the line 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 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 line generator.

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

    When a line 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 x and y accessors will subsequently be evaluated and the point will be added to the current line segment. Otherwise, the element will be skipped, the current line segment will be ended, and a new line segment will be generated for the next defined point. As a result, the generated line may have several discrete segments.

    Note that if a line 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 Line<Datum>

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

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

    When a line 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 x and y accessors will subsequently be evaluated and the point will be added to the current line segment. Otherwise, the element will be skipped, the current line segment will be ended, and a new line segment will be generated for the next defined point. As a result, the generated line may have several discrete segments.

    Note that if a line 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 Line<Datum>

  • Returns the current x-coordinate accessor function, which defaults to a function returning first element of a two-element array of numbers.

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

      • (d, index, data): number
      • Returns the current x-coordinate accessor function, which defaults to a function returning first element of a two-element array of numbers.

        Parameters

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

        Returns number

  • Sets the x accessor to the specified number and returns this line generator.

    Parameters

    • x: number

      A constant x-coordinate value.

    Returns Line<Datum>

  • Sets the x accessor to the specified function and returns this line generator.

    When a line is generated, the x accessor will be invoked for each defined element in the input data array.

    The default x accessor assumes that the input data are two-element arrays of numbers. 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)

      A coordinate accessor function which returns the x-coordinate value. The x 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 Line<Datum>

  • Returns the current y-coordinate accessor function, which defaults to a function returning second element of a two-element array of numbers.

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

      • (d, index, data): number
      • Returns the current y-coordinate accessor function, which defaults to a function returning second element of a two-element array of numbers.

        Parameters

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

        Returns number

  • Sets the y accessor to the specified number and returns this line generator.

    Parameters

    • y: number

      A constant y-coordinate value.

    Returns Line<Datum>

  • Sets the y accessor to the specified function and returns this line generator.

    When a line is generated, the y accessor will be invoked for each defined element in the input data array.

    The default y accessor assumes that the input data are two-element arrays of numbers. 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)

      A coordinate accessor function which returns the y-coordinate value. The y 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 Line<Datum>