Browse Source

Fix title alignment

pull/28/head
Florian Mounier 12 years ago
parent
commit
b142ca6c27
  1. 11
      demo/moulinrouge/tests.py
  2. 18
      pygal/graph/graph.py

11
demo/moulinrouge/tests.py

@ -54,8 +54,15 @@ def get_test_routes(app):
@app.route('/test/long_title') @app.route('/test/long_title')
def test_long_title(): def test_long_title():
bar = Bar() bar = Bar()
bar.add('Lol', [2, None, 12]) bar.add('Loooooooooooooooooooooooooooooooooool', [2, None, 12])
bar.title = '123456789 ' * 30 bar.title = (
'1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890 '
'12345678901 123456789012 1234567890123 12345678901234 '
'123456789012345 1234567890123456 12345678901234567 '
'123456789012345678 1234567890123456789 12345678901234567890 '
'123456789012345 1234567890123456 12345678901234567 '
'12345678901 123456789012 1234567890123 12345678901234 '
'1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890 ')
return bar.render_response() return bar.render_response()
@app.route('/test/none') @app.route('/test/none')

18
pygal/graph/graph.py

@ -143,13 +143,14 @@ class Graph(BaseGraph):
x_labels_major = [label[0] for label in self._x_labels] x_labels_major = [label[0] for label in self._x_labels]
else: else:
x_labels_major = [self._x_labels[ x_labels_major = [self._x_labels[
int(i * (label_count - 1) / (major_count - 1))][0] int(i * (label_count - 1) / (major_count - 1))][0]
for i in xrange(major_count)] for i in xrange(major_count)]
else: else:
x_labels_major = [] x_labels_major = []
for label, position in self._x_labels: for label, position in self._x_labels:
major = label in x_labels_major major = label in x_labels_major
if not (self.show_minor_x_labels or major): continue if not (self.show_minor_x_labels or major):
continue
guides = self.svg.node(axis, class_='guides') guides = self.svg.node(axis, class_='guides')
x = self.view.x(position) x = self.view.x(position)
y = self.view.height + 5 y = self.view.height + 5
@ -180,7 +181,8 @@ class Graph(BaseGraph):
self.nodes['plot'], class_="axis x x2") self.nodes['plot'], class_="axis x x2")
for label, position in self._x_2nd_labels: for label, position in self._x_2nd_labels:
major = label in x_labels_major major = label in x_labels_major
if not (self.show_minor_x_labels or major): continue if not (self.show_minor_x_labels or major):
continue
# it is needed, to have the same structure as primary axis # it is needed, to have the same structure as primary axis
guides = self.svg.node(secondary_ax, class_='guides') guides = self.svg.node(secondary_ax, class_='guides')
x = self.view.x(position) x = self.view.x(position)
@ -216,7 +218,8 @@ class Graph(BaseGraph):
)) ))
x = -5 x = -5
y = self.view.y(position) y = self.view.y(position)
if not y: continue if not y:
continue
if draw_axes: if draw_axes:
self.svg.node( self.svg.node(
guides, 'path', guides, 'path',
@ -348,10 +351,13 @@ class Graph(BaseGraph):
def _title(self): def _title(self):
"""Make the title""" """Make the title"""
if self.title: if self.title:
title_node = self.svg.node(
self.nodes['graph'],
class_="titles")
for i, title_line in enumerate(self.title, 1): for i, title_line in enumerate(self.title, 1):
self.svg.node( self.svg.node(
self.nodes['graph'], 'text', class_='title', title_node, 'text', class_='title',
x=self.margin.left + self.view.width / 2, x=self.width / 2,
y=i * (self.title_font_size + 10) y=i * (self.title_font_size + 10)
).text = title_line ).text = title_line

Loading…
Cancel
Save