[reportlab-users] BarLabelFormat

Dirk Datzert reportlab-users@reportlab.com
Fri, 26 Jul 2002 20:04:35 +0200


Hi Marcus,

in one of your previous mails you told us that your code is defined this
way:

def _formatHour(self, seconds):
      # the code above

from an other mail on this list the example definition was:

def _formatHour(value):
  return doSomethingWith(value)

Your problems result in different definition !

>From the code of barchart.py line 311:

                if labelFmt is None:
                        labelText = None
                elif type(labelFmt) is StringType:
                        labelText = labelFmt % self.data[rowNo][colNo]
                elif type(labelFmt) is FunctionType:
                        labelText = labelFmt(self.data[rowNo][colNo])
                elif isinstance(labelFmt, Formatter):
                        #these are callable objects
                        labelText = labelFmt(self.data[rowNo][colNo])
                else:
...

labelFmt will be your function and will always called with 1 argument -
the value of the data-point

My suggestion don't define your format-function with self-referenced !

Regards,
Dirk


Marcus Vinicius Laranjeira schrieb:
> 
> Dinu,
> 
> I did exactely what you told me to, and this is wath happened:
> 
> Traceback (most recent call last):
>   File "test.py", line 11, in ?
>     renderPM.drawToFile(y, 'test.jpg', 'JPG')
>   File "D:\PYTHON22\reportlab\graphics\renderPM.py", line 446, in
> drawToFile
>     draw(d, c, 0, 0)
>   File "D:\PYTHON22\reportlab\graphics\renderPM.py", line 44, in draw
>     R.draw(drawing, canvas, x, y)
>   File "D:\PYTHON22\reportlab\graphics\renderPM.py", line 91, in draw
>     self.drawNode(drawing)
>   File "D:\PYTHON22\reportlab\graphics\renderPM.py", line 106, in
> drawNode
>     self.drawNodeDispatcher(node)
>   File "D:\PYTHON22\reportlab\graphics\renderbase.py", line 196, in
> drawNodeDisp
> atcher
>     self.drawGroup(node)
>   File "D:\PYTHON22\reportlab\graphics\renderbase.py", line 213, in
> drawGroup
>     node2 = childNode.provideNode()
>   File "D:\PYTHON22\reportlab\graphics\widgetbase.py", line 147, in
> provideNode
>     return self.draw()
>   File "D:\PYTHON22\reportlab\graphics\charts\barcharts.py", line 450,
> in draw
>     return self._drawFinish()
>   File "D:\PYTHON22\reportlab\graphics\charts\barcharts.py", line 193,
> in _drawF
> inish
>     g.add(self.makeBars())
>   File "D:\PYTHON22\reportlab\graphics\charts\barcharts.py", line 427,
> in makeBa
> rs
>     self._addBarLabel(g,rowNo,colNo,x,y,width,height)
>   File "D:\PYTHON22\reportlab\graphics\charts\barcharts.py", line 322,
> in _addBa
> rLabel
>     text = self._getLabelText(rowNo,colNo)
>   File "D:\PYTHON22\reportlab\graphics\charts\barcharts.py", line 311,
> in _getLa
> belText
>     raise Exception, msg
> Exception: Unknown formatter type <bound method AvgTTR._formatHour of
> <AvgTTR.A
> vgTTR instance at 0x0108CA90>>, expected string or function
> 
> Why! ?!?!?!?!
> 
> At 18:25 26/07/02 +0200, you wrote:
> 
> > Marcus Vinicius Laranjeira:
> >
> >>     self.bc.barLabelFormat = self._formatHour(self)
> >
> >
> > Try:
> >
> >   self.bc.barLabelFormat = self._formatHour
> >
> > Dinu
> >
> > _______________________________________________
> > reportlab-users mailing list
> > reportlab-users@reportlab.com
> > http://two.pairlist.net/mailman/listinfo/reportlab-users
> >
> 
> Marcus Vinicius Laranjeira
> MON Center
> 
> Datacraft do Brasil - (http://www.datacraft.com.br)
> R. Tenente Negrão, 140 - 8o. Andar
> Itaim Bibi - São Paulo - SP - 04530-030
> Tel: +55-11-3053-0241
> Fax: +55-11-3053-0220