<commit_before>/*
 * Paperscript code, defines the rendering of the node net within its canvas
 *
 * Autor: joscha
 * Date: 03.05.2012
 */


// initialization ---------------------------------------------------------------------

var viewProperties = {
    zoomFactor: 1,
    frameWidth: 100,
    activeColor: new Color("#009900"),
    inhibitedColor: new Color("#ff0000"),
    selectionColor: new Color("#0099ff"),
    hoverColor: new Color("#089AC7"),
    linkColor: new Color("#000000"),
    bgColor: new Color("#ffffff"),
    nodeColor: new Color("#c2c2d6"),
    nodeLabelColor: new Color ("#94c2f5"),
    nodeForegroundColor: new Color ("#000000"),
    nodeFontColor: new Color ("#000000"),
    fontSize: 10,
    symbolSize: 14,
    nodeWidth: 84,
    compactNodeWidth: 32,
    cornerWidth: 6,
    padding: 5,
    slotWidth: 34,
    lineHeight: 15,
    compactNodes: false,
    compactModules: false,
    forceCompactBelowZoomFactor: 0.9,
    strokeWidth: 0.3,
    outlineColor: null,
    outlineWidth: 0.3,
    outlineWidthSelected: 2.0,
    highlightColor: new Color ("#ffffff"),
    gateShadowColor: new Color("#888888"),
    shadowColor: new Color ("#000000"),
    shadowStrokeWidth: 0,
    shadowDisplacement: new Point(0.5,1.5),
    innerShadowDisplacement: new Point(0.2,0.7),
    linkTension: 50,
    linkRadius: 30,
    arrowWidth: 6,
    arrowLength: 10,
    rasterize: false
};

// hashes from uids to object definitions; we import these via json
nodes = {};
links = {};
selection = {};

linkLayer = new Layer();
linkLayer.name = 'LinkLayer';
nodeLayer = new Layer();
nodeLayer.name = 'NodeLayer';
prerenderLayer = new Layer();
prerenderLayer.name = 'PrerenderLayer';
prerenderLayer.visible = false;

currentNodenet = $.cookie('selected_nodenet') || null;
var currentNodeSpace = 'Root';   // cookie
currentWorldadapter = null;
var rootNode = new Node("Root", 0, 0, 0, "Root", "Nodespace");

var selectionRectangle = new Rectangle(1,1,1,1);
var selectionBox = new Path.Rectangle(selectionRectangle);
selectionBox.strokeWidth = 0.5;
selectionBox.strokeColor = 'black';
selectionBox.dashArray = [4,2];

nodetypes = {};

initializeMenus();
initializeControls();
initializeSidebarForms();
if(currentNodenet){
    setCurrentNodenet(currentNodenet);
} else {
    initializeNodeNet();
}

world_data = {};
currentSimulationStep = 0;
nodenetRunning = false;

refreshNodenetList();
function refreshNodenetList(){
    $("#nodenet_list").load("/nodenet_list/"+(currentNodenet || ''), function(data){
        $('#nodenet_list .nodenet_select').on('click', function(event){
            event.preventDefault();
            var el = $(event.target);
            var uid = el.attr('data');
            setCurrentNodenet(uid);
        });
    });
}

function loadWorldData(nodenet_data){
    if(nodenet_data.world){
        api("get_world_properties", {world_uid: nodenet_data.world},
            success=function(data){
                world_data = data;
                currentWorld = data.uid;
                str = '';
                for (var name in world_data.worldadapters){
                    str += '<option>'+name+'</option>';
                }
                $('#nodenet_worldadapter').html(str);
                setNodenetValues(nodenet_data);
                showDefaultForm();
        });
    } else {
        $('#nodenet_worldadapter').html('<option>&lt;No world selected&gt;</option>');
        setNodenetValues(nodenet_data);
        showDefaultForm();
    }
}

