Interface Symbol<This, Datum>

A symbol generator.

Symbols provide a categorical shape encoding as is commonly used in scatterplots. Symbols are always centered at ⟨0,0⟩; use a transform (see: SVG, Canvas) to move the arc to a different position.

The first generic corresponds to the "this" context within which the symbol generator is invoked. The second generic corresponds to the data type of the datum underlying the symbol.

interface Symbol {
    context(): CanvasRenderingContext2D;
    context(context): Symbol<This, Datum>;
    size(): ((this, d, ...args) => number);
    size(size): Symbol<This, Datum>;
    size(size): Symbol<This, Datum>;
    type(): ((this, d, ...args) => SymbolType);
    type(type): Symbol<This, Datum>;
    type(type): Symbol<This, Datum>;
    (this, d?, ...args): string;
    (this, d?, ...args): void;
}

Type Parameters

  • This

  • Datum

  • Generates a symbol for the given arguments.

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

    The "this" context within which this function is invoked, will be the context within which the accessor methods of the generator are invoked. All arguments passed into this function, will be passed to the accessor functions of the generator.

    For example, with the default settings, no arguments are needed to produce a circle with area 64 square pixels.

    Parameters

    • this: This
    • Optional d: Datum

      The datum for which the symbol is to be generated.

    • Rest ...args: any[]

    Returns string

  • Generates an symbol for the given arguments.

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

    The "this" context within which this function is invoked, will be the context within which the accessor methods of the generator are invoked. All arguments passed into this function, will be passed to the accessor functions of the generator.

    For example, with the default settings, no arguments are needed to produce a circle with area 64 square pixels.

    Parameters

    • this: This
    • Optional d: Datum

      The datum for which the symbol is to be generated.

    • Rest ...args: any[]

    Returns void

Methods

Methods

  • Returns the current size accessor, which defaults to a function returning a constant value of 64.

    Returns ((this, d, ...args) => number)

      • (this, d, ...args): number
      • Returns the current size accessor, which defaults to a function returning a constant value of 64.

        Parameters

        • this: This
        • d: Datum
        • Rest ...args: any[]

        Returns number

  • Sets the size to the specified number and returns this symbol generator.

    Parameters

    • size: number

      A fixed size (area in square pixels).

    Returns Symbol<This, Datum>

  • Sets the size to the specified function and returns this symbol generator.

    Specifying the size as a function is useful for constructing a scatterplot with a size encoding. If you wish to scale the symbol to fit a given bounding box, rather than by area, try SVG’s getBBox.

    Parameters

    • size: ((this, d, ...args) => number)

      An accessor function returning a number to be used as a symbol size. The accessor function is invoked in the same "this" context as the generator was invoked in and receives the same arguments that were passed into the symbol generator.

        • (this, d, ...args): number
        • Parameters

          • this: This
          • d: Datum
          • Rest ...args: any[]

          Returns number

    Returns Symbol<This, Datum>

  • Returns the current symbol type accessor, which defaults to a function returning the circle symbol type.

    Returns ((this, d, ...args) => SymbolType)

      • (this, d, ...args): SymbolType
      • Returns the current symbol type accessor, which defaults to a function returning the circle symbol type.

        Parameters

        • this: This
        • d: Datum
        • Rest ...args: any[]

        Returns SymbolType

  • Sets the symbol type to the specified symbol type and returns this symbol generator.

    Parameters

    Returns Symbol<This, Datum>

  • Sets the symbol type to the specified function and returns this symbol generator.

    Parameters

    • type: ((this, d, ...args) => SymbolType)

      An accessor function returning a symbol type. The accessor function is invoked in the same "this" context as the generator was invoked in and receives the same arguments that were passed into the symbol generator. See symbols for the set of built-in symbol types. To implement a custom symbol type, return an object that implements symbolType.draw.

    Returns Symbol<This, Datum>