@@ -28,6 +28,7 @@ var ErrorBars = require('../components/errorbars');
2828var xmlnsNamespaces = require ( '../constants/xmlns_namespaces' ) ;
2929var svgTextUtils = require ( '../lib/svg_text_utils' ) ;
3030
31+ var defaultConfig = require ( './plot_config' ) ;
3132var helpers = require ( './helpers' ) ;
3233var subroutines = require ( './subroutines' ) ;
3334
@@ -80,6 +81,7 @@ Plotly.plot = function(gd, data, layout, config) {
8081
8182 // transfer configuration options to gd until we move over to
8283 // a more OO like model
84+
8385 setPlotContext ( gd , config ) ;
8486
8587 if ( ! layout ) layout = { } ;
@@ -363,32 +365,49 @@ Plotly.plot = function(gd, data, layout, config) {
363365 } ) ;
364366} ;
365367
366-
367368function opaqueSetBackground ( gd , bgColor ) {
368369 gd . _fullLayout . _paperdiv . style ( 'background' , 'white' ) ;
369- Plotly . defaultConfig . setBackground ( gd , bgColor ) ;
370+ defaultConfig . setBackground . dflt ( gd , bgColor ) ;
370371}
371372
372373function setPlotContext ( gd , config ) {
373- if ( ! gd . _context ) gd . _context = Lib . extendFlat ( { } , Plotly . defaultConfig ) ;
374- var context = gd . _context ;
374+ var keys , i ;
375375
376- if ( config ) {
377- Object . keys ( config ) . forEach ( function ( key ) {
378- if ( key in context ) {
379- if ( key === 'setBackground' && config [ key ] === 'opaque' ) {
380- context [ key ] = opaqueSetBackground ;
381- }
382- else context [ key ] = config [ key ] ;
383- }
384- } ) ;
376+ if ( ! gd . _context ) {
377+ gd . _context = { } ;
378+ keys = Object . keys ( defaultConfig ) ;
385379
386- // map plot3dPixelRatio to plotGlPixelRatio for backward compatibility
387- if ( config . plot3dPixelRatio && ! context . plotGlPixelRatio ) {
388- context . plotGlPixelRatio = context . plot3dPixelRatio ;
380+ // init context
381+ for ( i = 0 ; i < keys . length ; i ++ ) {
382+ var k = keys [ i ] ;
383+ gd . _context [ k ] = defaultConfig [ k ] . dflt ;
389384 }
390385 }
391386
387+ var context = gd . _context ;
388+
389+ config = Lib . isPlainObject ( config ) ? config : { } ;
390+ keys = Object . keys ( config ) ;
391+
392+ function coerce ( key , dflt ) {
393+ return Lib . coerce ( config , context , defaultConfig , key , dflt ) ;
394+ }
395+
396+ // extend context with config
397+ for ( i = 0 ; i < keys . length ; i ++ ) {
398+ coerce ( keys [ i ] ) ;
399+ }
400+
401+ // 'opaque' is special value for setBackground
402+ if ( config . setBackground === 'opaque' ) {
403+ context . setBackground = opaqueSetBackground ;
404+ }
405+
406+ // map plot3dPixelRatio to plotGlPixelRatio for backward compatibility
407+ if ( config . plot3dPixelRatio && ! context . plotGlPixelRatio ) {
408+ context . plotGlPixelRatio = context . plot3dPixelRatio ;
409+ }
410+
392411 // staticPlot forces a bunch of others:
393412 if ( context . staticPlot ) {
394413 context . editable = false ;
0 commit comments