Areas

detroit.area(x0: Accessor[T, float] | None = None, y0: Accessor[T, float] | None = None, y1: Accessor[T, float] | None = None)

The area generator produces an area defined by a topline and a baseline as in an area chart. 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 y scale’s output for zero). The topline is defined by x1 and y1 and is rendered first; 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. See also radial areas.

Parameters:
  • x0 (Accessor[T, float] | None) – x0 accessor function for data points

  • y0 (Accessor[T, float] | None) – y0 accessor function for data points

  • y1 (Accessor[T, float] | None) – y1 accessor function for data points

Returns:

New area generator

Return type:

Area

class detroit.shape.area.Area(x0: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | None = None, y0: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | None = None, y1: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | None = None)

The area generator produces an area defined by a topline and a baseline as in an area chart. 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 y scale’s output for zero). The topline is defined by x1 and y1 and is rendered first; 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. See also radial areas.

Parameters:
  • x0 (Accessor[T, float] | None) – x0 accessor function for data points

  • y0 (Accessor[T, float] | None) – y0 accessor function for data points

  • y1 (Accessor[T, float] | None) – y1 accessor function for data points

Returns:

New area generator

Return type:

Area

__call__(data: Iterable[T]) str | None

Generates an area for the given array of data.

Parameters:

data (Iterable[T]) – Data values

Returns:

Generated area if the area is not associated to a context

Return type:

str | None

Examples

>>> svg.append("path").attr("d", area(data))
x(x: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | int | float) Area

Sets x0 accessor function and sets x1 accessor function to None

Parameters:

x (Accessor[T, float] | Number) – x accessor function

Returns:

Itself

Return type:

Area

x0(x0: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | int | float) Area

Sets x0 accessor function

Parameters:

x0 (Accessor[T, float] | Number) – x0 accessor function

Returns:

Itself

Return type:

Area

x1(x1: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | int | float) Area

Sets x1 accessor function

Parameters:

x1 (Accessor[T, float] | Number) – x1 accessor function

Returns:

Itself

Return type:

Area

y(y: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | int | float) Area

Sets y0 accessor function and sets y1 accessor function to None

Parameters:

y (Accessor[T, float] | Number) – y accessor function

Returns:

Itself

Return type:

Area

y0(y0: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | int | float) Area

Sets y accessor function

Parameters:

y0 (Accessor[T, float] | Number) – y0 accessor function

Returns:

Itself

Return type:

Area

y1(y1: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | int | float) Area

Sets y accessor function

Parameters:

y1 (Accessor[T, float] | Number) – y1 accessor function

Returns:

Itself

Return type:

Area

area_line() Line

Returns a new line generator from the definition of the area.

Returns:

Line generator based on the area parameters

Return type:

Line

line_x0() Line

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 generator based on the area parameters

Return type:

Line

line_y0() Line

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 generator based on the area parameters

Return type:

Line

line_x1() Line

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 generator based on the area parameters

Return type:

Line

line_y1() Line

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 generator based on the area parameters

Return type:

Line

set_defined(defined: Callable[[T], bool] | Callable[[T, int], bool] | Callable[[T, int, list[Element]], bool] | int | float) Area

Sets defined accessor

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.

Parameters:

defined (Accessor[T, bool] | Number) – defined accessor function

Returns:

Itself

Return type:

Area

set_curve(curve: Callable[[Path], Curve] | None = None) Area

Sets curve factory.

Parameters:

curve (Callable[[Path], Curve] | None) – Curve factory function

Returns:

Itself

Return type:

Area

set_context(context: Path | None = None) Area

Sets the context.

Parameters:

context (Path | None) – Path

Returns:

Itself

Return type:

Area