{%- import '_macros_site.html' as macros_site with context -%} {#- ############################################################################ MACROS FOR RENDERING CHARTS AND TABLES. These macros encapsulate common functionality when generating various charts and tables within the Mentat GUI. There are macros responsible for rendering HTML, all with code reusability in mind. ############################################################################ -#} {%- macro _get_table_agg_footer(data, format_dict={}) %} {%- for table_aggregation in hawat_table_aggregations %} {{ get_icon(table_aggregation.icon_name) }} {{ table_aggregation.name }} {%- for col, val in data.agg(table_aggregation.func).items() %} {{ table_aggregation.format_func(val, format=format_dict.get(col)) }} {%- endfor %} {%- endfor %} {%- endmacro %} {#- Render HTML table based on the timeline chart dataframe. ChartSection chsection: Chart section containing table configuration and data. bool add_agg_footer: Add aggregation footer to the table. bool add_color: Add color to the table cells. (If both chart and table are obtained from the `get_timeline_chart_and_table_data_frame()` function, the colors for each set will match.) -#} {%- macro get_table_timeline(chsection, add_agg_footer=True, add_color=True) %} {%- set data_frame = chsection.data.timeline.df %}{# get pandas DataFrame #} {%- for column in data_frame %} {%- if column == '__SUM__' %} {%- else %} {%- endif %} {%- endfor %} {%- for bucket, row in data_frame.iterrows() %} {%- for val in row %} {%- endfor %} {%- endfor %} {%- if add_agg_footer %} {{ _get_table_agg_footer(data_frame) }} {%- endif %}
{{ _('Date') }}{{ _('Sum') }}{{ column }}
{{ bucket }}{{ babel_format_decimal(val) }}
{%- endmacro %} {#- Render HTML table based on the secondary chart dataframe. ChartSection chsection: Chart section containing table configuration and data. bool add_agg_footer: Add aggregation footer to the table. bool add_color: Add color to the table cells. (If both chart and table are obtained from the `get_timeline_chart_and_table_data_frame()` function, the colors for each set will match.) string csag_group: Name of the CSAG group to render the Context search for. -#} {%- macro get_table_secondary(chsection, add_agg_footer=True, add_color=True, csag_group=None) %} {%- set data_frame = chsection.data.secondary.df %}{# get pandas DataFrame #} {% if '__SHARE__' in data_frame %}{% endif %} {%- for name, row in data_frame.iterrows() %} {%- if '__SHARE__' in row %} {%- endif %} {%- endfor %} {%- if add_agg_footer %} {{ _get_table_agg_footer(data_frame, format_dict={'__SHARE__': '🗙'}) }} {%- endif %}
{{ chsection.column_name }} {{ chsection.value_formats.column_name }}{{ _('Share') }}
{%- if add_color %} {%- endif %} {{ name }} {% if csag_group and name and name not in ('__REST__','__unknown__') %}{{ macros_site.render_widget_csag_any(csag_group, [name], separate_dropdown = True, without_label = True) }}{% endif %} {{ chsection.value_formats.format_function(row['count']) }} {{ babel_format_percent(row['__SHARE__'], format='#,##0.##%') }}
{%- endmacro %} {%- macro _render_chart_download_dropdown(chart_id) %}
{%- endmacro %} {#- Render HTML columns that will contain chart and its related dataset table. string chart_id: Unique identifier of the chart. This will be used for generating all other required unique identifiers. ChartSection chsection: Chart section containing table configuration and data. jinja macro table_macro: Reference to macro for rendering the table. dict table_config: Additional configuration for the table rendering, passed to table_macro. bool scrollable_table: Make the viewport of the dataset table scrollable. -#} {%- macro chart_table_columns(chart_id, chsection, table_macro, table_config = {}, scrollable_table = True) %}
{{ _('Loading...') }}
{{ table_macro(chsection, **table_config) }}
{%- endmacro %} {#- Render HTML columns that will contain chart and its related dataset table, but in this case make the table togglable and hidden by default. string chart_id: Unique identifier of the chart. This will be used for generating all other required unique identifiers. ChartSection chsection: Chart section containing table configuration. pandas.DataFrame table_data_frame: Dataframe containing the table data. jinja macro table_macro: Reference to macro for rendering the table. dict table_config: Additional configuration for the table rendering, passed to table_macro. bool scrollable_table: Make the viewport of the dataset table scrollable. -#} {%- macro chart_table_togglable(chart_id, chsection, table_macro, table_config = {}, scrollable_table = True) %}
{{ _('Loading...') }}
{{ table_macro(chsection, **table_config) }}
{%- endmacro %} {#- ============================================================================ High-level chart rendering macros. ============================================================================ -#} {#- Render content of the chart panel dict charts: Dictionary of chart data to render. dict table_data: Dictionary of table data to render. ChartSection chsection: Chart section to render. string id_prefix: Prefix for all subsequent unique identifiers. bool dynamic: True Iff the current use is being fetched dynamically by the frontend -#} {%- macro render_dashboard_panel_content(chsection, id_prefix, dynamic=False) %} {%- if dynamic and permission_can('developer') %} {{ macros_site.render_sql_queries(sqlqueries, key=chsection.key) }} {{ macros_site.render_timemarks(time_marks, key=chsection.key, show_to_render_time=False) }} {%- endif %} {%- if chsection.data.timeline %} {%- set add_footer = chsection.allow_table_aggregation is none or chsection.allow_table_aggregation %} {{ chart_table_togglable( '{}-timeline'.format(id_prefix), chsection, get_table_timeline, table_config = {'add_agg_footer': add_footer} ) }}
{%- endif %} {%- if chsection.data.secondary %} {{ chart_table_columns( '{}-secondary'.format(id_prefix), chsection, get_table_secondary, table_config = { 'csag_group': chsection.get_csag_group(), 'add_agg_footer': chsection.get_aggregate_table(), 'add_color': chsection.data_complexity.value == 'single' } ) }} {%- endif %} {# Add data to be used when exporting source chart dataset and rendering charts #} {%- if chsection.data.timeline %} {%- endif %} {%- if chsection.data.secondary %} {%- endif %} {%- endmacro %} {#- Render tab panel navigation for common list of IDEA event charts. list chart_sections: List of ChartSection objects to render. string id_prefix: Prefix for all subsequent unique identifiers. render_empty: Render the section even in case the required key does not exist in the data. bool active_first: Highlight the first section as active. string active_section_key: The name of the section that should be active on load (takes precedence over active_first) function get_url_func: function which will return url to redirect to if the section key is not present in charts (useful with render_empty = True) bool include_tag: Include the '#' tag in the tab label. (if False, and tab fetched dynamically, spinner will not be present) bool bold: Make the tab label bold. -#} {%- macro render_dashboard_nav(chart_sections, id_prefix, render_empty = False, active_first = True, active_section_key = None, get_url_func = None, include_tag = True, bold = False) %} {%- set tmp = {'cntr': 0} %} {%- for chsection in chart_sections -%} {%- if chsection.key not in hide_sections and (not only_sections or chsection.key in only_sections) %} {%- if render_empty or chsection.data %} {%- if tmp.update({'cntr': tmp['cntr'] + 1}) %}{%- endif %} {%- endif %} {%- endif %} {%- endfor %} {%- endmacro %} {#- Render tab panels for common list of IDEA event charts. list chart_sections: List of ChartSection objects to render. string id_prefix: Prefix for all subsequent unique identifiers. bool render_empty: Render the section even in case the required key does not exist in the data. bool active_first: Highlight the first section as active. string active_section_key: The name of the section that should be active on load (takes precedence over active_first) -#} {%- macro render_dashboard_panels(chart_sections, id_prefix, render_empty = False, active_first = True, active_section_key = None) %} {%- set tmp = {'cntr': 0} %} {%- for chsection in chart_sections -%} {%- if render_empty or chsection.data %}
{%- if chsection.short_description %}

{{ chsection.short_description }}

{%- endif %} {%- if not chsection.data %} {%- endif %} {%- if chsection.description %}

{{ chsection.description }}

{%- endif %}
{%- if chsection.data %} {{ render_dashboard_panel_content( chsection, '{}-{}'.format(id_prefix, chsection.key)) }} {%- else %}
{{ _('Loading...') }}
{%- endif %}
{%- if tmp.update({'cntr': tmp['cntr'] + 1}) %}{%- endif %}
{%- endif %} {%- endfor %} {%- endmacro %}