<commit_before>{% extends 'OroDashboardBundle:Dashboard:chartWidget.html.twig' %}

{#
    Variables:
        data - should be an array contains 'fraction' and 'label' values in each row
               also you can build chart data in nested template by overriding 'data' block
#}
{% block content %}

{% set hasData = false %}
{% for source in data %}
    {% if source.itemCount and source.itemCount > 0 %}
        {% set hasData = true %}
    {% endif %}
{% endfor %}

{% if hasData %}
    <div class="chart-container">
        <div class="clearfix">
            <div id="{{ widgetId }}-chart" class="pie-chart chart pull-left"></div>
            <div id="{{ widgetId }}-legend" class="pie-chart-legend chart-legend pull-left"></div>
        </div>
    </div>

    <script type="text/javascript">
        require(['jquery', 'oroui/js/layout', 'flotr2'],
        function ($, layout, Flotr) {
            $(function () {
                var ratio = {{ isMobileVersion() ? '0.8' : '0.35' }};
                var $widgetContent = $('#{{ widgetContentId }}');
                var $chart = $('#{{ widgetId }}-chart');
                var $chartLegend = $('#{{ widgetId }}-legend');
                var setChartSize = function () {
                    var chartWidth = Math.min(Math.round($widgetContent.width() * ratio), 350);
                    if (chartWidth != $chart.width()) {
                        $chart.width(chartWidth);
                        $chart.height(chartWidth);
                        $chartLegend.height(chartWidth);
                        return true;
                    }
                    return false;
                };
                var setChartContainerSize = function () {
                    var $chartLegendTable = $chartLegend.find('table');
                    var $td = $chartLegendTable.find('td');
                    var padding = parseInt($td.css('padding-bottom'));
                    if (padding > 0 && ($chartLegendTable.height() + 20) > $chartLegend.height()) {
                        while (($chartLegendTable.height() + 20) > $chartLegend.height()) {
                            padding = padding - 1;
                            $td.css('padding-bottom', padding + 'px');
                            if (padding <= 0) {
                                break;
                            }
                        }
                    } else if (padding < 7 && ($chartLegendTable.height() + 20) < $chartLegend.height()) {
                        while (($chartLegendTable.height() + 20) < $chartLegend.height()) {
                            padding = padding + 1;
                            $td.css('padding-bottom', padding + 'px');
                            if (padding >= 7) {
                                break;
                            }
                        }
                    }
                    $chart.closest('.clearfix').width(
                        $chart.width() +
                        $chartLegendTable.outerWidth() +
                        parseInt($chartLegendTable.css('margin-left'))
                    );
                };
                var drawChart = function () {
                    if (!$chart.get(0).clientWidth) {
                        return;
                    }
                    var data = [];
                    {# build chart data #}
                    {% block data %}
                        {%- for item in data -%}
                            {% set rowData = {
                                data: [[0, item.fraction]],
                                label: item.label
                            } %}
                            data.push({{ rowData|json_encode|raw }});
                        {%- endfor -%}
                    {% endblock %}
                    Flotr.draw(
                        $chart.get(0),
                        data,
                        {
                            colors: {{ chartColors|json_encode|raw }},
                            fontColor: {{ chartFontColor|json_encode|raw }},
                            fontSize: {{ chartFontSize|json_encode|raw }},
                            shadowSize: 0,
                            HtmlText: true,
                            xaxis : {
                                showLabels : false
                            },
                            yaxis : {
                                showLabels : false
                            },
                            grid : {
                                color: {{ chartFontColor|json_encode|raw }},
                                verticalLines : false,
                                horizontalLines : false,
                                outlineWidth: 0
                            },
                            pie : {
                                show : true,
                                explode : 0,
                                sizeRatio: 0.8,
                                startAngle: Math.PI/3.5
                            },
                            mouse : {
                                track : true,
                                relative: true,
                                lineColor: {{ chartHighlightColor|json_encode|raw }},
                                trackFormatter: function (obj) {
                                    return obj.series.label + '&nbsp;&nbsp;&nbsp;' + (Math.round(obj.fraction * 10000) * 0.01) + ' %';
                                }
                            },
                            legend : {
                                position : 'ne',
                                container: $chartLegend.get(0),
                                labelBoxWidth: 20,
                                labelBoxHeight: 13,
                                labelBoxMargin: 0
                            }
                        }
                    );
                };

                layout.onPageRendered(function () {
                    setChartSize();
                    drawChart();
                    setChartContainerSize();
                });

                $(window).resize(function () {
                    if (setChartSize()) {
                        drawChart();
                        setChartContainerSize();
                    }
                });
            });
        });
    </script>
{% else %}
    <div class="clearfix no-data">
        <span>{{ 'oro.dashboard.no_data_found'|trans }}</span>
    </div>
{% endif %}

{% endblock %}
<commit_msg>BAP-3691: Dashboard Opportunities by status X-axis has multiple :in progress” and “won” values  - fixed incorrect rounding<commit_after>{% extends 'OroDashboardBundle:Dashboard:chartWidget.html.twig' %}

{#
    Variables:
        data - should be an array contains 'fraction' and 'label' values in each row
               also you can build chart data in nested template by overriding 'data' block
#}
{% block content %}

{% set hasData = false %}
{% for source in data %}
    {% if source.itemCount and source.itemCount > 0 %}
        {% set hasData = true %}
    {% endif %}
{% endfor %}

{% if hasData %}
    <div class="chart-container">
        <div class="clearfix">
            <div id="{{ widgetId }}-chart" class="pie-chart chart pull-left"></div>
            <div id="{{ widgetId }}-legend" class="pie-chart-legend chart-legend pull-left"></div>
        </div>
    </div>

    <script type="text/javascript">
        require(['jquery', 'oroui/js/layout', 'flotr2'],
        function ($, layout, Flotr) {
            $(function () {
                var ratio = {{ isMobileVersion() ? '0.8' : '0.35' }};
                var $widgetContent = $('#{{ widgetContentId }}');
                var $chart = $('#{{ widgetId }}-chart');
                var $chartLegend = $('#{{ widgetId }}-legend');
                var setChartSize = function () {
                    var chartWidth = Math.min(Math.round($widgetContent.width() * ratio), 350);
                    if (chartWidth != $chart.width()) {
                        $chart.width(chartWidth);
                        $chart.height(chartWidth);
                        $chartLegend.height(chartWidth);
                        return true;
                    }
                    return false;
                };
                var setChartContainerSize = function () {
                    var $chartLegendTable = $chartLegend.find('table');
                    var $td = $chartLegendTable.find('td');
                    var padding = parseInt($td.css('padding-bottom'));
                    if (padding > 0 && ($chartLegendTable.height() + 20) > $chartLegend.height()) {
                        while (($chartLegendTable.height() + 20) > $chartLegend.height()) {
                            padding = padding - 1;
                            $td.css('padding-bottom', padding + 'px');
                            if (padding <= 0) {
                                break;
                            }
                        }
                    } else if (padding < 7 && ($chartLegendTable.height() + 20) < $chartLegend.height()) {
                        while (($chartLegendTable.height() + 20) < $chartLegend.height()) {
                            padding = padding + 1;
                            $td.css('padding-bottom', padding + 'px');
                            if (padding >= 7) {
                                break;
                            }
                        }
                    }
                    $chart.closest('.clearfix').width(
                        $chart.width() +
                        $chartLegendTable.outerWidth() +
                        parseInt($chartLegendTable.css('margin-left'))
                    );
                };
                var drawChart = function () {
                    if (!$chart.get(0).clientWidth) {
                        return;
                    }
                    var data = [];
                    {# build chart data #}
                    {% block data %}
                        {%- for item in data -%}
                            {% set rowData = {
                                data: [[0, item.fraction]],
                                label: item.label
                            } %}
                            data.push({{ rowData|json_encode|raw }});
                        {%- endfor -%}
                    {% endblock %}
                    Flotr.draw(
                        $chart.get(0),
                        data,
                        {
                            colors: {{ chartColors|json_encode|raw }},
                            fontColor: {{ chartFontColor|json_encode|raw }},
                            fontSize: {{ chartFontSize|json_encode|raw }},
                            shadowSize: 0,
                            HtmlText: true,
                            xaxis : {
                                showLabels : false
                            },
                            yaxis : {
                                showLabels : false
                            },
                            grid : {
                                color: {{ chartFontColor|json_encode|raw }},
                                verticalLines : false,
                                horizontalLines : false,
                                outlineWidth: 0
                            },
                            pie : {
                                show : true,
                                explode : 0,
                                sizeRatio: 0.8,
                                startAngle: Math.PI/3.5
                            },
                            mouse : {
                                track : true,
                                relative: true,
                                lineColor: {{ chartHighlightColor|json_encode|raw }},
                                trackFormatter: function (obj) {
                                    return obj.series.label + '&nbsp;&nbsp;&nbsp;' + parseFloat(obj.fraction * 100).toFixed(2) + ' %';
                                }
                            },
                            legend : {
                                position : 'ne',
                                container: $chartLegend.get(0),
                                labelBoxWidth: 20,
                                labelBoxHeight: 13,
                                labelBoxMargin: 0
                            }
                        }
                    );
                };

                layout.onPageRendered(function () {
                    setChartSize();
                    drawChart();
                    setChartContainerSize();
                });

                $(window).resize(function () {
                    if (setChartSize()) {
                        drawChart();
                        setChartContainerSize();
                    }
                });
            });
        });
    </script>
{% else %}
    <div class="clearfix no-data">
        <span>{{ 'oro.dashboard.no_data_found'|trans }}</span>
    </div>
{% endif %}

{% endblock %}

{'fraction_non_alphanumeric': 0.11232187761944677, 'fraction_numerical': 0.00731540044197211, 'mean_word_length': 0.8657947114017629, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5109462', 'n_tokens_mistral': 3175, 'n_tokens_neox': 2859, 'n_words': 580}