Skip to content

Commit 2d5d3e0

Browse files
committed
Linting/formatting
1 parent 5c2dbda commit 2d5d3e0

File tree

4 files changed

+628
-366
lines changed

4 files changed

+628
-366
lines changed

src/components/color/index.js

Lines changed: 65 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
const isNumeric = require('fast-isnumeric');
44
const isTypedArray = require('../../lib/array').isTypedArray;
5-
const color = require('color').default
5+
const color = require('color').default;
66

77
const { background, defaultLine, defaults, lightLine } = require('./attributes');
88

9-
const rgb = cstr => {
9+
const rgb = (cstr) => {
1010
const { r, g, b } = color(cstr).rgb().object();
1111
return `rgb(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)})`;
12-
}
12+
};
1313

14-
const opacity = cstr => cstr ? color(cstr).alpha() : 0;
14+
const opacity = (cstr) => (cstr ? color(cstr).alpha() : 0);
1515

1616
const addOpacity = (cstr, op) => {
1717
const c = color(cstr).rgb().object();
@@ -24,18 +24,19 @@ const addOpacity = (cstr, op) => {
2424
const combine = (front, back = background) => {
2525
const fc = color(front).rgb().object();
2626
fc.alpha ||= 1;
27-
if(fc.alpha === 1) return color(front).rgb().string();
27+
if (fc.alpha === 1) return color(front).rgb().string();
2828

2929
const bc = color(back).rgb().object();
3030
bc.alpha ||= 1;
31-
const bcflat = bc.alpha === 1
32-
? bc
33-
: {
34-
r: 255 * (1 - bc.alpha) + bc.r * bc.alpha,
35-
g: 255 * (1 - bc.alpha) + bc.g * bc.alpha,
36-
b: 255 * (1 - bc.alpha) + bc.b * bc.alpha
37-
};
38-
31+
const bcflat =
32+
bc.alpha === 1
33+
? bc
34+
: {
35+
r: 255 * (1 - bc.alpha) + bc.r * bc.alpha,
36+
g: 255 * (1 - bc.alpha) + bc.g * bc.alpha,
37+
b: 255 * (1 - bc.alpha) + bc.b * bc.alpha
38+
};
39+
3940
const fcflat = {
4041
r: bcflat.r * (1 - fc.alpha) + fc.r * fc.alpha,
4142
g: bcflat.g * (1 - fc.alpha) + fc.g * fc.alpha,
@@ -58,7 +59,7 @@ const interpolate = (first, second, factor) => {
5859
const ic = {
5960
r: factor * fc.r + (1 - factor) * sc.r,
6061
g: factor * fc.g + (1 - factor) * sc.g,
61-
b: factor * fc.b + (1 - factor) * sc.b,
62+
b: factor * fc.b + (1 - factor) * sc.b
6263
};
6364

6465
return color(ic).rgb().string();
@@ -73,15 +74,19 @@ const interpolate = (first, second, factor) => {
7374
* otherwise we go all the way to white or black.
7475
*/
7576
const contrast = (cstr, lightAmount, darkAmount) => {
76-
let c = color(cstr)
77+
let c = color(cstr);
7778

78-
if(c.alpha() !== 1) c = color(combine(cstr, background));
79+
if (c.alpha() !== 1) c = color(combine(cstr, background));
7980

8081
// TODO: Should the API change such that lightAmount/darkAmount are passed in as decimal instead of percent number?
8182
const newColor = color(
8283
c.isDark()
83-
? (lightAmount ? c.lighten(lightAmount / 100) : background)
84-
: (darkAmount ? c.darken(darkAmount / 100) : defaultLine)
84+
? lightAmount
85+
? c.lighten(lightAmount / 100)
86+
: background
87+
: darkAmount
88+
? c.darken(darkAmount / 100)
89+
: defaultLine
8590
);
8691

8792
return newColor.rgb().string();
@@ -93,89 +98,94 @@ const fill = (s, cstr) => s.style({ fill: rgb(cstr), 'fill-opacity': opacity(cst
9398

9499
// search container for colors with the deprecated rgb(fractions) format
95100
// and convert them to rgb(0-255 values)
96-
const clean = container => {
97-
if(!container || typeof container !== 'object') return;
101+
const clean = (container) => {
102+
if (!container || typeof container !== 'object') return;
98103

99104
var keys = Object.keys(container);
100105
var i, j, key, val;
101106

102-
for(i = 0; i < keys.length; i++) {
107+
for (i = 0; i < keys.length; i++) {
103108
key = keys[i];
104109
val = container[key];
105110

106-
if(key.substr(key.length - 5) === 'color') {
111+
if (key.substr(key.length - 5) === 'color') {
107112
// only sanitize keys that end in "color" or "colorscale"
108113

109-
if(Array.isArray(val)) {
110-
for(j = 0; j < val.length; j++) val[j] = cleanOne(val[j]);
114+
if (Array.isArray(val)) {
115+
for (j = 0; j < val.length; j++) val[j] = cleanOne(val[j]);
111116
} else container[key] = cleanOne(val);
112-
} else if(key.substr(key.length - 10) === 'colorscale' && Array.isArray(val)) {
117+
} else if (key.substr(key.length - 10) === 'colorscale' && Array.isArray(val)) {
113118
// colorscales have the format [[0, color1], [frac, color2], ... [1, colorN]]
114119

115-
for(j = 0; j < val.length; j++) {
116-
if(Array.isArray(val[j])) val[j][1] = cleanOne(val[j][1]);
120+
for (j = 0; j < val.length; j++) {
121+
if (Array.isArray(val[j])) val[j][1] = cleanOne(val[j][1]);
117122
}
118-
} else if(Array.isArray(val)) {
123+
} else if (Array.isArray(val)) {
119124
// recurse into arrays of objects, and plain objects
120125

121126
var el0 = val[0];
122-
if(!Array.isArray(el0) && el0 && typeof el0 === 'object') {
123-
for(j = 0; j < val.length; j++) clean(val[j]);
127+
if (!Array.isArray(el0) && el0 && typeof el0 === 'object') {
128+
for (j = 0; j < val.length; j++) clean(val[j]);
124129
}
125-
} else if(val && typeof val === 'object' && !isTypedArray(val)) clean(val);
130+
} else if (val && typeof val === 'object' && !isTypedArray(val)) clean(val);
126131
}
127132
};
128133

129-
const cleanOne = val => {
130-
if(isNumeric(val) || typeof val !== 'string') return val;
134+
const cleanOne = (val) => {
135+
if (isNumeric(val) || typeof val !== 'string') return val;
131136

132137
var valTrim = val.trim();
133-
if(valTrim.substr(0, 3) !== 'rgb') return val;
138+
if (valTrim.substr(0, 3) !== 'rgb') return val;
134139

135140
var match = valTrim.match(/^rgba?\s*\(([^()]*)\)$/);
136-
if(!match) return val;
141+
if (!match) return val;
137142

138143
var parts = match[1].trim().split(/\s*[\s,]\s*/);
139144
var rgba = valTrim.charAt(3) === 'a' && parts.length === 4;
140-
if(!rgba && parts.length !== 3) return val;
145+
if (!rgba && parts.length !== 3) return val;
141146

142-
for(var i = 0; i < parts.length; i++) {
143-
if(!parts[i].length) return val;
147+
for (var i = 0; i < parts.length; i++) {
148+
if (!parts[i].length) return val;
144149
parts[i] = Number(parts[i]);
145150

146-
if(!(parts[i] >= 0)) {
151+
if (!(parts[i] >= 0)) {
147152
// all parts must be non-negative numbers
148153

149154
return val;
150155
}
151156

152-
if(i === 3) {
157+
if (i === 3) {
153158
// alpha>1 gets clipped to 1
154159

155-
if(parts[i] > 1) parts[i] = 1;
156-
} else if(parts[i] >= 1) {
160+
if (parts[i] > 1) parts[i] = 1;
161+
} else if (parts[i] >= 1) {
157162
// r, g, b must be < 1 (ie 1 itself is not allowed)
158163

159164
return val;
160165
}
161166
}
162167

163-
var rgbStr = Math.round(parts[0] * 255) + ', ' +
164-
Math.round(parts[1] * 255) + ', ' +
165-
Math.round(parts[2] * 255);
168+
var rgbStr = Math.round(parts[0] * 255) + ', ' + Math.round(parts[1] * 255) + ', ' + Math.round(parts[2] * 255);
166169

167-
if(rgba) return 'rgba(' + rgbStr + ', ' + parts[3] + ')';
170+
if (rgba) return 'rgba(' + rgbStr + ', ' + parts[3] + ')';
168171
return 'rgb(' + rgbStr + ')';
169-
}
172+
};
170173

171174
const equals = (cstr1, cstr2) => cstr1 && cstr2 && color(cstr1).rgb().string() === color(cstr2).rgb().string();
172175

173-
const isValid = cstr => {
174-
try { return cstr && !!color(cstr); }
175-
catch { return false; }
176-
}
176+
const isValid = (cstr) => {
177+
try {
178+
return cstr && !!color(cstr);
179+
} catch {
180+
return false;
181+
}
182+
};
177183

178-
const mix = (cstr1, cstr2, weight) => color(cstr1).mix(color(cstr2), weight / 100).rgb().string();
184+
const mix = (cstr1, cstr2, weight) =>
185+
color(cstr1)
186+
.mix(color(cstr2), weight / 100)
187+
.rgb()
188+
.string();
179189

180190
const mostReadable = (baseColor, colorList = []) => {
181191
let bestColor;
@@ -188,11 +198,11 @@ const mostReadable = (baseColor, colorList = []) => {
188198
bestColor = color(cstr).rgb().string();
189199
}
190200
}
191-
201+
192202
// Fall back to black/white if provided colors don't have proper contrast level
193203
return bestColor && color(baseColor).level(color(bestColor))
194204
? bestColor
195-
: mostReadable(baseColor, ["#000", "#fff"]);
205+
: mostReadable(baseColor, ['#000', '#fff']);
196206
};
197207

198208
module.exports = {
@@ -214,4 +224,4 @@ module.exports = {
214224
opacity,
215225
rgb,
216226
stroke
217-
}
227+
};

src/components/fx/hover.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,9 +2227,10 @@ function createSpikelines(gd, closestPoints, opts) {
22272227
hLinePointX = xa._offset + hLinePoint.x;
22282228
hLinePointY = ya._offset + hLinePoint.y;
22292229
}
2230-
var dfltHLineColor = Color.color(hLinePoint.color).contrast(Color.color(contrastColor)) < 1.5
2231-
? Color.contrast(contrastColor)
2232-
: hLinePoint.color;
2230+
var dfltHLineColor =
2231+
Color.color(hLinePoint.color).contrast(Color.color(contrastColor)) < 1.5
2232+
? Color.contrast(contrastColor)
2233+
: hLinePoint.color;
22332234
var yMode = ya.spikemode;
22342235
var yThickness = ya.spikethickness;
22352236
var yColor = ya.spikecolor || dfltHLineColor;
@@ -2311,9 +2312,10 @@ function createSpikelines(gd, closestPoints, opts) {
23112312
vLinePointY = ya._offset + vLinePoint.y;
23122313
}
23132314

2314-
var dfltVLineColor = Color.color(vLinePoint.color).contrast(Color.color(contrastColor)) < 1.5
2315-
? Color.contrast(contrastColor)
2316-
: vLinePoint.color;
2315+
var dfltVLineColor =
2316+
Color.color(vLinePoint.color).contrast(Color.color(contrastColor)) < 1.5
2317+
? Color.contrast(contrastColor)
2318+
: vLinePoint.color;
23172319
var xMode = xa.spikemode;
23182320
var xThickness = xa.spikethickness;
23192321
var xColor = xa.spikecolor || dfltVLineColor;

src/traces/heatmap/plot.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ module.exports = function (gd, plotinfo, cdheatmaps, heatmapLayer) {
202202

203203
function setColor(v, pixsize) {
204204
if (v === undefined || pixsize === undefined) return [0, 0, 0, 0];
205-
205+
206206
var c = sclFunc(v);
207207
c[0] = Math.round(c[0]);
208208
c[1] = Math.round(c[1]);
@@ -349,7 +349,7 @@ module.exports = function (gd, plotinfo, cdheatmaps, heatmapLayer) {
349349
bcount = Math.round(bcount / pixcount);
350350

351351
const cstr = `rgb(${rcount}, ${gcount}, ${bcount})`;
352-
352+
353353
gd._hmpixcount = (gd._hmpixcount || 0) + pixcount;
354354
gd._hmlumcount = (gd._hmlumcount || 0) + pixcount * Color.color(cstr).luminosity();
355355
}
@@ -542,7 +542,11 @@ module.exports = function (gd, plotinfo, cdheatmaps, heatmapLayer) {
542542

543543
var fontColor = font.color;
544544
if (!fontColor || fontColor === 'auto') {
545-
fontColor = Color.contrast(d.z === undefined ? gd._fullLayout.plot_bgcolor : `rgba(${sclFunc(d.z).map(Math.round).join()})`);
545+
fontColor = Color.contrast(
546+
d.z === undefined
547+
? gd._fullLayout.plot_bgcolor
548+
: `rgba(${sclFunc(d.z).map(Math.round).join()})`
549+
);
546550
}
547551

548552
thisLabel

0 commit comments

Comments
 (0)