@@ -89,6 +89,28 @@ describe('heatmap supplyDefaults', function() {
8989 expect ( traceOut . visible ) . toBe ( false ) ;
9090 } ) ;
9191
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+ } ) ;
92114} ) ;
93115
94116describe ( 'heatmap convertColumnXYZ' , function ( ) {
@@ -381,7 +403,43 @@ describe('heatmap plot', function() {
381403
382404 done ( ) ;
383405 } ) ;
406+ } ) ;
384407
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+ } ) ;
385443 } ) ;
386444} ) ;
387445
0 commit comments