Skip to content

Instantly share code, notes, and snippets.

@eugenesvk
Last active March 31, 2016 18:20
Show Gist options
  • Save eugenesvk/2c2d656edc13e72affb68b7688c9bd48 to your computer and use it in GitHub Desktop.
Save eugenesvk/2c2d656edc13e72affb68b7688c9bd48 to your computer and use it in GitHub Desktop.
generate plotly.js images using nw.js

plotly.js in nw.js

Generate plotly.js images using nw.js

How to run this thing?

1. Setup
  • Install nw.js (see instructions)
  • Make sure that the nw.js executable is linked to nw in your environment path
  • Clone this gist and cd into it
2. Generate a graph
npm start

and 🍻.`

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>plotly.js in nw.js</title>
<!-- <script type="text/javascript" src="https://cdn.plot.ly/plotly-latest.min.js"></script> -->
<!-- <script type="text/javascript" src="node_modules/plotly.js/dist/plotly.js"></script> -->
<script type="text/javascript" src="c:\Dev\Node.js\bin\node_modules\plotly.js\lib\index.js"></script>
<script type="text/javascript" src="c:\Dev\Node.js\bin\node_modules\plotly.js\dist\plotly.js"></script>
</head>
<body>
<div id="graph"></div>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
/* global Plotly:false */
var fs = require('fs');
var gui = require('nw.gui');
var outPath = 'out.svg';
var data = [{
x: ['giraffes', 'orangutans', 'monkeys'],
y: [20, 14, 23],
type: 'bar'
}];
var layout = {
title: 'plotly graph in nw.js'
};
Plotly.plot('graph', data, layout).then(function(gd) {
var svg = Plotly.Snapshot.toSVG(gd);
fs.writeFile(outPath, svg, function(err) {
if(err) throw err;
gui.App.quit();
});
});
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"name": "nw.js-plotly.js",
"version": "1.0.0",
"description": "generate plotly.js images using nw.js",
"main": "index.html",
"scripts": {
"start": "nw ."
},
"author": "Étienne Tétreault-Pinard",
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment