Skip to content

Commit bf082cb

Browse files
committed
apply new eslint rule - pass2 - manual
1 parent 797c382 commit bf082cb

File tree

15 files changed

+152
-139
lines changed

15 files changed

+152
-139
lines changed

src/components/color/index.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,21 @@ color.clean = function(container) {
106106
key = keys[i];
107107
val = container[key];
108108

109-
// only sanitize keys that end in "color" or "colorscale"
110109
if(key.substr(key.length - 5) === 'color') {
110+
// only sanitize keys that end in "color" or "colorscale"
111+
111112
if(Array.isArray(val)) {
112113
for(j = 0; j < val.length; j++) val[j] = cleanOne(val[j]);
113114
} else container[key] = cleanOne(val);
114115
} else if(key.substr(key.length - 10) === 'colorscale' && Array.isArray(val)) {
115116
// colorscales have the format [[0, color1], [frac, color2], ... [1, colorN]]
117+
116118
for(j = 0; j < val.length; j++) {
117119
if(Array.isArray(val[j])) val[j][1] = cleanOne(val[j][1]);
118120
}
119-
}
120-
// recurse into arrays of objects, and plain objects
121-
else if(Array.isArray(val)) {
121+
} else if(Array.isArray(val)) {
122+
// recurse into arrays of objects, and plain objects
123+
122124
var el0 = val[0];
123125
if(!Array.isArray(el0) && el0 && typeof el0 === 'object') {
124126
for(j = 0; j < val.length; j++) color.clean(val[j]);
@@ -144,14 +146,21 @@ function cleanOne(val) {
144146
if(!parts[i].length) return val;
145147
parts[i] = Number(parts[i]);
146148

147-
// all parts must be non-negative numbers
148-
if(!(parts[i] >= 0)) return val;
149-
// alpha>1 gets clipped to 1
149+
if(!(parts[i] >= 0)) {
150+
// all parts must be non-negative numbers
151+
152+
return val;
153+
}
154+
150155
if(i === 3) {
156+
// alpha>1 gets clipped to 1
157+
151158
if(parts[i] > 1) parts[i] = 1;
159+
} else if(parts[i] >= 1) {
160+
// r, g, b must be < 1 (ie 1 itself is not allowed)
161+
162+
return val;
152163
}
153-
// r, g, b must be < 1 (ie 1 itself is not allowed)
154-
else if(parts[i] >= 1) return val;
155164
}
156165

157166
var rgbStr = Math.round(parts[0] * 255) + ', ' +

src/components/modebar/manage.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,13 @@ function isSelectable(fullData) {
203203
if(trace.boxpoints === 'all' || trace.points === 'all') {
204204
selectable = true;
205205
}
206+
} else {
207+
// assume that in general if the trace module has selectPoints,
208+
// then it's selectable. Scatter is an exception to this because it must
209+
// have markers or text, not just be a scatter type.
210+
211+
selectable = true;
206212
}
207-
// assume that in general if the trace module has selectPoints,
208-
// then it's selectable. Scatter is an exception to this because it must
209-
// have markers or text, not just be a scatter type.
210-
else selectable = true;
211213
}
212214

213215
return selectable;

src/lib/extend.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ function _extend(inputs, isDeep, keepAllKeys, noArrayCopies) {
8484
src = target[key];
8585
copy = input[key];
8686

87-
// Stop early and just transfer the array if array copies are disallowed:
8887
if(noArrayCopies && isArray(copy)) {
88+
// Stop early and just transfer the array if array copies are disallowed:
89+
8990
target[key] = copy;
90-
}
91+
} else if(isDeep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
92+
// recurse if we're merging plain objects or arrays
9193

92-
// recurse if we're merging plain objects or arrays
93-
else if(isDeep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
9494
if(copyIsArray) {
9595
copyIsArray = false;
9696
clone = src && isArray(src) ? src : [];
@@ -100,10 +100,9 @@ function _extend(inputs, isDeep, keepAllKeys, noArrayCopies) {
100100

101101
// never move original objects, clone them
102102
target[key] = _extend([clone, copy], isDeep, keepAllKeys, noArrayCopies);
103-
}
103+
} else if(typeof copy !== 'undefined' || keepAllKeys) {
104+
// don't bring in undefined values, except for extendDeepAll
104105

105-
// don't bring in undefined values, except for extendDeepAll
106-
else if(typeof copy !== 'undefined' || keepAllKeys) {
107106
target[key] = copy;
108107
}
109108
}

src/lib/polygon.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ polygon.tester = function tester(ptsIn) {
113113
y1 = pts[i][1];
114114
xmini = Math.min(x0, x1);
115115

116-
// outside the bounding box of this segment, it's only a crossing
117-
// if it's below the box.
118116
if(x < xmini || x > Math.max(x0, x1) || y > Math.max(y0, y1)) {
117+
// outside the bounding box of this segment, it's only a crossing
118+
// if it's below the box.
119+
119120
continue;
120121
} else if(y < Math.min(y0, y1)) {
121122
// don't count the left-most point of the segment as a crossing
@@ -124,9 +125,9 @@ polygon.tester = function tester(ptsIn) {
124125
// Note that this is repeated below, but we can't factor it out
125126
// because
126127
if(x !== xmini) crossings++;
127-
}
128-
// inside the bounding box, check the actual line intercept
129-
else {
128+
} else {
129+
// inside the bounding box, check the actual line intercept
130+
130131
// vertical segment - we know already that the point is exactly
131132
// on the segment, so mark the crossing as exactly at the point.
132133
if(x1 === x0) ycross = y;

src/plot_api/helpers.js

+16-19
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ exports.cleanLayout = function(layout) {
6262
for(i = 0; i < keys.length; i++) {
6363
var key = keys[i];
6464

65-
// modifications to cartesian axes
6665
if(axisAttrRegex && axisAttrRegex.test(key)) {
66+
// modifications to cartesian axes
67+
6768
var ax = layout[key];
6869
if(ax.anchor && ax.anchor !== 'free') {
6970
ax.anchor = cleanId(ax.anchor);
@@ -96,26 +97,21 @@ exports.cleanLayout = function(layout) {
9697
}
9798

9899
cleanTitle(ax);
99-
}
100+
} else if(polarAttrRegex && polarAttrRegex.test(key)) {
101+
// modifications for polar
100102

101-
// modifications for polar
102-
else if(polarAttrRegex && polarAttrRegex.test(key)) {
103103
var polar = layout[key];
104-
105104
cleanTitle(polar.radialaxis);
106-
}
105+
} else if(ternaryAttrRegex && ternaryAttrRegex.test(key)) {
106+
// modifications for ternary
107107

108-
// modifications for ternary
109-
else if(ternaryAttrRegex && ternaryAttrRegex.test(key)) {
110108
var ternary = layout[key];
111-
112109
cleanTitle(ternary.aaxis);
113110
cleanTitle(ternary.baxis);
114111
cleanTitle(ternary.caxis);
115-
}
112+
} else if(sceneAttrRegex && sceneAttrRegex.test(key)) {
113+
// modifications for 3D scenes
116114

117-
// modifications for 3D scenes
118-
else if(sceneAttrRegex && sceneAttrRegex.test(key)) {
119115
var scene = layout[key];
120116

121117
// clean old Camera coords
@@ -602,25 +598,26 @@ exports.manageArrayContainers = function(np, newVal, undoit) {
602598

603599
var pLastIsNumber = isNumeric(pLast);
604600

605-
// delete item
606601
if(pLastIsNumber && newVal === null) {
602+
// delete item
603+
607604
// Clear item in array container when new value is null
608605
var contPath = parts.slice(0, pLength - 1).join('.');
609606
var cont = Lib.nestedProperty(obj, contPath).get();
610607
cont.splice(pLast, 1);
611608

612609
// Note that nested property clears null / undefined at end of
613610
// array container, but not within them.
614-
}
615-
// create item
616-
else if(pLastIsNumber && np.get() === undefined) {
611+
} else if(pLastIsNumber && np.get() === undefined) {
612+
// create item
613+
617614
// When adding a new item, make sure undo command will remove it
618615
if(np.get() === undefined) undoit[np.astr] = null;
619616

620617
np.set(newVal);
621-
}
622-
// update item
623-
else {
618+
} else {
619+
// update item
620+
624621
// If the last part of attribute string isn't a number,
625622
// np.set is all we need.
626623
np.set(newVal);

src/plot_api/plot_api.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -1625,18 +1625,17 @@ function _restyle(gd, aobj, traces) {
16251625
for(var impliedKey in valObject.impliedEdits) {
16261626
doextra(Lib.relativeAttr(ai, impliedKey), valObject.impliedEdits[impliedKey], i);
16271627
}
1628-
}
1629-
1630-
// changing colorbar size modes,
1631-
// make the resulting size not change
1632-
// note that colorbar fractional sizing is based on the
1633-
// original plot size, before anything (like a colorbar)
1634-
// increases the margins
1635-
else if((finalPart === 'thicknessmode' || finalPart === 'lenmode') &&
1628+
} else if((finalPart === 'thicknessmode' || finalPart === 'lenmode') &&
16361629
oldVal !== newVal &&
16371630
(newVal === 'fraction' || newVal === 'pixels') &&
16381631
innerContFull
16391632
) {
1633+
// changing colorbar size modes,
1634+
// make the resulting size not change
1635+
// note that colorbar fractional sizing is based on the
1636+
// original plot size, before anything (like a colorbar)
1637+
// increases the margins
1638+
16401639
var gs = fullLayout._size;
16411640
var orient = innerContFull.orient;
16421641
var topOrBottom = (orient === 'top') || (orient === 'bottom');
@@ -1690,10 +1689,10 @@ function _restyle(gd, aobj, traces) {
16901689
if((param.get() || defaultOrientation) === contFull.orientation) {
16911690
continue;
16921691
}
1693-
}
1694-
// orientationaxes has no value,
1695-
// it flips everything and the axes
1696-
else if(ai === 'orientationaxes') {
1692+
} else if(ai === 'orientationaxes') {
1693+
// orientationaxes has no value,
1694+
// it flips everything and the axes
1695+
16971696
cont.orientation =
16981697
{v: 'h', h: 'v'}[contFull.orientation];
16991698
}
@@ -2113,9 +2112,9 @@ function _relayout(gd, aobj) {
21132112
// depends on vi here too, so again can't use impliedEdits
21142113
doextra('width', vi ? null : fullLayout.width);
21152114
doextra('height', vi ? null : fullLayout.height);
2116-
}
2117-
// check autorange vs range
2118-
else if(pleafPlus.match(AX_RANGE_RE)) {
2115+
} else if(pleafPlus.match(AX_RANGE_RE)) {
2116+
// check autorange vs range
2117+
21192118
recordAlteredAxis(pleafPlus);
21202119
nestedProperty(fullLayout, ptrunk + '._inputRange').set(null);
21212120
} else if(pleafPlus.match(AX_AUTORANGE_RE)) {
@@ -2240,9 +2239,9 @@ function _relayout(gd, aobj) {
22402239
objEdits[propStr] = vi;
22412240

22422241
delete aobj[ai];
2243-
}
2244-
// handle axis reversal explicitly, as there's no 'reverse' attribute
2245-
else if(pleaf === 'reverse') {
2242+
} else if(pleaf === 'reverse') {
2243+
// handle axis reversal explicitly, as there's no 'reverse' attribute
2244+
22462245
if(parentIn.range) parentIn.range.reverse();
22472246
else {
22482247
doextra(ptrunk + '.autorange', true);

src/plot_api/plot_schema.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ function getLayoutAttributes() {
543543
_module = Registry.componentsRegistry[key];
544544
var schema = _module.schema;
545545

546+
if(schema && (schema.subplots || schema.layout)) {
546547
/*
547548
* Components with defined schema have already been merged in at register time
548549
* but a few components define attributes that apply only to xaxis
@@ -553,14 +554,14 @@ function getLayoutAttributes() {
553554
* we will need to extend both this code and mergeComponentAttrsToSubplot
554555
* (which will not find yaxis only for example)
555556
*/
556-
if(schema && (schema.subplots || schema.layout)) {
557+
557558
var subplots = schema.subplots;
558559
if(subplots && subplots.xaxis && !subplots.yaxis) {
559560
for(var xkey in subplots.xaxis) delete layoutAttributes.yaxis[xkey];
560561
}
561-
}
562+
} else if(_module.layoutAttributes) {
562563
// older style without schema need to be explicitly merged in now
563-
else if(_module.layoutAttributes) {
564+
564565
insertAttrs(layoutAttributes, _module.layoutAttributes, _module.name);
565566
}
566567
}

src/plots/cartesian/axes.js

+27-25
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,26 @@ axes.minDtick = function(ax, newDiff, newFirst, allow) {
233233
// and the plot itself may decide to cancel (ie non-grouped bars)
234234
if(['log', 'category', 'multicategory'].indexOf(ax.type) !== -1 || !allow) {
235235
ax._minDtick = 0;
236-
}
237-
// undefined means there's nothing there yet
238-
else if(ax._minDtick === undefined) {
236+
} else if(ax._minDtick === undefined) {
237+
// undefined means there's nothing there yet
238+
239239
ax._minDtick = newDiff;
240240
ax._forceTick0 = newFirst;
241241
} else if(ax._minDtick) {
242-
// existing minDtick is an integer multiple of newDiff
243-
// (within rounding err)
244-
// and forceTick0 can be shifted to newFirst
245242
if((ax._minDtick / newDiff + 1e-6) % 1 < 2e-6 &&
243+
// existing minDtick is an integer multiple of newDiff
244+
// (within rounding err)
245+
// and forceTick0 can be shifted to newFirst
246+
246247
(((newFirst - ax._forceTick0) / newDiff % 1) +
247248
1.000001) % 1 < 2e-6) {
248249
ax._minDtick = newDiff;
249250
ax._forceTick0 = newFirst;
250-
}
251-
// if the converse is true (newDiff is a multiple of minDtick and
252-
// newFirst can be shifted to forceTick0) then do nothing - same
253-
// forcing stands. Otherwise, cancel forced minimum
254-
else if((newDiff / ax._minDtick + 1e-6) % 1 > 2e-6 ||
251+
} else if((newDiff / ax._minDtick + 1e-6) % 1 > 2e-6 ||
252+
// if the converse is true (newDiff is a multiple of minDtick and
253+
// newFirst can be shifted to forceTick0) then do nothing - same
254+
// forcing stands. Otherwise, cancel forced minimum
255+
255256
(((newFirst - ax._forceTick0) / ax._minDtick % 1) +
256257
1.000001) % 1 > 2e-6) {
257258
ax._minDtick = 0;
@@ -431,17 +432,18 @@ function autoShiftNumericBins(binStart, data, ax, dataMin, dataMax) {
431432
var dataCount = data.length - blankCount;
432433

433434
if(intcount === dataCount && ax.type !== 'date') {
434-
// all integers: if bin size is <1, it's because
435-
// that was specifically requested (large nbins)
436-
// so respect that... but center the bins containing
437-
// integers on those integers
438435
if(ax.dtick < 1) {
436+
// all integers: if bin size is <1, it's because
437+
// that was specifically requested (large nbins)
438+
// so respect that... but center the bins containing
439+
// integers on those integers
440+
439441
binStart = dataMin - 0.5 * ax.dtick;
440-
}
441-
// otherwise start half an integer down regardless of
442-
// the bin size, just enough to clear up endpoint
443-
// ambiguity about which integers are in which bins.
444-
else {
442+
} else {
443+
// otherwise start half an integer down regardless of
444+
// the bin size, just enough to clear up endpoint
445+
// ambiguity about which integers are in which bins.
446+
445447
binStart -= 0.5;
446448
if(binStart + ax.dtick < dataMin) binStart += ax.dtick;
447449
}
@@ -829,9 +831,10 @@ function autoTickRound(ax) {
829831
ax._tickexponent = 3 * Math.round((rangeexp - 1) / 3);
830832
} else ax._tickexponent = rangeexp;
831833
}
834+
} else {
835+
// D1 or D2 (log)
836+
ax._tickround = null;
832837
}
833-
// D1 or D2 (log)
834-
else ax._tickround = null;
835838
}
836839

837840
// months and years don't have constant millisecond values
@@ -915,10 +918,9 @@ axes.tickFirst = function(ax) {
915918
}
916919
Lib.error('tickFirst did not converge', ax);
917920
return t0;
918-
}
921+
} else if(tType === 'L') {
922+
// Log scales: Linear, Digits
919923

920-
// Log scales: Linear, Digits
921-
else if(tType === 'L') {
922924
return Math.log(sRound(
923925
(Math.pow(10, r0) - tick0) / dtNum) * dtNum + tick0) / Math.LN10;
924926
} else if(tType === 'D') {

0 commit comments

Comments
 (0)