Area generator for creating filled areas between two lines.
Useful for area charts, stacked areas, and range visualizations.
Examples
data = [
%{date: ~D[2024-01-01], value: 10},
%{date: ~D[2024-01-02], value: 25},
%{date: ~D[2024-01-03], value: 15}
]
area = Visualize.Shape.Area.new()
|> Visualize.Shape.Area.x(fn d -> scale_x.(d.date) end)
|> Visualize.Shape.Area.y0(fn _d -> height end) # baseline
|> Visualize.Shape.Area.y1(fn d -> scale_y.(d.value) end)
|> Visualize.Shape.Area.curve(:monotone_x)
path_data = Visualize.Shape.Area.generate(area, data)
Summary
Functions
Sets the curve type
Sets the defined predicate: a falsy result breaks the area into separate rings
Generates the SVG path data string.
Generates a Path struct.
Creates a new area generator
Sets the x0 accessor (left edge)
Sets the x1 accessor (right edge)
Sets the x accessor (used for both x0 and x1)
Sets the y0 accessor (bottom edge / baseline)
Sets the y1 accessor (top edge)
Sets the y accessor (used for both y0 and y1)
Types
Functions
@spec curve(t(), Visualize.Shape.Curve.curve_type(), keyword()) :: t()
Sets the curve type
Sets the defined predicate: a falsy result breaks the area into separate rings
@spec generate(t(), Visualize.Data.Table.source()) :: String.t()
Generates the SVG path data string.
Note: For backend-agnostic usage, prefer generate_path/2
and render with your chosen backend.
@spec generate_path(t(), Visualize.Data.Table.source()) :: Visualize.IR.Path.t()
Generates a Path struct.
Each run of consecutive defined data (see defined/2) becomes one closed ring: the top
edge forward, a line to the bottom edge, the bottom edge reversed, and Z. A run of
fewer than two points draws nothing.
@spec new() :: t()
Creates a new area generator
Sets the x0 accessor (left edge)
Sets the x1 accessor (right edge)
Sets the x accessor (used for both x0 and x1)
Sets the y0 accessor (bottom edge / baseline)
Sets the y1 accessor (top edge)
Sets the y accessor (used for both y0 and y1)