Skip to content

Fix scattergl unselected marker opacity for array marker opacity traces #2503

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 2 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions src/traces/scattergl/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var subTypes = require('../scatter/subtypes');
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');

var constants = require('./constants');
var DESELECTDIM = require('../../constants/interactions').DESELECTDIM;

function convertStyle(gd, trace) {
var i;
Expand All @@ -41,6 +42,14 @@ function convertStyle(gd, trace) {
opts.marker = convertMarkerStyle(trace);
opts.selected = convertMarkerSelection(trace, trace.selected);
opts.unselected = convertMarkerSelection(trace, trace.unselected);

if(!trace.unselected && Array.isArray(trace.marker.opacity)) {
var mo = trace.marker.opacity;
opts.unselected.opacity = new Array(mo.length);
for(i = 0; i < mo.length; i++) {
opts.unselected.opacity[i] = DESELECTDIM * mo[i];
}
}
}

if(subTypes.hasLines(trace)) {
Expand Down
Binary file added test/image/baselines/gl2d_selectedpoints.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions test/image/mocks/gl2d_selectedpoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"data": [{
"name": "array marker opacity edge case",
"type": "scattergl",
"mode": "markers",
"x": [1, 2, 3, 4, 5, 6],
"y": [1, 3, 2, 4, 5, 7],
"marker": {
"size": 20,
"opacity": [0.9, 0.8, 0.7, 1, 0.6, 0.8]
},
"selectedpoints": [1, 4, 2]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

On master, this gives

image

where selectedpoints is essentially ignored.

}, {
"name": "array marker opacity + set unselected.marker.opacity",
"type": "scattergl",
"mode": "markers",
"x": [1, 2, 3, 4, 5, 6],
"y": [3, 5, 4, 6, 7, 9],
"marker": {
"size": 20,
"opacity": [0.9, 0.8, 0.7, 1, 0.6, 0.8]
},
"unselected": {
"marker": {
"opacity": 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before this commit, this gave:

image

that is unselected.marker.opacity was overrode.

}
},
"selectedpoints": [1, 4, 2]
}],
"layout": {
"showlegend": false
}
}