@@ -100,6 +100,62 @@ describe('image supplyDefaults', function() {
100
100
} ) ;
101
101
} ) ;
102
102
103
+ describe ( 'image smart layout defaults' , function ( ) {
104
+ var gd ;
105
+ beforeEach ( function ( ) {
106
+ gd = createGraphDiv ( ) ;
107
+ } ) ;
108
+
109
+ afterEach ( destroyGraphDiv ) ;
110
+
111
+ it ( 'should reverse yaxis if only images are present' , function ( done ) {
112
+ Plotly . newPlot ( gd , [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } ] )
113
+ . then ( function ( gd ) {
114
+ expect ( gd . _fullLayout . yaxis . range [ 0 ] ) . toBeGreaterThan ( gd . _fullLayout . yaxis . range [ 1 ] ) ;
115
+ } )
116
+ . catch ( failTest )
117
+ . then ( done ) ;
118
+ } ) ;
119
+
120
+ it ( 'should NOT reverse yaxis if another trace is present' , function ( done ) {
121
+ Plotly . newPlot ( gd , [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } , { type : 'scatter' , y : [ 5 , 3 , 2 ] } ] )
122
+ . then ( function ( gd ) {
123
+ expect ( gd . _fullLayout . yaxis . range [ 1 ] ) . toBeGreaterThan ( gd . _fullLayout . yaxis . range [ 0 ] ) ;
124
+ } )
125
+ . catch ( failTest )
126
+ . then ( done ) ;
127
+ } ) ;
128
+
129
+ it ( 'should set scaleanchor to make square pixels if only images are present' , function ( done ) {
130
+ Plotly . newPlot ( gd , [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } ] )
131
+ . then ( function ( gd ) {
132
+ expect ( gd . _fullLayout . yaxis . scaleanchor ) . toBe ( 'x' ) ;
133
+ } )
134
+ . catch ( failTest )
135
+ . then ( done ) ;
136
+ } ) ;
137
+
138
+ it ( 'should NOT set scaleanchor if another trace is present' , function ( done ) {
139
+ Plotly . newPlot ( gd , [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } , { type : 'scatter' , y : [ 5 , 3 , 2 ] } ] )
140
+ . then ( function ( gd ) {
141
+ expect ( gd . _fullLayout . yaxis . scaleanchor ) . toBe ( undefined ) ;
142
+ } )
143
+ . catch ( failTest )
144
+ . then ( done ) ;
145
+ } ) ;
146
+
147
+ it ( 'should NOT set scaleanchor if it\'s already defined' , function ( done ) {
148
+ Plotly . newPlot ( gd , [
149
+ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } , { type : 'scatter' , y : [ 5 , 3 , 2 ] }
150
+ ] , { yaxis : { scaleanchor : 'x3' } } )
151
+ . then ( function ( gd ) {
152
+ expect ( gd . _fullLayout . yaxis . scaleanchor ) . toBe ( undefined ) ;
153
+ } )
154
+ . catch ( failTest )
155
+ . then ( done ) ;
156
+ } ) ;
157
+ } ) ;
158
+
103
159
describe ( 'image plot' , function ( ) {
104
160
'use strict' ;
105
161
@@ -444,7 +500,7 @@ describe('image hover:', function() {
444
500
zmax : [ 1 , 1 , 1 ] ,
445
501
text : [ [ 'A' , 'B' , 'C' ] , [ 'D' , 'E' , 'F' ] ] ,
446
502
hovertemplate : '%{text}<extra></extra>'
447
- } ] , layout : { width : 400 , height : 400 } } ;
503
+ } ] , layout : { width : 400 , height : 400 , yaxis : { scaleanchor : null } } } ;
448
504
449
505
Plotly . newPlot ( gd , mockCopy )
450
506
. then ( function ( ) { _hover ( 140 , 200 ) ; } )
0 commit comments