Skip to content

Commit 8105955

Browse files
committed
jasmine test case for pointcloud
1 parent 8a09ccd commit 8105955

File tree

3 files changed

+219
-1
lines changed

3 files changed

+219
-1
lines changed

src/traces/pointcloud/convert.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var AXES = ['xaxis', 'yaxis'];
1818
function Pointcloud(scene, uid) {
1919
this.scene = scene;
2020
this.uid = uid;
21+
this.type = 'pointcloud';
2122

2223
this.pickXData = [];
2324
this.pickYData = [];

test/jasmine/karma.ciconf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function func(config) {
2222
func.defaultConfig.exclude = [
2323
'tests/gl_plot_interact_test.js',
2424
'tests/gl_plot_interact_basic_test.js',
25-
'tests/gl2d_scatterplot_contour_test.js'
25+
'tests/gl2d_scatterplot_contour_test.js',
26+
'tests/gl2d_pointcloud_test.js'
2627
];
2728

2829
// if true, Karma captures browsers, runs the tests and exits
+216
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
'use strict';
2+
3+
var Plotly = require('@lib/index');
4+
5+
// pointcloud is not part of the dist plotly.js bundle initially
6+
Plotly.register([
7+
require('@lib/pointcloud')
8+
]);
9+
10+
// Test utilities
11+
var createGraphDiv = require('../assets/create_graph_div');
12+
var destroyGraphDiv = require('../assets/destroy_graph_div');
13+
var failTest = require('../assets/fail_test');
14+
15+
var plotData = {
16+
'data': [
17+
{
18+
'type': 'pointcloud',
19+
'mode': 'markers',
20+
'marker': {
21+
'sizemin': 0.5,
22+
'sizemax': 100,
23+
'arearatio': 0,
24+
'color': 'rgba(255, 0, 0, 0.6)'
25+
},
26+
'x': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
27+
'y': [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
28+
},
29+
{
30+
'type': 'pointcloud',
31+
'mode': 'markers',
32+
'marker': {
33+
'sizemin': 0.5,
34+
'sizemax': 100,
35+
'arearatio': 0,
36+
'color': 'rgba(0, 0, 255, 0.9)',
37+
'opacity': 0.8,
38+
'blend': true
39+
},
40+
'opacity': 0.7,
41+
'x': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
42+
'y': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
43+
},
44+
{
45+
'type': 'pointcloud',
46+
'mode': 'markers',
47+
'marker': {
48+
'sizemin': 0.5,
49+
'sizemax': 100,
50+
'border': {
51+
'color': 'rgb(0, 0, 0)',
52+
'arearatio': 0.7071
53+
},
54+
'color': 'green',
55+
'opacity': 0.8,
56+
'blend': true
57+
},
58+
'opacity': 0.7,
59+
'x': [3, 4.5, 6],
60+
'y': [9, 9, 9]
61+
},
62+
{
63+
'type': 'pointcloud',
64+
'mode': 'markers',
65+
'marker': {
66+
'sizemin': 0.5,
67+
'sizemax': 100,
68+
'color': 'yellow',
69+
'opacity': 0.8,
70+
'blend': true
71+
},
72+
'opacity': 0.7,
73+
'xy': new Float32Array([1, 3, 9, 3]),
74+
'indices': new Int32Array([0, 1]),
75+
'xbounds': [1, 9],
76+
'ybounds': [3, 3]
77+
},
78+
{
79+
'type': 'pointcloud',
80+
'mode': 'markers',
81+
'marker': {
82+
'sizemin': 0.5,
83+
'sizemax': 100,
84+
'color': 'orange',
85+
'opacity': 0.8,
86+
'blend': true
87+
},
88+
'opacity': 0.7,
89+
'xy': new Float32Array([1, 4, 9, 4]),
90+
'indices': new Int32Array([0, 1])
91+
},
92+
{
93+
'type': 'pointcloud',
94+
'mode': 'markers',
95+
'marker': {
96+
'sizemin': 0.5,
97+
'sizemax': 100,
98+
'color': 'darkorange',
99+
'opacity': 0.8,
100+
'blend': true
101+
},
102+
'opacity': 0.7,
103+
'xy': new Float32Array([1, 5, 9, 5]),
104+
'xbounds': [1, 9],
105+
'ybounds': [5, 5]
106+
},
107+
{
108+
'type': 'pointcloud',
109+
'mode': 'markers',
110+
'marker': {
111+
'sizemin': 0.5,
112+
'sizemax': 100,
113+
'color': 'red',
114+
'opacity': 0.8,
115+
'blend': true
116+
},
117+
'opacity': 0.7,
118+
'xy': new Float32Array([1, 6, 9, 6])
119+
}
120+
],
121+
'layout': {
122+
'title': 'Point Cloud - basic',
123+
'xaxis': {
124+
'type': 'linear',
125+
'range': [
126+
-2.501411175139456,
127+
43.340777299865266
128+
],
129+
'autorange': true
130+
},
131+
'yaxis': {
132+
'type': 'linear',
133+
'range': [
134+
4,
135+
6
136+
],
137+
'autorange': true
138+
},
139+
'height': 598,
140+
'width': 1080,
141+
'autosize': true,
142+
'showlegend': false
143+
}
144+
};
145+
146+
function makePlot(gd, mock, done) {
147+
return Plotly.plot(gd, mock.data, mock.layout)
148+
.then(null, failTest)
149+
.then(done);
150+
}
151+
152+
describe('contourgl plots', function() {
153+
154+
var gd;
155+
156+
beforeEach(function() {
157+
gd = createGraphDiv();
158+
});
159+
160+
afterEach(function() {
161+
Plotly.purge(gd);
162+
destroyGraphDiv();
163+
});
164+
165+
it('render without raising an error', function(done) {
166+
makePlot(gd, plotData, done);
167+
});
168+
169+
it('should update properly', function(done) {
170+
var mock = plotData;
171+
var scene2d;
172+
173+
var xBaselineMins = [{'val': 0, 'pad': 50}, {'val': 0, 'pad': 50}, {'val': 3, 'pad': 50}, {'val': 1, 'pad': 50}, {'val': 1, 'pad': 50}, {'val': 1, 'pad': 50}, {'val': 1, 'pad': 50}];
174+
var xBaselineMaxes = [{'val': 9, 'pad': 50}, {'val': 9, 'pad': 50}, {'val': 6, 'pad': 50}, {'val': 9, 'pad': 50}, {'val': 9, 'pad': 50}, {'val': 9, 'pad': 50}, {'val': 9, 'pad': 50}];
175+
176+
var yBaselineMins = [{'val': 0, 'pad': 50}, {'val': 0, 'pad': 50}, {'val': 9, 'pad': 50}, {'val': 3, 'pad': 50}, {'val': 4, 'pad': 50}, {'val': 5, 'pad': 50}, {'val': 6, 'pad': 50}];
177+
var yBaselineMaxes = [{'val': 9, 'pad': 50}, {'val': 9, 'pad': 50}, {'val': 9, 'pad': 50}, {'val': 3, 'pad': 50}, {'val': 4, 'pad': 50}, {'val': 5, 'pad': 50}, {'val': 6, 'pad': 50}];
178+
179+
Plotly.plot(gd, mock.data, mock.layout).then(function() {
180+
scene2d = gd._fullLayout._plots.xy._scene2d;
181+
182+
expect(scene2d.traces[mock.data[0].uid].type).toEqual('pointcloud');
183+
184+
expect(scene2d.xaxis._min).toEqual(xBaselineMins);
185+
expect(scene2d.xaxis._max).toEqual(xBaselineMaxes);
186+
187+
expect(scene2d.yaxis._min).toEqual(yBaselineMins);
188+
expect(scene2d.yaxis._max).toEqual(yBaselineMaxes);
189+
190+
return Plotly.relayout(gd, 'xaxis.range', [3, 6]);
191+
}).then(function() {
192+
193+
expect(scene2d.xaxis._min).toEqual(xBaselineMins);
194+
expect(scene2d.xaxis._max).toEqual(xBaselineMaxes);
195+
196+
return Plotly.relayout(gd, 'xaxis.autorange', true);
197+
}).then(function() {
198+
199+
expect(scene2d.xaxis._min).toEqual(xBaselineMins);
200+
expect(scene2d.xaxis._max).toEqual(xBaselineMaxes);
201+
202+
return Plotly.relayout(gd, 'yaxis.range', [8, 20]);
203+
}).then(function() {
204+
205+
expect(scene2d.yaxis._min).toEqual(yBaselineMins);
206+
expect(scene2d.yaxis._max).toEqual(yBaselineMaxes);
207+
208+
return Plotly.relayout(gd, 'yaxis.autorange', true);
209+
}).then(function() {
210+
expect(scene2d.yaxis._min).toEqual(yBaselineMins);
211+
expect(scene2d.yaxis._max).toEqual(yBaselineMaxes);
212+
213+
done();
214+
});
215+
});
216+
});

0 commit comments

Comments
 (0)