Skip to content

Commit 86478a4

Browse files
committed
Fix sieve for offsetgroups
Previous attempt that used bar.p + offsetIndex resulted in the same bin for a bar with bar.p 0 and offsetIndex 1 and a bar with bar.p 1 and offsetIndex 0
1 parent c6f5dbe commit 86478a4

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/traces/bar/cross_trace_calc.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ function setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces, opts) {
284284
// flag the outmost bar (for text display purposes)
285285
for(var i = 0; i < calcTraces.length; i++) {
286286
var calcTrace = calcTraces[i];
287-
287+
var offsetIndex = calcTrace[0].t.offsetindex;
288288
for(var j = 0; j < calcTrace.length; j++) {
289289
var bar = calcTrace[j];
290290

291291
if(bar.s !== BADNUM) {
292-
var isOutmostBar = ((bar.b + bar.s) === sieve.get(bar.p, bar.s));
292+
var isOutmostBar = ((bar.b + bar.s) === sieve.get(bar.p, offsetIndex, bar.s));
293293
if(isOutmostBar) bar._outmost = true;
294294
}
295295
}
@@ -583,7 +583,7 @@ function stackBars(sa, sieve, opts) {
583583

584584
if(bar.s !== BADNUM) {
585585
// create base of funnels
586-
sieve.put(bar.p + offsetIndex, -0.5 * bar.s);
586+
sieve.put(bar.p, offsetIndex, -0.5 * bar.s);
587587
}
588588
}
589589
}
@@ -611,7 +611,7 @@ function stackBars(sa, sieve, opts) {
611611
value = bar.s + bar.b;
612612
}
613613

614-
var base = sieve.put(bar.p + offsetIndex, value);
614+
var base = sieve.put(bar.p, offsetIndex, value);
615615
var top = base + value;
616616

617617
// store the bar base and top in each calcdata item
@@ -644,12 +644,12 @@ function sieveBars(sieve) {
644644

645645
for(var i = 0; i < calcTraces.length; i++) {
646646
var calcTrace = calcTraces[i];
647-
647+
var offsetIndex = calcTrace[0].t.offsetindex;
648648
for(var j = 0; j < calcTrace.length; j++) {
649649
var bar = calcTrace[j];
650650

651651
if(bar.s !== BADNUM) {
652-
sieve.put(bar.p, bar.b + bar.s);
652+
sieve.put(bar.p, offsetIndex, bar.b + bar.s);
653653
}
654654
}
655655
}
@@ -661,6 +661,7 @@ function unhideBarsWithinTrace(sieve, pa) {
661661
for(var i = 0; i < calcTraces.length; i++) {
662662
var calcTrace = calcTraces[i];
663663
var fullTrace = calcTrace[0].trace;
664+
var offsetIndex = calcTrace[0].t.offsetindex;
664665

665666
if(fullTrace.base === undefined) {
666667
var inTraceSieve = new Sieve([calcTrace], {
@@ -674,7 +675,7 @@ function unhideBarsWithinTrace(sieve, pa) {
674675

675676
if(bar.p !== BADNUM) {
676677
// stack current bar and get previous sum
677-
var base = inTraceSieve.put(bar.p, bar.b + bar.s);
678+
var base = inTraceSieve.put(bar.p, offsetIndex, bar.b + bar.s);
678679

679680
// if previous sum if non-zero, this means:
680681
// multiple bars have same starting point are potentially hidden,
@@ -707,6 +708,7 @@ function normalizeBars(sa, sieve, opts) {
707708

708709
for(var i = 0; i < calcTraces.length; i++) {
709710
var calcTrace = calcTraces[i];
711+
var offsetIndex = calcTrace[0].t.offsetindex;
710712
var fullTrace = calcTrace[0].trace;
711713
var pts = [];
712714
var tozero = false;
@@ -716,7 +718,7 @@ function normalizeBars(sa, sieve, opts) {
716718
var bar = calcTrace[j];
717719

718720
if(bar.s !== BADNUM) {
719-
var scale = Math.abs(sTop / sieve.get(bar.p, bar.s));
721+
var scale = Math.abs(sTop / sieve.get(bar.p, offsetIndex, bar.s));
720722
bar.b *= scale;
721723
bar.s *= scale;
722724

src/traces/bar/sieve.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ function Sieve(traces, opts) {
6969
* @param {number} value
7070
* @returns {number} Previous bin value
7171
*/
72-
Sieve.prototype.put = function put(position, value) {
73-
var label = this.getLabel(position, value);
72+
Sieve.prototype.put = function put(position, group, value) {
73+
var label = this.getLabel(position, group, value);
7474
var oldValue = this.bins[label] || 0;
7575

7676
this.bins[label] = oldValue + value;
@@ -87,8 +87,8 @@ Sieve.prototype.put = function put(position, value) {
8787
* (required if this.sepNegVal is true)
8888
* @returns {number} Current bin value
8989
*/
90-
Sieve.prototype.get = function get(position, value) {
91-
var label = this.getLabel(position, value);
90+
Sieve.prototype.get = function get(position, group, value) {
91+
var label = this.getLabel(position, group, value);
9292
return this.bins[label] || 0;
9393
};
9494

@@ -103,10 +103,10 @@ Sieve.prototype.get = function get(position, value) {
103103
* (prefixed with a 'v' if value is negative and this.sepNegVal is
104104
* true; otherwise prefixed with '^')
105105
*/
106-
Sieve.prototype.getLabel = function getLabel(position, value) {
106+
Sieve.prototype.getLabel = function getLabel(position, group, value) {
107107
var prefix = (value < 0 && this.sepNegVal) ? 'v' : '^';
108108
var label = (this.overlapNoMerge) ?
109109
position :
110110
Math.round(position / this.binWidth);
111-
return prefix + label;
111+
return prefix + label + 'g' + group;
112112
};

0 commit comments

Comments
 (0)