@@ -75,7 +75,7 @@ describe('heatmap supplyDefaults', function() {
7575 expect ( traceOut . visible ) . toBe ( false ) ;
7676 } ) ;
7777
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 ( ) {
7979 traceIn = {
8080 x : [ 1 , 1 , 1 , 2 , 2 ] ,
8181 y : [ 1 , 2 , 3 , 1 , 2 ] ,
@@ -683,7 +683,7 @@ describe('heatmap plot', function() {
683683
684684 return Plotly . relayout ( gd , 'xaxis.range' , [ 2 , 3 ] ) ;
685685 } ) . then ( function ( ) {
686- assertImageCnt ( 2 ) ;
686+ assertImageCnt ( 3 ) ;
687687
688688 return Plotly . relayout ( gd , 'xaxis.autorange' , true ) ;
689689 } ) . then ( function ( ) {
@@ -763,8 +763,12 @@ describe('heatmap plot', function() {
763763 } ;
764764 var originalCreateElement = document . createElement ;
765765
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 ;
768772
769773 spyOn ( document , 'createElement' ) . and . callFake ( function ( elementType ) {
770774 var element = originalCreateElement . call ( document , elementType ) ;
@@ -782,8 +786,8 @@ describe('heatmap plot', function() {
782786 } ) . then ( function ( ) {
783787 var xGap = mockWithPadding . data [ 0 ] . xgap ;
784788 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 ) ;
787791
788792 argumentsWithPadding = getContextStub . fillRect . calls . allArgs ( )
789793 . slice ( getContextStub . fillRect . calls . allArgs ( ) . length - 25 ) ;
@@ -793,8 +797,8 @@ describe('heatmap plot', function() {
793797 argumentsWithPadding . forEach ( function ( args , i ) {
794798 expect ( args [ 0 ] ) . toBe ( argumentsWithoutPadding [ i ] [ 0 ] + xGapLeft , i ) ;
795799 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 ) ;
798802 } ) ;
799803 } )
800804 . then ( done , done . fail ) ;
@@ -827,7 +831,7 @@ describe('heatmap plot', function() {
827831 . then ( done , done . fail ) ;
828832 } ) ;
829833
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 ) {
831835 var mock1 = require ( '../../image/mocks/zsmooth_methods.json' ) ;
832836 var mock2 = require ( '../../image/mocks/heatmap_small_layout_zsmooth_fast.json' ) ;
833837
@@ -863,7 +867,7 @@ describe('heatmap plot', function() {
863867 } ) . then ( done , done . fail ) ;
864868 } ) ;
865869
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 ) {
867871 var mock1 = require ( '../../image/mocks/zsmooth_methods.json' ) ;
868872 var mock2 = require ( '../../image/mocks/heatmap_small_layout_zsmooth_fast.json' ) ;
869873
@@ -905,11 +909,11 @@ describe('heatmap plot', function() {
905909 return element ;
906910 } ) ;
907911
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 ) ;
911915
912- [ 0 , 1 ] . forEach ( function ( i ) {
916+ traceIndices . forEach ( function ( i ) {
913917 var createImageDataArgs = getContextStub . createImageData . calls . argsFor ( i ) ;
914918 var setImageDataArgs = imageDataStub . data . set . calls . argsFor ( i ) ;
915919
@@ -921,26 +925,18 @@ describe('heatmap plot', function() {
921925 expect ( pixels . length ) . toBe ( canvasW * canvasH * 4 ) ;
922926 expect ( checkPixels ( pixels ) ) . toBe ( true ) ;
923927 } ) ;
928+ }
929+
930+ Plotly . newPlot ( gd , mock1 . data , mock1 . layout ) . then ( function ( ) {
931+ assertImageData ( [ 0 , 1 , 2 ] ) ;
924932
925933 getContextStub . createImageData . calls . reset ( ) ;
926934 imageDataStub . data . set . calls . reset ( ) ;
927935 canvasStubs = [ ] ;
928936
929937 return Plotly . newPlot ( gd , mock2 . data , mock2 . layout ) ;
930938 } ) . 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 ] ) ;
944940 } ) . then ( done , done . fail ) ;
945941 } ) ;
946942} ) ;
0 commit comments