Lines

detroit.line(x: Accessor[T, float] | None = None, y: Accessor[T, float] | None = None)

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.

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

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

Returns:

New line generator

Return type:

Line

class detroit.shape.line.Line(x: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | None = None, y: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | None = None)

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.

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

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

Returns:

New line generator

Return type:

Line

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

Generate a line for the given list of data

Parameters:

data (Iterable[T]) – Data values

Returns:

Generated line if the line is not associated to a context

Return type:

str | None

Examples

>>> svg.append("path").attr("d", line(data)).attr("stroke", "currentColor")
x(x: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | int | float) Line

Sets x accessor function

Parameters:

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

Returns:

Itself

Return type:

Line

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

Sets y accessor function

Parameters:

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

Returns:

Itself

Return type:

Line

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

Sets defined accessor

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.

Parameters:

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

Returns:

Itself

Return type:

Line

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

Sets curve factory.

Parameters:

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

Returns:

Itself

Return type:

Line

set_context(context: Path | None = None) Line

Sets the context.

Parameters:

context (Path | None) – Path

Returns:

Itself

Return type:

Line