Someone named novoid on GitHub suggested to add some flexibility to the
ASCII bar plot.
Attached is a patch implementing it.
Example:
| 1 | WWW |
| 2 | WWWWWW |
| 3 | WWWWWWWWW |
| 4 | WWWWWWWWWWWW |
#+TBLFM: $2='(orgtbl-ascii-draw $1 0 @>$1 12)
Note the @>$1 cell reference passed to the MAX parameter.
Previously, only hard coded values like 4 could be used.
Regards
Thierry
>From f12eea7d34bf7d6445dc8a03923264fef73279a2 Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelweb...@free.fr>
Date: Sun, 18 Feb 2018 17:59:16 +0100
Subject: [PATCH] Added flexibility for ASCII bar plots
* org-table.el (orgtbl-ascii-draw): MIN and MAX
parameters now accept cell formulas such as @>$2
* manual.org, org.texi: reflect added feature
in reference documentation.
Thanks to github/novoid for suggesting this
---
contrib/manual.org | 3 ++-
doc/org.texi | 3 ++-
lisp/org-table.el | 4 ++++
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/contrib/manual.org b/contrib/manual.org
index 8a7a0b9..0db2ddf 100644
--- a/contrib/manual.org
+++ b/contrib/manual.org
@@ -3022,7 +3022,8 @@ Draw an ASCII bar in a table.
{{{var(MIN)}}} is the value displayed as an empty bar. {{{var(MAX)}}}
is the value filling all the {{{var(WIDTH)}}}. Sources values outside
-this range are displayed as =too small= or =too large=.
+this range are displayed as =too small= or =too large=. They can be
+constant values, or references to cells, like {{{var(@>$2)}}}.
{{{var(WIDTH)}}} is the number of characters of the bar plot. It
defaults to =12=.
diff --git a/doc/org.texi b/doc/org.texi
index 9b4a4de..603fb42 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -3353,7 +3353,8 @@ The formula is an elisp call:
@item MIN MAX
are the minimal and maximal values displayed. Sources values
outside this range are displayed as @samp{too small}
- or @samp{too large}.
+ or @samp{too large}. They can be constant values, or references
+ to cells, like @samp{@>$2}.
@item WIDTH
is the width in characters of the bar-plot. It defaults to @samp{12}.
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 9ab15e6..9060400 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -5672,6 +5672,10 @@ of regular ascii characters."
(len (1- (length characters)))
(value (float (if (numberp value)
value (string-to-number value))))
+ (min (float (if (numberp min)
+ min (string-to-number min))))
+ (max (float (if (numberp max)
+ max (string-to-number max))))
(relative (/ (- value min) (- max min)))
(steps (round (* relative width len))))
(cond ((< steps 0) "too small")
--
2.1.4