From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1enScp-00061F-Im for emacs-orgmode@gnu.org; Sun, 18 Feb 2018 12:19:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1enScm-0003GW-Ei for emacs-orgmode@gnu.org; Sun, 18 Feb 2018 12:19:43 -0500 Received: from smtp4-g21.free.fr ([212.27.42.4]:1026) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1enScm-0003ED-5B for emacs-orgmode@gnu.org; Sun, 18 Feb 2018 12:19:40 -0500 Received: from [IPv6:2a01:e35:2e21:def0:21de:fa02:5bf0:9db6] (unknown [IPv6:2a01:e35:2e21:def0:21de:fa02:5bf0:9db6]) by smtp4-g21.free.fr (Postfix) with ESMTP id 261F419F595 for ; Sun, 18 Feb 2018 18:19:37 +0100 (CET) Message-ID: <5A89B5A9.40309@free.fr> Date: Sun, 18 Feb 2018 18:19:37 +0100 From: Thierry Banel MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090601020105000300070401" Subject: [PATCH] adding flexibility to ASCII bar plot List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+kyle=kyleam.com@gnu.org Sender: "Emacs-orgmode" To: Org Mode This is a multi-part message in MIME format. --------------090601020105000300070401 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------090601020105000300070401 Content-Type: text/x-diff; name="0001-Added-flexibility-for-ASCII-bar-plots.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Added-flexibility-for-ASCII-bar-plots.patch" >From f12eea7d34bf7d6445dc8a03923264fef73279a2 Mon Sep 17 00:00:00 2001 From: Thierry Banel 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 --------------090601020105000300070401--