Interface Pie<This, Datum>

The pie generator does not produce a shape directly, but instead computes the necessary angles to represent a tabular dataset as a pie or donut chart; these angles can then be passed to an arc generator.

The first generic corresponds to the type of the "this" context within which the pie generator and its accessor functions will be invoked.

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

interface Pie {
    endAngle(): ((this, data, ...args) => number);
    endAngle(angle): Pie<This, Datum>;
    endAngle(angle): Pie<This, Datum>;
    padAngle(): ((this, data, ...args) => number);
    padAngle(angle): Pie<This, Datum>;
    padAngle(angle): Pie<This, Datum>;
    sort(): ((a, b) => number);
    sort(comparator): Pie<This, Datum>;
    sort(comparator): Pie<This, Datum>;
    sortValues(): ((a, b) => number);
    sortValues(comparator): Pie<This, Datum>;
    startAngle(): ((this, data, ...args) => number);
    startAngle(angle): Pie<This, Datum>;
    startAngle(angle): Pie<This, Datum>;
    value(): ((d, i, data) => number);
    value(value): Pie<This, Datum>;
    value(value): Pie<This, Datum>;
    (this, data, ...args): PieArcDatum<Datum>[];
}

Type Parameters

  • This

  • Datum

  • Generates a pie for the given array of data, returning an array of objects representing each datum’s arc angles. Any additional arguments are arbitrary; they are simply propagated to the pie generator’s accessor functions along with the this object. The length of the returned array is the same as data, and each element i in the returned array corresponds to the element i in the input data.

    This representation is designed to work with the arc generator’s default startAngle, endAngle and padAngle accessors. The angular units are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator, you should specify angles in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.

    Parameters

    • this: This
    • data: Datum[]

      Array of data elements.

    • Rest ...args: any[]

    Returns PieArcDatum<Datum>[]

