2 # -*- coding: ISO-8859-1 -*-
5 # Copyright (C) 2002-2004 Jörg Lehmann <joergl@users.sourceforge.net>
6 # Copyright (C) 2003-2004 Michael Schindler <m-schindler@users.sourceforge.net>
7 # Copyright (C) 2002-2004 André Wobst <wobsta@users.sourceforge.net>
9 # This file is part of PyX (http://pyx.sourceforge.net/).
11 # PyX is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # PyX is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with PyX; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 import math
, re
, string
27 from pyx
import canvas
, path
, trafo
, unit
28 from pyx
.graph
.axis
import painter
, axis
31 goldenmean
= 0.5 * (math
.sqrt(5) + 1)
35 """an axispos linear along a line with a fix direction for the ticks"""
37 def __init__(self
, convert
, x1
, y1
, x2
, y2
, fixtickdirection
):
38 """initializes the instance
39 - only the convert method is needed from the axis
40 - x1, y1, x2, y2 are PyX lengths (start and end position of the line)
41 - fixtickdirection is a tuple tick direction (fixed along the line)"""
42 self
.convert
= convert
47 self
.x1_pt
= unit
.topt(x1
)
48 self
.y1_pt
= unit
.topt(y1
)
49 self
.x2_pt
= unit
.topt(x2
)
50 self
.y2_pt
= unit
.topt(y2
)
51 self
.fixtickdirection
= fixtickdirection
53 def vbasepath(self
, v1
=None, v2
=None):
58 return path
.line_pt((1-v1
)*self
.x1_pt
+v1
*self
.x2_pt
,
59 (1-v1
)*self
.y1_pt
+v1
*self
.y2_pt
,
60 (1-v2
)*self
.x1_pt
+v2
*self
.x2_pt
,
61 (1-v2
)*self
.y1_pt
+v2
*self
.y2_pt
)
63 def basepath(self
, x1
=None, x2
=None):
72 return path
.line_pt((1-v1
)*self
.x1_pt
+v1
*self
.x2_pt
,
73 (1-v1
)*self
.y1_pt
+v1
*self
.y2_pt
,
74 (1-v2
)*self
.x1_pt
+v2
*self
.x2_pt
,
75 (1-v2
)*self
.y1_pt
+v2
*self
.y2_pt
)
77 def gridpath(self
, x
):
78 raise RuntimeError("gridpath not available")
80 def vgridpath(self
, v
):
81 raise RuntimeError("gridpath not available")
83 def vtickpoint_pt(self
, v
):
84 return (1-v
)*self
.x1_pt
+v
*self
.x2_pt
, (1-v
)*self
.y1_pt
+v
*self
.y2_pt
86 def vtickpoint(self
, v
):
87 return (1-v
)*self
.x1
+v
*self
.x2
, (1-v
)*self
.y1
+v
*self
.y2
89 def tickpoint_pt(self
, x
):
91 return (1-v
)*self
.x1_pt
+v
*self
.x2_pt
, (1-v
)*self
.y1_pt
+v
*self
.y2_pt
93 def tickpoint(self
, x
):
95 return (1-v
)*self
.x1
+v
*self
.x2
, (1-v
)*self
.y1
+v
*self
.y2
97 def tickdirection(self
, x
):
98 return self
.fixtickdirection
100 def vtickdirection(self
, v
):
101 return self
.fixtickdirection
104 class lineaxisposlinegrid(lineaxispos
):
105 """an axispos linear along a line with a fix direction for the ticks
106 with support for grid lines for a rectangular graphs"""
108 __implements__
= painter
._Iaxispos
110 def __init__(self
, convert
, x1
, y1
, x2
, y2
, fixtickdirection
, startgridlength
, endgridlength
):
111 """initializes the instance
112 - only the convert method is needed from the axis
113 - x1, y1, x2, y2 are PyX lengths (start and end position of the line)
114 - fixtickdirection is a tuple tick direction (fixed along the line)
115 - startgridlength and endgridlength are PyX lengths for the starting
116 and end point of the grid, respectively; the gridpath is a line along
117 the fixtickdirection"""
118 lineaxispos
.__init
__(self
, convert
, x1
, y1
, x2
, y2
, fixtickdirection
)
119 self
.startgridlength
= startgridlength
120 self
.endgridlength
= endgridlength
121 self
.startgridlength_pt
= unit
.topt(self
.startgridlength
)
122 self
.endgridlength_pt
= unit
.topt(self
.endgridlength
)
124 def gridpath(self
, x
):
126 return path
.line_pt((1-v
)*self
.x1_pt
+v
*self
.x2_pt
+self
.fixtickdirection
[0]*self
.startgridlength_pt
,
127 (1-v
)*self
.y1_pt
+v
*self
.y2_pt
+self
.fixtickdirection
[1]*self
.startgridlength_pt
,
128 (1-v
)*self
.x1_pt
+v
*self
.x2_pt
+self
.fixtickdirection
[0]*self
.endgridlength_pt
,
129 (1-v
)*self
.y1_pt
+v
*self
.y2_pt
+self
.fixtickdirection
[1]*self
.endgridlength_pt
)
131 def vgridpath(self
, v
):
132 return path
.line_pt((1-v
)*self
.x1_pt
+v
*self
.x2_pt
+self
.fixtickdirection
[0]*self
.startgridlength_pt
,
133 (1-v
)*self
.y1_pt
+v
*self
.y2_pt
+self
.fixtickdirection
[1]*self
.startgridlength_pt
,
134 (1-v
)*self
.x1_pt
+v
*self
.x2_pt
+self
.fixtickdirection
[0]*self
.endgridlength_pt
,
135 (1-v
)*self
.y1_pt
+v
*self
.y2_pt
+self
.fixtickdirection
[1]*self
.endgridlength_pt
)
138 class graphxy(canvas
.canvas
):
140 def plot(self
, data
, styles
=None):
142 raise RuntimeError("layout setup was already performed")
153 styles
= d
.getdefaultstyles()
154 elif styles
!= d
.getdefaultstyles():
155 raise RuntimeError("defaultstyles differ")
157 d
.setstyles(self
, styles
)
158 self
.plotdata
.append(d
)
161 def pos_pt(self
, x
, y
, xaxis
=None, yaxis
=None):
163 xaxis
= self
.axes
["x"]
165 yaxis
= self
.axes
["y"]
166 return self
.xpos_pt
+ xaxis
.convert(x
)*self
.width_pt
, self
.ypos_pt
+ yaxis
.convert(y
)*self
.height_pt
168 def pos(self
, x
, y
, xaxis
=None, yaxis
=None):
170 xaxis
= self
.axes
["x"]
172 yaxis
= self
.axes
["y"]
173 return self
.xpos
+ xaxis
.convert(x
)*self
.width
, self
.ypos
+ yaxis
.convert(y
)*self
.height
175 def vpos_pt(self
, vx
, vy
):
176 return self
.xpos_pt
+ vx
*self
.width_pt
, self
.ypos_pt
+ vy
*self
.height_pt
178 def vpos(self
, vx
, vy
):
179 return self
.xpos
+ vx
*self
.width
, self
.ypos
+ vy
*self
.height
181 def vgeodesic(self
, vx1
, vy1
, vx2
, vy2
):
182 """returns a geodesic path between two points in graph coordinates"""
183 return path
.line_pt(self
.xpos_pt
+ vx1
*self
.width_pt
,
184 self
.ypos_pt
+ vy1
*self
.height_pt
,
185 self
.xpos_pt
+ vx2
*self
.width_pt
,
186 self
.ypos_pt
+ vy2
*self
.height_pt
)
188 def vgeodesic_el(self
, vx1
, vy1
, vx2
, vy2
):
189 """returns a geodesic path element between two points in graph coordinates"""
190 return path
.lineto_pt(self
.xpos_pt
+ vx2
*self
.width_pt
,
191 self
.ypos_pt
+ vy2
*self
.height_pt
)
193 def vcap_pt(self
, coordinate
, length_pt
, vx
, vy
):
194 """returns an error cap path for a given coordinate, lengths and
195 point in graph coordinates"""
197 return path
.line_pt(self
.xpos_pt
+ vx
*self
.width_pt
- 0.5*length_pt
,
198 self
.ypos_pt
+ vy
*self
.height_pt
,
199 self
.xpos_pt
+ vx
*self
.width_pt
+ 0.5*length_pt
,
200 self
.ypos_pt
+ vy
*self
.height_pt
)
201 elif coordinate
== 1:
202 return path
.line_pt(self
.xpos_pt
+ vx
*self
.width_pt
,
203 self
.ypos_pt
+ vy
*self
.height_pt
- 0.5*length_pt
,
204 self
.xpos_pt
+ vx
*self
.width_pt
,
205 self
.ypos_pt
+ vy
*self
.height_pt
+ 0.5*length_pt
)
207 raise ValueError("direction invalid")
209 def keynum(self
, key
):
211 while key
[0] in string
.letters
:
217 def removedomethod(self
, method
):
221 self
.domethods
.remove(method
)
227 if not self
.removedomethod(self
.dolayout
): return
229 # count the usage of styles and perform selects
231 def stylesid(styles
):
232 return ":".join([str(id(style
)) for style
in styles
])
233 for data
in self
.plotdata
:
235 styletotal
[stylesid(data
.styles
)] += 1
237 styletotal
[stylesid(data
.styles
)] = 1
239 for data
in self
.plotdata
:
241 styleindex
[stylesid(data
.styles
)] += 1
243 styleindex
[stylesid(data
.styles
)] = 0
244 data
.selectstyles(self
, styleindex
[stylesid(data
.styles
)], styletotal
[stylesid(data
.styles
)])
246 # adjust the axes ranges
247 for step
in range(3):
248 for data
in self
.plotdata
:
249 data
.adjustaxes(self
, step
)
252 XPattern
= re
.compile(r
"x([2-9]|[1-9][0-9]+)?$")
253 YPattern
= re
.compile(r
"y([2-9]|[1-9][0-9]+)?$")
254 xaxisextents
= [0, 0]
255 yaxisextents
= [0, 0]
256 needxaxisdist
= [0, 0]
257 needyaxisdist
= [0, 0]
258 items
= list(self
.axes
.items())
259 items
.sort() #TODO: alphabetical sorting breaks for axis numbers bigger than 9
260 # TODO: linked axes are not taken into account (consider x being a link to x2)
261 for key
, axis
in items
:
262 num
= self
.keynum(key
)
263 num2
= 1 - num
% 2 # x1 -> 0, x2 -> 1, x3 -> 0, x4 -> 1, ...
264 num3
= 2 * (num
% 2) - 1 # x1 -> 1, x2 -> -1, x3 -> 1, x4 -> -1, ...
265 if XPattern
.match(key
):
266 if needxaxisdist
[num2
]:
267 xaxisextents
[num2
] += self
.axesdist
268 self
.axespos
[key
] = lineaxisposlinegrid(axis
.convert
,
270 self
.ypos
+ num2
*self
.height
- num3
*xaxisextents
[num2
],
271 self
.xpos
+ self
.width
,
272 self
.ypos
+ num2
*self
.height
- num3
*xaxisextents
[num2
],
274 xaxisextents
[num2
], xaxisextents
[num2
] + self
.height
)
276 self
.xbasepath
= self
.axespos
[key
].basepath
277 self
.xvbasepath
= self
.axespos
[key
].vbasepath
278 self
.xgridpath
= self
.axespos
[key
].gridpath
279 self
.xvgridpath
= self
.axespos
[key
].vgridpath
280 self
.xtickpoint_pt
= self
.axespos
[key
].tickpoint_pt
281 self
.xtickpoint
= self
.axespos
[key
].tickpoint
282 self
.xvtickpoint_pt
= self
.axespos
[key
].vtickpoint_pt
283 self
.xvtickpoint
= self
.axespos
[key
].tickpoint
284 self
.xtickdirection
= self
.axespos
[key
].tickdirection
285 self
.xvtickdirection
= self
.axespos
[key
].vtickdirection
286 elif YPattern
.match(key
):
287 if needyaxisdist
[num2
]:
288 yaxisextents
[num2
] += self
.axesdist
289 self
.axespos
[key
] = lineaxisposlinegrid(axis
.convert
,
290 self
.xpos
+ num2
*self
.width
- num3
*yaxisextents
[num2
],
292 self
.xpos
+ num2
*self
.width
- num3
*yaxisextents
[num2
],
293 self
.ypos
+ self
.height
,
295 yaxisextents
[num2
], yaxisextents
[num2
] + self
.width
)
297 self
.ybasepath
= self
.axespos
[key
].basepath
298 self
.yvbasepath
= self
.axespos
[key
].vbasepath
299 self
.ygridpath
= self
.axespos
[key
].gridpath
300 self
.yvgridpath
= self
.axespos
[key
].vgridpath
301 self
.ytickpoint_pt
= self
.axespos
[key
].tickpoint_pt
302 self
.ytickpoint
= self
.axespos
[key
].tickpoint
303 self
.yvtickpoint_pt
= self
.axespos
[key
].vtickpoint_pt
304 self
.yvtickpoint
= self
.axespos
[key
].tickpoint
305 self
.ytickdirection
= self
.axespos
[key
].tickdirection
306 self
.yvtickdirection
= self
.axespos
[key
].vtickdirection
308 raise ValueError("Axis key '%s' not allowed" % key
)
309 axis
.finish(self
.axespos
[key
])
310 if XPattern
.match(key
):
311 xaxisextents
[num2
] += axis
.axiscanvas
.extent
312 needxaxisdist
[num2
] = 1
313 if YPattern
.match(key
):
314 yaxisextents
[num2
] += axis
.axiscanvas
.extent
315 needyaxisdist
[num2
] = 1
318 def dobackground(self
):
320 if not self
.removedomethod(self
.dobackground
): return
321 if self
.backgroundattrs
is not None:
322 self
.draw(path
.rect_pt(self
.xpos_pt
, self
.ypos_pt
, self
.width_pt
, self
.height_pt
),
323 self
.backgroundattrs
)
327 if not self
.removedomethod(self
.doaxes
): return
328 for axis
in self
.axes
.values():
329 self
.insert(axis
.axiscanvas
)
333 if not self
.removedomethod(self
.dodata
): return
334 for data
in self
.plotdata
:
339 if not self
.removedomethod(self
.dokey
): return
340 if self
.key
is not None:
341 c
= self
.key
.paint(self
.plotdata
)
343 def parentchildalign(pmin
, pmax
, cmin
, cmax
, pos
, dist
, inside
):
344 ppos
= pmin
+0.5*(cmax
-cmin
)+dist
+pos
*(pmax
-pmin
-cmax
+cmin
-2*dist
)
345 cpos
= 0.5*(cmin
+cmax
)+(1-inside
)*(1-2*pos
)*(cmax
-cmin
+2*dist
)
347 x
= parentchildalign(self
.xpos_pt
, self
.xpos_pt
+self
.width_pt
,
348 bbox
.llx_pt
, bbox
.urx_pt
,
349 self
.key
.hpos
, unit
.topt(self
.key
.hdist
), self
.key
.hinside
)
350 y
= parentchildalign(self
.ypos_pt
, self
.ypos_pt
+self
.height_pt
,
351 bbox
.lly_pt
, bbox
.ury_pt
,
352 self
.key
.vpos
, unit
.topt(self
.key
.vdist
), self
.key
.vinside
)
353 self
.insert(c
, [trafo
.translate_pt(x
, y
)])
356 while len(self
.domethods
):
359 def initwidthheight(self
, width
, height
, ratio
):
360 if (width
is not None) and (height
is None):
362 self
.height
= (1.0/ratio
) * self
.width
363 elif (height
is not None) and (width
is None):
365 self
.width
= ratio
* self
.height
369 self
.width_pt
= unit
.topt(self
.width
)
370 self
.height_pt
= unit
.topt(self
.height
)
371 if self
.width_pt
<= 0: raise ValueError("width <= 0")
372 if self
.height_pt
<= 0: raise ValueError("height <= 0")
374 def initaxes(self
, axes
, addlinkaxes
=0):
375 for key
in ["x", "y"]:
376 if not axes
.has_key(key
):
377 axes
[key
] = axis
.linear()
378 elif axes
[key
] is None:
381 if not axes
.has_key(key
+ "2") and axes
.has_key(key
):
382 axes
[key
+ "2"] = axes
[key
].createlinkaxis()
383 elif axes
[key
+ "2"] is None:
386 self
.axesnames
= ([], [])
387 for key
in axes
.keys():
388 if len(key
) != 1 and (not key
[1:].isdigit() or key
[1:] == "1"):
389 raise ValueError("invalid axis count")
391 self
.axesnames
[0].append(key
)
393 self
.axesnames
[1].append(key
)
395 raise ValueError("invalid axis name")
397 def __init__(self
, xpos
=0, ypos
=0, width
=None, height
=None, ratio
=goldenmean
,
398 key
=None, backgroundattrs
=None, axesdist
=0.8*unit
.v_cm
, **axes
):
399 canvas
.canvas
.__init
__(self
)
402 self
.xpos_pt
= unit
.topt(self
.xpos
)
403 self
.ypos_pt
= unit
.topt(self
.ypos
)
404 self
.initwidthheight(width
, height
, ratio
)
405 self
.initaxes(axes
, 1)
409 self
.backgroundattrs
= backgroundattrs
410 self
.axesdist
= axesdist
412 self
.domethods
= [self
.dolayout
, self
.dobackground
, self
.doaxes
, self
.dodata
, self
.dokey
]
418 return canvas
.canvas
.bbox(self
)
422 return canvas
.canvas
.prolog(self
)
424 def outputPS(self
, file):
426 canvas
.canvas
.outputPS(self
, file)
430 # some thoughts, but deferred right now
432 # class graphxyz(graphxy):
434 # axisnames = "x", "y", "z"
436 # def _vxtickpoint(self, axis, v):
437 # return self._vpos(v, axis.vypos, axis.vzpos)
439 # def _vytickpoint(self, axis, v):
440 # return self._vpos(axis.vxpos, v, axis.vzpos)
442 # def _vztickpoint(self, axis, v):
443 # return self._vpos(axis.vxpos, axis.vypos, v)
445 # def vxtickdirection(self, axis, v):
446 # x1, y1 = self._vpos(v, axis.vypos, axis.vzpos)
447 # x2, y2 = self._vpos(v, 0.5, 0)
448 # dx, dy = x1 - x2, y1 - y2
449 # norm = math.hypot(dx, dy)
450 # return dx/norm, dy/norm
452 # def vytickdirection(self, axis, v):
453 # x1, y1 = self._vpos(axis.vxpos, v, axis.vzpos)
454 # x2, y2 = self._vpos(0.5, v, 0)
455 # dx, dy = x1 - x2, y1 - y2
456 # norm = math.hypot(dx, dy)
457 # return dx/norm, dy/norm
459 # def vztickdirection(self, axis, v):
461 # x1, y1 = self._vpos(axis.vxpos, axis.vypos, v)
462 # x2, y2 = self._vpos(0.5, 0.5, v)
463 # dx, dy = x1 - x2, y1 - y2
464 # norm = math.hypot(dx, dy)
465 # return dx/norm, dy/norm
467 # def _pos(self, x, y, z, xaxis=None, yaxis=None, zaxis=None):
468 # if xaxis is None: xaxis = self.axes["x"]
469 # if yaxis is None: yaxis = self.axes["y"]
470 # if zaxis is None: zaxis = self.axes["z"]
471 # return self._vpos(xaxis.convert(x), yaxis.convert(y), zaxis.convert(z))
473 # def pos(self, x, y, z, xaxis=None, yaxis=None, zaxis=None):
474 # if xaxis is None: xaxis = self.axes["x"]
475 # if yaxis is None: yaxis = self.axes["y"]
476 # if zaxis is None: zaxis = self.axes["z"]
477 # return self.vpos(xaxis.convert(x), yaxis.convert(y), zaxis.convert(z))
479 # def _vpos(self, vx, vy, vz):
480 # x, y, z = (vx - 0.5)*self._depth, (vy - 0.5)*self._width, (vz - 0.5)*self._height
481 # d0 = float(self.a[0]*self.b[1]*(z-self.eye[2])
482 # + self.a[2]*self.b[0]*(y-self.eye[1])
483 # + self.a[1]*self.b[2]*(x-self.eye[0])
484 # - self.a[2]*self.b[1]*(x-self.eye[0])
485 # - self.a[0]*self.b[2]*(y-self.eye[1])
486 # - self.a[1]*self.b[0]*(z-self.eye[2]))
487 # da = (self.eye[0]*self.b[1]*(z-self.eye[2])
488 # + self.eye[2]*self.b[0]*(y-self.eye[1])
489 # + self.eye[1]*self.b[2]*(x-self.eye[0])
490 # - self.eye[2]*self.b[1]*(x-self.eye[0])
491 # - self.eye[0]*self.b[2]*(y-self.eye[1])
492 # - self.eye[1]*self.b[0]*(z-self.eye[2]))
493 # db = (self.a[0]*self.eye[1]*(z-self.eye[2])
494 # + self.a[2]*self.eye[0]*(y-self.eye[1])
495 # + self.a[1]*self.eye[2]*(x-self.eye[0])
496 # - self.a[2]*self.eye[1]*(x-self.eye[0])
497 # - self.a[0]*self.eye[2]*(y-self.eye[1])
498 # - self.a[1]*self.eye[0]*(z-self.eye[2]))
499 # return da/d0 + self._xpos, db/d0 + self._ypos
501 # def vpos(self, vx, vy, vz):
502 # tx, ty = self._vpos(vx, vy, vz)
503 # return unit.t_pt(tx), unit.t_pt(ty)
505 # def xbaseline(self, axis, x1, x2, xaxis=None):
506 # if xaxis is None: xaxis = self.axes["x"]
507 # return self.vxbaseline(axis, xaxis.convert(x1), xaxis.convert(x2))
509 # def ybaseline(self, axis, y1, y2, yaxis=None):
510 # if yaxis is None: yaxis = self.axes["y"]
511 # return self.vybaseline(axis, yaxis.convert(y1), yaxis.convert(y2))
513 # def zbaseline(self, axis, z1, z2, zaxis=None):
514 # if zaxis is None: zaxis = self.axes["z"]
515 # return self.vzbaseline(axis, zaxis.convert(z1), zaxis.convert(z2))
517 # def vxbaseline(self, axis, v1, v2):
518 # return (path._line(*(self._vpos(v1, 0, 0) + self._vpos(v2, 0, 0))) +
519 # path._line(*(self._vpos(v1, 0, 1) + self._vpos(v2, 0, 1))) +
520 # path._line(*(self._vpos(v1, 1, 1) + self._vpos(v2, 1, 1))) +
521 # path._line(*(self._vpos(v1, 1, 0) + self._vpos(v2, 1, 0))))
523 # def vybaseline(self, axis, v1, v2):
524 # return (path._line(*(self._vpos(0, v1, 0) + self._vpos(0, v2, 0))) +
525 # path._line(*(self._vpos(0, v1, 1) + self._vpos(0, v2, 1))) +
526 # path._line(*(self._vpos(1, v1, 1) + self._vpos(1, v2, 1))) +
527 # path._line(*(self._vpos(1, v1, 0) + self._vpos(1, v2, 0))))
529 # def vzbaseline(self, axis, v1, v2):
530 # return (path._line(*(self._vpos(0, 0, v1) + self._vpos(0, 0, v2))) +
531 # path._line(*(self._vpos(0, 1, v1) + self._vpos(0, 1, v2))) +
532 # path._line(*(self._vpos(1, 1, v1) + self._vpos(1, 1, v2))) +
533 # path._line(*(self._vpos(1, 0, v1) + self._vpos(1, 0, v2))))
535 # def xgridpath(self, x, xaxis=None):
537 # if xaxis is None: xaxis = self.axes["x"]
538 # v = xaxis.convert(x)
539 # return path._line(self._xpos+v*self._width, self._ypos,
540 # self._xpos+v*self._width, self._ypos+self._height)
542 # def ygridpath(self, y, yaxis=None):
544 # if yaxis is None: yaxis = self.axes["y"]
545 # v = yaxis.convert(y)
546 # return path._line(self._xpos, self._ypos+v*self._height,
547 # self._xpos+self._width, self._ypos+v*self._height)
549 # def zgridpath(self, z, zaxis=None):
551 # if zaxis is None: zaxis = self.axes["z"]
552 # v = zaxis.convert(z)
553 # return path._line(self._xpos, self._zpos+v*self._height,
554 # self._xpos+self._width, self._zpos+v*self._height)
556 # def vxgridpath(self, v):
557 # return path.path(path._moveto(*self._vpos(v, 0, 0)),
558 # path._lineto(*self._vpos(v, 0, 1)),
559 # path._lineto(*self._vpos(v, 1, 1)),
560 # path._lineto(*self._vpos(v, 1, 0)),
563 # def vygridpath(self, v):
564 # return path.path(path._moveto(*self._vpos(0, v, 0)),
565 # path._lineto(*self._vpos(0, v, 1)),
566 # path._lineto(*self._vpos(1, v, 1)),
567 # path._lineto(*self._vpos(1, v, 0)),
570 # def vzgridpath(self, v):
571 # return path.path(path._moveto(*self._vpos(0, 0, v)),
572 # path._lineto(*self._vpos(0, 1, v)),
573 # path._lineto(*self._vpos(1, 1, v)),
574 # path._lineto(*self._vpos(1, 0, v)),
577 # def _addpos(self, x, y, dx, dy):
581 # def _connect(self, x1, y1, x2, y2):
583 # return path._lineto(x2, y2)
587 # if not self.removedomethod(self.doaxes): return
588 # axesdist_pt = unit.topt(self.axesdist)
589 # XPattern = re.compile(r"%s([2-9]|[1-9][0-9]+)?$" % self.axisnames[0])
590 # YPattern = re.compile(r"%s([2-9]|[1-9][0-9]+)?$" % self.axisnames[1])
591 # ZPattern = re.compile(r"%s([2-9]|[1-9][0-9]+)?$" % self.axisnames[2])
592 # items = list(self.axes.items())
593 # items.sort() #TODO: alphabetical sorting breaks for axis numbers bigger than 9
594 # for key, axis in items:
595 # num = self.keynum(key)
596 # num2 = 1 - num % 2 # x1 -> 0, x2 -> 1, x3 -> 0, x4 -> 1, ...
597 # num3 = 1 - 2 * (num % 2) # x1 -> -1, x2 -> 1, x3 -> -1, x4 -> 1, ...
598 # if XPattern.match(key):
601 # axis._vtickpoint = self._vxtickpoint
602 # axis.vgridpath = self.vxgridpath
603 # axis.vbaseline = self.vxbaseline
604 # axis.vtickdirection = self.vxtickdirection
605 # elif YPattern.match(key):
608 # axis._vtickpoint = self._vytickpoint
609 # axis.vgridpath = self.vygridpath
610 # axis.vbaseline = self.vybaseline
611 # axis.vtickdirection = self.vytickdirection
612 # elif ZPattern.match(key):
615 # axis._vtickpoint = self._vztickpoint
616 # axis.vgridpath = self.vzgridpath
617 # axis.vbaseline = self.vzbaseline
618 # axis.vtickdirection = self.vztickdirection
620 # raise ValueError("Axis key '%s' not allowed" % key)
621 # if axis.painter is not None:
623 # # if XPattern.match(key):
624 # # self._xaxisextents[num2] += axis._extent
625 # # needxaxisdist[num2] = 1
626 # # if YPattern.match(key):
627 # # self._yaxisextents[num2] += axis._extent
628 # # needyaxisdist[num2] = 1
630 # def __init__(self, tex, xpos=0, ypos=0, width=None, height=None, depth=None,
631 # phi=30, theta=30, distance=1,
632 # backgroundattrs=None, axesdist=0.8*unit.v_cm, **axes):
633 # canvas.canvas.__init__(self)
637 # self._xpos = unit.topt(xpos)
638 # self._ypos = unit.topt(ypos)
639 # self._width = unit.topt(width)
640 # self._height = unit.topt(height)
641 # self._depth = unit.topt(depth)
643 # self.height = height
645 # if self._width <= 0: raise ValueError("width < 0")
646 # if self._height <= 0: raise ValueError("height < 0")
647 # if self._depth <= 0: raise ValueError("height < 0")
648 # self._distance = distance*math.sqrt(self._width*self._width+
649 # self._height*self._height+
650 # self._depth*self._depth)
651 # phi *= -math.pi/180
652 # theta *= math.pi/180
653 # self.a = (-math.sin(phi), math.cos(phi), 0)
654 # self.b = (-math.cos(phi)*math.sin(theta),
655 # -math.sin(phi)*math.sin(theta),
657 # self.eye = (self._distance*math.cos(phi)*math.cos(theta),
658 # self._distance*math.sin(phi)*math.cos(theta),
659 # self._distance*math.sin(theta))
660 # self.initaxes(axes)
661 # self.axesdist = axesdist
662 # self.backgroundattrs = backgroundattrs
665 # self.domethods = [self.dolayout, self.dobackground, self.doaxes, self.dodata]
667 # self.defaultstyle = {}
671 # return bbox._bbox(self._xpos - 200, self._ypos - 200, self._xpos + 200, self._ypos + 200)