-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Improve axis tick increment #4070
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
Changes from all commits
3623224
0a07168
4855033
740574b
916bf80
86b135d
ab2facf
76b0368
7f585ce
14f704b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,38 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* 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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(scale < 1) scale = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var newX = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
scale * x + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
scale * delta | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) / scale; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Note 2: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// now we may also consider rounding to cover few more edge cases | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// e.g. 0.3 * 3 = 0.8999999999999999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var lenDt = ('' + delta).length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var lenX0 = ('' + x).length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var lenX1 = ('' + newX).length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(lenX1 >= lenX0 + lenDt) { // likely a rounding error! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
newX = +parseFloat(newX).toPrecision(12); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return newX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding those tests @archmoj - I understand (a little bit) more what you're attempting. That said, I feel like we should be extending plotly.js/src/plots/cartesian/axes.js Lines 1311 to 1408 in 96fe262
where instead of exiting early plotly.js/src/plots/cartesian/axes.js Line 1338 in 96fe262
for when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What is the root cause in your mind here? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; |
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 | ||
] | ||
} | ||
} | ||
} |
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 | ||
] | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One may simply
return x + delta
here to find out various failing tests.