<commit_before>/*
 * Copyright (c) 2015 Memorial Sloan-Kettering Cancer Center.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
 * FOR A PARTICULAR PURPOSE. The software and documentation provided hereunder
 * is on an "as is" basis, and Memorial Sloan-Kettering Cancer Center has no
 * obligations to provide maintenance, support, updates, enhancements or
 * modifications. In no event shall Memorial Sloan-Kettering Cancer Center be
 * liable to any party for direct, indirect, special, incidental or
 * consequential damages, including lost profits, arising out of the use of this
 * software and its documentation, even if Memorial Sloan-Kettering Cancer
 * Center has been advised of the possibility of such damage.
 */

/*
 * This file is part of cBioPortal.
 *
 * cBioPortal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/



var PieChart = function(){
    var pieChart, cluster;

    //All DIV ID names are organized based on the structure rule, initialized 
    //in initParam function
    var DIV = {
        parentID : "",
        mainDiv : "",
        titleDiv: "",
        chartDiv : "",
        labelTableID : "",
        labelTableTdID : ""
    };

    var chartID,
        className,
        selectedAttr,
        selectedAttrKeys,
        selectedAttrDisplay,
        ndx,
        plotDataButtonFlag = false,
        tableInitialized = false,
        pieLabelTableInitialized = false,
        chartColors;

    var labels =[],
        allSampleSize = 0,
        currentSampleSize = 0;
        maxLabelNameLength = 0,
        maxLabelValue = 0;

    var postFilterCallback,
        postRedrawCallback,
        pieLabelClickCallback,
        plotDataCallback;

    var titleLengthCutoff = 25;

    //Pie chart categories: w1h1, w1h2, w2h1, w2h2
    var category = ['w1','h1'];
    var currentView = 'pie'; //Default value: pie, table

    //The attributes will be converted to table view after initialization
    var tableAttrs = {'CANCER_TYPE':1, 'CANCER_TYPE_DETAILED':1};

    var reactTableData = {};
    var labelMetaData = [];
    
    //This function is designed to draw Pie Labels based on current color the
    //Pie Chart has. Pagging function will be added when the number of labels
    //bigger than 5.
    function addPieLabels() {
        initLabels();
        initReactData();
        labelFunction();
        addPieLabelEvents();

        //Make sure table will be reinitialized when table view selected
        if (currentView === 'table' && !tableInitialized ) {
            initReactTable(DIV.labelTableID, reactTableData);
            tableInitialized = true;
        }
    }
    
    function updatePieLabels() {
        updateCurrentLabels();
        initReactData();
        updateTables();
    }
    
    function updateTables() {
        if(pieLabelTableInitialized && currentView === 'pie') {
            updateQtipReactTable();
        }
        if(tableInitialized && currentView === 'table') {
            updateReactTable();
        }
    }

    function initReactData() {
        var result = {
            data: [],
            attributes: [
                {
                    "attr_id": "name",
                    "display_name": selectedAttrDisplay,
                    "datatype": "STRING",
                    "column_width": 215
                },<commit_msg>Fix issue #1326<commit_after>/*
 * Copyright (c) 2015 Memorial Sloan-Kettering Cancer Center.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
 * FOR A PARTICULAR PURPOSE. The software and documentation provided hereunder
 * is on an "as is" basis, and Memorial Sloan-Kettering Cancer Center has no
 * obligations to provide maintenance, support, updates, enhancements or
 * modifications. In no event shall Memorial Sloan-Kettering Cancer Center be
 * liable to any party for direct, indirect, special, incidental or
 * consequential damages, including lost profits, arising out of the use of this
 * software and its documentation, even if Memorial Sloan-Kettering Cancer
 * Center has been advised of the possibility of such damage.
 */

/*
 * This file is part of cBioPortal.
 *
 * cBioPortal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/



var PieChart = function(){
    var pieChart, cluster;

    //All DIV ID names are organized based on the structure rule, initialized 
    //in initParam function
    var DIV = {
        parentID : "",
        mainDiv : "",
        titleDiv: "",
        chartDiv : "",
        labelTableID : "",
        labelTableTdID : ""
    };

    var chartID,
        className,
        selectedAttr,
        selectedAttrKeys,
        selectedAttrDisplay,
        ndx,
        plotDataButtonFlag = false,
        tableInitialized = false,
        pieLabelTableInitialized = false,
        chartColors;

    var labels =[],
        allSampleSize = 0,
        currentSampleSize = 0;
        maxLabelNameLength = 0,
        maxLabelValue = 0;

    var postFilterCallback,
        postRedrawCallback,
        pieLabelClickCallback,
        plotDataCallback;

    var titleLengthCutoff = 25;

    //Pie chart categories: w1h1, w1h2, w2h1, w2h2
    var category = ['w1','h1'];
    var currentView = 'pie'; //Default value: pie, table

    //The attributes will be converted to table view after initialization
    var tableAttrs = {'CANCER_TYPE':1, 'CANCER_TYPE_DETAILED':1};

    var reactTableData = {};
    var labelMetaData = [];
    
    //This function is designed to draw Pie Labels based on current color the
    //Pie Chart has. Pagging function will be added when the number of labels
    //bigger than 5.
    function addPieLabels() {
        initLabels();
        initReactData();
        labelFunction();
        addPieLabelEvents();

        //Make sure table will be reinitialized when table view selected
        if (currentView === 'table' && !tableInitialized ) {
            initReactTable(DIV.labelTableID, reactTableData);
            tableInitialized = true;
        }
    }
    
    function updatePieLabels() {
        updateCurrentLabels();
        initReactData();
        updateTables();
    }
    
    function updateTables() {
        if(pieLabelTableInitialized) {
            updateQtipReactTable();
        }
        if(tableInitialized) {
            updateReactTable();
        }
    }

    function initReactData() {
        var result = {
            data: [],
            attributes: [
                {
                    "attr_id": "name",
                    "display_name": selectedAttrDisplay,
                    "datatype": "STRING",
                    "column_width": 215
                },
{'fraction_non_alphanumeric': 0.07842396777442094, 'fraction_numerical': 0.00730110775427996, 'mean_word_length': 2.4084084084084085, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, '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': '2013627', 'n_tokens_mistral': 2095, 'n_tokens_neox': 2012, 'n_words': 784}