Skip to content

Commit 4d70fd3

Browse files
committed
Refactor coercion logic
1 parent a910d42 commit 4d70fd3

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

src/components/shapes/defaults.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
6565
var ySizeMode = coerce('ysizemode');
6666

6767
// positioning
68-
var axLetters = ['x', 'y'];
69-
axLetters.forEach(function(axLetter) {
68+
['x', 'y'].forEach(axLetter => {
7069
var attrAnchor = axLetter + 'anchor';
7170
var sizeMode = axLetter === 'x' ? xSizeMode : ySizeMode;
7271
var gdMock = {_fullLayout: fullLayout};

src/components/shapes/helpers.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@ exports.countDefiningCoords = function(shapeType, path) {
6161
var segments = path.match(constants.segmentRE);
6262
if(!segments) return 0;
6363

64-
var coordCount = 0;
65-
segments.forEach(function(segment) {
64+
return segments.reduce((coordCount, segment) => {
6665
// for each path command, check if there is a drawn coordinate
6766
var segmentType = segment.charAt(0);
6867
var hasDrawnX = constants.paramIsX[segmentType].drawn !== undefined;
6968
var hasDrawnY = constants.paramIsY[segmentType].drawn !== undefined;
70-
if(hasDrawnX || hasDrawnY) coordCount++;
71-
});
72-
return coordCount;
69+
return coordCount + (hasDrawnX || hasDrawnY ? 1 : 0);
70+
}, 0);
7371
};
7472

7573
exports.getDataToPixel = function(gd, axis, shift, isVertical, refType) {

src/plots/cartesian/axes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ function expandRange(range) {
9898
* but can be prefixed, like 'ax' for annotation's arrow x
9999
* dflt: the default to coerce to, or blank to use the first axis (falling back on
100100
* extraOption if there is no axis)
101-
* extraOption: aside from existing axes with this letter, what non-axis value is allowed?
102-
* Only required if it's different from `dflt`
101+
* extraOption: fallback value, only required if it's different from `dflt`
103102
*/
104103
axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption) {
105104
var axLetter = attr.charAt(attr.length - 1);
@@ -143,7 +142,7 @@ axes.coerceRefArray = function(containerIn, containerOut, gd, attr, dflt, extraO
143142

144143
// Build the axis list, which we use to validate the axis references
145144
if(!dflt) dflt = axlist[0] || (typeof extraOption === 'string' ? extraOption : extraOption[0]);
146-
axlist = axlist.concat(axlist.map(function(x) { return x + ' domain'; }));
145+
axlist = axlist.concat(axlist.map(x => x + ' domain'));
147146
axlist = axlist.concat(extraOption ? extraOption : []);
148147

149148
// Handle array length mismatch
@@ -178,6 +177,7 @@ axes.coerceRefArray = function(containerIn, containerOut, gd, attr, dflt, extraO
178177
*/
179178
axes.getRefType = function(ar) {
180179
if(ar === undefined) { return ar; }
180+
if(Array.isArray(ar)) { return 'array'; }
181181
if(ar === 'paper') { return 'paper'; }
182182
if(ar === 'pixel') { return 'pixel'; }
183183
if(/( domain)$/.test(ar)) { return 'domain'; } else { return 'range'; }

0 commit comments

Comments
 (0)