Skip to content

Instantly share code, notes, and snippets.

@etpinard
Created May 5, 2017 23:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save etpinard/bb51194651cdb40fa7bcb1f35c34963e to your computer and use it in GitHub Desktop.
Save etpinard/bb51194651cdb40fa7bcb1f35c34963e to your computer and use it in GitHub Desktop.
plotly.js use modebar buttons handlers
node_modules
bundle.js
<body>
<script src="bundle.js"></script>
</body>
var Plotly = require('plotly.js')
var ModeBarButtons = require('plotly.js/src/components/modebar/buttons.js')
var gd = document.createElement('div')
var btn = document.createElement('button')
document.body.appendChild(gd)
document.body.appendChild(btn)
Plotly.newPlot(gd, [{
y: [1, 2, 1],
line: { shape: 'spline' }
}])
btn.innerHTML = 'RESET'
btn.setAttribute('data-attr', 'zoom')
btn.setAttribute('data-val', 'reset')
btn.onclick = function (ev) {
ModeBarButtons.resetScale2d.click(gd, ev)
}
{
"name": "plotly.js-use-modebar-buttons-handlers",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "browserify index.js > bundle.js",
"start": "http-server -p 9999"
},
"keywords": [],
"author": "Étienne Tétreault-Pinard <etienne.t.pinard@gmail.com>",
"license": "MIT",
"dependencies": {
"browserify": "^14.3.0",
"http-server": "^0.10.0",
"plotly.js": "^1.26.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment