diff --git a/draftlogs/5956_add.md b/draftlogs/5956_add.md index c790a7cb13f..7382acb7659 100644 --- a/draftlogs/5956_add.md +++ b/draftlogs/5956_add.md @@ -1,2 +1,2 @@ - - Add `smith` subplots and the `scattersmith` trace type for displaying Smith charts [[#5956](https://github.com/plotly/plotly.js/pull/5956)], + - Add `smith` subplots and the `scattersmith` trace type for displaying Smith charts [[#5956](https://github.com/plotly/plotly.js/pull/5956), [#5992](https://github.com/plotly/plotly.js/pull/5992)], with thanks to Kitware and @waxlamp for kicking off this effort. diff --git a/src/plots/smith/layout_defaults.js b/src/plots/smith/layout_defaults.js index fc332959a41..1a36a46dd59 100644 --- a/src/plots/smith/layout_defaults.js +++ b/src/plots/smith/layout_defaults.js @@ -16,6 +16,12 @@ var layoutAttributes = require('./layout_attributes'); var constants = require('./constants'); var axisNames = constants.axisNames; +var makeImagDflt = memoize(function(realTickvals) { + return realTickvals.slice().reverse().map(function(x) { return -x; }) + .concat([0]) + .concat(realTickvals); +}, String); + function handleDefaults(contIn, contOut, coerce, opts) { var bgColor = coerce('bgcolor'); opts.bgColor = Color.combine(bgColor, opts.paper_bgcolor); @@ -55,11 +61,10 @@ function handleDefaults(contIn, contOut, coerce, opts) { if(isRealAxis) { coerceAxis('tickvals'); } else { - var realTickvals = contOut.realaxis.tickvals || layoutAttributes.realaxis.tickvals.dflt; - var imagTickvalsDflt = - realTickvals.slice().reverse().map(function(x) { return -x; }) - .concat([0]) - .concat(realTickvals); + var imagTickvalsDflt = makeImagDflt( + contOut.realaxis.tickvals || + layoutAttributes.realaxis.tickvals.dflt + ); coerceAxis('tickvals', imagTickvalsDflt); } @@ -132,3 +137,15 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) { layoutOut: layoutOut }); }; + +function memoize(fn, keyFn) { + var cache = {}; + return function(val) { + var newKey = keyFn ? keyFn(val) : val; + if(newKey in cache) { return cache[newKey]; } + + var out = fn(val); + cache[newKey] = out; + return out; + }; +}