Skip to content

Commit c3c33fe

Browse files
authored
Merge pull request #3178 from plotly/parcoords-restyle-fix
Parcoords line.color restyle fix
2 parents e03d686 + a8fd24f commit c3c33fe

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

Diff for: src/traces/parcoords/parcoords.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,15 @@ module.exports = function(root, svg, parcoordsLineLayers, styledData, layout, ca
456456

457457
parcoordsLineLayer
458458
.each(function(d) {
459-
460459
if(d.viewModel) {
461-
if(d.lineLayer) d.lineLayer.update(d);
462-
else d.lineLayer = lineLayerMaker(this, d);
460+
if(!d.lineLayer || callbacks) { // recreate in case of having callbacks e.g. restyle. Should we test for callback to be a restyle?
461+
d.lineLayer = lineLayerMaker(this, d);
462+
} else d.lineLayer.update(d);
463463

464-
d.viewModel[d.key] = d.lineLayer;
464+
if(d.key || d.key === 0) d.viewModel[d.key] = d.lineLayer;
465465

466-
var setChanged = ((d.key) &&
467-
(((d.key !== 'contextLayer') || (callbacks)) || // unless there is callback on this line layer
468-
(!d.context))); // don't update background
466+
var setChanged = (!d.context || // don't update background
467+
callbacks); // unless there is a callback on the context layer. Should we test the callback?
469468

470469
d.lineLayer.render(d.viewModel.panels, setChanged);
471470
}

Diff for: test/jasmine/tests/config_test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var click = require('../assets/click');
77
var mouseEvent = require('../assets/mouse_event');
88
var failTest = require('../assets/fail_test');
99
var delay = require('../assets/delay');
10+
var RESIZE_DELAY = 300;
1011

1112
describe('config argument', function() {
1213

@@ -585,7 +586,7 @@ describe('config argument', function() {
585586
viewport.set(width / 2, height / 2);
586587

587588
return Promise.resolve()
588-
.then(delay(200))
589+
.then(delay(RESIZE_DELAY))
589590
.then(function() {
590591
checkLayoutSize(elWidth / 2, elHeight / 2);
591592
})
@@ -639,7 +640,7 @@ describe('config argument', function() {
639640
Plotly.plot(gd, data, {}, {responsive: true})
640641
.then(function() {return Plotly.restyle(gd, 'y[0]', data[0].y[0] + 2);})
641642
.then(function() {viewport.set(width / 2, width / 2);})
642-
.then(delay(200))
643+
.then(delay(RESIZE_DELAY))
643644
// .then(function() {viewport.set(newWidth, 2 * newHeight);}).then(delay(200))
644645
.then(function() {
645646
expect(cntWindowResize).toBe(1);
@@ -667,7 +668,7 @@ describe('config argument', function() {
667668
// Resize viewport
668669
.then(function() {viewport.set(width / 2, height / 2);})
669670
// Wait for resize to happen (Plotly.resize has an internal timeout)
670-
.then(delay(200))
671+
.then(delay(RESIZE_DELAY))
671672
// Check that final figure's size hasn't changed
672673
.then(function() {checkLayoutSize(width, height);})
673674
.catch(failTest)

Diff for: test/jasmine/tests/parcoords_test.js

+46-1
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,51 @@ describe('parcoords Lifecycle methods', function() {
790790
.then(done);
791791
});
792792
});
793+
794+
it('@gl line.color `Plotly.restyle` should work', function(done) {
795+
function getAvgPixelByChannel() {
796+
var canvas = d3.select('.gl-canvas-focus').node();
797+
var imgData = readPixel(canvas, 0, 0, canvas.width, canvas.height);
798+
var n = imgData.length / 4;
799+
var r = 0;
800+
var g = 0;
801+
var b = 0;
802+
803+
for(var i = 0; i < imgData.length; i++) {
804+
r += imgData[i++];
805+
g += imgData[i++];
806+
b += imgData[i++];
807+
}
808+
return [r / n, g / n, b / n];
809+
}
810+
811+
Plotly.plot(gd, [{
812+
type: 'parcoords',
813+
dimensions: [{
814+
values: [1, 2]
815+
}, {
816+
values: [2, 4]
817+
}],
818+
line: {color: 'blue'}
819+
}], {
820+
width: 300,
821+
height: 200
822+
})
823+
.then(function() {
824+
var rbg = getAvgPixelByChannel();
825+
expect(rbg[0]).toBe(0, 'no red');
826+
expect(rbg[2]).not.toBe(0, 'all blue');
827+
828+
return Plotly.restyle(gd, 'line.color', 'red');
829+
})
830+
.then(function() {
831+
var rbg = getAvgPixelByChannel();
832+
expect(rbg[0]).not.toBe(0, 'all red');
833+
expect(rbg[2]).toBe(0, 'no blue');
834+
})
835+
.catch(failTest)
836+
.then(done);
837+
});
793838
});
794839

795840
describe('parcoords basic use', function() {
@@ -868,7 +913,7 @@ describe('parcoords basic use', function() {
868913

869914
});
870915

871-
it('@gl Calling `Plotly.restyle` with a string path should amend the preexisting parcoords', function(done) {
916+
it('@gl Calling `Plotly.restyle` with a string path to colorscale should amend the preexisting parcoords', function(done) {
872917

873918
expect(gd.data.length).toEqual(1);
874919

0 commit comments

Comments
 (0)