Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensured initial dynamicmap values are escaped correctly in widgets #478

Merged
merged 1 commit into from
Feb 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions holoviews/plotting/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,26 @@ def isnumeric(val):
except:
return False

def escape_vals(vals):
def escape_vals(vals, escape_numerics=True):
"""
Escapes a list of values to a string, converting to
unicode for safety.
"""
return ["'"+unicode(safe_unicode(v))+"'" if not isnumeric(v) else
("'%.1f'" % v if v % 1 == 0 else "'%.10f'" % v) for v in vals]
if escape_numerics:
ints, floats = "'%.1f'", "'%.10f'"
else:
ints, floats = "%.1f", "%.10f"

escaped = []
for v in vals:
if not isnumeric(v):
v = "'"+unicode(safe_unicode(v))+"'"
elif v % 1 == 0:
v = ints % v
else:
v = floats % v
escaped.append(v)
return escaped

def escape_tuple(vals):
return "(" + ", ".join(vals) + (",)" if len(vals) == 1 else ")")
Expand Down Expand Up @@ -300,7 +313,7 @@ def get_widgets(self):
next_vals=next_vals)
widgets.append(widget_data)
dimensions.append(dim_str)
init_dim_vals = escape_list(escape_vals(init_dim_vals))
init_dim_vals = escape_list(escape_vals(init_dim_vals, self.plot.dynamic))
return widgets, dimensions, init_dim_vals


Expand Down