npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-highcharts-exporter

v0.0.6

Published

A basic Node.js package to export SVG sent by Highcharts into SVG, PNG, PDF, or JPG

Downloads

11

Readme

node-highcharts-exporter

Build Status

A basic Node.js Highcharts export module for converting the SVG sent by Highcharts's export module into svg (i.e. unaltered), jpeg, png, or pdf.

Usage

In your node app file:

// Assume this is executed inside the POST handler for a server
// running on http://localhost:3000/export
var nhe = require('node-highcharts-exporter');
nhe.exportChart(highchartsExportRequest, function(error, exportedChartInfo){
    if(error){
        console.log('Uh oh!',error.message);
        // Can send error message back to client
    } else{
        console.log('Exported chart. Here are the deets:', exportedChartInfo);
        // Can send exported chart back to client here. The chart's
        // path is in exportedChartInfo.filePath
    }
});

In your client-side Highcharts code:

new Highcharts.Chart({
    // some chart options
    exporting:{
        url: 'http://localhost:3000/export'
    }
    // more chart options
});

Demo

Start a server:

$ cd example;     // The example directory inside this module
$ npm install;    // Installs demo dependencies
$ node server.js; // Start the demo server listening on 'http://localhost:3000'

Now open example/demo.html in the browser and export the demo chart to any format.

Installation

One of its dependencies is netpbm utilities for conversion to jpeg. As described by node-netpbm, this needs some minor setup outside of npm and node. At this juncture, node-netpbm works on most *nix and OSX OSes, but no guarantees are made for Windows. It's not the end of the game, however, if you're running this on Windows and it doesn't work if your use case can do without jpeg exporting as it should work with png and pdf still. On OSX, a simple brew install netpbm takes care of the installation. After that, you can proceed to:

$ npm install -g node-highcharts-exporter

Methods

  • exportChart(exportRequest, callback): exportRequest is the request POSTed by Highcharts as described here. callback is a function with two parameters error and exportedChartInfo as below:
    // error object
    {
        message : 'Some error'
    }

    // exportedChartInfo object
    {
        fileName  : 'myChart',     // The name of the chart
        file      : 'myChart.png', // The name of the chart plus its extension
        type      : 'png',         // The type of file (png,svg,pdf,jpeg)
        parentDir : 'path/to/processingDir/exportRequestHash', // The directory where the file has been stored
        filePath  : 'path/to/processingDir/exportRequestHash/myChart.png' // Absolute path to exported chart
    }
  • config.set(configPropertyName, configPropertyValue) and config.get(): Setter and getter for config object. The getter returns the entire config object. At the moment, the config object is simply:
    {
        processingDir : 'defaults/to/directory/of/this/module' // If doesn't exist, will be created.
    }

Limitations

  • Handles only SVG, not JSON for rendering server-side like other solutions out there.
  • Does exporting a quick and dirty way by converting everything that is not SVG to PNG first then to PDF or JPEG.

To-dos

  • Handle chart sizes neatly to fit into PDF (if too big at the moment they'll get truncated)
  • Make an exportChartSync (if there is interest. It's hard with dependencies only having async methods themselves)
  • Enable a logging scheme (?)
  • Investigate JSON-based server-side rendering as an option