From c089679fac1e91755d1a5640b8e95ae12c1c4b92 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 28 Nov 2012 15:15:34 +0100 Subject: [PATCH 1/2] Make value formatting fully configurable (through a lambda). --- pygal/config.py | 4 ++++ pygal/graph/base.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pygal/config.py b/pygal/config.py index 17e127c..38fca08 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)") + value_format = Key( + None, type(lambda: 1), "Value", + "A function to convert numeric value to strings") + logarithmic = Key( False, bool, "Value", "Display values in logarithmic scale") diff --git a/pygal/graph/base.py b/pygal/graph/base.py index 547e96f..0516516 100644 --- a/pygal/graph/base.py +++ b/pygal/graph/base.py @@ -80,7 +80,7 @@ class BaseGraph(object): @property def _format(self): """Return the value formatter for this graph""" - return humanize if self.human_readable else str + return self.value_format or (humanize if self.human_readable else str) def _compute(self): """Initial computations to draw the graph""" From 46508dad6569b1bc7743006f4980a7940d9e01b9 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 28 Nov 2012 15:18:43 +0100 Subject: [PATCH 2/2] Rename Config.value_format to value_formatter --- pygal/config.py | 2 +- pygal/graph/base.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index 38fca08..8521cda 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -154,7 +154,7 @@ class Config(object): False, bool, "Value", "Display values in human readable format", "(ie: 12.4M)") - value_format = Key( + value_formatter = Key( None, type(lambda: 1), "Value", "A function to convert numeric value to strings") diff --git a/pygal/graph/base.py b/pygal/graph/base.py index 0516516..0835ef6 100644 --- a/pygal/graph/base.py +++ b/pygal/graph/base.py @@ -80,7 +80,8 @@ class BaseGraph(object): @property def _format(self): """Return the value formatter for this graph""" - return self.value_format or (humanize if self.human_readable else str) + return self.value_formatter or ( + humanize if self.human_readable else str) def _compute(self): """Initial computations to draw the graph"""