Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 88c4bce

Browse files
committedJun 11, 2018
Merge branch 'ipyplotly_integration' of https://github.com/plotly/plotly.py into ipyplotly_integration
2 parents 5444fcc + 7617945 commit 88c4bce

File tree

3 files changed

+69
-40
lines changed

3 files changed

+69
-40
lines changed
 

‎_plotly_utils/basevalidators.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import base64
22
import numbers
3-
import six
43
import textwrap
54
import uuid
65
from importlib import import_module
@@ -14,6 +13,8 @@
1413
# ----------------
1514
import sys
1615

16+
from _plotly_utils.compat import str_types
17+
1718
np = None
1819
pd = None
1920

@@ -349,7 +350,7 @@ def __init__(self,
349350
# ----------------------------
350351
# Look for regular expressions
351352
for v in self.values:
352-
if v and isinstance(v, str) and v[0] == '/' and v[-1] == '/':
353+
if v and isinstance(v, str_types) and v[0] == '/' and v[-1] == '/':
353354
# String is a regex with leading and trailing '/' character
354355
regex_str = v[1:-1]
355356
self.val_regexs.append(re.compile(regex_str))
@@ -387,7 +388,7 @@ def perform_replacemenet(self, v):
387388
"""
388389
Return v with any applicable regex replacements applied
389390
"""
390-
if isinstance(v, str):
391+
if isinstance(v, str_types):
391392
for repl_args in self.regex_replacements:
392393
if repl_args:
393394
v = re.sub(repl_args[0], repl_args[1], v)
@@ -442,7 +443,7 @@ def in_values(self, e):
442443
"""
443444
Return whether a value matches one of the enumeration options
444445
"""
445-
is_str = isinstance(e, str)
446+
is_str = isinstance(e, str_types)
446447
for v, regex in zip(self.values, self.val_regexs):
447448
if is_str and regex:
448449
in_values = fullmatch(regex, e) is not None
@@ -821,7 +822,7 @@ def validate_coerce(self, v):
821822

822823
# If strict, make sure all elements are strings.
823824
if self.strict:
824-
invalid_els = [e for e in v if not isinstance(e, str)]
825+
invalid_els = [e for e in v if not isinstance(e, str_types)]
825826
if invalid_els:
826827
self.raise_invalid_elements(invalid_els)
827828

@@ -862,10 +863,10 @@ def validate_coerce(self, v):
862863

863864
else:
864865
if self.strict:
865-
if not isinstance(v, str):
866+
if not isinstance(v, str_types):
866867
self.raise_invalid_val(v)
867868
else:
868-
if not isinstance(v, (str, int, float)):
869+
if not isinstance(v, str_types + (int, float)):
869870
self.raise_invalid_val(v)
870871

871872
# Convert value to a string
@@ -1081,7 +1082,7 @@ def perform_validate_coerce(v, allow_number=None):
10811082
if isinstance(v, numbers.Number) and allow_number:
10821083
# If allow_numbers then any number is ok
10831084
return v
1084-
elif not isinstance(v, str):
1085+
elif not isinstance(v, str_types):
10851086
# If not allow_numbers then value must be a string
10861087
return None
10871088
else:
@@ -1203,7 +1204,7 @@ def validate_coerce(self, v):
12031204
pass
12041205
if v is None:
12051206
v_valid = True
1206-
elif isinstance(v, str):
1207+
elif isinstance(v, str_types):
12071208
v_match = [
12081209
el for el in ColorscaleValidator.named_colorscales
12091210
if el.lower() == v.lower()
@@ -1218,7 +1219,7 @@ def validate_coerce(self, v):
12181219
len(e) != 2 or
12191220
not isinstance(e[0], numbers.Number) or
12201221
not (0 <= e[0] <= 1) or
1221-
not isinstance(e[1], str) or
1222+
not isinstance(e[1], str_types) or
12221223
ColorValidator.perform_validate_coerce(e[1]) is None)]
12231224

12241225
if len(invalid_els) == 0:
@@ -1337,7 +1338,7 @@ def description(self):
13371338
def validate_coerce(self, v):
13381339
if v is None:
13391340
pass
1340-
elif not isinstance(v, str):
1341+
elif not isinstance(v, str_types):
13411342
self.raise_invalid_val(v)
13421343
else:
13431344
# match = re.fullmatch(self.regex, v)
@@ -1419,7 +1420,7 @@ def description(self):
14191420
return desc
14201421

