Skip to content

Commit 3e7f03e

Browse files
committed
add option to set minDiff to 1 from distinctVals
1 parent 381cfbc commit 3e7f03e

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/lib/search.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ exports.sorterDes = function(a, b) { return b - a; };
7171
* just be off by a rounding error
7272
* return the distinct values and the minimum difference between any two
7373
*/
74-
exports.distinctVals = function(valsIn) {
74+
exports.distinctVals = function(valsIn, opts) {
75+
var unitMinDiff = (opts || {}).unitMinDiff;
76+
7577
var vals = valsIn.slice(); // otherwise we sort the original array...
7678
vals.sort(exports.sorterAsc); // undefined listed in the end - also works on IE11
7779

@@ -80,7 +82,9 @@ exports.distinctVals = function(valsIn) {
8082
if(vals[last] !== BADNUM) break;
8183
}
8284

83-
var minDiff = (vals[last] - vals[0]) || 1;
85+
var minDiff = 1;
86+
if(!unitMinDiff) minDiff = (vals[last] - vals[0]) || 1;
87+
8488
var errDiff = minDiff / (last || 1) / 10000;
8589
var newVals = [];
8690
var preV;

src/traces/bar/cross_trace_calc.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,15 @@ function initBase(sa, calcTraces) {
175175
}
176176

177177
function setGroupPositionsInOverlayMode(pa, sa, calcTraces, opts) {
178-
var sieve;
179-
var sieveOpts = {
180-
sepNegVal: false,
181-
overlapNoMerge: !opts.norm
182-
};
183-
184-
var categoryOverlay = opts.xCat || opts.yCat;
185-
if(categoryOverlay) {
186-
sieve = new Sieve(calcTraces, sieveOpts);
187-
}
188-
189178
// update position axis and set bar offsets and widths
190179
for(var i = 0; i < calcTraces.length; i++) {
191-
if(!categoryOverlay) sieve = new Sieve([calcTraces[i]], sieveOpts);
180+
var calcTrace = calcTraces[i];
181+
182+
var sieve = new Sieve([calcTrace], {
183+
unitMinDiff: opts.xCat || opts.yCat,
184+
sepNegVal: false,
185+
overlapNoMerge: !opts.norm
186+
});
192187

193188
// set bar offsets and widths, and update position axis
194189
setOffsetAndWidth(pa, sieve, opts);

src/traces/bar/sieve.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ function Sieve(traces, opts) {
4848
}
4949
this.positions = positions;
5050

51-
var dv = distinctVals(positions);
51+
var dv = distinctVals(positions, {
52+
unitMinDiff: opts.unitMinDiff
53+
});
54+
5255
this.distinctPositions = dv.vals;
5356
if(dv.vals.length === 1 && width1 !== Infinity) this.minDiff = width1;
5457
else this.minDiff = Math.min(dv.minDiff, width1);

0 commit comments

Comments
 (0)