Skip to content

Commit

Permalink
Improved throttling for select widget and added waiting to scrubber
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 8, 2016
1 parent 7c6bc30 commit 130f773
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
17 changes: 7 additions & 10 deletions holoviews/plotting/bokeh/bokehwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ var BokehMethods = {
if (current === undefined) {
return
}
if (this.time === undefined) {
// Do nothing the first time
} else if (this.timer === undefined | ((this.time + this.timer) > Date.now())) {
this.queue.push(current);
return
}
this.time = Date.now()
if(this.dynamic) {
current = JSON.stringify(current);
Expand All @@ -64,16 +58,19 @@ var BokehMethods = {
if (msg.msg_type != "execute_result") {
console.log("Warning: HoloViews callback returned unexpected data for key: (", current, ") with the following content:", msg.content)
this.time = undefined;
this.wait = false;
return
}
this.timer = Date.now() - this.time;
this.timed = (Date.now() - this.time) * 1.1;
if (msg.msg_type == "execute_result") {
if (msg.content.data['text/plain'] === "'Complete'") {
if (this.queue.length > 0) {
if (this.wait !== undefined) {
this.wait = false;
} else if (this.queue.length > 0) {
this.dynamic_update(this.queue[this.queue.length-1]);
this.queue = [];
}
return
}
return
}
var data = msg.content.data['text/plain'].slice(1, -1);
this.frames[current] = JSON.parse(data);
Expand Down
12 changes: 4 additions & 8 deletions holoviews/plotting/mpl/mplwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ var MPLMethods = {
}
},
dynamic_update : function(current){
if (this.time === undefined) {
// Do nothing the first time
} else if (this.timer === undefined | ((this.time + this.timer) > Date.now())) {
this.queue.push(current);
return
}
this.time = Date.now()
if (this.dynamic) {
current = JSON.stringify(current);
Expand All @@ -57,7 +51,6 @@ var MPLMethods = {
this.time = undefined;
return
}
this.timer = Date.now() - this.time;
if (!(this.mode == 'nbagg')) {
if(!(current in this.cache)) {
var data = msg.content.data['text/plain'].slice(1, -1);
Expand All @@ -69,7 +62,10 @@ var MPLMethods = {
}
this.update(current);
}
if (this.queue.length > 0) {
this.timed = (Date.now() - this.time) * 1.1;
if (this.wait !== undefined) {
this.wait = false;
} else if (this.queue.length > 0) {
this.dynamic_update(this.queue[this.queue.length-1]);
this.queue = [];
}
Expand Down
21 changes: 17 additions & 4 deletions holoviews/plotting/widgets/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ function SelectionWidget(frames, id, slider_ids, keyMap, dim_vals, notFound, loa
SelectionWidget.prototype = new HoloViewsWidget;

SelectionWidget.prototype.set_frame = function(dim_val, dim_idx){
if (this.time === undefined) {
// Do nothing the first time
} else if (this.timed === undefined | ((this.time + this.timed) > Date.now())) {
var current = this.current_vals.slice();
current[dim_idx] = dim_val;
this.queue.push(current);
return
}
this.current_vals[dim_idx] = dim_val;
if(this.dynamic) {
this.dynamic_update(this.current_vals)
Expand Down Expand Up @@ -148,14 +156,14 @@ function ScrubberWidget(frames, num_frames, id, interval, load_json, mode, cache
this.json_path = json_path;
document.getElementById(this.slider_id).max = this.length - 1;
this.init_slider(0);
this.queue = [];
this.wait = false;
}

ScrubberWidget.prototype = new HoloViewsWidget;

ScrubberWidget.prototype.set_frame = function(frame){
this.current_frame = frame;
widget = document.getElementById(this.slider_id);
this.current_frame = frame;
widget = document.getElementById(this.slider_id);
if (widget === null) {
this.pause_animation();
return
Expand All @@ -172,6 +180,7 @@ ScrubberWidget.prototype.set_frame = function(frame){
ScrubberWidget.prototype.process_error = function(msg){
if (msg.content.ename === 'StopIteration') {
this.pause_animation();
this.stopped = true;
var keys = Object.keys(this.frames)
this.length = keys.length;
document.getElementById(this.slider_id).max = this.length-1;
Expand All @@ -195,6 +204,10 @@ ScrubberWidget.prototype.get_loop_state = function(){

ScrubberWidget.prototype.next_frame = function() {
if (this.dynamic && this.current_frame + 1 >= this.length) {
if (this.wait) {
return
}
this.wait = true;
this.length += 1;
document.getElementById(this.slider_id).max = this.length-1;
}
Expand Down Expand Up @@ -226,7 +239,7 @@ ScrubberWidget.prototype.faster = function() {
}

ScrubberWidget.prototype.anim_step_forward = function() {
if(this.current_frame < this.length || this.dynamic){
if(this.current_frame < this.length || (this.dynamic && !this.stopped)){
this.next_frame();
}else{
var loop_state = this.get_loop_state();
Expand Down

0 comments on commit 130f773

Please sign in to comment.