emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] adding flexibility to ASCII bar plot
@ 2018-02-18 17:19 Thierry Banel
  0 siblings, 0 replies; only message in thread
From: Thierry Banel @ 2018-02-18 17:19 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 411 bytes --]

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












[-- Attachment #2: 0001-Added-flexibility-for-ASCII-bar-plots.patch --]
[-- Type: text/x-diff, Size: 2295 bytes --]

From f12eea7d34bf7d6445dc8a03923264fef73279a2 Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelwebmin@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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-02-18 17:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-18 17:19 [PATCH] adding flexibility to ASCII bar plot Thierry Banel

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).