Skip to content

Commit add15b1

Browse files
authored
Merge pull request #4635 from plotly/res3939-parcoords-context-line-color
expose parcoords context line color
2 parents fc6486d + b4dabb2 commit add15b1

File tree

5 files changed

+155
-2
lines changed

5 files changed

+155
-2
lines changed

src/traces/parcoords/attributes.js

+17
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,23 @@ module.exports = {
141141
description: 'The dimensions (variables) of the parallel coordinates chart. 2..60 dimensions are supported.'
142142
}),
143143

144+
unselected: {
145+
line: {
146+
color: {
147+
valType: 'color',
148+
dflt: '#777',
149+
role: 'style',
150+
editType: 'plot',
151+
description: [
152+
'Sets the color of lines in the background',
153+
'i.e. unselected lines.'
154+
].join(' ')
155+
},
156+
editType: 'plot'
157+
},
158+
editType: 'plot'
159+
},
160+
144161
line: extendFlat({editType: 'calc'},
145162
colorScaleAttrs('line', {
146163
// the default autocolorscale isn't quite usable for parcoords due to context ambiguity around 0 (grey, off-white)

src/traces/parcoords/constants.js

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module.exports = {
1919
layers: ['contextLineLayer', 'focusLineLayer', 'pickLineLayer'],
2020
axisTitleOffset: 28,
2121
axisExtentOffset: 10,
22-
deselectedLineColor: '#777',
2322
bar: {
2423
width: 4, // Visible width of the filter bar
2524
captureWidth: 10, // Mouse-sensitive width for interaction (Fitts law)

src/traces/parcoords/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,5 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
115115

116116
coerce('labelangle');
117117
coerce('labelside');
118+
coerce('unselected.line.color');
118119
};

src/traces/parcoords/parcoords.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function model(layout, d, i) {
154154
var trace = cd0.trace;
155155
var lineColor = helpers.convertTypedArray(cd0.lineColor);
156156
var line = trace.line;
157-
var deselectedLines = {color: rgba(c.deselectedLineColor)};
157+
var deselectedLines = {color: rgba(trace.unselected.line.color)};
158158
var cOpts = Colorscale.extractOpts(line);
159159
var cscale = cOpts.reversescale ? Colorscale.flipScale(cd0.cscale) : cd0.cscale;
160160
var domain = trace.domain;

test/jasmine/tests/parcoords_test.js

+136
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,12 @@ describe('parcoords Lifecycle methods', function() {
856856
}],
857857
line: {color: 'blue'}
858858
}], {
859+
margin: {
860+
t: 0,
861+
b: 0,
862+
l: 0,
863+
r: 0
864+
},
859865
width: 300,
860866
height: 200
861867
})
@@ -888,6 +894,12 @@ describe('parcoords Lifecycle methods', function() {
888894
}],
889895
line: {color: 'blue'}
890896
}], {
897+
margin: {
898+
t: 0,
899+
b: 0,
900+
l: 0,
901+
r: 0
902+
},
891903
width: 300,
892904
height: 200
893905
})
@@ -910,6 +922,130 @@ describe('parcoords Lifecycle methods', function() {
910922
.catch(failTest)
911923
.then(done);
912924
});
925+
926+
it('@gl unselected.line.color `Plotly.restyle` should change context layer line.color', function(done) {
927+
var testLayer = '.gl-canvas-context';
928+
929+
var list1 = [];
930+
var list2 = [];
931+
for(var i = 0; i <= 100; i++) {
932+
list1[i] = i;
933+
list2[i] = 100 - i;
934+
}
935+
936+
Plotly.plot(gd, [{
937+
type: 'parcoords',
938+
dimensions: [{
939+
constraintrange: [1, 10],
940+
values: list1
941+
}, {
942+
values: list2
943+
}],
944+
line: {color: '#0F0'},
945+
unselected: {line: {color: '#F00'}}
946+
}], {
947+
margin: {
948+
t: 0,
949+
b: 0,
950+
l: 0,
951+
r: 0
952+
},
953+
width: 300,
954+
height: 200
955+
})
956+
.then(function() {
957+
var rgb = getAvgPixelByChannel(testLayer);
958+
expect(rgb[0]).not.toBe(0, 'red');
959+
expect(rgb[1]).toBe(0, 'no green');
960+
expect(rgb[2]).toBe(0, 'no blue');
961+
962+
return Plotly.restyle(gd, 'unselected.line.color', '#00F');
963+
})
964+
.then(function() {
965+
var rgb = getAvgPixelByChannel(testLayer);
966+
expect(rgb[0]).toBe(0, 'no red');
967+
expect(rgb[1]).toBe(0, 'no green');
968+
expect(rgb[2]).not.toBe(0, 'blue');
969+
970+
return Plotly.restyle(gd, 'unselected.line.color', 'rgba(0,0,0,0)');
971+
})
972+
.then(function() {
973+
var rgb = getAvgPixelByChannel(testLayer);
974+
expect(rgb[0]).toBe(0, 'no red');
975+
expect(rgb[1]).toBe(0, 'no green');
976+
expect(rgb[2]).toBe(0, 'no blue');
977+
})
978+
.catch(failTest)
979+
.then(done);
980+
});
981+
982+
it('@gl unselected.line.color `Plotly.react` should change line.color and unselected.line.color', function(done) {
983+
var unselectedLayer = '.gl-canvas-context';
984+
var selectedLayer = '.gl-canvas-focus';
985+
986+
var list1 = [];
987+
var list2 = [];
988+
for(var i = 0; i <= 100; i++) {
989+
list1[i] = i;
990+
list2[i] = 100 - i;
991+
}
992+
993+
var fig = {
994+
data: [{
995+
type: 'parcoords',
996+
dimensions: [{
997+
constraintrange: [1, 10],
998+
values: list1
999+
}, {
1000+
values: list2
1001+
}],
1002+
line: {color: '#0F0'},
1003+
unselected: {line: {color: '#F00'}}
1004+
}],
1005+
layout: {
1006+
margin: {
1007+
t: 0,
1008+
b: 0,
1009+
l: 0,
1010+
r: 0
1011+
},
1012+
width: 300,
1013+
height: 200
1014+
}
1015+
};
1016+
1017+
var rgb;
1018+
1019+
Plotly.newPlot(gd, fig)
1020+
.then(function() {
1021+
rgb = getAvgPixelByChannel(unselectedLayer);
1022+
expect(rgb[0]).not.toBe(0, 'red');
1023+
expect(rgb[1]).toBe(0, 'no green');
1024+
expect(rgb[2]).toBe(0, 'no blue');
1025+
1026+
rgb = getAvgPixelByChannel(selectedLayer);
1027+
expect(rgb[0]).toBe(0, 'no red');
1028+
expect(rgb[1]).not.toBe(0, 'green');
1029+
expect(rgb[2]).toBe(0, 'no blue');
1030+
1031+
fig.data[0].line.color = '#FF0';
1032+
fig.data[0].unselected.line.color = '#00F';
1033+
return Plotly.react(gd, fig);
1034+
})
1035+
.then(function() {
1036+
rgb = getAvgPixelByChannel(selectedLayer);
1037+
expect(rgb[0]).not.toBe(0, 'red');
1038+
expect(rgb[1]).not.toBe(0, 'green');
1039+
expect(rgb[2]).toBe(0, 'no blue');
1040+
1041+
rgb = getAvgPixelByChannel(unselectedLayer);
1042+
expect(rgb[0]).toBe(0, 'no red');
1043+
expect(rgb[1]).toBe(0, 'no green');
1044+
expect(rgb[2]).not.toBe(0, 'blue');
1045+
})
1046+
.catch(failTest)
1047+
.then(done);
1048+
});
9131049
});
9141050

9151051
describe('parcoords basic use', function() {

0 commit comments

Comments
 (0)