Skip to content

Commit f8264b4

Browse files
committed
fix #2420 - exponents in z hover values
1 parent 4bcde5f commit f8264b4

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/plots/cartesian/axes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ function numFormat(v, ax, fmtoverride, hover) {
15281528
if(hover) {
15291529
// make a dummy axis obj to get the auto rounding and exponent
15301530
var ah = {
1531-
exponentformat: ax.exponentformat,
1531+
exponentformat: exponentFormat,
15321532
dtick: ax.showexponent === 'none' ? ax.dtick :
15331533
(isNumeric(v) ? Math.abs(v) || 1 : 1),
15341534
// if not showing any exponents, don't change the exponent

test/jasmine/tests/hover_label_test.js

+40
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Plotly = require('@lib/index');
44
var Fx = require('@src/components/fx');
55
var Lib = require('@src/lib');
66
var HOVERMINTIME = require('@src/components/fx').constants.HOVERMINTIME;
7+
var MINUS_SIGN = require('@src/constants/numerical').MINUS_SIGN;
78

89
var createGraphDiv = require('../assets/create_graph_div');
910
var destroyGraphDiv = require('../assets/destroy_graph_div');
@@ -550,6 +551,45 @@ describe('hover info', function() {
550551
.then(done);
551552
});
552553

554+
it('provides exponents correctly for z data', function(done) {
555+
function expFmt(val, exp) {
556+
return val + '×10\u200b<tspan style="font-size:70%" dy="-0.6em">' +
557+
(exp < 0 ? MINUS_SIGN + -exp : exp) +
558+
'</tspan><tspan dy="0.42em">\u200b</tspan>';
559+
}
560+
Plotly.plot(gd, [{
561+
type: 'heatmap',
562+
y: [0, 1, 2, 3],
563+
z: [
564+
[-1.23456789e23, -1e10, -1e4],
565+
[-1e-2, -1e-8, 0],
566+
[1.23456789e-23, 1e-8, 1e-2],
567+
[123.456789, 1.23456789e10, 1e23]
568+
],
569+
showscale: false
570+
}], {
571+
width: 600,
572+
height: 400,
573+
margin: {l: 0, t: 0, r: 0, b: 0}
574+
})
575+
.then(function() {
576+
[
577+
[expFmt(MINUS_SIGN + '1.234568', 23), MINUS_SIGN + '10B', MINUS_SIGN + '10k'],
578+
[MINUS_SIGN + '0.01', MINUS_SIGN + '10n', '0'],
579+
[expFmt('1.234568', -23), '10n', '0.01'],
580+
['123.4568', '12.34568B', expFmt('1', 23)]
581+
]
582+
.forEach(function(row, y) {
583+
row.forEach(function(zVal, x) {
584+
_hover(gd, (x + 0.5) * 200, (3.5 - y) * 100);
585+
assertHoverLabelContent({nums: 'x: ' + x + '\ny: ' + y + '\nz: ' + zVal}, zVal);
586+
});
587+
});
588+
})
589+
.catch(fail)
590+
.then(done);
591+
});
592+
553593
it('should display correct label content with specified format - contour', function(done) {
554594
Plotly.plot(gd, [{
555595
type: 'contour',

0 commit comments

Comments
 (0)