Skip to content

Commit 05e1b6b

Browse files
committed
add 'label' in legend event data for pie traces
1 parent fde209f commit 05e1b6b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/components/legend/draw.js

+3
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ function clickOrDoubleClick(gd, legend, legendItem, numClicks, evt) {
374374
if(trace._group) {
375375
evtData.group = trace._group;
376376
}
377+
if(trace.type === 'pie') {
378+
evtData.label = legendItem.datum()[0].label;
379+
}
377380

378381
var clickVal = Events.triggerHandler(gd, 'plotly_legendclick', evtData);
379382
if(clickVal === false) return;

test/jasmine/tests/legend_test.js

+26
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,8 @@ describe('legend interaction', function() {
13531353
});
13541354

13551355
gd.once('plotly_restyle', done);
1356+
gd.once('plotly_relayout', done);
1357+
13561358
click(clickArg[0], clickArg[1])();
13571359
});
13581360
}
@@ -1408,6 +1410,30 @@ describe('legend interaction', function() {
14081410
.catch(failTest)
14091411
.then(done);
14101412
});
1413+
1414+
it('should have correct keys (pie case)', function(done) {
1415+
Plotly.newPlot(gd, [{
1416+
type: 'pie',
1417+
labels: ['A', 'B', 'C', 'D'],
1418+
values: [1, 2, 1, 3]
1419+
}])
1420+
.then(function() {
1421+
return clickAndCheck([0, 1], {
1422+
curveNumber: 0,
1423+
expandedIndex: 0,
1424+
label: 'D'
1425+
});
1426+
})
1427+
.then(function() {
1428+
return clickAndCheck([2, 2], {
1429+
curveNumber: 0,
1430+
expandedIndex: 0,
1431+
label: 'A'
1432+
});
1433+
})
1434+
.catch(failTest)
1435+
.then(done);
1436+
});
14111437
});
14121438
});
14131439
});

0 commit comments

Comments
 (0)