{%- 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. pandas.DataFrame data: Dataframe containing the timeline chart data. ChartSection chsection: Chart section containing table configuration. 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(data, chsection, add_agg_footer=True, add_color=True) %} {%- for column in data %} {%- if column == '__SUM__' %} {%- else %} {%- endif %} {%- endfor %} {%- for bucket, row in data.iterrows() %} {%- for val in row %} {%- endfor %} {%- endfor %} {%- if add_agg_footer %} {{ _get_table_agg_footer(data) }} {%- endif %}
{{ _('Date') }}{{ _('Sum') }}{{ column }}
{{ bucket }}{{ babel_format_decimal(val) }}
{%- endmacro %} {#- Render HTML table based on the secondary chart dataframe. pandas.DataFrame data: Dataframe containing the timeline chart data. ChartSection chsection: Chart section containing table configuration. 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(data, chsection, add_agg_footer=True, add_color=True, csag_group=None) %} {% if '__SHARE__' in data %}{% endif %} {%- for name, row in data.iterrows() %} {%- if '__SHARE__' in row %} {%- endif %} {%- endfor %} {%- if add_agg_footer %} {{ _get_table_agg_footer(data, 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. 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_columns(chart_id, chsection, table_data_frame, table_macro, table_config = {}, scrollable_table = True) %}
_('Loading...')
{{ table_macro(table_data_frame, 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_data_frame, table_macro, table_config = {}, scrollable_table = True) %}
_('Loading...')
{{ table_macro(table_data_frame, 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(charts, table_data, chsection, id_prefix, dynamic=False) %} {%- if dynamic and permission_can('power') %} {{ 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 'timeline' in charts[chsection.key] %} {%- set add_footer = chsection.allow_table_aggregation is none or chsection.allow_table_aggregation %} {{ chart_table_togglable( '{}-timeline'.format(id_prefix), chsection, table_data[chsection.key]['timeline'], get_table_timeline, table_config = {'add_agg_footer': add_footer} ) }}
{%- endif %} {%- if 'secondary' in charts[chsection.key] %} {%- set add_color = chsection.data_complexity.value == 'single' %} {%- set add_footer = (chsection.allow_table_aggregation is none and add_color) or chsection.allow_table_aggregation %} {{ chart_table_columns( '{}-secondary'.format(id_prefix), chsection, table_data[chsection.key]['secondary'], get_table_secondary, table_config = { 'csag_group': chsection.csag_group or chsection.key, 'add_agg_footer': add_footer, 'add_color': add_color } ) }} {%- endif %} {# Add data to be used when exporting source chart dataset #} {%- if 'timeline' in table_data[chsection.key] %} {%- endif %} {%- if 'secondary' in table_data[chsection.key] %} {%- endif %} {%- if dynamic %} {# Add required json of charts to be parsed. If the tab is not fetched dynamically, the data will be already present in `charts`. #} {%- if 'timeline' in charts[chsection.key] %} {%- endif %} {%- if 'secondary' in charts[chsection.key] %} {%- endif %} {%- endif %} {%- endmacro %} {#- Render tab panel navigation for common list of IDEA event charts. dict charts: Dictionary of chart data to render. This structure will be inspected during rendering whether it contains required subkeys. 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) string grp_key: Group key to pass to javascript in case the charts variable does not contain the data directly but stored under this key. (useful when the site would contain the same chart section key more than once) 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(charts, chart_sections, id_prefix, render_empty = False, active_first = True, active_section_key = None, get_url_func = None, grp_key = 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 chsection.key in charts or render_empty %} {%- if tmp.update({'cntr': tmp['cntr'] + 1}) %}{%- endif %} {%- endif %} {%- endif %} {%- endfor %} {%- endmacro %} {#- Render tab panels for common list of IDEA event charts. dict charts: Dictionary of chart data to render. This structure will be inspected during rendering whether it contains required subkeys. dict table_data: Dictionary of table data to render. string id_prefix: Prefix for all subsequent unique identifiers. list chart_sections: List of ChartSection objects to render. 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(charts, table_data, id_prefix, chart_sections, render_empty = False, active_first = True, active_section_key = None) %} {%- set tmp = {'cntr': 0} %} {%- for chsection in chart_sections -%} {%- if chsection.key in charts or render_empty %}
{%- if chsection.short_description %}

{{ chsection.short_description }}

{%- endif %} {%- if chsection.key not in charts %} {%- endif %} {%- if chsection.description %}

{{ chsection.description }}

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