#Autogenerated by ReportLab guiedit do not edit "Line chart with area percentiles" from reportlab.lib.normalDate import ND from reportlab.lib.colors import toColor from reportlab.graphics.charts.lineplots import SimpleTimeSeriesPlot, FillPairedData from reportlab.graphics.charts.legends import Legend from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin from reportlab.lib.utils import recursiveSetAttr class RollingPerformanceChart(_DrawingEditorMixin,Drawing): def __init__(self,width=400,height=200,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) self._add(self,SimpleTimeSeriesPlot(),name='chart',validate=None,desc=None) self._add(self,Legend(),name='legend',validate=None,desc=None) self.width = 518 self.height = int((700-3*20)/3) self.chart.x = 30 self.chart.y = 40 self.legend.columnMaximum = 2 self.legend.x = self.chart.x self.legend.y = self.chart.y-20 self.legend.alignment='right' self.legend.dy = 5 self.legend.dx = 5 self.legend.deltay = 1 self.legend.deltax = 0 self.legend.dxTextSpace = 2 self.legend.variColumn = 1 self.legend.strokeWidth = 0.2 self._data = [[ "5th percentile","25th percentile","median","75th percentile","95th percentile","Fund","Benchmark","Target Return" ],["20171231",0.0015599999999999998,0.0048,0.0092,0.011399999999999999,0.02016,0.0092,0.011200000000000002,0.0111],["20180131",0.0025599999999999998,0.006500000000000001,0.0105,0.015600000000000001,0.023099999999999996,0.004,0.0174,0.0127],["20180228",-0.00638,0.0045000000000000005,0.0055000000000000005,0.0104,0.01774,0.0197,0.0084,-0.0009],["20180331",0.00106,0.0034999999999999996,0.0126,0.0176,0.0194,0.0034999999999999996,0.0016,0.0097],["20180430",-0.005520000000000002,0.006500000000000001,0.009300000000000001,0.0216,0.03543999999999999,0.0216,0.013999999999999999,0.0007000000000000001],["20180531",0.01424,0.0189,0.024,0.0375,0.04122,0.0218,0.0381,0.0028000000000000004],["20180630",-0.01142,0.0079,0.011399999999999999,0.0131,0.021519999999999997,0.0037,0.0163,0.0083],["20180731",-0.00268,0.0025,0.0053,0.0152,0.01776,0.0105,-0.0032,0.006500000000000001],["20180831",-0.0113,-0.0074,-0.0014000000000000002,0.0011,0.005179999999999999,-0.0121,-0.0074,0.0124],["20180930",-0.0392,-0.0126,0.0043,0.013600000000000001,0.01506,0.0006,0.015700000000000002,-0.0034000000000000002],["20181031",0.0017799999999999997,0.0048,0.0129,0.013600000000000001,0.01436,0.013999999999999999,0.0037,0.011200000000000002],["20181130",-0.01304,-0.0021,0.003,0.0101,0.025779999999999997,0.0253,-0.0021,0.0005],["20181231",0.004559999999999999,0.0097,0.0106,0.0189,0.03813999999999999,0.0012,0.0106,0.0129],["20190131",-0.02942,0.0007000000000000001,0.0084,0.024,0.05398,0.0051,0.0084,0.0048],["20190228",-0.04622,0.0026,0.009300000000000001,0.0206,0.05177999999999999,0.0026,0.009300000000000001,0.0134],["20190331",-0.04394000000000001,0.0045000000000000005,0.0079,0.0115,0.026739999999999993,0.0115,0.0175,0.013999999999999999],["20190430",0.0025,0.0046,0.0069,0.012,0.018099999999999998,0.012,0.0069,0.0037],["20190531",-0.026040000000000008,0.0022,0.0124,0.0163,0.053659999999999985,0.07490000000000001,0.0066,0.0146],["20190630",-0.004540000000000001,-0.0017000000000000001,0.0115,0.0381,0.06112,0.059500000000000004,0.0138,0.013600000000000001]] for a in ('chart.yValueAxis.labels.fontName','chart.xValueAxis.labels.fontName','legend.fontName'): recursiveSetAttr(self,a,'Helvetica') for a in ('chart.yValueAxis.labels.fontSize','chart.xValueAxis.labels.fontSize','legend.fontSize'): recursiveSetAttr(self,a,10) self._percentileLabels = ['5th to 95th Percentile','25th to 75th Percentile'] self._colors = [toColor(_) for _ in ('lightgrey','darkgrey','black','darkblue','brown','olive')] self._lineWidth = 2 self.chart.width = self.width-self.chart.x - 5 self.chart.height = self.height - self.chart.y - 5 self.chart.yValueAxis.labelTextPostFormat = '%s%%' self.chart.yValueAxis.avoidBoundSpace = 4 self.chart.yValueAxis.rangeRound='both' self.chart.yValueAxis.strokeWidth = 0.2 self.chart.xValueAxis.strokeWidth = 0.2 self.chart.xValueAxis.labels[0].boxAnchor='nw' self.chart.xValueAxis.labels[-1].boxAnchor='ne' self.legend.strokeWidth=0 self.legend.strokeColor=None self.legend.autoXPadding = 100 self.chart.xValueAxis.visibleGrid = 1 self.chart.yValueAxis.visibleGrid = 1 def getContents(self): data = self._data names = data[0] names = [names[2]] + names[5:] data = list(zip(*data[1:])) #transpose dates, data = data[0], data[1:] dates = [ND(int(s)) for s in dates] cnv = lambda x: [_*100 if isinstance(_,(int,float)) else _ for _ in x] data = [cnv(i) for i in data] #convert all to float * 100 chart = self.chart lines = chart.lines data = [list(zip(dates,i)) for i in data] #now make normaldate,value pairs in each series #5 25 med 75 95 .... --> 5 95 25 75 med .... data = [data[0],data[4],data[1],data[3],data[2]] + data[5:] data[0] = FillPairedData(data[0],1) data[2] = FillPairedData(data[2],3) kolors = self._colors lines[0].strokeColor = lines[1].strokeColor = lines[0].fillColor = lines[1].fillColor = kolors[0] lines[2].strokeColor = lines[3].strokeColor = lines[2].fillColor = lines[3].fillColor = kolors[1] lines[0].strokeWidth = lines[1].strokeWidth = 0.2 lines[2].strokeWidth = lines[3].strokeWidth = 0.2 I = range(4,len(data)) for i in I: lines[i].strokeColor = kolors[i-4+2] for i in I: lines[i].strokeWidth = self._lineWidth chart.data = data legend = self.legend legend.colorNamePairs = [(kolors[0],self._percentileLabels[0]),(kolors[1],self._percentileLabels[1])] + [(kolors[i-4+2],names[i-4]) for i in I] return Drawing.getContents(self) if __name__=="__main__": #NORUNTESTS RollingPerformanceChart().save(formats=['pdf'],outDir='.',fnRoot=None)