Generate plotly.js images using nw.js
- 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
npm start
and 🍻.`
Generate plotly.js images using nw.js
nw
in your environment pathcd
into itnpm 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(); | |
}); | |
}); |
{ | |
"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" | |
} |