Skip to content

Commit f89baca

Browse files
committed
make axes available in eventData to give access to its title
1 parent c501b44 commit f89baca

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/components/fx/hover.js

+4
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,10 @@ function _hover(gd, evt, subplot, noHoverEvent) {
670670
for(itemnum = 0; itemnum < hoverData.length; itemnum++) {
671671
var pt = hoverData[itemnum];
672672
var eventData = helpers.makeEventData(pt, pt.trace, pt.cd);
673+
674+
// Add axis information to eventData
675+
eventData.xaxis = gd._fullLayout[pt.trace.xaxis + 'axis'];
676+
eventData.yaxis = gd._fullLayout[pt.trace.yaxis + 'axis'];
673677
newhoverdata.push(eventData);
674678

675679
var ht = false;

test/jasmine/tests/hover_label_test.js

+23
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,29 @@ describe('hover info', function() {
16521652
.catch(failTest)
16531653
.then(done);
16541654
});
1655+
1656+
it('should contain the axis names', function(done) {
1657+
var gd = document.getElementById('graph');
1658+
Plotly.restyle(gd, 'hovertemplate', '%{yaxis.title}:%{y:$.2f}<br>%{xaxis.title}:%{x:0.4f}<extra></extra>')
1659+
.then(function() {
1660+
Fx.hover('graph', evt, 'xy');
1661+
1662+
var hoverTrace = gd._hoverdata[0];
1663+
1664+
expect(hoverTrace.curveNumber).toEqual(0);
1665+
expect(hoverTrace.pointNumber).toEqual(17);
1666+
expect(hoverTrace.x).toEqual(0.388);
1667+
expect(hoverTrace.y).toEqual(1);
1668+
1669+
assertHoverLabelContent({
1670+
nums: 'Cost ($/W​<tspan style="font-size:70%" dy="0.3em">P</tspan><tspan dy="-0.21em">​</tspan>):$1.00\nCumulative Production (GW):0.3880',
1671+
name: '',
1672+
axis: '0.388'
1673+
});
1674+
})
1675+
.catch(failTest)
1676+
.then(done);
1677+
});
16551678
});
16561679
});
16571680

0 commit comments

Comments
 (0)