Skip to content

Commit

Permalink
Enable various animations
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Dec 4, 2018
1 parent 0384bde commit 03caf3b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
32 changes: 18 additions & 14 deletions Orange/widgets/visualize/owscatterplotgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def __init__(self, scatter_widget, parent=None, view_box=ViewBox):
self.plot_widget.scene().installEventFilter(self._tooltip_delegate)
self.view_box.sigTransformChanged.connect(self.update_density)

self._timer = QTimer()
self._timer = None

def _create_legend(self, anchor):
legend = LegendItem()
Expand Down Expand Up @@ -730,32 +730,36 @@ def update_sizes(self):
self.master, "impute_sizes", self.default_impute_sizes)
size_imputer(size_data)

if self._timer.isActive():
if self._timer is not None and self._timer.isActive():
self._timer.stop()
self._timer = None

current_size_data = self.scatterplot_item.data["size"]
current_size_data = self.scatterplot_item.data["size"].copy()
diff = size_data - current_size_data
widget = self

class Timeout:
n_iter = 5
# 0.5 - np.cos(np.arange(0.17, 1, 0.17) * np.pi) / 2
factors = [0.06962899, 0.25912316, 0.51570538, 0.7679134,
0.94550326, 1]

def __init__(self, diff_=diff, item=self.scatterplot_item,
item_sel=self.scatterplot_item_sel):
# Yes, parent is needed in order test_owmds.test_nan_plot to work ?!?
def __init__(self, parent=self.scatterplot_item):
self._counter = 0
self._step = diff_ / self.n_iter
self._scatter_item, self._scatter_item_sel = item, item_sel

def __call__(self):
factor = self.factors[self._counter]
self._counter += 1
size = current_size_data + self._step
if self.n_iter == self._counter:
tmr.stop()
size = current_size_data + diff * factor
if len(self.factors) == self._counter:
widget._timer.stop()
widget._timer = None
size = size_data
self._scatter_item.setSize(size)
self._scatter_item_sel.setSize(size + SELECTION_WIDTH)
widget.scatterplot_item.setSize(size)
widget.scatterplot_item_sel.setSize(size + SELECTION_WIDTH)

if np.sum(current_size_data) / self.n_valid != -1 and np.sum(diff):
self._timer = tmr = QTimer(self.scatterplot_item, interval=50)
self._timer = QTimer(self.scatterplot_item, interval=50)
self._timer.timeout.connect(Timeout())
self._timer.start()
else:
Expand Down
18 changes: 10 additions & 8 deletions Orange/widgets/visualize/tests/test_owscatterplotbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
from Orange.widgets.widget import OWWidget


DEFAULT_TIMEOUT = 5000


class MockWidget(OWWidget):
name = "Mock"

Expand Down Expand Up @@ -167,7 +164,8 @@ def test_sampling(self):
master.get_label_data = lambda: \
np.array([str(x) for x in d], dtype=object)
graph.reset_graph()
self.process_events(until=lambda: not self.graph._timer.isActive())
self.process_events(until=lambda: not (
self.graph._timer is not None and self.graph._timer.isActive()))

# Check proper sampling
scatterplot_item = graph.scatterplot_item
Expand Down Expand Up @@ -195,7 +193,8 @@ def test_sampling(self):

# Check that sample is extended when sample size is changed
graph.set_sample_size(4)
self.process_events(until=lambda: not self.graph._timer.isActive())
self.process_events(until=lambda: not (
self.graph._timer is not None and self.graph._timer.isActive()))
scatterplot_item = graph.scatterplot_item
x, y = scatterplot_item.getData()
data = scatterplot_item.data
Expand Down Expand Up @@ -235,7 +234,8 @@ def test_sampling(self):

# Enable sampling when data is already present and not sampled
graph.set_sample_size(3)
self.process_events(until=lambda: not self.graph._timer.isActive())
self.process_events(until=lambda: not (
self.graph._timer is not None and self.graph._timer.isActive()))
scatterplot_item = graph.scatterplot_item
x, y = scatterplot_item.getData()
data = scatterplot_item.data
Expand Down Expand Up @@ -271,7 +271,8 @@ def test_sampling(self):
np.arange(100, 105, dtype=float))
d = self.xy[0] - 100
graph.reset_graph()
self.process_events(until=lambda: not self.graph._timer.isActive())
self.process_events(until=lambda: not (
self.graph._timer is not None and self.graph._timer.isActive()))
scatterplot_item = graph.scatterplot_item
x, y = scatterplot_item.getData()
self.assertEqual(len(x), 3)
Expand Down Expand Up @@ -376,7 +377,8 @@ def test_size_with_nans(self):

d[4] = np.nan
graph.update_sizes()
self.process_events(until=lambda: not self.graph._timer.isActive())
self.process_events(until=lambda: not (
self.graph._timer is not None and self.graph._timer.isActive()))
sizes2 = scatterplot_item.data["size"]

self.assertEqual(sizes[1] - sizes[0], sizes2[1] - sizes2[0])
Expand Down

0 comments on commit 03caf3b

Please sign in to comment.