<commit_before>var lizDataviz = function() {

    var dv = {
        'config' : null,
        'plots': {},
        'template': null
    };

    function optionToBoolean(string){
        var ret = false;
        if (string.toString().toLowerCase() == "true"){
            ret = true;
        }else{
            ret = false;
        }
        return ret;
    }

    function getPlots(){
        if(!dv.config.layers)
            return false;
        for( var i in dv.config.layers) {
            if (!( optionToBoolean(dv.config.layers[i]['only_show_child']) )) {
                addPlotContainer(i);
            }
        }
        lizMap.events.triggerEvent( "datavizplotcontainersadded" );
        for( var i in dv.config.layers) {
            if (!( optionToBoolean(dv.config.layers[i]['only_show_child']) )){
                getPlot(i, null, 'dataviz_plot_' + i);
            }
        }

        // Filter plot if needed
        lizMap.events.on({
            layerFilterParamChanged: function(e) {
                refreshPlotsOnFilter(e.featureType, e.filter);
            },
            layerfeatureremovefilter: function(e) {

                refreshPlotsOnFilter(e.featureType, null);
            }
        });

        // Change style of outer text in dark mode
        $('#dataviz-content.dark path.textline')
        .parent()
        .find('g.slicetext text')
        .css('fill', 'white');

    }

    function refreshPlotsOnFilter(featureType, filter){
        for( var i in dv.config.layers) {
            var dvLayerId = dv.config.layers[i]['layer_id']
            if( featureType in lizMap.config.layers ){
                var layerId = lizMap.config.layers[featureType].id;

                if( layerId == dvLayerId ){
                    if(filter === null){
                        getPlot(i, null, 'dataviz_plot_' + i);
                    }
                    else{
                        var pFilter = filter.replace(featureType+':', '');
                        if( pFilter.length > 5){
                            getPlot(i, pFilter, 'dataviz_plot_' + i);
                        }
                    }
                }
            }
        }
    }

    function buildPlotContainerHtml(title, abstract, target_id, with_title){
        with_title = typeof with_title !== 'undefined' ?  with_title : true;
        var html = '';
        html+= '<div class="dataviz_plot_container"  id="'+target_id+'_container">';
        if(with_title){
            html+= '<h3><span class="title">';
            html+= '<span class="icon"></span>&nbsp;';
            html+= '<span class="text">'+title+'</span>';
            html+= '</span></h3>';
        }
        html+= '<div class="menu-content">';
        if (abstract.trim() != '') {
            html+= '  <p>'+abstract.trim()+'</p>';
        }
        html+= '  <div class="dataviz-waiter progress progress-striped active" style="margin:5px 5px;">';
        html+= '    <div class="bar" style="width: 100%;"></div>';
        html+= '  </div>';
        html+= '  <div id="'+target_id+'"></div>';
        html+= '</div>';
        html+= '</div>';

        return html;
    }

    function addPlotContainer(plot_id){
        var dataviz_plot_id = 'dataviz_plot_' + plot_id;
        dv.plots[plot_id] = {'json': null, 'filter': null, 'show_plot': true, 'cache': null};
        var plot_config = dv.config.layers[plot_id];
        //if we chose to hide the parent plot the html variable become empty
        var html = '';
        if( !(optionToBoolean(plot_config.only_show_child)) )
        {
            html = buildPlotContainerHtml(plot_config.title, plot_config.abstract, dataviz_plot_id);
        }

        // Move plot at the end of the main container
        // to the corresponding place if id is referenced in the template
        var pgetter = '#dataviz_plot_template_' + plot_id;
        var p = $(pgetter);
        if( p.length ){
            p.append(html);
        }
        else{
            $('#dataviz-content').append(html);
        }
    }

    function getPlot(plot_id, exp_filter, target_id){
        if ( $('#'+target_id).length == 0) return;

        exp_filter = typeof exp_filter !== 'undefined' ?  exp_filter : null;
        target_id = typeof target_id !== 'undefined' ?  target_id : new Date().valueOf()+btoa(Math.random()).substring(0,12);

        var lparams = {
            'request': 'getPlot',
            'plot_id': plot_id
        };
        if (exp_filter) {
            lparams['exp_filter'] = exp_filter;
        }

        // Use cache if exsits
        if (!exp_filter && dv.plots[plot_id]['cache']
            && 'data' in dv.plots[plot_id]['cache']
            && dv.plots[plot_id]['cache'].data.length > 0
        ) {
            // Store filter
            dv.plots[plot_id]['filter'] = null;

            // Store json back<commit_msg>Add NULL test in dataviz.js<commit_after>var lizDataviz = function() {

    var dv = {
        'config' : null,
        'plots': {},
        'template': null
    };

    function optionToBoolean(string){
        var ret = false;
        if (string.toString().toLowerCase() == "true"){
            ret = true;
        }else{
            ret = false;
        }
        return ret;
    }

    function getPlots(){
        if(!dv.config.layers)
            return false;
        for( var i in dv.config.layers) {
            if (!( optionToBoolean(dv.config.layers[i]['only_show_child']) )) {
                addPlotContainer(i);
            }
        }
        lizMap.events.triggerEvent( "datavizplotcontainersadded" );
        for( var i in dv.config.layers) {
            if (!( optionToBoolean(dv.config.layers[i]['only_show_child']) )){
                getPlot(i, null, 'dataviz_plot_' + i);
            }
        }

        // Filter plot if needed
        lizMap.events.on({
            layerFilterParamChanged: function(e) {
                refreshPlotsOnFilter(e.featureType, e.filter);
            },
            layerfeatureremovefilter: function(e) {

                refreshPlotsOnFilter(e.featureType, null);
            }
        });

        // Change style of outer text in dark mode
        $('#dataviz-content.dark path.textline')
        .parent()
        .find('g.slicetext text')
        .css('fill', 'white');

    }

    function refreshPlotsOnFilter(featureType, filter){
        for( var i in dv.config.layers) {
            var dvLayerId = dv.config.layers[i]['layer_id']
            if( featureType in lizMap.config.layers ){
                var layerId = lizMap.config.layers[featureType].id;

                if( layerId == dvLayerId ){
                    if(filter === null){
                        getPlot(i, null, 'dataviz_plot_' + i);
                    }
                    else{
                        var pFilter = filter.replace(featureType+':', '');
                        if( pFilter.length > 5){
                            getPlot(i, pFilter, 'dataviz_plot_' + i);
                        }
                    }
                }
            }
        }
    }

    function buildPlotContainerHtml(title, abstract, target_id, with_title){
        with_title = typeof with_title !== 'undefined' ?  with_title : true;
        var html = '';
        html+= '<div class="dataviz_plot_container"  id="'+target_id+'_container">';
        if(with_title){
            html+= '<h3><span class="title">';
            html+= '<span class="icon"></span>&nbsp;';
            html+= '<span class="text">'+title+'</span>';
            html+= '</span></h3>';
        }
        html+= '<div class="menu-content">';
        if (abstract.trim() != '') {
            html+= '  <p>'+abstract.trim()+'</p>';
        }
        html+= '  <div class="dataviz-waiter progress progress-striped active" style="margin:5px 5px;">';
        html+= '    <div class="bar" style="width: 100%;"></div>';
        html+= '  </div>';
        html+= '  <div id="'+target_id+'"></div>';
        html+= '</div>';
        html+= '</div>';

        return html;
    }

    function addPlotContainer(plot_id){
        var dataviz_plot_id = 'dataviz_plot_' + plot_id;
        dv.plots[plot_id] = {'json': null, 'filter': null, 'show_plot': true, 'cache': null};
        var plot_config = dv.config.layers[plot_id];
        //if we chose to hide the parent plot the html variable become empty
        var html = '';
        if( !(optionToBoolean(plot_config.only_show_child)) )
        {
            html = buildPlotContainerHtml(plot_config.title, plot_config.abstract, dataviz_plot_id);
        }

        // Move plot at the end of the main container
        // to the corresponding place if id is referenced in the template
        var pgetter = '#dataviz_plot_template_' + plot_id;
        var p = $(pgetter);
        if( p.length ){
            p.append(html);
        }
        else{
            $('#dataviz-content').append(html);
        }
    }

    function getPlot(plot_id, exp_filter, target_id){
        if ( $('#'+target_id).length == 0) return;

        exp_filter = typeof exp_filter !== 'undefined' ?  exp_filter : null;
        target_id = typeof target_id !== 'undefined' ?  target_id : new Date().valueOf()+btoa(Math.random()).substring(0,12);

        var lparams = {
            'request': 'getPlot',
            'plot_id': plot_id
        };
        if (exp_filter) {
            lparams['exp_filter'] = exp_filter;
        }

        // Use cache if it exists
        if (!exp_filter && dv.plots[plot_id]['cache']
            && 'data' in dv.plots[plot_id]['cache']
            && dv.plots[plot_id]['cache'].data
            && dv.plots[plot_id]['cache'].data.length > 0
        ) {
            // Store filter
            dv.plots[plot_id]['filter'] = null;

            // Store json back
{'fraction_non_alphanumeric': 0.1451249487914789, 'fraction_numerical': 0.002662843097091356, 'mean_word_length': 1.729941291585127, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 47, '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': '5202880', 'n_tokens_mistral': 2933, 'n_tokens_neox': 2825, 'n_words': 601}