<commit_before>//= require pageComparison.js
//= require_self

"use strict";

var OpenSpeedMonitor = OpenSpeedMonitor || {};
OpenSpeedMonitor.ChartModules = OpenSpeedMonitor.ChartModules || {};
OpenSpeedMonitor.ChartModules.GuiHandling = OpenSpeedMonitor.ChartModules.GuiHandling || {};

OpenSpeedMonitor.ChartModules.GuiHandling.pageComparison = (function () {

    var pageComparisonChart = OpenSpeedMonitor.ChartModules.PageComparisonChart("#page-comparison-svg");
    var spinner = OpenSpeedMonitor.Spinner("#chart-container");
    var drawGraphButton = $("#graphButtonHtmlId");
    var avgLoaded = false;
    var medianLoaded = false;

    var init = function () {
        $(window).on('resize', function () {
            $("#chart-card").removeClass("hidden");
            renderChart({}, false);
        });
        $(window).on('historyStateLoaded', function () {
            loadData(false);
        });
        $("input[name='aggregationValue']").on("change", function () {
            spinner.start();
            renderChart({aggregationValue: getAggregationValue()}, true, true);
        });
        drawGraphButton.click(function () {
            loadData(true);
        });
        window.addEventListener("pageComparisonValidation", function (event) {
            setShowButtonState(event.detail.isValid)
        });
        setShowButtonState(false);
    };

    var setShowButtonState = function (enable) {
        var button = document.getElementById("graphButtonHtmlId");
        if (enable) {
            enableButton(button)
        } else {
            disableButton(button)
        }
    };

    var disableButton = function (button) {
        button.setAttribute("disabled", "disabled");
        document.getElementById('warning-no-page').style.display = 'block'
    }

    var enableButton = function (button) {
        button.removeAttribute("disabled");
        document.getElementById('warning-no-page').style.display = 'none'
    }

    var renderChart = function (data, isStateChange, isAggregationValueChange) {
        if (avgLoaded && getAggregationValue() === "avg") {
            spinner.stop()
        }
        if (medianLoaded && getAggregationValue() === "median") {
            spinner.stop()
        }

        if (data) {
            pageComparisonChart.setData(data);
            if (isStateChange) {
                $(window).trigger("historyStateChanged");
            }
        }
        if (!data.series) pageComparisonChart.render(isAggregationValueChange);
        if (data.series && getAggregationValue() === data.series[0].data[0].aggregationValue) {
            pageComparisonChart.render(isAggregationValueChange);
        }
    };

    var getAggregationValue = function () {
        return $('input[name=aggregationValue]:checked').val()
    };

    var handleNewData = function (data, isStateChange) {
        $("#chart-card").removeClass("hidden");
        data.aggregationValue = getAggregationValue();
        renderChart(data, isStateChange)
    };

    var loadData = function (isStateChange) {
        pageComparisonChart.resetData();
        avgLoaded = false;
        medianLoaded = false;

        var selectedTimeFrame = OpenSpeedMonitor.selectIntervalTimeframeCard.getTimeFrame();
        var queryData = {
            from: selectedTimeFrame[0].toISOString(),
            to: selectedTimeFrame[1].toISOString(),
            measurand: JSON.stringify(OpenSpeedMonitor.BarchartMeasurings.getValues()),
            selectedPageComparisons: JSON.stringify(OpenSpeedMonitor.ChartModules.GuiHandling.PageComparison.Comparisons.getComparisons())
        };

        spinner.start();
        getDataForAggregationValue("median", queryData, isStateChange);
        getDataForAggregationValue("avg", queryData, isStateChange);
    };

    function getDataForAggregationValue(aggregationValue, queryData, isStateChange) {
        queryData.selectedAggregationValue = aggregationValue;
        $.ajax({
            type: 'POST',
<<<<<<< HEAD
            data: queryData,
=======
            data: {
                from: selectedTimeFrame[0].toISOString(),
                to: selectedTimeFrame[1].toISOString(),
                measurand: JSON.stringify(OpenSpeedMonitor.BarchartMeasurings.getValues()),
                selectedPageComparisons: JSON.stringify(window.pageComparisonComponent.getComparisons())
            },
>>>>>>> feature/bootstrapAngular
            url: OpenSpeedMonitor.urls.pageComparisonGetData,
            dataType: "json",
            success: function (data) {
                if (aggregationValue === "avg") {
                    avgLoaded = true;
                } else {
                    medianLoaded = true;
                }
                if (!$("#error-div").hasClass("hidden"))
                    $("#error-div").addClass("hidden");

                if (!$.isEmptyObject(data)) {
                    $('#warning-no-data').hide();
                    handleNewData(data, isStateChange);
                    $("#dia-save-chart-as-png").removeClass("disabled");
                } else {
                    $('#warning-no-data').show();<commit_msg>fix merge conflict error in pageComparisonGuiHandling.js<commit_after>//= require pageComparison.js
//= require_self

"use strict";

var OpenSpeedMonitor = OpenSpeedMonitor || {};
OpenSpeedMonitor.ChartModules = OpenSpeedMonitor.ChartModules || {};
OpenSpeedMonitor.ChartModules.GuiHandling = OpenSpeedMonitor.ChartModules.GuiHandling || {};

OpenSpeedMonitor.ChartModules.GuiHandling.pageComparison = (function () {

    var pageComparisonChart = OpenSpeedMonitor.ChartModules.PageComparisonChart("#page-comparison-svg");
    var spinner = OpenSpeedMonitor.Spinner("#chart-container");
    var drawGraphButton = $("#graphButtonHtmlId");
    var avgLoaded = false;
    var medianLoaded = false;

    var init = function () {
        $(window).on('resize', function () {
            $("#chart-card").removeClass("hidden");
            renderChart({}, false);
        });
        $(window).on('historyStateLoaded', function () {
            loadData(false);
        });
        $("input[name='aggregationValue']").on("change", function () {
            spinner.start();
            renderChart({aggregationValue: getAggregationValue()}, true, true);
        });
        drawGraphButton.click(function () {
            loadData(true);
        });
        window.addEventListener("pageComparisonValidation", function (event) {
            setShowButtonState(event.detail.isValid)
        });
        setShowButtonState(false);
    };

    var setShowButtonState = function (enable) {
        var button = document.getElementById("graphButtonHtmlId");
        if (enable) {
            enableButton(button)
        } else {
            disableButton(button)
        }
    };

    var disableButton = function (button) {
        button.setAttribute("disabled", "disabled");
        document.getElementById('warning-no-page').style.display = 'block'
    }

    var enableButton = function (button) {
        button.removeAttribute("disabled");
        document.getElementById('warning-no-page').style.display = 'none'
    }

    var renderChart = function (data, isStateChange, isAggregationValueChange) {
        if (avgLoaded && getAggregationValue() === "avg") {
            spinner.stop()
        }
        if (medianLoaded && getAggregationValue() === "median") {
            spinner.stop()
        }

        if (data) {
            pageComparisonChart.setData(data);
            if (isStateChange) {
                $(window).trigger("historyStateChanged");
            }
        }
        if (!data.series) pageComparisonChart.render(isAggregationValueChange);
        if (data.series && getAggregationValue() === data.series[0].data[0].aggregationValue) {
            pageComparisonChart.render(isAggregationValueChange);
        }
    };

    var getAggregationValue = function () {
        return $('input[name=aggregationValue]:checked').val()
    };

    var handleNewData = function (data, isStateChange) {
        $("#chart-card").removeClass("hidden");
        data.aggregationValue = getAggregationValue();
        renderChart(data, isStateChange)
    };

    var loadData = function (isStateChange) {
        pageComparisonChart.resetData();
        avgLoaded = false;
        medianLoaded = false;

        var selectedTimeFrame = OpenSpeedMonitor.selectIntervalTimeframeCard.getTimeFrame();
        var queryData = {
            from: selectedTimeFrame[0].toISOString(),
            to: selectedTimeFrame[1].toISOString(),
            measurand: JSON.stringify(OpenSpeedMonitor.BarchartMeasurings.getValues()),
            selectedPageComparisons: JSON.stringify(window.pageComparisonComponent.getComparisons())
        };

        spinner.start();
        getDataForAggregationValue("median", queryData, isStateChange);
        getDataForAggregationValue("avg", queryData, isStateChange);
    };

    function getDataForAggregationValue(aggregationValue, queryData, isStateChange) {
        queryData.selectedAggregationValue = aggregationValue;
        $.ajax({
            type: 'POST',
            data: queryData,
            url: OpenSpeedMonitor.urls.pageComparisonGetData,
            dataType: "json",
            success: function (data) {
                if (aggregationValue === "avg") {
                    avgLoaded = true;
                } else {
                    medianLoaded = true;
                }
                if (!$("#error-div").hasClass("hidden"))
                    $("#error-div").addClass("hidden");

                if (!$.isEmptyObject(data)) {
                    $('#warning-no-data').hide();
                    handleNewData(data, isStateChange);
                    $("#dia-save-chart-as-png").removeClass("disabled");
                } else {
                    $('#warning-no-data').show();
{'fraction_non_alphanumeric': 0.1289050652107977, 'fraction_numerical': 0.0010110201193003741, 'mean_word_length': 2.4502964771538194, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '4906747', 'n_tokens_mistral': 2531, 'n_tokens_neox': 2489, 'n_words': 401}