@@ -75,7 +75,7 @@ describe('heatmap supplyDefaults', function() {
75
75
expect ( traceOut . visible ) . toBe ( false ) ;
76
76
} ) ;
77
77
78
- it ( 'should set visible to false when z isn\'t column not a 2d array' , function ( ) {
78
+ it ( 'should set visible to false when z isn\'t column nor a 2d array' , function ( ) {
79
79
traceIn = {
80
80
x : [ 1 , 1 , 1 , 2 , 2 ] ,
81
81
y : [ 1 , 2 , 3 , 1 , 2 ] ,
@@ -683,7 +683,7 @@ describe('heatmap plot', function() {
683
683
684
684
return Plotly . relayout ( gd , 'xaxis.range' , [ 2 , 3 ] ) ;
685
685
} ) . then ( function ( ) {
686
- assertImageCnt ( 2 ) ;
686
+ assertImageCnt ( 3 ) ;
687
687
688
688
return Plotly . relayout ( gd , 'xaxis.autorange' , true ) ;
689
689
} ) . then ( function ( ) {
@@ -763,8 +763,12 @@ describe('heatmap plot', function() {
763
763
} ;
764
764
var originalCreateElement = document . createElement ;
765
765
766
- mockWithoutPadding . data [ 0 ] . xgap = 0 ;
767
- mockWithoutPadding . data [ 0 ] . ygap = 0 ;
766
+ // We actually need to set a non-zero gap to ensure both mockWithPadding
767
+ // and mockWithoutPadding relies on the same drawing method (ie. default
768
+ // method using fillRect)
769
+ var nearZeroGap = 0.1 ;
770
+ mockWithoutPadding . data [ 0 ] . xgap = nearZeroGap ;
771
+ mockWithoutPadding . data [ 0 ] . ygap = nearZeroGap ;
768
772
769
773
spyOn ( document , 'createElement' ) . and . callFake ( function ( elementType ) {
770
774
var element = originalCreateElement . call ( document , elementType ) ;
@@ -782,8 +786,8 @@ describe('heatmap plot', function() {
782
786
} ) . then ( function ( ) {
783
787
var xGap = mockWithPadding . data [ 0 ] . xgap ;
784
788
var yGap = mockWithPadding . data [ 0 ] . ygap ;
785
- var xGapLeft = xGap / 2 ;
786
- var yGapTop = yGap / 2 ;
789
+ var xGapLeft = Math . floor ( xGap / 2 ) ;
790
+ var yGapTop = Math . floor ( yGap / 2 ) ;
787
791
788
792
argumentsWithPadding = getContextStub . fillRect . calls . allArgs ( )
789
793
. slice ( getContextStub . fillRect . calls . allArgs ( ) . length - 25 ) ;
@@ -793,8 +797,8 @@ describe('heatmap plot', function() {
793
797
argumentsWithPadding . forEach ( function ( args , i ) {
794
798
expect ( args [ 0 ] ) . toBe ( argumentsWithoutPadding [ i ] [ 0 ] + xGapLeft , i ) ;
795
799
expect ( args [ 1 ] ) . toBe ( argumentsWithoutPadding [ i ] [ 1 ] + yGapTop , i ) ;
796
- expect ( args [ 2 ] ) . toBe ( argumentsWithoutPadding [ i ] [ 2 ] - xGap , i ) ;
797
- expect ( args [ 3 ] ) . toBe ( argumentsWithoutPadding [ i ] [ 3 ] - yGap , i ) ;
800
+ expect ( args [ 2 ] ) . toBe ( argumentsWithoutPadding [ i ] [ 2 ] + nearZeroGap - xGap , i ) ;
801
+ expect ( args [ 3 ] ) . toBe ( argumentsWithoutPadding [ i ] [ 3 ] + nearZeroGap - yGap , i ) ;
798
802
} ) ;
799
803
} )
800
804
. then ( done , done . fail ) ;
@@ -827,7 +831,7 @@ describe('heatmap plot', function() {
827
831
. then ( done , done . fail ) ;
828
832
} ) ;
829
833
830
- it ( 'should set canvas dimensions according to z data shape if `zsmooth` is fast' , function ( done ) {
834
+ it ( 'should set canvas dimensions according to z data shape when using fast drawing method ' , function ( done ) {
831
835
var mock1 = require ( '../../image/mocks/zsmooth_methods.json' ) ;
832
836
var mock2 = require ( '../../image/mocks/heatmap_small_layout_zsmooth_fast.json' ) ;
833
837
@@ -863,7 +867,7 @@ describe('heatmap plot', function() {
863
867
} ) . then ( done , done . fail ) ;
864
868
} ) ;
865
869
866
- it ( 'should create imageData that fits the canvas dimensions if zsmooth is set' , function ( done ) {
870
+ it ( 'should create imageData that fits the canvas dimensions if zsmooth is set and/or drawing method is fast ' , function ( done ) {
867
871
var mock1 = require ( '../../image/mocks/zsmooth_methods.json' ) ;
868
872
var mock2 = require ( '../../image/mocks/heatmap_small_layout_zsmooth_fast.json' ) ;
869
873
@@ -905,11 +909,11 @@ describe('heatmap plot', function() {
905
909
return element ;
906
910
} ) ;
907
911
908
- Plotly . newPlot ( gd , mock1 . data , mock1 . layout ) . then ( function ( ) {
909
- expect ( getContextStub . createImageData . calls . count ( ) ) . toBe ( 2 ) ;
910
- expect ( imageDataStub . data . set . calls . count ( ) ) . toBe ( 2 ) ;
912
+ function assertImageData ( traceIndices ) {
913
+ expect ( getContextStub . createImageData . calls . count ( ) ) . toBe ( traceIndices . length ) ;
914
+ expect ( imageDataStub . data . set . calls . count ( ) ) . toBe ( traceIndices . length ) ;
911
915
912
- [ 0 , 1 ] . forEach ( function ( i ) {
916
+ traceIndices . forEach ( function ( i ) {
913
917
var createImageDataArgs = getContextStub . createImageData . calls . argsFor ( i ) ;
914
918
var setImageDataArgs = imageDataStub . data . set . calls . argsFor ( i ) ;
915
919
@@ -921,26 +925,18 @@ describe('heatmap plot', function() {
921
925
expect ( pixels . length ) . toBe ( canvasW * canvasH * 4 ) ;
922
926
expect ( checkPixels ( pixels ) ) . toBe ( true ) ;
923
927
} ) ;
928
+ }
929
+
930
+ Plotly . newPlot ( gd , mock1 . data , mock1 . layout ) . then ( function ( ) {
931
+ assertImageData ( [ 0 , 1 , 2 ] ) ;
924
932
925
933
getContextStub . createImageData . calls . reset ( ) ;
926
934
imageDataStub . data . set . calls . reset ( ) ;
927
935
canvasStubs = [ ] ;
928
936
929
937
return Plotly . newPlot ( gd , mock2 . data , mock2 . layout ) ;
930
938
} ) . then ( function ( ) {
931
- expect ( getContextStub . createImageData . calls . count ( ) ) . toBe ( 1 ) ;
932
- expect ( imageDataStub . data . set . calls . count ( ) ) . toBe ( 1 ) ;
933
-
934
- var canvasW = canvasStubs [ 0 ] . width . calls . argsFor ( 0 ) [ 0 ] ;
935
- var canvasH = canvasStubs [ 0 ] . height . calls . argsFor ( 0 ) [ 0 ] ;
936
-
937
- var createImageDataArgs = getContextStub . createImageData . calls . argsFor ( 0 ) ;
938
- expect ( createImageDataArgs ) . toEqual ( [ canvasW , canvasH ] ) ;
939
-
940
- var setImageDataArgs = imageDataStub . data . set . calls . argsFor ( 0 ) ;
941
- var pixels = setImageDataArgs [ 0 ] ;
942
- expect ( pixels . length ) . toBe ( canvasW * canvasH * 4 ) ;
943
- expect ( checkPixels ( pixels ) ) . toBe ( true ) ;
939
+ assertImageData ( [ 0 ] ) ;
944
940
} ) . then ( done , done . fail ) ;
945
941
} ) ;
946
942
} ) ;
0 commit comments