@@ -3,55 +3,225 @@ var createGraphDiv = require('../assets/create_graph_div');
33var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
44var failTest = require ( '../assets/fail_test' ) ;
55
6- describe ( 'Test mesh3d restyle' , function ( ) {
7- afterEach ( destroyGraphDiv ) ;
8-
9- it ( 'should clear *cauto* when restyle *cmin* and/or *cmax*' , function ( done ) {
10- var gd = createGraphDiv ( ) ;
11-
12- function _assert ( user , full ) {
13- var trace = gd . data [ 0 ] ;
14- var fullTrace = gd . _fullData [ 0 ] ;
15-
16- expect ( trace . cauto ) . toBe ( user [ 0 ] , 'user cauto' ) ;
17- expect ( trace . cmin ) . toBe ( user [ 1 ] , 'user cmin' ) ;
18- expect ( trace . cmax ) . toBe ( user [ 2 ] , 'user cmax' ) ;
19- expect ( fullTrace . cauto ) . toBe ( full [ 0 ] , 'full cauto' ) ;
20- expect ( fullTrace . cmin ) . toBe ( full [ 1 ] , 'full cmin' ) ;
21- expect ( fullTrace . cmax ) . toBe ( full [ 2 ] , 'full cmax' ) ;
6+ describe ( 'Test mesh3d' , function ( ) {
7+ 'use strict' ;
8+
9+ describe ( 'restyle' , function ( ) {
10+ afterEach ( destroyGraphDiv ) ;
11+
12+ it ( 'should clear *cauto* when restyle *cmin* and/or *cmax*' , function ( done ) {
13+ var gd = createGraphDiv ( ) ;
14+
15+ function _assert ( user , full ) {
16+ var trace = gd . data [ 0 ] ;
17+ var fullTrace = gd . _fullData [ 0 ] ;
18+
19+ expect ( trace . cauto ) . toBe ( user [ 0 ] , 'user cauto' ) ;
20+ expect ( trace . cmin ) . toBe ( user [ 1 ] , 'user cmin' ) ;
21+ expect ( trace . cmax ) . toBe ( user [ 2 ] , 'user cmax' ) ;
22+ expect ( fullTrace . cauto ) . toBe ( full [ 0 ] , 'full cauto' ) ;
23+ expect ( fullTrace . cmin ) . toBe ( full [ 1 ] , 'full cmin' ) ;
24+ expect ( fullTrace . cmax ) . toBe ( full [ 2 ] , 'full cmax' ) ;
25+ }
26+
27+ Plotly . plot ( gd , [ {
28+ type : 'mesh3d' ,
29+ x : [ 0 , 1 , 2 , 0 ] ,
30+ y : [ 0 , 0 , 1 , 2 ] ,
31+ z : [ 0 , 2 , 0 , 1 ] ,
32+ i : [ 0 , 0 , 0 , 1 ] ,
33+ j : [ 1 , 2 , 3 , 2 ] ,
34+ k : [ 2 , 3 , 1 , 3 ] ,
35+ intensity : [ 0 , 0.33 , 0.66 , 3 ]
36+ } ] )
37+ . then ( function ( ) {
38+ _assert ( [ undefined , undefined , undefined ] , [ true , 0 , 3 ] ) ;
39+
40+ return Plotly . restyle ( gd , 'cmin' , 0 ) ;
41+ } )
42+ . then ( function ( ) {
43+ _assert ( [ false , 0 , undefined ] , [ false , 0 , 3 ] ) ;
44+
45+ return Plotly . restyle ( gd , 'cmax' , 10 ) ;
46+ } )
47+ . then ( function ( ) {
48+ _assert ( [ false , 0 , 10 ] , [ false , 0 , 10 ] ) ;
49+
50+ return Plotly . restyle ( gd , 'cauto' , true ) ;
51+ } )
52+ . then ( function ( ) {
53+ _assert ( [ true , 0 , 10 ] , [ true , 0 , 3 ] ) ;
54+
55+ return Plotly . purge ( gd ) ;
56+ } )
57+ . catch ( failTest )
58+ . then ( done ) ;
59+ } ) ;
60+ } ) ;
61+
62+ describe ( 'dimension and expected visibility tests' , function ( ) {
63+ var gd ;
64+
65+ beforeEach ( function ( ) {
66+ gd = createGraphDiv ( ) ;
67+ } ) ;
68+
69+ afterEach ( function ( ) {
70+ Plotly . purge ( gd ) ;
71+ destroyGraphDiv ( ) ;
72+ } ) ;
73+
74+ function assertVisibility ( exp , msg ) {
75+ expect ( gd . _fullData [ 0 ] ) . not . toBe ( undefined , 'no visibility!' ) ;
76+ expect ( gd . _fullData [ 0 ] . visible ) . toBe ( exp , msg ) ;
2277 }
2378
24- Plotly . plot ( gd , [ {
25- type : 'mesh3d' ,
26- x : [ 0 , 1 , 2 , 0 ] ,
27- y : [ 0 , 0 , 1 , 2 ] ,
28- z : [ 0 , 2 , 0 , 1 ] ,
29- i : [ 0 , 0 , 0 , 1 ] ,
30- j : [ 1 , 2 , 3 , 2 ] ,
31- k : [ 2 , 3 , 1 , 3 ] ,
32- intensity : [ 0 , 0.33 , 0.66 , 3 ]
33- } ] )
34- . then ( function ( ) {
35- _assert ( [ undefined , undefined , undefined ] , [ true , 0 , 3 ] ) ;
36-
37- return Plotly . restyle ( gd , 'cmin' , 0 ) ;
38- } )
39- . then ( function ( ) {
40- _assert ( [ false , 0 , undefined ] , [ false , 0 , 3 ] ) ;
41-
42- return Plotly . restyle ( gd , 'cmax' , 10 ) ;
43- } )
44- . then ( function ( ) {
45- _assert ( [ false , 0 , 10 ] , [ false , 0 , 10 ] ) ;
46-
47- return Plotly . restyle ( gd , 'cauto' , true ) ;
48- } )
49- . then ( function ( ) {
50- _assert ( [ true , 0 , 10 ] , [ true , 0 , 3 ] ) ;
51-
52- return Plotly . purge ( gd ) ;
53- } )
54- . catch ( failTest )
55- . then ( done ) ;
79+ it ( '@gl mesh3d should be visible when the vertex array are empty' , function ( done ) {
80+ Plotly . plot ( gd , [ {
81+ x : [ ] ,
82+ y : [ ] ,
83+ z : [ ] ,
84+ type : 'mesh3d'
85+ } ] )
86+ . then ( function ( ) {
87+ assertVisibility ( false , 'not to be visible' ) ;
88+ } )
89+ . catch ( failTest )
90+ . then ( done ) ;
91+ } ) ;
92+
93+ it ( '@gl mesh3d should be visible when the index arrays are not provided' , function ( done ) {
94+ Plotly . plot ( gd , [ {
95+ x : [ 0 , 1 , 0.5 , 0.5 ] ,
96+ y : [ 0 , 0.5 , 1 , 0.5 ] ,
97+ z : [ 0 , 0.5 , 0.5 , 1 ] ,
98+ type : 'mesh3d'
99+ } ] )
100+ . then ( function ( ) {
101+ assertVisibility ( false , 'not to be visible' ) ;
102+ } )
103+ . catch ( failTest )
104+ . then ( done ) ;
105+ } ) ;
106+
107+ it ( '@gl mesh3d should be invisible when the indices are not integer' , function ( done ) {
108+ Plotly . plot ( gd , [ {
109+ x : [ 0 , 1 , 0.5 , 0.5 ] ,
110+ y : [ 0 , 0.5 , 1 , 0.5 ] ,
111+ z : [ 0 , 0.5 , 0.5 , 1 ] ,
112+ i : [ 0 , 0 , 0 , 1.00001 ] ,
113+ j : [ 1 , 1 , 2 , 2 ] ,
114+ k : [ 2 , 3 , 3 , 2.99999 ] ,
115+ type : 'mesh3d'
116+ } ] )
117+ . then ( function ( ) {
118+ assertVisibility ( false , 'not to be visible' ) ;
119+ } )
120+ . catch ( failTest )
121+ . then ( done ) ;
122+ } ) ;
123+
124+ it ( '@gl mesh3d should be invisible when the indices are equal or greater than the number of vertices' , function ( done ) {
125+ Plotly . plot ( gd , [ {
126+ x : [ 0 , 1 , 0.5 , 0.5 ] ,
127+ y : [ 0 , 0.5 , 1 , 0.5 ] ,
128+ z : [ 0 , 0.5 , 0.5 , 1 ] ,
129+ i : [ 0 , 0 , 0 , 1 ] ,
130+ j : [ 1 , 1 , 2 , 2 ] ,
131+ k : [ 2 , 3 , 3 , 4 ] ,
132+ type : 'mesh3d'
133+ } ] )
134+ . then ( function ( ) {
135+ assertVisibility ( false , 'not to be visible' ) ;
136+ } )
137+ . catch ( failTest )
138+ . then ( done ) ;
139+ } ) ;
140+
141+ it ( '@gl mesh3d should be invisible when the indices are negative' , function ( done ) {
142+ Plotly . plot ( gd , [ {
143+ x : [ 0 , 1 , 0.5 , 0.5 ] ,
144+ y : [ 0 , 0.5 , 1 , 0.5 ] ,
145+ z : [ 0 , 0.5 , 0.5 , 1 ] ,
146+ i : [ 0 , 0 , 0 , - 1 ] ,
147+ j : [ 1 , 1 , 2 , 2 ] ,
148+ k : [ 2 , 3 , 3 , 3 ] ,
149+ type : 'mesh3d'
150+ } ] )
151+ . then ( function ( ) {
152+ assertVisibility ( false , 'not to be visible' ) ;
153+ } )
154+ . catch ( failTest )
155+ . then ( done ) ;
156+ } ) ;
157+
158+ it ( '@gl mesh3d should be invisible when the indices have different sizes' , function ( done ) {
159+ Plotly . plot ( gd , [ {
160+ x : [ 0 , 1 , 0.5 , 0.5 ] ,
161+ y : [ 0 , 0.5 , 1 , 0.5 ] ,
162+ z : [ 0 , 0.5 , 0.5 , 1 ] ,
163+ i : [ 0 , 0 , 0 , 1 ] ,
164+ j : [ 1 , 1 , 2 ] ,
165+ k : [ 2 , 3 , 3 , 3 ] ,
166+ type : 'mesh3d'
167+ } ] )
168+ . then ( function ( ) {
169+ assertVisibility ( false , 'not to be visible' ) ;
170+ } )
171+ . catch ( failTest )
172+ . then ( done ) ;
173+ } ) ;
174+
175+ it ( '@gl mesh3d should be invisible when the indices of a triangle point to identical vertex twice' , function ( done ) {
176+ Plotly . plot ( gd , [ {
177+ x : [ 0 , 1 , 0.5 , 0.5 ] ,
178+ y : [ 0 , 0.5 , 1 , 0.5 ] ,
179+ z : [ 0 , 0.5 , 0.5 , 1 ] ,
180+ i : [ 0 , 0 , 0 , 1 ] ,
181+ j : [ 1 , 1 , 2 , 3 ] ,
182+ k : [ 2 , 3 , 3 , 3 ] ,
183+ type : 'mesh3d'
184+ } ] )
185+ . then ( function ( ) {
186+ assertVisibility ( false , 'not to be visible' ) ;
187+ } )
188+ . catch ( failTest )
189+ . then ( done ) ;
190+ } ) ;
191+
192+ it ( '@gl mesh3d should be visible when the indices are provided and OK' , function ( done ) {
193+ Plotly . plot ( gd , [ {
194+ x : [ 0 , 1 , 0.5 , 0.5 ] ,
195+ y : [ 0 , 0.5 , 1 , 0.5 ] ,
196+ z : [ 0 , 0.5 , 0.5 , 1 ] ,
197+ i : [ 0 , 0 , 0 , 1 ] ,
198+ j : [ 1 , 1 , 2 , 2 ] ,
199+ k : [ 2 , 3 , 3 , 3 ] ,
200+ type : 'mesh3d'
201+ } ] )
202+ . then ( function ( ) {
203+ assertVisibility ( true , 'to be visible' ) ;
204+ } )
205+ . catch ( failTest )
206+ . then ( done ) ;
207+ } ) ;
208+
209+ it ( '@gl mesh3d should be visible when the index arrays are empty' , function ( done ) {
210+ Plotly . plot ( gd , [ {
211+ x : [ 0 , 1 , 0.5 , 0.5 ] ,
212+ y : [ 0 , 0.5 , 1 , 0.5 ] ,
213+ z : [ 0 , 0.5 , 0.5 , 1 ] ,
214+ i : [ ] ,
215+ j : [ ] ,
216+ k : [ ] ,
217+ type : 'mesh3d'
218+ } ] )
219+ . then ( function ( ) {
220+ assertVisibility ( true , 'to be visible' ) ;
221+ } )
222+ . catch ( failTest )
223+ . then ( done ) ;
224+ } ) ;
56225 } ) ;
226+
57227} ) ;
0 commit comments