1 # -*- encoding: utf-8 -*-
4 # Copyright (C) 2005-2006 André Wobst <wobsta@users.sourceforge.net>
6 # This file is part of PyX (http://pyx.sourceforge.net/).
8 # PyX is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # PyX is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with PyX; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 from pyx
import path
, unit
27 """interface definition of axis tick position methods
28 - these methods are used for the postitioning of the ticks
29 when painting an axis"""
30 # TODO: should we add a local transformation (for label text etc?)
31 # (this might replace tickdirection (and even tickposition?))
33 def vbasepath(self
, v1
=None, v2
=None):
34 """return the basepath as a path
35 - like basepath, but for graph coordinates"""
37 def vgridpath(self
, v
):
38 """return the gridpath as a path for a given position v
40 - might return None when no gridpath is available"""
43 def vtickpoint_pt(self
, v
):
44 """return tick position (x, y) in pts for a tick at position v in graph coordinates"""
46 def vtickdirection(self
, v
):
47 """return direction tuple (dx, dy) for a tick at position v in graph coordinates"""
50 class pathpositioner(_positioner
):
51 """axis tick position methods along an arbitrary path"""
53 def __init__(self
, p
, direction
=1):
55 self
.normpath
= p
.normpath()
56 self
.arclen_pt
= self
.normpath
.arclen_pt()
57 self
.arclen
= self
.arclen_pt
* unit
.t_pt
58 self
.direction
= direction
60 def vbasepath(self
, v1
=None, v2
=None):
65 return self
.normpath
.split(self
.normpath
.arclentoparam(v2
* self
.arclen
))[0]
68 return self
.normpath
.split(self
.normpath
.arclentoparam(v1
* self
.arclen
))[1]
70 return self
.normpath
.split(*self
.normpath
.arclentoparam([v1
* self
.arclen
, v2
* self
.arclen
]))[1]
72 def vtickpoint_pt(self
, v
):
73 return self
.normpath
.at_pt(self
.normpath
.arclentoparam(v
* self
.arclen
))
75 def vtickdirection(self
, v
):
76 return self
.normpath
.rotation(self
.normpath
.arclentoparam(v
* self
.arclen
)).apply_pt(0, self
.direction
)
80 """an axispos linear along a line with a fix direction for the ticks"""
82 def __init__(self
, x1_pt
, y1_pt
, x2_pt
, y2_pt
, fixtickdirection
, vgridpath
):
87 self
.fixtickdirection
= fixtickdirection
88 self
.vgridpath
= vgridpath
90 def vbasepath(self
, v1
=None, v2
=None):
95 return path
.line_pt((1-v1
)*self
.x1_pt
+v1
*self
.x2_pt
,
96 (1-v1
)*self
.y1_pt
+v1
*self
.y2_pt
,
97 (1-v2
)*self
.x1_pt
+v2
*self
.x2_pt
,
98 (1-v2
)*self
.y1_pt
+v2
*self
.y2_pt
)
100 def vtickpoint_pt(self
, v
):
101 return (1-v
)*self
.x1_pt
+v
*self
.x2_pt
, (1-v
)*self
.y1_pt
+v
*self
.y2_pt
103 def vtickdirection(self
, v
):
104 return self
.fixtickdirection
107 class flexlineaxispos_pt(lineaxispos_pt
):
108 """an axispos linear along a line with flexible direction for the ticks"""
110 def __init__(self
, vtickpoint_pt
, vtickdirection
, vgridpath
):
111 self
.vtickpoint_pt
= vtickpoint_pt
112 self
.vtickdirection
= vtickdirection
113 self
.vgridpath
= vgridpath
115 def vbasepath(self
, v1
=None, v2
=None):
120 x1_pt
, y1_pt
= self
.vtickpoint_pt(v1
)
121 x2_pt
, y2_pt
= self
.vtickpoint_pt(v2
)
122 return path
.line_pt(x1_pt
, y1_pt
, x2_pt
, y2_pt
)