Skip to content

Commit 3ef2a2a

Browse files
Merge pull request #208 from vpython/improve_plot_interval
Improve plot interval
2 parents b810ec1 + 2da4ba2 commit 3ef2a2a

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

vpython/vpython.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ class standardAttributes(baseObj):
571571
[],
572572
['location', 'text'],
573573
[]],
574-
'extrusion':[ ['pos', 'color', 'start_face_color', 'end_face_color', 'start_normal', 'end_normal'],
574+
'extrusion':[ ['pos', 'color', 'start_face_color', 'end_face_color',
575+
'start_normal', 'end_normal'],
575576
[ 'axis', 'size', 'up' ],
576577
['path', 'shape', 'visible', 'opacity','shininess', 'emissive',
577578
'show_start_face', 'show_end_face', 'smooth', 'smooth_joints', 'sharp_joints',
@@ -2092,6 +2093,8 @@ def setup(self, args):
20922093
self._label = ''
20932094
self._legend = False
20942095
self._interval = -1
2096+
self._iterations = 0
2097+
self._firstplot = True
20952098
self._graph = None
20962099
self._data = []
20972100
self._visible = True
@@ -2134,6 +2137,7 @@ def setup(self, args):
21342137
cmd = {"cmd": objName, "idx": self.idx}
21352138

21362139
for a in argsToSend:
2140+
if a == 'interval': continue # do not send to browser; handle here instead
21372141
aval = getattr(self,a)
21382142
if isinstance(aval, vector):
21392143
aval = aval.value
@@ -2205,7 +2209,7 @@ def interval(self): return self._interval
22052209
@interval.setter
22062210
def interval(self,val):
22072211
self._interval = val
2208-
self.addattr('interval')
2212+
self._iterations = 0
22092213

22102214
def __del__(self):
22112215
cmd = {"cmd": "delete", "idx": self.idx}
@@ -2247,15 +2251,26 @@ def preresolve2(self, args):
22472251
raise AttributeError("Must be plot(x,y) or plot(pos=[x,y]) or plot([x,y]) or plot([x,y], ...) or plot([ [x,y], ... ])")
22482252

22492253
def plot(self, *args1, **args2):
2254+
if self._interval == 0:
2255+
return
2256+
if self._interval > 0:
2257+
self._iterations += 1
2258+
if self._firstplot:
2259+
self._firstplot = False
2260+
elif self._iterations < self._interval:
2261+
return
2262+
self._iterations = 0
22502263
if len(args1) > 0:
22512264
p = self.preresolve1(args1)
22522265
else:
22532266
p = self.preresolve2(args2)
22542267
self._data = self._data + p
22552268
self.addmethod('plot', p)
2256-
2269+
22572270
def delete(self):
22582271
self.addmethod('delete', 'None')
2272+
self._firstplot = True
2273+
self._iterations = 0
22592274

22602275
@property
22612276
def label(self): return self._label

0 commit comments

Comments
 (0)