Skip to content

Commit a0ff6a1

Browse files
committedFeb 15, 2019
add support for layout.meta references from hovertemplate
1 parent 1808fef commit a0ff6a1

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
 

‎src/components/fx/hover.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,12 @@ function createHoverText(hoverData, opts, gd) {
975975
var hovertemplateLabels = d.hovertemplateLabels || d;
976976
var eventData = d.eventData[0] || {};
977977
if(hovertemplate) {
978-
text = Lib.hovertemplateString(hovertemplate, hovertemplateLabels, eventData);
978+
text = Lib.hovertemplateString(
979+
hovertemplate,
980+
hovertemplateLabels,
981+
eventData,
982+
{meta: fullLayout.meta}
983+
);
979984

980985
text = text.replace(EXTRA_STRING_REGEX, function(match, extra) {
981986
name = extra; // Assign name for secondary text label

‎test/jasmine/tests/hover_label_test.js

+19
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,25 @@ describe('hover info', function() {
17331733
.catch(failTest)
17341734
.then(done);
17351735
});
1736+
1737+
it('should work with layout.meta references', function(done) {
1738+
var gd = document.getElementById('graph');
1739+
1740+
Plotly.update(gd,
1741+
{hovertemplate: 'TRACE -- %{meta[0]}<extra>%{meta[1]}</extra>'},
1742+
{meta: ['A', '$$$']}
1743+
).then(function() {
1744+
Fx.hover('graph', evt, 'xy');
1745+
1746+
assertHoverLabelContent({
1747+
nums: 'TRACE -- A',
1748+
name: '$$$',
1749+
axis: '0.388'
1750+
});
1751+
})
1752+
.catch(failTest)
1753+
.then(done);
1754+
});
17361755
});
17371756

17381757
it('should work with trace.name linked to layout.meta', function(done) {

0 commit comments

Comments
 (0)
Please sign in to comment.