Skip to content

Commit 9b7cd8d

Browse files
committed
lint in Bar.crossTraceCalc
- convert sieve instantiation to `new Sieve(traces, {/* */}` signature - more readable barmode switchboard
1 parent 6bde984 commit 9b7cd8d

File tree

2 files changed

+73
-60
lines changed

2 files changed

+73
-60
lines changed

src/traces/bar/cross_trace_calc.js

Lines changed: 61 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -57,52 +57,57 @@ function setGroupPositions(gd, pa, sa, calcTraces) {
5757
if(!calcTraces.length) return;
5858

5959
var barmode = gd._fullLayout.barmode;
60-
var overlay = (barmode === 'overlay');
61-
var group = (barmode === 'group');
6260
var excluded;
6361
var included;
6462
var i, calcTrace, fullTrace;
6563

6664
initBase(gd, pa, sa, calcTraces);
6765

68-
if(overlay) {
69-
setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces);
70-
} else if(group) {
71-
// exclude from the group those traces for which the user set an offset
72-
excluded = [];
73-
included = [];
74-
for(i = 0; i < calcTraces.length; i++) {
75-
calcTrace = calcTraces[i];
76-
fullTrace = calcTrace[0].trace;
77-
78-
if(fullTrace.offset === undefined) included.push(calcTrace);
79-
else excluded.push(calcTrace);
80-
}
66+
switch(barmode) {
67+
case 'overlay':
68+
setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces);
69+
break;
70+
71+
case 'group':
72+
// exclude from the group those traces for which the user set an offset
73+
excluded = [];
74+
included = [];
75+
for(i = 0; i < calcTraces.length; i++) {
76+
calcTrace = calcTraces[i];
77+
fullTrace = calcTrace[0].trace;
78+
79+
if(fullTrace.offset === undefined) included.push(calcTrace);
80+
else excluded.push(calcTrace);
81+
}
8182

82-
if(included.length) {
83-
setGroupPositionsInGroupMode(gd, pa, sa, included);
84-
}
85-
if(excluded.length) {
86-
setGroupPositionsInOverlayMode(gd, pa, sa, excluded);
87-
}
88-
} else {
89-
// exclude from the stack those traces for which the user set a base
90-
excluded = [];
91-
included = [];
92-
for(i = 0; i < calcTraces.length; i++) {
93-
calcTrace = calcTraces[i];
94-
fullTrace = calcTrace[0].trace;
95-
96-
if(fullTrace.base === undefined) included.push(calcTrace);
97-
else excluded.push(calcTrace);
98-
}
83+
if(included.length) {
84+
setGroupPositionsInGroupMode(gd, pa, sa, included);
85+
}
86+
if(excluded.length) {
87+
setGroupPositionsInOverlayMode(gd, pa, sa, excluded);
88+
}
89+
break;
90+
91+
case 'stack':
92+
case 'relative':
93+
// exclude from the stack those traces for which the user set a base
94+
excluded = [];
95+
included = [];
96+
for(i = 0; i < calcTraces.length; i++) {
97+
calcTrace = calcTraces[i];
98+
fullTrace = calcTrace[0].trace;
99+
100+
if(fullTrace.base === undefined) included.push(calcTrace);
101+
else excluded.push(calcTrace);
102+
}
99103

100-
if(included.length) {
101-
setGroupPositionsInStackOrRelativeMode(gd, pa, sa, included);
102-
}
103-
if(excluded.length) {
104-
setGroupPositionsInOverlayMode(gd, pa, sa, excluded);
105-
}
104+
if(included.length) {
105+
setGroupPositionsInStackOrRelativeMode(gd, pa, sa, included);
106+
}
107+
if(excluded.length) {
108+
setGroupPositionsInOverlayMode(gd, pa, sa, excluded);
109+
}
110+
break;
106111
}
107112

