-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Improve axis tick increment #5114
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1e479e6
display bug in image test
archmoj ed3f1c1
improve axis tick increment to reduce precision errors
archmoj 7e0ae99
update baseline - note d3 percent format have another bug showing cas…
archmoj eae05f2
avoid extra step for small scales and refactor to apply String for ca…
archmoj 789e7e3
avoid extra second step when not needed also optimize for performance
archmoj eba1cb4
update flaky list for image test
archmoj ebb63c8
avoid rounding big numbers in the second step
archmoj 671b578
rewrite logic using e+ check
archmoj 27f9774
add tests for not rounding big numbers in the second step
archmoj cb005b9
update flaky list
archmoj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright 2012-2020, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
module.exports = function incrementNumeric(x, delta) { | ||
if(!delta) return x; | ||
|
||
// Note 1: | ||
// 0.3 != 0.1 + 0.2 == 0.30000000000000004 | ||
// but 0.3 == (10 * 0.1 + 10 * 0.2) / 10 | ||
// Attempt to use integer steps to increment | ||
var scale = 1 / Math.abs(delta); | ||
var newX = (scale > 1) ? ( | ||
scale * x + | ||
scale * delta | ||
) / scale : x + delta; | ||
|
||
// Note 2: | ||
// now we may also consider rounding to cover few more edge cases | ||
// e.g. 0.3 * 3 = 0.8999999999999999 | ||
var lenX1 = String(newX).length; | ||
if(lenX1 > 16) { | ||
var lenDt = String(delta).length; | ||
var lenX0 = String(x).length; | ||
|
||
if(lenX1 >= lenX0 + lenDt) { // likely a rounding error! | ||
var s = parseFloat(newX).toPrecision(12); | ||
if(s.indexOf('e+') === -1) newX = +s; | ||
} | ||
} | ||
|
||
return newX; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"name": "s & positive", | ||
"x": [ | ||
"2019-12-31 23:59:59.998", | ||
"2020-01-01 00:00:00", | ||
"2020-01-01 00:00:00.002" | ||
], | ||
"y": [ | ||
"1e-1", | ||
"1e-2", | ||
"1e-0" | ||
], | ||
"type": "scatter" | ||
}, | ||
{ | ||
"name": "s & negative", | ||
"xaxis": "x2", | ||
"yaxis": "y2", | ||
"x": [ | ||
"2019-12-31 23:59:59.998", | ||
"2020-01-01 00:00:00", | ||
"2020-01-01 00:00:00.002" | ||
], | ||
"y": [ | ||
"-1e-1", | ||
"-1e-2", | ||
"-1e-0" | ||
], | ||
"type": "scatter" | ||
}, | ||
{ | ||
"name": "p & negative", | ||
"xaxis": "x3", | ||
"yaxis": "y3", | ||
"x": [ | ||
"2019-12-31 23:59:59.998", | ||
"2020-01-01 00:00:00", | ||
"2020-01-01 00:00:00.002" | ||
], | ||
"y": [ | ||
"-1e-1", | ||
"-1e-2", | ||
"-1e-0" | ||
], | ||
"type": "scatter" | ||
}, | ||
{ | ||
"name": "p & positive", | ||
"xaxis": "x4", | ||
"yaxis": "y4", | ||
"x": [ | ||
"2019-12-31 23:59:59.998", | ||
"2020-01-01 00:00:00", | ||
"2020-01-01 00:00:00.002" | ||
], | ||
"y": [ | ||
"1e-1", | ||
"1e-2", | ||
"1e-0" | ||
], | ||
"type": "scatter" | ||
} | ||
], | ||
"layout": { | ||
"width": 800, | ||
"height": 800, | ||
"xaxis": { | ||
"type": "date", | ||
"domain": [ | ||
0, | ||
0.45 | ||
] | ||
}, | ||
"xaxis2": { | ||
"type": "date", | ||
"anchor": "y2", | ||
"domain": [ | ||
0.6, | ||
1 | ||
] | ||
}, | ||
"xaxis3": { | ||
"type": "date", | ||
"anchor": "y3", | ||
"domain": [ | ||
0, | ||
0.45 | ||
] | ||
}, | ||
"xaxis4": { | ||
"type": "date", | ||
"anchor": "y4", | ||
"domain": [ | ||
0.6, | ||
1 | ||
] | ||
}, | ||
"yaxis": { | ||
"nticks": 10, | ||
"tickformat": "s", | ||
"domain": [ | ||
0, | ||
0.45 | ||
] | ||
}, | ||
"yaxis2": { | ||
"nticks": 10, | ||
"tickformat": "s", | ||
"anchor": "x2", | ||
"domain": [ | ||
0, | ||
0.45 | ||
] | ||
}, | ||
"yaxis3": { | ||
"nticks": 10, | ||
"tickformat": "p", | ||
"anchor": "x3", | ||
"domain": [ | ||
0.6, | ||
1 | ||
] | ||
}, | ||
"yaxis4": { | ||
"nticks": 10, | ||
"tickformat": "p", | ||
"anchor": "x4", | ||
"domain": [ | ||
0.6, | ||
1 | ||
] | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"type": "scatter", | ||
"y": [ | ||
1, | ||
0, | ||
0.5 | ||
] | ||
}, | ||
{ | ||
"xaxis": "x2", | ||
"yaxis": "y2", | ||
"type": "scatter", | ||
"y": [ | ||
1, | ||
0, | ||
0.5 | ||
] | ||
}, | ||
{ | ||
"xaxis": "x3", | ||
"yaxis": "y3", | ||
"type": "scatter", | ||
"y": [ | ||
1, | ||
0, | ||
0.5 | ||
] | ||
}, | ||
{ | ||
"xaxis": "x4", | ||
"yaxis": "y4", | ||
"type": "scatter", | ||
"y": [ | ||
1, | ||
0, | ||
0.5 | ||
] | ||
} | ||
], | ||
"layout": { | ||
"width": 800, | ||
"height": 800, | ||
"xaxis": { | ||
"domain": [ | ||
0, | ||
0.48 | ||
] | ||
}, | ||
"xaxis2": { | ||
"anchor": "y2", | ||
"domain": [ | ||
0.52, | ||
1 | ||
] | ||
}, | ||
"xaxis3": { | ||
"anchor": "y3", | ||
"domain": [ | ||
0, | ||
0.48 | ||
] | ||
}, | ||
"xaxis4": { | ||
"autorange": "reversed", | ||
"anchor": "y4", | ||
"domain": [ | ||
0.52, | ||
1 | ||
] | ||
}, | ||
"yaxis": { | ||
"tickformat": "p", | ||
"domain": [ | ||
0, | ||
0.48 | ||
] | ||
}, | ||
"yaxis2": { | ||
"tickformat": "p", | ||
"dtick": 0.1, | ||
"anchor": "x2", | ||
"domain": [ | ||
0.52, | ||
1 | ||
] | ||
}, | ||
"yaxis3": { | ||
"tickformat": "p", | ||
"dtick": 0.3, | ||
"anchor": "x3", | ||
"domain": [ | ||
0.52, | ||
1 | ||
] | ||
}, | ||
"yaxis4": { | ||
"tickformat": "p", | ||
"dtick": 0.05, | ||
"anchor": "x4", | ||
"domain": [ | ||
0, | ||
0.48 | ||
] | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.