Browse Source

Bugfix

pull/8/head
Florian Mounier 13 years ago
parent
commit
eefe21d09f
  1. 2
      pygal/__init__.py
  2. 23
      pygal/graph/base.py

2
pygal/__init__.py

@ -16,7 +16,7 @@
# #
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>. # along with pygal. If not, see <http://www.gnu.org/licenses/>.
__version__ = '0.9.5' __version__ = '0.9.7'
from collections import namedtuple from collections import namedtuple
from pygal.graph.bar import Bar from pygal.graph.bar import Bar

23
pygal/graph/base.py

@ -25,6 +25,8 @@ class BaseGraph(object):
return object.__getattribute__(self, attr) return object.__getattribute__(self, attr)
def _pos(self, min_, max_, scale, min_scale=4, max_scale=20): def _pos(self, min_, max_, scale, min_scale=4, max_scale=20):
if min_ == 0 and max_ == 0:
return [0]
order = round(log10(max(abs(min_), abs(max_)))) - 1 order = round(log10(max(abs(min_), abs(max_)))) - 1
while (max_ - min_) / float(10 ** order) < min_scale: while (max_ - min_) / float(10 ** order) < min_scale:
order -= 1 order -= 1
@ -38,8 +40,8 @@ class BaseGraph(object):
if min_ <= rounded <= max_: if min_ <= rounded <= max_:
positions.add(rounded) positions.add(rounded)
position += step position += step
if not positions: if len(positions) < 2:
return [min_] return [min_, max_]
return positions return positions
def _text_len(self, lenght, fs): def _text_len(self, lenght, fs):
@ -109,26 +111,9 @@ class BaseGraph(object):
serie.values = [serie.values] serie.values = [serie.values]
if sum(map(len, map(lambda s: s.values, self.series))) == 0: if sum(map(len, map(lambda s: s.values, self.series))) == 0:
return return
try:
self.validate() self.validate()
self._draw() self._draw()
return self.svg.render() return self.svg.render()
except Exception:
from traceback import format_exc
error_svg = (
'<?xml version="1.0" standalone="no"?>'
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
'"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'
'<svg xmlns="http://www.w3.org/2000/svg" version="1.1">')
trace = (format_exc()
.replace('&', '&amp;')
.replace('<', '&lt;')
.replace('>', '&gt;'))
for i, line in enumerate(trace.split('\n')):
error_svg += '<text y="%d">%s</text>' % (
(i + 1) * 25, line)
error_svg += '</svg>'
return error_svg
def validate(self): def validate(self):
if self.x_labels: if self.x_labels:

Loading…
Cancel
Save