11
11
12
12
var isNumeric = require ( 'fast-isnumeric' ) ;
13
13
var tinycolor = require ( 'tinycolor2' ) ;
14
- var nestedProperty = require ( './nested_property' ) ;
15
- var isPlainObject = require ( './is_plain_object' ) ;
16
- var filterUnique = require ( './filter_unique' ) ;
17
14
18
15
var getColorscale = require ( '../components/colorscale/get_scale' ) ;
19
16
var colorscaleNames = Object . keys ( require ( '../components/colorscale/scales' ) ) ;
17
+ var nestedProperty = require ( './nested_property' ) ;
20
18
21
- var idRegex = / ^ ( [ 2 - 9 ] | [ 1 - 9 ] [ 0 - 9 ] + ) $ / ;
22
-
23
- function isValObject ( obj ) {
24
- return obj && obj . valType !== undefined ;
25
- }
19
+ var ID_REGEX = / ^ ( [ 2 - 9 ] | [ 1 - 9 ] [ 0 - 9 ] + ) $ / ;
26
20
27
21
exports . valObjects = {
28
22
data_array : {
@@ -174,7 +168,7 @@ exports.valObjects = {
174
168
coerceFunction : function ( v , propOut , dflt ) {
175
169
var dlen = dflt . length ;
176
170
if ( typeof v === 'string' && v . substr ( 0 , dlen ) === dflt &&
177
- idRegex . test ( v . substr ( dlen ) ) ) {
171
+ ID_REGEX . test ( v . substr ( dlen ) ) ) {
178
172
propOut . set ( v ) ;
179
173
return ;
180
174
}
@@ -186,7 +180,7 @@ exports.valObjects = {
186
180
187
181
if ( v === dflt ) return true ;
188
182
if ( typeof v !== 'string' ) return false ;
189
- if ( v . substr ( 0 , dlen ) === dflt && idRegex . test ( v . substr ( dlen ) ) ) {
183
+ if ( v . substr ( 0 , dlen ) === dflt && ID_REGEX . test ( v . substr ( dlen ) ) ) {
190
184
return true ;
191
185
}
192
186
@@ -361,125 +355,3 @@ exports.validate = function(value, opts) {
361
355
valObject . coerceFunction ( value , propMock , failed , opts ) ;
362
356
return out !== failed ;
363
357
} ;
364
-
365
- /*
366
- * returns true for a valid value object and false for tree nodes in the attribute hierarchy
367
- */
368
- exports . isValObject = isValObject ;
369
-
370
- exports . IS_SUBPLOT_OBJ = '_isSubplotObj' ;
371
- exports . IS_LINKED_TO_ARRAY = '_isLinkedToArray' ;
372
- exports . DEPRECATED = '_deprecated' ;
373
-
374
- // list of underscore attributes to keep in schema as is
375
- exports . UNDERSCORE_ATTRS = [ exports . IS_SUBPLOT_OBJ , exports . IS_LINKED_TO_ARRAY , exports . DEPRECATED ] ;
376
-
377
- /**
378
- * Crawl the attribute tree, recursively calling a callback function
379
- *
380
- * @param {object } attrs
381
- * The node of the attribute tree (e.g. the root) from which recursion originates
382
- * @param {Function } callback
383
- * A callback function with the signature:
384
- * @callback callback
385
- * @param {object } attr an attribute
386
- * @param {String } attrName name string
387
- * @param {object[] } attrs all the attributes
388
- * @param {Number } level the recursion level, 0 at the root
389
- * @param {Number } [specifiedLevel]
390
- * The level in the tree, in order to let the callback function detect descend or backtrack,
391
- * typically unsupplied (implied 0), just used by the self-recursive call.
392
- * The necessity arises because the tree traversal is not controlled by callback return values.
393
- * The decision to not use callback return values for controlling tree pruning arose from
394
- * the goal of keeping the crawler backwards compatible. Observe that one of the pruning conditions
395
- * precedes the callback call.
396
- *
397
- * @return {object } transformOut
398
- * copy of transformIn that contains attribute defaults
399
- */
400
- exports . crawl = function ( attrs , callback , specifiedLevel ) {
401
- var level = specifiedLevel || 0 ;
402
- Object . keys ( attrs ) . forEach ( function ( attrName ) {
403
- var attr = attrs [ attrName ] ;
404
-
405
- if ( exports . UNDERSCORE_ATTRS . indexOf ( attrName ) !== - 1 ) return ;
406
-
407
- callback ( attr , attrName , attrs , level ) ;
408
-
409
- if ( isValObject ( attr ) ) return ;
410
- if ( isPlainObject ( attr ) ) exports . crawl ( attr , callback , level + 1 ) ;
411
- } ) ;
412
- } ;
413
-
414
- /**
415
- * Find all data array attributes in a given trace object - including
416
- * `arrayOk` attributes.
417
- *
418
- * @param {object } trace
419
- * full trace object that contains a reference to `_module.attributes`
420
- *
421
- * @return {array } arrayAttributes
422
- * list of array attributes for the given trace
423
- */
424
- exports . findArrayAttributes = function ( trace ) {
425
- var arrayAttributes = [ ] ,
426
- stack = [ ] ;
427
-
428
- /**
429
- * A closure that gathers attribute paths into its enclosed arraySplitAttributes
430
- * Attribute paths are collected iff their leaf node is a splittable attribute
431
- *
432
- * @callback callback
433
- * @param {object } attr an attribute
434
- * @param {String } attrName name string
435
- * @param {object[] } attrs all the attributes
436
- * @param {Number } level the recursion level, 0 at the root
437
- *
438
- * @closureVariable {String[][]} arrayAttributes the set of gathered attributes
439
- * Example of filled closure variable (expected to be initialized to []):
440
- * [["marker","size"],["marker","line","width"],["marker","line","color"]]
441
- */
442
- function callback ( attr , attrName , attrs , level ) {
443
- stack = stack . slice ( 0 , level ) . concat ( [ attrName ] ) ;
444
-
445
- var splittableAttr = attr . valType === 'data_array' || attr . arrayOk === true ;
446
- if ( ! splittableAttr ) return ;
447
-
448
- var astr = toAttrString ( stack ) ;
449
- var val = nestedProperty ( trace , astr ) . get ( ) ;
450
- if ( ! Array . isArray ( val ) ) return ;
451
-
452
- arrayAttributes . push ( astr ) ;
453
- }
454
-
455
- function toAttrString ( stack ) {
456
- return stack . join ( '.' ) ;
457
- }
458
-
459
- exports . crawl ( trace . _module . attributes , callback ) ;
460
-
461
- if ( trace . transforms ) {
462
- var transforms = trace . transforms ;
463
-
464
- for ( var i = 0 ; i < transforms . length ; i ++ ) {
465
- var transform = transforms [ i ] ;
466
-
467
- stack = [ 'transforms[' + i + ']' ] ;
468
- exports . crawl ( transform . _module . attributes , callback , 1 ) ;
469
- }
470
- }
471
-
472
- // Look into the fullInput module attributes for array attributes
473
- // to make sure that 'custom' array attributes are detected.
474
- //
475
- // At the moment, we need this block to make sure that
476
- // ohlc and candlestick 'open', 'high', 'low', 'close' can be
477
- // used with filter ang groupby transforms.
478
- if ( trace . _fullInput ) {
479
- exports . crawl ( trace . _fullInput . _module . attributes , callback ) ;
480
-
481
- arrayAttributes = filterUnique ( arrayAttributes ) ;
482
- }
483
-
484
- return arrayAttributes ;
485
- } ;
0 commit comments