@@ -13,6 +13,7 @@ var Plotly = require('../plotly');
1313var Registry = require ( '../registry' ) ;
1414var Plots = require ( '../plots/plots' ) ;
1515var Lib = require ( '../lib' ) ;
16+ var crawler = require ( './crawler' ) ;
1617
1718// FIXME polar attribute are not part of Plotly yet
1819var polarAreaAttrs = require ( '../plots/polar/area_attributes' ) ;
@@ -23,13 +24,7 @@ var extendDeep = Lib.extendDeep;
2324var extendDeepAll = Lib . extendDeepAll ;
2425
2526var 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' ;
3328
3429var plotSchema = {
3530 traces : { } ,
@@ -56,23 +51,9 @@ PlotSchema.get = function() {
5651 return plotSchema ;
5752} ;
5853
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 ;
6555
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 ;
7657
7758function getTraceAttributes ( type ) {
7859 var globalAttributes = Plots . attributes ,
@@ -132,13 +113,13 @@ function getLayoutAttributes() {
132113 // FIXME polar layout attributes
133114 layoutAttributes = assignPolarLayoutAttrs ( layoutAttributes ) ;
134115
135- // add IS_SUBPLOT_OBJ attribute
116+ // add crawler. IS_SUBPLOT_OBJ attribute
136117 layoutAttributes = handleSubplotObjs ( layoutAttributes ) ;
137118
138119 layoutAttributes = removeUnderscoreAttrs ( layoutAttributes ) ;
139120 mergeValTypeAndRole ( layoutAttributes ) ;
140121
141- // generate IS_LINKED_TO_ARRAY structure
122+ // generate crawler. IS_LINKED_TO_ARRAY structure
142123 handleLinkedToArray ( layoutAttributes ) ;
143124
144125 plotSchema . layout = { layoutAttributes : layoutAttributes } ;
@@ -159,7 +140,7 @@ function getTransformAttributes(name) {
159140function getDefs ( ) {
160141 plotSchema . defs = {
161142 valObjects : Lib . valObjects ,
162- metaKeys : UNDERSCORE_ATTRS . concat ( [ 'description' , 'role' ] )
143+ metaKeys : crawler . UNDERSCORE_ATTRS . concat ( [ 'description' , 'role' ] )
163144 } ;
164145}
165146
@@ -242,7 +223,7 @@ function mergeValTypeAndRole(attrs) {
242223 }
243224 }
244225
245- PlotSchema . crawl ( attrs , callback ) ;
226+ crawler . crawl ( attrs , callback ) ;
246227}
247228
248229// helper methods
@@ -268,7 +249,7 @@ function getModule(arg) {
268249function removeUnderscoreAttrs ( attributes ) {
269250 Object . keys ( attributes ) . forEach ( function ( k ) {
270251 if ( k . charAt ( 0 ) === '_' &&
271- UNDERSCORE_ATTRS . indexOf ( k ) === - 1 ) delete attributes [ k ] ;
252+ crawler . UNDERSCORE_ATTRS . indexOf ( k ) === - 1 ) delete attributes [ k ] ;
272253 } ) ;
273254 return attributes ;
274255}
@@ -322,7 +303,7 @@ function handleSubplotObjs(layoutAttributes) {
322303 isSubplotObj = subplotRegistry . attrRegex . test ( k ) ;
323304 }
324305
325- if ( isSubplotObj ) layoutAttributes [ k ] [ IS_SUBPLOT_OBJ ] = true ;
306+ if ( isSubplotObj ) layoutAttributes [ k ] [ crawler . IS_SUBPLOT_OBJ ] = true ;
326307 } ) ;
327308 } ) ;
328309
@@ -332,17 +313,17 @@ function handleSubplotObjs(layoutAttributes) {
332313function handleLinkedToArray ( layoutAttributes ) {
333314
334315 function callback ( attr , attrName , attrs ) {
335- if ( attr [ IS_LINKED_TO_ARRAY ] !== true ) return ;
316+ if ( attr [ crawler . IS_LINKED_TO_ARRAY ] !== true ) return ;
336317
337318 // TODO more robust logic
338319 var itemName = attrName . substr ( 0 , attrName . length - 1 ) ;
339320
340- delete attr [ IS_LINKED_TO_ARRAY ] ;
321+ delete attr [ crawler . IS_LINKED_TO_ARRAY ] ;
341322
342323 attrs [ attrName ] = { items : { } } ;
343324 attrs [ attrName ] . items [ itemName ] = attr ;
344325 attrs [ attrName ] . role = 'object' ;
345326 }
346327
347- PlotSchema . crawl ( layoutAttributes , callback ) ;
328+ crawler . crawl ( layoutAttributes , callback ) ;
348329}
0 commit comments