apply 3696 axes.py: fix bug in tick label positioning & fix reduce import py33
authorrobin
Wed, 31 Jul 2013 15:20:14 +0100
branchpy33
changeset 3754 7c3fb137ead7
parent 3753 251e8a89153d
child 3755 4b46b70be039
apply 3696 axes.py: fix bug in tick label positioning & fix reduce import
src/reportlab/graphics/charts/axes.py
--- a/src/reportlab/graphics/charts/axes.py	Wed Jul 31 14:45:23 2013 +0100
+++ b/src/reportlab/graphics/charts/axes.py	Wed Jul 31 15:20:14 2013 +0100
@@ -44,8 +44,10 @@
 from reportlab.graphics.widgets.grids import ShadedRect
 from reportlab.lib.colors import Color
 import copy
-from functools import reduce
-
+try:
+    reduce  # Python 2.x
+except NameError:
+    from functools import reduce
 
 # Helpers.
 def _findMinMaxValue(V, x, default, func, special=None):
@@ -754,13 +756,15 @@
                     label = self.labels[label]
                 else:
                     label = self.labels[i]
-                dy = label.dy
                 if pmv:
+                    _dy = label.dy
                     v = label._pmv = pmv[ic]
-                    if v<0: dy = -2*dy
+                    if v<0: _dy *= -2
+                else:
+                    _dy = 0
                 lpf = label.labelPosFrac
                 x = _x + (i+lpf) * barWidth
-                label.setOrigin(x, _y+dy)
+                label.setOrigin(x,_y+_dy)
                 label.setText(categoryNames[ic] or '')
                 g.add(label)
 
@@ -868,11 +872,13 @@
                     label = self.labels[i]
                 lpf = label.labelPosFrac
                 y = _y + (i+lpf) * barWidth
-                dx = label.dx
                 if pmv:
+                    _dx = label.dx
                     v = label._pmv = pmv[ic]
-                    if v<0: dx = -2*dx
-                label.setOrigin(_x+dx, y)
+                    if v<0: _dx *= -2
+                else:
+                    _dx = 0
+                label.setOrigin(_x+_dx, y)
                 label.setText(categoryNames[ic] or '')
                 g.add(label)
         return g