Skip to content

Commit

Permalink
add 'label' in legend event data for pie traces
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed May 1, 2018
1 parent fde209f commit 05e1b6b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ function clickOrDoubleClick(gd, legend, legendItem, numClicks, evt) {
if(trace._group) {
evtData.group = trace._group;
}
if(trace.type === 'pie') {
evtData.label = legendItem.datum()[0].label;
}

var clickVal = Events.triggerHandler(gd, 'plotly_legendclick', evtData);
if(clickVal === false) return;
Expand Down
26 changes: 26 additions & 0 deletions test/jasmine/tests/legend_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,8 @@ describe('legend interaction', function() {
});

gd.once('plotly_restyle', done);
gd.once('plotly_relayout', done);

click(clickArg[0], clickArg[1])();
});
}
Expand Down Expand Up @@ -1408,6 +1410,30 @@ describe('legend interaction', function() {
.catch(failTest)
.then(done);
});

it('should have correct keys (pie case)', function(done) {
Plotly.newPlot(gd, [{
type: 'pie',
labels: ['A', 'B', 'C', 'D'],
values: [1, 2, 1, 3]
}])
.then(function() {
return clickAndCheck([0, 1], {
curveNumber: 0,
expandedIndex: 0,
label: 'D'
});
})
.then(function() {
return clickAndCheck([2, 2], {
curveNumber: 0,
expandedIndex: 0,
label: 'A'
});
})
.catch(failTest)
.then(done);
});
});
});
});

0 comments on commit 05e1b6b

Please sign in to comment.