@@ -30,6 +30,9 @@ exports.valObjects = {
30
30
coerceFunction : function ( v , propOut , dflt ) {
31
31
if ( Array . isArray ( v ) ) propOut . set ( v ) ;
32
32
else if ( dflt !== undefined ) propOut . set ( dflt ) ;
33
+ } ,
34
+ isValidFunction : function ( v ) {
35
+ return Array . isArray ( v ) ;
33
36
}
34
37
} ,
35
38
enumerated : {
@@ -43,6 +46,10 @@ exports.valObjects = {
43
46
if ( opts . coerceNumber ) v = + v ;
44
47
if ( opts . values . indexOf ( v ) === - 1 ) propOut . set ( dflt ) ;
45
48
else propOut . set ( v ) ;
49
+ } ,
50
+ isValidFunction : function ( v , opts ) {
51
+ if ( opts . coerceNumber ) v = + v ;
52
+ return ( opts . values . indexOf ( v ) !== - 1 ) ;
46
53
}
47
54
} ,
48
55
'boolean' : {
@@ -52,6 +59,9 @@ exports.valObjects = {
52
59
coerceFunction : function ( v , propOut , dflt ) {
53
60
if ( v === true || v === false ) propOut . set ( v ) ;
54
61
else propOut . set ( dflt ) ;
62
+ } ,
63
+ isValidFunction : function ( v ) {
64
+ return typeof v === 'boolean' ;
55
65
}
56
66
} ,
57
67
number : {
@@ -70,6 +80,13 @@ exports.valObjects = {
70
80
propOut . set ( dflt ) ;
71
81
}
72
82
else propOut . set ( + v ) ;
83
+ } ,
84
+ isValidFunction : function ( v , opts ) {
85
+ return (
86
+ isNumeric ( v ) &&
87
+ ( v > opts . min || - Infinity ) &&
88
+ ( v < opts . max || Infinity )
89
+ ) ;
73
90
}
74
91
} ,
75
92
integer : {
@@ -87,6 +104,14 @@ exports.valObjects = {
87
104
propOut . set ( dflt ) ;
88
105
}
89
106
else propOut . set ( + v ) ;
107
+ } ,
108
+ isValidFunction : function ( v , opts ) {
109
+ return (
110
+ ( v % 1 === 0 ) &&
111
+ isNumeric ( v ) &&
112
+ ( v > opts . min || - Infinity ) ||
113
+ ( v < opts . max || Infinity )
114
+ ) ;
90
115
}
91
116
} ,
92
117
string : {
@@ -109,6 +134,11 @@ exports.valObjects = {
109
134
propOut . set ( dflt ) ;
110
135
}
111
136
else propOut . set ( s ) ;
137
+ } ,
138
+ isValidFunction : function ( v , opts ) {
139
+ if ( opts . strict === true && typeof v !== 'string' ) return false ;
140
+ if ( v === undefined || ( opts . noBlank === true && ! String ( v ) ) ) return false ;
141
+ return true ;
112
142
}
113
143
} ,
114
144
color : {
@@ -127,6 +157,9 @@ exports.valObjects = {
127
157
coerceFunction : function ( v , propOut , dflt ) {
128
158
if ( tinycolor ( v ) . isValid ( ) ) propOut . set ( v ) ;
129
159
else propOut . set ( dflt ) ;
160
+ } ,
161
+ isValidFunction : function ( v ) {
162
+ return tinycolor ( v ) . isValid ( ) ;
130
163
}
131
164
} ,
132
165
colorscale : {
@@ -142,6 +175,9 @@ exports.valObjects = {
142
175
otherOpts : [ 'dflt' ] ,
143
176
coerceFunction : function ( v , propOut , dflt ) {
144
177
propOut . set ( getColorscale ( v , dflt ) ) ;
178
+ } ,
179
+ isValidFunction : function ( ) {
180
+ return true ; // TODO be more strict
145
181
}
146
182
} ,
147
183
angle : {
@@ -157,6 +193,9 @@ exports.valObjects = {
157
193
if ( Math . abs ( v ) > 180 ) v -= Math . round ( v / 360 ) * 360 ;
158
194
propOut . set ( + v ) ;
159
195
}
196
+ } ,
197
+ isValidFunction : function ( ) {
198
+ return true ;
160
199
}
161
200
} ,
162
201
subplotid : {
@@ -175,6 +214,9 @@ exports.valObjects = {
175
214
return ;
176
215
}
177
216
propOut . set ( dflt ) ;
217
+ } ,
218
+ isValidFunction : function ( ) {
219
+ return true ;
178
220
}
179
221
} ,
180
222
flaglist : {
@@ -207,6 +249,9 @@ exports.valObjects = {
207
249
}
208
250
if ( ! vParts . length ) propOut . set ( dflt ) ;
209
251
else propOut . set ( vParts . join ( '+' ) ) ;
252
+ } ,
253
+ isValidFunction : function ( ) {
254
+ return true ; // TODO
210
255
}
211
256
} ,
212
257
any : {
@@ -216,6 +261,9 @@ exports.valObjects = {
216
261
coerceFunction : function ( v , propOut , dflt ) {
217
262
if ( v === undefined ) propOut . set ( dflt ) ;
218
263
else propOut . set ( v ) ;
264
+ } ,
265
+ isValidFunction : function ( v ) {
266
+ return ( v !== undefined ) ;
219
267
}
220
268
} ,
221
269
info_array : {
@@ -239,6 +287,9 @@ exports.valObjects = {
239
287
}
240
288
241
289
propOut . set ( vOut ) ;
290
+ } ,
291
+ isValidFunction : function ( ) {
292
+ return true ; // TODO
242
293
}
243
294
}
244
295
} ;
@@ -309,3 +360,15 @@ exports.coerceFont = function(coerce, attr, dfltObj) {
309
360
310
361
return out ;
311
362
} ;
363
+
364
+ exports . isValid = function ( containerIn , attributes , attribute ) {
365
+ var opts = nestedProperty ( attributes , attribute ) . get ( ) ,
366
+ propIn = nestedProperty ( containerIn , attribute ) ,
367
+ v = propIn . get ( ) ;
368
+
369
+ if ( opts . arrayOk && Array . isArray ( v ) ) return true ;
370
+
371
+ var out = exports . valObjects [ opts . valType ] . isValidFunction ( v , opts ) ;
372
+
373
+ return out ;
374
+ } ;
0 commit comments