Skip to content

Commit a22c0d5

Browse files
authored
Merge pull request #2596 from plotly/gl-format-typed-array-colors
Use isArrayOrTypedArray in gl_format_color.js
2 parents 2b1713d + 56848a4 commit a22c0d5

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/lib/gl_format_color.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var rgba = require('color-normalize');
1414

1515
var Colorscale = require('../components/colorscale');
1616
var colorDflt = require('../components/color/attributes').defaultLine;
17+
var isArrayOrTypedArray = require('./is_array').isArrayOrTypedArray;
1718

1819
var colorDfltRgba = rgba(colorDflt);
1920
var opacityDflt = 1;
@@ -37,10 +38,10 @@ function validateOpacity(opacityIn) {
3738
}
3839

3940
function formatColor(containerIn, opacityIn, len) {
40-
var colorIn = containerIn.color,
41-
isArrayColorIn = Array.isArray(colorIn),
42-
isArrayOpacityIn = Array.isArray(opacityIn),
43-
colorOut = [];
41+
var colorIn = containerIn.color;
42+
var isArrayColorIn = isArrayOrTypedArray(colorIn);
43+
var isArrayOpacityIn = isArrayOrTypedArray(opacityIn);
44+
var colorOut = [];
4445

4546
var sclFunc, getColor, getOpacity, colori, opacityi;
4647

test/jasmine/tests/gl2d_plot_interact_test.js

+31
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,37 @@ describe('@gl Test gl2d plots', function() {
917917
.catch(fail)
918918
.then(done);
919919
});
920+
921+
it('should work with typed array', function(done) {
922+
Plotly.plot(gd, [{
923+
type: 'scattergl',
924+
mode: 'markers',
925+
x: new Float32Array([1, 2, 3]),
926+
y: new Float32Array([1, 2, 1]),
927+
marker: {
928+
size: 20,
929+
colorscale: [[0, 'gray'], [1, 'red']],
930+
cmin: 0,
931+
cmax: 1,
932+
showscale: true,
933+
color: new Float32Array([0, 0.5, 1.0])
934+
}
935+
}])
936+
.then(function() {
937+
var opts = gd.calcdata[0][0].t._scene.markerOptions[0];
938+
939+
expect(opts.colors).toBeCloseTo2DArray([
940+
[0.5, 0.5, 0.5, 1],
941+
[0.75, 0.25, 0.25, 1],
942+
[1, 0, 0, 1]
943+
]);
944+
945+
expect(opts.positions)
946+
.toBeCloseToArray([1, 1, 2, 2, 3, 1]);
947+
})
948+
.catch(fail)
949+
.then(done);
950+
});
920951
});
921952

922953
describe('Test scattergl autorange:', function() {

0 commit comments

Comments
 (0)