Skip to content

Commit

Permalink
Add grid background color. Closes #40.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed May 19, 2016
1 parent 3594efc commit 7d5e873
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
15 changes: 9 additions & 6 deletions leather/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ def to_svg_group(self, width, height):
margin_width = width - (margin.left + margin.right)
margin_height = height - (margin.top + margin.bottom)

root_group.append(margin_group)

# Header
header_group = ET.Element('g')

header_margin = 0

if self._title:
Expand All @@ -193,13 +196,17 @@ def to_svg_group(self, width, height):
header_group.append(label)
header_margin += theme.title_font_char_height

margin_group.append(header_group)

# Body
body_group = ET.Element('g')
body_group.set('transform', svg.translate(0, header_margin))

body_width = margin_width
body_height = margin_height - header_margin

margin_group.append(body_group)

# Axes
x_scale, x_axis = self._validate_dimension(X)
y_scale, y_axis = self._validate_dimension(Y)
Expand All @@ -218,19 +225,15 @@ def to_svg_group(self, width, height):

header_group.set('transform', svg.translate(left_margin, 0))

body_group.append(axes_group)

# Series
series_group = ET.Element('g')

for series in self._layers:
series_group.append(series.to_svg(canvas_width, canvas_height, x_scale, y_scale))

axes_group.append(series_group)
body_group.append(axes_group)

margin_group.append(header_group)
margin_group.append(body_group)

root_group.append(margin_group)

return root_group

Expand Down
20 changes: 19 additions & 1 deletion leather/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ def to_svg(self, path=None, width=None, height=None):
xmlns='http://www.w3.org/2000/svg'
)

# Root / background
root_group = ET.Element('g')

root_group.append(ET.Element('rect',
x=six.text_type(0),
y=six.text_type(0),
width=six.text_type(width),
height=six.text_type(height),
fill=theme.background_color
))

root.append(root_group)

# Charts
grid_group = ET.Element('g')

chart_count = len(self._charts)
grid_width = math.ceil(math.sqrt(chart_count))
grid_height = math.ceil(chart_count / grid_width)
Expand All @@ -60,7 +76,9 @@ def to_svg(self, path=None, width=None, height=None):
chart = chart.to_svg_group(chart_width, chart_height)
group.append(chart)

root.append(group)
grid_group.append(group)

root_group.append(grid_group)

svg_text = svg.stringify(root)
close = True
Expand Down

0 comments on commit 7d5e873

Please sign in to comment.