Visualize.Shape (Visualize v0.2.35)

Copy Markdown View Source

Shape generators for creating SVG paths from data.

Provides generators for common chart elements:

  • Lines and areas for time series
  • Arcs for pie and donut charts
  • Symbols for scatter plots
  • Stacks for stacked bar/area charts
  • Bands (state timelines), rules and x-bands (annotations) as element lists
  • Percentile bands (median plus inner and outer bands) as a map of paths
  • Roses (one arc sector per datum over a radial scale) as a list of paths

Examples

# Line chart
line = Visualize.Shape.line()
  |> Visualize.Shape.x(fn d -> scale_x.(d.date) end)
  |> Visualize.Shape.y(fn d -> scale_y.(d.value) end)
  |> Visualize.Shape.curve(:monotone_x)

path_data = Visualize.Shape.generate(line, data)

# Pie chart
pie = Visualize.Shape.pie()
  |> Visualize.Shape.value(:count)

arcs = Visualize.Shape.generate(pie, data)

# Stacked area chart
stack = Visualize.Shape.stack()
  |> Visualize.Shape.keys([:apples, :oranges, :bananas])

series = Visualize.Shape.generate(stack, data)

Summary

Functions

Sets the sector-centre accessor (for roses), in the scale's domain units

Creates a new arc generator

Creates a new area generator

Creates a new band (state timeline) generator

Sets the corner radius (for arcs)

Sets the curve interpolation type

Sets the defined predicate

Sets the end angle (for arcs and pies)

Sets the fill accessor (for bands and x-bands)

Generates output from a shape generator.

Generates a Path struct (for Line, Area, Arc, Symbol, Band), a map of them for PercentileBand, or a list of them for Rose.

Sets the height accessor (for bands)

Sets the inner {lo, hi} band (for percentile bands); nil clears it

Sets the inner radius (for arcs and roses)

Sets the keys for stack generator

Sets the label accessor (for rules and x-bands); nil clears it

Creates a new line generator

Sets the median accessor (for percentile bands); nil clears it

Creates a new needle generator (spec/04 §16)

Sets the offset for stack generator

Sets the order for stack generator

Sets the outer {lo, hi} band (for percentile bands); nil clears it

Sets the outer radius (for arcs and roses)

Sets the pad angle (for arcs, pies and roses)

Sets the pad radius (for arcs)

Creates a new percentile-band generator (spec/04 §14)

Creates a new pie layout generator

Creates a new rose generator (spec/04 §15)

Creates a new rule (vertical annotation) generator

Sets the x scale (for rules and x-bands); nil means pixel values

Sets the symbol size

Sets the data comparator (for pies); nil clears it

Sets the value comparator (for pies); nil clears it

Creates a new stack generator

Sets the start angle (for arcs and pies)

Creates a new symbol generator

Sets the symbol type

Sets the value accessor (for pie and stack)

Sets the sector-width accessor (for roses), in the scale's domain units

Sets the x0 accessor (for areas, bands and x-bands)

Sets the x1 accessor (for areas, bands and x-bands)

Sets the x accessor

Creates a new x-band (shaded interval annotation) generator

Sets the y0 accessor (baseline for areas; extent for rules and x-bands)

Sets the y1 accessor (for areas; extent for rules and x-bands)

Sets the y accessor

Functions

angle(shape, accessor)

Sets the sector-centre accessor (for roses), in the scale's domain units

arc()

Creates a new arc generator

area()

Creates a new area generator

band()

Creates a new band (state timeline) generator

corner_radius(shape, radius)

Sets the corner radius (for arcs)

curve(shape, type, opts \\ [])

Sets the curve interpolation type

defined(shape, pred)

Sets the defined predicate

end_angle(shape, angle)

Sets the end angle (for arcs and pies)

fill(shape, accessor)

Sets the fill accessor (for bands and x-bands)

generate(shape, data \\ nil)

Generates output from a shape generator.

For Line, Area, Arc: returns path data string For Pie: returns list of arc data maps For Symbol: returns path data string For Stack: returns list of series with stacked values For Band, Rule, XBand: returns a list of Visualize.IR.Element For PercentileBand: returns %{outer:, inner:, median:} of path strings For Rose: returns a list of path strings, one per datum

generate_path(shape, data \\ nil)

Generates a Path struct (for Line, Area, Arc, Symbol, Band), a map of them for PercentileBand, or a list of them for Rose.

Use this for backend-agnostic path generation, then render with Visualize.Render.to_string/2 or create an element with Visualize.IR.Element.path/2.

height(shape, accessor)

Sets the height accessor (for bands)

inner(shape, pair)

Sets the inner {lo, hi} band (for percentile bands); nil clears it

inner_radius(shape, radius)

Sets the inner radius (for arcs and roses)

keys(shape, keys)

Sets the keys for stack generator

label(shape, accessor)

Sets the label accessor (for rules and x-bands); nil clears it

line()

Creates a new line generator

median(shape, accessor)

Sets the median accessor (for percentile bands); nil clears it

needle()

Creates a new needle generator (spec/04 §16)

offset(shape, offset)

Sets the offset for stack generator

order(shape, order)

Sets the order for stack generator

outer(shape, pair)

Sets the outer {lo, hi} band (for percentile bands); nil clears it

outer_radius(shape, radius)

Sets the outer radius (for arcs and roses)

pad_angle(shape, angle)

Sets the pad angle (for arcs, pies and roses)

pad_radius(shape, radius)

Sets the pad radius (for arcs)

percentile_band()

Creates a new percentile-band generator (spec/04 §14)

pie()

Creates a new pie layout generator

rose()

Creates a new rose generator (spec/04 §15)

rule()

Creates a new rule (vertical annotation) generator

scale(shape, scale)

Sets the x scale (for rules and x-bands); nil means pixel values

size(shape, size)

Sets the symbol size

sort(shape, comparator)

Sets the data comparator (for pies); nil clears it

sort_values(shape, comparator)

Sets the value comparator (for pies); nil clears it

stack()

Creates a new stack generator

start_angle(shape, angle)

Sets the start angle (for arcs and pies)

symbol()

Creates a new symbol generator

type(shape, type)

Sets the symbol type

value(shape, accessor)

Sets the value accessor (for pie and stack)

width(shape, accessor)

Sets the sector-width accessor (for roses), in the scale's domain units

x0(shape, accessor)

Sets the x0 accessor (for areas, bands and x-bands)

x1(shape, accessor)

Sets the x1 accessor (for areas, bands and x-bands)

x(shape, accessor)

Sets the x accessor

x_band()

Creates a new x-band (shaded interval annotation) generator

y0(shape, accessor)

Sets the y0 accessor (baseline for areas; extent for rules and x-bands)

y1(shape, accessor)

Sets the y1 accessor (for areas; extent for rules and x-bands)

y(shape, accessor)

Sets the y accessor