<commit_before>
(function($) {
    $.fn.barReporter = function(options) {
        options = $.extend({
            "data": [],
            "color": "green",
            "type": "stacked",
            "scale": undefined,
        }, options);

        //find the bar element or initialize & add to container
        var get_or_create_row = function(parent, id) {
            var el = $(parent).find("#brRow" + id);
            if( !el.length ) {
                el = $("<div class='brRow' id='brRow" + id + "'>" +
                    "<div class='brLabel'></div>" +
                    "<div class='brBars'></div>");
                $(parent).append( el );
            }
            return el;
        }
        
        //find or add a new bar
        var get_or_create_bar = function(parent, index) {
            var el = $(parent).find(".brBars #brBar" + index);
            if( !el.length ) {
                el = $("<div class='brBar' id='brBar" + index + "'></div>");
                $(parent).find(".brBars").append( el );
            }
            return el;
        }

        //calculates the scale to present items out of
        var get_scale = function() {
            if( options.scale ) {
                return options.scale
            }

            var scale = 0;

            for( var index in options.data ) {
                var data = options.data[index][0];
                var total = 0;

                //if row does not have array of data, row's total is simply the value
                if( !$.isArray(data) ) {
                    total = data;

                //if row has array of data, row is either sum of values or highest value (depends on report type)
                } else {
                    $(data).each(function(i,value) {
                        if( options.type == "stacked" ) {
                            total += value;
                        } else if( (options.type == "multi") && (value > total) ) {
                            total = value;
                        }
                    });
                }

                if( total > scale ) {
                    scale = total;
                }
            }

            return scale;
        }

        //Remove any rows that no longer exist
        if( $(this).find(".brRow").length >= options.data.length ) {
            $(this).find(".brRow").each(function(index) {
                if( index > options.data.length - 1 ) {
                    $(this).remove();
                }
            });
        }

        //loop through rows and render them
        $(options.data).each($.proxy(function(index, row_data) {

            //get or create row
            var row_el = get_or_create_row(this, index);

            var data = $.isArray( row_data[0] ) ? row_data[0] : [ row_data[0] ];
            var label = row_data[1];

            //Remove any bars that no longer exist
            if( row_el.find(".brBar").length >= data.length ) {
                row_el.find(".brBar").each(function(index) {
                    if( index > data.length - 1 ) {
                        $(this).remove();
                    }
                });
            }

            //Update bar data
            $(data).each( function(index, value) {
                var el = get_or_create_bar( row_el, index );
                var width = value / get_scale() * 100;
                $(el).css("width", width + "%");
            });

            //Update label
            $(row_el).find(".brLabel").text( label );

        }, this));
    }

})(jQuery);

//        Reporting.draw_status_bars({<commit_msg>Optimizations<commit_after>
(function($) {
    $.fn.barReporter = function(options) {
        options = $.extend({
            "data": [],
            "color": "green",
            "type": "stacked",
            "scale": undefined,
        }, options);

        //determine graph scale
        var scale = $.fn.barReporter.calculate_scale(options);

        //Remove any rows that no longer exist
        if( $(this).find(".brRow").length >= options.data.length ) {
            $(this).find(".brRow").each(function(index) {
                if( index > options.data.length - 1 ) {
                    $(this).remove();
                }
            });
        }

        //loop through rows and render them
        $(options.data).each($.proxy(function(index, row_data) {

            //get or create row
            var row_el = $.fn.barReporter.get_or_create_row(this, index);

            var data = $.isArray( row_data[0] ) ? row_data[0] : [ row_data[0] ];
            var label = row_data[1];

            //Remove any bars that no longer exist
            if( row_el.find(".brBar").length >= data.length ) {
                row_el.find(".brBar").each(function(index) {
                    if( index > data.length - 1 ) {
                        $(this).remove();
                    }
                });
            }

            //Update bar data
            $(data).each( function(index, value) {
                var el = $.fn.barReporter.get_or_create_bar( row_el, index );
                var width = value / scale * 100;
                $(el).css("width", width + "%");
            });

            //Update label
            $(row_el).find(".brLabel").text( label );

        }, this));
    };

    //find the bar element or initialize & add to container
    $.fn.barReporter.get_or_create_row = function(parent, id) {
        var el = $(parent).find("#brRow" + id);
        if( !el.length ) {
            el = $("<div class='brRow' id='brRow" + id + "'>" +
                "<div class='brLabel'></div>" +
                "<div class='brBars'></div>");
            $(parent).append( el );
        }
        return el;
    }

    //find or add a new bar
    $.fn.barReporter.get_or_create_bar = function(parent, index) {
        var el = $(parent).find(".brBars #brBar" + index);
        if( !el.length ) {
            el = $("<div class='brBar' id='brBar" + index + "'></div>");
            $(parent).find(".brBars").append( el );
        }
        return el;
    }

    //calculates the scale to present items out of
    $.fn.barReporter.calculate_scale = function(options) {
        if( options.scale ) {
            return options.scale
        }

        var scale = 0;

        for( var index in options.data ) {
            var data = options.data[index][0];
            var total = 0;

            //if row does not have array of data, row's total is simply the value
            if( !$.isArray(data) ) {
                total = data;

            //if row has array of data, row is either sum of values or highest value (depends on report type)
            } else {
                $(data).each(function(i,value) {
                    if( options.type == "stacked" ) {
                        total += value;
                    } else if( (options.type == "multi") && (value > total) ) {
                        total = value;
                    }
                });
            }

            if( total > scale ) {
                scale = total;
            }
        }

        return scale;
    }

})(jQuery);

//        Reporting.draw_status_bars({
{'fraction_non_alphanumeric': 0.14170266127908596, 'fraction_numerical': 0.0033440156054061585, 'mean_word_length': 1.2600755667506298, 'pattern_counts': {'":': 8, '<': 17, '<?xml version=': 0, '>': 29, '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': '2703379', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1920, 'n_words': 488}