Barograph.Barogram (barograph v0.1.0)

Copy Markdown View Source

Renders query results as SVG — a barogram is the trace a barograph produces (spec §11).

SVG, not PNG: no image encoder, no NIF, no headless browser; text output that diffs efficiently over a LiveView websocket and is CSS-themeable by the host application. Elements carry barogram-* classes; the line itself strokes currentColor.

v0.1 scope is the line chart. Area, step, scatter, and legends are v0.5 (spec §11.3).

Summary

Types

A point map as returned by Barograph.query/3 (%{bucket, value} or %{ts, value}).

Functions

Renders a list of query-result points as an SVG line chart string.

Types

point()

@type point() :: %{
  optional(:bucket) => number(),
  optional(:ts) => number(),
  value: number()
}

A point map as returned by Barograph.query/3 (%{bucket, value} or %{ts, value}).

Functions

svg(points, opts \\ [])

@spec svg(
  [point()],
  keyword()
) :: String.t()

Renders a list of query-result points as an SVG line chart string.

Points are maps with a :value and either a :bucket or :ts key — exactly what Barograph.query/3 returns, so results pipe straight in.

Options

  • :width - viewBox width (default 800)
  • :height - viewBox height (default 200)
  • :style - only :line for now (area/step/scatter are v0.5)

Points beyond 500 are rendered without per-point hover titles to keep the document small.