@@ -54,6 +54,9 @@ var numericNameWarningCountLimit = 5;
54
54
* all the stuff that doesn't pertain to any individual trace
55
55
* @param {object } config
56
56
* configuration options (see ./plot_config.js for more info)
57
+ * @param {object } dynamicBehavior
58
+ * object containing Javascript functions that mirror the behavior of options
59
+ * in data, layout, and config.
57
60
*
58
61
* OR
59
62
*
@@ -63,7 +66,7 @@ var numericNameWarningCountLimit = 5;
63
66
* object containing `data`, `layout`, `config`, and `frames` members
64
67
*
65
68
*/
66
- function plot ( gd , data , layout , config ) {
69
+ function plot ( gd , data , layout , config , dynamicBehavior ) {
67
70
var frames ;
68
71
69
72
gd = Lib . getGraphDiv ( gd ) ;
@@ -79,7 +82,7 @@ function plot(gd, data, layout, config) {
79
82
frames = obj . frames ;
80
83
}
81
84
82
- var okToPlot = Events . triggerHandler ( gd , 'plotly_beforeplot' , [ data , layout , config ] ) ;
85
+ var okToPlot = Events . triggerHandler ( gd , 'plotly_beforeplot' , [ data , layout , config , dynamicBehavior ] ) ;
83
86
if ( okToPlot === false ) return Promise . reject ( ) ;
84
87
85
88
// if there's no data or layout, and this isn't yet a plotly plot
@@ -88,6 +91,8 @@ function plot(gd, data, layout, config) {
88
91
Lib . warn ( 'Calling Plotly.plot as if redrawing ' +
89
92
'but this container doesn\'t yet have a plot.' , gd ) ;
90
93
}
94
+
95
+ gd . dynamicBehavior = dynamicBehavior || { } ;
91
96
92
97
function addFrames ( ) {
93
98
if ( frames ) {
@@ -97,7 +102,7 @@ function plot(gd, data, layout, config) {
97
102
98
103
// transfer configuration options to gd until we move over to
99
104
// a more OO like model
100
- setPlotContext ( gd , config ) ;
105
+ setPlotContext ( gd , config , dynamicBehavior . config ) ;
101
106
102
107
if ( ! layout ) layout = { } ;
103
108
@@ -136,7 +141,7 @@ function plot(gd, data, layout, config) {
136
141
gd . layout = helpers . cleanLayout ( layout ) ;
137
142
}
138
143
139
- Plots . supplyDefaults ( gd ) ;
144
+ Plots . supplyDefaults ( gd , dynamicBehavior ) ;
140
145
141
146
var fullLayout = gd . _fullLayout ;
142
147
var hasCartesian = fullLayout . _has ( 'cartesian' ) ;
@@ -405,7 +410,7 @@ function opaqueSetBackground(gd, bgColor) {
405
410
setBackground ( gd , blend ) ;
406
411
}
407
412
408
- function setPlotContext ( gd , config ) {
413
+ function setPlotContext ( gd , config , dynamicConfig ) {
409
414
if ( ! gd . _context ) {
410
415
gd . _context = Lib . extendDeep ( { } , dfltConfig ) ;
411
416
@@ -434,6 +439,17 @@ function setPlotContext(gd, config) {
434
439
}
435
440
}
436
441
442
+ if ( dynamicConfig ) {
443
+ keys = Object . keys ( dynamicConfig ) ;
444
+ for ( i = 0 ; i < keys . length ; i ++ ) {
445
+ key = keys [ i ] ;
446
+ // Prefer dynamic functions over static options
447
+ if ( key in context && typeof dynamicConfig [ key ] === 'function' ) {
448
+ context [ key ] = dynamicConfig [ key ] ;
449
+ }
450
+ }
451
+ }
452
+
437
453
// map plot3dPixelRatio to plotGlPixelRatio for backward compatibility
438
454
if ( config . plot3dPixelRatio && ! context . plotGlPixelRatio ) {
439
455
context . plotGlPixelRatio = context . plot3dPixelRatio ;
@@ -631,15 +647,16 @@ function redraw(gd) {
631
647
* @param {Object[] } data
632
648
* @param {Object } layout
633
649
* @param {Object } config
650
+ * @param {Object } dynamicBehavior
634
651
*/
635
- function newPlot ( gd , data , layout , config ) {
652
+ function newPlot ( gd , data , layout , config , dynamicBehavior ) {
636
653
gd = Lib . getGraphDiv ( gd ) ;
637
654
638
655
// remove gl contexts
639
656
Plots . cleanPlot ( [ ] , { } , gd . _fullData || [ ] , gd . _fullLayout || { } ) ;
640
657
641
658
Plots . purge ( gd ) ;
642
- return exports . plot ( gd , data , layout , config ) ;
659
+ return exports . plot ( gd , data , layout , config , dynamicBehavior ) ;
643
660
}
644
661
645
662
/**
@@ -2338,6 +2355,8 @@ function update(gd, traceUpdate, layoutUpdate, _traces) {
2338
2355
gd = Lib . getGraphDiv ( gd ) ;
2339
2356
helpers . clearPromiseQueue ( gd ) ;
2340
2357
2358
+ var dynamicBehavior = gd . dynamicBehavior ;
2359
+
2341
2360
if ( gd . framework && gd . framework . isPolar ) {
2342
2361
return Promise . resolve ( gd ) ;
2343
2362
}
@@ -2371,7 +2390,7 @@ function update(gd, traceUpdate, layoutUpdate, _traces) {
2371
2390
seq . push ( exports . plot ) ;
2372
2391
} else {
2373
2392
seq . push ( Plots . previousPromises ) ;
2374
- axRangeSupplyDefaultsByPass ( gd , relayoutFlags , relayoutSpecs ) || Plots . supplyDefaults ( gd ) ;
2393
+ axRangeSupplyDefaultsByPass ( gd , relayoutFlags , relayoutSpecs ) || Plots . supplyDefaults ( gd , dynamicBehavior ) ;
2375
2394
2376
2395
if ( restyleFlags . style ) seq . push ( subroutines . doTraceStyle ) ;
2377
2396
if ( restyleFlags . colorbars || relayoutFlags . colorbars ) seq . push ( subroutines . doColorBars ) ;
0 commit comments