<commit_before>/*
 * LODmilla-frontend
 *
 * https://github.com/dsd-sztaki-hu/LODmilla-frontend
 *
 * Copyright (c) 2014 <NAME>, <NAME>, <NAME>, <NAME> - MTA SZTAKI DSD
 *
 */

function applyLayout(layoutType, repaint)
{
    var buffer = new Buffer();
    var name = layoutType;
    var useVirtual = document.getElementById('layoutGroupCheckBox').checked;
    var createGroups = document.getElementById('layoutCreateGroupsCheckBox').checked;
    var maxSpringTime = $('#layoutSpringSlider').slider("option", "value");
    var weight = 1;
    var virtualWeight = 1;
    initLayout(name, buffer, useVirtual, weight, virtualWeight, createGroups);
    switch(layoutType)
    {
        case Graph.LayoutEnum.GRID:
            if (createGroups) gridLayoutGroupAdaptive(buffer, 100);
            else gridLayout(buffer, 100);
            Graph.layout = Graph.LayoutEnum.GRID;
            break;
        case Graph.LayoutEnum.RADIAL:
            if (createGroups) radialLayoutGroupAdaptivePhysical(buffer, 200);
            else radialLayout(buffer, 200);
            Graph.layout = Graph.LayoutEnum.RADIAL;
            break;
        case Graph.LayoutEnum.SPRING:
            springLayout2(buffer, 10000, maxSpringTime * 1000, 100, 100, 1, 1, 10000);
            Graph.layout = Graph.LayoutEnum.SPRING;
            break;
        case Graph.LayoutEnum.SPRINGXY:
            //springLayoutXY(buffer, steps, max_time,  min_distance, grid_distance, spring_strain, spring_length)
            //springLayoutXY(buffer, 10000, maxSpringTime * 1000, 100, 100, 1, 1, 10000);
            springLayoutXY2(buffer, 10000, maxSpringTime * 1000, 100, 100, 1, 1, 10000);
            Graph.layout = Graph.LayoutEnum.SPRINGXY;
            break;
        default :
            console.log("Wrong layout type.");
    }
    finishLayout(name, repaint, buffer, createGroups);
}

//TODO undo function

function initLayout(name, buffer, useVirtual, weight, virtualWeight, createGroups)
{
    Helper.showLoadScreen();
    // console.time("Loading nodes to buffer");
    //loading nodes to buffer
    for (var index in Graph.nodes)
    {
        var act = Graph.nodes[index];
        buffer.addVertex(act.resource_id, act.label, act.weight, false, act.left, act.top, act.type);
    }
    // console.timeEnd("Loading nodes to buffer");
    // console.time("Loading edges to buffer");
    //loading edges to buffer
    var conns = jsPlumbInstance.getAllConnections();
    $.each(conns, function(conn_id, l_conn) {
        var source = $(this.source).attr('uri');
        var target = $(this.target).attr('uri');
        $.each(l_conn.getOverlays(), function(overlay_id, overlay) {
            if (overlay.type === 'Label') {
                buffer.addConnection(source, target, overlay.getLabel());
            }
        });
    });

    // console.timeEnd("Loading edges to buffer");
    if (useVirtual) {
        // console.time("Loading virtual nodes to buffer");
        addVirtualTypeNodes(buffer, virtualWeight);
//        addVirtualNodes(buffer, virtualWeight);
//         console.timeEnd("Loading virtual nodes to buffer");
    }
    buffer.createNeighboursMap();
    buffer.createConnectionMap();
    buffer.createDistanceMap();
    buffer.createConnectionCost();
    if (createGroups) {
        // console.time("Create groups");
        buffer.createGroups();
        buffer.createGroupDistanceMap();
        // console.timeEnd("Create groups");
    }

    // console.time(name + " layout");
}

function finishLayout(name, repaint, buffer, createGroups)
{
    // console.timeEnd(name + " layout");
    updateNewPosition();
    decideZoom(Graph.zoomRatio);
    if (repaint)
    {
        repaintNodes();
    }
    else Helper.closeLoadScreen();
    measureLayout(buffer, createGroups);
}

