diff --git a/Stuff/Modules/explorer.py b/Stuff/Modules/explorer.py index 8cf6580..25aba46 100644 --- a/Stuff/Modules/explorer.py +++ b/Stuff/Modules/explorer.py @@ -79,7 +79,7 @@ def __init__(self, root): self.removeReflectionsVar.set(False) self.showShocksVar.set(True) self.showTailVar.set(False) - self.saveWhatVar.set("both frames") + self.saveWhatVar.set("all") self.saveWhichFilesVar.set("current") self.selectedParameter.set("") diff --git a/Stuff/Modules/graphs.py b/Stuff/Modules/graphs.py index 188760a..4f06b48 100644 --- a/Stuff/Modules/graphs.py +++ b/Stuff/Modules/graphs.py @@ -41,85 +41,7 @@ def getGraphTypes(): -class Graphs(Canvas): - "parent class for all 'wide' graphs in Explore page" - def __init__(self, parent, width = 620, height = 120): - super().__init__(parent) - self["width"] = width - self["height"] = height - self["background"] = "white" - self.height = height - self.width = width - self.parent = parent - self.drawnParameter = None - - - def changedTime(self, newTime): - "changes position of a time measure on a graph" - x = (newTime - self.minTime) * self.width / (self.maxTime - self.minTime) - if x < 2: - x = 2 - self.coords("timeMeasure", (x, 0, x, self.height)) - - - def CM_loaded(self, CM, minTime, maxTime, initTime): - "basic method called when a file is loaded" - # time measure - self.create_line((2, 0, 2, self.height), fill = "red", tags = "timeMeasure") - - # maximum time in miliseconds - if maxTime == "max": - self.maxTime = CM.data[-1][1] - else: - self.maxTime = maxTime - - if minTime == "min": - self.minTime = CM.data[0][1] - else: - self.minTime = minTime - - # set time measure - self.changedTime(initTime) - - self.drawParameter(cm = CM, parameter = self.drawnParameter) - - - def drawPeriods(self, periods, color = "red", width = 3): - "draws selected parameter on top of the graph" - if not periods: - return - timeSpread = (self.maxTime - self.minTime) - for period in periods: - if period[0] > self.minTime and period[1] < self.maxTime: - begin = period[0] - end = period[1] - elif self.minTime < period[1] < self.maxTime: - begin = self.minTime - end = period[1] - elif self.minTime < period[0] < self.maxTime: - begin = period[0] - end = self.maxTime - else: - continue - self.create_line(((begin - self.minTime) * self.width / timeSpread, - 0.03 * self.height, - (end - self.minTime) * self.width / timeSpread, - 0.03 * self.height), - fill = color, width = width, tags = "parameter") - - - def drawTimes(self, times): - "draws selected parameter on top of the graph" - if not times: - return - timeSpread = (self.maxTime - self.minTime) - for time in times: - if self.minTime < time < self.maxTime: - x = (time - self.minTime) * self.width / timeSpread - self.create_line((x, 0.01 * self.height, x, 0.07 * self.height), - fill = "red", width = 1, tags = "parameter") - - +class TheFatherOfAllGraphs(): def drawParameter(self, cm, parameter): "computes selected parameter to be drawn on top of the graph" if self.drawnParameter: @@ -271,10 +193,87 @@ def distance(line): for strategy, periods in strategies.items(): self.drawPeriods(periods, color = colors[strategy], width = 240) self.lower("parameter") - - - - + + +class Graphs(Canvas, TheFatherOfAllGraphs): + "parent class for all 'wide' graphs in Explore page" + def __init__(self, parent, width = 620, height = 120): + super().__init__(parent) + self["width"] = width + self["height"] = height + self["background"] = "white" + self.height = height + self.width = width + self.drawnParameter = None + self.parent = parent + + + def changedTime(self, newTime): + "changes position of a time measure on a graph" + x = (newTime - self.minTime) * self.width / (self.maxTime - self.minTime) + if x < 2: + x = 2 + self.coords("timeMeasure", (x, 0, x, self.height)) + + + def CM_loaded(self, CM, minTime, maxTime, initTime): + "basic method called when a file is loaded" + # time measure + self.create_line((2, 0, 2, self.height), fill = "red", tags = "timeMeasure") + + # maximum time in miliseconds + if maxTime == "max": + self.maxTime = CM.data[-1][1] + else: + self.maxTime = maxTime + + if minTime == "min": + self.minTime = CM.data[0][1] + else: + self.minTime = minTime + + # set time measure + self.changedTime(initTime) + + self.drawParameter(cm = CM, parameter = self.drawnParameter) + + + def drawPeriods(self, periods, color = "red", width = 3): + "draws selected parameter on top of the graph" + if not periods: + return + timeSpread = (self.maxTime - self.minTime) + for period in periods: + if period[0] > self.minTime and period[1] < self.maxTime: + begin = period[0] + end = period[1] + elif self.minTime < period[1] < self.maxTime: + begin = self.minTime + end = period[1] + elif self.minTime < period[0] < self.maxTime: + begin = period[0] + end = self.maxTime + else: + continue + self.create_line(((begin - self.minTime) * self.width / timeSpread, + 0.03 * self.height, + (end - self.minTime) * self.width / timeSpread, + 0.03 * self.height), + fill = color, width = width, tags = "parameter") + + + def drawTimes(self, times): + "draws selected parameter on top of the graph" + if not times: + return + timeSpread = (self.maxTime - self.minTime) + for time in times: + if self.minTime < time < self.maxTime: + x = (time - self.minTime) * self.width / timeSpread + self.create_line((x, 0.01 * self.height, x, 0.07 * self.height), + fill = "red", width = 1, tags = "parameter") + + def drawGraph(self, maxY, valueList): """draws lines on a canvas based on maxY and valueList parameters maxY parameter sets maximum value at y-axis @@ -291,11 +290,14 @@ def drawGraph(self, maxY, valueList): -class SvgGraph(): +class SvgGraph(TheFatherOfAllGraphs): "represents graph to be saved in .svg file" - def __init__(self, parent, cm): + def __init__(self, parent, cm, width = 620, height = 120): + self.height = height + self.width = width + self.drawnParameter = None self.parent = parent - + def saveGraph(self, cm): "returns information about graph for saving in .svg file" @@ -306,6 +308,42 @@ def saveGraph(self, cm): return self.points, self.maxY, self.furtherText + def drawPeriods(self, periods, color = "red", width = 3): + "draws selected parameter on top of the graph" + if not periods: + return + timeSpread = (self.maxTime - self.minTime) + for period in periods: + if period[0] > self.minTime and period[1] < self.maxTime: + begin = period[0] + end = period[1] + elif self.minTime < period[1] < self.maxTime: + begin = self.minTime + end = period[1] + elif self.minTime < period[0] < self.maxTime: + begin = period[0] + end = self.maxTime + else: + continue + self.create_line(((begin - self.minTime) * self.width / timeSpread, + 0.03 * self.height, + (end - self.minTime) * self.width / timeSpread, + 0.03 * self.height), + fill = color, width = width, tags = "parameter") + + + def drawTimes(self, times): + "draws selected parameter on top of the graph" + if not times: + return "" + timeSpread = (self.maxTime - self.minTime) + text = "" + for time in times: + if self.minTime < time < self.maxTime: + x = (time - self.minTime) * self.width / timeSpread + text += ''.format(x) + return text + class SpeedGraph(Graphs, SvgGraph): "graph depicting speed during the session" diff --git a/Stuff/Modules/image.py b/Stuff/Modules/image.py index eac9891..ebd65b0 100644 --- a/Stuff/Modules/image.py +++ b/Stuff/Modules/image.py @@ -57,7 +57,8 @@ class SVG(): def __init__(self, cm, components, root): self.start = int(root.timeFrame.startTimeVar.get()) self.end = int(root.timeFrame.timeVar.get()) - #graph = eval(root.graphTypeVar.get()[:-1] + ', cm, purpose = "svg")') + self.graph = eval(root.graphTypeVar.get()[:-5] + 'root, cm, purpose = "svg")') + self.parameter = "shocks" # for testing self.cm = cm self.components = components @@ -160,14 +161,14 @@ def addMain(self): def addArena(self): - self.add(self.addTrack(slice(7,9)), 2, 1) + self.add(self.addTrack(slice(7,9), places = False), 2, 1) def addRoom(self): self.add(self.addTrack(slice(2,4), shocks = True), 4, 1) - def addTrack(self, indices, shocks = False): + def addTrack(self, indices, places = True, shocks = False): "adds text into sefl.content corresponding to track from one frame of AAPA" track = '\n' @@ -179,7 +180,8 @@ def addTrack(self, indices, shocks = False): r = self.cm.radius track += '\n'.format(150 - r) - track += self.addPlaces() + if places: + track += self.addPlaces() track += '\n' - if shocks: + if shocks and shockPositions: track += self.addShocks(shockPositions) track += self.addBoundary() @@ -225,12 +227,14 @@ def addPlaces(self): 'points="{},{} {},{} {},{}"/>\n'.format(Sx1, Sy1, r, r, Sx2, Sy2) return places + def addShocks(self, positions): for position in positions: shocks = '\n'.format(*position) return shocks + def addBoundary(self): r = self.cm.radius bound = '\n'.format(r) @@ -238,52 +242,82 @@ def addBoundary(self): def addGraph(self): - pass + size = (600 + self.xgap, 120) + graph = ('\n'.format(size[0], size[1])) + + yCoordinates, maxY, furtherText = self.graph.saveGraph(self.cm) + points = [] + if yCoordinates: + length = len(yCoordinates) - 1 + for count, y in enumerate(yCoordinates): + points.append(((count * size[0]) / length, size[1] - ((y * size[1]) / maxY))) + + if points: + graph += '{1}\n'.format(x, label)) + text += ''.format(x, -2, -10) + + self.add(text, 2, 5) + def addYticks(self): pass + def addXlab(self): - pass + x = (self.x[4] - self.x[3]) / 2 + xlab = ('{1}'.format(x, self.xlab)) + self.add(xlab, 3, 6) - def addYlab(self): - pass + def addYlab(self): + y = (self.y[4] - self.y[3]) / 2 + ylab = ('{2}'.format(y, -y+10, self.ylab)) + self.add(ylab, 0, 3) - - -## -## -## def drawGraph(self, points, furtherText = "", origin = (0, 0), boundary = False): -## "adds text containing information about graph in self.content" -## size = (600, 120) -## self.content += '\n'.format(origin) -## if boundary: -## self.content += '\n'.format(*size) -## self.content += furtherText -## if points: -## self.content += '