author | rptlab |
Tue, 30 Apr 2013 14:28:14 +0100 | |
branch | py33 |
changeset 3723 | 99aa837b6703 |
parent 3721 | 0c93dd8ff567 |
child 4056 | be1be82d76fa |
permissions | -rw-r--r-- |
3617 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2012 |
817 | 2 |
#see license.txt for license details |
2332 | 3 |
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/graphics/charts/textlabels.py |
4 |
__version__=''' $Id$ ''' |
|
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
5 |
import string |
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
6 |
|
909
a5ee7d2bdb17
Extracted validator functions into lib.validators.
dinu_gherman
parents:
817
diff
changeset
|
7 |
from reportlab.lib import colors |
2716 | 8 |
from reportlab.lib.utils import simpleSplit, _simpleSplit |
1245 | 9 |
from reportlab.lib.validators import isNumber, isNumberOrNone, OneOf, isColorOrNone, isString, \ |
3645 | 10 |
isTextAnchor, isBoxAnchor, isBoolean, NoneOr, isInstanceOf, isNoneOrString, isNoneOrCallable |
948 | 11 |
from reportlab.lib.attrmap import * |
3628
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
12 |
from reportlab.pdfbase.pdfmetrics import stringWidth, getAscentDescent |
909
a5ee7d2bdb17
Extracted validator functions into lib.validators.
dinu_gherman
parents:
817
diff
changeset
|
13 |
from reportlab.graphics.shapes import Drawing, Group, Circle, Rect, String, STATE_DEFAULTS |
1328 | 14 |
from reportlab.graphics.shapes import _PATH_OP_ARG_COUNT, _PATH_OP_NAMES, definePath |
1247
6f7061d9dd0c
Working LabelOffset usage, still need variable styles
rgbecker
parents:
1245
diff
changeset
|
15 |
from reportlab.graphics.widgetbase import Widget, PropHolder |
3368
afa025c34493
reportlab: new base font mechanism more fully applied
rgbecker
parents:
3308
diff
changeset
|
16 |
from reportlab.graphics.shapes import _baseGFontName |
909
a5ee7d2bdb17
Extracted validator functions into lib.validators.
dinu_gherman
parents:
817
diff
changeset
|
17 |
|
1328 | 18 |
_gs = None |
2173 | 19 |
_A2BA= { |
20 |
'x': {0:'n', 45:'ne', 90:'e', 135:'se', 180:'s', 225:'sw', 270:'w', 315: 'nw', -45: 'nw'}, |
|
21 |
'y': {0:'e', 45:'se', 90:'s', 135:'sw', 180:'w', 225:'nw', 270:'n', 315: 'ne', -45: 'ne'}, |
|
22 |
} |
|
1328 | 23 |
|
1341 | 24 |
def _pathNumTrunc(n): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
25 |
if int(n)==n: return int(n) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
26 |
return round(n,5) |
1341 | 27 |
|
28 |
def _processGlyph(G, truncate=1, pathReverse=0): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
29 |
O = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
30 |
P = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
31 |
R = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
32 |
for g in G+(('end',),): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
33 |
op = g[0] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
34 |
if O and op in ['moveTo', 'moveToClosed','end']: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
35 |
if O[0]=='moveToClosed': |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
36 |
O = O[1:] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
37 |
if pathReverse: |
3721 | 38 |
for i in range(0,len(P),2): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
39 |
P[i+1], P[i] = P[i:i+2] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
40 |
P.reverse() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
41 |
O.reverse() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
42 |
O.insert(0,'moveTo') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
43 |
O.append('closePath') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
44 |
i = 0 |
3721 | 45 |
if truncate: P = list(map(_pathNumTrunc,P)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
46 |
for o in O: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
47 |
j = i + _PATH_OP_ARG_COUNT[_PATH_OP_NAMES.index(o)] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
48 |
if o=='closePath': |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
49 |
R.append(o) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
50 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
51 |
R.append((o,)+ tuple(P[i:j])) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
52 |
i = j |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
53 |
O = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
54 |
P = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
55 |
O.append(op) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
56 |
P.extend(g[1:]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
57 |
return R |
1328 | 58 |
|
3368
afa025c34493
reportlab: new base font mechanism more fully applied
rgbecker
parents:
3308
diff
changeset
|
59 |
def _text2PathDescription(text, x=0, y=0, fontName=_baseGFontName, fontSize=1000, |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
60 |
anchor='start', truncate=1, pathReverse=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
61 |
global _gs |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
62 |
if not _gs: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
63 |
import _renderPM |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
64 |
_gs = _renderPM.gstate(1,1) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
65 |
from reportlab.graphics import renderPM |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
66 |
renderPM._setFont(_gs,fontName,fontSize) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
67 |
P = [] |
2868
4bcd244d8c3c
textlabels.py: fix undefined variable bug reported by riek@zem.uni-bonn.de
rgbecker
parents:
2716
diff
changeset
|
68 |
if not anchor=='start': |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
69 |
textLen = stringWidth(text, fontName,fontSize) |
2868
4bcd244d8c3c
textlabels.py: fix undefined variable bug reported by riek@zem.uni-bonn.de
rgbecker
parents:
2716
diff
changeset
|
70 |
if anchor=='end': |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
71 |
x = x-textLen |
2868
4bcd244d8c3c
textlabels.py: fix undefined variable bug reported by riek@zem.uni-bonn.de
rgbecker
parents:
2716
diff
changeset
|
72 |
elif anchor=='middle': |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
73 |
x = x - textLen/2. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
74 |
for g in _gs._stringPath(text,x,y): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
75 |
P.extend(_processGlyph(g,truncate=truncate,pathReverse=pathReverse)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
76 |
return P |
1341 | 77 |
|
3368
afa025c34493
reportlab: new base font mechanism more fully applied
rgbecker
parents:
3308
diff
changeset
|
78 |
def _text2Path(text, x=0, y=0, fontName=_baseGFontName, fontSize=1000, |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
79 |
anchor='start', truncate=1, pathReverse=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
80 |
return definePath(_text2PathDescription(text,x=x,y=y,fontName=fontName, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
81 |
fontSize=fontSize,anchor=anchor,truncate=truncate,pathReverse=pathReverse)) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
82 |
|
1807 | 83 |
_BA2TA={'w':'start','nw':'start','sw':'start','e':'end', 'ne': 'end', 'se':'end', 'n':'middle','s':'middle','c':'middle'} |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
84 |
class Label(Widget): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
85 |
"""A text label to attach to something else, such as a chart axis. |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
86 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
87 |
This allows you to specify an offset, angle and many anchor |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
88 |
properties relative to the label's origin. It allows, for example, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
89 |
angled multiline axis labels. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
90 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
91 |
# fairly straight port of Robin Becker's textbox.py to new widgets |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
92 |
# framework. |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
93 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
94 |
_attrMap = AttrMap( |
3271 | 95 |
x = AttrMapValue(isNumber,desc=''), |
96 |
y = AttrMapValue(isNumber,desc=''), |
|
3308 | 97 |
dx = AttrMapValue(isNumber,desc='delta x - offset'), |
98 |
dy = AttrMapValue(isNumber,desc='delta y - offset'), |
|
3271 | 99 |
angle = AttrMapValue(isNumber,desc='angle of label: default (0), 90 is vertical, 180 is upside down, etc'), |
100 |
boxAnchor = AttrMapValue(isBoxAnchor,desc='anchoring point of the label'), |
|
101 |
boxStrokeColor = AttrMapValue(isColorOrNone,desc='border color of the box'), |
|
102 |
boxStrokeWidth = AttrMapValue(isNumber,desc='border width'), |
|
103 |
boxFillColor = AttrMapValue(isColorOrNone,desc='the filling color of the box'), |
|
104 |
boxTarget = AttrMapValue(OneOf('normal','anti','lo','hi'),desc="one of ('normal','anti','lo','hi')"), |
|
105 |
fillColor = AttrMapValue(isColorOrNone,desc='label text color'), |
|
106 |
strokeColor = AttrMapValue(isColorOrNone,desc='label text border color'), |
|
107 |
strokeWidth = AttrMapValue(isNumber,desc='label text border width'), |
|
108 |
text = AttrMapValue(isString,desc='the actual text to display'), |
|
109 |
fontName = AttrMapValue(isString,desc='the name of the font used'), |
|
110 |
fontSize = AttrMapValue(isNumber,desc='the size of the font'), |
|
111 |
leading = AttrMapValue(isNumberOrNone,desc=''), |
|
112 |
width = AttrMapValue(isNumberOrNone,desc='the width of the label'), |
|
113 |
maxWidth = AttrMapValue(isNumberOrNone,desc='maximum width the label can grow to'), |
|
114 |
height = AttrMapValue(isNumberOrNone,desc='the height of the text'), |
|
115 |
textAnchor = AttrMapValue(isTextAnchor,desc='the anchoring point of the text inside the label'), |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
116 |
visible = AttrMapValue(isBoolean,desc="True if the label is to be drawn"), |
3271 | 117 |
topPadding = AttrMapValue(isNumber,desc='padding at top of box'), |
118 |
leftPadding = AttrMapValue(isNumber,desc='padding at left of box'), |
|
119 |
rightPadding = AttrMapValue(isNumber,desc='padding at right of box'), |
|
120 |
bottomPadding = AttrMapValue(isNumber,desc='padding at bottom of box'), |
|
3628
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
121 |
useAscentDescent = AttrMapValue(isBoolean,desc="If True then the font's Ascent & Descent will be used to compute default heights and baseline."), |
3645 | 122 |
customDrawChanger = AttrMapValue(isNoneOrCallable,desc="An instance of CustomDrawChanger to modify the behavior at draw time", _advancedUsage=1), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
123 |
) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
124 |
|
2362 | 125 |
def __init__(self,**kw): |
2363 | 126 |
self._setKeywords(**kw) |
127 |
self._setKeywords( |
|
128 |
_text = 'Multi-Line\nString', |
|
129 |
boxAnchor = 'c', |
|
130 |
angle = 0, |
|
131 |
x = 0, |
|
132 |
y = 0, |
|
133 |
dx = 0, |
|
134 |
dy = 0, |
|
135 |
topPadding = 0, |
|
136 |
leftPadding = 0, |
|
137 |
rightPadding = 0, |
|
138 |
bottomPadding = 0, |
|
139 |
boxStrokeWidth = 0.5, |
|
140 |
boxStrokeColor = None, |
|
2511
83406bfe8569
merge 2643:2644 from stable textlabels.py, barcharts.py: added boxTarget support
rgbecker
parents:
2363
diff
changeset
|
141 |
boxTarget = 'normal', |
2363 | 142 |
strokeColor = None, |
143 |
boxFillColor = None, |
|
144 |
leading = None, |
|
145 |
width = None, |
|
146 |
maxWidth = None, |
|
147 |
height = None, |
|
148 |
fillColor = STATE_DEFAULTS['fillColor'], |
|
149 |
fontName = STATE_DEFAULTS['fontName'], |
|
150 |
fontSize = STATE_DEFAULTS['fontSize'], |
|
151 |
strokeWidth = 0.1, |
|
152 |
textAnchor = 'start', |
|
153 |
visible = 1, |
|
3628
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
154 |
useAscentDescent = False, |
2363 | 155 |
) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
156 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
157 |
def setText(self, text): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
158 |
"""Set the text property. May contain embedded newline characters. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
159 |
Called by the containing chart or axis.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
160 |
self._text = text |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
161 |
|
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
162 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
163 |
def setOrigin(self, x, y): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
164 |
"""Set the origin. This would be the tick mark or bar top relative to |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
165 |
which it is defined. Called by the containing chart or axis.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
166 |
self.x = x |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
167 |
self.y = y |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
168 |
|
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
169 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
170 |
def demo(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
171 |
"""This shows a label positioned with its top right corner |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
172 |
at the top centre of the drawing, and rotated 45 degrees.""" |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
173 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
174 |
d = Drawing(200, 100) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
175 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
176 |
# mark the origin of the label |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
177 |
d.add(Circle(100,90, 5, fillColor=colors.green)) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
178 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
179 |
lab = Label() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
180 |
lab.setOrigin(100,90) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
181 |
lab.boxAnchor = 'ne' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
182 |
lab.angle = 45 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
183 |
lab.dx = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
184 |
lab.dy = -20 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
185 |
lab.boxStrokeColor = colors.green |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
186 |
lab.setText('Another\nMulti-Line\nString') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
187 |
d.add(lab) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
188 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
189 |
return d |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
190 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
191 |
def _getBoxAnchor(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
192 |
'''hook for allowing special box anchor effects''' |
2173 | 193 |
ba = self.boxAnchor |
194 |
if ba in ('autox', 'autoy'): |
|
195 |
angle = self.angle |
|
196 |
na = (int((angle%360)/45.)*45)%360 |
|
197 |
if not (na % 90): # we have a right angle case |
|
198 |
da = (angle - na) % 360 |
|
199 |
if abs(da)>5: |
|
200 |
na = na + (da>0 and 45 or -45) |
|
201 |
ba = _A2BA[ba[-1]][na] |
|
202 |
return ba |
|
1263 | 203 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
204 |
def computeSize(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
205 |
# the thing will draw in its own coordinate system |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
206 |
self._lineWidths = [] |
1951 | 207 |
topPadding = self.topPadding |
208 |
leftPadding = self.leftPadding |
|
209 |
rightPadding = self.rightPadding |
|
210 |
bottomPadding = self.bottomPadding |
|
2716 | 211 |
self._lines = simpleSplit(self._text,self.fontName,self.fontSize,self.maxWidth) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
212 |
if not self.width: |
2926 | 213 |
self._width = leftPadding+rightPadding |
214 |
if self._lines: |
|
215 |
self._lineWidths = [stringWidth(line,self.fontName,self.fontSize) for line in self._lines] |
|
216 |
self._width += max(self._lineWidths) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
217 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
218 |
self._width = self.width |
3628
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
219 |
if self.useAscentDescent: |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
220 |
self._ascent, self._descent = getAscentDescent(self.fontName,self.fontSize) |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
221 |
self._baselineRatio = self._ascent/(self._ascent-self._descent) |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
222 |
else: |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
223 |
self._baselineRatio = 1/1.2 |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
224 |
if self.leading: |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
225 |
self._leading = self.leading |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
226 |
elif self.useAscentDescent: |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
227 |
self._leading = self._ascent - self._descent |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
228 |
else: |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
229 |
self._leading = self.fontSize*1.2 |
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
230 |
self._height = self.height or (self._leading*len(self._lines) + topPadding + bottomPadding) |
1951 | 231 |
self._ewidth = (self._width-leftPadding-rightPadding) |
232 |
self._eheight = (self._height-topPadding-bottomPadding) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
233 |
boxAnchor = self._getBoxAnchor() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
234 |
if boxAnchor in ['n','ne','nw']: |
1951 | 235 |
self._top = -topPadding |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
236 |
elif boxAnchor in ['s','sw','se']: |
1951 | 237 |
self._top = self._height-topPadding |
1683 | 238 |
else: |
2200
be0cfccc662a
Fixed up tabs and whitespace in all source files
andy_robinson
parents:
2173
diff
changeset
|
239 |
self._top = 0.5*self._eheight |
1951 | 240 |
self._bottom = self._top - self._eheight |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
241 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
242 |
if boxAnchor in ['ne','e','se']: |
1951 | 243 |
self._left = leftPadding - self._width |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
244 |
elif boxAnchor in ['nw','w','sw']: |
1951 | 245 |
self._left = leftPadding |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
246 |
else: |
1951 | 247 |
self._left = -self._ewidth*0.5 |
248 |
self._right = self._left+self._ewidth |
|
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
249 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
250 |
def _getTextAnchor(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
251 |
'''This can be overridden to allow special effects''' |
1807 | 252 |
ta = self.textAnchor |
2173 | 253 |
if ta=='boxauto': ta = _BA2TA[self._getBoxAnchor()] |
1807 | 254 |
return ta |
1251 | 255 |
|
3645 | 256 |
def _rawDraw(self): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
257 |
_text = self._text |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
258 |
self._text = _text or '' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
259 |
self.computeSize() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
260 |
self._text = _text |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
261 |
g = Group() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
262 |
g.translate(self.x + self.dx, self.y + self.dy) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
263 |
g.rotate(self.angle) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
264 |
|
3628
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
265 |
y = self._top - self._leading*self._baselineRatio |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
266 |
textAnchor = self._getTextAnchor() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
267 |
if textAnchor == 'start': |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
268 |
x = self._left |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
269 |
elif textAnchor == 'middle': |
1951 | 270 |
x = self._left + self._ewidth*0.5 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
271 |
else: |
1951 | 272 |
x = self._right |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
273 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
274 |
# paint box behind text just in case they |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
275 |
# fill it |
1798 | 276 |
if self.boxFillColor or (self.boxStrokeColor and self.boxStrokeWidth): |
1951 | 277 |
g.add(Rect( self._left-self.leftPadding, |
278 |
self._bottom-self.bottomPadding, |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
279 |
self._width, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
280 |
self._height, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
281 |
strokeColor=self.boxStrokeColor, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
282 |
strokeWidth=self.boxStrokeWidth, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
283 |
fillColor=self.boxFillColor) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
284 |
) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
285 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
286 |
fillColor, fontName, fontSize = self.fillColor, self.fontName, self.fontSize |
3628
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
287 |
strokeColor, strokeWidth, leading = self.strokeColor, self.strokeWidth, self._leading |
3635 | 288 |
svgAttrs=getattr(self,'_svgAttrs',{}) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
289 |
if strokeColor: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
290 |
for line in self._lines: |
3646 | 291 |
s = _text2Path(line, x, y, fontName, fontSize, textAnchor) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
292 |
s.fillColor = fillColor |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
293 |
s.strokeColor = strokeColor |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
294 |
s.strokeWidth = strokeWidth |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
295 |
g.add(s) |
3628
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
296 |
y -= leading |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
297 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
298 |
for line in self._lines: |
3635 | 299 |
s = String(x, y, line, _svgAttrs=svgAttrs) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
300 |
s.textAnchor = textAnchor |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
301 |
s.fontName = fontName |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
302 |
s.fontSize = fontSize |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
303 |
s.fillColor = fillColor |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
304 |
g.add(s) |
3628
4843650935df
textlabels.py: add useAscentDescent option to Label class
rgbecker
parents:
3617
diff
changeset
|
305 |
y -= leading |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
306 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
307 |
return g |
1203 | 308 |
|
3645 | 309 |
def draw(self): |
310 |
customDrawChanger = getattr(self,'customDrawChanger',None) |
|
311 |
if customDrawChanger: |
|
312 |
customDrawChanger(True,self) |
|
313 |
try: |
|
314 |
return self._rawDraw() |
|
315 |
finally: |
|
316 |
customDrawChanger(False,self) |
|
317 |
else: |
|
318 |
return self._rawDraw() |
|
319 |
||
1453 | 320 |
class LabelDecorator: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
321 |
_attrMap = AttrMap( |
3271 | 322 |
x = AttrMapValue(isNumberOrNone,desc=''), |
323 |
y = AttrMapValue(isNumberOrNone,desc=''), |
|
324 |
dx = AttrMapValue(isNumberOrNone,desc=''), |
|
325 |
dy = AttrMapValue(isNumberOrNone,desc=''), |
|
326 |
angle = AttrMapValue(isNumberOrNone,desc=''), |
|
327 |
boxAnchor = AttrMapValue(isBoxAnchor,desc=''), |
|
328 |
boxStrokeColor = AttrMapValue(isColorOrNone,desc=''), |
|
329 |
boxStrokeWidth = AttrMapValue(isNumberOrNone,desc=''), |
|
330 |
boxFillColor = AttrMapValue(isColorOrNone,desc=''), |
|
331 |
fillColor = AttrMapValue(isColorOrNone,desc=''), |
|
332 |
strokeColor = AttrMapValue(isColorOrNone,desc=''), |
|
333 |
strokeWidth = AttrMapValue(isNumberOrNone),desc='', |
|
334 |
fontName = AttrMapValue(isNoneOrString,desc=''), |
|
335 |
fontSize = AttrMapValue(isNumberOrNone,desc=''), |
|
336 |
leading = AttrMapValue(isNumberOrNone,desc=''), |
|
337 |
width = AttrMapValue(isNumberOrNone,desc=''), |
|
338 |
maxWidth = AttrMapValue(isNumberOrNone,desc=''), |
|
339 |
height = AttrMapValue(isNumberOrNone,desc=''), |
|
340 |
textAnchor = AttrMapValue(isTextAnchor,desc=''), |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
341 |
visible = AttrMapValue(isBoolean,desc="True if the label is to be drawn"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
342 |
) |
1453 | 343 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
344 |
def __init__(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
345 |
self.textAnchor = 'start' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
346 |
self.boxAnchor = 'w' |
3723
99aa837b6703
second stage of port to Python 3.3; working hello world
rptlab
parents:
3721
diff
changeset
|
347 |
for a in self._attrMap.keys(): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
348 |
if not hasattr(self,a): setattr(self,a,None) |
1453 | 349 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
350 |
def decorate(self,l,L): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
351 |
chart,g,rowNo,colNo,x,y,width,height,x00,y00,x0,y0 = l._callOutInfo |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
352 |
L.setText(chart.categoryAxis.categoryNames[colNo]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
353 |
g.add(L) |
1453 | 354 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
355 |
def __call__(self,l): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
356 |
from copy import deepcopy |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
357 |
L = Label() |
3723
99aa837b6703
second stage of port to Python 3.3; working hello world
rptlab
parents:
3721
diff
changeset
|
358 |
for a,v in self.__dict__.items(): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
359 |
if v is None: v = getattr(l,a,None) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
360 |
setattr(L,a,v) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
361 |
self.decorate(l,L) |
1453 | 362 |
|
1251 | 363 |
isOffsetMode=OneOf('high','low','bar','axis') |
1247
6f7061d9dd0c
Working LabelOffset usage, still need variable styles
rgbecker
parents:
1245
diff
changeset
|
364 |
class LabelOffset(PropHolder): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
365 |
_attrMap = AttrMap( |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
366 |
posMode = AttrMapValue(isOffsetMode,desc="Where to base +ve offset"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
367 |
pos = AttrMapValue(isNumber,desc='Value for positive elements'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
368 |
negMode = AttrMapValue(isOffsetMode,desc="Where to base -ve offset"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
369 |
neg = AttrMapValue(isNumber,desc='Value for negative elements'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
370 |
) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
371 |
def __init__(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
372 |
self.posMode=self.negMode='axis' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
373 |
self.pos = self.neg = 0 |
1247
6f7061d9dd0c
Working LabelOffset usage, still need variable styles
rgbecker
parents:
1245
diff
changeset
|
374 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
375 |
def _getValue(self, chart, val): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
376 |
flipXY = chart._flipXY |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
377 |
A = chart.categoryAxis |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
378 |
jA = A.joinAxis |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
379 |
if val>=0: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
380 |
mode = self.posMode |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
381 |
delta = self.pos |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
382 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
383 |
mode = self.negMode |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
384 |
delta = self.neg |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
385 |
if flipXY: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
386 |
v = A._x |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
387 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
388 |
v = A._y |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
389 |
if jA: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
390 |
if flipXY: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
391 |
_v = jA._x |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
392 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
393 |
_v = jA._y |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
394 |
if mode=='high': |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
395 |
v = _v + jA._length |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
396 |
elif mode=='low': |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
397 |
v = _v |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
398 |
elif mode=='bar': |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
399 |
v = _v+val |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
400 |
return v+delta |
1247
6f7061d9dd0c
Working LabelOffset usage, still need variable styles
rgbecker
parents:
1245
diff
changeset
|
401 |
|
1284 | 402 |
NoneOrInstanceOfLabelOffset=NoneOr(isInstanceOf(LabelOffset)) |
1247
6f7061d9dd0c
Working LabelOffset usage, still need variable styles
rgbecker
parents:
1245
diff
changeset
|
403 |
|
3646 | 404 |
class PMVLabel(Label): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
405 |
_attrMap = AttrMap( |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
406 |
BASE=Label, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
407 |
) |
1203 | 408 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
409 |
def __init__(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
410 |
Label.__init__(self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
411 |
self._pmv = 0 |
1251 | 412 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
413 |
def _getBoxAnchor(self): |
3648
29290d936f9c
textlabels.py: call super methods in PMVLabel _get Box/Text Anchor
robin
parents:
3646
diff
changeset
|
414 |
a = Label._getBoxAnchor(self) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
415 |
if self._pmv<0: a = {'nw':'se','n':'s','ne':'sw','w':'e','c':'c','e':'w','sw':'ne','s':'n','se':'nw'}[a] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
416 |
return a |
1251 | 417 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
418 |
def _getTextAnchor(self): |
3648
29290d936f9c
textlabels.py: call super methods in PMVLabel _get Box/Text Anchor
robin
parents:
3646
diff
changeset
|
419 |
a = Label._getTextAnchor(self) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
420 |
if self._pmv<0: a = {'start':'end', 'middle':'middle', 'end':'start'}[a] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
421 |
return a |
1284 | 422 |
|
3646 | 423 |
class BarChartLabel(PMVLabel): |
424 |
""" |
|
425 |
An extended Label allowing for nudging, lines visibility etc |
|
426 |
""" |
|
427 |
_attrMap = AttrMap( |
|
428 |
BASE=PMVLabel, |
|
429 |
lineStrokeWidth = AttrMapValue(isNumberOrNone, desc="Non-zero for a drawn line"), |
|
430 |
lineStrokeColor = AttrMapValue(isColorOrNone, desc="Color for a drawn line"), |
|
431 |
fixedEnd = AttrMapValue(NoneOrInstanceOfLabelOffset, desc="None or fixed draw ends +/-"), |
|
432 |
fixedStart = AttrMapValue(NoneOrInstanceOfLabelOffset, desc="None or fixed draw starts +/-"), |
|
433 |
nudge = AttrMapValue(isNumber, desc="Non-zero sign dependent nudge"), |
|
434 |
) |
|
435 |
||
436 |
def __init__(self): |
|
437 |
PMVLabel.__init__(self) |
|
438 |
self.lineStrokeWidth = 0 |
|
439 |
self.lineStrokeColor = None |
|
440 |
self.fixedStart = self.fixedEnd = None |
|
441 |
self.nudge = 0 |
|
442 |
||
1284 | 443 |
class NA_Label(BarChartLabel): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
444 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
445 |
An extended Label allowing for nudging, lines visibility etc |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
446 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
447 |
_attrMap = AttrMap( |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
448 |
BASE=BarChartLabel, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
449 |
text = AttrMapValue(isNoneOrString, desc="Text to be used for N/A values"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
450 |
) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
451 |
def __init__(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
452 |
BarChartLabel.__init__(self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1558
diff
changeset
|
453 |
self.text = 'n/a' |
1798 | 454 |
NoneOrInstanceOfNA_Label=NoneOr(isInstanceOf(NA_Label)) |
3645 | 455 |
|
456 |
from reportlab.graphics.charts.utils import CustomDrawChanger |
|
457 |
class RedNegativeChanger(CustomDrawChanger): |
|
458 |
def __init__(self,fillColor=colors.red): |
|
459 |
CustomDrawChanger.__init__(self) |
|
460 |
self.fillColor = fillColor |
|
461 |
def _changer(self,obj): |
|
462 |
R = {} |
|
463 |
if obj._text.startswith('-'): |
|
464 |
R['fillColor'] = obj.fillColor |
|
465 |
obj.fillColor = self.fillColor |
|
466 |
return R |