Repository navigation
Implemented issue 4044. Created a Cell subclass, SciCell, to override th... #4245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
9eb3204
3249f50
fbdc81a
3efbf16
74676a4
0fa3b19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ | |
|
|
||
| from . import artist | ||
| from .artist import Artist, allow_rasterization | ||
| from .patches import Rectangle | ||
| from .patches import Rectangle, Polygon | ||
| from .cbook import is_string_like | ||
| from matplotlib import docstring | ||
| from .text import Text | ||
|
|
@@ -146,6 +146,37 @@ def set_text_props(self, **kwargs): | |
| self._text.update(kwargs) | ||
|
|
||
|
|
||
| class SciCell(Cell): | ||
| """ | ||
| A SciCell is a Cell, but it only draws the horizontal lines of the Cell | ||
|
|
||
| """ | ||
|
|
||
| @allow_rasterization | ||
| def draw(self, renderer): | ||
| if not self.get_visible(): | ||
| return | ||
|
|
||
| bbox = Rectangle.get_bbox(self) | ||
| x, y, w, h = bbox.bounds | ||
|
|
||
| topLineVertices = [[x, y], [x + w, y]] | ||
| botLineVertices = [[x, y + h], [x + w, y + h]] | ||
|
|
||
| topLine = Polygon(topLineVertices) | ||
| botLine = Polygon(botLineVertices) | ||
|
|
||
| topLine.update_from(self) | ||
| botLine.update_from(self) | ||
|
|
||
| topLine.draw(renderer) | ||
| botLine.draw(renderer) | ||
|
|
||
| # position the text | ||
| self._set_text_position(renderer) | ||
| self._text.draw(renderer) | ||
|
|
||
|
|
||
| class Table(Artist): | ||
| """ | ||
| Create a table of cells. | ||
|
|
@@ -211,12 +242,15 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs): | |
| self.set_clip_on(False) | ||
|
|
||
| self._cachedRenderer = None | ||
| self._cellType = 'default' | ||
| self._cellCreation = {"default": Cell, "scicell": SciCell} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an instance level attribute. A class level would look something like class foo(object):
bar = {'a': 1, 'b': 2}
def __init__(self, lab):
if lab not in self.bar:
raise ValueError("invalid key")
self.label = self.bar[lab]The |
||
|
|
||
| def add_cell(self, row, col, *args, **kwargs): | ||
| """ Add a cell to the table. """ | ||
| xy = (0, 0) | ||
|
|
||
| cell = Cell(xy, *args, **kwargs) | ||
| cell = self._cellCreation[self._cellType](xy, *args, **kwargs) | ||
|
|
||
| cell.set_figure(self.figure) | ||
| cell.set_transform(self.get_transform()) | ||
|
|
||
|
|
@@ -453,16 +487,32 @@ def get_celld(self): | |
| 'return a dict of cells in the table' | ||
| return self._cells | ||
|
|
||
| @property | ||
| def cellType(self): | ||
| return self._cellType | ||
|
|
||
| @cellType.setter | ||
| def cellType(self, cellType): | ||
| if cellType is None: | ||
| self._cellType = 'default' | ||
|
|
||
| elif cellType in ('default', 'scicell'): | ||
| self._cellType = cellType | ||
|
|
||
| else: | ||
| raise ValueError('Unrecognized cellType %s; ' | ||
| 'must be "default" or "scicell"' % cellType) | ||
|
|
||
|
|
||
| def table(ax, | ||
| cellText=None, cellColours=None, | ||
| cellLoc='right', colWidths=None, | ||
| rowLabels=None, rowColours=None, rowLoc='left', | ||
| colLabels=None, colColours=None, colLoc='center', | ||
| loc='bottom', bbox=None, | ||
| loc='bottom', bbox=None, cellType=None, | ||
| **kwargs): | ||
| """ | ||
| TABLE(cellText=None, cellColours=None, | ||
| TABLE(cellType='default', cellText=None, cellColours=None, | ||
| cellLoc='right', colWidths=None, | ||
| rowLabels=None, rowColours=None, rowLoc='left', | ||
| colLabels=None, colColours=None, colLoc='center', | ||
|
|
@@ -472,6 +522,10 @@ def table(ax, | |
|
|
||
| Thanks to John Gill for providing the class and table. | ||
| """ | ||
| if cellType is not None and cellType not in ('default', 'scicell'): | ||
| raise ValueError('cellType must be "default" or "scicell" ' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look at the values in the dict instead of hard-coding them. |
||
| 'instead of %s ' % cellType) | ||
|
|
||
| # Check we have some cellText | ||
| if cellText is None: | ||
| # assume just colours are needed | ||
|
|
@@ -529,6 +583,7 @@ def table(ax, | |
| # Now create the table | ||
| table = Table(ax, loc, bbox, **kwargs) | ||
| height = table._approx_text_height() | ||
| table.cellType = cellType | ||
|
|
||
| # Add the cells | ||
| for row in xrange(rows): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
underscores instead of camel case please. Yes, the code base is mixed, but lets not make it worse with new additions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, scratch that, better to match internally in this class.