Skip to content

Instantly share code, notes, and snippets.

@etpinard
Last active May 9, 2016 16:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etpinard/04b60ae5161e90a85be2b6199fe89c16 to your computer and use it in GitHub Desktop.
Save etpinard/04b60ae5161e90a85be2b6199fe89c16 to your computer and use it in GitHub Desktop.
generate plotly.js attribute schema
node_modules
npm-debug.log
schema.json

plotly.js schema

Generate the plotly.js attribute schema with node.js.

How to run this thing ?

1. Setup

  • Clone this gist
  • cd into it
  • Run npm i

2. Generate the attribute schema

npm start

and see results in ./schema.json 🍻.

var fs = require('fs');
var jsdom = require('jsdom');
var plotly = fs.readFileSync('./node_modules/plotly.js/dist/plotly-with-meta.js', 'utf-8');
jsdom.env({
html: '<html><body></body></html>',
src: [plotly],
done: main
});
function main(err, window) {
var Plotly = window.Plotly;
var schema = Plotly.PlotSchema.get();
fs.writeFile('./schema.json', format(schema), function(err) {
if(err) throw err;
});
}
function format(schema) {
return JSON.stringify(schema, null, 2);
}
{
"name": "plotly.js-schema",
"version": "1.0.0",
"description": "generate plotly.js attribute schema",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "Étienne Tétreault-Pinard",
"license": "MIT",
"dependencies": {
"jsdom": "^9.0.0",
"plotly.js": "^1.10.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment