AshReports.ChartEngine.ChartData (ash_reports v0.1.0)

Data structure for processed chart data in AshReports Phase 5.1.

Represents chart data in a normalized format suitable for various chart providers while maintaining metadata for internationalization and interactive features.

Summary

Functions

Apply statistical aggregation to the chart data.

Add real-time update capability to chart data.

Filter chart data based on provided criteria.

Create a new ChartData structure from raw data.

Sort chart data by specified field and direction.

Convert chart data to Chart.js compatible format.

Convert chart data to D3.js compatible format.

Convert chart data to Plotly compatible format.

Types

data_type()

@type data_type() ::
  :numeric
  | :categorical
  | :coordinate_pairs
  | :multi_series
  | :time_series
  | :mixed

format_type()

@type format_type() :: :raw | :aggregated | :statistical | :normalized

t()

@type t() :: %AshReports.ChartEngine.ChartData{
  average_value: number() | nil,
  cache_key: String.t() | nil,
  data_type: data_type(),
  datasets: list(),
  date_format: String.t() | nil,
  drill_down_fields: list(),
  errors: list(),
  filterable_fields: list(),
  format_type: format_type(),
  has_gaps: boolean(),
  labels: list(),
  last_updated: DateTime.t() | nil,
  locale: String.t(),
  max_value: number() | nil,
  median_value: number() | nil,
  metadata: term(),
  min_value: number() | nil,
  number_format: String.t() | nil,
  processed_data: list(),
  processing_time_ms: number() | nil,
  raw_data: list() | map(),
  series_count: integer(),
  sortable_fields: list(),
  std_deviation: number() | nil,
  svg: term(),
  text_direction: String.t(),
  time_interval: atom() | nil,
  time_range: {DateTime.t(), DateTime.t()} | nil,
  value_count: integer(),
  warnings: list()
}

Functions

aggregate(chart_data, aggregation_type)

@spec aggregate(t(), atom()) :: t()

Apply statistical aggregation to the chart data.

enable_real_time(chart_data, opts \\ [])

@spec enable_real_time(
  t(),
  keyword()
) :: t()

Add real-time update capability to chart data.

filter(chart_data, criteria)

@spec filter(t(), map()) :: t()

Filter chart data based on provided criteria.

new(raw_data, opts \\ [])

@spec new(
  list() | map(),
  keyword()
) :: t()

Create a new ChartData structure from raw data.

Examples

# Numeric series data
data = ChartData.new([1, 2, 3, 4, 5])

# Coordinate pairs
data = ChartData.new([{1, 10}, {2, 20}, {3, 15}])

# Multi-series data
data = ChartData.new(%{
  "Series A" => [1, 2, 3],
  "Series B" => [4, 5, 6]
})

sort(chart_data, field, direction \\ :asc)

@spec sort(t(), atom(), :asc | :desc) :: t()

Sort chart data by specified field and direction.

to_chartjs_format(chart_data)

@spec to_chartjs_format(t()) :: map()

Convert chart data to Chart.js compatible format.

to_d3_format(chart_data)

@spec to_d3_format(t()) :: list()

Convert chart data to D3.js compatible format.

to_plotly_format(chart_data)

@spec to_plotly_format(t()) :: map()

Convert chart data to Plotly compatible format.