function setNodenetValues(data){
    $('#nodenet_name').val(data.name);
    var str = '';
    for (var key in nodetypes){
        str += '<tr><td>'+key+'</td></tr>';
    }
    $('#nodenet_nodetypes').html(str);
    if (!jQuery.isEmptyObject(world_data)) {
        var worldadapter_select = $('#nodenet_worldadapter');
        worldadapter_select.val(data.worldadapter);
        if(worldadapter_select.val() != data.worldadapter){
            dialogs.notification("The worldadapter of this nodenet is not compatible to the world. Please choose a worldadapter from the list", 'Error');
        }
        var i;
        str = '';
        if (world_data.worldadapters[data.worldadapter].datatargets) {
            for (i in world_data.worldadapters[data.worldadapter].datatargets){
                str += '<tr><td>'+world_data.worldadapters[data.worldadapter].datatargets[i]+'</td></tr>';
            }
        }
        $('#nodenet_datatargets').html(str || '<tr><td>No datatargets defined</td></tr>');
        str = '';
        if (world_data.worldadapters[data.worldadapter].datasources){
            for (i in world_data.worldadapters[data.worldadapter].datasources){
                str += '<tr><td>'+world_data.worldadapters[data.worldadapter].datasources[i]+'</td></tr>';
            }
        }
        $('#nodenet_datasources').html(str || '<tr><td>No datasources defined</td></tr>');
    }
}

function setCurrentNodenet(uid){
    console.log(nodetypes);
    api('load_nodenet_into_ui',
        {nodenet_uid: uid},
        function(data){
            showDefaultForm();
            $.cookie('selected_nodenet', currentNodenet, { expires: 7, path: '/' });
            if(uid != currentNodenet || jQuery.isEmptyObject(nodetypes)){
                api('get_available_node_types', {nodenet_uid:uid}, function(nodetypedata){
                    nodetypes = nodetypedata;
                    initializeNodeNet(data);
                });
            }
            currentNodenet = uid;
            $('#nodenet_step').val(data.step);
            refreshNodenetList();
        },
        function(data) {
            currentNodenet = null;
            $.cookie('selected_nodenet', '', { expires: -1, path: '/' });
            dialogs.notification(data.Error, "error");
        });
}

