<commit_before>require('css/legend.css');
var m = require('mithril');

module.exports = {
    view: function(data, repr, opts) {
        if(data[0].label){
            data.sort(function(a, b) {
                return a.label.localeCompare(b.label);
            });
        }
        return [
            m('div', {
                className: 'legend-grid'
            }, data.map(function(item) {
                return m('span', {
                    className: 'legend-grid-item'
                }, repr(item));
            })),
            m('span', {className: 'pull-left'}, opts.footer || '')
        ];
    }
};<commit_msg>Order legend to reflect add components<commit_after>require('css/legend.css');
var m = require('mithril');

/** Finds the index of a string in an array
 *
 * @param {Array} array The array to search through
 * @param {String} str The string to find
 * @returns {*}
 */
var find_index = function (array, str) {
    for (var i = 0; i < array.length; i++) {
        console.log(array[i].label);
        if (array[i].label === str)
            return i;
    }
    return -1;
};

/** Removes an index from an array immutably
 *
 * @param {Array} array the array to modify
 * @param {Int} index the index to remove
 * @returns {*} a new array missing the index value
 */
var remove_index = function (array, index) {
    var new_array = [];
    for (var i = 0; i < array.length; i++) {
        if (i != index)
            new_array.push(array[i]);
    }
    return new_array;
};

module.exports = {
    view: function (data, repr, opts) {

        var clean_array = data.splice();

        console.log("removing other");
        var other_index = find_index(data, "Other");
        var other = data[other_index];
        data = remove_index(data, other_index);


        console.log("removing Uncat");
        var uncat_index = find_index(data, "Uncategorized");
        var uncat = data[uncat_index];
        data = remove_index(data, uncat_index);

        console.log("Sorting");
        if (data[0].label) {
            data.sort(function (a, b) {
                return a.label.localeCompare(b.label);
            });
        }

        console.log("Pushing objects back");
        console.log(other, uncat);
        data.push(other);
        data.push(uncat);

        return [
            m('div', {
                className: 'legend-grid'
            }, data.map(function (item) {
                return m('span', {
                    className: 'legend-grid-item'
                }, repr(item));
            })),
            m('span', {className: 'pull-left'}, opts.footer || '')
        ];
    }
};
{'fraction_non_alphanumeric': 0.14925939992404103, 'fraction_numerical': 0.0018989745537409798, 'mean_word_length': 1.8661588683351469, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2478299', 'n_tokens_mistral': 806, 'n_tokens_neox': 775, 'n_words': 194}