-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Adjust imaginary tickvals default to fix react #5992
Conversation
var imagTickvalsDflt = | ||
realTickvals.slice().reverse().map(function(x) { return -x; }) | ||
.concat([0]) | ||
.concat(realTickvals); |
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.
I imagine the problem with this is we get a new array each time, so Plotly.react
thinks this has changed and needs replotting? I do think as a default this behavior makes sense, can we fix it with a simple memoizer? Something like:
function memoize(fn, keyFn) {
var cache = {};
return function(val) {
var newKey = keyFn ? keyFn(val) : val;
if (newKey in cache) { return cache[newKey]; }
out = fn(val);
cache[newKey] = out;
return out;
}
}
var makeImagDflt = memoizeOne(function(realTickvals) {
return realTickvals.slice().reverse().map(function(x) { return -x; })
.concat([0])
.concat(realTickvals);
}, String);
var a = makeImagDflt([2,4,5])
var b = makeImagDflt([2,4,5])
a===b // true
var c = makeImagDflt([1,2,3])
var d = makeImagDflt([2,4,5])
d===b // true
A memoizer might be useful in other contexts too... we use them quite a lot in Dash anyway.
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.
It's a kind of magic!
Applied in 844e24c
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.
💃 🧙
The magical default for imaginary
tickvals
added in #5956 (comment) broke the react ("noCi"plotl_api_react_test
).@plotly/plotly_js