// Open the websocket connection var ws = new WebSocket((window.location.protocol === 'https:' ? 'wss://' : 'ws://') + window.location.host + '/ws'); // Open conection with Socket ws.onopen = function() { console.log('Connection opened!'); }; // Receive data from server ws.onmessage = function(message) { //console.log('Message received!'); var msg = JSON.parse(message.data); switch(msg['type']) { case 'trials': $('#load').removeClass('loader'); reset_trials(); set_trials(msg['data']); break; case 'get_trial': console.log(msg['data']); GraphVisualization.import(convertJSON(msg['data']['graph']), msg['data']['models'], function() { $('#load').hide(); reset_configuration(); set_configuration(); $('#home_menu').click(function() { setTimeout(function() { reset_timeline(); set_timeline(msg['data']['graph']); }, 1000); }); reset_timeline(); set_timeline(msg['data']['graph']); }); $('#charts .chart').removeClass('no-data'); set_chart_nodes(msg['data']['graph'], chart_nodes) set_chart_attrs(msg['data']['graph'], chart_attrs, $('.config-item #properties').val()) break; case 'settings': $('#wrapper-settings').empty().removeClass('none'); initGUI(msg['data']); break; case 'error': console.log(msg['error']); _socket.error(msg['error']); $('#load').removeClass('loader'); break; case 'log': $('.console').append('$ ' + msg['logger'] + ': ' + msg['logging'] + '
'); $('.console').animate({ scrollTop: $('.console')[0].scrollHeight }, 'slow'); break; default: console.log('Unexpected message!') } } var _socket = { send: function(message, type) { var json = {} json['type'] = type json['data'] = message ws.send(JSON.stringify(json)) }, error: function(message) { $('#error-message').text(message); $('.alert.alert-danger').show(); } }; var set_trials = function(trials) { for ( i in trials ) { var list_item = $('
  • ').appendTo('.dropdown#trials .dropdown-menu'); $('').val(i).text(trials[i]).appendTo(list_item); } // Select 'trials' $('.dropdown#trials li a').click(function() { var a = $('.dropdown-toggle .caret'); $('.dropdown-toggle').text($(this).text() + ' ').append(a); _socket.send($(this).val(), 'get_trial'); }); // Request first trial as default _socket.send(0, 'get_trial') }; var reset_trials = function() { // 'Trials' selector $('.dropdown-menu').empty(); var a = $('.dropdown-toggle .caret'); $('.dropdown-toggle').text('Trials ').append(a); } var convertJSON = function(json) { json.links.forEach(function(link) { link.source = json.nodes[link.source] link.target = json.nodes[link.target] }); // Fix spells for nodes json.nodes.forEach(function(node) { for (i in node.spells) { if (node.spells[i][0] > node.spells[i][1]) { aux = node.spells[i][0]; node.spells[i][0] = node.spells[i][1]; node.spells[i][1] = aux; } } }); return json; } var update_statistics_table = function() { $('#percentTable tbody').empty() var statisticsSorted = Object.keys(self.GraphVisualization.statistics).sort(function(a,b) { return self.GraphVisualization.statistics[b] - self.GraphVisualization.statistics[a]; }); for ( var i in statisticsSorted ) { if ( i <= 5 ) { // Draw table var appendTo = '#percentTable > tbody tr:nth-child(' + Number(parseInt(i) + 1) + ')'; var propertyName = (statisticsSorted[i].includes('class')) ? statisticsSorted[i].split('.').pop().split('\'')[0] : statisticsSorted[i]; $('').addClass('col-sm-12').appendTo('#percentTable > tbody'); $('').css('background-color', self.GraphVisualization.color(statisticsSorted[i])).addClass('col-sm-1').appendTo(appendTo); $('').addClass('text-left col-sm-4').text(self.GraphVisualization.statistics[statisticsSorted[i]] + ' %').appendTo(appendTo); $('').addClass('text-right col-sm-6 property-name').text(propertyName).appendTo(appendTo); } } } var set_configuration = function() { // Number of nodes and links info table $('').appendTo('#info-graph > tbody'); $('').text('Nodes:').appendTo('#info-graph > tbody tr:nth-child(1)'); $('').text(self.GraphVisualization.nodes).addClass('text-right').appendTo('#info-graph > tbody tr:nth-child(1)'); $('').appendTo('#info-graph > tbody'); $('').text('Links:').appendTo('#info-graph > tbody tr:nth-child(2)'); $('').text(self.GraphVisualization.links).addClass('text-right').appendTo('#info-graph > tbody tr:nth-child(2)'); // Options of 'Select' for ( var i in self.GraphVisualization.model['dynamic'] ) { $('