Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
optimized XGMML export (json intermediate no longer necessary)
  • Loading branch information
proost committed Jan 8, 2016
1 parent 9c83620 commit b6a473a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
13 changes: 1 addition & 12 deletions planet/static/js/planet_graph.js
Expand Up @@ -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));
Expand Down
1 change: 0 additions & 1 deletion planet/static/js/planet_svg_legend.js
Expand Up @@ -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');
}
Expand Down
28 changes: 14 additions & 14 deletions planet/static/js/planet_xgmml.js
Expand Up @@ -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' );
Expand All @@ -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();
Expand Down

0 comments on commit b6a473a

Please sign in to comment.