Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0d817fc

Browse filesBrowse files
committed
improve jasmine test
1 parent 5266d29 commit 0d817fc
Copy full SHA for 0d817fc

File tree

Expand file treeCollapse file tree

2 files changed

+115
-109
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+115
-109
lines changed

‎src/traces/image/defaults.js

Copy file name to clipboardExpand all lines: src/traces/image/defaults.js
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,23 @@ module.exports = function supplyDefaults(traceIn, traceOut) {
1717
function coerce(attr, dflt) {
1818
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
1919
}
20+
var z = coerce('z');
21+
if(z === undefined || !z.length) {
22+
traceOut.visible = false;
23+
return;
24+
}
25+
2026
coerce('x0');
2127
coerce('y0');
2228
coerce('dx');
2329
coerce('dy');
24-
coerce('z');
25-
coerce('colormodel');
30+
var colormodel = coerce('colormodel');
2631

27-
coerce('zmin', constants.colormodel[traceOut.colormodel].min);
28-
coerce('zmax', constants.colormodel[traceOut.colormodel].max);
32+
coerce('zmin', constants.colormodel[colormodel].min);
33+
coerce('zmax', constants.colormodel[colormodel].max);
2934
var dims = traceOut.colormodel.length;
3035
var dfltHovertemplate;
31-
if(traceOut.colormodel === 'hsl' || traceOut.colormodel === 'hsla') {
36+
if(colormodel === 'hsl' || colormodel === 'hsla') {
3237
dfltHovertemplate = 'z: [%{z[0]}, %{z[1]}, %{z[2]}' + (dims === 4 ? ', %{z[3]}' : '') + ']' + '<br><span style="text-transform:uppercase">%{colormodel}</span>: [%{c[0]}°, %{c[1]}%, %{c[2]}%' + (dims === 4 ? ', %{c[3]}' : '') + ']';
3338
} else {
3439
dfltHovertemplate = 'z: [%{z[0]}, %{z[1]}, %{z[2]}' + (dims === 4 ? ', %{z[3]}' : '') + ']' + '<br><span style="text-transform:uppercase">%{colormodel}</span>: [%{c[0]}, %{c[1]}, %{c[2]}' + (dims === 4 ? ', %{c[3]}' : '') + ']';

‎test/jasmine/tests/image_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/image_test.js
+105-104Lines changed: 105 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,61 @@
11
var Plotly = require('@lib/index');
2+
var Plots = require('@src/plots/plots');
23
var Lib = require('@src/lib');
34

45
var Image = require('@src/traces/image');
56

67
var d3 = require('d3');
78
var createGraphDiv = require('../assets/create_graph_div');
89
var destroyGraphDiv = require('../assets/destroy_graph_div');
9-
// var supplyAllDefaults = require('../assets/supply_defaults');
1010
var failTest = require('../assets/fail_test');
1111

1212
var customAssertions = require('../assets/custom_assertions');
1313
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
1414
var Fx = require('@src/components/fx');
1515

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+
});
8659
//
8760
// describe('image calc', function() {
8861
// 'use strict';
@@ -148,16 +121,16 @@ describe('image plot', function() {
148121
.then(done);
149122
});
150123

124+
function getImageURL() {
125+
return d3.select('.im > image').attr('href');
126+
}
127+
151128
[['dx', 2, 4], ['dy', 2, 4], ['z[5][5]', [[0, 0, 0, 1]], [[255, 0, 0, 1]]]].forEach(function(test) {
152129
var attr = test[0];
153130
it('should be able to restyle ' + attr, function(done) {
154131
var mock = require('@mocks/image_adventurer.json');
155132
var mockCopy = Lib.extendDeep({}, mock);
156133

157-
function getImageURL() {
158-
return d3.select('.im > image').attr('href');
159-
}
160-
161134
var imageURLs = [];
162135

163136
Plotly.plot(gd, mockCopy).then(function() {
@@ -186,35 +159,63 @@ describe('image plot', function() {
186159
});
187160
});
188161

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+
});
218219
});
219220

220221
describe('image hover', function() {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.