Skip to content

Commit a7ed2c2

Browse files
committed
🔒 Plotly.restyle support for typed arrays
1 parent 09d37b6 commit a7ed2c2

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/plot_api/plot_api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,9 @@ function _restyle(gd, aobj, traces) {
15681568
else {
15691569
if(valObject) {
15701570
// must redo calcdata when restyling array values of arrayOk attributes
1571-
if(valObject.arrayOk && (Array.isArray(newVal) || Array.isArray(oldVal))) {
1571+
if(valObject.arrayOk && (
1572+
Lib.isArrayOrTypedArray(newVal) || Lib.isArrayOrTypedArray(oldVal))
1573+
) {
15721574
flags.calc = true;
15731575
}
15741576
else editTypes.update(flags, valObject);

test/jasmine/tests/scatter_test.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,15 @@ describe('end-to-end scatter tests', function() {
768768
});
769769

770770
it('should work with typed arrays', function(done) {
771-
var colors = ['rgb(255, 0, 0)', 'rgb(0, 0, 255)', 'rgb(0, 255, 0)'];
772-
var sizes = [20, 30, 10];
771+
function _assert(colors, sizes) {
772+
var pts = d3.selectAll('.point');
773+
expect(pts.size()).toBe(3, '# of pts');
774+
775+
pts.each(function(_, i) {
776+
expect(getColor(this)).toBe(colors[i], 'color ' + i);
777+
expect(getMarkerSize(this)).toBe(sizes[i], 'size ' + i);
778+
});
779+
}
773780

774781
Plotly.newPlot(gd, [{
775782
x: new Float32Array([1, 2, 3]),
@@ -787,14 +794,22 @@ describe('end-to-end scatter tests', function() {
787794
}
788795
}])
789796
.then(function() {
790-
var pts = d3.selectAll('.point');
791-
expect(pts.size()).toBe(3, '# of pts');
797+
_assert(
798+
['rgb(255, 0, 0)', 'rgb(0, 0, 255)', 'rgb(0, 255, 0)'],
799+
[20, 30, 10]
800+
);
792801

793-
pts.each(function(_, i) {
794-
expect(getColor(this)).toBe(colors[i], 'color ' + i);
795-
expect(getMarkerSize(this)).toBe(sizes[i], 'size ' + i);
802+
return Plotly.restyle(gd, {
803+
'marker.size': [new Float32Array([40, 30, 20])],
804+
'marker.color': [new Float32Array([20, 30, 10])]
796805
});
797806
})
807+
.then(function() {
808+
_assert(
809+
['rgb(0, 255, 0)', 'rgb(0, 0, 255)', 'rgb(255, 0, 0)'],
810+
[40, 30, 20]
811+
);
812+
})
798813
.catch(fail)
799814
.then(done);
800815
});

0 commit comments

Comments
 (0)