| | 95 | # render yvals above/beside bars |
| | 96 | if self.options.yvals.show: |
| | 97 | cx.save() |
| | 98 | cx.set_font_size(self.options.yvals.fontSize) |
| | 99 | cx.set_source_rgb(*hex2rgb(self.options.yvals.fontColor)) |
| | 100 | |
| | 101 | label = unicode(bar.yval) |
| | 102 | extents = cx.text_extents(label) |
| | 103 | labelW = extents[2] |
| | 104 | labelH = extents[3] |
| | 105 | |
| | 106 | self._renderYVal(cx, label, labelW, labelH, x, y, w, h) |
| | 107 | |
| | 108 | cx.restore() |
| | 109 | |
| | 149 | def _renderYVal(self, cx, label, labelW, labelH, barX, barY, barW, barH): |
| | 150 | x = barX + (barW / 2.0) - (labelW / 2.0) |
| | 151 | if self.options.yvals.inside: |
| | 152 | y = barY + (1.5 * labelH) |
| | 153 | else: |
| | 154 | y = barY - 0.5 * labelH |
| | 155 | |
| | 156 | # if the label doesn't fit below the bar, put it above the bar |
| | 157 | if y > (barY + barH): |
| | 158 | y = barY - 0.5 * labelH |
| | 159 | |
| | 160 | cx.move_to(x, y) |
| | 161 | cx.show_text(label) |
| | 162 | |
| | 221 | def _renderYVal(self, cx, label, labelW, labelH, barX, barY, barW, barH): |
| | 222 | y = barY + (barH / 2.0) + (labelH / 2.0) |
| | 223 | if self.options.yvals.inside: |
| | 224 | x = barX + barW - (1.2 * labelW) |
| | 225 | else: |
| | 226 | x = barX + barW + 0.2 * labelW |
| | 227 | |
| | 228 | # if the label doesn't fit to the left of the bar, put it to the right |
| | 229 | if x < barX: |
| | 230 | x = barX + barW + 0.2 * labelW |
| | 231 | |
| | 232 | cx.move_to(x, y) |
| | 233 | cx.show_text(label) |
| | 234 | |