14211422
def vc_scalar(self, v):
1422-
if not isinstance(v, str):
1423+
if not isinstance(v, str_types):
14231424
return None
14241425

14251426
# To be generous we accept flags separated on plus ('+'),
@@ -1660,7 +1661,7 @@ def description(self):
16601661
def validate_coerce(self, v):
16611662
if v is None:
16621663
pass
1663-
elif isinstance(v, str):
1664+
elif isinstance(v, str_types):
16641665
# Future possibilities:
16651666
# - Detect filesystem system paths and convert to URI
16661667
# - Validate either url or data uri

‎_plotly_utils/compat.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import six
2+
3+
str_types = six.string_types + (six.text_type,)

‎js/src/Figure.js

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -762,34 +762,59 @@ var FigureView = widgets.DOMWidgetView.extend({
762762
var initialTraces = _.cloneDeep(this.model.get("_data"));
763763
var initialLayout = _.cloneDeep(this.model.get("_layout"));
764764

765-
Plotly.newPlot(this.el, initialTraces, initialLayout).then(
766-
function () {
767-
// ### Send trace deltas ###
768-
// We create an array of deltas corresponding to the new
769-
// traces.
770-
that._sendTraceDeltas(trace_edit_id);
771-
772-
// ### Send layout delta ###
773-
that._sendLayoutDelta(layout_edit_id);
774-
775-
// Wire up plotly event callbacks
776-
that.el.on("plotly_restyle",
777-
function(update) {that.handle_plotly_restyle(update)});
778-
that.el.on("plotly_relayout",
779-
function(update) {that.handle_plotly_relayout(update)});
780-
that.el.on("plotly_update",
781-
function(update) {that.handle_plotly_update(update)});
782-
that.el.on("plotly_click",
783-
function(update) {that.handle_plotly_click(update)});
784-
that.el.on("plotly_hover",
785-
function(update) {that.handle_plotly_hover(update)});
786-
that.el.on("plotly_unhover",
787-
function(update) {that.handle_plotly_unhover(update)});
788-
that.el.on("plotly_selected",
789-
function(update) {that.handle_plotly_selected(update)});
790-
that.el.on("plotly_doubleclick",
791-
function(update) {that.handle_plotly_doubleclick(update)});
765+
Plotly.newPlot(that.el, [], {
766+
'xaxis': {'showgrid': false, 'showticklabels': false, 'zeroline': false},
767+
'yaxis': {'showgrid': false, 'showticklabels': false, 'zeroline': false}
768+
}).then(function () {
769+
Plotly.Plots.resize(that.el).then(function () {
770+
Plotly.newPlot(that.el, initialTraces, initialLayout).then(
771+
function () {
772+
// Plotly.Plots.resize(that.el);
773+
774+
// ### Send trace deltas ###
775+
// We create an array of deltas corresponding to the new
776+
// traces.
777+
that._sendTraceDeltas(trace_edit_id);
778+
779+
// ### Send layout delta ###
780+
that._sendLayoutDelta(layout_edit_id);
781+
782+
// Wire up plotly event callbacks
783+
that.el.on("plotly_restyle",
784+
function (update) {
785+
that.handle_plotly_restyle(update)
786+
});
787+
that.el.on("plotly_relayout",
788+
function (update) {
789+
that.handle_plotly_relayout(update)
790+
});
791+
that.el.on("plotly_update",
792+
function (update) {
793+
that.handle_plotly_update(update)
794+
});
795+
that.el.on("plotly_click",
796+
function (update) {
797+
that.handle_plotly_click(update)
798+
});
799+
that.el.on("plotly_hover",
800+
function (update) {
801+
that.handle_plotly_hover(update)
802+
});
803+
that.el.on("plotly_unhover",
804+
function (update) {
805+
that.handle_plotly_unhover(update)
806+
});
807+
that.el.on("plotly_selected",
808+
function (update) {
809+
that.handle_plotly_selected(update)
810+
});
811+
that.el.on("plotly_doubleclick",
812+
function (update) {
813+
that.handle_plotly_doubleclick(update)
814+
});
815+
});
792816
});
817+
});
793818
},
794819
/**
795820
* Purge Plotly.js data structures from the notebook output display

0 commit comments

Comments
 (0)
Please sign in to comment.