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

Add plotly-esque point data info to pie & sankey event data #1896

Merged
merged 4 commits into from Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/traces/pie/plot.js
Expand Up @@ -77,6 +77,10 @@ module.exports = function plot(gd, cdpie) {
return;
}

// to have consistent event data compared to other traces
pt.pointNumber = pt.i;
pt.curveNumber = trace.index;

quadrants[pt.pxmid[1] < 0 ? 0 : 1][pt.pxmid[0] < 0 ? 0 : 1].push(pt);

var cx = cd0.cx + depthVector[0],
Expand Down
25 changes: 18 additions & 7 deletions test/jasmine/tests/pie_test.js
Expand Up @@ -178,7 +178,9 @@ describe('pie hovering', function() {
var fields = [
'v', 'label', 'color', 'i', 'hidden',
'text', 'px1', 'pxmid', 'midangle',
'px0', 'largeArc', 'cxFinal', 'cyFinal',
'px0', 'largeArc',
'pointNumber', 'curveNumber',
'cxFinal', 'cyFinal',
'originalEvent'
];

Expand Down Expand Up @@ -392,18 +394,22 @@ describe('Test event property of interactions on a pie plot:', function() {
expect(typeof trace).toEqual(typeof {}, 'points.trace');

var pt = futureData.points[0];
expect(Object.keys(pt)).toEqual([
expect(Object.keys(pt)).toEqual(jasmine.arrayContaining([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, didn't know about arrayContaining!

'v', 'label', 'color', 'i', 'hidden', 'vTotal', 'text', 't',
'trace', 'r', 'cx', 'cy', 'px1', 'pxmid', 'midangle', 'px0',
'largeArc', 'cxFinal', 'cyFinal'
]);
'largeArc', 'cxFinal', 'cyFinal',
'pointNumber', 'curveNumber'
]));
expect(Object.keys(pt).length).toBe(21);

expect(typeof pt.color).toEqual(typeof '#1f77b4', 'points[0].color');
expect(pt.cx).toEqual(200, 'points[0].cx');
expect(pt.cxFinal).toEqual(200, 'points[0].cxFinal');
expect(pt.cy).toEqual(160, 'points[0].cy');
expect(pt.cyFinal).toEqual(160, 'points[0].cyFinal');
expect(pt.hidden).toEqual(false, 'points[0].hidden');
expect(pt.i).toEqual(4, 'points[0].i');
expect(pt.pointNumber).toEqual(4, 'points[0].pointNumber');
expect(pt.label).toEqual('4', 'points[0].label');
expect(pt.largeArc).toEqual(0, 'points[0].largeArc');
expect(pt.midangle).toEqual(1.0471975511965976, 'points[0].midangle');
Expand All @@ -416,6 +422,7 @@ describe('Test event property of interactions on a pie plot:', function() {
expect(typeof pt.trace).toEqual(typeof {}, 'points[0].trace');
expect(pt.v).toEqual(5, 'points[0].v');
expect(pt.vTotal).toEqual(15, 'points[0].vTotal');
expect(pt.curveNumber).toEqual(0, 'points[0].curveNumber');

var evt = futureData.event;
expect(evt.clientX).toEqual(pointPos[0], 'event.clientX');
Expand Down Expand Up @@ -453,18 +460,21 @@ describe('Test event property of interactions on a pie plot:', function() {
expect(typeof trace).toEqual(typeof {}, 'points.trace');

var pt = futureData.points[0];
expect(Object.keys(pt)).toEqual([
expect(Object.keys(pt)).toEqual(jasmine.arrayContaining([
'v', 'label', 'color', 'i', 'hidden', 'vTotal', 'text', 't',
'trace', 'r', 'cx', 'cy', 'px1', 'pxmid', 'midangle', 'px0',
'largeArc', 'cxFinal', 'cyFinal'
]);
'largeArc', 'cxFinal', 'cyFinal',
'pointNumber', 'curveNumber'
]));

expect(typeof pt.color).toEqual(typeof '#1f77b4', 'points[0].color');
expect(pt.cx).toEqual(200, 'points[0].cx');
expect(pt.cxFinal).toEqual(200, 'points[0].cxFinal');
expect(pt.cy).toEqual(160, 'points[0].cy');
expect(pt.cyFinal).toEqual(160, 'points[0].cyFinal');
expect(pt.hidden).toEqual(false, 'points[0].hidden');
expect(pt.i).toEqual(4, 'points[0].i');
expect(pt.pointNumber).toEqual(4, 'points[0].pointNumber');
expect(pt.label).toEqual('4', 'points[0].label');
expect(pt.largeArc).toEqual(0, 'points[0].largeArc');
expect(pt.midangle).toEqual(1.0471975511965976, 'points[0].midangle');
Expand All @@ -477,6 +487,7 @@ describe('Test event property of interactions on a pie plot:', function() {
expect(typeof pt.trace).toEqual(typeof {}, 'points[0].trace');
expect(pt.v).toEqual(5, 'points[0].v');
expect(pt.vTotal).toEqual(15, 'points[0].vTotal');
expect(pt.curveNumber).toEqual(0, 'points[0].curveNumber');

var evt = futureData.event;
expect(evt.clientX).toEqual(pointPos[0], 'event.clientX');
Expand Down