| 72 | |
| 73 | |
| 74 | class SvgPlot(gui.Svg): |
| 75 | def __init__(self, _width, _height): |
| 76 | super(SvgPlot, self).__init__(width = _width, height = _height) |
| 77 | self.width = _width |
| 78 | self.height = _height |
| 79 | self.polyList = [] |
| 80 | self.font_size = 15 |
| 81 | self.plot_inner_border = self.font_size |
| 82 | self.textYMin = gui.SvgText(0, self.height + self.font_size, "min") |
| 83 | self.textYMax = gui.SvgText(0, 0, "max") |
| 84 | self.textYMin.style['font-size'] = gui.to_pix(self.font_size) |
| 85 | self.textYMax.style['font-size'] = gui.to_pix(self.font_size) |
| 86 | self.append([self.textYMin, self.textYMax]) |
| 87 | |
| 88 | def append_poly(self, polys): |
| 89 | for poly in polys: |
| 90 | self.append(poly) |
| 91 | self.polyList.append(poly) |
| 92 | poly.textXMin = gui.SvgText(0, 0, "actualValue") |
| 93 | poly.textXMax = gui.SvgText(0, 0, "actualValue") |
| 94 | poly.textYVal = gui.SvgText(0, 0, "actualValue") |
| 95 | poly.textYVal.style['font-size'] = gui.to_pix(self.font_size) |
| 96 | |
| 97 | poly.lineYValIndicator = gui.SvgLine(0, 0, 0, 0) |
| 98 | poly.lineXMinIndicator = gui.SvgLine(0, 0, 0, 0) |
| 99 | poly.lineXMaxIndicator = gui.SvgLine(0, 0, 0, 0) |
| 100 | self.append([poly.textXMin, poly.textXMax, poly.textYVal, poly.lineYValIndicator, |
| 101 | poly.lineXMinIndicator, poly.lineXMaxIndicator]) |
| 102 | |
| 103 | def remove_poly(self, poly): |
| 104 | self.remove_child(poly) |
| 105 | self.polyList.remove(poly) |
| 106 | self.remove_child(poly.textXMin) |
| 107 | self.remove_child(poly.textXMax) |
| 108 | self.remove_child(poly.textYVal) |
| 109 | |
| 110 | def render(self): |
| 111 | self.set_viewbox(-self.plot_inner_border, -self.plot_inner_border, self.width + self.plot_inner_border * 2, |
| 112 | self.height + self.plot_inner_border * 2) |
| 113 | if len(self.polyList) < 1: |
| 114 | return |
| 115 | minX = min(self.polyList[0].plotData.coordsX) |
| 116 | maxX = max(self.polyList[0].plotData.coordsX) |
| 117 | minY = min(self.polyList[0].plotData.coordsY) |
| 118 | maxY = max(self.polyList[0].plotData.coordsY) |
| 119 | |
| 120 | for poly in self.polyList: |
| 121 | minX = min(minX, min(poly.plotData.coordsX)) |
| 122 | maxX = max(maxX, max(poly.plotData.coordsX)) |
| 123 | minY = min(minY, min(poly.plotData.coordsY)) |
| 124 | maxY = max(maxY, max(poly.plotData.coordsY)) |
| 125 | self.textYMin.set_text("min:%s" % minY) |
| 126 | self.textYMax.set_text("max:%s" % maxY) |
| 127 | |
| 128 | i = 1 |
| 129 | for poly in self.polyList: |
| 130 | scaledTranslatedYpos = (-poly.plotData.coordsY[-1] + maxY + (self.height-(maxY-minY))/2.0) |
| 131 | |