Skip to content

Commit e860999

Browse files
authored
Merge pull request #1636 from plotly/carpet-legend-dblclick-toggle
Fix carpet legend dblclick toggle
2 parents 93d5d0b + 92bf6f5 commit e860999

File tree

2 files changed

+78
-7
lines changed

2 files changed

+78
-7
lines changed

src/components/legend/draw.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@ function handleClick(g, gd, numClicks) {
514514
allTraces.push(i);
515515
// Allow the legendonly state through for *all* trace types (including
516516
// carpet for which it's overridden with true/false in supplyDefaults)
517-
traceVisibility.push('legendonly');
517+
traceVisibility.push(
518+
Registry.traceIs(fullData[i], 'notLegendIsolatable') ? true : 'legendonly'
519+
);
518520
}
519521

520522
if(legendgroup === '') {

test/jasmine/tests/legend_test.js

+75-6
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,9 @@ describe('legend interaction', function() {
650650
done();
651651
});
652652
});
653-
afterAll(function() {
654-
destroyGraphDiv();
655-
});
653+
654+
afterAll(destroyGraphDiv);
655+
656656
describe('single click', function() {
657657
it('should hide slice', function(done) {
658658
legendItem.dispatchEvent(new MouseEvent('mousedown'));
@@ -663,9 +663,11 @@ describe('legend interaction', function() {
663663
done();
664664
}, DBLCLICKDELAY + 20);
665665
});
666+
666667
it('should fade legend item', function() {
667668
expect(+legendItem.parentNode.style.opacity).toBeLessThan(1);
668669
});
670+
669671
it('should unhide slice', function(done) {
670672
legendItem.dispatchEvent(new MouseEvent('mousedown'));
671673
legendItem.dispatchEvent(new MouseEvent('mouseup'));
@@ -674,6 +676,7 @@ describe('legend interaction', function() {
674676
done();
675677
}, DBLCLICKDELAY + 20);
676678
});
679+
677680
it('should unfade legend item', function() {
678681
expect(+legendItem.parentNode.style.opacity).toBe(1);
679682
});
@@ -691,6 +694,7 @@ describe('legend interaction', function() {
691694
done();
692695
}, 20);
693696
});
697+
694698
it('should fade other legend items', function() {
695699
var legendItemi;
696700
for(var i = 0; i < legendItems.length; i++) {
@@ -702,6 +706,7 @@ describe('legend interaction', function() {
702706
}
703707
}
704708
});
709+
705710
it('should unhide all slices', function(done) {
706711
legendItem.dispatchEvent(new MouseEvent('mousedown'));
707712
legendItem.dispatchEvent(new MouseEvent('mouseup'));
@@ -712,6 +717,7 @@ describe('legend interaction', function() {
712717
done();
713718
}, 20);
714719
});
720+
715721
it('should unfade legend items', function() {
716722
var legendItemi;
717723
for(var i = 0; i < legendItems.length; i++) {
@@ -721,6 +727,7 @@ describe('legend interaction', function() {
721727
});
722728
});
723729
});
730+
724731
describe('non-pie chart', function() {
725732
var mockCopy, gd, legendItems, legendItem;
726733
var testEntry = 2;
@@ -736,9 +743,8 @@ describe('legend interaction', function() {
736743
done();
737744
});
738745
});
739-
afterAll(function() {
740-
destroyGraphDiv();
741-
});
746+
747+
afterAll(destroyGraphDiv);
742748

743749
describe('single click', function() {
744750
it('should hide series', function(done) {
@@ -749,9 +755,11 @@ describe('legend interaction', function() {
749755
done();
750756
}, DBLCLICKDELAY + 20);
751757
});
758+
752759
it('should fade legend item', function() {
753760
expect(+legendItem.parentNode.style.opacity).toBeLessThan(1);
754761
});
762+
755763
it('should unhide series', function(done) {
756764
legendItem.dispatchEvent(new MouseEvent('mousedown'));
757765
legendItem.dispatchEvent(new MouseEvent('mouseup'));
@@ -760,10 +768,12 @@ describe('legend interaction', function() {
760768
done();
761769
}, DBLCLICKDELAY + 20);
762770
});
771+
763772
it('should unfade legend item', function() {
764773
expect(+legendItem.parentNode.style.opacity).toBe(1);
765774
});
766775
});
776+
767777
describe('double click', function() {
768778
it('should hide series', function(done) {
769779
legendItem.dispatchEvent(new MouseEvent('mousedown'));
@@ -781,6 +791,7 @@ describe('legend interaction', function() {
781791
done();
782792
}, 20);
783793
});
794+
784795
it('should fade legend item', function() {
785796
var legendItemi;
786797
for(var i = 0; i < legendItems.length; i++) {
@@ -792,6 +803,7 @@ describe('legend interaction', function() {
792803
}
793804
}
794805
});
806+
795807
it('should unhide series', function(done) {
796808
legendItem.dispatchEvent(new MouseEvent('mousedown'));
797809
legendItem.dispatchEvent(new MouseEvent('mouseup'));
@@ -804,6 +816,7 @@ describe('legend interaction', function() {
804816
done();
805817
}, 20);
806818
});
819+
807820
it('should unfade legend items', function() {
808821
var legendItemi;
809822
for(var i = 0; i < legendItems.length; i++) {
@@ -813,4 +826,60 @@ describe('legend interaction', function() {
813826
});
814827
});
815828
});
829+
830+
describe('carpet plots', function() {
831+
afterAll(destroyGraphDiv);
832+
833+
function _click(index) {
834+
var item = d3.selectAll('rect.legendtoggle')[0][index || 0];
835+
return new Promise(function(resolve) {
836+
item.dispatchEvent(new MouseEvent('mousedown'));
837+
item.dispatchEvent(new MouseEvent('mouseup'));
838+
setTimeout(resolve, DBLCLICKDELAY + 20);
839+
});
840+
}
841+
842+
function _dblclick(index) {
843+
var item = d3.selectAll('rect.legendtoggle')[0][index || 0];
844+
return new Promise(function(resolve) {
845+
item.dispatchEvent(new MouseEvent('mousedown'));
846+
item.dispatchEvent(new MouseEvent('mouseup'));
847+
item.dispatchEvent(new MouseEvent('mousedown'));
848+
item.dispatchEvent(new MouseEvent('mouseup'));
849+
setTimeout(resolve, 20);
850+
});
851+
}
852+
853+
function assertVisible(gd, expectation) {
854+
var actual = gd._fullData.map(function(trace) { return trace.visible; });
855+
expect(actual).toEqual(expectation);
856+
}
857+
858+
it('should ignore carpet traces when toggling', function(done) {
859+
var _mock = Lib.extendDeep({}, require('@mocks/cheater.json'));
860+
var gd = createGraphDiv();
861+
862+
Plotly.plot(gd, _mock).then(function() {
863+
assertVisible(gd, [true, true, true, true]);
864+
})
865+
.then(_click)
866+
.then(function() {
867+
assertVisible(gd, [true, 'legendonly', true, true]);
868+
})
869+
.then(_click)
870+
.then(function() {
871+
assertVisible(gd, [true, true, true, true]);
872+
})
873+
.then(_dblclick)
874+
.then(function() {
875+
assertVisible(gd, [true, true, 'legendonly', 'legendonly']);
876+
})
877+
.then(_dblclick)
878+
.then(function() {
879+
assertVisible(gd, [true, true, true, true]);
880+
})
881+
.catch(fail)
882+
.then(done);
883+
});
884+
});
816885
});

0 commit comments

Comments
 (0)