Skip to content

Commit 66fa8bb

Browse files
committed
Fold table.CustomCell into Cell.
We don't use plain Cells, only CustomCells, which is a subclass. Flattening the inheritance hierarchy makes it easier to document all parameters in a single constructor. No backcompat break as CustomCell is left as an alias.
1 parent 0ba2b40 commit 66fa8bb

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

doc/api/api_changes_3.3/behaviour.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,8 @@ The default method used to format `.Slider` values has been changed to use a
163163
values are displayed with an appropriate number of significant digits even if
164164
they are much smaller or much bigger than 1. To restore the old behavior,
165165
explicitly pass a "%1.2f" as the *valfmt* parameter to `.Slider`.
166+
167+
``table.CustomCell`` is now an alias for `.table.Cell`
168+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169+
All the functionality of ``CustomCell`` has been moved to its base class
170+
`~.table.Cell`.

lib/matplotlib/table.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,21 @@ class Cell(Rectangle):
3939
PAD = 0.1
4040
"""Padding between text and rectangle."""
4141

42+
_edges = 'BRTL'
43+
_edge_aliases = {'open': '',
44+
'closed': _edges, # default
45+
'horizontal': 'BT',
46+
'vertical': 'RL'
47+
}
48+
4249
def __init__(self, xy, width, height,
4350
edgecolor='k', facecolor='w',
4451
fill=True,
4552
text='',
4653
loc=None,
47-
fontproperties=None
54+
fontproperties=None,
55+
*,
56+
visible_edges='closed',
4857
):
4958
"""
5059
Parameters
@@ -68,12 +77,18 @@ def __init__(self, xy, width, height,
6877
fontproperties : dict
6978
A dict defining the font properties of the text. Supported keys and
7079
values are the keyword arguments accepted by `.FontProperties`.
80+
visible_edges : str, default: 'closed'
81+
The cell edges to be drawn with a line: a substring of 'BRTL'
82+
(bottom, right, top, left), or one of 'open' (no edges drawn),
83+
'closed' (all edges drawn), 'horizontal' (bottom and top),
84+
'vertical' (right and left).
7185
"""
7286

7387
# Call base
7488
Rectangle.__init__(self, xy, width=width, height=height, fill=fill,
7589
edgecolor=edgecolor, facecolor=facecolor)
7690
self.set_clip_on(False)
91+
self.visible_edges = visible_edges
7792

7893
# Create text object
7994
if loc is None:
@@ -178,23 +193,6 @@ def set_text_props(self, **kwargs):
178193
self._text.update(kwargs)
179194
self.stale = True
180195

181-
182-
class CustomCell(Cell):
183-
"""
184-
A `.Cell` subclass with configurable edge visibility.
185-
"""
186-
187-
_edges = 'BRTL'
188-
_edge_aliases = {'open': '',
189-
'closed': _edges, # default
190-
'horizontal': 'BT',
191-
'vertical': 'RL'
192-
}
193-
194-
def __init__(self, *args, visible_edges, **kwargs):
195-
super().__init__(*args, **kwargs)
196-
self.visible_edges = visible_edges
197-
198196
@property
199197
def visible_edges(self):
200198
"""
@@ -239,6 +237,9 @@ def get_path(self):
239237
)
240238

241239

240+
CustomCell = Cell # Backcompat. alias.
241+
242+
242243
class Table(Artist):
243244
"""
244245
A table of cells.
@@ -342,20 +343,20 @@ def add_cell(self, row, col, *args, **kwargs):
342343
343344
Returns
344345
-------
345-
`.CustomCell`
346+
`.Cell`
346347
The created cell.
347348
348349
"""
349350
xy = (0, 0)
350-
cell = CustomCell(xy, visible_edges=self.edges, *args, **kwargs)
351+
cell = Cell(xy, visible_edges=self.edges, *args, **kwargs)
351352
self[row, col] = cell
352353
return cell
353354

354355
def __setitem__(self, position, cell):
355356
"""
356357
Set a custom cell in a given position.
357358
"""
358-
cbook._check_isinstance(CustomCell, cell=cell)
359+
cbook._check_isinstance(Cell, cell=cell)
359360
try:
360361
row, col = position[0], position[1]
361362
except Exception as err:
@@ -374,7 +375,7 @@ def __getitem__(self, position):
374375
@property
375376
def edges(self):
376377
"""
377-
The default value of `~.CustomCell.visible_edges` for newly added
378+
The default value of `~.Cell.visible_edges` for newly added
378379
cells using `.add_cell`.
379380
380381
Notes
@@ -724,7 +725,7 @@ def table(ax,
724725
725726
edges : substring of 'BRTL' or {'open', 'closed', 'horizontal', 'vertical'}
726727
The cell edges to be drawn with a line. See also
727-
`~.CustomCell.visible_edges`.
728+
`~.Cell.visible_edges`.
728729
729730
Returns
730731
-------

0 commit comments

Comments
 (0)