|
20 | 20 | import enthought.traits.api as traits |
21 | 21 | from enthought.traits.api import HasTraits, Instance, Trait, Float, Int, \ |
22 | 22 | Array, Tuple |
23 | | - |
| 23 | +from enthought.traits.trait_numeric import TraitArray |
24 | 24 | from matplotlib import agg |
25 | 25 | from matplotlib import colors as mcolors |
26 | 26 | from matplotlib import cbook |
|
30 | 30 |
|
31 | 31 | ## begin core infrastructure |
32 | 32 |
|
| 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 |
33 | 45 |
|
| 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 | + |
34 | 53 | class Affine(HasTraits): |
35 | 54 | """ |
36 | 55 | An affine 3x3 matrix that supports matrix multiplication with |
@@ -396,22 +415,13 @@ class PathPrimitive(HasTraits): |
396 | 415 | alpha = mtraits.Alpha(1.0) |
397 | 416 | linewidth = mtraits.LineWidth(1.0) |
398 | 417 | antialiased = mtraits.AntiAliased |
399 | | - pathdata =Tuple(Array('b'), Array('d')) |
| 418 | + pathdata =Tuple(Array('b'), VertexArray) |
400 | 419 | affine = Instance(Affine, ()) |
401 | 420 |
|
402 | 421 | def _pathdata_default(self): |
403 | 422 | return (npy.array([0,0], dtype=npy.uint8), |
404 | 423 | npy.array([[0,0],[0,0]], npy.float_)) |
405 | 424 |
|
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') |
415 | 425 |
|
416 | 426 | class MarkerPrimitive(HasTraits): |
417 | 427 | locs = Array('d') |
@@ -852,7 +862,7 @@ class Path(Artist): |
852 | 862 | linestyle = mtraits.LineStyle('-') |
853 | 863 | linewidth = mtraits.LineWidth(1.0) |
854 | 864 | model = mtraits.Model |
855 | | - pathdata = traits.Tuple(Array('b'), Array('d')) |
| 865 | + pathdata = traits.Tuple(Array('b'), VertexArray) |
856 | 866 | sequence = 'paths' |
857 | 867 | zorder = Float(1.0) |
858 | 868 |
|
@@ -1039,8 +1049,6 @@ def _XY_changed(self): |
1039 | 1049 | #print 'LINE shapes', codes.shape, self.XY.shape |
1040 | 1050 | self.pathdata = codes, self.XY |
1041 | 1051 |
|
1042 | | - # XXX: to we need to push pathdata changed here or will it |
1043 | | - # happen automagically |
1044 | 1052 |
|
1045 | 1053 |
|
1046 | 1054 | class Polygon(Path): |
|
0 commit comments