@@ -2037,9 +2037,10 @@ plots.didMarginChange = function(margin0, margin1) {
2037
2037
* keepall: keep data and src
2038
2038
* @param {String } output If you specify 'object', the result will not be stringified
2039
2039
* @param {Boolean } useDefaults If truthy, use _fullLayout and _fullData
2040
+ * @param {Boolean } includeConfig If truthy, include _context
2040
2041
* @returns {Object|String }
2041
2042
*/
2042
- plots . graphJson = function ( gd , dataonly , mode , output , useDefaults ) {
2043
+ plots . graphJson = function ( gd , dataonly , mode , output , useDefaults , includeConfig ) {
2043
2044
// if the defaults aren't supplied yet, we need to do that...
2044
2045
if ( ( useDefaults && dataonly && ! gd . _fullData ) ||
2045
2046
( useDefaults && ! dataonly && ! gd . _fullLayout ) ) {
@@ -2050,18 +2051,20 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
2050
2051
var layout = ( useDefaults ) ? gd . _fullLayout : gd . layout ;
2051
2052
var frames = ( gd . _transitionData || { } ) . _frames ;
2052
2053
2053
- function stripObj ( d ) {
2054
+ function stripObj ( d , keepFunction ) {
2054
2055
if ( typeof d === 'function' ) {
2055
- return null ;
2056
+ return keepFunction ? '_function_' : null ;
2056
2057
}
2057
2058
if ( Lib . isPlainObject ( d ) ) {
2058
2059
var o = { } ;
2059
2060
var v , src ;
2060
2061
for ( v in d ) {
2061
2062
// remove private elements and functions
2062
2063
// _ 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 ( keepFunction && typeof d [ v ] === 'function' ) {
2067
+ o [ v ] = '_function' ;
2065
2068
continue ;
2066
2069
}
2067
2070
@@ -2091,13 +2094,13 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
2091
2094
}
2092
2095
2093
2096
// OK, we're including this... recurse into it
2094
- o [ v ] = stripObj ( d [ v ] ) ;
2097
+ o [ v ] = stripObj ( d [ v ] , keepFunction ) ;
2095
2098
}
2096
2099
return o ;
2097
2100
}
2098
2101
2099
2102
if ( Array . isArray ( d ) ) {
2100
- return d . map ( stripObj ) ;
2103
+ return d . map ( function ( x ) { return stripObj ( x , keepFunction ) ; } ) ;
2101
2104
}
2102
2105
2103
2106
if ( Lib . isTypedArray ( d ) ) {
@@ -2126,6 +2129,8 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
2126
2129
2127
2130
if ( frames ) obj . frames = stripObj ( frames ) ;
2128
2131
2132
+ if ( includeConfig ) obj . config = stripObj ( gd . _context , true ) ;
2133
+
2129
2134
return ( output === 'object' ) ? obj : JSON . stringify ( obj ) ;
2130
2135
} ;
2131
2136
0 commit comments