@@ -113,6 +113,65 @@ def _build_mathjax_script(url):
113
113
.format (url = url ))
114
114
115
115
116
+ def _get_jconfig (config ):
117
+ # TODO: The get_config 'source of truth' should
118
+ # really be somewhere other than plotly.plotly
119
+ config = config if config else plotly .plotly .get_config ()
120
+
121
+ configkeys = (
122
+ 'staticPlot' ,
123
+ 'plotlyServerURL' ,
124
+ 'editable' ,
125
+ 'edits' ,
126
+ 'autosizable' ,
127
+ 'queueLength' ,
128
+ 'fillFrame' ,
129
+ 'frameMargins' ,
130
+ 'scrollZoom' ,
131
+ 'doubleClick' ,
132
+ 'showTips' ,
133
+ 'showAxisDragHandles' ,
134
+ 'showAxisRangeEntryBoxes' ,
135
+ 'showLink' ,
136
+ 'sendData' ,
137
+ 'linkText' ,
138
+ 'showSources' ,
139
+ 'displayModeBar' ,
140
+ 'modeBarButtonsToRemove' ,
141
+ 'modeBarButtonsToAdd' ,
142
+ 'modeBarButtons' ,
143
+ 'toImageButtonOptions' ,
144
+ 'displaylogo' ,
145
+ 'plotGlPixelRatio' ,
146
+ 'setBackground' ,
147
+ 'topojsonURL' ,
148
+ 'mapboxAccessToken' ,
149
+ 'logging' ,
150
+ 'globalTransforms' ,
151
+ 'locale' ,
152
+ 'locales' ,
153
+ )
154
+
155
+ clean_config = dict ((k , config [k ]) for k in configkeys if k in config )
156
+
157
+ # TODO: The get_config 'source of truth' should
158
+ # really be somewhere other than plotly.plotly
159
+ plotly_platform_url = plotly .plotly .get_config ().get ('plotly_domain' ,
160
+ 'https://plot.ly' )
161
+
162
+ if (plotly_platform_url != 'https://plot.ly' and
163
+ clean_config ['linkText' ] == 'Export to plot.ly' ):
164
+
165
+ link_domain = plotly_platform_url \
166
+ .replace ('https://' , '' )\
167
+ .replace ('http://' , '' )
168
+ link_text = clean_config ['linkText' ].replace ('plot.ly' , link_domain )
169
+ clean_config ['linkText' ] = link_text
170
+ clean_config ['plotlyServerURL' ] = plotly_platform_url
171
+
172
+ return clean_config
173
+
174
+
116
175
# Build script to set global PlotlyConfig object. This must execute before
117
176
# plotly.js is loaded.
118
177
_window_plotly_config = """\
@@ -271,56 +330,9 @@ def _plot_html(figure_or_data, config, validate, default_width,
271
330
else :
272
331
jframes = None
273
332
274
- configkeys = (
275
- 'staticPlot' ,
276
- 'plotlyServerURL' ,
277
- 'editable' ,
278
- 'edits' ,
279
- 'autosizable' ,
280
- 'queueLength' ,
281
- 'fillFrame' ,
282
- 'frameMargins' ,
283
- 'scrollZoom' ,
284
- 'doubleClick' ,
285
- 'showTips' ,
286
- 'showAxisDragHandles' ,
287
- 'showAxisRangeEntryBoxes' ,
288
- 'showLink' ,
289
- 'sendData' ,
290
- 'linkText' ,
291
- 'showSources' ,
292
- 'displayModeBar' ,
293
- 'modeBarButtonsToRemove' ,
294
- 'modeBarButtonsToAdd' ,
295
- 'modeBarButtons' ,
296
- 'toImageButtonOptions' ,
297
- 'displaylogo' ,
298
- 'plotGlPixelRatio' ,
299
- 'setBackground' ,
300
- 'topojsonURL' ,
301
- 'mapboxAccessToken' ,
302
- 'logging' ,
303
- 'globalTransforms' ,
304
- 'locale' ,
305
- 'locales' ,
306
- )
307
-
308
- config_clean = dict ((k , config [k ]) for k in configkeys if k in config )
309
- jconfig = _json .dumps (config_clean )
310
-
311
- # TODO: The get_config 'source of truth' should
312
- # really be somewhere other than plotly.plotly
333
+ jconfig = _json .dumps (_get_jconfig (config ))
313
334
plotly_platform_url = plotly .plotly .get_config ().get ('plotly_domain' ,
314
335
'https://plot.ly' )
315
- if (plotly_platform_url != 'https://plot.ly' and
316
- config ['linkText' ] == 'Export to plot.ly' ):
317
-
318
- link_domain = plotly_platform_url \
319
- .replace ('https://' , '' )\
320
- .replace ('http://' , '' )
321
- link_text = config ['linkText' ].replace ('plot.ly' , link_domain )
322
- config ['linkText' ] = link_text
323
- jconfig = jconfig .replace ('Export to plot.ly' , link_text )
324
336
325
337
if jframes :
326
338
script = '''
@@ -426,6 +438,8 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
426
438
config .setdefault ('showLink' , show_link )
427
439
config .setdefault ('linkText' , link_text )
428
440
441
+ jconfig = _get_jconfig (config )
442
+
429
443
figure = tools .return_figure_from_figure_or_data (figure_or_data , validate )
430
444
431
445
# Though it can add quite a bit to the display-bundle size, we include
@@ -438,7 +452,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
438
452
frames = _json .loads (_json .dumps (figure .get ('frames' , None ),
439
453
cls = plotly .utils .PlotlyJSONEncoder ))
440
454
441
- fig = {'data' : data , 'layout' : layout }
455
+ fig = {'data' : data , 'layout' : layout , 'config' : jconfig }
442
456
if frames :
443
457
fig ['frames' ] = frames
444
458
0 commit comments