Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1525a0d

Browse filesBrowse files
committed
image: build hovertemplate based on hoverinfo in hover.js
1 parent d18225d commit 1525a0d
Copy full SHA for 1525a0d

File tree

5 files changed

+34
-30
lines changed
Filter options

5 files changed

+34
-30
lines changed

‎src/components/fx/hover.js

Copy file name to clipboardExpand all lines: src/components/fx/hover.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
630630
if(pt.cd[pt.index] && pt.cd[pt.index].ht) {
631631
ht = pt.cd[pt.index].ht;
632632
}
633-
pt.hovertemplate = ht || pt.trace.hovertemplate || false;
633+
pt.hovertemplate = ht || pt.trace.hovertemplate || pt.hovertemplate;
634634
}
635635

636636
pt.eventData = [eventData];

‎src/traces/image/attributes.js

Copy file name to clipboardExpand all lines: src/traces/image/attributes.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ module.exports = extendFlat({
7676
description: 'Set the pixel\'s vertical size'
7777
},
7878
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
79-
flags: ['x', 'y', 'z', 'color'],
80-
dflt: 'all'
79+
flags: ['x', 'y', 'z', 'color', 'name']
8180
}),
8281
hovertemplate: hovertemplateAttrs({})
8382
});

‎src/traces/image/defaults.js

Copy file name to clipboardExpand all lines: src/traces/image/defaults.js
+1-23Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,6 @@ module.exports = function supplyDefaults(traceIn, traceOut) {
3131

3232
coerce('zmin', constants.colormodel[colormodel].min);
3333
coerce('zmax', constants.colormodel[colormodel].max);
34-
var dims = traceOut.colormodel.length;
3534

36-
var ht = coerce('hovertemplate');
37-
if(!ht) {
38-
var hoverinfo = coerce('hoverinfo');
39-
var parts = hoverinfo.split('+');
40-
41-
if(parts.indexOf('all') !== -1) parts = attributes.hoverinfo.flags;
42-
ht = [];
43-
if(parts.indexOf('x') !== -1) ht.push('x: %{x}');
44-
if(parts.indexOf('y') !== -1) ht.push('y: %{y}');
45-
if(parts.indexOf('z') !== -1) ht.push('z: [%{z[0]}, %{z[1]}, %{z[2]}' + (dims === 4 ? ', %{z[3]}' : '') + ']');
46-
if(parts.indexOf('color') !== -1) {
47-
var colorstring = [];
48-
colorstring.push('<span style="text-transform:uppercase">%{colormodel}</span>: ');
49-
if(colormodel === 'hsl' || colormodel === 'hsla') {
50-
colorstring.push('[%{c[0]}°, %{c[1]}%, %{c[2]}%' + (dims === 4 ? ', %{c[3]}' : '') + ']');
51-
} else {
52-
colorstring.push('[%{c[0]}, %{c[1]}, %{c[2]}' + (dims === 4 ? ', %{c[3]}' : '') + ']');
53-
}
54-
ht.push(colorstring.join(''));
55-
}
56-
traceOut.hovertemplate = ht.join('<br>');
57-
}
35+
coerce('hovertemplate');
5836
};

‎src/traces/image/hover.js

Copy file name to clipboardExpand all lines: src/traces/image/hover.js
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
var Fx = require('../../components/fx');
1212
var Lib = require('../../lib');
13+
var attributes = require('./attributes');
1314
// var Axes = require('../../plots/cartesian/axes');
1415

1516
module.exports = function hoverPoints(pointData, xval, yval) {
@@ -18,10 +19,35 @@ module.exports = function hoverPoints(pointData, xval, yval) {
1819
var xa = pointData.xa;
1920
var ya = pointData.ya;
2021

22+
// Return early if not on image
2123
if(Fx.inbox(xval - cd0.x0, xval - (cd0.x0 + cd0.w * trace.dx), 0) > 0 ||
2224
Fx.inbox(yval - cd0.y0, yval - (cd0.y0 + cd0.h * trace.dy), 0) > 0) {
2325
return;
2426
}
27+
var ht;
28+
if(!trace.hovertemplate) {
29+
var colormodel = trace.colormodel;
30+
var dims = colormodel.length;
31+
var hoverinfo = cd0.hi || trace.hoverinfo;
32+
var parts = hoverinfo.split('+');
33+
34+
ht = [];
35+
if(parts.indexOf('all') !== -1) parts = attributes.hoverinfo.flags;
36+
if(parts.indexOf('x') !== -1) ht.push('x: %{x}');
37+
if(parts.indexOf('y') !== -1) ht.push('y: %{y}');
38+
if(parts.indexOf('z') !== -1) ht.push('z: [%{z[0]}, %{z[1]}, %{z[2]}' + (dims === 4 ? ', %{z[3]}' : '') + ']');
39+
if(parts.indexOf('color') !== -1) {
40+
var colorstring = [];
41+
colorstring.push('<span style="text-transform:uppercase">%{colormodel}</span>: ');
42+
if(colormodel === 'hsl' || colormodel === 'hsla') {
43+
colorstring.push('[%{c[0]}°, %{c[1]}%, %{c[2]}%' + (dims === 4 ? ', %{c[3]}' : '') + ']');
44+
} else {
45+
colorstring.push('[%{c[0]}, %{c[1]}, %{c[2]}' + (dims === 4 ? ', %{c[3]}' : '') + ']');
46+
}
47+
ht.push(colorstring.join(''));
48+
}
49+
ht = ht.join('<br>');
50+
}
2551

2652
// Find nearest pixel's index and pixel center
2753
var nx = Math.floor((xval - cd0.x0) / trace.dx);
@@ -34,5 +60,6 @@ module.exports = function hoverPoints(pointData, xval, yval) {
3460
x1: xa.c2p(cd0.x0 + (nx + 1) * trace.dx),
3561
y0: py,
3662
y1: py,
63+
hovertemplate: ht
3764
})];
3865
};

‎test/jasmine/tests/image_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/image_test.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ describe('image hover:', function() {
299299
.then(function() {
300300
assertHoverLabelContent({
301301
nums: 'x: 25.5\ny: 14.5\nz: [54, 136, 153]\n<tspan style="text-transform:uppercase">rgb</tspan>: [54, 136, 153]',
302-
name: 'trace 0'
302+
name: ''
303303
});
304304
})
305305
.catch(failTest)
@@ -313,7 +313,7 @@ describe('image hover:', function() {
313313
.then(function() {
314314
assertHoverLabelContent({
315315
nums: 'x: 31.5\ny: 35.5\nz: [128, 77, 54, 254]\n<tspan style="text-transform:uppercase">rgba</tspan>: [128, 77, 54, 1]',
316-
name: 'trace 0'
316+
name: ''
317317
});
318318
})
319319
.catch(failTest)
@@ -328,7 +328,7 @@ describe('image hover:', function() {
328328
.then(function() {
329329
assertHoverLabelContent({
330330
nums: 'x: 31.5\ny: 35.5\nz: [128, 77, 54]\n<tspan style="text-transform:uppercase">hsl</tspan>: [128°, 77%, 54%]',
331-
name: 'trace 0'
331+
name: ''
332332
});
333333
})
334334
.catch(failTest)
@@ -343,7 +343,7 @@ describe('image hover:', function() {
343343
.then(function() {
344344
assertHoverLabelContent({
345345
nums: 'x: 31.5\ny: 35.5\nz: [128, 77, 54, 254]\n<tspan style="text-transform:uppercase">hsla</tspan>: [128°, 77%, 54%, 1]',
346-
name: 'trace 0'
346+
name: ''
347347
});
348348
})
349349
.catch(failTest)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.