@@ -147,51 +147,55 @@ def set_text_props(self, **kwargs):
147147 self ._text .update (kwargs )
148148
149149
150- class FancyCell (Cell ):
150+ class CustomCell (Cell ):
151151 """
152- A subclass of Cell where vertical and horizontal lines may
153- be selectively ommited.
152+ A subclass of Cell where the sides may be visibly toggled.
153+
154154 """
155155
156- def __init__ (self , xy , width , height ,
157- edgecolor = 'k' , facecolor = 'w' ,
158- fill = True ,
159- text = '' ,
160- loc = None ,
161- fontproperties = None ,
162- edgeVisibility = "LRBT"
163- ):
164- Cell .__init__ (self , xy , width , height , edgecolor , facecolor , fill ,
165- text , loc , fontproperties )
166- for letter in edgeVisibility :
167- if letter not in "LRBT" :
168- msg = ('Invalid edgeVisibility params for FancyCell:' +
169- '{0}, must only consist of {1}.' ).format (
170- value ,
171- ", " .join ({'T' , 'B' , 'L' , 'R' }),
172- )
173- raise ValueError (msg )
174- self ._edgeVisibility = edgeVisibility
156+ EDGES = 'BRTL'
157+ EDGE_ALIASES = {'open' : '' ,
158+ 'closed' : EDGES , # default
159+ 'horizontal' : 'BT' ,
160+ 'vertical' : 'RL'
161+ }
162+
163+ def __init__ (self , * args , ** kwargs ):
164+
165+ visible_edges = kwargs .pop ('visible_edges' )
166+ Cell .__init__ (self , * args , ** kwargs )
167+
168+ if visible_edges is None :
169+ self ._visible_edges = self .EDGES
170+ elif visible_edges in self .EDGE_ALIASES :
171+ self ._visible_edges = self .EDGE_ALIASES [visible_edges ]
172+ else :
173+ for edge in visible_edges :
174+ if edge not in self .EDGES :
175+ msg = 'Invalid edge param {0}, must only be one of {1} or \
176+ string of {2}.' .format (
177+ visible_edges ,
178+ ", " .join (self .EDGE_ALIASES .keys ()),
179+ ", " .join (self .EDGES ),
180+ )
181+ raise ValueError (msg )
182+ self ._visible_edges = visible_edges
175183
176184 def get_path (self ):
177- 'Return a path where the edges specificed by edgeVisibility are drawn'
178- edgeCodes = [Path .MOVETO , Path .MOVETO , Path .MOVETO ,
179- Path .MOVETO , Path .MOVETO ]
180- if 'B' in self ._edgeVisibility :
181- edgeCodes [1 ] = Path .LINETO
182- if 'R' in self ._edgeVisibility :
183- edgeCodes [2 ] = Path .LINETO
184- if 'T' in self ._edgeVisibility :
185- edgeCodes [3 ] = Path .LINETO
186- if 'L' in self ._edgeVisibility :
187- edgeCodes [4 ] = Path .LINETO
188-
189- path = Path ([[0.0 , 0.0 ], [1.0 , 0.0 ], [1.0 , 1.0 ], [0.0 , 1.0 ],
190- [0.0 , 0.0 ]],
191- edgeCodes ,
192- readonly = True
193- )
194- return path
185+ 'Return a path where the edges specificed by _visible_edges are drawn'
186+
187+ codes = [Path .MOVETO ] * 4
188+ codes .append (Path .CLOSEPOLY )
189+
190+ for i , edge in enumerate (self .EDGES , 1 ):
191+ if edge in self ._visible_edges :
192+ codes [i ] = Path .LINETO
193+
194+ return Path (
195+ [[0.0 , 0.0 ], [1.0 , 0.0 ], [1.0 , 1.0 ], [0.0 , 1.0 ], [0.0 , 0.0 ]],
196+ codes ,
197+ readonly = True
198+ )
195199
196200
197201class Table (Artist ):
@@ -227,12 +231,6 @@ class Table(Artist):
227231 'bottom' : 17 ,
228232 }
229233
230- DRAWLINE_ALIASES = {'open' : '' ,
231- 'closed' : 'LRBT' , # default
232- 'horizontal' : 'TB' ,
233- 'vertical' : 'LR'
234- }
235-
236234 FONTSIZE = 10
237235 AXESPAD = 0.02 # the border between the axes and table edge
238236
@@ -257,7 +255,7 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
257255
258256 self ._texts = []
259257 self ._cells = {}
260- self ._drawLines = "LTRB"
258+ self ._drawLines = None
261259 self ._autoRows = []
262260 self ._autoColumns = []
263261 self ._autoFontsize = True
@@ -271,7 +269,7 @@ def add_cell(self, row, col, *args, **kwargs):
271269 """ Add a cell to the table. """
272270 xy = (0 , 0 )
273271
274- cell = FancyCell (xy , edgeVisibility = self ._drawLines , * args , ** kwargs )
272+ cell = CustomCell (xy , visible_edges = self ._drawLines , * args , ** kwargs )
275273 cell .set_figure (self .figure )
276274 cell .set_transform (self .get_transform ())
277275
@@ -284,21 +282,7 @@ def drawLines(self):
284282
285283 @drawLines .setter
286284 def drawLines (self , value ):
287- if value is None :
288- pass # Leave as previously set
289- elif value in self .DRAWLINE_ALIASES .keys ():
290- self ._drawLines = self .DRAWLINE_ALIASES [value ]
291- else :
292- for letter in value :
293- if letter not in "LRBT" :
294- msg = ('Unrecognized draw lines for Cell:' +
295- ' {0}, must be one of {1}.' ).format (
296- value ,
297- ", " .join ({'open' , 'closed' , 'horizontal' ,
298- 'vertical' , 'string consisting of {T, B, R, L}' }),
299- )
300- raise ValueError (msg )
301- self ._drawLines = value
285+ self ._drawLines = value
302286
303287 def _approx_text_height (self ):
304288 return (self .FONTSIZE / 72.0 * self .figure .dpi /
@@ -536,14 +520,14 @@ def table(ax,
536520 cellLoc = 'right' , colWidths = None ,
537521 rowLabels = None , rowColours = None , rowLoc = 'left' ,
538522 colLabels = None , colColours = None , colLoc = 'center' ,
539- loc = 'bottom' , bbox = None , drawLines = 'LRBT ' ,
523+ loc = 'bottom' , bbox = None , drawLines = 'BRTL ' ,
540524 ** kwargs ):
541525 """
542526 TABLE(cellText=None, cellColours=None,
543527 cellLoc='right', colWidths=None,
544528 rowLabels=None, rowColours=None, rowLoc='left',
545529 colLabels=None, colColours=None, colLoc='center',
546- loc='bottom', bbox=None, drawLines='LRBT ')
530+ loc='bottom', bbox=None, drawLines='BRTL ')
547531
548532 Factory function to generate a Table instance.
549533
0 commit comments