From e8e515c295300e9cf469a5e02e4a9b82f3b25d38 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Wobst?= Date: Thu, 11 Oct 2012 22:31:00 +0000 Subject: [PATCH] add a one dimensional graph git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@3287 069f4177-920e-0410-937b-c2a4a81bcd90 --- pyx/graph/__init__.py | 12 +++++------ pyx/graph/graph.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/pyx/graph/__init__.py b/pyx/graph/__init__.py index c8f3084a..69ffa6cb 100644 --- a/pyx/graph/__init__.py +++ b/pyx/graph/__init__.py @@ -22,11 +22,11 @@ __allmodules__ = ["data", "key", "style", "axis"] for module in __allmodules__: - __import__(module, globals(), locals(), []) +__import__(module, globals(), locals(), []) -import graph -__allgraph__ = ["graphxy", "graphxyz"] -for importfromgraph in __allgraph__: - locals()[importfromgraph] = getattr(graph, importfromgraph) + import graph + __allgraph__ = ["graphx", "graphxy", "graphxyz"] + for importfromgraph in __allgraph__: +locals()[importfromgraph] = getattr(graph, importfromgraph) -__all__ = __allmodules__ + __allgraph__ + __all__ = __allmodules__ + __allgraph__ diff --git a/pyx/graph/graph.py b/pyx/graph/graph.py index 4f2212eb..4ab7099c 100644 --- a/pyx/graph/graph.py +++ b/pyx/graph/graph.py @@ -23,7 +23,7 @@ import math, re, string, warnings -from pyx import canvas, path, trafo, unit +from pyx import canvas, path, pycompat, trafo, unit from pyx.graph.axis import axis, positioner @@ -580,6 +580,61 @@ class graphxy(graph): self.layer("key").insert(c, [trafo.translate_pt(x, y)]) + +class graphx(graphxy): + + def __init__(self, xpos=0, ypos=0, length=None, size=0.5*unit.v_cm, direction="vertical", + key=None, backgroundattrs=None, axesdist=0.8*unit.v_cm, **axes): + for name in axes: + if not name.startswith("x"): + raise ValueError("Only x axes are allowed") + self.direction = direction + if self.direction == "vertical": + kwargsxy = dict(width=size, height=length, flipped=True) + elif self.direction == "horizontal": + kwargsxy = dict(width=length, height=size) + else: + raise ValueError("vertical or horizontal direction required") + kwargsxy.update(**axes) + + graphxy.__init__(self, xpos=xpos, ypos=ypos, ratio=None, key=key, y=axis.lin(min=0, max=1, parter=None), + backgroundattrs=backgroundattrs, axesdist=axesdist, **kwargsxy) + + def pos_pt(self, x, xaxis=None): + return graphxy.pos_pt(self, x, 0.5, xaxis) + + def pos(self, x, xaxis=None): + return graphxy.pos(self, x, 0.5, xaxis) + + def vpos_pt(self, vx): + return graphxy.vpos_pt(self, vx, 0.5) + + def vpos(self, vx): + return graphxy.vpos(self, vx, 0.5) + + def vgeodesic(self, vx1, vx2): + return graphxy.vgeodesic(self, vx1, 0.5, vx2, 0.5) + + def vgeodesic_el(self, vx1, vy1, vx2, vy2): + return graphxy.vgeodesic_el(self, vx1, 0.5, vx2, 0.5) + + def vcap_pt(self, coordinate, length_pt, vx): + if coordinate == 0: + return graphxy.vcap_pt(self, coordinate, length_pt, vx, 0.5) + else: + raise ValueError("direction invalid") + + def xvgridpath(self, vx): + return graphxy.xvgridpath(self, vx) + + def yvgridpath(self, vy): + raise Exception("This method does not exist on a one dimensional graph.") + + def axisatv(self, axis, v): + raise Exception("This method does not exist on a one dimensional graph.") + + + class graphxyz(graphxy): class central: -- 2.11.4.GIT