@@ -2,6 +2,8 @@ var d3 = require('d3');
2
2
3
3
var Plotly = require ( '@lib/index' ) ;
4
4
var Colorbar = require ( '@src/components/colorbar' ) ;
5
+ var Plots = require ( '@src/plots/plots' ) ;
6
+ var subroutines = require ( '@src/plot_api/subroutines' ) ;
5
7
6
8
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
7
9
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -433,5 +435,71 @@ describe('Test colorbar:', function() {
433
435
. catch ( failTest )
434
436
. then ( done ) ;
435
437
} ) ;
438
+
439
+ it ( 'can edit colorbar visuals in optimized edit pathway' , function ( done ) {
440
+ spyOn ( subroutines , 'doColorBars' ) . and . callThrough ( ) ;
441
+ spyOn ( Plots , 'doCalcdata' ) . and . callThrough ( ) ;
442
+
443
+ function getOutline ( cb ) {
444
+ return Number ( cb . select ( '.cboutline' ) . node ( ) . style [ 'stroke-width' ] ) ;
445
+ }
446
+
447
+ function _assert ( msg , exp ) {
448
+ var gd3 = d3 . select ( gd ) ;
449
+ var cb0 = gd3 . select ( '.cbtrace0' ) ;
450
+ var cb1 = gd3 . select ( '.cbcoloraxis' ) ;
451
+
452
+ if ( msg !== 'base' ) {
453
+ expect ( subroutines . doColorBars ) . toHaveBeenCalledTimes ( 1 ) ;
454
+ expect ( Plots . doCalcdata ) . toHaveBeenCalledTimes ( 0 ) ;
455
+ }
456
+ subroutines . doColorBars . calls . reset ( ) ;
457
+ Plots . doCalcdata . calls . reset ( ) ;
458
+
459
+ expect ( getOutline ( cb0 ) ) . toBe ( exp . outline [ 0 ] , 'trace0 cb outline' ) ;
460
+ expect ( getOutline ( cb1 ) ) . toBe ( exp . outline [ 1 ] , 'coloraxis cb outline' ) ;
461
+ }
462
+
463
+ Plotly . newPlot ( gd , [ {
464
+ type : 'heatmap' ,
465
+ z : [ [ 1 , 2 , 3 ] , [ 2 , 1 , 2 ] ] ,
466
+ uid : 'trace0'
467
+ } , {
468
+ y : [ 1 , 2 , 3 ] ,
469
+ marker : { color : [ 2 , 1 , 2 ] , coloraxis : 'coloraxis' }
470
+ } ] , {
471
+ width : 500 ,
472
+ height : 500
473
+ } )
474
+ . then ( function ( ) { _assert ( 'base' , { outline : [ 1 , 1 ] } ) ; } )
475
+ . then ( function ( ) {
476
+ return Plotly . restyle ( gd , 'colorbar.outlinewidth' , 2 , [ 0 ] ) ;
477
+ } )
478
+ . then ( function ( ) { _assert ( 'after restyle' , { outline : [ 2 , 1 ] } ) ; } )
479
+ . then ( function ( ) {
480
+ return Plotly . relayout ( gd , 'coloraxis.colorbar.outlinewidth' , 5 ) ;
481
+ } )
482
+ . then ( function ( ) { _assert ( 'after relayout' , { outline : [ 2 , 5 ] } ) ; } )
483
+ . then ( function ( ) {
484
+ return Plotly . update ( gd , { 'colorbar.outlinewidth' : 1 } , { } , [ 0 ] ) ;
485
+ } )
486
+ . then ( function ( ) { _assert ( 'after trace update' , { outline : [ 1 , 5 ] } ) ; } )
487
+ . then ( function ( ) {
488
+ return Plotly . update ( gd , { } , { 'coloraxis.colorbar.outlinewidth' : 1 } ) ;
489
+ } )
490
+ . then ( function ( ) { _assert ( 'after layout update' , { outline : [ 1 , 1 ] } ) ; } )
491
+ . then ( function ( ) {
492
+ gd . data [ 0 ] . colorbar = { outlinewidth : 10 } ;
493
+ return Plotly . react ( gd , gd . data , gd . layout ) ;
494
+ } )
495
+ . then ( function ( ) { _assert ( 'after trace react' , { outline : [ 10 , 1 ] } ) ; } )
496
+ . then ( function ( ) {
497
+ gd . layout . coloraxis = { colorbar : { outlinewidth : 10 } } ;
498
+ return Plotly . react ( gd , gd . data , gd . layout ) ;
499
+ } )
500
+ . then ( function ( ) { _assert ( 'after layout trace' , { outline : [ 10 , 10 ] } ) ; } )
501
+ . catch ( failTest )
502
+ . then ( done ) ;
503
+ } ) ;
436
504
} ) ;
437
505
} ) ;
0 commit comments