Skip to content

Commit 4db5f99

Browse files
authored
Merge pull request #3195 from plotly/issue-3178
Second jasmine test to lock issue #3101
2 parents fe2d8d7 + 3c223f2 commit 4db5f99

File tree

1 file changed

+60
-22
lines changed

1 file changed

+60
-22
lines changed

test/jasmine/tests/parcoords_test.js

+60-22
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ function purgeGraphDiv(done) {
4545
return delay(50)().then(done);
4646
}
4747

48+
function getAvgPixelByChannel(id) {
49+
var canvas = d3.select(id).node();
50+
51+
var imgData = readPixel(canvas, 0, 0, canvas.width, canvas.height);
52+
var n = imgData.length * 0.25;
53+
var r = 0;
54+
var g = 0;
55+
var b = 0;
56+
57+
for(var i = 0; i < imgData.length; i++) {
58+
r += imgData[i++];
59+
g += imgData[i++];
60+
b += imgData[i++];
61+
}
62+
return [r / n, g / n, b / n];
63+
}
64+
4865
describe('parcoords initialization tests', function() {
4966

5067
'use strict';
@@ -799,22 +816,39 @@ describe('parcoords Lifecycle methods', function() {
799816
});
800817
});
801818

802-
it('@gl line.color `Plotly.restyle` should work', function(done) {
803-
function getAvgPixelByChannel() {
804-
var canvas = d3.select('.gl-canvas-focus').node();
805-
var imgData = readPixel(canvas, 0, 0, canvas.width, canvas.height);
806-
var n = imgData.length / 4;
807-
var r = 0;
808-
var g = 0;
809-
var b = 0;
810-
811-
for(var i = 0; i < imgData.length; i++) {
812-
r += imgData[i++];
813-
g += imgData[i++];
814-
b += imgData[i++];
815-
}
816-
return [r / n, g / n, b / n];
817-
}
819+
it('@gl line.color `Plotly.restyle` should change focus layer', function(done) {
820+
var testLayer = '.gl-canvas-focus';
821+
Plotly.plot(gd, [{
822+
type: 'parcoords',
823+
dimensions: [{
824+
values: [1, 2]
825+
}, {
826+
values: [2, 4]
827+
}],
828+
line: {color: 'blue'}
829+
}], {
830+
width: 300,
831+
height: 200
832+
})
833+
.then(function() {
834+
var rgb = getAvgPixelByChannel(testLayer);
835+
expect(rgb[0]).toBe(0, 'no red');
836+
expect(rgb[2]).not.toBe(0, 'all blue');
837+
838+
return Plotly.restyle(gd, 'line.color', 'red');
839+
})
840+
.then(function() {
841+
var rgb = getAvgPixelByChannel(testLayer);
842+
expect(rgb[0]).not.toBe(0, 'all red');
843+
expect(rgb[2]).toBe(0, 'no blue');
844+
})
845+
.catch(failTest)
846+
.then(done);
847+
});
848+
849+
it('@gl line.color `Plotly.restyle` should not change context layer', function(done) {
850+
var testLayer = '.gl-canvas-context';
851+
var old_rgb, new_rgb;
818852

819853
Plotly.plot(gd, [{
820854
type: 'parcoords',
@@ -829,16 +863,20 @@ describe('parcoords Lifecycle methods', function() {
829863
height: 200
830864
})
831865
.then(function() {
832-
var rbg = getAvgPixelByChannel();
833-
expect(rbg[0]).toBe(0, 'no red');
834-
expect(rbg[2]).not.toBe(0, 'all blue');
866+
var rgb = getAvgPixelByChannel(testLayer);
867+
old_rgb = rgb[0] + rgb[1] + rgb[2] / 3.0;
868+
expect(old_rgb).toBeGreaterThan(0, 'not all black');
869+
expect(old_rgb).toBeLessThan(255, 'not all white');
835870

836871
return Plotly.restyle(gd, 'line.color', 'red');
837872
})
838873
.then(function() {
839-
var rbg = getAvgPixelByChannel();
840-
expect(rbg[0]).not.toBe(0, 'all red');
841-
expect(rbg[2]).toBe(0, 'no blue');
874+
var rgb = getAvgPixelByChannel(testLayer);
875+
new_rgb = rgb[0] + rgb[1] + rgb[2] / 3.0;
876+
expect(new_rgb).toBeGreaterThan(0, 'not all black');
877+
expect(new_rgb).toBeLessThan(255, 'not all white');
878+
879+
expect(new_rgb).toBe(old_rgb, 'no change to context');
842880
})
843881
.catch(failTest)
844882
.then(done);

0 commit comments

Comments
 (0)