Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8aaad6e

Browse files
author
mahdis-z
committed
modebar buttons
1 parent b583373 commit 8aaad6e

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: Add Buttons to ModeBar
3+
plot_url: https://codepen.io/plotly/embed/gObEmLr/?height=450&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: configuration
6+
order: 5.7
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
The following example shows how to add a button to your modebar, either using one of the [Plotly icons](https://github.com/plotly/plotly.js/blob/master/src/fonts/ploticon.js) or an [arbitrary icon](https://fontawesome.com/icons?d=gallery&m=free) with a custom behaviour.
11+
---
12+
var icon1 = {
13+
'width': 500,
14+
'height': 600,
15+
'path':'M224 512c35.32 0 63.97-28.65 63.97-64H160.03c0 35.35 28.65 64 63.97 64zm215.39-149.71c-19.32-20.76-55.47-51.99-55.47-154.29 0-77.7-54.48-139.9-127.94-155.16V32c0-17.67-14.32-32-31.98-32s-31.98 14.33-31.98 32v20.84C118.56 68.1 64.08 130.3 64.08 208c0 102.3-36.15 133.53-55.47 154.29-6 6.45-8.66 14.16-8.61 21.71.11 16.4 12.98 32 32.1 32h383.8c19.12 0 32-15.6 32.1-32 .05-7.55-2.61-15.27-8.61-21.71z'}
16+
var colors = ['green', 'red', 'blue']
17+
var data = [{
18+
mode: 'lines',
19+
y: [2, 1, 2],
20+
line: {color: colors[0], width: 3, shape: 'spline'}}]
21+
var layout = {
22+
title: 'add mode bar button with custom icon',
23+
modebardisplay: false}
24+
var config = {
25+
modeBarButtonsToAdd: [
26+
{
27+
name: 'color toggler',
28+
icon: icon1,
29+
click: function(gd) {
30+
var newColor = colors[Math.floor(3 * Math.random())]
31+
Plotly.restyle(gd, 'line.color', newColor)
32+
}},
33+
{
34+
name: 'button1',
35+
icon: Plotly.Icons.pencil,
36+
direction: 'up',
37+
click: function(gd) {alert('button1')
38+
}}],
39+
modeBarButtonsToRemove: ['pan2d','select2d','lasso2d','resetScale2d','zoomOut2d']}
40+
41+
Plotly.newPlot('graph', data, layout, config)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Display the Modebar
3+
plot_url: https://codepen.io/plotly/embed/jbMvLq/?height=450&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: configuration
6+
order: 4
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
When you hover over the top right of a Plotly graph, a bar appears which we call it `modeBar`. To display or hide this modebar set `displayModeBar` in `config` to `true` or `false`.
11+
---
12+
var data = {
13+
y:['Marc', 'Henrietta', 'Jean', 'Claude', 'Jeffrey', 'Jonathan', 'Jennifer', 'Zacharias'],
14+
x: [90, 40, 60, 80, 75, 92, 87, 73],
15+
type: 'bar',
16+
orientation: 'h'
17+
};
18+
19+
var layout = {title: 'Always Display the Modebar', showlegend: false};
20+
Plotly.newPlot('myDiv', data, layout, {displayModeBar: true});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Remove ModeBar Button
3+
plot_url: https://codepen.io/plotly/embed/OQyEaP/?height=450&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: configuration
6+
order: 5.5
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
To delete buttons from the modebar, put buttons name in an array of string and pass it to 'modeBarButtonsToRemove' in config. Here is all the buttons' names:
11+
<ul>
12+
<li>- 2D: zoom2d, pan2d, select2d, lasso2d, zoomIn2d, zoomOut2d, autoScale2d, resetScale2d</li>
13+
<li>- 3D: zoom3d, pan3d, orbitRotation, tableRotation, handleDrag3d, resetCameraDefault3d, resetCameraLastSave3d, hoverClosest3d</li>
14+
<li>- Cartesian: hoverClosestCartesian, hoverCompareCartesian</li>
15+
<li>- Geo: zoomInGeo, zoomOutGeo, resetGeo, hoverClosestGeo</li>
16+
<li>- Other: hoverClosestGl2d, hoverClosestPie, toggleHover, resetViews, "toImage", "sendDataToCloud", "toggleSpikelines", “resetViewMapbox"</li>
17+
</ul>
18+
---
19+
var data = {
20+
x:['trees', 'flowers', 'hedges'],
21+
y: [90, 130, 40],
22+
type: 'bar'};
23+
24+
var layout = {
25+
title: 'Remove Modebar Buttons',
26+
showlegend: false};
27+
28+
Plotly.newPlot('myDiv', data, layout, {modeBarButtonsToRemove: ['toImage']});

0 commit comments

Comments
 (0)