Skip to content

Commit d38232d

Browse files
authored
Merge pull request #5992 from plotly/fixup-smith-react-test
Adjust imaginary tickvals default to fix react
2 parents 96ec99e + 844e24c commit d38232d

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

draftlogs/5956_add.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
- Add `smith` subplots and the `scattersmith` trace type for displaying Smith charts [[#5956](https://github.com/plotly/plotly.js/pull/5956)],
1+
- 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)],
22
with thanks to Kitware and @waxlamp for kicking off this effort.

src/plots/smith/layout_defaults.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ var layoutAttributes = require('./layout_attributes');
1616
var constants = require('./constants');
1717
var axisNames = constants.axisNames;
1818

19+
var makeImagDflt = memoize(function(realTickvals) {
20+
return realTickvals.slice().reverse().map(function(x) { return -x; })
21+
.concat([0])
22+
.concat(realTickvals);
23+
}, String);
24+
1925
function handleDefaults(contIn, contOut, coerce, opts) {
2026
var bgColor = coerce('bgcolor');
2127
opts.bgColor = Color.combine(bgColor, opts.paper_bgcolor);
@@ -55,11 +61,10 @@ function handleDefaults(contIn, contOut, coerce, opts) {
5561
if(isRealAxis) {
5662
coerceAxis('tickvals');
5763
} else {
58-
var realTickvals = contOut.realaxis.tickvals || layoutAttributes.realaxis.tickvals.dflt;
59-
var imagTickvalsDflt =
60-
realTickvals.slice().reverse().map(function(x) { return -x; })
61-
.concat([0])
62-
.concat(realTickvals);
64+
var imagTickvalsDflt = makeImagDflt(
65+
contOut.realaxis.tickvals ||
66+
layoutAttributes.realaxis.tickvals.dflt
67+
);
6368

6469
coerceAxis('tickvals', imagTickvalsDflt);
6570
}
@@ -132,3 +137,15 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
132137
layoutOut: layoutOut
133138
});
134139
};
140+
141+
function memoize(fn, keyFn) {
142+
var cache = {};
143+
return function(val) {
144+
var newKey = keyFn ? keyFn(val) : val;
145+
if(newKey in cache) { return cache[newKey]; }
146+
147+
var out = fn(val);
148+
cache[newKey] = out;
149+
return out;
150+
};
151+
}

0 commit comments

Comments
 (0)