Skip to content
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

legend: enable selection of a trace by clicking its symbol #3635

Merged
merged 2 commits into from
Mar 18, 2019
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: 6 additions & 3 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ module.exports = function draw(gd) {
})
.each(function() {
d3.select(this)
.call(drawTexts, gd, maxLength)
.call(setupTraceToggle, gd);
.call(drawTexts, gd, maxLength);
})
.call(style, gd);
.call(style, gd)
.each(function() {
d3.select(this)
.call(setupTraceToggle, gd);
});

Lib.syncOrAsync([Plots.previousPromises,
function() {
Expand Down
27 changes: 27 additions & 0 deletions test/jasmine/tests/legend_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var assertPlotSize = require('../assets/custom_assertions').assertPlotSize;

var mock = require('@mocks/legend_horizontal.json');

var Drawing = require('@src/components/drawing');

describe('legend defaults', function() {
Expand Down Expand Up @@ -1639,3 +1641,28 @@ describe('legend interaction', function() {
});
});
});

describe('legend DOM', function() {
'use strict';

afterEach(destroyGraphDiv);

it('draws `legendtoggle` last to make sure it is unobstructed', function(done) {
var gd = createGraphDiv();
Plotly.newPlot(gd, mock)
.then(function() {
// Find legend in figure
var legend = document.getElementsByClassName('legend')[0];

// For each legend item
var legendItems = legend.getElementsByClassName('traces');
Array.prototype.slice.call(legendItems).forEach(function(legendItem) {
// Check that the last element is our `legendtoggle`
var lastEl = legendItem.children[legendItem.children.length - 1];
expect(lastEl.getAttribute('class')).toBe('legendtoggle');
});
})
.catch(failTest)
.then(done);
});
});