<commit_before>/**
 * Copyright 2014 Solinea, Inc.
 *
 * Licensed under the Solinea Software License Agreement (goldstone),
 * Version 1.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *     http://www.solinea.com/goldstone/LICENSE.pdf
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author: <NAME>
 */

// view is linked to collection when instantiated in api_perf_report.html

var StackedBarChartView = Backbone.View.extend({

    // adapted from
    // goldstone.charts.bivariateWithAverage

    defaults: {
        margin: {
            // top: 20,
            // bottom: 30,
            // right: 20,
            // left: 40
            top: goldstone.settings.charts.margins.top,
            right: goldstone.settings.charts.margins.right,
            bottom: goldstone.settings.charts.margins.bottom,
            left: goldstone.settings.charts.margins.left + 20
        }
    },

    initialize: function(options) {

        this.options = options || {};

        // essential for unique chart objects,
        // as objects/arrays are pass by reference
        this.defaults = _.clone(this.defaults);

        this.defaults.chartTitle = this.options.chartTitle;
        this.defaults.height = this.options.height - this.defaults.margin.top - this.defaults.margin.bottom;
        this.defaults.infoCustom = this.options.infoCustom;
        this.el = this.options.el;
        this.defaults.width = this.options.width - this.defaults.margin.left - this.defaults.margin.right;
        this.defaults.start = this.collection.defaults.reportParams.start;
        this.defaults.end = this.collection.defaults.reportParams.end;
        this.defaults.interval = this.collection.defaults.reportParams.interval;

        // easy to pass in a unique yAxisLabel. This pattern can be
        // expanded to any variable to allow overriding the default.
        if (this.options.yAxisLabel) {
            this.defaults.yAxisLabel = this.options.yAxisLabel;
        }

        var ns = this.defaults;
        var self = this;

        // registers 'sync' event so view 'watches' collection for data update
        this.collection.on('sync', this.update, this);
        this.collection.on('error', this.dataErrorMessage, this);

        // this is triggered by a listener set on novaReportView.js
        this.on('selectorChanged', function() {
            this.collection.defaults.globalLookback = $('#global-lookback-range').val();
            this.collection.urlGenerator();
            this.collection.fetch();
            this.defaults.start = this.collection.defaults.reportParams.start;
            this.defaults.end = this.collection.defaults.reportParams.end;
            this.defaults.interval = this.collection.defaults.reportParams.interval;

            $(this.el).find('#api-perf-info').popover({
                content: this.htmlGen.apply(this),
            });

            $(this.el).find('#spinner').show();
        });

        var appendSpinnerLocation = this.el;
        $('<img id="spinner" src="' + blueSpinnerGif + '">').load(function() {
            $(this).appendTo(appendSpinnerLocation).css({
                'position': 'relative',
                'margin-left': (ns.width / 2),
                'margin-top': -(ns.height / 2)
            });
        });

        this.render();

        // chart info button popover generator
        this.htmlGen = function() {
            var start = moment(goldstone.time.fromPyTs(ns.start / 1000)).format();
            var end = moment(goldstone.time.fromPyTs(ns.end / 1000)).format();
            var custom = _.map(ns.infoCustom, function(e) {
                return e.key + ": " + e.value + "<br>";
            });
            var result = '<div class="infoButton"><br>' + custom +
                'Start: ' + start + '<br>' +
                'End: ' + end + '<br>' +
                'Interval: ' + ns.interval + '<br>' +
                '<br></div>';
            return result;
        };

        $(this.el).find('#api-perf-info').popover({
            trigger: 'manual',
            content: function() {
                return self.htmlGen.apply(this);
            },
            placement: 'bottom',
            html: 'true'<commit_msg>Aligns spinner between apiPerf and stackedBar views.<commit_after>/**
 * Copyright 2014 Solinea, Inc.
 *
 * Licensed under the Solinea Software License Agreement (goldstone),
 * Version 1.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *     http://www.solinea.com/goldstone/LICENSE.pdf
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author: <NAME>
 */

// view is linked to collection when instantiated in api_perf_report.html

var StackedBarChartView = Backbone.View.extend({

    // adapted from
    // goldstone.charts.bivariateWithAverage

    defaults: {
        margin: {
            // top: 20,
            // bottom: 30,
            // right: 20,
            // left: 40
            top: goldstone.settings.charts.margins.top,
            right: goldstone.settings.charts.margins.right,
            bottom: goldstone.settings.charts.margins.bottom,
            left: goldstone.settings.charts.margins.left + 20
        }
    },

    initialize: function(options) {

        this.options = options || {};

        // essential for unique chart objects,
        // as objects/arrays are pass by reference
        this.defaults = _.clone(this.defaults);

        this.defaults.chartTitle = this.options.chartTitle;
        this.defaults.height = this.options.height - this.defaults.margin.top - this.defaults.margin.bottom;
        this.defaults.infoCustom = this.options.infoCustom;
        this.el = this.options.el;
        this.defaults.width = this.options.width - this.defaults.margin.left - this.defaults.margin.right;
        this.defaults.start = this.collection.defaults.reportParams.start;
        this.defaults.end = this.collection.defaults.reportParams.end;
        this.defaults.interval = this.collection.defaults.reportParams.interval;

        // easy to pass in a unique yAxisLabel. This pattern can be
        // expanded to any variable to allow overriding the default.
        if (this.options.yAxisLabel) {
            this.defaults.yAxisLabel = this.options.yAxisLabel;
        }

        var ns = this.defaults;
        var self = this;

        // registers 'sync' event so view 'watches' collection for data update
        this.collection.on('sync', this.update, this);
        this.collection.on('error', this.dataErrorMessage, this);

        // this is triggered by a listener set on novaReportView.js
        this.on('selectorChanged', function() {
            this.collection.defaults.globalLookback = $('#global-lookback-range').val();
            this.collection.urlGenerator();
            this.collection.fetch();
            this.defaults.start = this.collection.defaults.reportParams.start;
            this.defaults.end = this.collection.defaults.reportParams.end;
            this.defaults.interval = this.collection.defaults.reportParams.interval;

            $(this.el).find('#api-perf-info').popover({
                content: this.htmlGen.apply(this),
            });

            $(this.el).find('#spinner').show();
        });

        var appendSpinnerLocation = this.el;
        $('<img id="spinner" src="' + blueSpinnerGif + '">').load(function() {
            $(this).appendTo(appendSpinnerLocation).css({
                'position': 'relative',
                'margin-left': ((ns.width + ns.margin.left + ns.margin.right) / 2),
                'margin-top': -((ns.height + ns.margin.top + ns.margin.bottom) / 2)
            });
        });

        this.render();

        // chart info button popover generator
        this.htmlGen = function() {
            var start = moment(goldstone.time.fromPyTs(ns.start / 1000)).format();
            var end = moment(goldstone.time.fromPyTs(ns.end / 1000)).format();
            var custom = _.map(ns.infoCustom, function(e) {
                return e.key + ": " + e.value + "<br>";
            });
            var result = '<div class="infoButton"><br>' + custom +
                'Start: ' + start + '<br>' +
                'End: ' + end + '<br>' +
                'Interval: ' + ns.interval + '<br>' +
                '<br></div>';
            return result;
        };

        $(this.el).find('#api-perf-info').popover({
            trigger: 'manual',
            content: function() {
                return self.htmlGen.apply(this);
            },
            placement: 'bottom',
            html: 'true'
{'fraction_non_alphanumeric': 0.12593233163982273, 'fraction_numerical': 0.005621013944438439, 'mean_word_length': 2.106783075889859, 'pattern_counts': {'":': 2, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3741761', 'n_tokens_mistral': 2563, 'n_tokens_neox': 2426, 'n_words': 607}