AshDyan.Charts (AshDyan v0.1.0)

Copy Markdown View Source

Turn an AshDyan.Result into chart-library-ready shapes.

AshDyan.run/1 returns a stable labels/series structure. This module maps that structure onto common chart types and serializes it for popular charting libraries, so a client can render a chart without knowing AshDyan's internals.

Chart types

  • :bar — categorical counts / grouped aggregates.
  • :line — time-bucketed series, percentiles, or any ordered axis.
  • :area — like :line but filled (good for cumulative / time series).
  • :pie / :donut — single-series frequency or aggregate breakdowns.
  • :histogram — binned numeric distribution (the :histogram result type).
  • :scatter — (x, y) pairs when a result has exactly two series.

Recommendation

recommend/1 picks a sensible default chart type from the result's type and shape, so a generic UI can render something reasonable without per-call config.

Serialization

  • to_chartjs/2 — returns a Chart.js data/options map (JSON-encodable).
  • to_echarts/2 — returns an ECharts option map (JSON-encodable).

Summary

Functions

Build a chart-ready map for the given chart type.

Pick a default chart type for a result.

Serialize a result to a Chart.js data/options map.

Serialize a result to an ECharts option map.

Types

chart_type()

@type chart_type() :: :bar | :line | :area | :pie | :donut | :histogram | :scatter

Functions

build(result, chart_type)

@spec build(AshDyan.Result.t(), chart_type() | nil) :: map()

Build a chart-ready map for the given chart type.

Returns %{type: chart_type, labels: [...], series: [...], options: %{}}. If chart_type is omitted, recommend/1 is used.

recommend(result)

@spec recommend(AshDyan.Result.t()) :: chart_type()

Pick a default chart type for a result.

  • :frequency:bar (or :pie when there is a single series).
  • :aggregate:bar (or :pie for a single series).
  • :time_bucket:line.
  • :percentile:line.
  • :histogram:histogram.

to_chartjs(result, chart_type \\ nil)

@spec to_chartjs(AshDyan.Result.t(), chart_type() | nil) :: map()

Serialize a result to a Chart.js data/options map.

chart_type is optional (defaults to recommend/1). The returned map is JSON-encodable via Jason.encode!/1.

to_echarts(result, chart_type \\ nil)

@spec to_echarts(AshDyan.Result.t(), chart_type() | nil) :: map()

Serialize a result to an ECharts option map.

chart_type is optional (defaults to recommend/1). The returned map is JSON-encodable via Jason.encode!/1.