#Autogenerated by ReportLab guiedit do not edit
import operator, palette, phrases
from reportlab.lib.formatters import DecimalFormatter
from reportlab.lib.colors import fidblue, fidred, fid_aa_palette, white, red, yellow
from reportlab.graphics.charts.legends import Legend
from reportlab.graphics.charts.barcharts import VerticalBarChart
from reportlab.graphics.charts.textlabels import Label
from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin, Rect, Line

class TBCDrawing(_DrawingEditorMixin,Drawing):
	def __init__(self,width=250,height=216,*args,**kw):
		apply(Drawing.__init__,(self,width,height)+args,kw)
		self._data = kw.get('_data',[(5000, 4880), (0,12000),(0,6000)])
		self._enddate = kw.get('_enddate','[enddate]')
		self._targetValue = kw.get('_targetValue',22000)
		self._lang = kw.get('_lang',phrases._langDefault)
		self.background = Rect(0,0,self.width,self.height,fillColor=white,strokeColor=fidblue,strokeWidth=1)
		self._add(self,Line(0,0,0,0,strokeWidth=0.5,strokeColor=fidred),name='tLine',validate=None,desc='The target line')
		self._add(self,Label(),name='tLabel',validate=None,desc='The target label')
		self._add(self,VerticalBarChart(),name='chart',validate=None,desc=None)
		self._add(self,Legend(),name='legend',validate=None,desc=None)
		self.chart.x=68
		self.chart.y=25.5
		self.chart.height=171.5
		self.chart.categoryAxis.style='stacked'
		self.chart.categoryAxis.visible=1
		self.chart.data = self._data
		self.chart.useAbsolute = 1
		self.chart.barWidth = 32.6
		self.chart.groupSpacing = 11
		self.chart.valueAxis.labelTextFormat =DecimalFormatter(places=0,thousandSep=phrases.thousandSep[self._lang],prefix=phrases.cc[self._lang])
		self.chart.bars.strokeWidth = 0.5
		self.chart.valueAxis.visibleTicks = 0
		self.chart.valueAxis.strokeWidth = 0.5
		self.chart.categoryAxis.strokeWidth = 0.5
		self.chart.categoryAxis.tickUp = self.chart.categoryAxis.tickDown = 0
		self.legend.x = 159
		self.legend.y = 1.4*72
		self.legend.alignment='right'
		self.legend.strokeWidth = 0.5
		self.legend.dx = 0.1*72
		self.legend.dy = 7.2
		self.legend.deltay = 13
		self.legend.dxTextSpace = 5
		self.chart.valueAxis.rangeRound='ceiling'
		self.chart.valueAxis.labels[0].visible=0
		self.tLine.x1 = self.chart.x
		self.tLabel.x = self.tLine.x2 = self.legend.x-4
		self.tLabel.boxAnchor = 'w'
		self.tLabel.fontSize = 9
		self.tLabel.fontName = 'Helvetica'
		self.chart.valueAxis.labels.fontSize = self.tLabel.fontSize
		self.chart.valueAxis.labels.fontName = self.tLabel.fontName
		self.legend.fontSize = self.tLabel.fontSize
		self.legend.fontName = self.tLabel.fontName
		self.tLabel.fillColor = fidred
		self.chart.bars[0].fillColor = fidblue
		self.chart.bars[1].fillColor = red
		self.chart.bars[2].fillColor = yellow
		tbc = phrases.tbclabels[self._lang]
		self.legend.colorNamePairs = [(self.chart.bars[2].fillColor, tbc.gr), (self.chart.bars[1].fillColor, tbc.rp), (self.chart.bars[0].fillColor, tbc.ininv)]
		self.chart.categoryAxis.categoryNames = [tbc.now,'']
		self.chart.categoryAxis.labels.dy = -3
		self.chart.categoryAxis.labels.fontName = self.tLabel.fontName
		self.chart.categoryAxis.labels.fontSize = self.tLabel.fontSize
		self.chart.categoryAxis.labels.boxAnchor = 'nw'
		self.chart.categoryAxis.labels.dx = -self.chart.barWidth*0.5

	def getContents(self):
		import operator
		tbc = phrases.tbclabels[self._lang]
		self.chart.valueAxis.valueMax = max(self._targetValue,self.chart.data[0][1]+self.chart.data[1][1]+self.chart.data[2][1])
		self.chart.categoryAxis.categoryNames[1]=tbc.by+self._enddate
		self.chart.width = self.chart._desiredCategoryAxisLength()
		self.chart.draw()
		self.tLabel.y = self.tLine.y1 = self.tLine.y2 = self.chart.valueAxis.scale(self._targetValue)
		self.tLabel.setText(tbc.target+self.chart.valueAxis.labelTextFormat(self._targetValue))
		return apply(Drawing.getContents,(self,))

if __name__=="__main__": #NORUNTESTS
	TBCDrawing().save(formats=['pdf'],outDir='.',fnRoot=None)
