Visualize.Shape.Arc (Visualize v0.2.25)

Copy Markdown View Source

Arc generator for creating circular or annular sectors.

Used for pie charts, donut charts, and radial visualizations. The geometry is d3-shape's arc: pad_angle narrows the sector at pad_radius, and corner_radius rounds its four corners with tangent arcs.

Examples

arc = Visualize.Shape.Arc.new()
  |> Visualize.Shape.Arc.inner_radius(50)
  |> Visualize.Shape.Arc.outer_radius(100)
  |> Visualize.Shape.Arc.corner_radius(8)

# Generate from angles
path_data = Visualize.Shape.Arc.generate(arc, %{
  start_angle: 0,
  end_angle: :math.pi() / 2
})

Summary

Functions

The {start, end} angles the arc's accessors give for a datum, for a label fitted to its sector (spec/14 §5.5, #138).

Generates a centroid point for the arc

Sets the corner radius; applied up to half the ring thickness

Sets the end angle accessor

Generates the SVG path data string.

Generates a Path struct

Sets the inner radius

Creates a new arc generator

Sets the outer radius

Sets the pad angle: the sector is narrowed by half of it on each side

Sets the radius at which the pad angle is measured.

The inner and outer radius of the arc for data, {r0, r1} (spec/14 §5.5).

Sets the start angle accessor

Types

accessor()

@type accessor() :: (any() -> number()) | number()

t()

@type t() :: %Visualize.Shape.Arc{
  corner_radius: accessor(),
  end_angle: accessor() | nil,
  inner_radius: accessor(),
  outer_radius: accessor() | nil,
  pad_angle: accessor(),
  pad_radius: accessor() | nil,
  start_angle: accessor() | nil
}

Functions

angles(arc, data)

@spec angles(t(), map() | any()) :: {number(), number()}

The {start, end} angles the arc's accessors give for a datum, for a label fitted to its sector (spec/14 §5.5, #138).

centroid(arc, data)

@spec centroid(t(), map() | any()) :: {number(), number()}

Generates a centroid point for the arc

corner_radius(arc, radius)

@spec corner_radius(t(), accessor()) :: t()

Sets the corner radius; applied up to half the ring thickness

end_angle(arc, angle)

@spec end_angle(t(), accessor()) :: t()

Sets the end angle accessor

generate(arc, data)

@spec generate(t(), map() | any()) :: String.t()

Generates the SVG path data string.

Note: For backend-agnostic usage, prefer generate_path/2 and render with your chosen backend.

generate_path(arc, data)

@spec generate_path(t(), map() | any()) :: Visualize.IR.Path.t()

Generates a Path struct

inner_radius(arc, radius)

@spec inner_radius(t(), accessor()) :: t()

Sets the inner radius

new()

@spec new() :: t()

Creates a new arc generator

outer_radius(arc, radius)

@spec outer_radius(t(), accessor()) :: t()

Sets the outer radius

pad_angle(arc, angle)

@spec pad_angle(t(), accessor()) :: t()

Sets the pad angle: the sector is narrowed by half of it on each side

pad_radius(arc, radius)

@spec pad_radius(t(), accessor() | nil) :: t()

Sets the radius at which the pad angle is measured.

The linear gap the padding opens is pad_radius · pad_angle, kept constant across the ring, so the angular shift is larger on the inner edge than on the outer. nil (the default) uses √(r0² + r1²), as d3 does.

radii(arc, data)

@spec radii(t(), map() | any()) :: {number(), number()}

The inner and outer radius of the arc for data, {r0, r1} (spec/14 §5.5).

start_angle(arc, angle)

@spec start_angle(t(), accessor()) :: t()

Sets the start angle accessor