<commit_before>- extends "smartmin/base.html"
- load smartmin i18n

- block pre-content

  {% include 'polls/poll_header.haml' with poll=object %}

- block content

  .
    - if not request.region
      - trans "Charts only include data from non-regional issues"

    .pull-away
      %form.form-inline{ method:"get" }
        %label.control-label{ for:"window-select" }
        - trans "Show"
        %select.form-control{ id:"window-select", name:"window", onchange:"onChartWindowChange(this)" }
          - for win in window_options
            - if win == window
              %option{ value:"{{ win.name }}", selected:"selected" }
                {{ win.label }}
            - else
              %option{ value:"{{ win.name }}" }
                {{ win.label }}


  - for question in questions
    %h3
      {{ question.order }}. {{ question.text }}

    .chart{ data-chart-type:"trend", data-question-id:"{{ question.pk }}", data-window-min:"{{ window_min }}", data-window-max:"{{ window_max }}" }

    %script{ type:"text/javascript" }
      var chart_{{ question.pk }}_series = {{ question.chart_data }};


- block extra-script
  :javascript
    $(function() {
      $('.chart').each(function() {
        var container = $(this);
        var chart_type = container.data('chart-type');
        var question_id = container.data('question-id');
        var window_min = container.data('window-min');
        var window_max = container.data('window-max');
        var series = eval('chart_' + question_id + '_series');

        if (series && series.length > 0) {
          if (chart_type == 'trend') {
            init_chart_trend(container, series, window_min, window_max);
          }
        }
        else {
          init_chart_nodata(container);
        }
      });
    });

    function init_chart_trend(container, series, window_min, window_max) {
      container.highcharts({
        chart: { type: 'area' },
        title: null,
        xAxis: {
            type: 'datetime',
            title: { enabled: false },
            min: window_min,
            max: window_max
        },
        yAxis: {
            title: {
                text: 'Percent'
            }
        },
        tooltip: {
            pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.percentage:.1f}%</b> ({point.y:,.0f})<br/>',
            shared: true
        },
        plotOptions: {
            area: {
                stacking: 'percent',
                lineColor: '#ffffff',
                lineWidth: 1,
                marker: {
                    lineWidth: 1,
                    lineColor: '#ffffff'
                }
            }
        },
        series: series,
        credits: { enabled: false }
      });
    }

    function init_chart_nodata(container) {
      container.addClass('chart-no-data');
      container.text("No data")
    }

    function onChartWindowChange(ctrl) {
      ctrl.form.submit();
    }

- block extra-style
    {{ block.super }}
    :css<commit_msg>Fixed date format in chart tooltips<commit_after>- extends "smartmin/base.html"
- load smartmin i18n

- block pre-content

  {% include 'polls/poll_header.haml' with poll=object %}

- block content

  .
    - if not request.region
      - trans "Charts only include data from non-regional issues"

    .pull-away
      %form.form-inline{ method:"get" }
        %label.control-label{ for:"window-select" }
        - trans "Show"
        %select.form-control{ id:"window-select", name:"window", onchange:"onChartWindowChange(this)" }
          - for win in window_options
            - if win == window
              %option{ value:"{{ win.name }}", selected:"selected" }
                {{ win.label }}
            - else
              %option{ value:"{{ win.name }}" }
                {{ win.label }}


  - for question in questions
    %h3
      {{ question.order }}. {{ question.text }}

    .chart{ data-chart-type:"trend", data-question-id:"{{ question.pk }}", data-window-min:"{{ window_min }}", data-window-max:"{{ window_max }}" }

    %script{ type:"text/javascript" }
      var chart_{{ question.pk }}_series = {{ question.chart_data }};


- block extra-script
  :javascript
    $(function() {
      $('.chart').each(function() {
        var container = $(this);
        var chart_type = container.data('chart-type');
        var question_id = container.data('question-id');
        var window_min = container.data('window-min');
        var window_max = container.data('window-max');
        var series = eval('chart_' + question_id + '_series');

        if (series && series.length > 0) {
          if (chart_type == 'trend') {
            init_chart_trend(container, series, window_min, window_max);
          }
        }
        else {
          init_chart_nodata(container);
        }
      });
    });

    function init_chart_trend(container, series, window_min, window_max) {
      container.highcharts({
        chart: { type: 'area' },
        title: null,
        xAxis: {
            type: 'datetime',
            title: { enabled: false },
            min: window_min,
            max: window_max
        },
        yAxis: {
            title: {
                text: 'Percent'
            }
        },
        tooltip: {
            xDateFormat: '%b %d, %Y',
            pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.percentage:.1f}%</b> ({point.y:,.0f})<br/>',
            shared: true
        },
        plotOptions: {
            area: {
                stacking: 'percent',
                lineColor: '#ffffff',
                lineWidth: 1,
                marker: {
                    lineWidth: 1,
                    lineColor: '#ffffff'
                }
            }
        },
        series: series,
        credits: { enabled: false }
      });
    }

    function init_chart_nodata(container) {
      container.addClass('chart-no-data');
      container.text("No data")
    }

    function onChartWindowChange(ctrl) {
      ctrl.form.submit();
    }

- block extra-style
    {{ block.super }}
    :css
{'fraction_non_alphanumeric': 0.1464215364412344, 'fraction_numerical': 0.0026263952724885093, 'mean_word_length': 1.7745901639344261, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2206174', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1739, 'n_words': 360}