Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 47cb1a3

Browse files
committed
added vertex array trait handler
svn path=/trunk/matplotlib/; revision=3605
1 parent f84c634 commit 47cb1a3

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

mpl1/mpl1.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import enthought.traits.api as traits
2121
from enthought.traits.api import HasTraits, Instance, Trait, Float, Int, \
2222
Array, Tuple
23-
23+
from enthought.traits.trait_numeric import TraitArray
2424
from matplotlib import agg
2525
from matplotlib import colors as mcolors
2626
from matplotlib import cbook
@@ -30,7 +30,26 @@
3030

3131
## begin core infrastructure
3232

33+
class TraitVertexArray(TraitArray):
34+
35+
def __init__ ( self, typecode = None, shape = None, coerce = False ):
36+
TraitArray.__init__(self, typecode, shape, coerce)
37+
38+
def validate(self, object, name, value):
39+
orig = value
40+
value = TraitArray.validate(self, object, name, value)
41+
if len(value.shape)!=2 or value.shape[1]!=2:
42+
return self.error(object, name, orig)
43+
44+
return value
3345

46+
def info(self):
47+
return 'an Nx2 array of doubles which are x,y vertices'
48+
49+
VertexArray = Trait(npy.array([[0,0], [1,1]], npy.float_),
50+
TraitVertexArray('d'))
51+
52+
3453
class Affine(HasTraits):
3554
"""
3655
An affine 3x3 matrix that supports matrix multiplication with
@@ -396,22 +415,13 @@ class PathPrimitive(HasTraits):
396415
alpha = mtraits.Alpha(1.0)
397416
linewidth = mtraits.LineWidth(1.0)
398417
antialiased = mtraits.AntiAliased
399-
pathdata =Tuple(Array('b'), Array('d'))
418+
pathdata =Tuple(Array('b'), VertexArray)
400419
affine = Instance(Affine, ())
401420

402421
def _pathdata_default(self):
403422
return (npy.array([0,0], dtype=npy.uint8),
404423
npy.array([[0,0],[0,0]], npy.float_))
405424

406-
def _pathdata_changed(self, old, new):
407-
codes, xy = new
408-
409-
if len(xy.shape)!=2:
410-
raise ValueError('xy in path data must be Nx2')
411-
Ncodes = len(codes)
412-
Nxy = xy.shape[0]
413-
if Ncodes!=Nxy:
414-
raise ValueError('codes and xy must have equal rows')
415425

416426
class MarkerPrimitive(HasTraits):
417427
locs = Array('d')
@@ -852,7 +862,7 @@ class Path(Artist):
852862
linestyle = mtraits.LineStyle('-')
853863
linewidth = mtraits.LineWidth(1.0)
854864
model = mtraits.Model
855-
pathdata = traits.Tuple(Array('b'), Array('d'))
865+
pathdata = traits.Tuple(Array('b'), VertexArray)
856866
sequence = 'paths'
857867
zorder = Float(1.0)
858868

@@ -1039,8 +1049,6 @@ def _XY_changed(self):
10391049
#print 'LINE shapes', codes.shape, self.XY.shape
10401050
self.pathdata = codes, self.XY
10411051

1042-
# XXX: to we need to push pathdata changed here or will it
1043-
# happen automagically
10441052

10451053

10461054
class Polygon(Path):

0 commit comments

Comments
 (0)