emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Thierry Banel <tbanelwebmin@free.fr>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: [PATCH] adding flexibility to ASCII bar plot
Date: Sun, 18 Feb 2018 18:19:37 +0100	[thread overview]
Message-ID: <5A89B5A9.40309@free.fr> (raw)

[-- 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


                 reply	other threads:[~2018-02-18 17:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5A89B5A9.40309@free.fr \
    --to=tbanelwebmin@free.fr \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).