Skip to content

Commit dffa93a

Browse files
authored
Pass configured plotly_domain to FigureWidget as plotlyServerURL config parameter (#1284)
1 parent 579d823 commit dffa93a

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

Diff for: js/src/Figure.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var FigureModel = widgets.DOMWidgetModel.extend({
3636
// messages
3737
_data: [],
3838
_layout: {},
39+
_config: {},
3940

4041
// Python -> JS messages
4142
// ---------------------
@@ -748,8 +749,9 @@ var FigureView = widgets.DOMWidgetView.extend({
748749
// the model is not directly mutated by the Plotly.js library.
749750
var initialTraces = _.cloneDeep(this.model.get("_data"));
750751
var initialLayout = _.cloneDeep(this.model.get("_layout"));
752+
var config = this.model.get("_config");
751753

752-
Plotly.newPlot(that.el, initialTraces, initialLayout).then(
754+
Plotly.newPlot(that.el, initialTraces, initialLayout, config).then(
753755
function () {
754756

755757
// ### Send trace deltas ###

Diff for: plotly/basedatatypes.py

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from copy import deepcopy, copy
1010
from pprint import PrettyPrinter
1111

12+
from plotly.offline.offline import _get_jconfig
1213
from .optional_imports import get_module
1314

1415
from . import offline as pyo
@@ -191,6 +192,16 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
191192
self._layout_obj._orphan_props.clear()
192193
self._layout_obj._parent = self
193194

195+
# Config
196+
# ------
197+
# Pass along default config to the front end. For now this just
198+
# ensures that the plotly domain url gets passed to the front end.
199+
# In the future we can extend this to allow the user to supply
200+
# arbitrary config options like in plotly.offline.plot/iplot. But
201+
# this will require a fair amount of testing to determine which
202+
# options are compatible with FigureWidget.
203+
self._config = _get_jconfig(None)
204+
194205
# Frames
195206
# ------
196207

Diff for: plotly/basewidget.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class BaseFigureWidget(BaseFigure, widgets.DOMWidget):
4646
# using the relayout/restyle/update/etc. messages.
4747
_layout = Dict().tag(sync=True, **custom_serializers)
4848
_data = List().tag(sync=True, **custom_serializers)
49+
_config = Dict().tag(sync=True, **custom_serializers)
4950

5051
# ### Python -> JS message properties ###
5152
# These properties are used to send messages from Python to the

Diff for: plotly/offline/offline.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,18 @@ def _get_jconfig(config):
158158
# really be somewhere other than plotly.plotly
159159
plotly_platform_url = plotly.plotly.get_config().get('plotly_domain',
160160
'https://plot.ly')
161+
clean_config['plotlyServerURL'] = plotly_platform_url
161162

162163
if (plotly_platform_url != 'https://plot.ly' and
163-
clean_config['linkText'] == 'Export to plot.ly'):
164-
164+
clean_config.get('linkText', None) == 'Export to plot.ly'):
165165
link_domain = plotly_platform_url\
166166
.replace('https://', '')\
167167
.replace('http://', '')
168168
link_text = clean_config['linkText'].replace('plot.ly', link_domain)
169169
clean_config['linkText'] = link_text
170-
clean_config['plotlyServerURL'] = plotly_platform_url
171170

172171
return clean_config
173-
172+
174173

175174
# Build script to set global PlotlyConfig object. This must execute before
176175
# plotly.js is loaded.

Diff for: plotlywidget/static/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12607,6 +12607,7 @@ var FigureModel = widgets.DOMWidgetModel.extend({
1260712607
// messages
1260812608
_data: [],
1260912609
_layout: {},
12610+
_config: {},
1261012611

1261112612
// Python -> JS messages
1261212613
// ---------------------
@@ -13319,8 +13320,9 @@ var FigureView = widgets.DOMWidgetView.extend({
1331913320
// the model is not directly mutated by the Plotly.js library.
1332013321
var initialTraces = _.cloneDeep(this.model.get("_data"));
1332113322
var initialLayout = _.cloneDeep(this.model.get("_layout"));
13323+
var config = this.model.get("_config");
1332213324

13323-
Plotly.newPlot(that.el, initialTraces, initialLayout).then(
13325+
Plotly.newPlot(that.el, initialTraces, initialLayout, config).then(
1332413326
function () {
1332513327

1332613328
// ### Send trace deltas ###

Diff for: plotlywidget/static/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)