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

Use isArrayOrTypedArray in gl_format_color.js #2596

Merged
merged 1 commit into from
May 1, 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
9 changes: 5 additions & 4 deletions src/lib/gl_format_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var rgba = require('color-normalize');

var Colorscale = require('../components/colorscale');
var colorDflt = require('../components/color/attributes').defaultLine;
var isArrayOrTypedArray = require('./is_array').isArrayOrTypedArray;

var colorDfltRgba = rgba(colorDflt);
var opacityDflt = 1;
Expand All @@ -37,10 +38,10 @@ function validateOpacity(opacityIn) {
}

function formatColor(containerIn, opacityIn, len) {
var colorIn = containerIn.color,
isArrayColorIn = Array.isArray(colorIn),
isArrayOpacityIn = Array.isArray(opacityIn),
colorOut = [];
var colorIn = containerIn.color;
var isArrayColorIn = isArrayOrTypedArray(colorIn);
var isArrayOpacityIn = isArrayOrTypedArray(opacityIn);
var colorOut = [];

var sclFunc, getColor, getOpacity, colori, opacityi;

Expand Down
31 changes: 31 additions & 0 deletions test/jasmine/tests/gl2d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,37 @@ describe('@gl Test gl2d plots', function() {
.catch(fail)
.then(done);
});

it('should work with typed array', function(done) {
Plotly.plot(gd, [{
type: 'scattergl',
mode: 'markers',
x: new Float32Array([1, 2, 3]),
y: new Float32Array([1, 2, 1]),
marker: {
size: 20,
colorscale: [[0, 'gray'], [1, 'red']],
cmin: 0,
cmax: 1,
showscale: true,
color: new Float32Array([0, 0.5, 1.0])
}
}])
.then(function() {
var opts = gd.calcdata[0][0].t._scene.markerOptions[0];

expect(opts.colors).toBeCloseTo2DArray([
[0.5, 0.5, 0.5, 1],
[0.75, 0.25, 0.25, 1],
[1, 0, 0, 1]
]);

expect(opts.positions)
.toBeCloseToArray([1, 1, 2, 2, 3, 1]);
})
.catch(fail)
.then(done);
});
});

describe('Test scattergl autorange:', function() {
Expand Down