@@ -2037,9 +2037,10 @@ plots.didMarginChange = function(margin0, margin1) {
20372037 * keepall: keep data and src
20382038 * @param {String } output If you specify 'object', the result will not be stringified
20392039 * @param {Boolean } useDefaults If truthy, use _fullLayout and _fullData
2040+ * @param {Boolean } includeConfig If truthy, include _context
20402041 * @returns {Object|String }
20412042 */
2042- plots . graphJson = function ( gd , dataonly , mode , output , useDefaults ) {
2043+ plots . graphJson = function ( gd , dataonly , mode , output , useDefaults , includeConfig ) {
20432044 // if the defaults aren't supplied yet, we need to do that...
20442045 if ( ( useDefaults && dataonly && ! gd . _fullData ) ||
20452046 ( useDefaults && ! dataonly && ! gd . _fullLayout ) ) {
@@ -2050,18 +2051,21 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
20502051 var layout = ( useDefaults ) ? gd . _fullLayout : gd . layout ;
20512052 var frames = ( gd . _transitionData || { } ) . _frames ;
20522053
2053- function stripObj ( d ) {
2054+ function stripObj ( d , keepFunction ) {
20542055 if ( typeof d === 'function' ) {
2055- return null ;
2056+ return keepFunction ? '_function_' : null ;
20562057 }
20572058 if ( Lib . isPlainObject ( d ) ) {
20582059 var o = { } ;
20592060 var v , src ;
20602061 for ( v in d ) {
20612062 // remove private elements and functions
20622063 // _ is for private, [ is a mistake ie [object Object]
2063- if ( typeof d [ v ] === 'function' ||
2064- [ '_' , '[' ] . indexOf ( v . charAt ( 0 ) ) !== - 1 ) {
2064+ if ( [ '_' , '[' ] . indexOf ( v . charAt ( 0 ) ) !== - 1 ) continue ;
2065+
2066+ // if a function, add if necessary then move on
2067+ if ( typeof d [ v ] === 'function' ) {
2068+ if ( keepFunction ) o [ v ] = '_function' ;
20652069 continue ;
20662070 }
20672071
@@ -2091,13 +2095,13 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
20912095 }
20922096
20932097 // OK, we're including this... recurse into it
2094- o [ v ] = stripObj ( d [ v ] ) ;
2098+ o [ v ] = stripObj ( d [ v ] , keepFunction ) ;
20952099 }
20962100 return o ;
20972101 }
20982102
20992103 if ( Array . isArray ( d ) ) {
2100- return d . map ( stripObj ) ;
2104+ return d . map ( function ( x ) { return stripObj ( x , keepFunction ) ; } ) ;
21012105 }
21022106
21032107 if ( Lib . isTypedArray ( d ) ) {
@@ -2126,6 +2130,8 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
21262130
21272131 if ( frames ) obj . frames = stripObj ( frames ) ;
21282132
2133+ if ( includeConfig ) obj . config = stripObj ( gd . _context , true ) ;
2134+
21292135 return ( output === 'object' ) ? obj : JSON . stringify ( obj ) ;
21302136} ;
21312137
0 commit comments