A group of polyline and circles
| 22 | |
| 23 | |
| 24 | class SvgComposedPoly(gui.SvgGroup): |
| 25 | """ A group of polyline and circles |
| 26 | """ |
| 27 | def __init__(self, x, y, maxlen, stroke, color, *args, **kwargs): |
| 28 | super(SvgComposedPoly, self).__init__(*args, **kwargs) |
| 29 | self.maxlen = maxlen |
| 30 | self.plotData = gui.SvgPolyline(self.maxlen) |
| 31 | self.plotData.set_fill('none') |
| 32 | self.append(self.plotData) |
| 33 | self.set_stroke(stroke, color) |
| 34 | self.set_fill(color) |
| 35 | self.circle_radius = stroke |
| 36 | self.circles_list = list() |
| 37 | self.x_factor = 1.0 |
| 38 | self.y_factor = 1.0 |
| 39 | |
| 40 | def add_coord(self, x, y): |
| 41 | """ Adds a coord to the polyline and creates another circle |
| 42 | """ |
| 43 | x = x*self.x_factor |
| 44 | y = y*self.y_factor |
| 45 | self.plotData.add_coord(x, y) |
| 46 | self.circles_list.append(gui.SvgCircle(x, y, self.circle_radius)) |
| 47 | self.append(self.circles_list[-1]) |
| 48 | if len(self.circles_list) > self.maxlen: |
| 49 | self.remove_child(self.circles_list[0]) |
| 50 | del self.circles_list[0] |
| 51 | |
| 52 | def scale(self, x_factor, y_factor): |
| 53 | self.x_factor = x_factor/self.x_factor |
| 54 | self.y_factor = y_factor/self.y_factor |
| 55 | self.plotData.attributes['points'] = "" |
| 56 | tmpx = collections.deque() |
| 57 | tmpy = collections.deque() |
| 58 | |
| 59 | for c in self.circles_list: |
| 60 | self.remove_child(c) |
| 61 | self.circles_list = list() |
| 62 | |
| 63 | while len(self.plotData.coordsX)>0: |
| 64 | tmpx.append( self.plotData.coordsX.popleft() ) |
| 65 | tmpy.append( self.plotData.coordsY.popleft() ) |
| 66 | |
| 67 | while len(tmpx)>0: |
| 68 | self.add_coord(tmpx.popleft(), tmpy.popleft()) |
| 69 | |
| 70 | self.x_factor = x_factor |
| 71 | self.y_factor = y_factor |
| 72 | |
| 73 | |
| 74 | class SvgPlot(gui.Svg): |