<commit_before>function forEachIn(obj, callback) {
    for (key in obj) {
        if (obj.hasOwnProperty(key)) {
            callback(key, obj[key]);
        }
    }
}


var _pageItems = [];
var _selectedIds = [];
function removeItemFromSelectedList(id) {
    for (var i = 0; i < _selectedIds.length; i++) {
        if (_selectedIds[i] == id) {
            _selectedIds.splice(i, 1);
        }
    }
}

function distanceInsideRect(area, x, y) {
    if (x >= area[0] && x <= area[0] + area[2]
        && y >= area[1] && y <= area[1] + area[3]) {

        var distance = Math.min(x - area[0], area[0] + area[2] - x)
            + Math.min(y - area[1], area[1] + area[3] - y);
        return distance;
    }
    else return -1;
}
function initGalenPageDump(pageData) {

    var canvas = $(".image .canvas");
    for (objectName in pageData.items) {
        if (pageData.items.hasOwnProperty(objectName)) {
            var item = pageData.items[objectName];
            item.name = objectName;
            item.id = _pageItems.length;
            item.selected = false;
            _pageItems.push(item);
            renderPageItem(canvas, item); 
        }
    }

    canvas.click(function (event) {
        var offset = $(this).offset();
        var x = event.pageX - offset.left;
        var y = event.pageY - offset.top;

        //Finding the closest to the rect

        var minDistance = 1000000;
        var selectedId = -1;
        for (var i = 0; i < _pageItems.length; i++) {
           var distance = distanceInsideRect(_pageItems[i].area, x, y);
           if (distance > -1 && distance < minDistance) {
               selectedId = i;
               minDistance = distance;
           }
        }

        if (selectedId >=0 ) {
            selectItem(selectedId);
        }
    });
}

<commit_msg>Added sorting objects by name in pagedump<commit_after>function forEachIn(obj, callback) {
    for (key in obj) {
        if (obj.hasOwnProperty(key)) {
            callback(key, obj[key]);
        }
    }
}


var _pageItems = [];
var _selectedIds = [];
function removeItemFromSelectedList(id) {
    for (var i = 0; i < _selectedIds.length; i++) {
        if (_selectedIds[i] == id) {
            _selectedIds.splice(i, 1);
        }
    }
}

function distanceInsideRect(area, x, y) {
    if (x >= area[0] && x <= area[0] + area[2]
        && y >= area[1] && y <= area[1] + area[3]) {

        var distance = Math.min(x - area[0], area[0] + area[2] - x)
            + Math.min(y - area[1], area[1] + area[3] - y);
        return distance;
    }
    else return -1;
}
function sortItemsByName(items) {
    for (var i=0; i<items.length - 1; i++) {
        for(var j = i+1; j<items.length; j++) {
            if (items[i].name  > items[j].name) {
                var temp = items[i];
                items[i] = items[j];
                items[j] = temp;
            }
        }
    }
    return items;
}
function initGalenPageDump(pageData) {

    var canvas = $(".image .canvas");

    for (objectName in pageData.items) {
        if (pageData.items.hasOwnProperty(objectName)) {
            var item = pageData.items[objectName];
            item.name = objectName;
            item.id = _pageItems.length;
            item.selected = false;
            _pageItems.push(item);
        }
    }

    //sorting items by name
    var sortedItems = sortItemsByName(_pageItems);
    for (var i = 0; i<sortedItems.length; i++) {
        sortedItems[i].id = i;
        renderPageItem(canvas, sortedItems[i]); 
    }

    canvas.click(function (event) {
        var offset = $(this).offset();
        var x = event.pageX - offset.left;
        var y = event.pageY - offset.top;

        //Finding the closest to the rect

        var minDistance = 1000000;
        var selectedId = -1;
        for (var i = 0; i < _pageItems.length; i++) {
           var distance = distanceInsideRect(_pageItems[i].area, x, y);
           if (distance > -1 && distance < minDistance) {
               selectedId = i;
               minDistance = distance;
           }
        }

        if (selectedId >=0 ) {
            selectItem(selectedId);
        }
    });
}


{'fraction_non_alphanumeric': 0.14172089660159073, 'fraction_numerical': 0.013497228247770547, 'mean_word_length': 1.8116531165311653, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 12, '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': '6951513', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1310, 'n_words': 316}