@@ -89,6 +89,28 @@ describe('heatmap supplyDefaults', function() {
89
89
expect ( traceOut . visible ) . toBe ( false ) ;
90
90
} ) ;
91
91
92
+ it ( 'should set paddings to 0 when not defined' , function ( ) {
93
+ traceIn = {
94
+ type : 'heatmap' ,
95
+ z : [ [ 1 , 2 ] , [ 3 , 4 ] ]
96
+ } ;
97
+
98
+ supplyDefaults ( traceIn , traceOut , defaultColor , layout ) ;
99
+ expect ( traceOut . xgap ) . toBe ( 0 ) ;
100
+ expect ( traceOut . ygap ) . toBe ( 0 ) ;
101
+ } ) ;
102
+
103
+ it ( 'should not step on defined paddings' , function ( ) {
104
+ traceIn = {
105
+ xgap : 10 ,
106
+ type : 'heatmap' ,
107
+ z : [ [ 1 , 2 ] , [ 3 , 4 ] ]
108
+ } ;
109
+
110
+ supplyDefaults ( traceIn , traceOut , defaultColor , layout ) ;
111
+ expect ( traceOut . xgap ) . toBe ( 10 ) ;
112
+ expect ( traceOut . ygap ) . toBe ( 0 ) ;
113
+ } ) ;
92
114
} ) ;
93
115
94
116
describe ( 'heatmap convertColumnXYZ' , function ( ) {
@@ -381,7 +403,43 @@ describe('heatmap plot', function() {
381
403
382
404
done ( ) ;
383
405
} ) ;
406
+ } ) ;
384
407
408
+ it ( 'draws canvas with correct margins' , function ( done ) {
409
+ var mockWithPadding = require ( '@mocks/heatmap_brick_padding.json' ) ,
410
+ mockWithoutPadding = Lib . extendDeep ( { } , mockWithPadding ) ,
411
+ gd = createGraphDiv ( ) ,
412
+ getContextStub = {
413
+ fillRect : jasmine . createSpy ( )
414
+ } ,
415
+ originalCreateElement = document . createElement ;
416
+
417
+ mockWithoutPadding . data [ 0 ] . xgap = 0 ;
418
+ mockWithoutPadding . data [ 0 ] . ygap = 0 ;
419
+
420
+ spyOn ( document , 'createElement' ) . and . callFake ( function ( elementType ) {
421
+ var element = originalCreateElement . call ( document , elementType ) ;
422
+ if ( elementType === 'canvas' ) {
423
+ spyOn ( element , 'getContext' ) . and . returnValue ( getContextStub ) ;
424
+ }
425
+ return element ;
426
+ } ) ;
427
+
428
+ var argumentsWithoutPadding = [ ] ,
429
+ argumentsWithPadding = [ ] ;
430
+ Plotly . plot ( gd , mockWithoutPadding . data , mockWithoutPadding . layout ) . then ( function ( ) {
431
+ argumentsWithoutPadding = getContextStub . fillRect . calls . allArgs ( ) . slice ( 0 ) ;
432
+ expect ( argumentsWithoutPadding ) . toEqual ( [ [ 0 , 180 , 177 , 90 ] , [ 177 , 180 , 177 , 90 ] , [ 354 , 180 , 177 , 90 ] ,
433
+ [ 0 , 90 , 177 , 90 ] , [ 177 , 90 , 177 , 90 ] , [ 354 , 90 , 177 , 90 ] ,
434
+ [ 0 , 0 , 177 , 90 ] , [ 177 , 0 , 177 , 90 ] , [ 354 , 0 , 177 , 90 ] ] ) ;
435
+ return Plotly . plot ( gd , mockWithPadding . data , mockWithPadding . layout ) ;
436
+ } ) . then ( function ( ) {
437
+ argumentsWithPadding = getContextStub . fillRect . calls . allArgs ( ) . slice ( getContextStub . fillRect . calls . allArgs ( ) . length - 9 ) ;
438
+ expect ( argumentsWithPadding ) . toEqual ( [ [ 0 , 184 , 171 , 86 ] , [ 180 , 184 , 171 , 86 ] , [ 360 , 184 , 171 , 86 ] ,
439
+ [ 0 , 92 , 171 , 86 ] , [ 180 , 92 , 171 , 86 ] , [ 360 , 92 , 171 , 86 ] ,
440
+ [ 0 , 0 , 171 , 86 ] , [ 180 , 0 , 171 , 86 ] , [ 360 , 0 , 171 , 86 ] ] ) ;
441
+ done ( ) ;
442
+ } ) ;
385
443
} ) ;
386
444
} ) ;
387
445
0 commit comments