"Treble pie" # Autogenerated by ReportLab guiedit do not edit from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin from reportlab.graphics.charts.doughnut import Doughnut from reportlab.lib.corp import white from reportlab.lib.colors import toColor class CompositionChart(_DrawingEditorMixin,Drawing): def __init__(self,width=400,height=200,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) self.width = 400 self.height = 200 innerpieWidth = 0.8108 self._add(self, Doughnut(), name="InnerPie", validate=None, desc=None) InnerPie = self.InnerPie InnerPie.height = self.width / 2 InnerPie.width = self.width / 2 InnerPie.x = (self.width / 2) - (self.InnerPie.width / 2) InnerPie.y = (self.height / 2) - (self.InnerPie.height / 2) InnerPie.data = [0.5, 0.30, 0.2] InnerPie.startAngle = 180 InnerPie.labels = ["Icyan", "Iviolet", "Iblue"] InnerPie.sideLabels = 0 InnerPie.slices.fontName = "Helvetica-Oblique" InnerPie.slices.fontSize = 9 InnerPie.slices.strokeColor = white InnerPie.slices.strokeWidth = 1.5 InnerPie.innerRadiusFraction = 0.075 InnerPie.slices[0].fillColor = toColor('lightblue') InnerPie.slices[1].fillColor = toColor('palegreen') InnerPie.slices[2].fillColor = toColor('darkblue')# darkblue InnerPie.slices.fontColor = white InnerPie.slices.labelRadius = 0.5 self._add(self, Doughnut(), name="InnerPie1", validate=None, desc=None) InnerPie1 = self.InnerPie1 InnerPie1.height = InnerPie.height InnerPie1.width = InnerPie.width InnerPie1.x = InnerPie.x InnerPie1.y = InnerPie.y InnerPie1.data = [0.5, 0.30, 0.2] InnerPie1.startAngle = 180 InnerPie1.sideLabels = 0 InnerPie1.slices.fontName = "Helvetica-Oblique" InnerPie1.slices.fontSize = 9 InnerPie1.slices.strokeColor = None # InnerPie1.slices.strokeWidth = 1.5 InnerPie1.innerRadiusFraction = 0.075 InnerPie1.slices.fillColor = None InnerPie1.slices[0].fillColor = None InnerPie1.slices[1].fillColor = None InnerPie1.slices[2].fillColor = None InnerPie1.slices.fontColor = white InnerPie1.slices.labelRadius = 0.25 self._add(self, Doughnut(), name="OuterPie", validate=None, desc=None) OuterPie = self.OuterPie OuterPie.width = 0.8043 * self.height OuterPie.height = 0.8043 * self.height OuterPie.innerRadiusFraction = 0.8108 OuterPie.x = (self.width / 2) - (self.OuterPie.width / 2) OuterPie.y = (self.height / 2) - (self.OuterPie.height / 2) OuterPie.startAngle = 180 OuterPie.data = [0.5, 0.3, 0.2] OuterPie.slices.strokeColor = white OuterPie.slices.strokeWidth = 1.5 OuterPie.slices.fontName = "Helvetica" OuterPie.slices.fontSize = 9 OuterPie.labels = None # ['Ocyan', 'Oviolet', 'Oblue'] OuterPie.slices.label_boxAnchor = "autox" OuterPie.simpleLabels = 0 OuterPie.slices.labelRadius = 1.05 OuterPie.slices[0].fillColor = toColor('magenta') OuterPie.slices[1].fillColor = toColor('darkgreen') self._add(self, Doughnut(), name="OuterPie1", validate=None, desc=None) OuterPie1 = self.OuterPie1 OuterPie1.width = OuterPie.width OuterPie1.height = OuterPie.height OuterPie1.innerRadiusFraction = 0.8108 OuterPie1.x = OuterPie.x OuterPie1.y = OuterPie.y OuterPie1.startAngle = 180 OuterPie1.data = [0.5, 0.3, 0.2] OuterPie1.slices.strokeColor = white OuterPie1.slices.strokeWidth = 1.5 OuterPie1.slices.fontName = "Helvetica" OuterPie1.slices.fontSize = 9 OuterPie1.slices[0].fillColor = toColor('orange') OuterPie1.slices[1].fillColor = toColor('pink') OuterPie1.slices.labelRadius = 0.90 OuterPie1.slices.label_boxAnchor = "autox" OuterPie1.simpleLabels = 0 def getContents(self): data = self.InnerPie.data InnerPie1 = self.InnerPie1 f = 100 / sum(data) data = [(f * v) for v in data] InnerPie1.data = data InnerPie1.labels = ["%.0f%%" % v for v in data] if max(data) >= 75: InnerPie1.startAngle = 150 if max(data) >= 75: InnerPie1.slices.labelRadius = 0.5 data = self.OuterPie.data OuterPie1 = self.OuterPie1 OuterPie1.data = data # OuterPie1.labels = ['%.0f%%' % (f*v) for v in data] return Drawing.getContents(self) if __name__ == "__main__": # NORUNTESTS CompositionChart().save(formats=["pdf"], outDir=".", fnRoot=None)