Skip to content

Commit

Permalink
Pass configured plotly_domain to FigureWidget as plotlyServerURL conf…
Browse files Browse the repository at this point in the history
…ig parameter (#1284)
  • Loading branch information
jonmmease authored Nov 23, 2018
1 parent 579d823 commit dffa93a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
4 changes: 3 additions & 1 deletion js/src/Figure.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var FigureModel = widgets.DOMWidgetModel.extend({
// messages
_data: [],
_layout: {},
_config: {},

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

Plotly.newPlot(that.el, initialTraces, initialLayout).then(
Plotly.newPlot(that.el, initialTraces, initialLayout, config).then(
function () {

// ### Send trace deltas ###
Expand Down
11 changes: 11 additions & 0 deletions plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from copy import deepcopy, copy
from pprint import PrettyPrinter

from plotly.offline.offline import _get_jconfig
from .optional_imports import get_module

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

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

# Frames
# ------

Expand Down
1 change: 1 addition & 0 deletions plotly/basewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BaseFigureWidget(BaseFigure, widgets.DOMWidget):
# using the relayout/restyle/update/etc. messages.
_layout = Dict().tag(sync=True, **custom_serializers)
_data = List().tag(sync=True, **custom_serializers)
_config = Dict().tag(sync=True, **custom_serializers)

# ### Python -> JS message properties ###
# These properties are used to send messages from Python to the
Expand Down
7 changes: 3 additions & 4 deletions plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,18 @@ def _get_jconfig(config):
# really be somewhere other than plotly.plotly
plotly_platform_url = plotly.plotly.get_config().get('plotly_domain',
'https://plot.ly')
clean_config['plotlyServerURL'] = plotly_platform_url

if (plotly_platform_url != 'https://plot.ly' and
clean_config['linkText'] == 'Export to plot.ly'):

clean_config.get('linkText', None) == 'Export to plot.ly'):
link_domain = plotly_platform_url\
.replace('https://', '')\
.replace('http://', '')
link_text = clean_config['linkText'].replace('plot.ly', link_domain)
clean_config['linkText'] = link_text
clean_config['plotlyServerURL'] = plotly_platform_url

return clean_config


# Build script to set global PlotlyConfig object. This must execute before
# plotly.js is loaded.
Expand Down
4 changes: 3 additions & 1 deletion plotlywidget/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12607,6 +12607,7 @@ var FigureModel = widgets.DOMWidgetModel.extend({
// messages
_data: [],
_layout: {},
_config: {},

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

Plotly.newPlot(that.el, initialTraces, initialLayout).then(
Plotly.newPlot(that.el, initialTraces, initialLayout, config).then(
function () {

// ### Send trace deltas ###
Expand Down
2 changes: 1 addition & 1 deletion plotlywidget/static/index.js.map

Large diffs are not rendered by default.

0 comments on commit dffa93a

Please sign in to comment.