Skip to content

Commit 1736f46

Browse files
committed
Convert var to const where applicable
1 parent a78674a commit 1736f46

File tree

6 files changed

+79
-79
lines changed

6 files changed

+79
-79
lines changed

src/components/shapes/calc_autorange.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ module.exports = function calcAutorange(gd) {
6161
* @returns {object} - mapping of axis IDs to arrays of converted coordinate values
6262
*/
6363
function calcArrayRefAutorange(gd, shape, axLetter) {
64-
var refs = shape[axLetter + 'ref'];
65-
var paramsToUse = axLetter === 'x' ? constants.paramIsX : constants.paramIsY;
64+
const refs = shape[axLetter + 'ref'];
65+
const paramsToUse = axLetter === 'x' ? constants.paramIsX : constants.paramIsY;
6666

6767
function addToAxisGroup(ref, val) {
6868
if(ref === 'paper' || Axes.getRefType(ref) === 'domain') return;
@@ -71,18 +71,18 @@ function calcArrayRefAutorange(gd, shape, axLetter) {
7171
}
7272

7373
// group coordinates by axis reference so we can calculate the extremes for each axis
74-
var axisGroups = {};
74+
const axisGroups = {};
7575
if(shape.type === 'path' && shape.path) {
76-
var segments = shape.path.match(constants.segmentRE) || [];
76+
const segments = shape.path.match(constants.segmentRE) || [];
7777
var refIndex = 0;
7878
for(var i = 0; i < segments.length; i++) {
79-
var segment = segments[i];
80-
var command = segment.charAt(0);
81-
var drawnIndex = paramsToUse[command].drawn;
79+
const segment = segments[i];
80+
const command = segment.charAt(0);
81+
const drawnIndex = paramsToUse[command].drawn;
8282

8383
if(drawnIndex === undefined) continue;
8484

85-
var params = segment.slice(1).match(constants.paramRE);
85+
const params = segment.slice(1).match(constants.paramRE);
8686
if(params && params.length > drawnIndex) {
8787
addToAxisGroup(refs[refIndex], params[drawnIndex]);
8888
refIndex++;
@@ -94,9 +94,9 @@ function calcArrayRefAutorange(gd, shape, axLetter) {
9494
}
9595

9696
// Convert coordinates to data values
97-
var convertedGroups = {};
98-
for(var axId in axisGroups) {
99-
var ax = Axes.getFromId(gd, axId);
97+
const convertedGroups = {};
98+
for(const axId in axisGroups) {
99+
const ax = Axes.getFromId(gd, axId);
100100
if(!ax) continue;
101101
var convertVal = (ax.type === 'category' || ax.type === 'multicategory') ? ax.r2c : ax.d2c;
102102
if(ax.type === 'date') convertVal = helpers.decodeDate(convertVal);

src/components/shapes/defaults.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
6868
var ySizeMode = coerce('ysizemode');
6969

7070
// positioning
71-
var dflts = [0.25, 0.75];
72-
var pixelDflts = [0, 10];
71+
const dflts = [0.25, 0.75];
72+
const pixelDflts = [0, 10];
7373

7474
['x', 'y'].forEach(axLetter => {
7575
var attrAnchor = axLetter + 'anchor';
@@ -81,12 +81,12 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
8181

8282
// xref, yref - handle both string and array values
8383
var axRef;
84-
var refAttr = axLetter + 'ref';
85-
var inputRef = shapeIn[refAttr];
84+
const refAttr = axLetter + 'ref';
85+
const inputRef = shapeIn[refAttr];
8686

8787
if(Array.isArray(inputRef) && inputRef.length > 0) {
8888
// Array case: use coerceRefArray for validation
89-
var expectedLen = helpers.countDefiningCoords(shapeType, path, axLetter);
89+
const expectedLen = helpers.countDefiningCoords(shapeType, path, axLetter);
9090
axRef = Axes.coerceRefArray(shapeIn, shapeOut, gdMock, axLetter, undefined, 'paper', expectedLen);
9191
shapeOut['_' + axLetter + 'refArray'] = true;
9292
} else {
@@ -107,8 +107,8 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
107107

108108
if(noPath) {
109109
[0, 1].forEach(function(i) {
110-
var ref = axRef[i];
111-
var refType = Axes.getRefType(ref);
110+
const ref = axRef[i];
111+
const refType = Axes.getRefType(ref);
112112
if(refType === 'range') {
113113
ax = Axes.getFromId(gdMock, ref);
114114
pos2r = helpers.shapePositionToRange(ax);
@@ -120,8 +120,8 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
120120
pos2r = r2pos = Lib.identity;
121121
}
122122

123-
var attr = axLetter + i;
124-
var inValue = shapeIn[attr];
123+
const attr = axLetter + i;
124+
const inValue = shapeIn[attr];
125125
shapeIn[attr] = pos2r(shapeIn[attr], true);
126126

127127
if(sizeMode === 'pixel') {
@@ -134,7 +134,7 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
134134
shapeIn[attr] = inValue;
135135

136136
if(i === 0 && sizeMode === 'pixel') {
137-
var inAnchor = shapeIn[attrAnchor];
137+
const inAnchor = shapeIn[attrAnchor];
138138
shapeIn[attrAnchor] = pos2r(shapeIn[attrAnchor], true);
139139
Axes.coercePosition(shapeOut, gdMock, coerce, ref, attrAnchor, 0.25);
140140
shapeOut[attrAnchor] = r2pos(shapeOut[attrAnchor]);
@@ -143,7 +143,7 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
143143
});
144144
}
145145
} else {
146-
var axRefType = Axes.getRefType(axRef);
146+
const axRefType = Axes.getRefType(axRef);
147147

148148
if(axRefType === 'range') {
149149
ax = Axes.getFromId(gdMock, axRef);
@@ -164,10 +164,10 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
164164
// ranges to send to coerce, then put it back after
165165
// this is all to give reasonable default position behavior on log axes, which is
166166
// a pretty unimportant edge case so we could just ignore this.
167-
var attr0 = axLetter + '0';
168-
var attr1 = axLetter + '1';
169-
var in0 = shapeIn[attr0];
170-
var in1 = shapeIn[attr1];
167+
const attr0 = axLetter + '0';
168+
const attr1 = axLetter + '1';
169+
const in0 = shapeIn[attr0];
170+
const in1 = shapeIn[attr1];
171171
shapeIn[attr0] = pos2r(shapeIn[attr0], true);
172172
shapeIn[attr1] = pos2r(shapeIn[attr1], true);
173173

@@ -189,7 +189,7 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
189189
// Coerce xanchor and yanchor
190190
if(sizeMode === 'pixel') {
191191
// Hack for log axis described above
192-
var inAnchor = shapeIn[attrAnchor];
192+
const inAnchor = shapeIn[attrAnchor];
193193
shapeIn[attrAnchor] = pos2r(shapeIn[attrAnchor], true);
194194

195195
Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attrAnchor, 0.25);

src/components/shapes/display_labels.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ module.exports = function drawLabel(gd, index, options, shapeGroup) {
2727
if (options.type !== 'path') {
2828
var _xa = Axes.getFromId(gd, options.xref);
2929
var _ya = Axes.getFromId(gd, options.yref);
30-
var isMultiAxisX = Array.isArray(options.xref);
31-
var isMultiAxisY = Array.isArray(options.yref);
30+
const isMultiAxisX = Array.isArray(options.xref);
31+
const isMultiAxisY = Array.isArray(options.yref);
3232

3333
// For multi-axis shapes, derived variables are meaningless
3434
// Skip them and let texttemplatefallback handle those cases.
35-
var derivedX = ['dx', 'width', 'xcenter', 'slope', 'length'];
36-
var derivedY = ['dy', 'height', 'ycenter', 'slope', 'length'];
35+
const derivedX = ['dx', 'width', 'xcenter', 'slope', 'length'];
36+
const derivedY = ['dy', 'height', 'ycenter', 'slope', 'length'];
3737

3838
for (var key in shapeLabelTexttemplateVars) {
3939
if (isMultiAxisX && derivedX.includes(key)) continue;
@@ -94,20 +94,20 @@ module.exports = function drawLabel(gd, index, options, shapeGroup) {
9494
// Otherwise, we use the x and y bounds defined in the shape options
9595
// and convert them to pixel coordinates
9696
// Setup conversion functions, handling array refs for multi-axis shapes
97-
var isArrayXref = Array.isArray(options.xref);
98-
var isArrayYref = Array.isArray(options.yref);
99-
var xa0 = Axes.getFromId(gd, isArrayXref ? options.xref[0] : options.xref);
100-
var xa1 = Axes.getFromId(gd, isArrayXref ? options.xref[1] : options.xref);
101-
var ya0 = Axes.getFromId(gd, isArrayYref ? options.yref[0] : options.yref);
102-
var ya1 = Axes.getFromId(gd, isArrayYref ? options.yref[1] : options.yref);
103-
var xRefType0 = Axes.getRefType(isArrayXref ? options.xref[0] : options.xref);
104-
var xRefType1 = Axes.getRefType(isArrayXref ? options.xref[1] : options.xref);
105-
var yRefType0 = Axes.getRefType(isArrayYref ? options.yref[0] : options.yref);
106-
var yRefType1 = Axes.getRefType(isArrayYref ? options.yref[1] : options.yref);
107-
var x2p = function(v, shift, xa, xRefType) {
97+
const isArrayXref = Array.isArray(options.xref);
98+
const isArrayYref = Array.isArray(options.yref);
99+
const xa0 = Axes.getFromId(gd, isArrayXref ? options.xref[0] : options.xref);
100+
const xa1 = Axes.getFromId(gd, isArrayXref ? options.xref[1] : options.xref);
101+
const ya0 = Axes.getFromId(gd, isArrayYref ? options.yref[0] : options.yref);
102+
const ya1 = Axes.getFromId(gd, isArrayYref ? options.yref[1] : options.yref);
103+
const xRefType0 = Axes.getRefType(isArrayXref ? options.xref[0] : options.xref);
104+
const xRefType1 = Axes.getRefType(isArrayXref ? options.xref[1] : options.xref);
105+
const yRefType0 = Axes.getRefType(isArrayYref ? options.yref[0] : options.yref);
106+
const yRefType1 = Axes.getRefType(isArrayYref ? options.yref[1] : options.yref);
107+
const x2p = function(v, shift, xa, xRefType) {
108108
return helpers.getDataToPixel(gd, xa, shift, false, xRefType)(v);
109109
};
110-
var y2p = function(v, shift, ya, yRefType) {
110+
const y2p = function(v, shift, ya, yRefType) {
111111
return helpers.getDataToPixel(gd, ya, shift, true, yRefType)(v);
112112
};
113113
shapex0 = x2p(options.x0, options.x0shift, xa0, xRefType0);

src/components/shapes/draw.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function drawOne(gd, index) {
9191
// TODO: use d3 idioms instead of deleting and redrawing every time
9292
if(!options._input || options.visible !== true) return;
9393

94-
var isMultiAxisShape = Array.isArray(options.xref) || Array.isArray(options.yref);
94+
const isMultiAxisShape = Array.isArray(options.xref) || Array.isArray(options.yref);
9595

9696
if(options.layer === 'above') {
9797
drawShape(gd._fullLayout._shapeUpperLayer);
@@ -199,31 +199,31 @@ function setClipPath(shapePath, gd, shapeOptions) {
199199
// if axis is 'paper' or an axis with " domain" appended, then there is no
200200
// clip axis
201201

202-
var xref = shapeOptions.xref;
203-
var yref = shapeOptions.yref;
202+
const xref = shapeOptions.xref;
203+
const yref = shapeOptions.yref;
204204

205205
// For multi-axis shapes, create a custom clip path from axis bounds
206206
if(Array.isArray(xref) || Array.isArray(yref)) {
207-
var clipId = 'clip' + gd._fullLayout._uid + 'shape' + shapeOptions._index;
208-
var rect = getMultiAxisClipRect(gd, xref, yref);
207+
const clipId = 'clip' + gd._fullLayout._uid + 'shape' + shapeOptions._index;
208+
const rect = getMultiAxisClipRect(gd, xref, yref);
209209

210210
Lib.ensureSingleById(gd._fullLayout._clips, 'clipPath', clipId, function(s) {
211211
s.append('rect');
212212
}).select('rect').attr(rect);
213213

214214
Drawing.setClipUrl(shapePath, clipId, gd);
215215
} else {
216-
var clipAxes = (xref + yref).replace(/paper/g, '').replace(/[xyz][0-9]* *domain/g, '');
216+
const clipAxes = (xref + yref).replace(/paper/g, '').replace(/[xyz][0-9]* *domain/g, '');
217217
Drawing.setClipUrl(shapePath, clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null, gd);
218218
}
219219
}
220220

221221
function getMultiAxisClipRect(gd, xref, yref) {
222-
var gs = gd._fullLayout._size;
222+
const gs = gd._fullLayout._size;
223223

224224
function getBounds(refs, isVertical) {
225225
// Retrieve all existing axes from the references
226-
var axes = (Array.isArray(refs) ? refs : [refs])
226+
const axes = (Array.isArray(refs) ? refs : [refs])
227227
.map(r => Axes.getFromId(gd, r))
228228
.filter(Boolean);
229229

@@ -234,13 +234,13 @@ function getMultiAxisClipRect(gd, xref, yref) {
234234

235235
// Otherwise, we find all find and return the smallest start point
236236
// and largest end point to be used as the clip bounds
237-
var startBounds = axes.map(function(ax) { return ax._offset; });
238-
var endBounds = axes.map(function(ax) { return ax._offset + ax._length; });
237+
const startBounds = axes.map(function(ax) { return ax._offset; });
238+
const endBounds = axes.map(function(ax) { return ax._offset + ax._length; });
239239
return [Math.min(...startBounds), Math.max(...endBounds)];
240240
}
241241

242-
var xb = getBounds(xref, false);
243-
var yb = getBounds(yref, true);
242+
const xb = getBounds(xref, false);
243+
const yb = getBounds(yref, true);
244244
return {x: xb[0], y: yb[0], width: xb[1] - xb[0], height: yb[1] - yb[0]};
245245
}
246246

src/components/shapes/helpers.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ exports.countDefiningCoords = function(shapeType, path, axLetter) {
5858
if(shapeType !== 'path') return 2;
5959
if(!path) return 0;
6060

61-
var segments = path.match(constants.segmentRE);
61+
const segments = path.match(constants.segmentRE);
6262
if(!segments) return 0;
6363

64-
var paramIsAxis = axLetter === 'x' ? constants.paramIsX : constants.paramIsY;
64+
const paramIsAxis = axLetter === 'x' ? constants.paramIsX : constants.paramIsY;
6565

6666
return segments.reduce((coordCount, segment) => {
6767
// for each path command, check if there is a drawn coordinate for this axis
68-
var segmentType = segment.charAt(0);
69-
var hasDrawn = paramIsAxis[segmentType].drawn !== undefined;
68+
const segmentType = segment.charAt(0);
69+
const hasDrawn = paramIsAxis[segmentType].drawn !== undefined;
7070
return coordCount + (hasDrawn ? 1 : 0);
7171
}, 0);
7272
};
@@ -191,10 +191,10 @@ exports.makeSelectionsOptionsAndPlotinfo = function(gd, index) {
191191

192192

193193
exports.getPathString = function(gd, options) {
194-
var shapeType = options.type;
195-
var xRefType = Axes.getRefType(options.xref);
196-
var yRefType = Axes.getRefType(options.yref);
197-
var gs = gd._fullLayout._size;
194+
const shapeType = options.type;
195+
const xRefType = Axes.getRefType(options.xref);
196+
const yRefType = Axes.getRefType(options.yref);
197+
const gs = gd._fullLayout._size;
198198
var xa, ya;
199199
var xShiftStart, xShiftEnd, yShiftStart, yShiftEnd;
200200
var x2p, y2p;
@@ -210,7 +210,7 @@ exports.getPathString = function(gd, options) {
210210
converter = function(v) { return axis._offset + axis._length * v; };
211211
}
212212
} else {
213-
var d2r = exports.shapePositionToRange(axis);
213+
const d2r = exports.shapePositionToRange(axis);
214214
converter = function(v) { return axis._offset + axis.r2p(d2r(v, true)); };
215215

216216
if(shapeType === 'path' && axis.type === 'date') converter = exports.decodeDate(converter);
@@ -261,7 +261,7 @@ exports.getPathString = function(gd, options) {
261261
xShiftStart = getPixelShift(xa, options.x0shift);
262262
xShiftEnd = getPixelShift(xa, options.x1shift);
263263
if(options.xsizemode === 'pixel') {
264-
var xAnchorPos = x2p(options.xanchor);
264+
const xAnchorPos = x2p(options.xanchor);
265265
x0 = xAnchorPos + options.x0 + xShiftStart;
266266
x1 = xAnchorPos + options.x1 + xShiftEnd;
267267
} else {
@@ -278,7 +278,7 @@ exports.getPathString = function(gd, options) {
278278
yShiftStart = getPixelShift(ya, options.y0shift);
279279
yShiftEnd = getPixelShift(ya, options.y1shift);
280280
if(options.ysizemode === 'pixel') {
281-
var yAnchorPos = y2p(options.yanchor);
281+
const yAnchorPos = y2p(options.yanchor);
282282
y0 = yAnchorPos - options.y0 + yShiftStart;
283283
y1 = yAnchorPos - options.y1 + yShiftEnd;
284284
} else {
@@ -303,13 +303,13 @@ exports.getPathString = function(gd, options) {
303303
};
304304

305305
function convertPath(options, x2p, y2p) {
306-
var pathIn = options.path;
307-
var xSizemode = options.xsizemode;
308-
var ySizemode = options.ysizemode;
309-
var xAnchor = options.xanchor;
310-
var yAnchor = options.yanchor;
311-
var isArrayXref = Array.isArray(options.xref);
312-
var isArrayYref = Array.isArray(options.yref);
306+
const pathIn = options.path;
307+
const xSizemode = options.xsizemode;
308+
const ySizemode = options.ysizemode;
309+
const xAnchor = options.xanchor;
310+
const yAnchor = options.yanchor;
311+
const isArrayXref = Array.isArray(options.xref);
312+
const isArrayYref = Array.isArray(options.yref);
313313
var xVertexIndex = 0;
314314
var yVertexIndex = 0;
315315

@@ -319,12 +319,12 @@ function convertPath(options, x2p, y2p) {
319319
var xParams = constants.paramIsX[segmentType];
320320
var yParams = constants.paramIsY[segmentType];
321321
var nParams = constants.numParams[segmentType];
322-
var hasDrawnX = xParams.drawn !== undefined;
323-
var hasDrawnY = yParams.drawn !== undefined;
322+
const hasDrawnX = xParams.drawn !== undefined;
323+
const hasDrawnY = yParams.drawn !== undefined;
324324

325325
// Use vertex indices for array refs (same converter for all params in segment)
326-
var segmentX2p = isArrayXref ? x2p[xVertexIndex] : x2p;
327-
var segmentY2p = isArrayYref ? y2p[yVertexIndex] : y2p;
326+
const segmentX2p = isArrayXref ? x2p[xVertexIndex] : x2p;
327+
const segmentY2p = isArrayYref ? y2p[yVertexIndex] : y2p;
328328

329329
var paramString = segment.slice(1).replace(constants.paramRE, function(param) {
330330
if(xParams[paramNumber]) {

src/plots/cartesian/axes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption
136136
* Only required if it's different from `dflt`
137137
*/
138138
axes.coerceRefArray = function(containerIn, containerOut, gd, attr, dflt, extraOption, expectedLen) {
139-
var axLetter = attr.charAt(attr.length - 1);
139+
const axLetter = attr.charAt(attr.length - 1);
140140
var axlist = gd._fullLayout._subplots[axLetter + 'axis'];
141-
var refAttr = attr + 'ref';
141+
const refAttr = attr + 'ref';
142142
var axRef = containerIn[refAttr];
143143

144144
// Build the axis list, which we use to validate the axis references

0 commit comments

Comments
 (0)