@@ -25,6 +25,7 @@ var editTypes = require('./edit_types');
25
25
26
26
var extendFlat = Lib . extendFlat ;
27
27
var extendDeepAll = Lib . extendDeepAll ;
28
+ var isPlainObject = Lib . isPlainObject ;
28
29
29
30
var IS_SUBPLOT_OBJ = '_isSubplotObj' ;
30
31
var IS_LINKED_TO_ARRAY = '_isLinkedToArray' ;
@@ -140,7 +141,7 @@ exports.crawl = function(attrs, callback, specifiedLevel, attrString) {
140
141
141
142
if ( exports . isValObject ( attr ) ) return ;
142
143
143
- if ( Lib . isPlainObject ( attr ) && attrName !== 'impliedEdits' ) {
144
+ if ( isPlainObject ( attr ) && attrName !== 'impliedEdits' ) {
144
145
exports . crawl ( attr , callback , level + 1 , fullAttrString ) ;
145
146
}
146
147
} ) ;
@@ -387,7 +388,7 @@ function recurseIntoValObject(valObject, parts, i) {
387
388
// the innermost schema item we find.
388
389
for ( ; i < parts . length ; i ++ ) {
389
390
var newValObject = valObject [ parts [ i ] ] ;
390
- if ( Lib . isPlainObject ( newValObject ) ) valObject = newValObject ;
391
+ if ( isPlainObject ( newValObject ) ) valObject = newValObject ;
391
392
else break ;
392
393
393
394
if ( i === parts . length - 1 ) break ;
@@ -565,6 +566,7 @@ function getFramesAttributes() {
565
566
function formatAttributes ( attrs ) {
566
567
mergeValTypeAndRole ( attrs ) ;
567
568
formatArrayContainers ( attrs ) ;
569
+ stringify ( attrs ) ;
568
570
569
571
return attrs ;
570
572
}
@@ -596,7 +598,7 @@ function mergeValTypeAndRole(attrs) {
596
598
attrs [ attrName + 'src' ] = makeSrcAttr ( attrName ) ;
597
599
}
598
600
}
599
- else if ( Lib . isPlainObject ( attr ) ) {
601
+ else if ( isPlainObject ( attr ) ) {
600
602
// all attrs container objects get role 'object'
601
603
attr . role = 'object' ;
602
604
}
@@ -624,6 +626,29 @@ function formatArrayContainers(attrs) {
624
626
exports . crawl ( attrs , callback ) ;
625
627
}
626
628
629
+ // this can take around 10ms and should only be run from PlotSchema.get(),
630
+ // to ensure JSON.stringify(PlotSchema.get()) gives the intended result.
631
+ function stringify ( attrs ) {
632
+ function walk ( attr ) {
633
+ for ( var k in attr ) {
634
+ if ( isPlainObject ( attr [ k ] ) ) {
635
+ walk ( attr [ k ] ) ;
636
+ } else if ( Array . isArray ( attr [ k ] ) ) {
637
+ for ( var i = 0 ; i < attr [ k ] . length ; i ++ ) {
638
+ walk ( attr [ k ] [ i ] ) ;
639
+ }
640
+ } else {
641
+ // as JSON.stringify(/test/) // => {}
642
+ if ( attr [ k ] instanceof RegExp ) {
643
+ attr [ k ] = attr [ k ] . toString ( ) ;
644
+ }
645
+ }
646
+ }
647
+ }
648
+
649
+ walk ( attrs ) ;
650
+ }
651
+
627
652
function assignPolarLayoutAttrs ( layoutAttributes ) {
628
653
extendFlat ( layoutAttributes , {
629
654
radialaxis : polarAxisAttrs . radialaxis ,
0 commit comments