Coder Social home page Coder Social logo

raszi / export-svg-chart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thibaudcolas/export-svg-chart

0.0 1.0 0.0 17 KB

Converts SVG+CSS charts built with front-end technologies like D3 into SVG/PNG Node buffers for server-side use.

Home Page: http://blog.thib.me/exporting-d3-charts-to-svg-and-png

JavaScript 100.00%

export-svg-chart's Introduction

export-svg-chart npm Build Status dependency Status devDependency Status

Converts SVG+CSS charts built with front-end technologies like D3 into SVG/PNG Node buffers for server-side use.

Install

This package requires node 4 or above.

npm install export-svg-chart --save

Example

To get SVG and PNG exports of your chart, you need to point the library towards a page that takes care of rendering it. This can be a dynamic rendering with UI elements, or an "export/print"-specific page with another skin for the chart.

const fs = require('fs');
const exportSvgChart = require('export-svg-chart');

const options = {
    url: 'http://bl.ocks.org/mbostock/raw/7341714/',
    selector: '.chart',
};

exportSvgChart(options, (err, buffers) => {
    if (err) return console.log(err);

    fs.writeFile('basic-example.svg', buffers.svg);
    fs.writeFile('basic-example.png', buffers.pngs);
});

http://bl.ocks.org/mbostock/raw/7341714/ becomes:

basic example PNG

Basic example SVG

What it does

Under the hood, this is using Electron which uses Chromium's rendering engine. The export is generated with saveSvgAsPng.

Caveats

  • saveSvgAsPng doesn't support inlining of font face definitions (yet).
  • If the chart is styled with ancestor selectors that are outside of it, the selectors need to be re-mapped when they are inlined. This isn't supported within this library at the moment.

export-svg-chart's People

Contributors

thibaudcolas avatar

Watchers

James Cloos avatar

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.