Skip to content

Commit

Permalink
Merge pull request #575 from ioam/dynamic_labels
Browse files Browse the repository at this point in the history
Fixed dimension escaping and bug setting dynamic widget labels
  • Loading branch information
jlstevens committed Mar 24, 2016
2 parents a4618a5 + c1b642f commit 3847c3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions holoviews/plotting/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,17 @@ def get_widgets(self):
if all(isnumeric(v) for v in dim.values):
dim_vals = {i: v for i, v in enumerate(dim.values)}
widget_type = 'slider'
value_labels = escape_list(escape_vals([dim.pprint_value(v)
for v in dim.values]))
else:
dim_vals = escape_list(escape_vals(dim.values))
value_labels = escape_list(escape_vals([dim.pprint_value(v)
for v in dim_vals]))
widget_type = 'dropdown'
init_dim_vals.append(dim_vals[0])
else:
widget_type = 'slider'
value_labels = []
dim_vals = [dim.soft_range[0] if dim.soft_range[0] else dim.range[0],
dim.soft_range[1] if dim.soft_range[1] else dim.range[1]]
dim_range = dim_vals[1] - dim_vals[0]
Expand Down Expand Up @@ -317,13 +322,14 @@ def get_widgets(self):

visibility = '' if visible else 'display: none'
dim_str = safe_unicode(dim.name)
widget_data = dict(dim=dimension_sanitizer(dim_str), dim_label=dim_str,
escaped_dim = dimension_sanitizer(dim_str)
widget_data = dict(dim=escaped_dim, dim_label=dim_str,
dim_idx=idx, vals=dim_vals, type=widget_type,
visibility=visibility, step=step, next_dim=next_dim,
next_vals=next_vals, labels=value_labels)

widgets.append(widget_data)
dimensions.append(dim_str)
dimensions.append(escaped_dim)
init_dim_vals = escape_list(escape_vals(init_dim_vals, not self.plot.dynamic))
return widgets, dimensions, init_dim_vals

Expand Down
7 changes: 5 additions & 2 deletions holoviews/plotting/widgets/jsslider.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
require(["jQueryUI", "underscore"], function(jUI, _){
if (noConflict) $.noConflict(true);
var vals = {{ widget_data['vals'] }};
var labels = {{ widget_data['labels'] }};
var next_vals = {{ widget_data['next_vals'] }};
if ({{ dynamic }} && vals.constructor === Array) {
var min = parseFloat(vals[0]);
var max = parseFloat(vals[vals.length-1]);
var step = {{ widget_data['step'] }};
var labels = [min];
} else {
var min = 0;
if ({{ dynamic }}) {
Expand All @@ -87,6 +87,7 @@
var max = vals.length - 1;
}
var step = 1;
var labels = {{ widget_data['labels'] }};
}
function adjustFontSize(text) {
var width_ratio = (text.parent().width()/8)/text.val().length;
Expand All @@ -109,11 +110,13 @@
var labels = slider.slider("option", "dim_labels");
if ({{ dynamic }} && vals.constructor === Array) {
var dim_val = ui.value;
var label = ui.value;
} else {
var dim_val = vals[ui.value];
var label = labels[ui.value];
}
var text = $('#textInput{{ id }}_{{ widget_data['dim'] }}');
text.val(labels[ui.value]);
text.val(label);
adjustFontSize(text);
anim{{ id }}.set_frame(dim_val, {{ widget_data['dim_idx'] }});
if (Object.keys(next_vals).length > 0) {
Expand Down

0 comments on commit 3847c3c

Please sign in to comment.