@@ -116,11 +116,19 @@ describe('image smart layout defaults', function() {
116
116
expect ( gd . _fullLayout . yaxis . autorange ) . toBe ( 'reversed' ) ;
117
117
} ) ;
118
118
119
- it ( 'should NOT reverse yaxis if another trace is present' , function ( ) {
119
+ it ( 'should reverse yaxis even if another trace is present' , function ( ) {
120
120
gd = { } ;
121
121
gd . data = [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } , { type : 'scatter' , y : [ 5 , 3 , 2 ] } ] ;
122
122
supplyAllDefaults ( gd ) ;
123
- expect ( gd . _fullLayout . yaxis . autorange ) . not . toBe ( 'reversed' ) ;
123
+ expect ( gd . _fullLayout . yaxis . autorange ) . toBe ( 'reversed' ) ;
124
+ } ) ;
125
+
126
+ it ( 'should NOT reverse yaxis if it\'s already defined' , function ( ) {
127
+ gd = { } ;
128
+ gd . data = [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } ] ;
129
+ gd . layout = { yaxis : { autorange : false } } ;
130
+ supplyAllDefaults ( gd ) ;
131
+ expect ( gd . _fullLayout . yaxis . autorange ) . toBe ( false ) ;
124
132
} ) ;
125
133
126
134
it ( 'should set scaleanchor to make square pixels if only images are present' , function ( ) {
@@ -130,19 +138,43 @@ describe('image smart layout defaults', function() {
130
138
expect ( gd . _fullLayout . yaxis . scaleanchor ) . toBe ( 'x' ) ;
131
139
} ) ;
132
140
133
- it ( 'should NOT set scaleanchor if another trace is present' , function ( ) {
141
+ it ( 'should set scaleanchor even if another trace is present' , function ( ) {
134
142
gd = { } ;
135
143
gd . data = [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } , { type : 'scatter' , y : [ 5 , 3 , 2 ] } ] ;
136
144
supplyAllDefaults ( gd ) ;
137
- expect ( gd . _fullLayout . yaxis . scaleanchor ) . toBe ( undefined ) ;
145
+ expect ( gd . _fullLayout . yaxis . scaleanchor ) . toBe ( 'x' ) ;
138
146
} ) ;
139
147
140
148
it ( 'should NOT set scaleanchor if it\'s already defined' , function ( ) {
141
- gd . data = [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } , { type : 'scatter' , y : [ 5 , 3 , 2 ] } ] ;
149
+ gd . data = [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } ] ;
142
150
gd . layout = { yaxis : { scaleanchor : 'x3' } } ;
143
151
supplyAllDefaults ( gd ) ;
144
152
expect ( gd . _fullLayout . yaxis . scaleanchor ) . toBe ( undefined ) ;
145
153
} ) ;
154
+
155
+ it ( 'should constrain axes to domain if only images are present' , function ( ) {
156
+ gd = { } ;
157
+ gd . data = [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } ] ;
158
+ supplyAllDefaults ( gd ) ;
159
+ expect ( gd . _fullLayout . xaxis . constrain ) . toBe ( 'domain' ) ;
160
+ expect ( gd . _fullLayout . yaxis . constrain ) . toBe ( 'domain' ) ;
161
+ } ) ;
162
+
163
+ it ( 'should constrain axes to domain even if another trace is present' , function ( ) {
164
+ gd = { } ;
165
+ gd . data = [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } , { type : 'scatter' , y : [ 5 , 3 , 2 ] } ] ;
166
+ supplyAllDefaults ( gd ) ;
167
+ expect ( gd . _fullLayout . xaxis . constrain ) . toBe ( 'domain' ) ;
168
+ expect ( gd . _fullLayout . yaxis . constrain ) . toBe ( 'domain' ) ;
169
+ } ) ;
170
+
171
+ it ( 'should NOT constrain axes to domain if it\'s already defined' , function ( ) {
172
+ gd . data = [ { type : 'image' , z : [ [ [ 255 , 0 , 0 ] ] ] } ] ;
173
+ gd . layout = { yaxis : { constrain : false } , xaxis : { constrain : false } } ;
174
+ supplyAllDefaults ( gd ) ;
175
+ expect ( gd . _fullLayout . xaxis . constrain ) . toBe ( 'range' ) ;
176
+ expect ( gd . _fullLayout . yaxis . constrain ) . toBe ( 'range' ) ;
177
+ } ) ;
146
178
} ) ;
147
179
148
180
describe ( 'image plot' , function ( ) {
@@ -489,7 +521,7 @@ describe('image hover:', function() {
489
521
zmax : [ 1 , 1 , 1 ] ,
490
522
text : [ [ 'A' , 'B' , 'C' ] , [ 'D' , 'E' , 'F' ] ] ,
491
523
hovertemplate : '%{text}<extra></extra>'
492
- } ] , layout : { width : 400 , height : 400 } } ;
524
+ } ] , layout : { width : 400 , height : 400 , yaxis : { constrain : 'range' } } } ;
493
525
494
526
Plotly . newPlot ( gd , mockCopy )
495
527
. then ( function ( ) { _hover ( 140 , 180 ) ; } )
0 commit comments