| 122 | | |
| 123 | | def _updateTicks(self): |
| 124 | | """Evaluates bar ticks""" |
| 125 | | super(StackedBarChart, self)._updateTicks() |
| 126 | | offset = (self.minxdelta * self.xscale) / 2 |
| 127 | | tmp = self.xticks |
| 128 | | self.xticks = [(1.0 - tick[0], tick[1]) for tick in self.yticks] |
| 129 | | self.yticks = [(tick[0] + offset, tick[1]) for tick in tmp] |
| 130 | | |
| 131 | | def _renderLines(self, cx): |
| 132 | | """Aux function for _renderBackground""" |
| 133 | | ticks = self.xticks |
| 134 | | for tick in ticks: |
| 135 | | self._renderLine(cx, tick, True) |
| 136 | | |
| 137 | | def _getShadowRectangle(self, x, y, w, h): |
| 138 | | return (x, y-2, w+2, h+4) |
| 139 | | |
| 140 | | def _renderXAxis(self, cx): |
| 141 | | """Draws the horizontal line representing the X axis""" |
| 142 | | cx.new_path() |
| 143 | | cx.move_to(self.area.x, self.area.y + self.area.h) |
| 144 | | cx.line_to(self.area.x + self.area.w, self.area.y + self.area.h) |
| 145 | | cx.close_path() |
| 146 | | cx.stroke() |
| 147 | | |
| 148 | | def _renderYAxis(self, cx): |
| 149 | | # draws the vertical line representing the Y axis |
| 150 | | cx.new_path() |
| 151 | | cx.move_to(self.area.x + self.area.origin * self.area.w, |
| 152 | | self.area.y) |
| 153 | | cx.line_to(self.area.x + self.area.origin * self.area.w, |
| 154 | | self.area.y + self.area.h) |
| 155 | | cx.close_path() |
| 156 | | cx.stroke() |
| 157 | | |
| 158 | | def _renderYVal(self, cx, label, labelW, labelH, barX, barY, barW, barH): |
| 159 | | y = barY + (barH / 2.0) + (labelH / 2.0) |
| 160 | | if self.options.yvals.inside: |
| 161 | | x = barX + barW - (1.2 * labelW) |
| 162 | | else: |
| 163 | | x = barX + barW + 0.2 * labelW |
| 164 | | |
| 165 | | # if the label doesn't fit to the left of the bar, put it to the right |
| 166 | | if x < barX: |
| 167 | | x = barX + barW + 0.2 * labelW |
| 168 | | |
| 169 | | cx.move_to(x, y) |
| 170 | | cx.show_text(label) |
| 171 | | |
| 172 | | |
| 173 | | class Rect(object): |
| 174 | | |
| 175 | | def __init__(self, x, y, w, h, xval, yval, name): |
| 176 | | self.x, self.y, self.w, self.h = x, y, w, h |
| 177 | | self.xval, self.yval = xval, yval |
| 178 | | self.name = name |
| 179 | | |
| 180 | | def __str__(self): |
| 181 | | return ("<pycha.bar.Rect@(%.2f, %.2f) %.2fx%.2f (%.2f, %.2f) %s>" |
| 182 | | % (self.x, self.y, self.w, self.h, self.xval, self.yval, |
| 183 | | self.name)) |