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 c1b2674

Browse filesBrowse files
committed
Fix hover label exponents
1 parent e78ed04 commit c1b2674
Copy full SHA for c1b2674

File tree

Expand file treeCollapse file tree

2 files changed

+34
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+34
-5
lines changed

‎src/plots/cartesian/axes.js

Copy file name to clipboardExpand all lines: src/plots/cartesian/axes.js
+17-5Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,11 @@ axes.tickText = function(ax, x, hover) {
12061206
return showAttr !== 'all' && x !== first_or_last;
12071207
}
12081208

1209-
hideexp = ax.exponentformat !== 'none' && isHidden(ax.showexponent) ? 'hide' : '';
1209+
if (hover) {
1210+
hideexp = 'never'
1211+
} else {
1212+
hideexp = ax.exponentformat !== 'none' && isHidden(ax.showexponent) ? 'hide' : '';
1213+
}
12101214

12111215
if(ax.type === 'date') formatDate(ax, out, hover, extraPrecision);
12121216
else if(ax.type === 'log') formatLog(ax, out, hover, extraPrecision, hideexp);
@@ -1344,10 +1348,18 @@ function formatCategory(ax, out) {
13441348
}
13451349

13461350
function formatLinear(ax, out, hover, extraPrecision, hideexp) {
1347-
// don't add an exponent to zero if we're showing all exponents
1348-
// so the only reason you'd show an exponent on zero is if it's the
1349-
// ONLY tick to get an exponent (first or last)
1350-
if(ax.showexponent === 'all' && Math.abs(out.x / ax.dtick) < 1e-6) {
1351+
if (hideexp === 'never') {
1352+
// If this is a hover label, then we must *never* hide the exponent
1353+
// for the sake of display, which could give the wrong value by
1354+
// potentially many orders of magnitude. If hideexp was 'never', then
1355+
// it's now succeeded by preventing the other condition from automating
1356+
// this choice. Thus we can unset it so that the axis formatting takes
1357+
// precedence.
1358+
hideexp = ''
1359+
} else if(ax.showexponent === 'all' && Math.abs(out.x / ax.dtick) < 1e-6) {
1360+
// don't add an exponent to zero if we're showing all exponents
1361+
// so the only reason you'd show an exponent on zero is if it's the
1362+
// ONLY tick to get an exponent (first or last)
13511363
hideexp = 'hide';
13521364
}
13531365
out.text = numFormat(out.x, ax, hideexp, extraPrecision);

‎test/jasmine/tests/axes_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/axes_test.js
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,23 @@ describe('Test axes', function() {
22572257

22582258
expect(mockCalc(ax).length).toBe(10001);
22592259
});
2260+
2261+
it('never hides the exponent when in hover mode', function() {
2262+
var ax = {
2263+
type: 'linear',
2264+
tickmode: 'linear',
2265+
tick0: 0,
2266+
dtick: 2e20,
2267+
range: [0, 1.0732484076433121e21],
2268+
_length: 270
2269+
};
2270+
2271+
mockCalc(ax);
2272+
2273+
expect(mockHoverText(ax, 1e-21)).toBe('1e\u221221');
2274+
expect(mockHoverText(ax, 1)).toBe('1');
2275+
expect(mockHoverText(ax, 1e21)).toBe('1e+21');
2276+
});
22602277
});
22612278

22622279
describe('autoBin', function() {

0 commit comments

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