Skip to content

Z exponent fix #2422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ function numFormat(v, ax, fmtoverride, hover) {
if(hover) {
// make a dummy axis obj to get the auto rounding and exponent
var ah = {
exponentformat: ax.exponentformat,
exponentformat: exponentFormat,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch 🎣

dtick: ax.showexponent === 'none' ? ax.dtick :
(isNumeric(v) ? Math.abs(v) || 1 : 1),
// if not showing any exponents, don't change the exponent
Expand Down
40 changes: 40 additions & 0 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Plotly = require('@lib/index');
var Fx = require('@src/components/fx');
var Lib = require('@src/lib');
var HOVERMINTIME = require('@src/components/fx').constants.HOVERMINTIME;
var MINUS_SIGN = require('@src/constants/numerical').MINUS_SIGN;

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
Expand Down Expand Up @@ -550,6 +551,45 @@ describe('hover info', function() {
.then(done);
});

it('provides exponents correctly for z data', function(done) {
function expFmt(val, exp) {
return val + '×10\u200b<tspan style="font-size:70%" dy="-0.6em">' +
(exp < 0 ? MINUS_SIGN + -exp : exp) +
'</tspan><tspan dy="0.42em">\u200b</tspan>';
}
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1, 2, 3],
z: [
[-1.23456789e23, -1e10, -1e4],
[-1e-2, -1e-8, 0],
[1.23456789e-23, 1e-8, 1e-2],
[123.456789, 1.23456789e10, 1e23]
],
showscale: false
}], {
width: 600,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
[
[expFmt(MINUS_SIGN + '1.234568', 23), MINUS_SIGN + '10B', MINUS_SIGN + '10k'],
[MINUS_SIGN + '0.01', MINUS_SIGN + '10n', '0'],
[expFmt('1.234568', -23), '10n', '0.01'],
['123.4568', '12.34568B', expFmt('1', 23)]
]
.forEach(function(row, y) {
row.forEach(function(zVal, x) {
Copy link
Contributor

@etpinard etpinard Feb 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ test! Why create 12 test cases when we can loop over 12 bricks!

_hover(gd, (x + 0.5) * 200, (3.5 - y) * 100);
assertHoverLabelContent({nums: 'x: ' + x + '\ny: ' + y + '\nz: ' + zVal}, zVal);
});
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - contour', function(done) {
Plotly.plot(gd, [{
type: 'contour',
Expand Down