@@ -28,7 +28,9 @@ var modebarButtons = module.exports = {};
28
28
* @param {string } [gravity]
29
29
* icon positioning
30
30
* @param {function } click
31
- * click handler associated with the button
31
+ * click handler associated with the button, a function of
32
+ * 'gd' (the main graph object) and
33
+ * 'ev' (the event object)
32
34
* @param {string } [attr]
33
35
* attribute associated with button,
34
36
* use this with 'val' to keep track of the state
@@ -42,7 +44,7 @@ modebarButtons.toImage = {
42
44
name : 'toImage' ,
43
45
title : 'Download plot as a png' ,
44
46
icon : 'camera' ,
45
- click : function ( modebar ) {
47
+ click : function ( gd ) {
46
48
var format = 'png' ;
47
49
48
50
if ( Lib . isIE ( ) ) {
@@ -51,22 +53,22 @@ modebarButtons.toImage = {
51
53
return ;
52
54
}
53
55
54
- if ( modebar . _snapshotInProgress ) {
56
+ if ( gd . _snapshotInProgress ) {
55
57
Lib . notifier ( 'Snapshotting is still in progress - please hold' , 'long' ) ;
56
58
return ;
57
59
}
58
60
59
- modebar . _snapshotInProgress = true ;
61
+ gd . _snapshotInProgress = true ;
60
62
Lib . notifier ( 'Taking snapshot - this may take a few seconds' , 'long' ) ;
61
63
62
- var ev = Snapshot . toImage ( modebar . graphInfo , { format : format } ) ;
64
+ var ev = Snapshot . toImage ( gd , { format : format } ) ;
63
65
64
- var filename = modebar . graphInfo . fn || 'newplot' ;
66
+ var filename = gd . fn || 'newplot' ;
65
67
filename += '.' + format ;
66
68
67
69
ev . once ( 'success' , function ( result ) {
68
70
69
- modebar . _snapshotInProgress = false ;
71
+ gd . _snapshotInProgress = false ;
70
72
71
73
var downloadLink = document . createElement ( 'a' ) ;
72
74
downloadLink . href = result ;
@@ -80,7 +82,7 @@ modebarButtons.toImage = {
80
82
} ) ;
81
83
82
84
ev . once ( 'error' , function ( err ) {
83
- modebar . _snapshotInProgress = false ;
85
+ gd . _snapshotInProgress = false ;
84
86
85
87
Lib . notifier ( 'Sorry there was a problem downloading your ' + format , 'long' ) ;
86
88
console . error ( err ) ;
@@ -94,8 +96,7 @@ modebarButtons.sendDataToCloud = {
94
96
name : 'sendDataToCloud' ,
95
97
title : 'Save and edit plot in cloud' ,
96
98
icon : 'disk' ,
97
- click : function ( modebar ) {
98
- var gd = modebar . graphInfo ;
99
+ click : function ( gd ) {
99
100
Plotly . Plots . sendDataToCloud ( gd ) ;
100
101
}
101
102
} ;
@@ -176,19 +177,18 @@ modebarButtons.hoverCompareCartesian = {
176
177
click : handleCartesian
177
178
} ;
178
179
179
- function handleCartesian ( modebar , ev ) {
180
+ function handleCartesian ( gd , ev ) {
180
181
var button = ev . currentTarget ,
181
182
astr = button . getAttribute ( 'data-attr' ) ,
182
183
val = button . getAttribute ( 'data-val' ) || true ,
183
- graphInfo = modebar . graphInfo ,
184
- fullLayout = graphInfo . _fullLayout ,
184
+ fullLayout = gd . _fullLayout ,
185
185
aobj = { } ;
186
186
187
187
if ( astr === 'zoom' ) {
188
188
var mag = ( val === 'in' ) ? 0.5 : 2 ,
189
189
r0 = ( 1 + mag ) / 2 ,
190
190
r1 = ( 1 - mag ) / 2 ,
191
- axList = Plotly . Axes . list ( graphInfo , null , true ) ;
191
+ axList = Plotly . Axes . list ( gd , null , true ) ;
192
192
193
193
var ax , axName , initialRange ;
194
194
@@ -212,7 +212,8 @@ function handleCartesian(modebar, ev) {
212
212
}
213
213
}
214
214
}
215
- } else {
215
+ }
216
+ else {
216
217
// if ALL traces have orientation 'h', 'hovermode': 'x' otherwise: 'y'
217
218
if ( astr === 'hovermode' && ( val === 'x' || val === 'y' ) ) {
218
219
val = fullLayout . _isHoriz ? 'y' : 'x' ;
@@ -222,17 +223,15 @@ function handleCartesian(modebar, ev) {
222
223
aobj [ astr ] = val ;
223
224
}
224
225
225
- Plotly . relayout ( graphInfo , aobj ) . then ( function ( ) {
226
- modebar . updateActiveButton ( ) ;
226
+ Plotly . relayout ( gd , aobj ) . then ( function ( ) {
227
227
if ( astr === 'dragmode' ) {
228
228
if ( fullLayout . _hasCartesian ) {
229
229
Plotly . Fx . setCursor (
230
230
fullLayout . _paper . select ( '.nsewdrag' ) ,
231
231
{ pan :'move' , zoom :'crosshair' } [ val ]
232
232
) ;
233
233
}
234
- Plotly . Fx . supplyLayoutDefaults ( graphInfo . layout , fullLayout ,
235
- graphInfo . _fullData ) ;
234
+ Plotly . Fx . supplyLayoutDefaults ( gd . layout , fullLayout , gd . _fullData ) ;
236
235
}
237
236
} ) ;
238
237
}
@@ -273,11 +272,10 @@ modebarButtons.tableRotation = {
273
272
click : handleDrag3d
274
273
} ;
275
274
276
- function handleDrag3d ( modebar , ev ) {
275
+ function handleDrag3d ( gd , ev ) {
277
276
var button = ev . currentTarget ,
278
277
attr = button . getAttribute ( 'data-attr' ) ,
279
278
val = button . getAttribute ( 'data-val' ) || true ,
280
- graphInfo = modebar . graphInfo ,
281
279
layoutUpdate = { } ;
282
280
283
281
layoutUpdate [ attr ] = val ;
@@ -286,9 +284,7 @@ function handleDrag3d(modebar, ev) {
286
284
* Dragmode will go through the relayout -> doplot -> scene.plot()
287
285
* routine where the dragmode will be set in scene.plot()
288
286
*/
289
- Plotly . relayout ( graphInfo , layoutUpdate ) . then ( function ( ) {
290
- modebar . updateActiveButton ( ) ;
291
- } ) ;
287
+ Plotly . relayout ( gd , layoutUpdate ) ;
292
288
}
293
289
294
290
modebarButtons . resetCameraDefault3d = {
@@ -307,11 +303,11 @@ modebarButtons.resetCameraLastSave3d = {
307
303
click : handleCamera3d
308
304
} ;
309
305
310
- function handleCamera3d ( modebar , ev ) {
306
+ function handleCamera3d ( gd , ev ) {
311
307
var button = ev . currentTarget ,
312
308
attr = button . getAttribute ( 'data-attr' ) ,
313
- layout = modebar . graphInfo . layout ,
314
- fullLayout = modebar . graphInfo . _fullLayout ,
309
+ layout = gd . layout ,
310
+ fullLayout = gd . _fullLayout ,
315
311
sceneIds = Plotly . Plots . getSubplotIds ( fullLayout , 'gl3d' ) ;
316
312
317
313
for ( var i = 0 ; i < sceneIds . length ; i ++ ) {
@@ -343,11 +339,10 @@ modebarButtons.hoverClosest3d = {
343
339
toggle : true ,
344
340
icon : 'tooltip_basic' ,
345
341
gravity : 'ne' ,
346
- click : function ( modebar , ev ) {
342
+ click : function ( gd , ev ) {
347
343
var button = ev . currentTarget ,
348
344
val = JSON . parse ( button . getAttribute ( 'data-val' ) ) || false ,
349
- graphInfo = modebar . graphInfo ,
350
- fullLayout = graphInfo . _fullLayout ,
345
+ fullLayout = gd . _fullLayout ,
351
346
sceneIds = Plotly . Plots . getSubplotIds ( fullLayout , 'gl3d' ) ;
352
347
353
348
var axes = [ 'xaxis' , 'yaxis' , 'zaxis' ] ,
@@ -385,9 +380,7 @@ modebarButtons.hoverClosest3d = {
385
380
button . setAttribute ( 'data-val' , JSON . stringify ( currentSpikes ) ) ;
386
381
}
387
382
388
- Plotly . relayout ( graphInfo , layoutUpdate ) . then ( function ( ) {
389
- modebar . updateActiveButton ( button ) ;
390
- } ) ;
383
+ Plotly . relayout ( gd , layoutUpdate ) ;
391
384
}
392
385
} ;
393
386
@@ -429,11 +422,11 @@ modebarButtons.hoverClosestGeo = {
429
422
click : handleGeo
430
423
} ;
431
424
432
- function handleGeo ( modebar , ev ) {
425
+ function handleGeo ( gd , ev ) {
433
426
var button = ev . currentTarget ,
434
427
attr = button . getAttribute ( 'data-attr' ) ,
435
428
val = button . getAttribute ( 'data-val' ) || true ,
436
- fullLayout = modebar . graphInfo . _fullLayout ,
429
+ fullLayout = gd . _fullLayout ,
437
430
geoIds = Plotly . Plots . getSubplotIds ( fullLayout , 'geo' ) ;
438
431
439
432
for ( var i = 0 ; i < geoIds . length ; i ++ ) {
@@ -449,8 +442,6 @@ function handleGeo(modebar, ev) {
449
442
else if ( attr === 'reset' ) geo . zoomReset ( ) ;
450
443
else if ( attr === 'hovermode' ) geo . showHover = ! geo . showHover ;
451
444
}
452
-
453
- modebar . updateActiveButton ( button ) ;
454
445
}
455
446
456
447
modebarButtons . hoverClosestGl2d = {
@@ -461,17 +452,7 @@ modebarButtons.hoverClosestGl2d = {
461
452
toggle : true ,
462
453
icon : 'tooltip_basic' ,
463
454
gravity : 'ne' ,
464
- click : function ( modebar , ev ) {
465
- var button = ev . currentTarget ,
466
- graphInfo = modebar . graphInfo ,
467
- newHover = graphInfo . _fullLayout . hovermode ?
468
- false :
469
- 'closest' ;
470
-
471
- Plotly . relayout ( graphInfo , 'hovermode' , newHover ) . then ( function ( ) {
472
- modebar . updateActiveButton ( button ) ;
473
- } ) ;
474
- }
455
+ click : toggleHover
475
456
} ;
476
457
477
458
modebarButtons . hoverClosestPie = {
@@ -481,15 +462,11 @@ modebarButtons.hoverClosestPie = {
481
462
val : 'closest' ,
482
463
icon : 'tooltip_basic' ,
483
464
gravity : 'ne' ,
484
- click : function ( modebar ) {
485
- var graphInfo = modebar . graphInfo ,
486
- newHover = graphInfo . _fullLayout . hovermode ?
487
- false :
488
- 'closest' ;
489
-
490
- Plotly . relayout ( graphInfo , 'hovermode' , newHover ) . then ( function ( ) {
491
- modebar . updateActiveButton ( ) ;
492
- } ) ;
493
-
494
- }
465
+ click : toggleHover
495
466
} ;
467
+
468
+ function toggleHover ( gd ) {
469
+ var newHover = gd . _fullLayout . hovermode ? false : 'closest' ;
470
+
471
+ Plotly . relayout ( gd , 'hovermode' , newHover ) ;
472
+ }
0 commit comments