// fetch visible nodes and links
function initializeNodeNet(data){

    currentNodeSpace = "Root";
<commit_msg>fix nodenet cookie<commit_after>/*
 * Paperscript code, defines the rendering of the node net within its canvas
 *
 * Autor: joscha
 * Date: 03.05.2012
 */


// initialization ---------------------------------------------------------------------

var viewProperties = {
    zoomFactor: 1,
    frameWidth: 100,
    activeColor: new Color("#009900"),
    inhibitedColor: new Color("#ff0000"),
    selectionColor: new Color("#0099ff"),
    hoverColor: new Color("#089AC7"),
    linkColor: new Color("#000000"),
    bgColor: new Color("#ffffff"),
    nodeColor: new Color("#c2c2d6"),
    nodeLabelColor: new Color ("#94c2f5"),
    nodeForegroundColor: new Color ("#000000"),
    nodeFontColor: new Color ("#000000"),
    fontSize: 10,
    symbolSize: 14,
    nodeWidth: 84,
    compactNodeWidth: 32,
    cornerWidth: 6,
    padding: 5,
    slotWidth: 34,
    lineHeight: 15,
    compactNodes: false,
    compactModules: false,
    forceCompactBelowZoomFactor: 0.9,
    strokeWidth: 0.3,
    outlineColor: null,
    outlineWidth: 0.3,
    outlineWidthSelected: 2.0,
    highlightColor: new Color ("#ffffff"),
    gateShadowColor: new Color("#888888"),
    shadowColor: new Color ("#000000"),
    shadowStrokeWidth: 0,
    shadowDisplacement: new Point(0.5,1.5),
    innerShadowDisplacement: new Point(0.2,0.7),
    linkTension: 50,
    linkRadius: 30,
    arrowWidth: 6,
    arrowLength: 10,
    rasterize: false
};

// hashes from uids to object definitions; we import these via json
nodes = {};
links = {};
selection = {};

linkLayer = new Layer();
linkLayer.name = 'LinkLayer';
nodeLayer = new Layer();
nodeLayer.name = 'NodeLayer';
prerenderLayer = new Layer();
prerenderLayer.name = 'PrerenderLayer';
prerenderLayer.visible = false;

currentNodenet = $.cookie('selected_nodenet') || null;
var currentNodeSpace = 'Root';   // cookie
currentWorldadapter = null;
var rootNode = new Node("Root", 0, 0, 0, "Root", "Nodespace");

var selectionRectangle = new Rectangle(1,1,1,1);
var selectionBox = new Path.Rectangle(selectionRectangle);
selectionBox.strokeWidth = 0.5;
selectionBox.strokeColor = 'black';
selectionBox.dashArray = [4,2];

nodetypes = {};

initializeMenus();
initializeControls();
initializeSidebarForms();
if(currentNodenet){
    setCurrentNodenet(currentNodenet);
} else {
    initializeNodeNet();
}

world_data = {};
currentSimulationStep = 0;
nodenetRunning = false;

refreshNodenetList();
function refreshNodenetList(){
    $("#nodenet_list").load("/nodenet_list/"+(currentNodenet || ''), function(data){
        $('#nodenet_list .nodenet_select').on('click', function(event){
            event.preventDefault();
            var el = $(event.target);
            var uid = el.attr('data');
            setCurrentNodenet(uid);
        });
    });
}

function loadWorldData(nodenet_data){
    if(nodenet_data.world){
        api("get_world_properties", {world_uid: nodenet_data.world},
            success=function(data){
                world_data = data;
                currentWorld = data.uid;
                str = '';
                for (var name in world_data.worldadapters){
                    str += '<option>'+name+'</option>';
                }
                $('#nodenet_worldadapter').html(str);
                setNodenetValues(nodenet_data);
                showDefaultForm();
        });
    } else {
        $('#nodenet_worldadapter').html('<option>&lt;No world selected&gt;</option>');
        setNodenetValues(nodenet_data);
        showDefaultForm();
    }
}

function setNodenetValues(data){
    $('#nodenet_name').val(data.name);
    var str = '';
    for (var key in nodetypes){
        str += '<tr><td>'+key+'</td></tr>';
    }
    $('#nodenet_nodetypes').html(str);
    if (!jQuery.isEmptyObject(world_data)) {
        var worldadapter_select = $('#nodenet_worldadapter');
        worldadapter_select.val(data.worldadapter);
        if(worldadapter_select.val() != data.worldadapter){
            dialogs.notification("The worldadapter of this nodenet is not compatible to the world. Please choose a worldadapter from the list", 'Error');
        }
        var i;
        str = '';
        if (world_data.worldadapters[data.worldadapter].datatargets) {
            for (i in world_data.worldadapters[data.worldadapter].datatargets){
                str += '<tr><td>'+world_data.worldadapters[data.worldadapter].datatargets[i]+'</td></tr>';
            }
        }
        $('#nodenet_datatargets').html(str || '<tr><td>No datatargets defined</td></tr>');
        str = '';
        if (world_data.worldadapters[data.worldadapter].datasources){
            for (i in world_data.worldadapters[data.worldadapter].datasources){
                str += '<tr><td>'+world_data.worldadapters[data.worldadapter].datasources[i]+'</td></tr>';
            }
        }
        $('#nodenet_datasources').html(str || '<tr><td>No datasources defined</td></tr>');
    }
}

function setCurrentNodenet(uid){
    console.log(nodetypes);
    api('load_nodenet_into_ui',
        {nodenet_uid: uid},
        function(data){
            showDefaultForm();
            $.cookie('selected_nodenet', uid, { expires: 7, path: '/' });
            if(uid != currentNodenet || jQuery.isEmptyObject(nodetypes)){
                api('get_available_node_types', {nodenet_uid:uid}, function(nodetypedata){
                    nodetypes = nodetypedata;
                    initializeNodeNet(data);
                });
            }
            currentNodenet = uid;
            $('#nodenet_step').val(data.step);
            refreshNodenetList();
        },
        function(data) {
            currentNodenet = null;
            $.cookie('selected_nodenet', '', { expires: -1, path: '/' });
            dialogs.notification(data.Error, "error");
        });
}

// fetch visible nodes and links
function initializeNodeNet(data){

    currentNodeSpace = "Root";

{'fraction_non_alphanumeric': 0.15715016192261802, 'fraction_numerical': 0.020282938469405147, 'mean_word_length': 2.7527982091461465, 'pattern_counts': {'":': 0, '<': 51, '<?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': '1064518', 'n_tokens_mistral': 3742, 'n_tokens_neox': 3533, 'n_words': 698}