108113
collectExtents(calcTraces, pa);
@@ -154,13 +159,15 @@ function initBase(gd, pa, sa, calcTraces) {
154159

155160
function setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces) {
156161
var barnorm = gd._fullLayout.barnorm;
157-
var separateNegativeValues = false;
158-
var dontMergeOverlappingData = !barnorm;
159162

160163
// update position axis and set bar offsets and widths
161164
for(var i = 0; i < calcTraces.length; i++) {
162165
var calcTrace = calcTraces[i];
163-
var sieve = new Sieve([calcTrace], separateNegativeValues, dontMergeOverlappingData);
166+
167+
var sieve = new Sieve([calcTrace], {
168+
separateNegativeValues: false,
169+
dontMergeOverlappingData: !barnorm
170+
});
164171

165172
// set bar offsets and widths, and update position axis
166173
setOffsetAndWidth(gd, pa, sieve);
@@ -182,9 +189,11 @@ function setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces) {
182189
function setGroupPositionsInGroupMode(gd, pa, sa, calcTraces) {
183190
var fullLayout = gd._fullLayout;
184191
var barnorm = fullLayout.barnorm;
185-
var separateNegativeValues = false;
186-
var dontMergeOverlappingData = !barnorm;
187-
var sieve = new Sieve(calcTraces, separateNegativeValues, dontMergeOverlappingData);
192+
193+
var sieve = new Sieve(calcTraces, {
194+
separateNegativeValues: false,
195+
dontMergeOverlappingData: !barnorm
196+
});
188197

189198
// set bar offsets and widths, and update position axis
190199
setOffsetAndWidthInGroupMode(gd, pa, sieve);
@@ -201,12 +210,12 @@ function setGroupPositionsInGroupMode(gd, pa, sa, calcTraces) {
201210
function setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces) {
202211
var fullLayout = gd._fullLayout;
203212
var barmode = fullLayout.barmode;
204-
var stack = barmode === 'stack';
205-
var relative = barmode === 'relative';
206213
var barnorm = fullLayout.barnorm;
207-
var separateNegativeValues = relative;
208-
var dontMergeOverlappingData = !(barnorm || stack || relative);
209-
var sieve = new Sieve(calcTraces, separateNegativeValues, dontMergeOverlappingData);
214+
215+
var sieve = new Sieve(calcTraces, {
216+
separateNegativeValues: barmode === 'relative',
217+
dontMergeOverlappingData: !(barnorm || barmode === 'stack' || barmode === 'relative')
218+
});
210219

211220
// set bar offsets and widths, and update position axis
212221
setOffsetAndWidth(gd, pa, sieve);
@@ -562,7 +571,9 @@ function sieveBars(gd, sa, sieve) {
562571
for(var j = 0; j < calcTrace.length; j++) {
563572
var bar = calcTrace[j];
564573

565-
if(bar.s !== BADNUM) sieve.put(bar.p, bar.b + bar.s);
574+
if(bar.s !== BADNUM) {
575+
sieve.put(bar.p, bar.b + bar.s);
576+
}
566577
}
567578
}
568579
}

src/traces/bar/sieve.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ var BADNUM = require('../../constants/numerical').BADNUM;
1717
* Helper class to sieve data from traces into bins
1818
*
1919
* @class
20-
* @param {Array} traces
21-
* Array of calculated traces
22-
* @param {boolean} [separateNegativeValues]
23-
* If true, then split data at the same position into a bar
24-
* for positive values and another for negative values
25-
* @param {boolean} [dontMergeOverlappingData]
26-
* If true, then don't merge overlapping bars into a single bar
20+
*
21+
* @param {Array} traces
22+
* Array of calculated traces
23+
* @param {object} opts
24+
* - @param {boolean} [separateNegativeValues]
25+
* If true, then split data at the same position into a bar
26+
* for positive values and another for negative values
27+
* - @param {boolean} [dontMergeOverlappingData]
28+
* If true, then don't merge overlapping bars into a single bar
2729
*/
28-
function Sieve(traces, separateNegativeValues, dontMergeOverlappingData) {
30+
function Sieve(traces, opts) {
2931
this.traces = traces;
30-
this.separateNegativeValues = separateNegativeValues;
31-
this.dontMergeOverlappingData = dontMergeOverlappingData;
32+
this.separateNegativeValues = opts.separateNegativeValues;
33+
this.dontMergeOverlappingData = opts.dontMergeOverlappingData;
3234

3335
// for single-bin histograms - see histogram/calc
3436
var width1 = Infinity;

0 commit comments

Comments
 (0)