def drawLegend(self, x, y, Ltype, Color, String, line2F = False, startX = 0): if Ltype == 'Line': legend = LineLegend() legend.strokeWidth = 0.1 elif Ltype == 'Rect': legend = Legend() legend.dx = 5 legend.dy = 5 else: return -1 legend.alignment = 'right' legend.x = x legend.y = y legend.fontName = 'Helvetica' legend.fontSize = 7 legend.dxTextSpace = 4 legend.colorNamePairs = [(Color, String)] #We use private functions to calculate the width. Bad? maxWidth = legend._calculateMaxWidth(legend.colorNamePairs) maxWidth += legend.dx + legend.dxTextSpace + legend.autoXPadding #To fit more possible legends, we start writing legends at some points above #max Y val, and we allow max of 2 (5 size) lines, when we reach end of line 1, #pass the moveToline2F (True) to drawLegends, so next time it calls drawLegend #it passes proper x, y values. moveToline2F = False cantDrawF = False if (maxWidth + x) > self.width: if line2F != True: moveToline2F = True legend.y -= 7 if startX != 0: legend.x = startX else: cantDrawF = True else: cantDrawF = True if cantDrawF: print("Legend list too long. %s doesn't fit in graph" % String) maxWidth = -1 else: self.drawing.add(legend) return (maxWidth, moveToline2F)