Skip to content

Commit

Permalink
Style table and fix thead
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Jun 5, 2014
1 parent 55e8f3d commit 8bb982e
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions pygal/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def render(self, total=False, transpose=False, style=False):
_ = lambda x: x if x is not None else ''

if self.x_labels:
labels = list(self.x_labels)
labels = [None] + list(self.x_labels)
if len(labels) < self._len:
labels += [None] * (self._len - len(labels))
if len(labels) > self._len:
labels = labels[:self._len]
labels += [None] * (self._len + 1 - len(labels))
if len(labels) > self._len + 1:
labels = labels[:self._len + 1]
table.append(labels)

if total:
Expand Down Expand Up @@ -113,6 +113,10 @@ def render(self, total=False, transpose=False, style=False):
else:
tbody = table

if total:
tfoot = [tbody[-1]]
tbody = tbody[:-1]

parts = []
if thead:
parts.append(
Expand Down Expand Up @@ -147,12 +151,35 @@ def render(self, total=False, transpose=False, style=False):
if style:
if style is True:
css = '''
#{{ id }}{
width: 100%;
}
#{{ id }} tbody tr:nth-child(odd) td {
background-color: #f9f9f9;
}
#{{ id }} {
border-collapse: collapse;
border-spacing: 0;
empty-cells: show;
border: 1px solid #cbcbcb;
}
#{{ id }} td, #{{ id }} th {
border-left: 1px solid #cbcbcb;
border-width: 0 0 0 1px;
margin: 0;
padding: 0.5em 1em;
}
#{{ id }} td:first-child, #{{ id }} th:first-child {
border-left-width: 0;
}
#{{ id }} thead, #{{ id }} tfoot {
color: #000;
text-align: left;
vertical-align: bottom;
}
#{{ id }} thead {
background: #e0e0e0;
}
#{{ id }} tfoot {
background: #ededed;
}
#{{ id }} tr:nth-child(2n-1) td {
background-color: #f2f2f2;
}
'''
else:
css = style
Expand Down

0 comments on commit 8bb982e

Please sign in to comment.