@@ -13,6 +13,7 @@ var Plotly = require('../plotly');
13
13
var Registry = require ( '../registry' ) ;
14
14
var Plots = require ( '../plots/plots' ) ;
15
15
var Lib = require ( '../lib' ) ;
16
+ var crawler = require ( './crawler' ) ;
16
17
17
18
// FIXME polar attribute are not part of Plotly yet
18
19
var polarAreaAttrs = require ( '../plots/polar/area_attributes' ) ;
@@ -23,13 +24,7 @@ var extendDeep = Lib.extendDeep;
23
24
var extendDeepAll = Lib . extendDeepAll ;
24
25
25
26
var NESTED_MODULE = '_nestedModules' ,
26
- COMPOSED_MODULE = '_composedModules' ,
27
- IS_SUBPLOT_OBJ = '_isSubplotObj' ,
28
- IS_LINKED_TO_ARRAY = '_isLinkedToArray' ,
29
- DEPRECATED = '_deprecated' ;
30
-
31
- // list of underscore attributes to keep in schema as is
32
- var UNDERSCORE_ATTRS = [ IS_SUBPLOT_OBJ , IS_LINKED_TO_ARRAY , DEPRECATED ] ;
27
+ COMPOSED_MODULE = '_composedModules' ;
33
28
34
29
var plotSchema = {
35
30
traces : { } ,
@@ -56,23 +51,9 @@ PlotSchema.get = function() {
56
51
return plotSchema ;
57
52
} ;
58
53
59
- PlotSchema . crawl = function ( attrs , callback , specifiedLevel ) {
60
- var level = specifiedLevel || 0 ;
61
- Object . keys ( attrs ) . forEach ( function ( attrName ) {
62
- var attr = attrs [ attrName ] ;
63
-
64
- if ( UNDERSCORE_ATTRS . indexOf ( attrName ) !== - 1 ) return ;
54
+ PlotSchema . crawl = crawler . crawl ;
65
55
66
- callback ( attr , attrName , attrs , level ) ;
67
-
68
- if ( PlotSchema . isValObject ( attr ) ) return ;
69
- if ( Lib . isPlainObject ( attr ) ) PlotSchema . crawl ( attr , callback , level + 1 ) ;
70
- } ) ;
71
- } ;
72
-
73
- PlotSchema . isValObject = function ( obj ) {
74
- return obj && obj . valType !== undefined ;
75
- } ;
56
+ PlotSchema . isValObject = Lib . isValObject ;
76
57
77
58
function getTraceAttributes ( type ) {
78
59
var globalAttributes = Plots . attributes ,
@@ -132,13 +113,13 @@ function getLayoutAttributes() {
132
113
// FIXME polar layout attributes
133
114
layoutAttributes = assignPolarLayoutAttrs ( layoutAttributes ) ;
134
115
135
- // add IS_SUBPLOT_OBJ attribute
116
+ // add crawler. IS_SUBPLOT_OBJ attribute
136
117
layoutAttributes = handleSubplotObjs ( layoutAttributes ) ;
137
118
138
119
layoutAttributes = removeUnderscoreAttrs ( layoutAttributes ) ;
139
120
mergeValTypeAndRole ( layoutAttributes ) ;
140
121
141
- // generate IS_LINKED_TO_ARRAY structure
122
+ // generate crawler. IS_LINKED_TO_ARRAY structure
142
123
handleLinkedToArray ( layoutAttributes ) ;
143
124
144
125
plotSchema . layout = { layoutAttributes : layoutAttributes } ;
@@ -159,7 +140,7 @@ function getTransformAttributes(name) {
159
140
function getDefs ( ) {
160
141
plotSchema . defs = {
161
142
valObjects : Lib . valObjects ,
162
- metaKeys : UNDERSCORE_ATTRS . concat ( [ 'description' , 'role' ] )
143
+ metaKeys : crawler . UNDERSCORE_ATTRS . concat ( [ 'description' , 'role' ] )
163
144
} ;
164
145
}
165
146
@@ -242,7 +223,7 @@ function mergeValTypeAndRole(attrs) {
242
223
}
243
224
}
244
225
245
- PlotSchema . crawl ( attrs , callback ) ;
226
+ crawler . crawl ( attrs , callback ) ;
246
227
}
247
228
248
229
// helper methods
@@ -268,7 +249,7 @@ function getModule(arg) {
268
249
function removeUnderscoreAttrs ( attributes ) {
269
250
Object . keys ( attributes ) . forEach ( function ( k ) {
270
251
if ( k . charAt ( 0 ) === '_' &&
271
- UNDERSCORE_ATTRS . indexOf ( k ) === - 1 ) delete attributes [ k ] ;
252
+ crawler . UNDERSCORE_ATTRS . indexOf ( k ) === - 1 ) delete attributes [ k ] ;
272
253
} ) ;
273
254
return attributes ;
274
255
}
@@ -322,7 +303,7 @@ function handleSubplotObjs(layoutAttributes) {
322
303
isSubplotObj = subplotRegistry . attrRegex . test ( k ) ;
323
304
}
324
305
325
- if ( isSubplotObj ) layoutAttributes [ k ] [ IS_SUBPLOT_OBJ ] = true ;
306
+ if ( isSubplotObj ) layoutAttributes [ k ] [ crawler . IS_SUBPLOT_OBJ ] = true ;
326
307
} ) ;
327
308
} ) ;
328
309
@@ -332,17 +313,17 @@ function handleSubplotObjs(layoutAttributes) {
332
313
function handleLinkedToArray ( layoutAttributes ) {
333
314
334
315
function callback ( attr , attrName , attrs ) {
335
- if ( attr [ IS_LINKED_TO_ARRAY ] !== true ) return ;
316
+ if ( attr [ crawler . IS_LINKED_TO_ARRAY ] !== true ) return ;
336
317
337
318
// TODO more robust logic
338
319
var itemName = attrName . substr ( 0 , attrName . length - 1 ) ;
339
320
340
- delete attr [ IS_LINKED_TO_ARRAY ] ;
321
+ delete attr [ crawler . IS_LINKED_TO_ARRAY ] ;
341
322
342
323
attrs [ attrName ] = { items : { } } ;
343
324
attrs [ attrName ] . items [ itemName ] = attr ;
344
325
attrs [ attrName ] . role = 'object' ;
345
326
}
346
327
347
- PlotSchema . crawl ( layoutAttributes , callback ) ;
328
+ crawler . crawl ( layoutAttributes , callback ) ;
348
329
}
0 commit comments