<commit_before>/*
* ********************************
*         GENERAL TEMPLATE
* ********************************
* <div class="ui list">
*     <div class="item">...</div>      // category
*     <div class="item">...</div>      // category
*     <div class="item">...</div>      // category
*     <div class="item">...</div>      // category
*     ...
* </div>
*
*
* ************************
*         CATEGORY
* ************************
* <div class="item">
*     <i class="sitemap icon"></i>      // only if it has children
*     <div class="content">
*         <div class="header">
*             Category name
*             <button class="ui circular icon basic button">
*                 <i class="down chevron icon"></i>
*             </button>
*         </div>
*     </div>
* </div>
*
* */

function TaxonomyTree(Options) {
    this.url = Options.url;
    this.container = Options.container;
    this.skipCategories = Options.skipCategories || [];
    this.generation_task = Options.generation_task;
    this.categories = [];
    this.id_to_idx = {};
    this.ontology_tree;
    this.data;
    this.openedCategories = [];
    this.infoCategories = [];
}

TaxonomyTree.prototype = {

    load: function () {
        var tt = this;
        $.getJSON(tt.url)
            .done(function (data) {
                tt.data = data;
                tt.update();
            })
    },

    update: function () {
        var tt = this;
        tt.buildTree();
        tt.showTree();
        console.log(tt.data);
    },

    buildTree: function () {
        var tt = this;
        var root = tt.data;
        $(tt.container).append(
            $("<div>", {
                class: "ui list"
            })
        );
        tt.ontology_tree = tt.addNode(root);
    },

    addNode: function (node, path, bigId) {
        var tt = this;
        var skip_this = tt.skipCategories.indexOf(node.name) > -1;
        var cur_path = path || [];
        var cur_bigId = bigId || '';

        var category_info = {
            name: node.name,
            path: cur_path,
            children: node.children,
            id: node.node_id,
            TT: tt,
            bigId: cur_bigId
        };

        var category = new Category(category_info);
        var DOM = skip_this ? $(tt.container) : category.DOM;
        tt.categories.push(category);
        tt.id_to_idx[cur_bigId] = tt.categories.length -1;

        if (category.hasChildren()) {
            var parent_node = skip_this ? tt.data : node;
            var children_DOM_container = DOM.find(".list");
            $(parent_node.children).each(function () {
                // recursively build tree
                var new_path = cur_path.concat([this.name]);
                var new_bigId = (cur_bigId === '') ? this.node_id: cur_bigId + ',' + this.node_id;
                var child_DOM = tt.addNode(this, new_path, new_bigId);
                children_DOM_container.append(child_DOM)
            });
        }

        return DOM;
    },

    showTree: function () {
        var tt = this;
        $(tt.container).append(tt.ontology_tree);
    },

    locateCategory: function(bigId) {
        var tt = this;

        tt.collapseAll()
            .then(function () {
                tt.getCategoryInfo(bigId);
                return tt.openCategoryPath(bigId);
            })
            .then(function () {
                tt.scrollToCategory(bigId)
            })
    },

    getCategoryInfo: function (bigId) {
        var tt = this;
        var cat_idx = tt.id_to_idx[bigId];
        var category = tt.categories[cat_idx];
        category.toggleInfo();
    },

    openCategoryPath: function (bigId) {
        var tt = this;
        var node_ids = bigId.split(',');
        var proms = [];
        var id = '';
        for (var i = 0; i < node_ids.length; i++) {
            id += (i === 0) ? node_ids[i] : ',' + node_ids[i];
            var category = tt.categories[tt.id_to_idx[id]];
            if (!category.expanded) {
                proms.push(category.openChildren());
            }
        }
        return Promise.all(proms);
    },

    scrollToCategory: function (bigId) {
        var tt = this;
        var cat_idx = tt.id_to_idx[bigId];
        var category = tt.categories[cat_idx];
        var element = category.DOM;
        var el_offset = element.offset().top;
        var el_height = element.height();
        var window_height = $(window).height();
        var offset;

        if (el_height < window_height) {
            offset = el_offset - ((window_height/2) - (el_height/2));
        }
        else {
            offset = el_offset;
        }

        var body = $('body');
        return body.stop().animate({
            scrollTop: offset
        }, 200).promise();
    },

    collapseAll: function () {
        var tt = this;
        var proms = [];
        return Promise.all(proms.concat(
            tt.collapseAllCategories(),
            tt.hideAllInfo()
        ));
    },

    collapseAllCategories: function () {
        var tt = this;
        var proms = [];
        for (var i = 0; i < tt.openedCategories.length; i++) {
            var category = tt.openedCategories[i];
            if (category.expanded)
                proms.push(category.closeChildren());
        }
        return proms;
    },

    hideAllInfo: function () {<commit_msg>Fix scroll to category<commit_after>/*
* ********************************
*         GENERAL TEMPLATE
* ********************************
* <div class="ui list">
*     <div class="item">...</div>      // category
*     <div class="item">...</div>      // category
*     <div class="item">...</div>      // category
*     <div class="item">...</div>      // category
*     ...
* </div>
*
*
* ************************
*         CATEGORY
* ************************
* <div class="item">
*     <i class="sitemap icon"></i>      // only if it has children
*     <div class="content">
*         <div class="header">
*             Category name
*             <button class="ui circular icon basic button">
*                 <i class="down chevron icon"></i>
*             </button>
*         </div>
*     </div>
* </div>
*
* */

function TaxonomyTree(Options) {
    this.url = Options.url;
    this.container = Options.container;
    this.skipCategories = Options.skipCategories || [];
    this.generation_task = Options.generation_task;
    this.categories = [];
    this.id_to_idx = {};
    this.ontology_tree;
    this.data;
    this.openedCategories = [];
    this.infoCategories = [];
}

TaxonomyTree.prototype = {

    load: function () {
        var tt = this;
        $.getJSON(tt.url)
            .done(function (data) {
                tt.data = data;
                tt.update();
            })
    },

    update: function () {
        var tt = this;
        tt.buildTree();
        tt.showTree();
        console.log(tt.data);
    },

    buildTree: function () {
        var tt = this;
        var root = tt.data;
        $(tt.container).append(
            $("<div>", {
                class: "ui list"
            })
        );
        tt.ontology_tree = tt.addNode(root);
    },

    addNode: function (node, path, bigId) {
        var tt = this;
        var skip_this = tt.skipCategories.indexOf(node.name) > -1;
        var cur_path = path || [];
        var cur_bigId = bigId || '';

        var category_info = {
            name: node.name,
            path: cur_path,
            children: node.children,
            id: node.node_id,
            TT: tt,
            bigId: cur_bigId
        };

        var category = new Category(category_info);
        var DOM = skip_this ? $(tt.container) : category.DOM;
        tt.categories.push(category);
        tt.id_to_idx[cur_bigId] = tt.categories.length -1;

        if (category.hasChildren()) {
            var parent_node = skip_this ? tt.data : node;
            var children_DOM_container = DOM.find(".list");
            $(parent_node.children).each(function () {
                // recursively build tree
                var new_path = cur_path.concat([this.name]);
                var new_bigId = (cur_bigId === '') ? this.node_id: cur_bigId + ',' + this.node_id;
                var child_DOM = tt.addNode(this, new_path, new_bigId);
                children_DOM_container.append(child_DOM)
            });
        }

        return DOM;
    },

    showTree: function () {
        var tt = this;
        $(tt.container).append(tt.ontology_tree);
    },

    locateCategory: function(bigId) {
        var tt = this;

        tt.collapseAll()
            .then(function () {
                tt.getCategoryInfo(bigId);
                return tt.openCategoryPath(bigId);
            })
            .then(function () {
                tt.scrollToCategory(bigId)
            })
    },

    getCategoryInfo: function (bigId) {
        var tt = this;
        var cat_idx = tt.id_to_idx[bigId];
        var category = tt.categories[cat_idx];
        category.toggleInfo();
    },

    openCategoryPath: function (bigId) {
        var tt = this;
        var node_ids = bigId.split(',');
        var proms = [];
        var id = '';
        for (var i = 0; i < node_ids.length; i++) {
            id += (i === 0) ? node_ids[i] : ',' + node_ids[i];
            var category = tt.categories[tt.id_to_idx[id]];
            if (!category.expanded) {
                proms.push(category.openChildren());
            }
        }
        return Promise.all(proms);
    },

    scrollToCategory: function (bigId) {
        var tt = this;
        var cat_idx = tt.id_to_idx[bigId];
        var category = tt.categories[cat_idx];
        var element = category.DOM;
        var el_offset = element.offset().top;
        var el_height = element.height();
        var window_height = $(window).height();
        var offset;

        if (el_height < window_height) {
            offset = el_offset - ((window_height/2) - (el_height/2));
        }
        else {
            offset = el_offset;
        }
        window.scroll({top:offset});  // the jquery animation does not work
        // var body = $('body');
        // return body.stop().animate({
        //     scrollTop: offset
        // }, 200).promise();
    },

    collapseAll: function () {
        var tt = this;
        var proms = [];
        return Promise.all(proms.concat(
            tt.collapseAllCategories(),
            tt.hideAllInfo()
        ));
    },

    collapseAllCategories: function () {
        var tt = this;
        var proms = [];
        for (var i = 0; i < tt.openedCategories.length; i++) {
            var category = tt.openedCategories[i];
            if (category.expanded)
                proms.push(category.closeChildren());
        }
        return proms;
    },

    hideAllInfo: function () {
{'fraction_non_alphanumeric': 0.15900241053217135, 'fraction_numerical': 0.0018542555164101613, 'mean_word_length': 1.6641145961965917, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 51, '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': '3739002', 'n_tokens_mistral': 3241, 'n_tokens_neox': 3126, 'n_words': 650}