Skip to content

Commit 7ebee7d

Browse files
committed
Add group + group test and revert src/plots
1 parent 464b18a commit 7ebee7d

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

src/plots/plots.js

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,42 +1053,25 @@ plots.supplyTransformDefaults = function(traceIn, traceOut, layout) {
10531053
};
10541054

10551055
function applyTransforms(fullTrace, fullData, layout, fullLayout) {
1056-
var dataOut = [];
1056+
var container = fullTrace.transforms,
1057+
dataOut = [fullTrace];
10571058

1058-
// Takes single trace, returns list of expanded traces
1059-
function recurse(trace, transformIndex) {
1060-
var transformedTraces = [trace];
1061-
var transform = trace.transforms[transformIndex];
1062-
var _module = transformsRegistry[transform.type];
1059+
for(var i = 0; i < container.length; i++) {
1060+
var transform = container[i],
1061+
_module = transformsRegistry[transform.type];
10631062

10641063
if(_module && _module.transform) {
1065-
transformedTraces = _module.transform([trace], {
1064+
dataOut = _module.transform(dataOut, {
10661065
transform: transform,
1067-
fullTrace: trace,
1066+
fullTrace: fullTrace,
10681067
fullData: fullData,
10691068
layout: layout,
10701069
fullLayout: fullLayout,
1071-
transformIndex: transformIndex
1070+
transformIndex: i
10721071
});
10731072
}
1074-
1075-
for(var i = 0; i < transformedTraces.length; i++) {
1076-
if(transformIndex >= transformedTraces[i].transforms.length - 1) {
1077-
// If we get here, we've reached the end of the line and this expanded
1078-
// trace has no more transforms to apply. That is, it's an output trace
1079-
// so we push it onto dataOut.
1080-
dataOut.push(transformedTraces[i]);
1081-
} else {
1082-
// Otherwise there are more transforms to be performed. We don't need
1083-
// to worry about the return value since every transform will eventually
1084-
// reach the end of the line and push its result onto the output.
1085-
recurse(transformedTraces[i], transformIndex + 1);
1086-
}
1087-
}
10881073
}
10891074

1090-
recurse(fullTrace, 0);
1091-
10921075
return dataOut;
10931076
}
10941077

test/jasmine/tests/transform_multi_test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,4 +815,28 @@ describe('supplyDefaults with groupby + filter', function() {
815815
expect(out[1].x).toEqual([4, 5, 6]);
816816
expect(out[1].y).toEqual([7, 6, 8]);
817817
});
818+
819+
it('computes the correct data when groupby + groupby', function() {
820+
var out = _transform([{
821+
x: [1, 2, 3, 4, 5, 6, 7, 8],
822+
y: [4, 6, 5, 7, 6, 8, 9, 10],
823+
transforms: [{
824+
type: 'groupby',
825+
groups: [1, 1, 1, 1, 2, 2, 2, 2]
826+
}, {
827+
type: 'groupby',
828+
groups: [3, 4, 3, 4, 3, 4, 3, 5],
829+
}]
830+
}]);
831+
// | | | | | | | |
832+
// v v v v v v v v
833+
// Trace number: 0 1 0 1 2 3 2 4
834+
835+
expect(out.length).toEqual(5);
836+
expect(out[0].x).toEqual([1, 3]);
837+
expect(out[1].x).toEqual([2, 4]);
838+
expect(out[2].x).toEqual([5, 7]);
839+
expect(out[3].x).toEqual([6]);
840+
expect(out[4].x).toEqual([8]);
841+
});
818842
});

0 commit comments

Comments
 (0)