1
1
var Plotly = require ( '@lib/index' ) ;
2
+ var Plots = require ( '@src/plots/plots' ) ;
2
3
var Lib = require ( '@src/lib' ) ;
3
4
4
5
var Image = require ( '@src/traces/image' ) ;
5
6
6
7
var d3 = require ( 'd3' ) ;
7
8
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
8
9
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
9
- // var supplyAllDefaults = require('../assets/supply_defaults');
10
10
var failTest = require ( '../assets/fail_test' ) ;
11
11
12
12
var customAssertions = require ( '../assets/custom_assertions' ) ;
13
13
var assertHoverLabelContent = customAssertions . assertHoverLabelContent ;
14
14
var Fx = require ( '@src/components/fx' ) ;
15
15
16
- // describe('image supplyDefaults', function() {
17
- // 'use strict';
18
- //
19
- // var traceIn;
20
- // var traceOut;
21
- //
22
- // var layout = {
23
- // _subplots: {cartesian: ['xy'], xaxis: ['x'], yaxis: ['y']}
24
- // };
25
- //
26
- // var supplyDefaults = Image.supplyDefaults;
27
- //
28
- // beforeEach(function() {
29
- // traceOut = {};
30
- // });
31
- //
32
- // it('should set visible to false when z is empty', function() {
33
- // traceIn = {
34
- // z: []
35
- // };
36
- // supplyDefaults(traceIn, traceOut);
37
- // expect(traceOut.visible).toBe(false);
38
- //
39
- // traceIn = {
40
- // z: [[]]
41
- // };
42
- // supplyDefaults(traceIn, traceOut);
43
- // expect(traceOut.visible).toBe(false);
44
- //
45
- // traceIn = {
46
- // z: [[], [], []]
47
- // };
48
- // supplyDefaults(traceIn, traceOut);
49
- // expect(traceOut.visible).toBe(false);
50
- //
51
- // traceIn = {
52
- // type: 'image',
53
- // z: [[[255, 0, 0]]]
54
- // };
55
- // traceOut = Plots.supplyTraceDefaults(traceIn, {type: 'image'}, 0, layout);
56
- // expect(traceOut.visible).toBe(true);
57
- // });
58
- //
59
- // it('should set visible to false when z is non-numeric', function() {
60
- // traceIn = {
61
- // type: 'heatmap',
62
- // z: [['a', 'b'], ['c', 'd']]
63
- // };
64
- // supplyDefaults(traceIn, traceOut, defaultColor, layout);
65
- // expect(traceOut.visible).toBe(false);
66
- // });
67
- //
68
- // it('should set visible to false when z isn\'t column not a 2d array', function() {
69
- // traceIn = {
70
- // x: [1, 1, 1, 2, 2],
71
- // y: [1, 2, 3, 1, 2],
72
- // z: [1, ['this is considered a column'], 1, 2, 3]
73
- // };
74
- // supplyDefaults(traceIn, traceOut, defaultColor, layout);
75
- // expect(traceOut.visible).not.toBe(false);
76
- //
77
- // traceIn = {
78
- // x: [1, 1, 1, 2, 2],
79
- // y: [1, 2, 3, 1, 2],
80
- // z: [[0], ['this is not considered a column'], 1, ['nor 2d']]
81
- // };
82
- // supplyDefaults(traceIn, traceOut, defaultColor, layout);
83
- // expect(traceOut.visible).toBe(false);
84
- // });
85
- // });
16
+ describe ( 'image supplyDefaults' , function ( ) {
17
+ 'use strict' ;
18
+
19
+ var traceIn ;
20
+ var traceOut ;
21
+
22
+ var layout = {
23
+ _subplots : { cartesian : [ 'xy' ] , xaxis : [ 'x' ] , yaxis : [ 'y' ] }
24
+ } ;
25
+
26
+ var supplyDefaults = Image . supplyDefaults ;
27
+
28
+ beforeEach ( function ( ) {
29
+ traceOut = { } ;
30
+ } ) ;
31
+
32
+ it ( 'should set visible to false when z is empty' , function ( ) {
33
+ traceIn = {
34
+ z : [ ]
35
+ } ;
36
+ supplyDefaults ( traceIn , traceOut ) ;
37
+ expect ( traceOut . visible ) . toBe ( false ) ;
38
+
39
+ traceIn = {
40
+ z : [ [ ] ]
41
+ } ;
42
+ supplyDefaults ( traceIn , traceOut ) ;
43
+ expect ( traceOut . visible ) . toBe ( false ) ;
44
+
45
+ traceIn = {
46
+ z : [ [ ] , [ ] , [ ] ]
47
+ } ;
48
+ supplyDefaults ( traceIn , traceOut ) ;
49
+ expect ( traceOut . visible ) . toBe ( false ) ;
50
+
51
+ traceIn = {
52
+ type : 'image' ,
53
+ z : [ [ [ 255 , 0 , 0 ] ] ]
54
+ } ;
55
+ traceOut = Plots . supplyTraceDefaults ( traceIn , { type : 'image' } , 0 , layout ) ;
56
+ expect ( traceOut . visible ) . toBe ( true ) ;
57
+ } ) ;
58
+ } ) ;
86
59
//
87
60
// describe('image calc', function() {
88
61
// 'use strict';
@@ -148,16 +121,16 @@ describe('image plot', function() {
148
121
. then ( done ) ;
149
122
} ) ;
150
123
124
+ function getImageURL ( ) {
125
+ return d3 . select ( '.im > image' ) . attr ( 'href' ) ;
126
+ }
127
+
151
128
[ [ 'dx' , 2 , 4 ] , [ 'dy' , 2 , 4 ] , [ 'z[5][5]' , [ [ 0 , 0 , 0 , 1 ] ] , [ [ 255 , 0 , 0 , 1 ] ] ] ] . forEach ( function ( test ) {
152
129
var attr = test [ 0 ] ;
153
130
it ( 'should be able to restyle ' + attr , function ( done ) {
154
131
var mock = require ( '@mocks/image_adventurer.json' ) ;
155
132
var mockCopy = Lib . extendDeep ( { } , mock ) ;
156
133
157
- function getImageURL ( ) {
158
- return d3 . select ( '.im > image' ) . attr ( 'href' ) ;
159
- }
160
-
161
134
var imageURLs = [ ] ;
162
135
163
136
Plotly . plot ( gd , mockCopy ) . then ( function ( ) {
@@ -186,35 +159,63 @@ describe('image plot', function() {
186
159
} ) ;
187
160
} ) ;
188
161
189
- // it('keeps the correct ordering after hide and show', function(done) {
190
- // function getIndices() {
191
- // var out = [];
192
- // d3.selectAll('.im image').each(function(d) { out.push(d.trace.index); });
193
- // return out;
194
- // }
195
- //
196
- // Plotly.newPlot(gd, [{
197
- // type: 'heatmap',
198
- // z: [[1, 2], [3, 4]]
199
- // }, {
200
- // type: 'heatmap',
201
- // z: [[2, 1], [4, 3]],
202
- // contours: {coloring: 'lines'}
203
- // }])
204
- // .then(function() {
205
- // expect(getIndices()).toEqual([0, 1]);
206
- // return Plotly.restyle(gd, 'visible', false, [0]);
207
- // })
208
- // .then(function() {
209
- // expect(getIndices()).toEqual([1]);
210
- // return Plotly.restyle(gd, 'visible', true, [0]);
211
- // })
212
- // .then(function() {
213
- // expect(getIndices()).toEqual([0, 1]);
214
- // })
215
- // .catch(failTest)
216
- // .then(done);
217
- // });
162
+ it ( 'should rescale pixels according to zmin/zmax' , function ( done ) {
163
+ var imageURLs = [ ] ;
164
+ Plotly . newPlot ( gd , [ {
165
+ type : 'image' ,
166
+ z : [ [ [ 255 , 0 , 0 ] , [ 0 , 255 , 0 ] , [ 0 , 0 , 255 ] ] ]
167
+ } ] ) . then ( function ( ) {
168
+ imageURLs . push ( getImageURL ( ) ) ;
169
+
170
+ return Plotly . restyle ( gd , {
171
+ z : [ [ [ [ 1.5 , 0 , 0 ] , [ 0 , 1.5 , 0 ] , [ 0 , 0 , 1.5 ] ] ] ] ,
172
+ zmin : [ [ 0.5 , 0.5 , 0.5 ] ] ,
173
+ zmax : [ [ 1.5 , 1.5 , 1.5 ] ] ,
174
+ } ) ;
175
+ } ) . then ( function ( ) {
176
+ imageURLs . push ( getImageURL ( ) ) ;
177
+ expect ( imageURLs [ 1 ] ) . toEqual ( imageURLs [ 0 ] ) ;
178
+
179
+ return Plotly . restyle ( gd , {
180
+ z : [ [ [ [ 50 , 0 , 0 ] , [ 0 , 50 , 0 ] , [ 0 , 0 , 50 ] ] ] ]
181
+ } ) ;
182
+ } ) . then ( function ( ) {
183
+ imageURLs . push ( getImageURL ( ) ) ;
184
+ expect ( imageURLs [ 2 ] ) . toEqual ( imageURLs [ 1 ] ) ;
185
+ } )
186
+ . catch ( failTest )
187
+ . then ( done ) ;
188
+ } ) ;
189
+
190
+ it ( 'keeps the correct ordering after hide and show' , function ( done ) {
191
+ function getIndices ( ) {
192
+ var out = [ ] ;
193
+ d3 . selectAll ( '.im image' ) . each ( function ( d ) { out . push ( d . trace . index ) ; } ) ;
194
+ return out ;
195
+ }
196
+
197
+ Plotly . newPlot ( gd , [ {
198
+ type : 'image' ,
199
+ z : [ [ [ 1 , 2 ] , [ 3 , 4 ] ] ]
200
+ } , {
201
+ type : 'image' ,
202
+ z : [ [ [ 2 , 1 ] , [ 4 , 3 ] ] ] ,
203
+ contours : { coloring : 'lines' }
204
+ } ] )
205
+ . then ( function ( ) {
206
+ expect ( getIndices ( ) ) . toEqual ( [ 0 , 1 ] ) ;
207
+ return Plotly . restyle ( gd , 'visible' , false , [ 0 ] ) ;
208
+ } )
209
+ . then ( function ( ) {
210
+ expect ( getIndices ( ) ) . toEqual ( [ 1 ] ) ;
211
+ return Plotly . restyle ( gd , 'visible' , true , [ 0 ] ) ;
212
+ } )
213
+ . then ( function ( ) {
214
+ expect ( getIndices ( ) ) . toEqual ( [ 0 , 1 ] ) ;
215
+ } )
216
+ . catch ( failTest )
217
+ . then ( done ) ;
218
+ } ) ;
218
219
} ) ;
219
220
220
221
describe ( 'image hover' , function ( ) {
0 commit comments