{# Chart Macros ============ Reusable chart components using Chart.js with Alpine.js integration. Prerequisites: Add Chart.js CDN to your base template: Usage: {% from 'shared/macros/charts.html' import chart_card, line_chart, bar_chart, doughnut_chart %} {# Line chart in a card #} {{ chart_card('salesChart', 'Monthly Sales', 'line', chart_config) }} {# Standalone bar chart #} {{ bar_chart('ordersChart', chart_data, height='300px') }} #} {# Chart Card ========== A card container with a chart and optional dropdown menu. Parameters: - id: Unique chart ID (used for canvas element) - title: Card title - chart_type: 'line' | 'bar' | 'doughnut' | 'pie' (default: 'line') - height: Chart height (default: '300px') - show_menu: Whether to show dropdown menu (default: true) - subtitle: Optional subtitle text #} {% macro chart_card(id, title, chart_type='line', height='300px', show_menu=true, subtitle=none) %}

{{ title }}

{% if subtitle %}

{{ subtitle }}

{% endif %}
{% if show_menu %}
{{ caller() if caller is defined else '' }}
{% endif %}
{% endmacro %} {# Line Chart ========== A standalone line chart canvas. Parameters: - id: Unique chart ID - height: Chart height (default: '300px') - class_extra: Additional CSS classes #} {% macro line_chart(id, height='300px', class_extra='') %}
{% endmacro %} {# Bar Chart ========= A standalone bar chart canvas. Parameters: - id: Unique chart ID - height: Chart height (default: '300px') - class_extra: Additional CSS classes #} {% macro bar_chart(id, height='300px', class_extra='') %}
{% endmacro %} {# Doughnut Chart ============== A standalone doughnut/pie chart canvas. Parameters: - id: Unique chart ID - size: Chart size (default: '200px') - class_extra: Additional CSS classes #} {% macro doughnut_chart(id, size='200px', class_extra='') %}
{% endmacro %} {# Stats Chart Card ================ A card with a stat value and small sparkline chart. Parameters: - id: Unique chart ID - title: Stat title - value_var: Alpine.js variable for the value - trend_var: Alpine.js variable for trend ('up' | 'down' | 'neutral') - trend_value_var: Alpine.js variable for trend percentage - chart_height: Sparkline height (default: '60px') #} {% macro stats_chart_card(id, title, value_var, trend_var=none, trend_value_var=none, chart_height='60px') %}

{{ title }}

{% if trend_var %} {% endif %}

{% endmacro %} {# Chart Legend ============ A custom chart legend. Parameters: - items: List of legend items [{'label': '', 'color': ''}] - layout: 'horizontal' | 'vertical' (default: 'horizontal') #} {% macro chart_legend(items, layout='horizontal') %}
{% for item in items %}
{{ item.label }}
{% endfor %}
{% endmacro %} {# Chart.js Configuration Helper ============================= JavaScript template for common chart configurations. Include this in a {% endmacro %} {# Example Usage Comment ===================== Copy this to your page to see how to use the chart macros: {% from 'shared/macros/charts.html' import chart_card, chart_config_script %} {{ chart_card('monthlySales', 'Monthly Sales', 'line') }} {{ chart_config_script() }} #}