Git Product home page Git Product logo

cytoscape-svg's Introduction

cytoscape-svg

Description

Export the current graph view as an SVG image. (demo)

The exported SVG can be saved as a PDF with svg2pdf.js libary. See an example in demo.html

Dependencies

  • Cytoscape.js ^3.2.0
  • canvas2svg

Usage instructions

Download the library:

  • via npm: npm install cytoscape-svg,
  • via bower: bower install cytoscape-svg, or
  • via direct download in the repository (probably from a tag).

Import the library as appropriate for your project:

ES import:

import cytoscape from 'cytoscape';
import svg from 'cytoscape-svg';

cytoscape.use( svg );

CommonJS require:

let cytoscape = require('cytoscape');
let svg = require('cytoscape-svg');

cytoscape.use( svg ); // register extension

AMD:

require(['cytoscape', 'cytoscape-svg'], function( cytoscape, svg ){
  svg( cytoscape ); // register extension
});

Plain HTML/JS has the extension registered for you automatically, because no require() is needed.

API

cy.svg(options)
  • options: the export options
    • full: Whether to export the current viewport view (false, default) or the entire graph (true).
    • scale: This value specifies a positive number that scales the size of the resultant image.
    • bg: The background color of the SVG (transparent by default).

Build targets

  • npm run test : Run Mocha tests in ./test
  • npm run build : Build ./src/** into cytoscape-svg.js
  • npm run watch : Automatically build on changes with live reloading (N.b. you must already have an HTTP server running)
  • npm run dev : Automatically build on changes with live reloading with webpack dev server
  • npm run lint : Run eslint on the source

N.b. all builds use babel, so modern ES features can be used in the src.

Publishing instructions

This project is set up to automatically be published to npm and bower. To publish:

  1. Build the extension : npm run build:release
  2. Commit the build : git commit -am "Build for release"
  3. Bump the version number and tag: npm version major|minor|patch
  4. Push to origin: git push && git push --tags
  5. Publish to npm: npm publish .
  6. If publishing to bower for the first time, you'll need to run bower register cytoscape-svg https://github.com/kinimesi/cytoscape-svg.git
  7. Make a new release for Zenodo.

cytoscape-svg's People

Contributors

kinimesi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cytoscape-svg's Issues

Add element's id in SVG

Hi !

After exporting the graph to svg, we observe that there is no id for the different elements which makes their selection difficult.
Would it be possible to include specific identifiers for each of them ?

Shape and color issues

First, thank you for this, it looks like there are some style features that this (or the libraries it uses) fails to render as expected. Is there a supported style reference list? If there is I would evaluate changing my styles in order to get a good svg output.

I was surprised both by what it renders well, and just as surprised by the rest.

Here is an example cytoscape.js view
image

and the svg output
image

'edge-text-rotation': 'autorotate' breaks colors

As soon as I display any labels using 'edge-text-rotation': 'autorotate', the SVG loses all colors and just becomes black and white. See the attached image of a correctly displayed and an incorrectly displayed image. As soon as I remove the edge text rotation, it works again.

svg-autorotate-bug

Selector

  {
      'selector': 'edge',
      'css':
      {
        'z-compound-depth': 'bottom',
        'width': 2.0,
        'edge-text-rotation': 'autorotate',
        'label': function(edge)
        {
          return "bla";
        },
}

Export to PDF

Hey, thanks for this great package; it still works well for me. I would also like to export as PDF, specifically a PDF that contains only the SVG file. I assume this should be relatively easy, but I failed to do it myself. I mostly tried using https://github.com/yWorks/svg2pdf.js.

Export nodeHTML content

Hi,

I am using the plugin cytoscape-node-html-label to display information in nodes. When I export the graph using your library I loose the content of those nodes. Is there any way to export those information ?

Many thanks in advance,

David

Cannot download .svg picture

Hi I tried using the cytoscape-svg library to download my network in .svg format but it didnt work. I had the below error:
image

Below is the code which I have:

     const downloadPng = (cyToDownload, picFormat) => {
        if (picFormat == 'png') {
          const png = cyToDownload.png()
          var a = document.createElement("a"); //Create <a>
          a.href = png
          a.download = "local_network.png"; //File name Here
          a.click(); //Download file
        } 

        else if (picFormat == 'jpg') {
        const jpg = cyToDownload.jpg()
        var a = document.createElement("a"); //Create <a>
        a.href = jpg
        a.download = "local_network.jpg"; //File name Here
        a.click(); //Download file
        } 

        else if (picFormat == 'svg') {
        console.log("download func called")
        const svgPic = cyToDownload.svg()
        console.log(svgPic)
        var a = document.createElement("a"); //Create <a>
        a.href = svgPic
        a.download = "local_network.svg"; //File name Here
        a.click(); //Download file
        }
  }

So my functions to download my network in png and jpg work, so I don't know why it can't download the network in .svg format. Could I get some help please?

Thank you
Jonathan

background color

Is there a way to set the background color? My application has a black background but the SVG gets exported with a white background.

border not exported

when i add to the node element an image background with
'background-image': svgpin_Url,

where earlier i have:

const svg_pin =  '<svg width="400" height="5" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M 90 0 v 1 h 220 v -1 z" fill="black"></path></svg>';
const svgpin_Url = encodeURI("data:image/svg+xml;utf-8," + svg_pin);

then when the svg is exported, the border line of the node is not exported anymore.

Error: Attempted to apply path command to node g

Hello,

I am using the SVG plugin with default options and it doesn't work, throwing the following error:

Attempted to apply path command to node g
| ctx.__applyCurrentDefaultPath | @ | cytoscape-svg.js:826
  | ctx.stroke | @ | cytoscape-svg.js:1000
  | drawBorder | @ | cytoscape.cjs.js:29898
  | push.ROFb.CRp$5.drawNode | @ | cytoscape.cjs.js:29972
  | push.ROFb.CRp$1.drawElement | @ | cytoscape.cjs.js:28547
  | push.ROFb.CRp$1.drawElements | @ | cytoscape.cjs.js:28708
  | CRp.bufferCanvasImage | @ | cytoscape-svg.js:197
  | CRp.svg | @ | cytoscape-svg.js:214
  | export | @ | cytoscape-chart.proxy.ts:501
  | (anonymous) | @ | cytoscape-chart.proxy.ts:440
  | (anonymous) | @ | tslib.es6.js:76
  | ZoneAwarePromise | @ | zone-evergreen.js:1387
  | __awaiter | @ | tslib.es6.js:72

Please advise.
Best Regards
Alexander

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.