Skip to content

Commit

Permalink
Implemented throttling for ScrubberWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed May 29, 2018
1 parent d8e29d6 commit dd6bd2e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
13 changes: 7 additions & 6 deletions holoviews/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,16 +1557,17 @@ def cross_index(values, index):
making up the cartesian product and a linear index, returning
the cross product of the values at the supplied index.
"""
lengths = [len(v) for v in values][::-1]
partials = [np.product(lengths[:i]) for i in range(1, len(values)+1)][::-1]
length = partials.pop(0)
lengths = [len(v) for v in values]
length = np.product(lengths)
if index >= length:
raise ValueError('Index out of bounds')
raise IndexError('Index %d out of bounds for cross-product of size %d'
% (index, length))
indexes = []
for p in partials:
for i in range(1, len(values))[::-1]:
p = np.product(lengths[-i:])
indexes.append(index//p)
index -= indexes[-1] * p
indexes.append(index%lengths[0])
indexes.append(index)
return tuple(v[i] for v, i in zip(values, indexes))


Expand Down
14 changes: 10 additions & 4 deletions holoviews/plotting/widgets/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,20 @@ ScrubberWidget.prototype.set_frame = function(frame){
return
}
widget.value = this.current_frame;
if(this.cached) {
this.update(frame)
} else {
if (this.dynamic || !this.cached) {
if ((this.time !== undefined) && ((this.wait) && ((this.time + 10000) > Date.now()))) {
this.queue.push(frame);
return
}
this.queue = [];
this.time = Date.now();
this.wait = true;
this.dynamic_update(frame)
} else {
this.update(frame)
}
}


ScrubberWidget.prototype.get_loop_state = function(){
var button_group = document[this.loop_select_id].state;
for (var i = 0; i < button_group.length; i++) {
Expand Down
46 changes: 43 additions & 3 deletions tests/core/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"""
import sys, math
import unittest
import datetime
from unittest import SkipTest
from itertools import product
from collections import OrderedDict

import datetime
import numpy as np
from collections import OrderedDict
try:
import pandas as pd
except:
Expand All @@ -17,7 +18,7 @@
from holoviews.core.util import (
sanitize_identifier_fn, find_range, max_range, wrap_tuple_streams,
deephash, merge_dimensions, get_path, make_path_unique, compute_density,
date_range, dt_to_int, compute_edges, isfinite
date_range, dt_to_int, compute_edges, isfinite, cross_index
)
from holoviews import Dimension, Element
from holoviews.streams import PointerXY
Expand Down Expand Up @@ -731,3 +732,42 @@ def test_close_edges(self):
def test_uneven_edges(self):
self.assertEqual(compute_edges(self.array3),
np.array([0.5, 1.5, 3.0, 5.0]))


class TestCrossIndex(ComparisonTestCase):

def setUp(self):
self.values1 = ['A', 'B', 'C']
self.values2 = [1, 2, 3, 4]
self.values3 = ['?', '!']
self.values4 = ['x']

def test_cross_index_full_product(self):
values = [self.values1, self.values2, self.values3, self.values4]
cross_product = list(product(*values))
for i, p in enumerate(cross_product):
self.assertEqual(cross_index(values, i), p)

def test_cross_index_depth_1(self):
values = [self.values1]
cross_product = list(product(*values))
for i, p in enumerate(cross_product):
self.assertEqual(cross_index(values, i), p)

def test_cross_index_depth_2(self):
values = [self.values1, self.values2]
cross_product = list(product(*values))
for i, p in enumerate(cross_product):
self.assertEqual(cross_index(values, i), p)

def test_cross_index_depth_3(self):
values = [self.values1, self.values2, self.values3]
cross_product = list(product(*values))
for i, p in enumerate(cross_product):
self.assertEqual(cross_index(values, i), p)

def test_cross_index_large(self):
values = [[chr(65+i) for i in range(26)], list(range(500)),
[chr(97+i) for i in range(26)], [chr(48+i) for i in range(10)]]
self.assertEqual(cross_index(values, 50001), ('A', 192, 'i', '1'))
self.assertEqual(cross_index(values, 500001), ('D', 423, 'c', '1'))

0 comments on commit dd6bd2e

Please sign in to comment.