~ubuntu-branches/debian/sid/pyx/sid

« back to all changes in this revision

Viewing changes to pyx/graph/graph.py

  • Committer: Bazaar Package Importer
  • Author(s): Stuart Prescott
  • Date: 2011-05-20 00:13:52 UTC
  • mto: (9.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20110520001352-odcuqpdezuusbbw1
Tags: upstream-0.11.1
Import upstream version 0.11.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: ISO-8859-1 -*-
2
 
#
3
 
#
4
 
# Copyright (C) 2002-2004 J�rg Lehmann <joergl@users.sourceforge.net>
 
1
# -*- encoding: utf-8 -*-
 
2
#
 
3
#
 
4
# Copyright (C) 2002-2004 Jörg Lehmann <joergl@users.sourceforge.net>
5
5
# Copyright (C) 2003-2004 Michael Schindler <m-schindler@users.sourceforge.net>
6
 
# Copyright (C) 2002-2006 Andr� Wobst <wobsta@users.sourceforge.net>
 
6
# Copyright (C) 2002-2011 André Wobst <wobsta@users.sourceforge.net>
7
7
#
8
8
# This file is part of PyX (http://pyx.sourceforge.net/).
9
9
#
22
22
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
23
23
 
24
24
 
25
 
from __future__ import nested_scopes
26
 
 
27
25
import math, re, string, warnings
28
26
from pyx import canvas, path, trafo, unit
29
27
from pyx.graph import style
133
131
        canvas.canvas.__init__(self)
134
132
        self.axes = {}
135
133
        self.plotitems = []
 
134
        self.keyitems = []
136
135
        self._calls = {}
137
136
        self.didranges = 0
138
137
        self.didstyles = 0
250
249
 
251
250
        self.didstyles = 1
252
251
 
253
 
    def doplot(self, plotitem):
254
 
        if self.did(self.doplot, plotitem):
 
252
    def doplotitem(self, plotitem):
 
253
        if self.did(self.doplotitem, plotitem):
255
254
            return
256
255
        self.dostyles()
257
256
        plotitem.draw(self)
258
257
 
 
258
    def doplot(self):
 
259
        for plotitem in self.plotitems:
 
260
            self.doplotitem(plotitem)
 
261
 
259
262
    def dodata(self):
260
 
        for plotitem in self.plotitems:
261
 
            self.doplot(plotitem)
 
263
        warnings.warn("dodata() has been deprecated. Use doplot() instead.")
 
264
        self.doplot()
 
265
 
 
266
    def dokeyitem(self, plotitem):
 
267
        if self.did(self.dokeyitem, plotitem):
 
268
            return
 
269
        self.dostyles()
 
270
        if plotitem.title is not None:
 
271
            self.keyitems.append(plotitem)
262
272
 
263
273
    def dokey(self):
264
274
        raise NotImplementedError
266
276
    def finish(self):
267
277
        self.dobackground()
268
278
        self.doaxes()
269
 
        self.dodata()
 
279
        self.doplot()
270
280
        self.dokey()
271
281
 
272
282
 
497
507
        if self.did(self.dokey):
498
508
            return
499
509
        self.dobackground()
500
 
        self.dostyles()
 
510
        for plotitem in self.plotitems:
 
511
            self.dokeyitem(plotitem)
501
512
        if self.key is not None:
502
 
            c = self.key.paint(self.plotitems)
 
513
            c = self.key.paint(self.keyitems)
503
514
            bbox = c.bbox()
504
515
            def parentchildalign(pmin, pmax, cmin, cmax, pos, dist, inside):
505
516
                ppos = pmin+0.5*(cmax-cmin)+dist+pos*(pmax-pmin-cmax+cmin-2*dist)
631
642
                else:
632
643
                    self.axes[axisname] = axis.linkedaxis(self.axes[okey], axisname)
633
644
        if not axes.has_key("z"):
634
 
            self.axes["z"] = axis.anchoredaxis(axis.linear(), self.texrunner, axisname)
 
645
            self.axes["z"] = axis.anchoredaxis(axis.linear(), self.texrunner, "z")
635
646
 
636
647
        if self.axes.has_key("x"):
637
648
            self.xbasepath = self.axes["x"].basepath
686
697
            yaxis = self.axes["y"]
687
698
        if zaxis is None:
688
699
            zaxis = self.axes["z"]
689
 
        return self.vpos_pt(xaxis.convert(x), yaxis.convert(y), zaxis.convert(y))
 
700
        return self.vpos_pt(xaxis.convert(x), yaxis.convert(y), zaxis.convert(z))
690
701
 
691
702
    def pos(self, x, y, z, xaxis=None, yaxis=None, zaxis=None):
692
703
        if xaxis is None:
695
706
            yaxis = self.axes["y"]
696
707
        if zaxis is None:
697
708
            zaxis = self.axes["z"]
698
 
        return self.vpos(xaxis.convert(x), yaxis.convert(y), zaxis.convert(y))
 
709
        return self.vpos(xaxis.convert(x), yaxis.convert(y), zaxis.convert(z))
699
710
 
700
711
    def vpos_pt(self, vx, vy, vz):
701
712
        x, y = self.projector.point(2*self.xscale*(vx - 0.5),
731
742
 
732
743
    def vgeodesic_el(self, vx1, vy1, vz1, vx2, vy2, vz2):
733
744
        """returns a geodesic path element between two points in graph coordinates"""
734
 
        return path.lineto_pt(*(self.vpos_pt(vx1, vy1, vz1) + self.vpos_pt(vx2, vy2, vz2)))
 
745
        return path.lineto_pt(*self.vpos_pt(vx2, vy2, vz2))
735
746
 
736
747
    def vcap_pt(self, coordinate, length_pt, vx, vy, vz):
737
748
        """returns an error cap path for a given coordinate, lengths and
847
858
                                                                       lambda vz: self.vtickdirection(0, 1, vz, 1, 0, vz),
848
859
                                                                       self.zvgridpath))
849
860
        elif axisname == "z4":
850
 
            self.axes["z4"].setpositioner(positioner.flexlineaxispos_pt(lambda vz: self.vpos_pt(0, 0, vz),
 
861
            self.axes["z4"].setpositioner(positioner.flexlineaxispos_pt(lambda vz: self.vpos_pt(1, 1, vz),
851
862
                                                                       lambda vz: self.vtickdirection(1, 1, vz, 0, 0, vz),
852
863
                                                                       self.zvgridpath))
853
864
        else:
875
886
        if self.did(self.dokey):
876
887
            return
877
888
        self.dobackground()
878
 
        self.dostyles()
 
889
        for plotitem in self.plotitems:
 
890
            self.dokeyitem(plotitem)
879
891
        if self.key is not None:
880
 
            c = self.key.paint(self.plotitems)
 
892
            c = self.key.paint(self.keyitems)
881
893
            bbox = c.bbox()
882
894
            def parentchildalign(pmin, pmax, cmin, cmax, pos, dist, inside):
883
895
                ppos = pmin+0.5*(cmax-cmin)+dist+pos*(pmax-pmin-cmax+cmin-2*dist)