rbbt.plots.graph.build_d3 = function(graph_model){ var model = rbbt.plots.graph.consolidate(graph_model) var node_index = {} for (i=0; i< model.nodes.length; i++) node_index[model.nodes[i].code] = i for (i=0; i< model.edges.length; i++){ var edge = model.edges[i] edge.source = node_index[edge.source] edge.target = node_index[edge.target] } model.links = model.edges model.edges = undefined model.node_index = node_index return model } rbbt.plots.graph.build_cytoscape = function(graph_model){ var model = rbbt.plots.graph.consolidate(graph_model) var dataSchema = {nodes: [], edges:[]} var node_vars = {} for (i in model.nodes){ for (p in model.nodes[i]){ if (undefined !== model.nodes[i][p]) node_vars[p] = typeof model.nodes[i][p] } } for (p in node_vars){ dataSchema.nodes.push({name: p, type: node_vars[p]}) } node_vars = {} for (i in model.edges){ for (p in model.edges[i]){ if (undefined !== model.edges[i][p]) node_vars[p] = typeof model.edges[i][p] } } for (p in node_vars){ dataSchema.edges.push({name: p, type: node_vars[p]}) } var cy_model = {} cy_model.dataSchema = dataSchema cy_model.data = model return cy_model } rbbt.plots.graph.build_cytoscapejs = function(graph_model){ var model = rbbt.plots.graph.consolidate(graph_model) var nodes = [] forArray(model.nodes, function(node){ var clean = clean_hash(node) if (undefined === clean.id) clean.id = clean.code nodes.push({data: clean}) }) var edges = [] forArray(model.edges, function(edge){ var clean = clean_hash(edge) if (undefined === clean.id) clean.id = clean.code edges.push({data: clean}) }) var cy_model = {} cy_model.elements = {nodes: nodes, edges: edges} return cy_model } rbbt.plots.graph.view_cytoscapejs = function(graph_model, elem, style, layout, extra){ var default_style = [ // the stylesheet for the graph // Default values { selector: 'node', style: { 'background-color': 'blue', 'label': 'data(id)' } }, { selector: 'edge', style: { 'width': 1, 'line-color': 'grey', 'target-arrow-color': '#ccc', 'target-arrow-shape': 'triangle' } }, { selector: 'node[label]', style: {'label': 'data(label)' } }, { selector: 'node[color]', style: { 'background-color': 'data(color)' } }, { selector: 'node[shape]', style: { 'shape': 'data(shape)' } }, { selector: 'edge[color]', style: { 'line-color': 'data(color)', 'target-arrow-color': 'data(color)'} }, { selector: 'edge[target-arrow-shape]', style: { 'target-arrow-shape': 'data(target-arrow-shape)'} }, { selector: 'edge[target-arrow-color]', style: { 'target-arrow-color': 'data(target-arrow-color)'} } ] var default_layout = { name: 'cose' } if (undefined === style) style = default_style if (undefined === layout) layout = default_layout var deferred = m.deferred() rbbt.plots.graph.update(graph_model).then(function(updated_model){ var cy_model = rbbt.plots.graph.build_cytoscapejs(updated_model) require_js(['/plugins/cytoscapejs/cytoscape.js'], function(){ var cy_params = { container: elem, elements: cy_model.elements, style: style, } if (undefined !== extra) forHash(extra, function(k,v){ cy_params[k,v] }) var cy = cytoscape(cy_params) cy.layout(default_layout) cy.one('layoutready', function(){ deferred.resolve(this) }) }) }, rbbt.exception.report) return deferred.promise } rbbt.plots.graph.view_cytoscape = function(graph_model, elem, style, layout, extra){ rbbt.plots.graph.update(graph_model).then(function(updated_model){ var dataset = rbbt.plots.graph.build_cytoscape(updated_model) require_js(['/js/cytoscape/js/src/AC_OETags.js', '/js/cytoscape/js/src/cytoscapeweb.js', '/js/cytoscape'], function(){ var win = elem.find('.window') if (win.length == 0){ win = $('