Skip to content

add 'tickformatstops' #1965

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 17 commits into from
Oct 16, 2017
Merged
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
30 changes: 8 additions & 22 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1539,40 +1539,26 @@ axes.getTickFormat = function(ax) {
if(ax.tickformatstops && ax.tickformatstops.length > 0) {
switch(ax.type) {
case 'date': {
tickstop = ax.tickformatstops.reduce(function(acc, stop) {
if(!isProperStop(ax.dtick, stop.dtickrange, convertToMs)) {
return acc;
}
if(!acc) {
return stop;
} else {
return getRangeWidth(stop.dtickrange, convertToMs) > getRangeWidth(acc.dtickrange, convertToMs) ? stop : acc;
}
}, null);
tickstop = ax.tickformatstops.find(function(stop) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice and clean - unfortunately it doesn't look like IE supports Array.find, not even in IE11
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
We've also tended to gravitate toward for loops over Array methods for performance reasons. Not a big deal here as this array will be fairly small, but it should still help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, just switched from the project where is supported and don't care about IE11 support.
Replaced with for loop and fixed tests.

return isProperStop(ax.dtick, stop.dtickrange, convertToMs)
});
break;
}
case 'linear': {
tickstop = ax.tickformatstops.reduce(function(acc, stop) {
if(!isProperStop(ax.dtick, stop.dtickrange)) {
return acc;
}
if(!acc) {
return stop;
} else {
return getRangeWidth(stop.dtickrange) > getRangeWidth(acc.dtickrange) ? stop : acc;
}
}, null);
tickstop = ax.tickformatstops.find(function(stop) {
return isProperStop(ax.dtick, stop.dtickrange, convertToMs)
});
break;
}
case 'log': {
tickstop = ax.tickformatstops.filter(function(stop) {
tickstop = ax.tickformatstops.find(function(stop) {
var left = stop.dtickrange[0], right = stop.dtickrange[1];
var isLeftDtickNull = left === null;
var isRightDtickNull = right === null;
var isDtickInRangeLeft = compareLogTicks(ax.dtick, left) >= 0;
var isDtickInRangeRight = compareLogTicks(ax.dtick, right) <= 0;
return (isLeftDtickNull || isDtickInRangeLeft) && (isRightDtickNull || isDtickInRangeRight);
})[0];
});
break;
}
default:
Expand Down