Skip to content

Commit

Permalink
Merge pull request #4410 from danieljblinick/support-typed-arrays-for…
Browse files Browse the repository at this point in the history
…-data-transforms-groups

adding support for defining groups in data.transforms.groups using ty…
  • Loading branch information
etpinard authored Dec 9, 2019
2 parents 0be6afd + 56c68bd commit 162afe4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/transforms/groupby.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function transformOne(trace, state) {
var groups = trace.transforms[transformIndex].groups;
var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);

if(!(Array.isArray(groups)) || groups.length === 0) {
if(!(Lib.isArrayOrTypedArray(groups)) || groups.length === 0) {
return [trace];
}

Expand Down
30 changes: 30 additions & 0 deletions test/jasmine/tests/transform_groupby_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ describe('groupby', function() {
}]
}];

var mockDataWithTypedArrayGroups = [{
mode: 'markers',
x: [20, 11, 12, 0, 1, 2, 3],
y: [1, 2, 3, 2, 5, 2, 0],
transforms: [{
type: 'groupby',
groups: new Uint8Array([2, 1, 2, 2, 2, 1, 1]),
styles: [
{target: 1, value: {marker: {color: 'green'}}},
{target: 2, value: {marker: {color: 'black'}}}
]
}]
}];

afterEach(destroyGraphDiv);

it('Plotly.plot should plot the transform traces', function(done) {
Expand Down Expand Up @@ -318,6 +332,22 @@ describe('groupby', function() {
.catch(failTest)
.then(done);
});

it('Plotly.plot should group points properly using typed array', function(done) {
var data = Lib.extendDeep([], mockDataWithTypedArrayGroups);

var gd = createGraphDiv();

Plotly.plot(gd, data).then(function() {
expect(gd._fullData.length).toEqual(2);
expect(gd._fullData[0].x).toEqual([20, 12, 0, 1]);
expect(gd._fullData[0].y).toEqual([1, 3, 2, 5]);
expect(gd._fullData[1].x).toEqual([11, 2, 3]);
expect(gd._fullData[1].y).toEqual([2, 2, 0]);
})
.catch(failTest)
.then(done);
});
});

describe('many-to-many transforms', function() {
Expand Down

0 comments on commit 162afe4

Please sign in to comment.