author | robin <robin@reportlab.com> |
Tue, 07 Mar 2017 10:00:34 +0000 | |
changeset 4330 | 617ffa6bbdc8 |
parent 4275 | 54ce6704aa97 |
child 4370 | 823a8c33ce43 |
permissions | -rw-r--r-- |
4330 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2017 |
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/lineplots.py |
3032 | 4 |
|
4252 | 5 |
__version__='3.3.0' |
3032 | 6 |
__doc__="""This module defines a very preliminary Line Plot example.""" |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
7 |
|
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
8 |
import string, time |
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
9 |
|
1683 | 10 |
from reportlab.lib import colors |
11 |
from reportlab.lib.validators import * |
|
948 | 12 |
from reportlab.lib.attrmap import * |
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
13 |
from reportlab.graphics.shapes import Drawing, Group, Rect, Line, PolyLine, Polygon, _SetKeyWordArgs |
920
254852733833
Switched to using PropHolder superclass for LinePlotProperties.
dinu_gherman
parents:
915
diff
changeset
|
14 |
from reportlab.graphics.widgetbase import Widget, TypedPropertyCollection, PropHolder |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
15 |
from reportlab.graphics.charts.textlabels import Label |
1616 | 16 |
from reportlab.graphics.charts.axes import XValueAxis, YValueAxis, AdjYValueAxis, NormalDateXValueAxis |
827
be88a17f65ca
Moved utility functions into new module utils.py.
dinu_gherman
parents:
817
diff
changeset
|
17 |
from reportlab.graphics.charts.utils import * |
1278 | 18 |
from reportlab.graphics.widgets.markers import uSymbol2Symbol, isSymbol, makeMarker |
2361 | 19 |
from reportlab.graphics.widgets.grids import Grid, DoubleGrid, ShadedRect, ShadedPolygon |
1628 | 20 |
from reportlab.pdfbase.pdfmetrics import stringWidth, getFont |
1692 | 21 |
from reportlab.graphics.charts.areas import PlotArea |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
22 |
|
889 | 23 |
# This might be moved again from here... |
920
254852733833
Switched to using PropHolder superclass for LinePlotProperties.
dinu_gherman
parents:
915
diff
changeset
|
24 |
class LinePlotProperties(PropHolder): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
25 |
_attrMap = AttrMap( |
1797 | 26 |
strokeWidth = AttrMapValue(isNumber, desc='Width of a line.'), |
2144
7122e953ee36
Add dasharray to allowed attributes for linechart lines
rgbecker
parents:
2099
diff
changeset
|
27 |
strokeColor = AttrMapValue(isColorOrNone, desc='Color of a line.'), |
7122e953ee36
Add dasharray to allowed attributes for linechart lines
rgbecker
parents:
2099
diff
changeset
|
28 |
strokeDashArray = AttrMapValue(isListOfNumbersOrNone, desc='Dash array of a line.'), |
3271 | 29 |
symbol = AttrMapValue(None, desc='Widget placed at data points.',advancedUsage=1), |
30 |
shader = AttrMapValue(None, desc='Shader Class.',advancedUsage=1), |
|
31 |
filler = AttrMapValue(None, desc='Filler Class.',advancedUsage=1), |
|
2426 | 32 |
name = AttrMapValue(isStringOrNone, desc='Name of the line.'), |
3271 | 33 |
inFill = AttrMapValue(isBoolean, desc='If true flood fill to x axis',advancedUsage=1), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
34 |
) |
889 | 35 |
|
4169
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
36 |
class InFillValue(int): |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
37 |
def __new__(cls,v,yValue=None): |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
38 |
self = int.__new__(cls,v) |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
39 |
self.yValue = yValue |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
40 |
return self |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
41 |
|
1797 | 42 |
class Shader(_SetKeyWordArgs): |
43 |
_attrMap = AttrMap(BASE=PlotArea, |
|
44 |
vertical = AttrMapValue(isBoolean, desc='If true shade to x axis'), |
|
45 |
colors = AttrMapValue(SequenceOf(isColorOrNone,lo=2,hi=2), desc='(AxisColor, LineColor)'), |
|
46 |
) |
|
47 |
||
48 |
def shade(self, lp, g, rowNo, rowColor, row): |
|
49 |
c = [None,None] |
|
50 |
c = getattr(self,'colors',c) or c |
|
51 |
if not c[0]: c[0] = getattr(lp,'fillColor',colors.white) |
|
52 |
if not c[1]: c[1] = rowColor |
|
889 | 53 |
|
2419 | 54 |
class NoFiller: |
55 |
def fill(self, lp, g, rowNo, rowColor, points): |
|
56 |
pass |
|
57 |
||
2361 | 58 |
class Filler: |
59 |
'''mixin providing simple polygon fill''' |
|
2419 | 60 |
_attrMap = AttrMap( |
61 |
fillColor = AttrMapValue(isColorOrNone, desc='filler interior color'), |
|
62 |
strokeColor = AttrMapValue(isColorOrNone, desc='filler edge color'), |
|
63 |
strokeWidth = AttrMapValue(isNumberOrNone, desc='filler edge width'), |
|
64 |
) |
|
65 |
def __init__(self,**kw): |
|
66 |
self.__dict__ = kw |
|
67 |
||
2361 | 68 |
def fill(self, lp, g, rowNo, rowColor, points): |
2419 | 69 |
g.add(Polygon(points, |
70 |
fillColor=getattr(self,'fillColor',rowColor), |
|
71 |
strokeColor=getattr(self,'strokeColor',rowColor), |
|
72 |
strokeWidth=getattr(self,'strokeWidth',0.1))) |
|
2361 | 73 |
|
74 |
class ShadedPolyFiller(Filler,ShadedPolygon): |
|
75 |
pass |
|
76 |
||
77 |
class PolyFiller(Filler,Polygon): |
|
78 |
pass |
|
79 |
||
3975
4a3599863c11
eliminate from . imports in favour of absolutes to allow running modules
robin
parents:
3800
diff
changeset
|
80 |
from reportlab.graphics.charts.linecharts import AbstractLineChart |
2427
1de04210b407
charts: autolegending in place, legend now has boxAnchor
rgbecker
parents:
2426
diff
changeset
|
81 |
class LinePlot(AbstractLineChart): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
82 |
"""Line plot with multiple lines. |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
83 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
84 |
Both x- and y-axis are value axis (so there are no seperate |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
85 |
X and Y versions of this class). |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
86 |
""" |
1692 | 87 |
_attrMap = AttrMap(BASE=PlotArea, |
3271 | 88 |
reversePlotOrder = AttrMapValue(isBoolean, desc='If true reverse plot order.',advancedUsage=1), |
89 |
lineLabelNudge = AttrMapValue(isNumber, desc='Distance between a data point and its label.',advancedUsage=1), |
|
1692 | 90 |
lineLabels = AttrMapValue(None, desc='Handle to the list of data point labels.'), |
91 |
lineLabelFormat = AttrMapValue(None, desc='Formatting string or function used for data point labels.'), |
|
2018 | 92 |
lineLabelArray = AttrMapValue(None, desc='explicit array of line label values, must match size of data if present.'), |
1692 | 93 |
joinedLines = AttrMapValue(isNumber, desc='Display data points joined with lines if true.'), |
94 |
strokeColor = AttrMapValue(isColorOrNone, desc='Color used for background border of plot area.'), |
|
95 |
fillColor = AttrMapValue(isColorOrNone, desc='Color used for background interior of plot area.'), |
|
96 |
lines = AttrMapValue(None, desc='Handle of the lines.'), |
|
97 |
xValueAxis = AttrMapValue(None, desc='Handle of the x axis.'), |
|
98 |
yValueAxis = AttrMapValue(None, desc='Handle of the y axis.'), |
|
99 |
data = AttrMapValue(None, desc='Data to be plotted, list of (lists of) x/y tuples.'), |
|
3271 | 100 |
annotations = AttrMapValue(None, desc='list of callables, will be called with self, xscale, yscale.',advancedUsage=1), |
101 |
behindAxes = AttrMapValue(isBoolean, desc='If true use separate line group.',advancedUsage=1), |
|
102 |
gridFirst = AttrMapValue(isBoolean, desc='If true use draw grids before axes.',advancedUsage=1), |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
103 |
) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
104 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
105 |
def __init__(self): |
1692 | 106 |
PlotArea.__init__(self) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
107 |
self.reversePlotOrder = 0 |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
108 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
109 |
self.xValueAxis = XValueAxis() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
110 |
self.yValueAxis = YValueAxis() |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
111 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
112 |
# this defines two series of 3 points. Just an example. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
113 |
self.data = [ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
114 |
((1,1), (2,2), (2.5,1), (3,3), (4,5)), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
115 |
((1,2), (2,3), (2.5,2), (3,4), (4,6)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
116 |
] |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
117 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
118 |
self.lines = TypedPropertyCollection(LinePlotProperties) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
119 |
self.lines.strokeWidth = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
120 |
self.lines[0].strokeColor = colors.red |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
121 |
self.lines[1].strokeColor = colors.blue |
1628 | 122 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
123 |
self.lineLabels = TypedPropertyCollection(Label) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
124 |
self.lineLabelFormat = None |
2018 | 125 |
self.lineLabelArray = None |
889 | 126 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
127 |
# this says whether the origin is inside or outside |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
128 |
# the bar - +10 means put the origin ten points |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
129 |
# above the tip of the bar if value > 0, or ten |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
130 |
# points inside if bar value < 0. This is different |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
131 |
# to label dx/dy which are not dependent on the |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
132 |
# sign of the data. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
133 |
self.lineLabelNudge = 10 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
134 |
# if you have multiple series, by default they butt |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
135 |
# together. |
1278 | 136 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
137 |
# New line chart attributes. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
138 |
self.joinedLines = 1 # Connect items with straight lines. |
1278 | 139 |
|
1936 | 140 |
#private attributes |
141 |
self._inFill = None |
|
2701 | 142 |
self.annotations = [] |
2848 | 143 |
self.behindAxes = 0 |
144 |
self.gridFirst = 0 |
|
1936 | 145 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
146 |
def demo(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
147 |
"""Shows basic use of a line chart.""" |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
148 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
149 |
drawing = Drawing(400, 200) |
1278 | 150 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
151 |
data = [ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
152 |
((1,1), (2,2), (2.5,1), (3,3), (4,5)), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
153 |
((1,2), (2,3), (2.5,2), (3.5,5), (4,6)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
154 |
] |
1628 | 155 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
156 |
lp = LinePlot() |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
157 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
158 |
lp.x = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
159 |
lp.y = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
160 |
lp.height = 125 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
161 |
lp.width = 300 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
162 |
lp.data = data |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
163 |
lp.joinedLines = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
164 |
lp.lineLabelFormat = '%2.0f' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
165 |
lp.strokeColor = colors.black |
839 | 166 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
167 |
lp.lines[0].strokeColor = colors.red |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
168 |
lp.lines[0].symbol = makeMarker('FilledCircle') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
169 |
lp.lines[1].strokeColor = colors.blue |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
170 |
lp.lines[1].symbol = makeMarker('FilledDiamond') |
1278 | 171 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
172 |
lp.xValueAxis.valueMin = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
173 |
lp.xValueAxis.valueMax = 5 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
174 |
lp.xValueAxis.valueStep = 1 |
839 | 175 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
176 |
lp.yValueAxis.valueMin = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
177 |
lp.yValueAxis.valueMax = 7 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
178 |
lp.yValueAxis.valueStep = 1 |
1628 | 179 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
180 |
drawing.add(lp) |
1278 | 181 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
182 |
return drawing |
1278 | 183 |
|
839 | 184 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
185 |
def calcPositions(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
186 |
"""Works out where they go. |
1278 | 187 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
188 |
Sets an attribute _positions which is a list of |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
189 |
lists of (x, y) matching the data. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
190 |
""" |
915 | 191 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
192 |
self._seriesCount = len(self.data) |
3721 | 193 |
self._rowLength = max(list(map(len,self.data))) |
1628 | 194 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
195 |
self._positions = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
196 |
for rowNo in range(len(self.data)): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
197 |
line = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
198 |
for colNo in range(len(self.data[rowNo])): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
199 |
datum = self.data[rowNo][colNo] # x,y value |
3800 | 200 |
if isinstance(datum[0],str): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
201 |
x = self.xValueAxis.scale(mktime(mkTimeTuple(datum[0]))) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
202 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
203 |
x = self.xValueAxis.scale(datum[0]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
204 |
y = self.yValueAxis.scale(datum[1]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
205 |
line.append((x, y)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
206 |
self._positions.append(line) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
207 |
|
2070 | 208 |
def _innerDrawLabel(self, rowNo, colNo, x, y): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
209 |
"Draw a label for a given item in the list." |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
210 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
211 |
labelFmt = self.lineLabelFormat |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
212 |
labelValue = self.data[rowNo][colNo][1] ### |
839 | 213 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
214 |
if labelFmt is None: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
215 |
labelText = None |
3800 | 216 |
elif isinstance(labelFmt,str): |
2018 | 217 |
if labelFmt == 'values': |
218 |
labelText = self.lineLabelArray[rowNo][colNo] |
|
219 |
else: |
|
220 |
labelText = labelFmt % labelValue |
|
3326 | 221 |
elif hasattr(labelFmt,'__call__'): |
3513
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
222 |
if not hasattr(labelFmt,'__labelFmtEX__'): |
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
223 |
labelText = labelFmt(labelValue) |
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
224 |
else: |
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
225 |
labelText = labelFmt(self,rowNo,colNo,x,y) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
226 |
else: |
3800 | 227 |
raise ValueError("Unknown formatter type %s, expected string or function"% labelFmt) |
839 | 228 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
229 |
if labelText: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
230 |
label = self.lineLabels[(rowNo, colNo)] |
3248
97d4415ab527
lineplots/linecharts: fix lineLabels.visble and also remove Formatter usage
rgbecker
parents:
3239
diff
changeset
|
231 |
if not label.visible: return |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
232 |
#hack to make sure labels are outside the bar |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
233 |
if y > 0: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
234 |
label.setOrigin(x, y + self.lineLabelNudge) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
235 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
236 |
label.setOrigin(x, y - self.lineLabelNudge) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
237 |
label.setText(labelText) |
2070 | 238 |
else: |
239 |
label = None |
|
240 |
return label |
|
241 |
||
242 |
def drawLabel(self, G, rowNo, colNo, x, y): |
|
243 |
'''Draw a label for a given item in the list. |
|
244 |
G must have an add method''' |
|
245 |
G.add(self._innerDrawLabel(rowNo,colNo,x,y)) |
|
839 | 246 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
247 |
def makeLines(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
248 |
g = Group() |
4169
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
249 |
yA = self.yValueAxis |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
250 |
xA = self.xValueAxis |
1998 | 251 |
bubblePlot = getattr(self,'_bubblePlot',None) |
252 |
if bubblePlot: |
|
253 |
bubbleR = min(yA._bubbleRadius,xA._bubbleRadius) |
|
254 |
bubbleMax = xA._bubbleMax |
|
889 | 255 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
256 |
labelFmt = self.lineLabelFormat |
889 | 257 |
|
3721 | 258 |
P = list(range(len(self._positions))) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
259 |
if self.reversePlotOrder: P.reverse() |
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
260 |
inFill = getattr(self,'_inFill',None) |
4236 | 261 |
lines = self.lines |
262 |
styleCount = len(lines) |
|
263 |
if inFill or [rowNo for rowNo in P if getattr(lines[rowNo%styleCount],'inFill',False)]: |
|
4169
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
264 |
inFillY = getattr(inFill,'yValue',None) |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
265 |
if inFillY is None: |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
266 |
inFillY = xA._y |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
267 |
else: |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
268 |
inFillY = yA.scale(inFillY) |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
269 |
inFillX0 = yA._x |
bffa5d27d3b4
lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents:
3975
diff
changeset
|
270 |
inFillX1 = inFillX0 + xA._length |
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
271 |
inFillG = getattr(self,'_inFillG',g) |
2848 | 272 |
lG = getattr(self,'_lineG',g) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
273 |
# Iterate over data rows. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
274 |
for rowNo in P: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
275 |
row = self._positions[rowNo] |
4236 | 276 |
styleRowNo = rowNo % styleCount |
277 |
rowStyle = lines[styleRowNo] |
|
3298 | 278 |
rowColor = getattr(rowStyle,'strokeColor',None) |
1998 | 279 |
dash = getattr(rowStyle, 'strokeDashArray', None) |
889 | 280 |
|
1998 | 281 |
if hasattr(rowStyle, 'strokeWidth'): |
282 |
width = rowStyle.strokeWidth |
|
4236 | 283 |
elif hasattr(lines, 'strokeWidth'): |
284 |
width = lines.strokeWidth |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
285 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
286 |
width = None |
920
254852733833
Switched to using PropHolder superclass for LinePlotProperties.
dinu_gherman
parents:
915
diff
changeset
|
287 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
288 |
# Iterate over data columns. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
289 |
if self.joinedLines: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
290 |
points = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
291 |
for xy in row: |
3367 | 292 |
points += [xy[0], xy[1]] |
2698
c9740075f020
graphics: minor fixes and improvements to lineplots
rgbecker
parents:
2690
diff
changeset
|
293 |
if inFill or getattr(rowStyle,'inFill',False): |
2516
cdfd0126c655
merge stable 2657:2658 axes/lineplots.py: fix inFill behaviour
rgbecker
parents:
2427
diff
changeset
|
294 |
fpoints = [inFillX0,inFillY] + points + [inFillX1,inFillY] |
2361 | 295 |
filler = getattr(rowStyle, 'filler', None) |
296 |
if filler: |
|
2419 | 297 |
filler.fill(self,inFillG,rowNo,rowColor,fpoints) |
2361 | 298 |
else: |
2516
cdfd0126c655
merge stable 2657:2658 axes/lineplots.py: fix inFill behaviour
rgbecker
parents:
2427
diff
changeset
|
299 |
inFillG.add(Polygon(fpoints,fillColor=rowColor,strokeColor=rowColor,strokeWidth=width or 0.1)) |
2426 | 300 |
if inFill in (None,0,2): |
1935 | 301 |
line = PolyLine(points,strokeColor=rowColor,strokeLineCap=0,strokeLineJoin=1) |
302 |
if width: |
|
303 |
line.strokeWidth = width |
|
304 |
if dash: |
|
305 |
line.strokeDashArray = dash |
|
2848 | 306 |
lG.add(line) |
889 | 307 |
|
1998 | 308 |
if hasattr(rowStyle, 'symbol'): |
309 |
uSymbol = rowStyle.symbol |
|
4236 | 310 |
elif hasattr(lines, 'symbol'): |
311 |
uSymbol = lines.symbol |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
312 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
313 |
uSymbol = None |
889 | 314 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
315 |
if uSymbol: |
1998 | 316 |
if bubblePlot: drow = self.data[rowNo] |
3513
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
317 |
for j,xy in enumerate(row): |
4275 | 318 |
if (styleRowNo,j) in lines: |
4236 | 319 |
juSymbol = getattr(lines[styleRowNo,j],'symbol',uSymbol) |
320 |
else: |
|
321 |
juSymbol = uSymbol |
|
322 |
if juSymbol is uSymbol: |
|
323 |
symbol = uSymbol |
|
324 |
symColor = rowColor |
|
325 |
else: |
|
326 |
symbol = juSymbol |
|
327 |
symColor = getattr(symbol,'fillColor',rowColor) |
|
328 |
symbol = uSymbol2Symbol(symbol,xy[0],xy[1],symColor) |
|
3513
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
329 |
if symbol: |
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
330 |
if bubblePlot: |
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
331 |
symbol.size = bubbleR*(drow[j][2]/bubbleMax)**0.5 |
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
332 |
g.add(symbol) |
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
333 |
else: |
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
334 |
if bubblePlot: drow = self.data[rowNo] |
7c77623a9b88
lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents:
3401
diff
changeset
|
335 |
for j,xy in enumerate(row): |
4236 | 336 |
juSymbol = getattr(lines[styleRowNo,j],'symbol',None) |
337 |
if not juSymbol: continue |
|
338 |
symColor = getattr(juSymbol,'fillColor',getattr(juSymbol,'strokeColor',rowColor)) |
|
339 |
symbol = uSymbol2Symbol(juSymbol,xy[0],xy[1],symColor) |
|
1998 | 340 |
if symbol: |
341 |
if bubblePlot: |
|
342 |
symbol.size = bubbleR*(drow[j][2]/bubbleMax)**0.5 |
|
343 |
g.add(symbol) |
|
1628 | 344 |
|
1998 | 345 |
# Draw data labels. |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
346 |
for colNo in range(len(row)): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
347 |
x1, y1 = row[colNo] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
348 |
self.drawLabel(g, rowNo, colNo, x1, y1) |
1278 | 349 |
|
1998 | 350 |
shader = getattr(rowStyle, 'shader', None) |
1797 | 351 |
if shader: shader.shade(self,g,rowNo,rowColor,row) |
352 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
353 |
return g |
889 | 354 |
|
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
355 |
def draw(self): |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
356 |
yA = self.yValueAxis |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
357 |
xA = self.xValueAxis |
1998 | 358 |
if getattr(self,'_bubblePlot',None): |
359 |
yA._bubblePlot = xA._bubblePlot = 1 |
|
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
360 |
yA.setPosition(self.x, self.y, self.height) |
2099 | 361 |
if yA: yA.joinAxis = xA |
362 |
if xA: xA.joinAxis = yA |
|
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
363 |
yA.configure(self.data) |
889 | 364 |
|
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
365 |
# if zero is in chart, put x axis there, otherwise use bottom. |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
366 |
xAxisCrossesAt = yA.scale(0) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
367 |
if ((xAxisCrossesAt > self.y + self.height) or (xAxisCrossesAt < self.y)): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
368 |
y = self.y |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
369 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
370 |
y = xAxisCrossesAt |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
371 |
|
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
372 |
xA.setPosition(self.x, y, self.width) |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
373 |
xA.configure(self.data) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
374 |
self.calcPositions() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
375 |
g = Group() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
376 |
g.add(self.makeBackground()) |
2848 | 377 |
if self._inFill or self.behindAxes: |
2516
cdfd0126c655
merge stable 2657:2658 axes/lineplots.py: fix inFill behaviour
rgbecker
parents:
2427
diff
changeset
|
378 |
xA._joinToAxis() |
2848 | 379 |
if self._inFill: |
380 |
self._inFillG = Group() |
|
381 |
g.add(self._inFillG) |
|
382 |
if self.behindAxes: |
|
383 |
self._lineG = Group() |
|
384 |
g.add(self._lineG) |
|
3550 | 385 |
xA._joinToAxis() |
386 |
yA._joinToAxis() |
|
3548
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
387 |
xAex = xA.visibleAxis and [xA._y] or [] |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
388 |
yAex = yA.visibleAxis and [yA._x] or [] |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
389 |
skipGrid = getattr(xA,'skipGrid','none') |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
390 |
if skipGrid!=None: |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
391 |
if skipGrid in ('both','top'): |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
392 |
yAex.append(xA._x+xA._length) |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
393 |
if skipGrid in ('both','bottom'): |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
394 |
yAex.append(xA._x) |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
395 |
skipGrid = getattr(yA,'skipGrid','none') |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
396 |
if skipGrid!=None: |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
397 |
if skipGrid in ('both','top'): |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
398 |
xAex.append(yA._y+yA._length) |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
399 |
if skipGrid in ('both','bottom'): |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
400 |
xAex.append(yA._y) |
2848 | 401 |
if self.gridFirst: |
3548
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
402 |
xA.makeGrid(g,parent=self,dim=yA.getGridDims,exclude=yAex) |
dfb3110087ad
axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents:
3513
diff
changeset
|
403 |
yA.makeGrid(g,parent=self,dim=xA.getGridDims,exclude=xAex) |
3401 | 404 |
g.add(xA.draw()) |
405 |
g.add(yA.draw()) |
|
2848 | 406 |
if not self.gridFirst: |
3206
25606c688529
charts: silly attempt at getting the grid to draw last
rgbecker
parents:
3032
diff
changeset
|
407 |
xAdgl = getattr(xA,'drawGridLast',False) |
25606c688529
charts: silly attempt at getting the grid to draw last
rgbecker
parents:
3032
diff
changeset
|
408 |
yAdgl = getattr(yA,'drawGridLast',False) |
3398
ac8ff8482dae
lineplots.py, axes.py: start support for excluding grid lines
rgbecker
parents:
3367
diff
changeset
|
409 |
if not xAdgl: xA.makeGrid(g,parent=self,dim=yA.getGridDims,exclude=yAex) |
ac8ff8482dae
lineplots.py, axes.py: start support for excluding grid lines
rgbecker
parents:
3367
diff
changeset
|
410 |
if not yAdgl: yA.makeGrid(g,parent=self,dim=xA.getGridDims,exclude=xAex) |
2701 | 411 |
annotations = getattr(self,'annotations',[]) |
2700 | 412 |
for a in annotations: |
2701 | 413 |
if getattr(a,'beforeLines',None): |
2700 | 414 |
g.add(a(self,xA.scale,yA.scale)) |
3239 | 415 |
g.add(self.makeLines()) |
3206
25606c688529
charts: silly attempt at getting the grid to draw last
rgbecker
parents:
3032
diff
changeset
|
416 |
if not self.gridFirst: |
3398
ac8ff8482dae
lineplots.py, axes.py: start support for excluding grid lines
rgbecker
parents:
3367
diff
changeset
|
417 |
if xAdgl: xA.makeGrid(g,parent=self,dim=yA.getGridDims,exclude=yAex) |
ac8ff8482dae
lineplots.py, axes.py: start support for excluding grid lines
rgbecker
parents:
3367
diff
changeset
|
418 |
if yAdgl: yA.makeGrid(g,parent=self,dim=xA.getGridDims,exclude=xAex) |
2700 | 419 |
for a in annotations: |
2701 | 420 |
if not getattr(a,'beforeLines',None): |
2700 | 421 |
g.add(a(self,xA.scale,yA.scale)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
422 |
return g |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
423 |
|
3217 | 424 |
def addCrossHair(self,name,xv,yv,strokeColor=colors.black,strokeWidth=1,beforeLines=True): |
425 |
from reportlab.graphics.shapes import Group, Line |
|
426 |
annotations = [a for a in getattr(self,'annotations',[]) if getattr(a,'name',None)!=name] |
|
427 |
def annotation(self,xScale,yScale): |
|
428 |
x = xScale(xv) |
|
429 |
y = yScale(yv) |
|
430 |
g = Group() |
|
3721 | 431 |
xA = xScale.__self__ #the x axis |
3217 | 432 |
g.add(Line(xA._x,y,xA._x+xA._length,y,strokeColor=strokeColor,strokeWidth=strokeWidth)) |
3721 | 433 |
yA = yScale.__self__ #the y axis |
3217 | 434 |
g.add(Line(x,yA._y,x,yA._y+yA._length,strokeColor=strokeColor,strokeWidth=strokeWidth)) |
435 |
return g |
|
436 |
annotation.beforeLines = beforeLines |
|
437 |
annotations.append(annotation) |
|
438 |
self.annotations = annotations |
|
439 |
||
2070 | 440 |
class LinePlot3D(LinePlot): |
441 |
_attrMap = AttrMap(BASE=LinePlot, |
|
442 |
theta_x = AttrMapValue(isNumber, desc='dx/dz'), |
|
443 |
theta_y = AttrMapValue(isNumber, desc='dy/dz'), |
|
444 |
zDepth = AttrMapValue(isNumber, desc='depth of an individual series'), |
|
445 |
zSpace = AttrMapValue(isNumber, desc='z gap around series'), |
|
446 |
) |
|
447 |
theta_x = .5 |
|
448 |
theta_y = .5 |
|
449 |
zDepth = 10 |
|
2079 | 450 |
zSpace = 3 |
2070 | 451 |
|
452 |
def calcPositions(self): |
|
453 |
LinePlot.calcPositions(self) |
|
454 |
nSeries = self._seriesCount |
|
455 |
zSpace = self.zSpace |
|
456 |
zDepth = self.zDepth |
|
457 |
if self.xValueAxis.style=='parallel_3d': |
|
2079 | 458 |
_3d_depth = nSeries*zDepth+(nSeries+1)*zSpace |
2070 | 459 |
else: |
460 |
_3d_depth = zDepth + 2*zSpace |
|
461 |
self._3d_dx = self.theta_x*_3d_depth |
|
462 |
self._3d_dy = self.theta_y*_3d_depth |
|
463 |
||
464 |
def _calc_z0(self,rowNo): |
|
465 |
zSpace = self.zSpace |
|
466 |
if self.xValueAxis.style=='parallel_3d': |
|
467 |
z0 = rowNo*(self.zDepth+zSpace)+zSpace |
|
468 |
else: |
|
469 |
z0 = zSpace |
|
470 |
return z0 |
|
471 |
||
472 |
def _zadjust(self,x,y,z): |
|
2071 | 473 |
return x+z*self.theta_x, y+z*self.theta_y |
2070 | 474 |
|
475 |
def makeLines(self): |
|
476 |
bubblePlot = getattr(self,'_bubblePlot',None) |
|
477 |
assert not bubblePlot, "_bubblePlot not supported for 3d yet" |
|
478 |
#if bubblePlot: |
|
479 |
# yA = self.yValueAxis |
|
480 |
# xA = self.xValueAxis |
|
481 |
# bubbleR = min(yA._bubbleRadius,xA._bubbleRadius) |
|
482 |
# bubbleMax = xA._bubbleMax |
|
483 |
||
484 |
labelFmt = self.lineLabelFormat |
|
2152 | 485 |
positions = self._positions |
2070 | 486 |
|
3721 | 487 |
P = list(range(len(positions))) |
2070 | 488 |
if self.reversePlotOrder: P.reverse() |
489 |
inFill = getattr(self,'_inFill',None) |
|
490 |
assert not inFill, "inFill not supported for 3d yet" |
|
491 |
#if inFill: |
|
492 |
# inFillY = self.xValueAxis._y |
|
493 |
# inFillX0 = self.yValueAxis._x |
|
494 |
# inFillX1 = inFillX0 + self.xValueAxis._length |
|
495 |
# inFillG = getattr(self,'_inFillG',g) |
|
496 |
zDepth = self.zDepth |
|
497 |
_zadjust = self._zadjust |
|
498 |
theta_x = self.theta_x |
|
499 |
theta_y = self.theta_y |
|
3975
4a3599863c11
eliminate from . imports in favour of absolutes to allow running modules
robin
parents:
3800
diff
changeset
|
500 |
from reportlab.graphics.charts.linecharts import _FakeGroup |
2070 | 501 |
F = _FakeGroup() |
2152 | 502 |
|
3975
4a3599863c11
eliminate from . imports in favour of absolutes to allow running modules
robin
parents:
3800
diff
changeset
|
503 |
from reportlab.graphics.charts.utils3d import _make_3d_line_info, find_intersections |
2152 | 504 |
if self.xValueAxis.style!='parallel_3d': |
505 |
tileWidth = getattr(self,'_3d_tilewidth',1) |
|
506 |
if getattr(self,'_find_intersections',None): |
|
507 |
from copy import copy |
|
3721 | 508 |
fpositions = list(map(copy,positions)) |
2152 | 509 |
I = find_intersections(fpositions,small=tileWidth) |
510 |
ic = None |
|
511 |
for i,j,x,y in I: |
|
512 |
if ic!=i: |
|
513 |
ic = i |
|
514 |
jc = 0 |
|
515 |
else: |
|
516 |
jc+=1 |
|
517 |
fpositions[i].insert(j+jc,(x,y)) |
|
518 |
tileWidth = None |
|
519 |
else: |
|
520 |
fpositions = positions |
|
521 |
else: |
|
522 |
tileWidth = None |
|
523 |
fpositions = positions |
|
2151 | 524 |
|
2070 | 525 |
# Iterate over data rows. |
526 |
styleCount = len(self.lines) |
|
527 |
for rowNo in P: |
|
2152 | 528 |
row = positions[rowNo] |
2070 | 529 |
n = len(row) |
530 |
rowStyle = self.lines[rowNo % styleCount] |
|
531 |
rowColor = rowStyle.strokeColor |
|
532 |
dash = getattr(rowStyle, 'strokeDashArray', None) |
|
533 |
z0 = self._calc_z0(rowNo) |
|
534 |
z1 = z0 + zDepth |
|
535 |
||
536 |
if hasattr(rowStyle, 'strokeWidth'): |
|
537 |
width = rowStyle.strokeWidth |
|
538 |
elif hasattr(self.lines, 'strokeWidth'): |
|
539 |
width = self.lines.strokeWidth |
|
540 |
else: |
|
541 |
width = None |
|
542 |
||
543 |
# Iterate over data columns. |
|
544 |
if self.joinedLines: |
|
545 |
if n: |
|
2152 | 546 |
frow = fpositions[rowNo] |
547 |
x0, y0 = frow[0] |
|
3721 | 548 |
for colNo in range(1,len(frow)): |
2152 | 549 |
x1, y1 = frow[colNo] |
2070 | 550 |
_make_3d_line_info( F, x0, x1, y0, y1, z0, z1, |
551 |
theta_x, theta_y, |
|
2152 | 552 |
rowColor, fillColorShaded=None, tileWidth=tileWidth, |
2070 | 553 |
strokeColor=None, strokeWidth=None, strokeDashArray=None, |
554 |
shading=0.1) |
|
555 |
x0, y0 = x1, y1 |
|
556 |
||
557 |
if hasattr(rowStyle, 'symbol'): |
|
558 |
uSymbol = rowStyle.symbol |
|
559 |
elif hasattr(self.lines, 'symbol'): |
|
560 |
uSymbol = self.lines.symbol |
|
561 |
else: |
|
562 |
uSymbol = None |
|
563 |
||
564 |
if uSymbol: |
|
565 |
for xy in row: |
|
566 |
x1, y1 = row[colNo] |
|
2072 | 567 |
x1, y1 = _zadjust(x1,y1,z0) |
2070 | 568 |
symbol = uSymbol2Symbol(uSymbol,xy[0],xy[1],rowColor) |
2072 | 569 |
if symbol: F.add((1,z0,z0,x1,y1,symbol)) |
2070 | 570 |
|
571 |
# Draw data labels. |
|
3721 | 572 |
for colNo in range(n): |
2070 | 573 |
x1, y1 = row[colNo] |
2072 | 574 |
x1, y1 = _zadjust(x1,y1,z0) |
2070 | 575 |
L = self._innerDrawLabel(rowNo, colNo, x1, y1) |
2072 | 576 |
if L: F.add((2,z0,z0,x1,y1,L)) |
2070 | 577 |
|
578 |
F.sort() |
|
579 |
g = Group() |
|
3328 | 580 |
for v in F.value(): g.add(v[-1]) |
2070 | 581 |
return g |
582 |
||
1616 | 583 |
_monthlyIndexData = [[(19971202, 100.0), |
584 |
(19971231, 100.1704367), |
|
585 |
(19980131, 101.5639577), |
|
586 |
(19980228, 102.1879927), |
|
587 |
(19980331, 101.6337257), |
|
588 |
(19980430, 102.7640446), |
|
589 |
(19980531, 102.9198038), |
|
590 |
(19980630, 103.25938789999999), |
|
591 |
(19980731, 103.2516421), |
|
592 |
(19980831, 105.4744329), |
|
593 |
(19980930, 109.3242705), |
|
594 |
(19981031, 111.9859291), |
|
595 |
(19981130, 110.9184642), |
|
596 |
(19981231, 110.9184642), |
|
597 |
(19990131, 111.9882532), |
|
598 |
(19990228, 109.7912614), |
|
599 |
(19990331, 110.24189629999999), |
|
600 |
(19990430, 110.4279321), |
|
601 |
(19990531, 109.33955469999999), |
|
602 |
(19990630, 108.2341748), |
|
603 |
(19990731, 110.21294469999999), |
|
604 |
(19990831, 110.9683062), |
|
605 |
(19990930, 112.4425371), |
|
606 |
(19991031, 112.7314032), |
|
607 |
(19991130, 112.3509645), |
|
608 |
(19991231, 112.3660659), |
|
609 |
(20000131, 110.9255248), |
|
610 |
(20000229, 110.5266306), |
|
611 |
(20000331, 113.3116101), |
|
612 |
(20000430, 111.0449133), |
|
613 |
(20000531, 111.702717), |
|
614 |
(20000630, 113.5832178)], |
|
615 |
[(19971202, 100.0), |
|
616 |
(19971231, 100.0), |
|
617 |
(19980131, 100.8), |
|
618 |
(19980228, 102.0), |
|
619 |
(19980331, 101.9), |
|
620 |
(19980430, 103.0), |
|
621 |
(19980531, 103.0), |
|
622 |
(19980630, 103.1), |
|
623 |
(19980731, 103.1), |
|
624 |
(19980831, 102.8), |
|
625 |
(19980930, 105.6), |
|
626 |
(19981031, 108.3), |
|
627 |
(19981130, 108.1), |
|
628 |
(19981231, 111.9), |
|
629 |
(19990131, 113.1), |
|
630 |
(19990228, 110.2), |
|
631 |
(19990331, 111.8), |
|
632 |
(19990430, 112.3), |
|
633 |
(19990531, 110.1), |
|
634 |
(19990630, 109.3), |
|
635 |
(19990731, 111.2), |
|
636 |
(19990831, 111.7), |
|
637 |
(19990930, 112.6), |
|
638 |
(19991031, 113.2), |
|
639 |
(19991130, 113.9), |
|
640 |
(19991231, 115.4), |
|
641 |
(20000131, 112.7), |
|
642 |
(20000229, 113.9), |
|
643 |
(20000331, 115.8), |
|
644 |
(20000430, 112.2), |
|
645 |
(20000531, 112.6), |
|
646 |
(20000630, 114.6)]] |
|
647 |
||
3650 | 648 |
class SimpleTimeSeriesPlot(LinePlot): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
649 |
"""A customized version of LinePlot. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
650 |
It uses NormalDateXValueAxis() and AdjYValueAxis() for the X and Y axes. |
3650 | 651 |
""" |
652 |
def __init__(self): |
|
653 |
LinePlot.__init__(self) |
|
654 |
self.xValueAxis = NormalDateXValueAxis() |
|
3652 | 655 |
self.yValueAxis = YValueAxis() |
3650 | 656 |
self.data = _monthlyIndexData |
657 |
||
658 |
class GridLinePlot(SimpleTimeSeriesPlot): |
|
659 |
"""A customized version of SimpleTimeSeriesSPlot. |
|
660 |
It uses NormalDateXValueAxis() and AdjYValueAxis() for the X and Y axes. |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
661 |
The chart has a default grid background with thin horizontal lines |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
662 |
aligned with the tickmarks (and labels). You can change the back- |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
663 |
ground to be any Grid or ShadedRect, or scale the whole chart. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
664 |
If you do provide a background, you can specify the colours of the |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
665 |
stripes with 'background.stripeColors'. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
666 |
""" |
1616 | 667 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
668 |
_attrMap = AttrMap(BASE=LinePlot, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
669 |
background = AttrMapValue(None, desc='Background for chart area (now Grid or ShadedRect).'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
670 |
scaleFactor = AttrMapValue(isNumberOrNone, desc='Scalefactor to apply to whole drawing.'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
671 |
) |
1616 | 672 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
673 |
def __init__(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
674 |
from reportlab.lib import colors |
3650 | 675 |
SimpleTimeSeriesPlot.__init__(self) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
676 |
self.scaleFactor = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
677 |
self.background = Grid() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
678 |
self.background.orientation = 'horizontal' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
679 |
self.background.useRects = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
680 |
self.background.useLines = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
681 |
self.background.strokeWidth = 0.5 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
682 |
self.background.strokeColor = colors.black |
1616 | 683 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
684 |
def demo(self,drawing=None): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
685 |
from reportlab.lib import colors |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
686 |
if not drawing: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
687 |
drawing = Drawing(400, 200) |
3650 | 688 |
lp = GridLinePlot() |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
689 |
lp.x = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
690 |
lp.y = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
691 |
lp.height = 125 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
692 |
lp.width = 300 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
693 |
lp.data = _monthlyIndexData |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
694 |
lp.joinedLines = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
695 |
lp.strokeColor = colors.black |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
696 |
c0 = colors.PCMYKColor(100,65,0,30, spotName='PANTONE 288 CV', density=100) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
697 |
lp.lines[0].strokeColor = c0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
698 |
lp.lines[0].strokeWidth = 2 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
699 |
lp.lines[0].strokeDashArray = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
700 |
c1 = colors.PCMYKColor(0,79,91,0, spotName='PANTONE Wm Red CV', density=100) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
701 |
lp.lines[1].strokeColor = c1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
702 |
lp.lines[1].strokeWidth = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
703 |
lp.lines[1].strokeDashArray = [3,1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
704 |
lp.xValueAxis.labels.fontSize = 10 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
705 |
lp.xValueAxis.labels.textAnchor = 'start' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
706 |
lp.xValueAxis.labels.boxAnchor = 'w' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
707 |
lp.xValueAxis.labels.angle = -45 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
708 |
lp.xValueAxis.labels.dx = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
709 |
lp.xValueAxis.labels.dy = -8 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
710 |
lp.xValueAxis.xLabelFormat = '{mm}/{yy}' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
711 |
lp.yValueAxis.labelTextFormat = '%5d%% ' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
712 |
lp.yValueAxis.tickLeft = 5 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
713 |
lp.yValueAxis.labels.fontSize = 10 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
714 |
lp.background = Grid() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
715 |
lp.background.stripeColors = [colors.pink, colors.lightblue] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
716 |
lp.background.orientation = 'vertical' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
717 |
drawing.add(lp,'plot') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
718 |
return drawing |
1616 | 719 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
720 |
def draw(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
721 |
xva, yva = self.xValueAxis, self.yValueAxis |
1803 | 722 |
if xva: xva.joinAxis = yva |
723 |
if yva: yva.joinAxis = xva |
|
1616 | 724 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
725 |
yva.setPosition(self.x, self.y, self.height) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
726 |
yva.configure(self.data) |
1616 | 727 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
728 |
# if zero is in chart, put x axis there, otherwise |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
729 |
# use bottom. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
730 |
xAxisCrossesAt = yva.scale(0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
731 |
if ((xAxisCrossesAt > self.y + self.height) or (xAxisCrossesAt < self.y)): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
732 |
y = self.y |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
733 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
734 |
y = xAxisCrossesAt |
1616 | 735 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
736 |
xva.setPosition(self.x, y, self.width) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
737 |
xva.configure(self.data) |
1616 | 738 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
739 |
back = self.background |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
740 |
if isinstance(back, Grid): |
1802 | 741 |
if back.orientation == 'vertical' and xva._tickValues: |
3721 | 742 |
xpos = list(map(xva.scale, [xva._valueMin] + xva._tickValues)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
743 |
steps = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
744 |
for i in range(len(xpos)-1): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
745 |
steps.append(xpos[i+1] - xpos[i]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
746 |
back.deltaSteps = steps |
1802 | 747 |
elif back.orientation == 'horizontal' and yva._tickValues: |
3721 | 748 |
ypos = list(map(yva.scale, [yva._valueMin] + yva._tickValues)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
749 |
steps = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
750 |
for i in range(len(ypos)-1): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
751 |
steps.append(ypos[i+1] - ypos[i]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
752 |
back.deltaSteps = steps |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
753 |
elif isinstance(back, DoubleGrid): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
754 |
# Ideally, these lines would not be needed... |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
755 |
back.grid0.x = self.x |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
756 |
back.grid0.y = self.y |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
757 |
back.grid0.width = self.width |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
758 |
back.grid0.height = self.height |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
759 |
back.grid1.x = self.x |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
760 |
back.grid1.y = self.y |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
761 |
back.grid1.width = self.width |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
762 |
back.grid1.height = self.height |
1616 | 763 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
764 |
# some room left for optimization... |
1802 | 765 |
if back.grid0.orientation == 'vertical' and xva._tickValues: |
3721 | 766 |
xpos = list(map(xva.scale, [xva._valueMin] + xva._tickValues)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
767 |
steps = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
768 |
for i in range(len(xpos)-1): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
769 |
steps.append(xpos[i+1] - xpos[i]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
770 |
back.grid0.deltaSteps = steps |
1802 | 771 |
elif back.grid0.orientation == 'horizontal' and yva._tickValues: |
3721 | 772 |
ypos = list(map(yva.scale, [yva._valueMin] + yva._tickValues)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
773 |
steps = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
774 |
for i in range(len(ypos)-1): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
775 |
steps.append(ypos[i+1] - ypos[i]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
776 |
back.grid0.deltaSteps = steps |
1802 | 777 |
if back.grid1.orientation == 'vertical' and xva._tickValues: |
3721 | 778 |
xpos = list(map(xva.scale, [xva._valueMin] + xva._tickValues)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
779 |
steps = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
780 |
for i in range(len(xpos)-1): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
781 |
steps.append(xpos[i+1] - xpos[i]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
782 |
back.grid1.deltaSteps = steps |
1802 | 783 |
elif back.grid1.orientation == 'horizontal' and yva._tickValues: |
3721 | 784 |
ypos = list(map(yva.scale, [yva._valueMin] + yva._tickValues)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
785 |
steps = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
786 |
for i in range(len(ypos)-1): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
787 |
steps.append(ypos[i+1] - ypos[i]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
788 |
back.grid1.deltaSteps = steps |
1616 | 789 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
790 |
self.calcPositions() |
1616 | 791 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
792 |
width, height, scaleFactor = self.width, self.height, self.scaleFactor |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
793 |
if scaleFactor and scaleFactor!=1: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
794 |
#g = Drawing(scaleFactor*width, scaleFactor*height) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
795 |
g.transform = (scaleFactor, 0, 0, scaleFactor,0,0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
796 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
797 |
g = Group() |
1616 | 798 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
799 |
g.add(self.makeBackground()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
800 |
g.add(self.xValueAxis) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
801 |
g.add(self.yValueAxis) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
802 |
g.add(self.makeLines()) |
1616 | 803 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
804 |
return g |
1616 | 805 |
|
1996
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
806 |
class AreaLinePlot(LinePlot): |
2306 | 807 |
'''we're given data in the form [(X1,Y11,..Y1M)....(Xn,Yn1,...YnM)]'''#' |
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
808 |
def __init__(self): |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
809 |
LinePlot.__init__(self) |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
810 |
self._inFill = 1 |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
811 |
self.reversePlotOrder = 1 |
2006 | 812 |
self.data = [(1,20,100,30),(2,11,50,15),(3,15,70,40)] |
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
813 |
|
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
814 |
def draw(self): |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
815 |
try: |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
816 |
odata = self.data |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
817 |
n = len(odata) |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
818 |
m = len(odata[0]) |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
819 |
S = n*[0] |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
820 |
self.data = [] |
3721 | 821 |
for i in range(1,m): |
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
822 |
D = [] |
3721 | 823 |
for j in range(n): |
1934
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
824 |
S[j] = S[j] + odata[j][i] |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
825 |
D.append((odata[j][0],S[j])) |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
826 |
self.data.append(D) |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
827 |
return LinePlot.draw(self) |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
828 |
finally: |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
829 |
self.data = odata |
104a813e8402
Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents:
1803
diff
changeset
|
830 |
|
1996
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
831 |
class SplitLinePlot(AreaLinePlot): |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
832 |
def __init__(self): |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
833 |
AreaLinePlot.__init__(self) |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
834 |
self.xValueAxis = NormalDateXValueAxis() |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
835 |
self.yValueAxis = AdjYValueAxis() |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
836 |
self.data=[(20030601,0.95,0.05,0.0),(20030701,0.95,0.05,0.0),(20030801,0.95,0.05,0.0),(20030901,0.95,0.05,0.0),(20031001,0.95,0.05,0.0),(20031101,0.95,0.05,0.0),(20031201,0.95,0.05,0.0),(20040101,0.95,0.05,0.0),(20040201,0.95,0.05,0.0),(20040301,0.95,0.05,0.0),(20040401,0.95,0.05,0.0),(20040501,0.95,0.05,0.0),(20040601,0.95,0.05,0.0),(20040701,0.95,0.05,0.0),(20040801,0.95,0.05,0.0),(20040901,0.95,0.05,0.0),(20041001,0.95,0.05,0.0),(20041101,0.95,0.05,0.0),(20041201,0.95,0.05,0.0),(20050101,0.95,0.05,0.0),(20050201,0.95,0.05,0.0),(20050301,0.95,0.05,0.0),(20050401,0.95,0.05,0.0),(20050501,0.95,0.05,0.0),(20050601,0.95,0.05,0.0),(20050701,0.95,0.05,0.0),(20050801,0.95,0.05,0.0),(20050901,0.95,0.05,0.0),(20051001,0.95,0.05,0.0),(20051101,0.95,0.05,0.0),(20051201,0.95,0.05,0.0),(20060101,0.95,0.05,0.0),(20060201,0.95,0.05,0.0),(20060301,0.95,0.05,0.0),(20060401,0.95,0.05,0.0),(20060501,0.95,0.05,0.0),(20060601,0.95,0.05,0.0),(20060701,0.95,0.05,0.0),(20060801,0.95,0.05,0.0),(20060901,0.95,0.05,0.0),(20061001,0.95,0.05,0.0),(20061101,0.95,0.05,0.0),(20061201,0.95,0.05,0.0),(20070101,0.95,0.05,0.0),(20070201,0.95,0.05,0.0),(20070301,0.95,0.05,0.0),(20070401,0.95,0.05,0.0),(20070501,0.95,0.05,0.0),(20070601,0.95,0.05,0.0),(20070701,0.95,0.05,0.0),(20070801,0.95,0.05,0.0),(20070901,0.95,0.05,0.0),(20071001,0.95,0.05,0.0),(20071101,0.95,0.05,0.0),(20071201,0.95,0.05,0.0),(20080101,0.95,0.05,0.0),(20080201,0.95,0.05,0.0),(20080301,0.95,0.05,0.0),(20080401,0.95,0.05,0.0),(20080501,0.95,0.05,0.0),(20080601,0.95,0.05,0.0),(20080701,0.95,0.05,0.0),(20080801,0.95,0.05,0.0),(20080901,0.95,0.05,0.0),(20081001,0.95,0.05,0.0),(20081101,0.95,0.05,0.0),(20081201,0.95,0.05,0.0),(20090101,0.95,0.05,0.0),(20090201,0.91,0.09,0.0),(20090301,0.91,0.09,0.0),(20090401,0.91,0.09,0.0),(20090501,0.91,0.09,0.0),(20090601,0.91,0.09,0.0),(20090701,0.91,0.09,0.0),(20090801,0.91,0.09,0.0),(20090901,0.91,0.09,0.0),(20091001,0.91,0.09,0.0),(20091101,0.91,0.09,0.0),(20091201,0.91,0.09,0.0),(20100101,0.91,0.09,0.0),(20100201,0.81,0.19,0.0),(20100301,0.81,0.19,0.0),(20100401,0.81,0.19,0.0),(20100501,0.81,0.19,0.0),(20100601,0.81,0.19,0.0),(20100701,0.81,0.19,0.0),(20100801,0.81,0.19,0.0),(20100901,0.81,0.19,0.0),(20101001,0.81,0.19,0.0),(20101101,0.81,0.19,0.0),(20101201,0.81,0.19,0.0),(20110101,0.81,0.19,0.0),(20110201,0.72,0.28,0.0),(20110301,0.72,0.28,0.0),(20110401,0.72,0.28,0.0),(20110501,0.72,0.28,0.0),(20110601,0.72,0.28,0.0),(20110701,0.72,0.28,0.0),(20110801,0.72,0.28,0.0),(20110901,0.72,0.28,0.0),(20111001,0.72,0.28,0.0),(20111101,0.72,0.28,0.0),(20111201,0.72,0.28,0.0),(20120101,0.72,0.28,0.0),(20120201,0.53,0.47,0.0),(20120301,0.53,0.47,0.0),(20120401,0.53,0.47,0.0),(20120501,0.53,0.47,0.0),(20120601,0.53,0.47,0.0),(20120701,0.53,0.47,0.0),(20120801,0.53,0.47,0.0),(20120901,0.53,0.47,0.0),(20121001,0.53,0.47,0.0),(20121101,0.53,0.47,0.0),(20121201,0.53,0.47,0.0),(20130101,0.53,0.47,0.0),(20130201,0.44,0.56,0.0),(20130301,0.44,0.56,0.0),(20130401,0.44,0.56,0.0),(20130501,0.44,0.56,0.0),(20130601,0.44,0.56,0.0),(20130701,0.44,0.56,0.0),(20130801,0.44,0.56,0.0),(20130901,0.44,0.56,0.0),(20131001,0.44,0.56,0.0),(20131101,0.44,0.56,0.0),(20131201,0.44,0.56,0.0),(20140101,0.44,0.56,0.0),(20140201,0.36,0.5,0.14),(20140301,0.36,0.5,0.14),(20140401,0.36,0.5,0.14),(20140501,0.36,0.5,0.14),(20140601,0.36,0.5,0.14),(20140701,0.36,0.5,0.14),(20140801,0.36,0.5,0.14),(20140901,0.36,0.5,0.14),(20141001,0.36,0.5,0.14),(20141101,0.36,0.5,0.14),(20141201,0.36,0.5,0.14),(20150101,0.36,0.5,0.14),(20150201,0.3,0.41,0.29),(20150301,0.3,0.41,0.29),(20150401,0.3,0.41,0.29),(20150501,0.3,0.41,0.29),(20150601,0.3,0.41,0.29),(20150701,0.3,0.41,0.29),(20150801,0.3,0.41,0.29),(20150901,0.3,0.41,0.29),(20151001,0.3,0.41,0.29),(20151101,0.3,0.41,0.29),(20151201,0.3,0.41,0.29),(20160101,0.3,0.41,0.29),(20160201,0.26,0.36,0.38),(20160301,0.26,0.36,0.38),(20160401,0.26,0.36,0.38),(20160501,0.26,0.36,0.38),(20160601,0.26,0.36,0.38),(20160701,0.26,0.36,0.38),(20160801,0.26,0.36,0.38),(20160901,0.26,0.36,0.38),(20161001,0.26,0.36,0.38),(20161101,0.26,0.36,0.38),(20161201,0.26,0.36,0.38),(20170101,0.26,0.36,0.38),(20170201,0.2,0.3,0.5),(20170301,0.2,0.3,0.5),(20170401,0.2,0.3,0.5),(20170501,0.2,0.3,0.5),(20170601,0.2,0.3,0.5),(20170701,0.2,0.3,0.5),(20170801,0.2,0.3,0.5),(20170901,0.2,0.3,0.5),(20171001,0.2,0.3,0.5),(20171101,0.2,0.3,0.5),(20171201,0.2,0.3,0.5),(20180101,0.2,0.3,0.5),(20180201,0.13,0.37,0.5),(20180301,0.13,0.37,0.5),(20180401,0.13,0.37,0.5),(20180501,0.13,0.37,0.5),(20180601,0.13,0.37,0.5),(20180701,0.13,0.37,0.5),(20180801,0.13,0.37,0.5),(20180901,0.13,0.37,0.5),(20181001,0.13,0.37,0.5),(20181101,0.13,0.37,0.5),(20181201,0.13,0.37,0.5),(20190101,0.13,0.37,0.5),(20190201,0.1,0.4,0.5),(20190301,0.1,0.4,0.5),(20190401,0.1,0.4,0.5),(20190501,0.1,0.4,0.5),(20190601,0.1,0.4,0.5),(20190701,0.1,0.4,0.5),(20190801,0.1,0.4,0.5),(20190901,0.1,0.4,0.5),(20191001,0.1,0.4,0.5),(20191101,0.1,0.4,0.5),(20191201,0.1,0.4,0.5),(20200101,0.1,0.4,0.5)] |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
837 |
self.yValueAxis.requiredRange = None |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
838 |
self.yValueAxis.leftAxisPercent = 0 |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
839 |
self.yValueAxis.leftAxisOrigShiftMin = 0 |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
840 |
self.yValueAxis.leftAxisOrigShiftIPC = 0 |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
841 |
self.lines[0].strokeColor = colors.toColor(0x0033cc) |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
842 |
self.lines[1].strokeColor = colors.toColor(0x99c3ff) |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
843 |
self.lines[2].strokeColor = colors.toColor(0xCC0033) |
0150666f5022
dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents:
1974
diff
changeset
|
844 |
|
1628 | 845 |
def _maxWidth(T, fontName, fontSize): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
846 |
'''return max stringWidth for the list of strings T''' |
3800 | 847 |
if not isinstance(T,(tuple,list)): T = (T,) |
3721 | 848 |
T = [_f for _f in T if _f] |
849 |
return T and max(list(map(lambda t,sW=stringWidth,fN=fontName, fS=fontSize: sW(t,fN,fS),T))) or 0 |
|
1628 | 850 |
|
851 |
class ScatterPlot(LinePlot): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
852 |
"""A scatter plot widget""" |
1628 | 853 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
854 |
_attrMap = AttrMap(BASE=LinePlot, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
855 |
width = AttrMapValue(isNumber, desc="Width of the area inside the axes"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
856 |
height = AttrMapValue(isNumber, desc="Height of the area inside the axes"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
857 |
outerBorderOn = AttrMapValue(isBoolean, desc="Is there an outer border (continuation of axes)"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
858 |
outerBorderColor = AttrMapValue(isColorOrNone, desc="Color of outer border (if any)"), |
3271 | 859 |
labelOffset = AttrMapValue(isNumber, desc="Space between label and Axis (or other labels)",advancedUsage=1), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
860 |
axisTickLengths = AttrMapValue(isNumber, desc="Lenth of the ticks on both axes"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
861 |
axisStrokeWidth = AttrMapValue(isNumber, desc="Stroke width for both axes"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
862 |
xLabel = AttrMapValue(isString, desc="Label for the whole X-Axis"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
863 |
yLabel = AttrMapValue(isString, desc="Label for the whole Y-Axis"), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
864 |
data = AttrMapValue(isAnything, desc='Data points - a list of x/y tuples.'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
865 |
strokeColor = AttrMapValue(isColorOrNone, desc='Color used for border of plot area.'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
866 |
fillColor = AttrMapValue(isColorOrNone, desc='Color used for background interior of plot area.'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
867 |
leftPadding = AttrMapValue(isNumber, desc='Padding on left of drawing'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
868 |
rightPadding = AttrMapValue(isNumber, desc='Padding on right of drawing'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
869 |
topPadding = AttrMapValue(isNumber, desc='Padding at top of drawing'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
870 |
bottomPadding = AttrMapValue(isNumber, desc='Padding at bottom of drawing'), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
871 |
) |
1628 | 872 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
873 |
def __init__(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
874 |
LinePlot.__init__(self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
875 |
self.width = 142 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
876 |
self.height = 77 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
877 |
self.outerBorderOn = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
878 |
self.outerBorderColor = colors.black |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
879 |
self.background = None |
1628 | 880 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
881 |
_labelOffset = 3 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
882 |
_axisTickLengths = 2 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
883 |
_axisStrokeWidth = 0.5 |
1628 | 884 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
885 |
self.yValueAxis.valueMin = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
886 |
self.yValueAxis.valueMax = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
887 |
self.yValueAxis.valueStep = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
888 |
self.yValueAxis.labelTextFormat = '%s' |
1628 | 889 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
890 |
self.xLabel="X Lable" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
891 |
self.xValueAxis.labels.fontSize = 6 |
1628 | 892 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
893 |
self.yLabel="Y Lable" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
894 |
self.yValueAxis.labels.fontSize = 6 |
1628 | 895 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
896 |
self.data =[((0.030, 62.73), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
897 |
(0.074, 54.363), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
898 |
(1.216, 17.964)), |
1628 | 899 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
900 |
((1.360, 11.621), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
901 |
(1.387, 50.011), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
902 |
(1.428, 68.953)), |
1628 | 903 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
904 |
((1.444, 86.888), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
905 |
(1.754, 35.58), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
906 |
(1.766, 36.05))] |
1628 | 907 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
908 |
#values for lineplot |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
909 |
self.joinedLines = 0 |
1628 | 910 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
911 |
self.leftPadding=5 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
912 |
self.rightPadding=10 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
913 |
self.topPadding=5 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
914 |
self.bottomPadding=5 |
1628 | 915 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
916 |
self.x = self.leftPadding+_axisTickLengths+(_labelOffset*2) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
917 |
self.x=self.x+_maxWidth(str(self.yValueAxis.valueMax), self.yValueAxis.labels.fontName, self.yValueAxis.labels.fontSize) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
918 |
self.y = self.bottomPadding+_axisTickLengths+_labelOffset+self.xValueAxis.labels.fontSize |
1628 | 919 |
|
1683 | 920 |
self.xValueAxis.labels.dy = -_labelOffset |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
921 |
self.xValueAxis.tickDown = _axisTickLengths |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
922 |
self.xValueAxis.strokeWidth = _axisStrokeWidth |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
923 |
self.xValueAxis.rangeRound='both' |
1683 | 924 |
self.yValueAxis.labels.dx = -_labelOffset |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
925 |
self.yValueAxis.tickLeft = _axisTickLengths |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
926 |
self.yValueAxis.strokeWidth = _axisStrokeWidth |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
927 |
self.yValueAxis.rangeRound='both' |
1628 | 928 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
929 |
self.lineLabelFormat="%.2f" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
930 |
self.lineLabels.fontSize = 5 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
931 |
self.lineLabels.boxAnchor = 'e' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
932 |
self.lineLabels.dx = -2 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
933 |
self.lineLabelNudge = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
934 |
self.lines.symbol=makeMarker('FilledCircle',size=3) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
935 |
self.lines[1].symbol=makeMarker('FilledDiamond',size=3) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
936 |
self.lines[2].symbol=makeMarker('FilledSquare',size=3) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
937 |
self.lines[2].strokeColor = colors.green |
1628 | 938 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
939 |
def _getDrawingDimensions(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
940 |
tx = self.leftPadding+self.yValueAxis.tickLeft+(self.yValueAxis.labels.dx*2)+self.xValueAxis.labels.fontSize |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
941 |
tx=tx+(5*_maxWidth(str(self.yValueAxis.valueMax), self.yValueAxis.labels.fontName, self.yValueAxis.labels.fontSize)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
942 |
tx=tx+self.width+self.rightPadding |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
943 |
t=('%.2f%%'%self.xValueAxis.valueMax) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
944 |
tx=tx+(_maxWidth(t, self.yValueAxis.labels.fontName, self.yValueAxis.labels.fontSize)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
945 |
ty = self.bottomPadding+self.xValueAxis.tickDown+(self.xValueAxis.labels.dy*2)+(self.xValueAxis.labels.fontSize*2) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
946 |
ty=ty+self.yValueAxis.labels.fontSize+self.height+self.topPadding |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
947 |
#print (tx, ty) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
948 |
return (tx,ty) |
1628 | 949 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
950 |
def demo(self,drawing=None): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
951 |
if not drawing: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
952 |
tx,ty=self._getDrawingDimensions() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
953 |
drawing = Drawing(tx,ty) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
954 |
drawing.add(self.draw()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
955 |
return drawing |
1628 | 956 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
957 |
def draw(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
958 |
ascent=getFont(self.xValueAxis.labels.fontName).face.ascent |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
959 |
if ascent==0: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
960 |
ascent=0.718 # default (from helvetica) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
961 |
ascent=ascent*self.xValueAxis.labels.fontSize # normalize |
1628 | 962 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
963 |
#basic LinePlot - does the Axes, Ticks etc |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
964 |
lp = LinePlot.draw(self) |
1628 | 965 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
966 |
xLabel = self.xLabel |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
967 |
if xLabel: #Overall label for the X-axis |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
968 |
xl=Label() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
969 |
xl.x = (self.x+self.width)/2.0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
970 |
xl.y = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
971 |
xl.fontName = self.xValueAxis.labels.fontName |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
972 |
xl.fontSize = self.xValueAxis.labels.fontSize |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
973 |
xl.setText(xLabel) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
974 |
lp.add(xl) |
1628 | 975 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
976 |
yLabel = self.yLabel |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
977 |
if yLabel: #Overall label for the Y-axis |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
978 |
yl=Label() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
979 |
yl.angle = 90 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
980 |
yl.x = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
981 |
yl.y = (self.y+self.height/2.0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
982 |
yl.fontName = self.yValueAxis.labels.fontName |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
983 |
yl.fontSize = self.yValueAxis.labels.fontSize |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
984 |
yl.setText(yLabel) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
985 |
lp.add(yl) |
1628 | 986 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
987 |
# do a bounding box - in the same style as the axes |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
988 |
if self.outerBorderOn: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
989 |
lp.add(Rect(self.x, self.y, self.width, self.height, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
990 |
strokeColor = self.outerBorderColor, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
991 |
strokeWidth = self.yValueAxis.strokeWidth, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
992 |
fillColor = None)) |
1628 | 993 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
994 |
lp.shift(self.leftPadding, self.bottomPadding) |
1628 | 995 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
996 |
return lp |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
997 |
|
839 | 998 |
def sample1a(): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
999 |
"A line plot with non-equidistant points in x-axis." |
1628 | 1000 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1001 |
drawing = Drawing(400, 200) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1002 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1003 |
data = [ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1004 |
((1,1), (2,2), (2.5,1), (3,3), (4,5)), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1005 |
((1,2), (2,3), (2.5,2), (3.5,5), (4,6)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1006 |
] |
1628 | 1007 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1008 |
lp = LinePlot() |
839 | 1009 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1010 |
lp.x = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1011 |
lp.y = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1012 |
lp.height = 125 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1013 |
lp.width = 300 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1014 |
lp.data = data |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1015 |
lp.joinedLines = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1016 |
lp.strokeColor = colors.black |
839 | 1017 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1018 |
lp.lines.symbol = makeMarker('UK_Flag') |
1336 | 1019 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1020 |
lp.lines[0].strokeWidth = 2 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1021 |
lp.lines[1].strokeWidth = 4 |
920
254852733833
Switched to using PropHolder superclass for LinePlotProperties.
dinu_gherman
parents:
915
diff
changeset
|
1022 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1023 |
lp.xValueAxis.valueMin = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1024 |
lp.xValueAxis.valueMax = 5 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1025 |
lp.xValueAxis.valueStep = 1 |
839 | 1026 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1027 |
lp.yValueAxis.valueMin = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1028 |
lp.yValueAxis.valueMax = 7 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1029 |
lp.yValueAxis.valueStep = 1 |
1628 | 1030 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1031 |
drawing.add(lp) |
839 | 1032 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1033 |
return drawing |
839 | 1034 |
|
1035 |
||
1036 |
def sample1b(): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1037 |
"A line plot with non-equidistant points in x-axis." |
1628 | 1038 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1039 |
drawing = Drawing(400, 200) |
839 | 1040 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1041 |
data = [ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1042 |
((1,1), (2,2), (2.5,1), (3,3), (4,5)), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1043 |
((1,2), (2,3), (2.5,2), (3.5,5), (4,6)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1044 |
] |
1628 | 1045 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1046 |
lp = LinePlot() |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1047 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1048 |
lp.x = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1049 |
lp.y = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1050 |
lp.height = 125 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1051 |
lp.width = 300 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1052 |
lp.data = data |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1053 |
lp.joinedLines = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1054 |
lp.lines.symbol = makeMarker('Circle') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1055 |
lp.lineLabelFormat = '%2.0f' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1056 |
lp.strokeColor = colors.black |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1057 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1058 |
lp.xValueAxis.valueMin = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1059 |
lp.xValueAxis.valueMax = 5 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1060 |
lp.xValueAxis.valueSteps = [1, 2, 2.5, 3, 4, 5] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1061 |
lp.xValueAxis.labelTextFormat = '%2.1f' |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1062 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1063 |
lp.yValueAxis.valueMin = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1064 |
lp.yValueAxis.valueMax = 7 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1065 |
lp.yValueAxis.valueStep = 1 |
1628 | 1066 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1067 |
drawing.add(lp) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1068 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1069 |
return drawing |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1070 |
|
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1071 |
|
839 | 1072 |
def sample1c(): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1073 |
"A line plot with non-equidistant points in x-axis." |
1628 | 1074 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1075 |
drawing = Drawing(400, 200) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1076 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1077 |
data = [ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1078 |
((1,1), (2,2), (2.5,1), (3,3), (4,5)), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1079 |
((1,2), (2,3), (2.5,2), (3.5,5), (4,6)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1080 |
] |
1628 | 1081 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1082 |
lp = LinePlot() |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1083 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1084 |
lp.x = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1085 |
lp.y = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1086 |
lp.height = 125 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1087 |
lp.width = 300 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1088 |
lp.data = data |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1089 |
lp.joinedLines = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1090 |
lp.lines[0].symbol = makeMarker('FilledCircle') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1091 |
lp.lines[1].symbol = makeMarker('Circle') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1092 |
lp.lineLabelFormat = '%2.0f' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1093 |
lp.strokeColor = colors.black |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1094 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1095 |
lp.xValueAxis.valueMin = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1096 |
lp.xValueAxis.valueMax = 5 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1097 |
lp.xValueAxis.valueSteps = [1, 2, 2.5, 3, 4, 5] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1098 |
lp.xValueAxis.labelTextFormat = '%2.1f' |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1099 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1100 |
lp.yValueAxis.valueMin = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1101 |
lp.yValueAxis.valueMax = 7 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1102 |
lp.yValueAxis.valueSteps = [1, 2, 3, 5, 6] |
1628 | 1103 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1104 |
drawing.add(lp) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1105 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1106 |
return drawing |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1107 |
|
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1108 |
|
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1109 |
def preprocessData(series): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1110 |
"Convert date strings into seconds and multiply values by 100." |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1111 |
|
3721 | 1112 |
return [(str2seconds(x[0]), x[1]*100) for x in series] |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1113 |
|
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1114 |
|
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1115 |
def sample2(): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1116 |
"A line plot with non-equidistant points in x-axis." |
1628 | 1117 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1118 |
drawing = Drawing(400, 200) |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1119 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1120 |
data = [ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1121 |
(('25/11/1991',1), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1122 |
('30/11/1991',1.000933333), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1123 |
('31/12/1991',1.0062), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1124 |
('31/01/1992',1.0112), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1125 |
('29/02/1992',1.0158), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1126 |
('31/03/1992',1.020733333), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1127 |
('30/04/1992',1.026133333), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1128 |
('31/05/1992',1.030266667), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1129 |
('30/06/1992',1.034466667), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1130 |
('31/07/1992',1.038733333), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1131 |
('31/08/1992',1.0422), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1132 |
('30/09/1992',1.045533333), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1133 |
('31/10/1992',1.049866667), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1134 |
('30/11/1992',1.054733333), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1135 |
('31/12/1992',1.061), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1136 |
), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1137 |
] |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1138 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1139 |
data[0] = preprocessData(data[0]) |
1628 | 1140 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1141 |
lp = LinePlot() |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1142 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1143 |
lp.x = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1144 |
lp.y = 50 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1145 |
lp.height = 125 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1146 |
lp.width = 300 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1147 |
lp.data = data |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1148 |
lp.joinedLines = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1149 |
lp.lines.symbol = makeMarker('FilledDiamond') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1150 |
lp.strokeColor = colors.black |
737
8f0e58918da9
Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff
changeset
|
1151 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1152 |
start = mktime(mkTimeTuple('25/11/1991')) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1153 |
t0 = mktime(mkTimeTuple('30/11/1991')) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1628
diff
changeset
|
1154 |
t1 = mktime(mkTimeTuple('31/12/1991')) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_r |