Skip to content

add unselected.line.color and unselected.line.opacity options to parcoords trace #6216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/6216_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add `unselected.line.color` and `unselected.line.opacity` options to `parcoords` trace [[#6216](https://github.com/plotly/plotly.js/pull/6216)]
23 changes: 22 additions & 1 deletion src/traces/parcoords/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,26 @@ module.exports = {
autoColorDflt: false,
editTypeOverride: 'calc'
})
)
),

unselected: {
line: {
color: {
valType: 'color',
dflt: '',
editType: 'plot',
description: 'Sets the color of unselected lines.'
},
opacity: {
valType: 'number',
min: 0,
max: 1,
dflt: 'auto',
editType: 'plot',
description: 'Sets the opacity of unselected lines.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we describe 'auto'? Not the full formula, just qualitatively something like "The default 'auto' decreases the opacity smoothly as the number of lines increases."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Addressed in 47bef38.

},
editType: 'plot'
},
editType: 'plot'
}
};
1 change: 0 additions & 1 deletion src/traces/parcoords/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = {
layers: ['contextLineLayer', 'focusLineLayer', 'pickLineLayer'],
axisTitleOffset: 28,
axisExtentOffset: 10,
deselectedLineColor: '#777',
bar: {
width: 4, // Visible width of the filter bar
captureWidth: 10, // Mouse-sensitive width for interaction (Fitts law)
Expand Down
7 changes: 7 additions & 0 deletions src/traces/parcoords/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}

function coerce2(attr, dflt) {
return Lib.coerce2(traceIn, traceOut, attributes, attr, dflt);
}

var dimensionsIn = traceIn.dimensions;
if(Array.isArray(dimensionsIn) && dimensionsIn.length > maxDimensionCount) {
Lib.log('parcoords traces support up to ' + maxDimensionCount + ' dimensions at the moment');
Expand Down Expand Up @@ -107,4 +111,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('labelangle');
coerce('labelside');

var unselectedLineColor = coerce2('unselected.line.color');
coerce('unselected.line.opacity', unselectedLineColor ? 1 : 'auto');
};
5 changes: 3 additions & 2 deletions src/traces/parcoords/lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function makeItem(
var layoutWidth = model.layoutWidth * plotGlPixelRatio;

var deselectedLinesColor = model.deselectedLines.color;
var deselectedLinesOpacity = model.deselectedLines.opacity;

var itemModel = Lib.extendFlat({
key: crossfilterDimensionIndex,
Expand All @@ -206,8 +207,8 @@ function makeItem(
deselectedLinesColor[0] / 255,
deselectedLinesColor[1] / 255,
deselectedLinesColor[2] / 255,
deselectedLinesColor[3] < 1 ?
deselectedLinesColor[3] :
deselectedLinesOpacity !== 'auto' ?
deselectedLinesColor[3] * deselectedLinesOpacity :
Math.max(1 / 255, Math.pow(1 / model.lines.color.length, 1 / 3))
],

Expand Down
5 changes: 4 additions & 1 deletion src/traces/parcoords/parcoords.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ function model(layout, d, i) {
var trace = cd0.trace;
var lineColor = helpers.convertTypedArray(cd0.lineColor);
var line = trace.line;
var deselectedLines = {color: rgba(c.deselectedLineColor)};
var deselectedLines = {
color: rgba(trace.unselected.line.color || '#777'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can '#777' be the attribute default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Using #777 (explicitly or any other color) should set the color of lines to exactly that color.
But I am open to using auto instead of blank string as the dflt of unselected.line.color, if you prefer that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have lots of examples where a color and an opacity are specified side-by-side... and it doesn't mean it's NOT that color, just that there's opacity applied later that dilutes it.

Actually thinking about this a bit more, I might even suggest removing the "set opacity to 1 if a color is explicitly specified" and keep 'auto' as the consistent default, because if you did want to change this color most likely you still want it diluted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Addressed in 47bef38.

opacity: trace.unselected.line.opacity
};
var cOpts = Colorscale.extractOpts(line);
var cscale = cOpts.reversescale ? Colorscale.flipScale(cd0.cscale) : cd0.cscale;
var domain = trace.domain;
Expand Down
Binary file modified test/image/baselines/gl2d_parcoords_constraints.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_parcoords_dark_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions test/image/mocks/gl2d_parcoords_constraints.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
]
},

"unselected": {
"line": {
"color": "white"
}
},

"dimensions": [
{
"label": "±1.1",
Expand Down
6 changes: 6 additions & 0 deletions test/image/mocks/gl2d_parcoords_dark_background.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"color": [-41, -1317, -164, -1856, -79, -931, -191, -2983, -341, -3846, -278, -3019, -523, -2357, -985, -3447, -211, -2842, -458, -4388, -784, -2563, -935, -2253, -313, -3667, -1479, -1030, -632, -623, -1945, -1324, -1221, -878, -947, -1615, -697, -575, -482, -905, -869, -433, -484, -349, -667, -248, -1135, -888, -1019, -223, -2067, -729, -579, -659, -334, -340, -554, -455, -377, -375, -453, -834, -934, -334, -369, -290, -354, -497, -490, -329, -729, -1794, -151, -1162, -3935, -1013, -509, -825, -997, -320, -680, -422, -785, -542, -563, -489, -1283, -680, -78, -450, -514, -449, -548, -661, -641, -503, -570, -257, -394, -450]
},

"unselected": {
"line": {
"opacity": 0.5
}
},

"dimensions": [
{
"constraintrange": [100000, 150000],
Expand Down
122 changes: 122 additions & 0 deletions test/jasmine/tests/parcoords_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,128 @@ describe('parcoords Lifecycle methods', function() {
})
.then(done, done.fail);
});

it('@gl unselected.line.color `Plotly.restyle` should change context layer line.color', function(done) {
var testLayer = '.gl-canvas-context';

var list1 = [];
var list2 = [];
for(var i = 0; i <= 100; i++) {
list1[i] = i;
list2[i] = 100 - i;
}

Plotly.newPlot(gd, [{
type: 'parcoords',
dimensions: [{
constraintrange: [1, 10],
values: list1
}, {
values: list2
}],
line: {color: '#0F0'},
unselected: {line: {color: '#F00'}}
}], {
margin: {
t: 0,
b: 0,
l: 0,
r: 0
},
width: 300,
height: 200
})
.then(function() {
var rgb = getAvgPixelByChannel(testLayer);
expect(rgb[0]).not.toBe(0, 'red');
expect(rgb[1]).toBe(0, 'no green');
expect(rgb[2]).toBe(0, 'no blue');

return Plotly.restyle(gd, 'unselected.line.color', '#00F');
})
.then(function() {
var rgb = getAvgPixelByChannel(testLayer);
expect(rgb[0]).toBe(0, 'no red');
expect(rgb[1]).toBe(0, 'no green');
expect(rgb[2]).not.toBe(0, 'blue');

return Plotly.restyle(gd, 'unselected.line.color', 'rgba(0,0,0,0)');
})
.then(function() {
var rgb = getAvgPixelByChannel(testLayer);
expect(rgb[0]).toBe(0, 'no red');
expect(rgb[1]).toBe(0, 'no green');
expect(rgb[2]).toBe(0, 'no blue');
})
.then(done, done.fail);
});

it('@gl unselected.line.color `Plotly.react` should change line.color and unselected.line.color', function(done) {
var unselectedLayer = '.gl-canvas-context';
var selectedLayer = '.gl-canvas-focus';

var list1 = [];
var list2 = [];
for(var i = 0; i <= 100; i++) {
list1[i] = i;
list2[i] = 100 - i;
}

var fig = {
data: [{
type: 'parcoords',
dimensions: [{
constraintrange: [1, 10],
values: list1
}, {
values: list2
}],
line: {color: '#0F0'},
unselected: {line: {color: '#F00'}}
}],
layout: {
margin: {
t: 0,
b: 0,
l: 0,
r: 0
},
width: 300,
height: 200
}
};

var rgb;

Plotly.newPlot(gd, fig)
.then(function() {
rgb = getAvgPixelByChannel(unselectedLayer);
expect(rgb[0]).not.toBe(0, 'red');
expect(rgb[1]).toBe(0, 'no green');
expect(rgb[2]).toBe(0, 'no blue');

rgb = getAvgPixelByChannel(selectedLayer);
expect(rgb[0]).toBe(0, 'no red');
expect(rgb[1]).not.toBe(0, 'green');
expect(rgb[2]).toBe(0, 'no blue');

fig.data[0].line.color = '#FF0';
fig.data[0].unselected.line.color = '#00F';
return Plotly.react(gd, fig);
})
.then(function() {
rgb = getAvgPixelByChannel(selectedLayer);
expect(rgb[0]).not.toBe(0, 'red');
expect(rgb[1]).not.toBe(0, 'green');
expect(rgb[2]).toBe(0, 'no blue');

rgb = getAvgPixelByChannel(unselectedLayer);
expect(rgb[0]).toBe(0, 'no red');
expect(rgb[1]).toBe(0, 'no green');
expect(rgb[2]).not.toBe(0, 'blue');
})
.then(done, done.fail);
});
});

describe('parcoords hover', function() {
Expand Down
22 changes: 22 additions & 0 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -40355,6 +40355,28 @@
"editType": "none",
"valType": "any"
},
"unselected": {
"editType": "plot",
"line": {
"color": {
"description": "Sets the color of unselected lines.",
"dflt": "",
"editType": "plot",
"valType": "color"
},
"editType": "plot",
"opacity": {
"description": "Sets the opacity of unselected lines.",
"dflt": "auto",
"editType": "plot",
"max": 1,
"min": 0,
"valType": "number"
},
"role": "object"
},
"role": "object"
},
"visible": {
"description": "Determines whether or not this trace is visible. If *legendonly*, the trace is not drawn, but can appear as a legend item (provided that the legend itself is visible).",
"dflt": true,
Expand Down