Methods

  • Returns the current end angle accessor, which defaults to a function returning a constant 2*pi.

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

      • (this, data, ...args): number
      • Returns the current end angle accessor, which defaults to a function returning a constant 2*pi.

        Parameters

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

        Returns number

  • Sets the overall end angle of the pie to the specified number and returns this pie generator.

    The default end angle is 2*pi.

    The end angle here means the overall end angle of the pie, i.e., the end angle of the last arc. The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator, you should specify an angle in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.

    The value of the end angle is constrained to startAngle ± τ, such that |endAngle - startAngle| ≤ τ.

    Parameters

    • angle: number

      A constant angle.

    Returns Pie<This, Datum>

  • Sets the overall end angle of the pie to the specified function and returns this pie generator.

    The default end angle is 2*pi.

    The end angle here means the overall end angle of the pie, i.e., the end angle of the last arc. The end angle accessor is invoked once, being passed the same arguments and this context as the pie generator. The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator, you should specify an angle in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.

    The value of the end angle is constrained to startAngle ± τ, such that |endAngle - startAngle| ≤ τ.

    Parameters

    • angle: ((this, data, ...args) => number)

      An angle accessor function, which is invoked once, being passed the same arguments and this context as the pie generator.

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

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

          Returns number

    Returns Pie<This, Datum>

  • Returns the current pad angle accessor, which defaults to a function returning a constant zero.

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

      • (this, data, ...args): number
      • Returns the current pad angle accessor, which defaults to a function returning a constant zero.

        Parameters

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

        Returns number

  • Sets the pad angle to the specified number and returns this pie generator.

    The pad angle here means the angular separation between each adjacent arc. The total amount of padding reserved is the specified angle times the number of elements in the input data array, and at most |endAngle - startAngle|; the remaining space is then divided proportionally by value such that the relative area of each arc is preserved. The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator, you should specify an angle in radians.

    Parameters

    • angle: number

      A constant angle.

    Returns Pie<This, Datum>

  • Sets the pad angle to the specified function and returns this pie generator.

    The pad angle here means the angular separation between each adjacent arc. The total amount of padding reserved is the specified angle times the number of elements in the input data array, and at most |endAngle - startAngle|; the remaining space is then divided proportionally by value such that the relative area of each arc is preserved. The pad angle accessor is invoked once, being passed the same arguments and this context as the pie generator. The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator, you should specify an angle in radians.

    Parameters

    • angle: ((this, data, ...args) => number)

      An angle accessor function, which is invoked once, being passed the same arguments and this context as the pie generator.

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

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

          Returns number

    Returns Pie<This, Datum>

  • Returns the current data comparator, which defaults to null.

    Returns ((a, b) => number)

      • (a, b): number
      • Parameters

        • a: Datum
        • b: Datum

        Returns number

  • Sets the data comparator to the specified function and returns this pie generator.

    If both the data comparator and the value comparator are null, then arcs are positioned in the original input order. Otherwise, the data is sorted according to the data comparator, and the resulting order is used. Setting the data comparator implicitly sets the value comparator to null.

    Sorting does not affect the order of the generated arc array which is always in the same order as the input data array; it merely affects the computed angles of each arc. The first arc starts at the start angle and the last arc ends at the end angle.

    Parameters

    • comparator: ((a, b) => number)

      A compare function takes two arguments a and b, each elements from the input data array. If the arc for a should be before the arc for b, then the comparator must return a number less than zero; if the arc for a should be after the arc for b, then the comparator must return a number greater than zero; returning zero means that the relative order of a and b is unspecified.

        • (a, b): number
        • Parameters

          • a: Datum
          • b: Datum

          Returns number

    Returns Pie<This, Datum>

  • Sets the data comparator to null and returns this pie generator.

    If both the data comparator and the value comparator are null, then arcs are positioned in the original input order.

    Parameters

    • comparator: null

      null, to set the pie generator to use the original input order or use the sortValues comparator, if any.

    Returns Pie<This, Datum>

  • Returns the current value comparator, which defaults to descending value.

    Returns ((a, b) => number)

      • (a, b): number
      • Parameters

        • a: number
        • b: number

        Returns number

  • Sets the value comparator to the specified function and returns this pie generator.

    If both the data comparator and the value comparator are null, then arcs are positioned in the original input order. Otherwise, the data is sorted according to the data comparator, and the resulting order is used. Setting the value comparator implicitly sets the data comparator to null.

    The value comparator is similar to the data comparator, except the two arguments a and b are values derived from the input data array using the value accessor, not the data elements. If the arc for a should be before the arc for b, then the comparator must return a number less than zero; if the arc for a should be after the arc for b, then the comparator must return a number greater than zero; returning zero means that the relative order of a and b is unspecified.

    Parameters

    • comparator: ((a, b) => number)
        • (a, b): number
        • Parameters

          • a: number
          • b: number

          Returns number

    Returns Pie<This, Datum>

  • Returns the current start angle accessor, which defaults to a function returning a constant zero.

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

      • (this, data, ...args): number
      • Returns the current start angle accessor, which defaults to a function returning a constant zero.

        Parameters

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

        Returns number

  • Sets the overall start angle of the pie to the specified number and returns this pie generator.

    The default start angle is zero.

    The start angle here means the overall start angle of the pie, i.e., the start angle of the first arc. The start angle accessor is invoked once, being passed the same arguments and this context as the pie generator. The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator, you should specify an angle in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.

    Parameters

    • angle: number

      A constant angle.

    Returns Pie<This, Datum>

  • Sets the overall start angle of the pie to the specified function and returns this pie generator.

    The default start angle is zero.

    The start angle here means the overall start angle of the pie, i.e., the start angle of the first arc. The start angle accessor is invoked once, being passed the same arguments and this context as the pie generator. The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator, you should specify an angle in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.

    Parameters

    • angle: ((this, data, ...args) => number)

      An angle accessor function, which is invoked once, being passed the same arguments and this context as the pie generator.

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

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

          Returns number

    Returns Pie<This, Datum>

  • Returns the current value accessor, which defaults to a function returning the first argument passed into it. The default value accessor assumes that the input data are numbers, or that they are coercible to numbers using valueOf.

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

      • (d, i, data): number
      • Returns the current value accessor, which defaults to a function returning the first argument passed into it. The default value accessor assumes that the input data are numbers, or that they are coercible to numbers using valueOf.

        Parameters

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

        Returns number

  • Sets the value accessor to use the specified constant number and returns this pie generator.

    Parameters

    • value: number

      Constant value to be used.

    Returns Pie<This, Datum>

  • Sets the value accessor to use the specified function and returns this pie generator.

    When a pie is generated, the value accessor will be invoked for each element in the input data array. The default value accessor assumes that the input data are numbers, or that they are coercible to numbers using valueOf. If your data are not simply numbers, then you should specify an accessor that returns the corresponding numeric value for a given datum.

    Parameters

    • value: ((d, i, data) => number)

      A value accessor function, which is invoked for each element in the input data array, being passed the element d, the index i, and the array data as three arguments. It returns a numeric value.

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

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

          Returns number

    Returns Pie<This, Datum>