<commit_before>/*
 #
 # Copyright (c) 2017 nexB Inc. and others. All rights reserved.
 # http://nexb.com and https://github.com/nexB/scancode-toolkit/
 # The ScanCode software is licensed under the Apache License version 2.0.
 # AboutCode is a trademark of nexB Inc.
 #
 # You may not use this software except in compliance with the License.
 # You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
 # 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.
 #
 */


// Bar chart summary for AboutCode scan data
class AboutCodeBarChart {
    constructor(barChartId, aboutCodeDB) {
        this.barChartId = barChartId;
        this.aboutCodeDB = aboutCodeDB;
        this.handlers = {};

        this.chartOptions = {
            name: "License Summary",
            margin: 30,
            barHeight: 25,
            xAxisName: "License Count",
            yAxisName: "License Name"
        };

        this.chartAttributesSelect = $("select#select-chart-attribute");
        this.barChartTotalFiles = $("span.total-files");

        this.chartAttributesSelect.select2({ placeholder: "Select an attribute" });

        // Populate bar chart summary select box values
        $.each(AboutCodeDataTable.TABLE_COLUMNS, (i, column) => {
            if (column.bar_chart_class) {
                this.chartAttributesSelect.append(
                    `<option class="${column.bar_chart_class}" value="${column.name}">${column.title}</option>`);
            }
        });

        this.chartAttributesSelect.on( "change", () => this.showSummary());

        $(".bar-chart-copyrights").wrapAll(`<optgroup label="Copyright Information"/>`);
        $(".bar-chart-licenses").wrapAll(`<optgroup label="License Information"/>`);
        $(".bar-chart-emails").wrapAll(`<optgroup label="Email Information"/>`);
        $(".bar-chart-file-infos").wrapAll(`<optgroup label="File Information"/>`);
        $(".bar-chart-package-infos").wrapAll(`<optgroup label="Package Information"/>`);

        this.reload();
    }

    on(event, handler) {
        this.handlers[event] = handler;
        return this;
    }

    database(aboutCodeDB) {
        this.aboutCodeDB = aboutCodeDB;
    }

    reload() {
        this.aboutCodeDB
            .getFileCount()
            .then(value => this.barChartTotalFiles.text(value));

        this.barChart = new BarChart([], this.chartOptions, this.barChartId);
    }

    draw() {
        this.barChart.draw();
    }

    showSummary() {
        if (this.chartAttributesSelect.val()) {<commit_msg>Fix directory filter for bar chart summary #168<commit_after>/*
 #
 # Copyright (c) 2017 nexB Inc. and others. All rights reserved.
 # http://nexb.com and https://github.com/nexB/scancode-toolkit/
 # The ScanCode software is licensed under the Apache License version 2.0.
 # AboutCode is a trademark of nexB Inc.
 #
 # You may not use this software except in compliance with the License.
 # You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
 # 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.
 #
 */


// Bar chart summary for AboutCode scan data
class AboutCodeBarChart {
    constructor(barChartId, aboutCodeDB) {
        this.barChartId = barChartId;
        this.aboutCodeDB = aboutCodeDB;
        this.handlers = {};

        this.chartOptions = {
            name: "License Summary",
            margin: 30,
            barHeight: 25,
            xAxisName: "License Count",
            yAxisName: "License Name"
        };

        this.chartAttributesSelect = $("select#select-chart-attribute");
        this.barChartTotalFiles = $("span.total-files");

        this.chartAttributesSelect.select2({ placeholder: "Select an attribute" });

        // Populate bar chart summary select box values
        $.each(AboutCodeDataTable.TABLE_COLUMNS, (i, column) => {
            if (column.bar_chart_class) {
                this.chartAttributesSelect.append(
                    `<option class="${column.bar_chart_class}" value="${column.name}">${column.title}</option>`);
            }
        });

        this.chartAttributesSelect.on( "change", () => this.showSummary());

        $(".bar-chart-copyrights").wrapAll(`<optgroup label="Copyright Information"/>`);
        $(".bar-chart-licenses").wrapAll(`<optgroup label="License Information"/>`);
        $(".bar-chart-emails").wrapAll(`<optgroup label="Email Information"/>`);
        $(".bar-chart-file-infos").wrapAll(`<optgroup label="File Information"/>`);
        $(".bar-chart-package-infos").wrapAll(`<optgroup label="Package Information"/>`);

        this.reload();
    }

    on(event, handler) {
        this.handlers[event] = handler;
        return this;
    }

    database(aboutCodeDB) {
        this.aboutCodeDB = aboutCodeDB;
    }

    reload() {
        this.aboutCodeDB
            .getFileCount()
            .then(value => this.barChartTotalFiles.text(value));

        this.barChart = new BarChart([], this.chartOptions, this.barChartId);
    }

    draw() {
        this.showSummary();
    }

    showSummary() {
        if (this.chartAttributesSelect.val()) {
{'fraction_non_alphanumeric': 0.1293408929836995, 'fraction_numerical': 0.005138199858256556, 'mean_word_length': 2.6823222439660794, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '5544306', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1520, 'n_words': 405}