Browse Source

Secondary interpolation fix. Fix #165

pull/185/head
Florian Mounier 10 years ago
parent
commit
333597f195
  1. 7
      demo/moulinrouge/tests.py
  2. 4
      pygal/graph/bar.py
  3. 5
      pygal/graph/graph.py
  4. 15
      pygal/graph/line.py

7
demo/moulinrouge/tests.py

@ -517,6 +517,13 @@ def get_test_routes(app):
pie.legend_at_bottom_columns = 4 pie.legend_at_bottom_columns = 4
return pie.render_response() return pie.render_response()
@app.route('/test/interpolate/secondary')
def test_interpolate_secondary():
chart = Line(title=u'Some different points', interpolate='cubic')
chart.add('line', [1000, 2000, 7000])
chart.add('other line', [100, 500, 500], secondary=True)
return chart.render_response()
@app.route('/test/legend_at_bottom/<chart>') @app.route('/test/legend_at_bottom/<chart>')
def test_legend_at_bottom_for(chart): def test_legend_at_bottom_for(chart):
graph = CHARTS_BY_NAME[chart]() graph = CHARTS_BY_NAME[chart]()

4
pygal/graph/bar.py

@ -61,9 +61,7 @@ class Bar(Graph):
serie_node = self.svg.serie(serie) serie_node = self.svg.serie(serie)
bars = self.svg.node(serie_node['plot'], class_="bars") bars = self.svg.node(serie_node['plot'], class_="bars")
if rescale and self.secondary_series: if rescale and self.secondary_series:
points = [ points = self._rescale(serie.points)
(x, self._scale_diff + (y - self._scale_min_2nd) * self._scale)
for x, y in serie.points if y is not None]
else: else:
points = serie.points points = serie.points

5
pygal/graph/graph.py

@ -419,6 +419,11 @@ class Graph(BaseGraph):
x, y, self.interpolation_precision, x, y, self.interpolation_precision,
**self.interpolation_parameters)) **self.interpolation_parameters))
def _rescale(self, points):
return [
(x, self._scale_diff + (y - self._scale_min_2nd) * self._scale)
for x, y in points if y is not None]
def _tooltip_data(self, node, value, x, y, classes=None): def _tooltip_data(self, node, value, x, y, classes=None):
self.svg.node(node, 'desc', class_="value").text = value self.svg.node(node, 'desc', class_="value").text = value
if classes is None: if classes is None:

15
pygal/graph/line.py

@ -69,7 +69,11 @@ class Line(Graph):
if y is not None: if y is not None:
break break
else: else:
raise ValueError("Invalid value ({}) for config key 'missing_value_fill_truncation'; Use 'x', 'y' or 'either'".format(self.missing_value_fill_truncation)) raise ValueError(
"Invalid value ({}) for config key "
"'missing_value_fill_truncation';"
" Use 'x', 'y' or 'either'".format(
self.missing_value_fill_truncation))
end -= 1 end -= 1
return ([(values[0][0], zero)] + return ([(values[0][0], zero)] +
@ -80,9 +84,7 @@ class Line(Graph):
"""Draw the line serie""" """Draw the line serie"""
serie_node = self.svg.serie(serie) serie_node = self.svg.serie(serie)
if rescale and self.secondary_series: if rescale and self.secondary_series:
points = [ points = self._rescale(serie.points)
(x, self._scale_diff + (y - self._scale_min_2nd) * self._scale)
for x, y in serie.points if y is not None]
else: else:
points = serie.points points = serie.points
view_values = list(map(self.view, points)) view_values = list(map(self.view, points))
@ -118,7 +120,10 @@ class Line(Graph):
if serie.stroke: if serie.stroke:
if self.interpolate: if self.interpolate:
view_values = list(map(self.view, serie.interpolated)) points = serie.interpolated
if rescale and self.secondary_series:
points = self._rescale(points)
view_values = list(map(self.view, points))
if serie.fill: if serie.fill:
view_values = self._fill(view_values) view_values = self._fill(view_values)
self.svg.line( self.svg.line(

Loading…
Cancel
Save