forked from HaeffnerLab/RealSimpleGrapher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollingGraphWidget.py
More file actions
42 lines (39 loc) · 1.56 KB
/
ScrollingGraphWidget.py
File metadata and controls
42 lines (39 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from GraphWidget import PyQTGraphWidget
from PyQt5 import QtGui, QtCore
class ScrollingPyQTGraphWidget(PyQTGraphWidget):
def __init__(self, name, reactor, parent=None, ylim=(0, 1), cxn=None):
super().__init__(name, reactor, parent)
self.set_xlimits([0, 100])
self.pointsToKeep = 100
def update_figure(self):
x = [0]
y = [0]
for ident, params in self.artists.items():
if params.shown:
try:
index = params.index
x = params.dataset.data[:, 0]
y = params.dataset.data[:, index + 1]
params.artist.setData(x, y)
except TypeError:
pass
except Exception as e:
raise e
try:
mousepressed = QtGui.QGuiApplication.mouseButtons()
if (mousepressed == QtCore.Qt.LeftButton) or (
mousepressed == QtCore.Qt.RightButton
):
return
# see if we need to redraw
xmin_cur, xmax_cur = self.current_limits
x_cur = x[-1] # current largest x value
window_width = xmax_cur - xmin_cur
# scroll if we've reached 75% of the window
if x_cur > (xmin_cur + 0.75 * window_width) and (x_cur < xmax_cur):
shift = (xmax_cur - xmin_cur) / 2.0
xmin = xmin_cur + shift
xmax = xmax_cur + shift
self.set_xlimits([xmin, xmax])
except Exception as e:
raise e