From b6a473a783414d8c3a248af465af402071109e0a Mon Sep 17 00:00:00 2001 From: proost Date: Fri, 8 Jan 2016 11:56:35 +0100 Subject: [PATCH] optimized XGMML export (json intermediate no longer necessary) --- planet/static/js/planet_graph.js | 13 +------------ planet/static/js/planet_svg_legend.js | 1 - planet/static/js/planet_xgmml.js | 28 +++++++++++++-------------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/planet/static/js/planet_graph.js b/planet/static/js/planet_graph.js index 62a252f..ca09741 100644 --- a/planet/static/js/planet_graph.js +++ b/planet/static/js/planet_graph.js @@ -297,19 +297,8 @@ $('#cy-download-jsoncy').click(function(ev) { $('#cy-download-xgmml').click(function(ev) { ev.preventDefault(); - var eles = cy.elements(); - - eles.each( function(i, ele) { - if (ele.isNode()) { - ele.data('current_color', ele.renderedStyle('background-color')); - ele.data('current_shape', ele.renderedStyle('shape')); - } else if (ele.isEdge()) { - ele.data('current_color', ele.renderedStyle('line-color')); - ele.data('current_width', ele.renderedStyle('width')); - } - }); - xgmml = writeXGMML(cy.json()); + xgmml = writeXGMML(cy); var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(xgmml)); diff --git a/planet/static/js/planet_svg_legend.js b/planet/static/js/planet_svg_legend.js index bf2f188..ef2af26 100644 --- a/planet/static/js/planet_svg_legend.js +++ b/planet/static/js/planet_svg_legend.js @@ -117,7 +117,6 @@ function generate_legend(label_set, attribute) { var document_height = parseInt(svg_legend.attr('height').replace('px','')); if (total_height > document_height) { var viewbox = svg_legend.attr('viewBox'); - console.log(viewbox); svg_legend.attr('viewBox', '0 0 750 ' + total_height); svg_legend.attr('height', total_height + 'px'); } diff --git a/planet/static/js/planet_xgmml.js b/planet/static/js/planet_xgmml.js index 8f16590..a9430b5 100644 --- a/planet/static/js/planet_xgmml.js +++ b/planet/static/js/planet_xgmml.js @@ -63,30 +63,30 @@ function writeXGMML(data) { xw.writeAttributeString( 'value', '#ffffff'); xw.writeEndElement(); - data.elements.nodes.forEach( function(node) { + data.nodes.forEach( function(node) { if (!node.data.compound) { xw.writeStartElement( 'node' ); - xw.writeAttributeString( 'id', node.data.id ); - xw.writeAttributeString( 'label', node.data.name ); + xw.writeAttributeString( 'id', node.data('id') ); + xw.writeAttributeString( 'label', node.data('name') ); xw.writeAttributeString( 'name', 'base' ); xw.writeStartElement( 'att' ); xw.writeAttributeString( 'label', 'gene_name' ); xw.writeAttributeString( 'name', 'gene_name' ); - xw.writeAttributeString( 'value', node.data.gene_name ); + xw.writeAttributeString( 'value', node.data('gene_name') ); xw.writeAttributeString( 'type', 'string'); xw.writeEndElement(); xw.writeStartElement( 'graphics' ); xw.writeAttributeString( 'width', '1' ); - xw.writeAttributeString( 'fill', __convertColor(node.data.current_color) ); + xw.writeAttributeString( 'fill', __convertColor(node.renderedStyle('background-color')) ); xw.writeAttributeString( 'outline', "#000000" ); xw.writeAttributeString( 'x', node.position.x); xw.writeAttributeString( 'y', node.position.y); xw.writeAttributeString( 'h', '30.0'); xw.writeAttributeString( 'w', '30.0'); - xw.writeAttributeString( 'type', __convertShape(node.data.current_shape) ); + xw.writeAttributeString( 'type', __convertShape(node.renderedStyle('shape')) ); xw.writeStartElement( 'att' ); xw.writeAttributeString( 'name', 'cytoscapeNodeGraphicsAttributes' ); @@ -112,17 +112,17 @@ function writeXGMML(data) { } }); - data.elements.edges.forEach( function(edge) { + data.edges.forEach( function(edge) { xw.writeStartElement( 'edge' ); - xw.writeAttributeString( 'id', edge.data.id ); - xw.writeAttributeString( 'label', edge.data.id ); - xw.writeAttributeString( 'source', edge.data.source ); - xw.writeAttributeString( 'target', edge.data.target ); + xw.writeAttributeString( 'id', edge.data('id') ); + xw.writeAttributeString( 'label', edge.data('id') ); + xw.writeAttributeString( 'source', edge.data('source') ); + xw.writeAttributeString( 'target', edge.data('target') ); xw.writeStartElement( 'graphics' ); - xw.writeAttributeString( 'width', edge.data.current_width.replace('px', '') ); - xw.writeAttributeString( 'fill', __convertColor(edge.data.current_color) ); - if (edge.data.homology) { + xw.writeAttributeString( 'width', edge.renderedStyle('width').replace('px', '') ); + xw.writeAttributeString( 'fill', __convertColor(edge.renderedStyle('line-color')) ); + if (edge.data('homology')) { xw.writeAttributeString( 'EDGE_LINE_TYPE', 'LONG_DASH' ); } xw.writeEndElement();