Ticket #22: yvals_above_bars.patch

File yvals_above_bars.patch, 1.3 kB (added by aprzywecki@…, 3 years ago)

add option for showing y values over bars (VerticalBarChart? only)

  • pycha/chart.py

     
    653653        shadow=True, 
    654654        width=2 
    655655    ), 
     656    showyvals=Option( 
     657        hide=True, 
     658        fontSize=11 
     659    ), 
    656660    fillOpacity=1.0, 
    657661    shouldFill=True, 
    658662    barWidthFillFraction=0.75, 
  • pycha/bar.py

     
    7070            y = self.area.y + self.area.h * bar.y 
    7171            w = self.area.w * bar.w 
    7272            h = self.area.h * bar.h 
     73             
     74            # render yvals above bars 
     75            if not self.options.showyvals.hide: 
     76                cx.save() 
     77                cx.set_font_size(self.options.showyvals.fontSize) 
     78                cx.set_source_rgba(0, 0, 0, 1) 
     79                label = unicode(bar.yval) 
     80                extents = cx.text_extents(label) 
     81                labelWidth = extents[2] 
     82                labelHeight = extents[3] 
     83                cx.move_to(x+(w/2.0)-labelWidth, y-labelHeight) 
     84                cx.show_text(label) 
     85                cx.restore() 
    7386 
    7487            if w < 1 or h < 1: 
    7588                return # don't draw when the bar is too small