Skip to content

Convert typed array to 'regular' arrays before sendToCloud #2995

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

Merged
merged 1 commit into from
Sep 11, 2018
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
4 changes: 4 additions & 0 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,10 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
return d.map(stripObj);
}

if(Lib.isTypedArray(d)) {
return Lib.simpleMap(d, Lib.identity);
}

// convert native dates to date strings...
// mostly for external users exporting to plotly
if(Lib.isJSDate(d)) return Lib.ms2DateTimeLocal(+d);
Expand Down
45 changes: 40 additions & 5 deletions test/jasmine/tests/plots_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,13 @@ describe('Test Plots', function() {
});

describe('Plots.graphJson', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);

it('should serialize data, layout and frames', function(done) {
var mock = {
Expand Down Expand Up @@ -533,7 +540,7 @@ describe('Test Plots', function() {
}]
};

Plotly.plot(createGraphDiv(), mock).then(function(gd) {
Plotly.plot(gd, mock).then(function() {
var str = Plots.graphJson(gd, false, 'keepdata');
var obj = JSON.parse(str);

Expand All @@ -547,10 +554,38 @@ describe('Test Plots', function() {
name: 'garbage'
});
})
.then(function() {
destroyGraphDiv();
done();
});
.catch(failTest)
.then(done);
});

it('should convert typed arrays to regular arrays', function(done) {
var trace = {
x: new Float32Array([1, 2, 3]),
y: new Float32Array([1, 2, 1]),
marker: {
size: new Float32Array([20, 30, 10]),
color: new Float32Array([10, 30, 20]),
cmin: 10,
cmax: 30,
colorscale: [
[0, 'rgb(255, 0, 0)'],
[0.5, 'rgb(0, 255, 0)'],
[1, 'rgb(0, 0, 255)']
]
}
};

Plotly.plot(gd, [trace]).then(function() {
var str = Plots.graphJson(gd, false, 'keepdata');
var obj = JSON.parse(str);

expect(obj.data[0].x).toEqual([1, 2, 3]);
expect(obj.data[0].y).toEqual([1, 2, 1]);
expect(obj.data[0].marker.size).toEqual([20, 30, 10]);
expect(obj.data[0].marker.color).toEqual([10, 30, 20]);
})
.catch(failTest)
.then(done);
});
});

Expand Down