Skip to content

Commit

Permalink
Merge pull request #478 from ioam/dynamic_fix
Browse files Browse the repository at this point in the history
Ensured initial dynamicmap values are escaped correctly in widgets
  • Loading branch information
jlstevens committed Feb 9, 2016
2 parents 40d3fd5 + e778c6f commit adb56eb
Showing 1 changed file with 17 additions and 4 deletions.
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

0 comments on commit adb56eb

Please sign in to comment.