Skip to content

Commit 225d310

Browse files
committed
position hover label above circular links
1 parent 4539d28 commit 225d310

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/traces/sankey/plot.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,23 @@ module.exports = function plot(gd, calcData) {
151151
var obj = d.link.trace.link;
152152
if(obj.hoverinfo === 'none' || obj.hoverinfo === 'skip') return;
153153
var rootBBox = gd._fullLayout._paperdiv.node().getBoundingClientRect();
154-
var boundingBox = element.getBoundingClientRect();
155-
var hoverCenterX = boundingBox.left + boundingBox.width / 2;
156-
var hoverCenterY = boundingBox.top + boundingBox.height / 2;
154+
var hoverCenterX;
155+
var hoverCenterY;
156+
if(d.link.circular) {
157+
hoverCenterX = (d.link.circularPathData.leftInnerExtent + d.link.circularPathData.rightInnerExtent) / 2 + d.parent.translateX;
158+
hoverCenterY = d.link.circularPathData.verticalFullExtent + d.parent.translateY;
159+
} else {
160+
var boundingBox = element.getBoundingClientRect();
161+
hoverCenterX = boundingBox.left + boundingBox.width / 2 - rootBBox.left;
162+
hoverCenterY = boundingBox.top + boundingBox.height / 2 - rootBBox.top;
163+
}
157164

158165
var hovertemplateLabels = {valueLabel: d3.format(d.valueFormat)(d.link.value) + d.valueSuffix};
159166
d.link.fullData = d.link.trace;
160167

161168
var tooltip = Fx.loneHover({
162-
x: hoverCenterX - rootBBox.left,
163-
y: hoverCenterY - rootBBox.top,
169+
x: hoverCenterX,
170+
y: hoverCenterY,
164171
name: hovertemplateLabels.valueLabel,
165172
text: [
166173
d.link.label || '',

src/traces/sankey/render.js

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function linkModel(d, l, i) {
120120
valueFormat: d.valueFormat,
121121
valueSuffix: d.valueSuffix,
122122
sankey: d.sankey,
123+
parent: d,
123124
interactionState: d.interactionState
124125
};
125126
}

0 commit comments

Comments
 (0)