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 3 commits
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
26 changes: 16 additions & 10 deletions src/traces/sankey/plot.js
Expand Up @@ -115,24 +115,26 @@ function castHoverOption(trace, attr) {
}

module.exports = function plot(gd, calcData) {

var fullLayout = gd._fullLayout;
var svg = fullLayout._paper;
var size = fullLayout._size;

var linkSelect = function(element, d) {
gd._hoverdata = [d.link];
gd._hoverdata.trace = calcData.trace;
var evt = d.link;
evt.originalEvent = d3.event;
gd._hoverdata = [evt];
Fx.click(gd, { target: true });
};

var linkHover = function(element, d, sankey) {
var evt = d.link;
evt.originalEvent = d3.event;
d3.select(element).call(linkHoveredStyle.bind(0, d, sankey, true));
Fx.hover(gd, d.link, 'sankey');
Fx.hover(gd, evt, 'sankey');
};

var linkHoverFollow = function(element, d) {
var trace = gd._fullData[d.traceId];
var trace = d.link.trace;
var rootBBox = gd.getBoundingClientRect();
var boundingBox = element.getBoundingClientRect();
var hoverCenterX = boundingBox.left + boundingBox.width / 2;
Expand Down Expand Up @@ -166,26 +168,30 @@ module.exports = function plot(gd, calcData) {
var linkUnhover = function(element, d, sankey) {
d3.select(element).call(linkNonHoveredStyle.bind(0, d, sankey, true));
gd.emit('plotly_unhover', {
event: d3.event,
points: [d.link]
});

Fx.loneUnhover(fullLayout._hoverlayer.node());
};

var nodeSelect = function(element, d, sankey) {
gd._hoverdata = [d.node];
gd._hoverdata.trace = calcData.trace;
var evt = d.node;
evt.originalEvent = d3.event;
gd._hoverdata = [evt];
d3.select(element).call(nodeNonHoveredStyle, d, sankey);
Fx.click(gd, { target: true });
};

var nodeHover = function(element, d, sankey) {
var evt = d.node;
evt.originalEvent = d3.event;
d3.select(element).call(nodeHoveredStyle, d, sankey);
Fx.hover(gd, d.node, 'sankey');
Fx.hover(gd, evt, 'sankey');
};

var nodeHoverFollow = function(element, d) {
var trace = gd._fullData[d.traceId];
var trace = d.node.trace;
var nodeRect = d3.select(element).select('.nodeRect');
var rootBBox = gd.getBoundingClientRect();
var boundingBox = nodeRect.node().getBoundingClientRect();
Expand Down Expand Up @@ -220,9 +226,9 @@ module.exports = function plot(gd, calcData) {
};

var nodeUnhover = function(element, d, sankey) {

d3.select(element).call(nodeNonHoveredStyle, d, sankey);
gd.emit('plotly_unhover', {
event: d3.event,
points: [d.node]
});

Expand Down
14 changes: 11 additions & 3 deletions src/traces/sankey/render.js
Expand Up @@ -65,7 +65,6 @@ function switchToSankeyFormat(nodes) {
// view models

function sankeyModel(layout, d, i) {

var trace = unwrap(d).trace,
domain = trace.domain,
nodeSpec = trace.node,
Expand Down Expand Up @@ -121,6 +120,7 @@ function sankeyModel(layout, d, i) {

return {
key: i,
trace: trace,
guid: Math.floor(1e12 * (1 + Math.random())),
horizontal: horizontal,
width: width,
Expand Down Expand Up @@ -150,13 +150,17 @@ function sankeyModel(layout, d, i) {
}

function linkModel(uniqueKeys, d, l) {

var tc = tinycolor(l.color);
var basicKey = l.source.label + '|' + l.target.label;
var foundKey = uniqueKeys[basicKey];
uniqueKeys[basicKey] = (foundKey === void(0) ? foundKey : 0) + 1;
var key = basicKey + (foundKey === void(0) ? '' : '__' + foundKey);

// for event data
l.trace = d.trace;
l.curveNumber = d.trace.index;
l.pointNumber = 'TODO';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@monfera is there a easy way to grab the pointNumber value off the sankey link & node d3-esque data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 15dc324

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @etpinard I missed the question on the road, now see it's done, very nice! 🙇


return {
key: key,
traceId: d.key,
Expand All @@ -173,7 +177,6 @@ function linkModel(uniqueKeys, d, l) {
}

function nodeModel(uniqueKeys, d, n) {

var tc = tinycolor(n.color),
zoneThicknessPad = c.nodePadAcross,
zoneLengthPad = d.nodePad / 2,
Expand All @@ -185,6 +188,11 @@ function nodeModel(uniqueKeys, d, n) {
uniqueKeys[basicKey] = (foundKey === void(0) ? foundKey : 0) + 1;
var key = basicKey + (foundKey === void(0) ? '' : '__' + foundKey);

// for event data
n.trace = d.trace;
n.curveNumber = d.trace.index;
n.pointNumber = 'TODO';

return {
key: key,
traceId: d.key,
Expand Down