From ac31c049804472a0e9ad2ab3769ee4ed79f53bea Mon Sep 17 00:00:00 2001 From: Thomas Jost Date: Wed, 31 Oct 2012 17:40:59 +0100 Subject: [PATCH] Add formatter config option --- pygal/config.py | 4 ++++ pygal/graph/base.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pygal/config.py b/pygal/config.py index 17e127c..f306019 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -154,6 +154,10 @@ class Config(object): False, bool, "Value", "Display values in human readable format", "(ie: 12.4M)") + formatter = Key( + None, callable, "Value", + "Function used to convert values into human readable format") + logarithmic = Key( False, bool, "Value", "Display values in logarithmic scale") diff --git a/pygal/graph/base.py b/pygal/graph/base.py index 5b413d2..6140d54 100644 --- a/pygal/graph/base.py +++ b/pygal/graph/base.py @@ -80,7 +80,12 @@ class BaseGraph(object): @property def _format(self): """Return the value formatter for this graph""" - return humanize if self.human_readable else str + if self.formatter is not None: + return self.formatter + elif self.human_readable: + return humanize + else: + return str def _compute(self): """Initial computations to draw the graph"""