|
From: <jd...@us...> - 2007-07-22 19:53:46
|
Revision: 3605
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3605&view=rev
Author: jdh2358
Date: 2007-07-22 12:53:44 -0700 (Sun, 22 Jul 2007)
Log Message:
-----------
added vertex array trait handler
Modified Paths:
--------------
trunk/matplotlib/mpl1/mpl1.py
Modified: trunk/matplotlib/mpl1/mpl1.py
===================================================================
--- trunk/matplotlib/mpl1/mpl1.py 2007-07-22 16:53:37 UTC (rev 3604)
+++ trunk/matplotlib/mpl1/mpl1.py 2007-07-22 19:53:44 UTC (rev 3605)
@@ -20,7 +20,7 @@
import enthought.traits.api as traits
from enthought.traits.api import HasTraits, Instance, Trait, Float, Int, \
Array, Tuple
-
+from enthought.traits.trait_numeric import TraitArray
from matplotlib import agg
from matplotlib import colors as mcolors
from matplotlib import cbook
@@ -30,7 +30,26 @@
## begin core infrastructure
+class TraitVertexArray(TraitArray):
+ def __init__ ( self, typecode = None, shape = None, coerce = False ):
+ TraitArray.__init__(self, typecode, shape, coerce)
+
+ def validate(self, object, name, value):
+ orig = value
+ value = TraitArray.validate(self, object, name, value)
+ if len(value.shape)!=2 or value.shape[1]!=2:
+ return self.error(object, name, orig)
+
+ return value
+
+ def info(self):
+ return 'an Nx2 array of doubles which are x,y vertices'
+
+VertexArray = Trait(npy.array([[0,0], [1,1]], npy.float_),
+ TraitVertexArray('d'))
+
+
class Affine(HasTraits):
"""
An affine 3x3 matrix that supports matrix multiplication with
@@ -396,23 +415,14 @@
alpha = mtraits.Alpha(1.0)
linewidth = mtraits.LineWidth(1.0)
antialiased = mtraits.AntiAliased
- pathdata =Tuple(Array('b'), Array('d'))
+ pathdata =Tuple(Array('b'), VertexArray)
affine = Instance(Affine, ())
def _pathdata_default(self):
return (npy.array([0,0], dtype=npy.uint8),
npy.array([[0,0],[0,0]], npy.float_))
- def _pathdata_changed(self, old, new):
- codes, xy = new
- if len(xy.shape)!=2:
- raise ValueError('xy in path data must be Nx2')
- Ncodes = len(codes)
- Nxy = xy.shape[0]
- if Ncodes!=Nxy:
- raise ValueError('codes and xy must have equal rows')
-
class MarkerPrimitive(HasTraits):
locs = Array('d')
path = Instance(PathPrimitive, ()) # marker path in points
@@ -852,7 +862,7 @@
linestyle = mtraits.LineStyle('-')
linewidth = mtraits.LineWidth(1.0)
model = mtraits.Model
- pathdata = traits.Tuple(Array('b'), Array('d'))
+ pathdata = traits.Tuple(Array('b'), VertexArray)
sequence = 'paths'
zorder = Float(1.0)
@@ -1039,8 +1049,6 @@
#print 'LINE shapes', codes.shape, self.XY.shape
self.pathdata = codes, self.XY
- # XXX: to we need to push pathdata changed here or will it
- # happen automagically
class Polygon(Path):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|