Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for defining groups in data.transforms.groups using ty… #4410

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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