Tapir.DataHelper (Tapir v0.1.0)
View SourceHelper module for processing Ash resource data into chart-ready format.
This module handles the transformation of data from Ash resources into the format expected by Chart.js for rendering charts.
Summary
Functions
Returns empty chart data structure for error states.
Processes data from an Ash resource for chart rendering.
Transforms a list of data into Chart.js format.
Functions
Returns empty chart data structure for error states.
Processes data from an Ash resource for chart rendering.
Parameters
resource- The Ash resource to queryx_field- Field to use for X-axis/labelsy_field- Field to use for Y-axis/valuesgroup_by- Optional field to group data byquery_params- Additional filters for the queryaggregate_function- How to aggregate data (:count, :sum, :avg, etc.)date_grouping- How to group date fields (:day, :week, :month, :year)chart_type- Type of chart being created
Returns
A map with the structure expected by Chart.js:
%{
labels: ["Label 1", "Label 2", "Label 3"],
datasets: [
%{
label: "Dataset Name",
data: [10, 20, 30],
backgroundColor: ["color1", "color2", "color3"],
borderColor: ["color1", "color2", "color3"],
borderWidth: 1
}
]
}
Transforms a list of data into Chart.js format.
Examples
iex> data = [%{name: "A", value: 10}, %{name: "B", value: 20}]
iex> params = %{x_field: :name, y_field: :value}
iex> Tapir.DataHelper.transform_for_chart(data, params)
%{
labels: ["A", "B"],
datasets: [%{label: "Value", data: [10, 20], ...}]
}