def drawState(win, state, color=None): retval = [] for list in states[state]: polygon = Polygon(*[ll2xy(pair[0], pair[1]) for pair in list]) if color is not None: state_colors[state] = Color(color) elif state not in state_colors: state_colors[state] = Color(Myro.pickOne(Myro.getColorNames())) polygon.fill = state_colors[state] polygon.draw(win) retval.append(polygon) return retval
def __init__(self, title, width, height, data, x_label=None, y_label="Count"): self.colors = ["yellow", "red", "blue", "green", "orange", "purple"] + Myro.getColorNames() self.title = title self.x_label = x_label self.y_label = y_label self.width = width self.height = height self.data = data self.left, self.right, self.top, self.bottom = 100, 50, 100, 100 self.rotate = 45 self.use_height = .50 self.use_width = .75 self.win = Window(self.title, self.width, self.height) self.background = Rectangle((self.left, self.top), (self.width - self.right, self.height - self.bottom)) self.background.fill = Color("white") self.background.draw(self.win) self.button = Button((self.width - 70, self.height - 50), "Rescale") self.button.draw(self.win) self.button.connect("click", rescale) title = Text((self.width/2,self.top/2), self.title) title.color = Color("black") title.draw(self.win) if self.y_label: y_label = Text((self.left/2, self.height/2), self.y_label) y_label.fontSize = 12 y_label.rotate(90) y_label.color = Color("black") y_label.draw(self.win) if self.x_label: x_label = Text((self.left + (self.width - self.left - self.right)/2, (self.height - self.bottom) + self.bottom/2), self.x_label) x_label.fontSize = 12 x_label.color = Color("black") x_label.draw(self.win) self.bars = {} self.draw()