@@ -6,6 +6,7 @@ var convertColumnXYZ = require('@src/traces/heatmap/convert_column_xyz');
6
6
var Heatmap = require ( '@src/traces/heatmap' ) ;
7
7
8
8
var d3 = require ( 'd3' ) ;
9
+ var sinon = require ( 'sinon' ) ;
9
10
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
10
11
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
11
12
var customMatchers = require ( '../assets/custom_matchers' ) ;
@@ -89,6 +90,34 @@ describe('heatmap supplyDefaults', function() {
89
90
expect ( traceOut . visible ) . toBe ( false ) ;
90
91
} ) ;
91
92
93
+ it ( 'should set paddings to 0 when not defined' , function ( ) {
94
+ traceIn = {
95
+ type : 'heatmap' ,
96
+ z : [ [ 1 , 2 ] , [ 3 , 4 ] ]
97
+ } ;
98
+
99
+ supplyDefaults ( traceIn , traceOut , defaultColor , layout ) ;
100
+ expect ( traceOut . padding . b ) . toBe ( 0 ) ;
101
+ expect ( traceOut . padding . l ) . toBe ( 0 ) ;
102
+ expect ( traceOut . padding . r ) . toBe ( 0 ) ;
103
+ expect ( traceOut . padding . t ) . toBe ( 0 ) ;
104
+ } ) ;
105
+
106
+ it ( 'should not step on defined paddings' , function ( ) {
107
+ traceIn = {
108
+ padding : {
109
+ b : 10
110
+ } ,
111
+ type : 'heatmap' ,
112
+ z : [ [ 1 , 2 ] , [ 3 , 4 ] ]
113
+ } ;
114
+
115
+ supplyDefaults ( traceIn , traceOut , defaultColor , layout ) ;
116
+ expect ( traceOut . padding . b ) . toBe ( 10 ) ;
117
+ expect ( traceOut . padding . l ) . toBe ( 0 ) ;
118
+ expect ( traceOut . padding . r ) . toBe ( 0 ) ;
119
+ expect ( traceOut . padding . t ) . toBe ( 0 ) ;
120
+ } ) ;
92
121
} ) ;
93
122
94
123
describe ( 'heatmap convertColumnXYZ' , function ( ) {
@@ -319,7 +348,16 @@ describe('heatmap calc', function() {
319
348
describe ( 'heatmap plot' , function ( ) {
320
349
'use strict' ;
321
350
322
- afterEach ( destroyGraphDiv ) ;
351
+ var sandbox ;
352
+
353
+ beforeEach ( function ( ) {
354
+ sandbox = sinon . sandbox . create ( ) ;
355
+ } ) ;
356
+
357
+ afterEach ( function ( ) {
358
+ destroyGraphDiv ( ) ;
359
+ sandbox . restore ( ) ;
360
+ } ) ;
323
361
324
362
it ( 'should not draw traces that are off-screen' , function ( done ) {
325
363
var mock = require ( '@mocks/heatmap_multi-trace.json' ) ,
@@ -381,7 +419,48 @@ describe('heatmap plot', function() {
381
419
382
420
done ( ) ;
383
421
} ) ;
422
+ } ) ;
423
+
424
+ it ( 'draws canvas with correct margins' , function ( done ) {
425
+ var mockWithPadding = require ( '@mocks/heatmap_brick_padding.json' ) ,
426
+ mockWithoutPadding = Lib . extendDeep ( { } , mockWithPadding ) ,
427
+ gd = createGraphDiv ( ) ,
428
+ getContextStub = {
429
+ fillRect : sinon . stub ( )
430
+ } ,
431
+ originalCreateElement = document . createElement ,
432
+ bottom = mockWithPadding . data [ 0 ] . padding . b ,
433
+ left = mockWithPadding . data [ 0 ] . padding . l ,
434
+ right = mockWithPadding . data [ 0 ] . padding . r ,
435
+ top = mockWithPadding . data [ 0 ] . padding . t ;
436
+
437
+ mockWithoutPadding . data [ 0 ] . padding = null ;
438
+ sandbox . stub ( document , 'createElement' , function ( elementType ) {
439
+ var element = originalCreateElement . call ( document , elementType ) ;
440
+ if ( elementType === 'canvas' ) {
441
+ sinon . stub ( element , 'getContext' ) . returns ( getContextStub ) ;
442
+ }
443
+ return element ;
444
+ } ) ;
384
445
446
+ var argumentsWithoutPadding = [ ] ,
447
+ argumentsWithPadding = [ ] ,
448
+ callCount ;
449
+ Plotly . plot ( gd , mockWithoutPadding . data , mockWithoutPadding . layout ) . then ( function ( ) {
450
+ callCount = getContextStub . fillRect . callCount ;
451
+ argumentsWithoutPadding = getContextStub . fillRect . args . slice ( 0 ) ;
452
+ return Plotly . plot ( gd , mockWithPadding . data , mockWithPadding . layout ) ;
453
+ } ) . then ( function ( ) {
454
+ argumentsWithPadding = getContextStub . fillRect . args . slice ( getContextStub . fillRect . args . length - callCount ) ;
455
+ argumentsWithoutPadding . forEach ( function ( argumentWithoutPadding , index ) {
456
+ var argumentWithPadding = argumentsWithPadding [ index ] ;
457
+ expect ( argumentWithoutPadding [ 0 ] + left ) . toEqual ( argumentWithPadding [ 0 ] ) ;
458
+ expect ( argumentWithoutPadding [ 1 ] + top ) . toEqual ( argumentWithPadding [ 1 ] ) ;
459
+ expect ( argumentWithoutPadding [ 2 ] - right - left ) . toEqual ( argumentWithPadding [ 2 ] ) ;
460
+ expect ( argumentWithoutPadding [ 3 ] - top - bottom ) . toEqual ( argumentWithPadding [ 3 ] ) ;
461
+ } ) ;
462
+ done ( ) ;
463
+ } ) ;
385
464
} ) ;
386
465
} ) ;
387
466
0 commit comments