Skip to content

Fix carpet legend dblclick toggle #1636

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
Apr 28, 2017
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
4 changes: 3 additions & 1 deletion src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,9 @@ function handleClick(g, gd, numClicks) {
allTraces.push(i);
// Allow the legendonly state through for *all* trace types (including
// carpet for which it's overridden with true/false in supplyDefaults)
traceVisibility.push('legendonly');
traceVisibility.push(
Registry.traceIs(fullData[i], 'notLegendIsolatable') ? true : 'legendonly'
);
}

if(legendgroup === '') {
Expand Down
81 changes: 75 additions & 6 deletions test/jasmine/tests/legend_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,9 @@ describe('legend interaction', function() {
done();
});
});
afterAll(function() {
destroyGraphDiv();
});

afterAll(destroyGraphDiv);

describe('single click', function() {
it('should hide slice', function(done) {
legendItem.dispatchEvent(new MouseEvent('mousedown'));
Expand All @@ -663,9 +663,11 @@ describe('legend interaction', function() {
done();
}, DBLCLICKDELAY + 20);
});

it('should fade legend item', function() {
expect(+legendItem.parentNode.style.opacity).toBeLessThan(1);
});

it('should unhide slice', function(done) {
legendItem.dispatchEvent(new MouseEvent('mousedown'));
legendItem.dispatchEvent(new MouseEvent('mouseup'));
Expand All @@ -674,6 +676,7 @@ describe('legend interaction', function() {
done();
}, DBLCLICKDELAY + 20);
});

it('should unfade legend item', function() {
expect(+legendItem.parentNode.style.opacity).toBe(1);
});
Expand All @@ -691,6 +694,7 @@ describe('legend interaction', function() {
done();
}, 20);
});

it('should fade other legend items', function() {
var legendItemi;
for(var i = 0; i < legendItems.length; i++) {
Expand All @@ -702,6 +706,7 @@ describe('legend interaction', function() {
}
}
});

it('should unhide all slices', function(done) {
legendItem.dispatchEvent(new MouseEvent('mousedown'));
legendItem.dispatchEvent(new MouseEvent('mouseup'));
Expand All @@ -712,6 +717,7 @@ describe('legend interaction', function() {
done();
}, 20);
});

it('should unfade legend items', function() {
var legendItemi;
for(var i = 0; i < legendItems.length; i++) {
Expand All @@ -721,6 +727,7 @@ describe('legend interaction', function() {
});
});
});

describe('non-pie chart', function() {
var mockCopy, gd, legendItems, legendItem;
var testEntry = 2;
Expand All @@ -736,9 +743,8 @@ describe('legend interaction', function() {
done();
});
});
afterAll(function() {
destroyGraphDiv();
});

afterAll(destroyGraphDiv);

describe('single click', function() {
it('should hide series', function(done) {
Expand All @@ -749,9 +755,11 @@ describe('legend interaction', function() {
done();
}, DBLCLICKDELAY + 20);
});

it('should fade legend item', function() {
expect(+legendItem.parentNode.style.opacity).toBeLessThan(1);
});

it('should unhide series', function(done) {
legendItem.dispatchEvent(new MouseEvent('mousedown'));
legendItem.dispatchEvent(new MouseEvent('mouseup'));
Expand All @@ -760,10 +768,12 @@ describe('legend interaction', function() {
done();
}, DBLCLICKDELAY + 20);
});

it('should unfade legend item', function() {
expect(+legendItem.parentNode.style.opacity).toBe(1);
});
});

describe('double click', function() {
it('should hide series', function(done) {
legendItem.dispatchEvent(new MouseEvent('mousedown'));
Expand All @@ -781,6 +791,7 @@ describe('legend interaction', function() {
done();
}, 20);
});

it('should fade legend item', function() {
var legendItemi;
for(var i = 0; i < legendItems.length; i++) {
Expand All @@ -792,6 +803,7 @@ describe('legend interaction', function() {
}
}
});

it('should unhide series', function(done) {
legendItem.dispatchEvent(new MouseEvent('mousedown'));
legendItem.dispatchEvent(new MouseEvent('mouseup'));
Expand All @@ -804,6 +816,7 @@ describe('legend interaction', function() {
done();
}, 20);
});

it('should unfade legend items', function() {
var legendItemi;
for(var i = 0; i < legendItems.length; i++) {
Expand All @@ -813,4 +826,60 @@ describe('legend interaction', function() {
});
});
});

describe('carpet plots', function() {
afterAll(destroyGraphDiv);

function _click(index) {
var item = d3.selectAll('rect.legendtoggle')[0][index || 0];
return new Promise(function(resolve) {
item.dispatchEvent(new MouseEvent('mousedown'));
item.dispatchEvent(new MouseEvent('mouseup'));
setTimeout(resolve, DBLCLICKDELAY + 20);
});
}

function _dblclick(index) {
var item = d3.selectAll('rect.legendtoggle')[0][index || 0];
return new Promise(function(resolve) {
item.dispatchEvent(new MouseEvent('mousedown'));
item.dispatchEvent(new MouseEvent('mouseup'));
item.dispatchEvent(new MouseEvent('mousedown'));
item.dispatchEvent(new MouseEvent('mouseup'));
setTimeout(resolve, 20);
});
}

function assertVisible(gd, expectation) {
var actual = gd._fullData.map(function(trace) { return trace.visible; });
expect(actual).toEqual(expectation);
}

it('should ignore carpet traces when toggling', function(done) {
var _mock = Lib.extendDeep({}, require('@mocks/cheater.json'));
var gd = createGraphDiv();

Plotly.plot(gd, _mock).then(function() {
assertVisible(gd, [true, true, true, true]);
})
.then(_click)
.then(function() {
assertVisible(gd, [true, 'legendonly', true, true]);
})
.then(_click)
.then(function() {
assertVisible(gd, [true, true, true, true]);
})
.then(_dblclick)
.then(function() {
assertVisible(gd, [true, true, 'legendonly', 'legendonly']);
})
.then(_dblclick)
.then(function() {
assertVisible(gd, [true, true, true, true]);
})
.catch(fail)
.then(done);
});
});
});