Skip to content

Commit 09d37b6

Browse files
committed
some typed array tests
1 parent c0e2f73 commit 09d37b6

File tree

4 files changed

+94
-10
lines changed

4 files changed

+94
-10
lines changed

test/jasmine/tests/heatmap_test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,34 @@ describe('heatmap calc', function() {
449449
[100, 255, 1010]
450450
]);
451451
});
452+
453+
it('should fill in bricks if x/y not given (typed array case)', function() {
454+
var out = _calc({
455+
z: [
456+
new Float32Array([1, 2, 3]),
457+
new Float32Array([3, 1, 2])
458+
]
459+
});
460+
461+
expect(out.x).toBeCloseToArray([-0.5, 0.5, 1.5, 2.5]);
462+
expect(out.y).toBeCloseToArray([-0.5, 0.5, 1.5]);
463+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
464+
});
465+
466+
it('should convert x/y coordinates into bricks (typed array case)', function() {
467+
var out = _calc({
468+
x: new Float32Array([1, 2, 3]),
469+
y: new Float32Array([2, 6]),
470+
z: [
471+
new Float32Array([1, 2, 3]),
472+
new Float32Array([3, 1, 2])
473+
]
474+
});
475+
476+
expect(out.x).toBeCloseToArray([0.5, 1.5, 2.5, 3.5]);
477+
expect(out.y).toBeCloseToArray([0, 4, 8]);
478+
expect(out.z).toBeCloseTo2DArray([[1, 2, 3], [3, 1, 2]]);
479+
});
452480
});
453481

454482
describe('heatmap plot', function() {

test/jasmine/tests/lib_test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,24 @@ describe('Test lib.js:', function() {
652652
expect(cOut).toBe(outObj.b.c);
653653
});
654654

655+
describe('data_array valType', function() {
656+
var attrs = {
657+
d: {valType: 'data_array'}
658+
};
659+
660+
it('should pass ref to out object (plain array case)', function() {
661+
var arr = [1, 2, 3];
662+
out = coerce({d: arr}, {}, attrs, 'd');
663+
expect(out).toBe(arr);
664+
});
665+
666+
it('should pass ref to out object (typed array case)', function() {
667+
var arr = new Float32Array([1, 2, 3]);
668+
out = coerce({d: arr}, {}, attrs, 'd');
669+
expect(out).toBe(arr);
670+
});
671+
});
672+
655673
describe('string valType', function() {
656674
var dflt = 'Jabberwock',
657675
stringAttrs = {

test/jasmine/tests/plot_api_test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,13 @@ describe('Test plot api', function() {
26002600
['text_chart_arrays', require('@mocks/text_chart_arrays.json')],
26012601
['updatemenus', require('@mocks/updatemenus.json')],
26022602
['violins', require('@mocks/violins.json')],
2603-
['world-cals', require('@mocks/world-cals.json')]
2603+
['world-cals', require('@mocks/world-cals.json')],
2604+
['typed arrays', {
2605+
data: [{
2606+
x: new Float32Array([1, 2, 3]),
2607+
y: new Float32Array([1, 2, 1])
2608+
}]
2609+
}]
26042610
];
26052611

26062612
mockList.forEach(function(mockSpec) {

test/jasmine/tests/scatter_test.js

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ var fail = require('../assets/fail_test');
1313
var assertClip = customAssertions.assertClip;
1414
var assertNodeDisplay = customAssertions.assertNodeDisplay;
1515

16+
var getOpacity = function(node) { return Number(node.style.opacity); };
17+
var getFillOpacity = function(node) { return Number(node.style['fill-opacity']); };
18+
var getColor = function(node) { return node.style.fill; };
19+
var getMarkerSize = function(node) {
20+
// find path arc multiply by 2 to get the corresponding marker.size value
21+
// (works for circles only)
22+
return d3.select(node).attr('d').split('A')[1].split(',')[0] * 2;
23+
};
24+
1625
describe('Test scatter', function() {
1726
'use strict';
1827

@@ -757,6 +766,38 @@ describe('end-to-end scatter tests', function() {
757766
.catch(fail)
758767
.then(done);
759768
});
769+
770+
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];
773+
774+
Plotly.newPlot(gd, [{
775+
x: new Float32Array([1, 2, 3]),
776+
y: new Float32Array([1, 2, 1]),
777+
marker: {
778+
size: new Float32Array([20, 30, 10]),
779+
color: new Float32Array([10, 30, 20]),
780+
cmin: 10,
781+
cmax: 30,
782+
colorscale: [
783+
[0, 'rgb(255, 0, 0)'],
784+
[0.5, 'rgb(0, 255, 0)'],
785+
[1, 'rgb(0, 0, 255)']
786+
]
787+
}
788+
}])
789+
.then(function() {
790+
var pts = d3.selectAll('.point');
791+
expect(pts.size()).toBe(3, '# of pts');
792+
793+
pts.each(function(_, i) {
794+
expect(getColor(this)).toBe(colors[i], 'color ' + i);
795+
expect(getMarkerSize(this)).toBe(sizes[i], 'size ' + i);
796+
});
797+
})
798+
.catch(fail)
799+
.then(done);
800+
});
760801
});
761802

762803
describe('scatter hoverPoints', function() {
@@ -860,15 +901,6 @@ describe('Test Scatter.style', function() {
860901
};
861902
}
862903

863-
var getOpacity = function(node) { return Number(node.style.opacity); };
864-
var getFillOpacity = function(node) { return Number(node.style['fill-opacity']); };
865-
var getColor = function(node) { return node.style.fill; };
866-
var getMarkerSize = function(node) {
867-
// find path arc multiply by 2 to get the corresponding marker.size value
868-
// (works for circles only)
869-
return d3.select(node).attr('d').split('A')[1].split(',')[0] * 2;
870-
};
871-
872904
var r = 'rgb(255, 0, 0)';
873905
var g = 'rgb(0, 255, 0)';
874906
var b = 'rgb(0, 0, 255)';

0 commit comments

Comments
 (0)