function measureLayout(buffer, createGroups)
{
    var spring_length = 100;
    var v = buffer.vertexes,
        n = buffer.neighbours, //they are connected to the same nodes<commit_msg>uncommented layout measure<commit_after>/*
 * LODmilla-frontend
 *
 * https://github.com/dsd-sztaki-hu/LODmilla-frontend
 *
 * Copyright (c) 2014 <NAME>, <NAME>, <NAME>, <NAME> - MTA SZTAKI DSD
 *
 */

function applyLayout(layoutType, repaint)
{
    var buffer = new Buffer();
    var name = layoutType;
    var useVirtual = document.getElementById('layoutGroupCheckBox').checked;
    var createGroups = document.getElementById('layoutCreateGroupsCheckBox').checked;
    var maxSpringTime = $('#layoutSpringSlider').slider("option", "value");
    var weight = 1;
    var virtualWeight = 1;
    initLayout(name, buffer, useVirtual, weight, virtualWeight, createGroups);
    switch(layoutType)
    {
        case Graph.LayoutEnum.GRID:
            if (createGroups) gridLayoutGroupAdaptive(buffer, 100);
            else gridLayout(buffer, 100);
            Graph.layout = Graph.LayoutEnum.GRID;
            break;
        case Graph.LayoutEnum.RADIAL:
            if (createGroups) radialLayoutGroupAdaptivePhysical(buffer, 200);
            else radialLayout(buffer, 200);
            Graph.layout = Graph.LayoutEnum.RADIAL;
            break;
        case Graph.LayoutEnum.SPRING:
            springLayout2(buffer, 10000, maxSpringTime * 1000, 100, 100, 1, 1, 10000);
            Graph.layout = Graph.LayoutEnum.SPRING;
            break;
        case Graph.LayoutEnum.SPRINGXY:
            //springLayoutXY(buffer, steps, max_time,  min_distance, grid_distance, spring_strain, spring_length)
            //springLayoutXY(buffer, 10000, maxSpringTime * 1000, 100, 100, 1, 1, 10000);
            springLayoutXY2(buffer, 10000, maxSpringTime * 1000, 100, 100, 1, 1, 10000);
            Graph.layout = Graph.LayoutEnum.SPRINGXY;
            break;
        default :
            console.log("Wrong layout type.");
    }
    finishLayout(name, repaint, buffer, createGroups);
}

//TODO undo function

function initLayout(name, buffer, useVirtual, weight, virtualWeight, createGroups)
{
    Helper.showLoadScreen();
    // console.time("Loading nodes to buffer");
    //loading nodes to buffer
    for (var index in Graph.nodes)
    {
        var act = Graph.nodes[index];
        buffer.addVertex(act.resource_id, act.label, act.weight, false, act.left, act.top, act.type);
    }
    // console.timeEnd("Loading nodes to buffer");
    // console.time("Loading edges to buffer");
    //loading edges to buffer
    var conns = jsPlumbInstance.getAllConnections();
    $.each(conns, function(conn_id, l_conn) {
        var source = $(this.source).attr('uri');
        var target = $(this.target).attr('uri');
        $.each(l_conn.getOverlays(), function(overlay_id, overlay) {
            if (overlay.type === 'Label') {
                buffer.addConnection(source, target, overlay.getLabel());
            }
        });
    });

    // console.timeEnd("Loading edges to buffer");
    if (useVirtual) {
        // console.time("Loading virtual nodes to buffer");
        addVirtualTypeNodes(buffer, virtualWeight);
//        addVirtualNodes(buffer, virtualWeight);
//         console.timeEnd("Loading virtual nodes to buffer");
    }
    buffer.createNeighboursMap();
    buffer.createConnectionMap();
    buffer.createDistanceMap();
    buffer.createConnectionCost();
    if (createGroups) {
        // console.time("Create groups");
        buffer.createGroups();
        buffer.createGroupDistanceMap();
        // console.timeEnd("Create groups");
    }

    // console.time(name + " layout");
}

function finishLayout(name, repaint, buffer, createGroups)
{
    // console.timeEnd(name + " layout");
    updateNewPosition();
    decideZoom(Graph.zoomRatio);
    if (repaint)
    {
        repaintNodes();
    }
    else Helper.closeLoadScreen();
    // measureLayout(buffer, createGroups);
}

function measureLayout(buffer, createGroups)
{
    var spring_length = 100;
    var v = buffer.vertexes,
        n = buffer.neighbours, //they are connected to the same nodes
{'fraction_non_alphanumeric': 0.12509476876421532, 'fraction_numerical': 0.02249178670710134, 'mean_word_length': 2.7907088122605366, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '2683271', 'n_tokens_mistral': 2442, 'n_tokens_neox': 2239, 'n_words': 515}