emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* make orgtbl-ascii-plot easier to install
@ 2014-07-13 16:02 Thierry Banel
  2014-07-28 14:40 ` Bastien
  0 siblings, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-07-13 16:02 UTC (permalink / raw)
  To: emacs-orgmode

Hi The List

I moved orgtbl-ascii-plot to MELPA (it was in Worg).
(orgtbl-ascii-plot draws plots in pure Emacs by typing C-c p).

Of course, I am still open to Dominik Carsten suggestion
to add it into the core (org-table.el).
http://thread.gmane.org/gmane.emacs.orgmode/79668

In the process I wrote a tutorial on how to contribute to Org
through Melpa + GitHub.
See http://orgmode.org/worg/org-tutorials/melpa-github.html

As usual, your comments, enhancements, criticisms
are welcome.

Have fun
Thierry

-------------

Documentation:
http://orgmode.org/worg/org-contrib/orgtbl-ascii-plot.html

Install:
add the MELPA repository in your .emacs:
(add-to-list 'package-archives '("melpa" .
"http://melpa.milkbox.net/packages/") t)
M-x package-list-packages

Source:
https://github.com/tbanel/orgtblasciiplot/blob/master/orgtbl-ascii-plot.el

| n | n^2 | ascii-plot   |
|---+-----+--------------|
| 0 |   0 |              |
| 1 |   1 | .            |
| 2 |   4 | h            |
| 3 |   9 | Wl           |
| 4 |  16 | WWW          |
| 5 |  25 | WWWWl        |
| 6 |  36 | WWWWWWh      |
| 7 |  49 | WWWWWWWWW.   |
| 8 |  64 | WWWWWWWWWWWW |
#+TBLFM: $2=$1^2::$3='(orgtbl-ascii-draw $2 0 64 12)

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-07-13 16:02 make orgtbl-ascii-plot easier to install Thierry Banel
@ 2014-07-28 14:40 ` Bastien
  2014-08-10 22:22   ` Thierry Banel
  0 siblings, 1 reply; 31+ messages in thread
From: Bastien @ 2014-07-28 14:40 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Hi Thierry,

Thierry Banel <tbanelwebmin@free.fr> writes:

> I moved orgtbl-ascii-plot to MELPA (it was in Worg).
> (orgtbl-ascii-plot draws plots in pure Emacs by typing C-c p).

Thanks for this.

> Of course, I am still open to Dominik Carsten suggestion
> to add it into the core (org-table.el).
> http://thread.gmane.org/gmane.emacs.orgmode/79668

Please go ahead and provide a patch for this, I agree this
is a nice addition for Org's core.

Best,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-07-28 14:40 ` Bastien
@ 2014-08-10 22:22   ` Thierry Banel
  2014-08-26  8:29     ` Nicolas Goaziou
  0 siblings, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-08-10 22:22 UTC (permalink / raw)
  To: emacs-orgmode

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

Le 28/07/2014 16:40, Bastien a écrit :
>> Of course, I am still open to Dominik Carsten suggestion
>> to add it into the core (org-table.el).
>> http://thread.gmane.org/gmane.emacs.orgmode/79668
> Please go ahead and provide a patch for this, I agree this
> is a nice addition for Org's core.
>
Sorry for the late answer, I was on the road.
The patch is attached hereafter.

Have fun
Thierry



[-- Attachment #2: 0001-org-table.el-add-ascii-plotting-in-tables.patch --]
[-- Type: text/x-diff, Size: 4682 bytes --]

From 5fddaba2208c2cb4ce3b6bc24d0d10571124fb39 Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelwebmin@free.fr>
Date: Mon, 11 Aug 2014 00:00:21 +0200
Subject: [PATCH] 	* org-table.el: add ascii plotting in tables, 
 (orgtbl-ascii-plot): top-level function 
 (orgtbl-ascii-draw), 	(orgtbl-uc-draw-grid), 
 (orgtbl-uc-draw-cont): helper functions which go in table
 formulas 	for drawing bars 	* org.el: C-c p key
 binding on orgtbl-ascii-plot

---
 lisp/org-table.el |   83 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 lisp/org.el       |    1 +
 2 files changed, 84 insertions(+)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index d1609f9..5921902 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -5004,6 +5004,89 @@ it here: http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el."
       (user-error "Please download ascii-art-to-unicode.el (use C-c C-l to insert the link to it)"))
     (buffer-string)))
 
+(defun orgtbl-ascii-draw (value min max &optional width characters)
+  "Draws an ascii bar in a table.
+VALUE is a the value to plot, the width of the bar to draw.
+A value equal to MIN will be displayed as empty (zero width bar).
+A value equal to MAX will draw a bar filling all the WIDTH.
+WIDTH is the expected width in characters of the column.
+CHARACTERS is a string of characters that will compose the bar,
+with shades of grey from pure white to pure black.
+It defaults to a 10 characters string of regular ascii characters.
+"
+  (unless characters (setq characters " .:;c!lhVHW"))
+  (unless width (setq width 12))
+  (if (stringp value)
+      (setq value (string-to-number value)))
+  (setq value (* (/ (- (+ value 0.0) min) (- max min)) width))
+  (cond
+   ((< value     0) "too small")
+   ((> value width) "too large")
+   (t
+    (let ((len (1- (length characters))))
+      (concat
+       (make-string (floor value) (elt characters len))
+       (string (elt characters
+		    (floor (* (- value (floor value)) len)))))))))
+
+(defun orgtbl-uc-draw-grid (value min max &optional width)
+  "Draws an ascii bar in a table.
+It is a variant of orgtbl-ascii-draw with Unicode block characters,
+for a smooth display.
+Bars appear as grids (to the extend the font allows).
+"
+  ;; http://en.wikipedia.org/wiki/Block_Elements
+  ;; best viewed with the "DejaVu Sans Mono" font
+  (orgtbl-ascii-draw value min max width " \u258F\u258E\u258D\u258C\u258B\u258A\u2589"))
+
+(defun orgtbl-uc-draw-cont (value min max &optional width)
+  "Draws an ascii bar in a table.
+It is a variant of orgtbl-ascii-draw with Unicode block characters,
+for a smooth display.
+Bars are solid (to the extend the font allows).
+"
+  (orgtbl-ascii-draw value min max width " \u258F\u258E\u258D\u258C\u258B\u258A\u2589\u2588"))
+
+;;;###autoload
+(defun orgtbl-ascii-plot (&optional ask)
+  "Draws an ascii bars plot in a column, out of values found in another column.
+A numeric prefix may be given to override the default 12 characters wide plot.
+"
+  (interactive "P")
+  (let ((col (org-table-current-column))
+	(min  1e999)
+	(max -1e999)
+	(length 12)
+	(table (org-table-to-lisp)))
+    (cond ((consp ask)
+	   (setq length
+		 (or
+		  (read-string "Length of column [12] " nil nil 12)
+		  12)))
+	  ((numberp ask)
+	   (setq length ask)))
+    (mapc
+     (lambda (x)
+       (when (consp x)
+	 (setq x (nth (1- col) x))
+	 (when (string-match
+		"^[-+]?\\([0-9]*[.]\\)?[0-9]*\\([eE][+-]?[0-9]+\\)?$"
+		x)
+	   (setq x (string-to-number x))
+	   (if (> min x) (setq min x))
+	   (if (< max x) (setq max x)))))
+     (or (memq 'hline table) table)) ;; skip table header if any
+    (org-table-insert-column)
+    (org-table-move-column-right)
+    (org-table-store-formulas
+     (cons
+      (cons
+       (number-to-string (1+ col))
+       (format "'(%s $%s %s %s %s)"
+	       "orgtbl-ascii-draw" col min max length))
+      (org-table-get-stored-formulas)))
+    (org-table-recalculate t)))
+
 (defun org-table-get-remote-range (name-or-id form)
   "Get a field value or a list of values in a range from table at ID.
 
diff --git a/lisp/org.el b/lisp/org.el
index 9b25204..928a5dd 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19459,6 +19459,7 @@ boundaries."
 (org-defkey org-mode-map "\C-c="    'org-table-eval-formula)
 (org-defkey org-mode-map "\C-c'"    'org-edit-special)
 (org-defkey org-mode-map "\C-c`"    'org-table-edit-field)
+(org-defkey org-mode-map "\C-cp"    'orgtbl-ascii-plot)
 (org-defkey org-mode-map "\C-c|"    'org-table-create-or-convert-from-region)
 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
 (org-defkey org-mode-map "\C-c~"    'org-table-create-with-table.el)
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-10 22:22   ` Thierry Banel
@ 2014-08-26  8:29     ` Nicolas Goaziou
  2014-08-26 19:52       ` Thierry Banel
  0 siblings, 1 reply; 31+ messages in thread
From: Nicolas Goaziou @ 2014-08-26  8:29 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Hello,

Thierry Banel <tbanelwebmin@free.fr> writes:

> Sorry for the late answer, I was on the road.
> The patch is attached hereafter.

Thank you for the patch. Some comments follow.

> From 5fddaba2208c2cb4ce3b6bc24d0d10571124fb39 Mon Sep 17 00:00:00 2001
> From: Thierry Banel <tbanelwebmin@free.fr>
> Date: Mon, 11 Aug 2014 00:00:21 +0200
> Subject: [PATCH] 	* org-table.el: add ascii plotting in tables, 
>  (orgtbl-ascii-plot): top-level function 
>  (orgtbl-ascii-draw), 	(orgtbl-uc-draw-grid), 
>  (orgtbl-uc-draw-cont): helper functions which go in table

If they are helper functions, I suggest to use "--" in their name, e.g.,
`orgbtl--ascii-draw'.

> +(defun orgtbl-ascii-draw (value min max &optional width characters)
> +  "Draws an ascii bar in a table.
> +VALUE is a the value to plot, the width of the bar to draw.
> +A value equal to MIN will be displayed as empty (zero width bar).
> +A value equal to MAX will draw a bar filling all the WIDTH.
> +WIDTH is the expected width in characters of the column.
> +CHARACTERS is a string of characters that will compose the bar,

This is a minor issue, but a "string of characters" sounds strange:
aren't all strings constituted of characters? Maybe you really want
a list of characters.

> +with shades of grey from pure white to pure black.
> +It defaults to a 10 characters string of regular ascii characters.
> +"

Spurious newline at the end of the docstring.

> +  (unless characters (setq characters " .:;c!lhVHW"))
> +  (unless width (setq width 12))

I suggest let-binding variables instead:

  (let ((characters (or characters " .:;c!lhvHW"))
        (width (or width 12))))

> +  (if (stringp value)
> +      (setq value (string-to-number value)))

Prefer `and' or `when' over one-armed `if'.  Also, this may be dangerous
since `string-to-number' can return funny values.  Why wouldn't you
simply forbid strings and limit VALUE to integers.

> +  (setq value (* (/ (- (+ value 0.0) min) (- max min)) width))

(let ((value ...)))

> +  (cond
> +   ((< value     0) "too small")
> +   ((> value width) "too large")
> +   (t
> +    (let ((len (1- (length characters))))
> +      (concat
> +       (make-string (floor value) (elt characters len))
> +       (string (elt characters
> +		    (floor (* (- value (floor value)) len)))))))))
> +
> +(defun orgtbl-uc-draw-grid (value min max &optional width)
> +  "Draws an ascii bar in a table.
> +It is a variant of orgtbl-ascii-draw with Unicode block characters,
> +for a smooth display.
> +Bars appear as grids (to the extend the font allows).
> +"

Spurious newline. I wouldn't put the last sentence on its own line, too.
Also, isn't it "extent"?

> +(defun orgtbl-uc-draw-cont (value min max &optional width)
> +  "Draws an ascii bar in a table.
> +It is a variant of orgtbl-ascii-draw with Unicode block characters,
> +for a smooth display.
> +Bars are solid (to the extend the font allows).
> +"

Ditto.

> +  (orgtbl-ascii-draw value min max width " \u258F\u258E\u258D\u258C\u258B\u258A\u2589\u2588"))
> +
> +;;;###autoload
> +(defun orgtbl-ascii-plot (&optional ask)
> +  "Draws an ascii bars plot in a column, out of values found in another column.
> +A numeric prefix may be given to override the default 12 characters wide plot.
> +"

You must refer explicitly to ASK in your docstring. In particular, you
may want to detail the distinction between '(4) and 4.

Spurious newline too.

> +  (interactive "P")
> +  (let ((col (org-table-current-column))
> +	(min  1e999)

`most-positive-fixnum'

> +	(max -1e999)

`most-negative-fixnum'

> +	(length 12)
> +	(table (org-table-to-lisp)))
> +    (cond ((consp ask)
> +	   (setq length
> +		 (or
> +		  (read-string "Length of column [12] " nil nil 12)
> +		  12)))
> +	  ((numberp ask)
> +	   (setq length ask)))

(let ((length (cond ((consp ask)
                     (read-number "Length of column [12] " nil nil 12))
                    ((numberp ask) ask)
                    (t 12)))))

> +    (mapc

Small nitpick: I suggest to use `dolist' instead of `mapc' (no funcall
overhead).

> +     (lambda (x)
> +       (when (consp x)
> +	 (setq x (nth (1- col) x))
> +	 (when (string-match
> +		"^[-+]?\\([0-9]*[.]\\)?[0-9]*\\([eE][+-]?[0-9]+\\)?$"
> +		x)

Would `org-table-number-regexp' make sense here instead of the
hard-coded regexp?

> +	   (setq x (string-to-number x))
> +	   (if (> min x) (setq min x))
> +	   (if (< max x) (setq max x)))))

(when (> min x) ...)
(when (< max x))

> +     (or (memq 'hline table) table)) ;; skip table header if any

This check is not sufficient in the following cases:

  |-----------|
  | no header |
  |-----------|

and

  |----------|
  |  header  |
  |----------|
  | contents |

IOW, you need to eliminate the leading 'hline, if any, and skip until
the next 'hline if there is one and if there is something after it.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-26  8:29     ` Nicolas Goaziou
@ 2014-08-26 19:52       ` Thierry Banel
  2014-08-26 20:27         ` Nicolas Goaziou
  0 siblings, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-08-26 19:52 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/html, Size: 7822 bytes --]

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-26 19:52       ` Thierry Banel
@ 2014-08-26 20:27         ` Nicolas Goaziou
  2014-08-26 21:42           ` Thierry Banel
  0 siblings, 1 reply; 31+ messages in thread
From: Nicolas Goaziou @ 2014-08-26 20:27 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Thierry Banel <tbanelwebmin@free.fr> writes:

> I'll change to let-binding. What is the rational for that ? Better
> byte-code ?

This is faster, indeed. Also, the scope of the binding is explicit. It
is sometimes hard to tell where the value of a setq'ed variable comes
from.

> Can I limit VALUE to numbers ? VALUE comes from a cell in the table.
> The formula line of the table looks like this:
>
> #+TBLFM: $2='(orgtbl-ascii-draw $1 1 3 12)
>
> VALUE is $1 in this formula.
> If (string-to-number VALUE) fails, it will return zero, which is not
> very harmful.

Nevermind then.

> Actually this should be `cl-most-positive-float', because everything
> here works in floating point values. Thanks for the clue.

Oh, right. Then, I wouldn't bother in this case. Org supports Emacs 23
and cl-lib is not easily available.

> Small nitpick: I suggest to use `dolist' instead of `mapc' (no funcall
> overhead).
>
> Sure, easier to read.

This is also kinda like let vs setq.

> Before hard-coding this regexp, I took a look at what was already
> there. org-table-number-regexp matches too much, for instance it
> matches:
> "<345"
> "345()"
> "345%45" 
> "0x45" // hexadecimal
> "1101#2" // base two
> Anyway, the string feeds (string-to-number x) which does not accept
> all those variations. So I created a regexp exactly fitted for
> (string-to-number). 

OK.

> IOW, you need to eliminate the leading 'hline, if any,and skip until
> the next 'hline if there is one and if there is something after it.
>
> Ok. Not completely fool-proof, but better.

Do you think of another case that wouldn't be covered by this?

> On the other hand, this loop searches for the min and the max of
> a column, ignoring entries which are not numbers. So it could just
> iterate over the full column, including any kind of headers.
>
> | header | <-- ignored
> |--------| <-- ignored
> | 1 | <-- used (will set min=1)
> | 2 | <-- used
> | xx | <-- ignored
> | 3 | <-- used (will set max=3)
> |--------| <-- ignored

But header and the rest of the column may be both numbers but expressed
in different units, e.g. header could be a year and column inhabitants.
FWIW, I think skipping header (when there is one) is a good idea.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-26 20:27         ` Nicolas Goaziou
@ 2014-08-26 21:42           ` Thierry Banel
  2014-08-26 22:09             ` Nicolas Goaziou
  0 siblings, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-08-26 21:42 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/html, Size: 6397 bytes --]

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-26 21:42           ` Thierry Banel
@ 2014-08-26 22:09             ` Nicolas Goaziou
  2014-08-26 22:21               ` Thierry Banel
  2014-08-27 21:35               ` Thierry Banel
  0 siblings, 2 replies; 31+ messages in thread
From: Nicolas Goaziou @ 2014-08-26 22:09 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Thierry Banel <tbanelwebmin@free.fr> writes:

> Do you recommend to stay away from CL & CL-LIB for ORG stuff ?
> `DOLIST' comes from CL as well...

Actually, `dolist' is a macro from "subr.el", which is then shadowed by
`cl-dolist', so there's no problem here.

BTW, you can use macros from cl (cl-lib doesn't exist in Emacs 23), not
so functions.

>     
>         IOW, you need to eliminate the leading 'hline, if any,and skip until
> the next 'hline if there is one and if there is something after it.
>
> Ok. Not completely fool-proof, but better.
>
>     
> Do you think of another case that wouldn't be covered by this?
>
> 1st case: a header and several hlines.
> In this case, values 1,2,3 will be ignored.
>
> | header |
> |--------| <-- leading hline: skipped
> | 1 |
> | 2 |
> | 3 |
> |--------| <-- next hline: ignore whatever is before
> | 4 |
> | 5 |
> | 6 |

I wasn't clear. A "leading hline" is when the very first row is a hline
(or worse consecutive hlines start the table). In the example above,
there is no such leading hline, so you don't eliminate it. Therefore,
only header will be skipped.

> 2nd case: no header at all, values in boxes.
> Values 1,2,3 will be ignored as well.
>
> |--------| <-- leading hline: skipped
> | 1 |
> | 2 |
> | 3 |
> |--------| <-- next hline: ignore whatever is before
> | 4 |
> | 5 |
> | 6 |
> |--------| <-- last hline

There is a header. By definition, anything in the first column group is
a header. There is no limitations on the number of rows involved.

It may be a bit surprising, but this is consistent with the rest of Org.

> The only ill-interpreted case is this one, with no header.
> The first values are considered as headers:
>
> |---+----|
> | 3 | | <-- formula not applied
> | 4 | | <-- formula not applied
> |---+----|
> | 5 | 50 |
> | 6 | 60 |
> |---+----|
> #+TBLFM: $2=$1*10

See above.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-26 22:09             ` Nicolas Goaziou
@ 2014-08-26 22:21               ` Thierry Banel
  2014-08-27 21:35               ` Thierry Banel
  1 sibling, 0 replies; 31+ messages in thread
From: Thierry Banel @ 2014-08-26 22:21 UTC (permalink / raw)
  To: emacs-orgmode

Everything is clear now.
Thanks Nicolas for those guidelines.
Regards,
Thierry

Le 27/08/2014 00:09, Nicolas Goaziou a écrit :
> Actually, `dolist' is a macro from "subr.el", which is then shadowed by
> `cl-dolist', so there's no problem here.
>
> BTW, you can use macros from cl (cl-lib doesn't exist in Emacs 23), not
> so functions.
Ok, good.

>>     
>>
>> By definition, anything in the first column group is
>> a header. There is no limitations on the number of rows involved.
>>
>> It may be a bit surprising, but this is consistent with the rest of Org.
>>
> Regards, 
Good.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-26 22:09             ` Nicolas Goaziou
  2014-08-26 22:21               ` Thierry Banel
@ 2014-08-27 21:35               ` Thierry Banel
  2014-08-27 23:28                 ` Nicolas Goaziou
  1 sibling, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-08-27 21:35 UTC (permalink / raw)
  To: emacs-orgmode

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

Hereafter is an enhanced version of orgtbl-ascii-plot.

Thanks, Nicolas, for your feedback. Enhancements you suggested include:
- let-binding (instead of setq)
- better support for table headers (correct parsing of 'hline)
- no dependency on cl-lib (hopefully achieving Emacs 23 support)
- use dolist (instead of mapc)
- clean up doc-strings

Have fun
Thierry



[-- Attachment #2: 0001-Add-ascii-plotting-in-tables.patch --]
[-- Type: text/x-diff, Size: 6943 bytes --]

From 002e3b5baec9ba513c70914b9bfe17966aa9ca24 Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelwebmin@free.fr>
Date: Wed, 27 Aug 2014 23:11:11 +0200
Subject: [PATCH] Add ascii plotting in tables

* org-table.el (orgtbl-ascii-plot): top-level function.
(orgtbl-ascii-draw), (orgtbl-uc-draw-grid), (orgtbl-uc-draw-cont):
functions which go in table formulas for drawing bars.
* org.el: key binding and menu binding

Thanks to Michael Brand and Nicolas Goaziou for feedback and
enhancements.
---
 lisp/org-table.el | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lisp/org.el       |   4 ++-
 2 files changed, 107 insertions(+), 2 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 06a1008..88ae094 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -4326,7 +4326,8 @@ to execute outside of tables."
 	 ["Move Column Left" org-metaleft :active (org-at-table-p) :keys "M-<left>"]
 	 ["Move Column Right" org-metaright :active (org-at-table-p) :keys "M-<right>"]
 	 ["Delete Column" org-shiftmetaleft :active (org-at-table-p) :keys "M-S-<left>"]
-	 ["Insert Column" org-shiftmetaright :active (org-at-table-p) :keys "M-S-<right>"])
+	 ["Insert Column" org-shiftmetaright :active (org-at-table-p) :keys "M-S-<right>"]
+	 ["Ascii plot" orgtbl-ascii-plot :active (org-at-table-p) :keys "C-c p"])
 	("Row"
 	 ["Move Row Up" org-metaup :active (org-at-table-p) :keys "M-<up>"]
 	 ["Move Row Down" org-metadown :active (org-at-table-p) :keys "M-<down>"]
@@ -5008,6 +5009,108 @@ it here: http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el."
       (user-error "Please download ascii-art-to-unicode.el (use C-c C-l to insert the link to it)"))
     (buffer-string)))
 
+;; Put the cursor in a column containing numerical values
+;; of an Org-Mode table,
+;; type C-c p
+;; A new column is added with a bar plot.
+;; When the table is refreshed (C-u C-c *),
+;; the plot is updated to reflect the new values.
+
+(defun orgtbl-ascii-draw (value min max &optional width characters)
+  "Draws an ascii bar in a table.
+VALUE is a the value to plot, the width of the bar to draw.  A
+value equal to MIN will be displayed as empty (zero width bar).
+A value equal to MAX will draw a bar filling all the WIDTH.
+WIDTH is the expected width in characters of the column.
+CHARACTERS is a string that will compose the bar, with shades of
+grey from pure white to pure black. It defaults to a 10
+characters string of regular ascii characters."
+  (let* ((characters (or characters " .:;c!lhVHW"))
+	 (width (or width 12))
+	 (value (if (numberp value) value (string-to-number value)))
+	 (value (* (/ (- (+ value 0.0) min) (- max min)) width)))
+    (cond
+     ((< value     0) "too small")
+     ((> value width) "too large")
+     (t
+      (let ((len (1- (length characters))))
+	(concat
+	 (make-string (floor value) (elt characters len))
+	 (string (elt characters
+		      (floor (* (- value (floor value)) len))))))))))
+  
+;;;###autoload
+(defun orgtbl-ascii-plot (&optional ask)
+  "Draws an ascii bars plot in a column.
+With cursor in a column containing numerical values, this
+function will draw a plot in a new column. ASK, if given, is a
+numeric prefix to override the default 12 characters width of the
+plot. ASK may also be the C-u prefix, which will prompt for the
+width."
+  (interactive "P")
+  (let ((col (org-table-current-column))
+	(min  1e999) ;; 1e999 will be converted to infinity
+	(max -1e999) ;; which is the desired result
+	(table (org-table-to-lisp))
+	(length
+	 (cond ((consp ask)
+		(read-number "Length of column " 12))
+	       ((numberp ask) ask)
+	       (t 12))))
+    (dolist (x 
+	     (let ((t1 ;; skip table header
+		    (if (eq (car table) 'hline)
+			(cdr table)
+		      table)))
+	       (or (cdr (memq 'hline t1)) t1)))
+      (when (consp x)
+	(setq x (nth (1- col) x))
+	(when (string-match
+	       "^[-+]?\\([0-9]*[.]\\)?[0-9]*\\([eE][+-]?[0-9]+\\)?$"
+	       x)
+	  (setq x (string-to-number x))
+	  (when (> min x) (setq min x))
+	  (when (< max x) (setq max x)))))
+    (org-table-insert-column)
+    (org-table-move-column-right)
+    (org-table-store-formulas
+     (cons
+      (cons
+       (number-to-string (1+ col))
+       (format "'(%s $%s %s %s %s)"
+	       "orgtbl-ascii-draw" col min max length))
+      (org-table-get-stored-formulas)))
+    (org-table-recalculate t)))
+
+;; Example of extension: unicode characters
+;; Here are two examples of different styles.
+
+;; Unicode block characters are used to give a smooth effect.
+;; See http://en.wikipedia.org/wiki/Block_Elements
+;; Use one of those drawing functions
+;; - orgtbl-ascii-draw   (the default ascii)
+;; - orgtbl-uc-draw-grid (unicode with a grid effect)
+;; - orgtbl-uc-draw-cont (smooth unicode)
+
+;; This is best viewed with the "DejaVu Sans Mono" font
+;; (use M-x set-default-font).
+
+(defun orgtbl-uc-draw-grid (value min max &optional width)
+  "Draws an ascii bar in a table. It is a variant of
+orgtbl-ascii-draw with Unicode block characters, for a smooth
+display. Bars appear as grids (to the extent the font allows)."
+  ;; http://en.wikipedia.org/wiki/Block_Elements
+  ;; best viewed with the "DejaVu Sans Mono" font
+  (orgtbl-ascii-draw value min max width
+		     " \u258F\u258E\u258D\u258C\u258B\u258A\u2589"))
+  
+(defun orgtbl-uc-draw-cont (value min max &optional width)
+  "Draws an ascii bar in a table. It is a variant of
+orgtbl-ascii-draw with Unicode block characters, for a smooth
+display. Bars are solid (to the extent the font allows)."
+  (orgtbl-ascii-draw value min max width
+		     " \u258F\u258E\u258D\u258C\u258B\u258A\u2589\u2588"))
+
 (defun org-table-get-remote-range (name-or-id form)
   "Get a field value or a list of values in a range from table at ID.
 
diff --git a/lisp/org.el b/lisp/org.el
index 9fada32..e05a416 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19470,6 +19470,7 @@ boundaries."
 (org-defkey org-mode-map "\C-c="    'org-table-eval-formula)
 (org-defkey org-mode-map "\C-c'"    'org-edit-special)
 (org-defkey org-mode-map "\C-c`"    'org-table-edit-field)
+(org-defkey org-mode-map "\C-cp"    'orgtbl-ascii-plot)
 (org-defkey org-mode-map "\C-c|"    'org-table-create-or-convert-from-region)
 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
 (org-defkey org-mode-map "\C-c~"    'org-table-create-with-table.el)
@@ -21142,7 +21143,8 @@ on context.  See the individual commands for more information."
      ["Move Column Left" org-metaleft (org-at-table-p)]
      ["Move Column Right" org-metaright (org-at-table-p)]
      ["Delete Column" org-shiftmetaleft (org-at-table-p)]
-     ["Insert Column" org-shiftmetaright (org-at-table-p)])
+     ["Insert Column" org-shiftmetaright (org-at-table-p)]
+     ["Ascii plot" orgtbl-ascii-plot (org-at-table-p)])
     ("Row"
      ["Move Row Up" org-metaup (org-at-table-p)]
      ["Move Row Down" org-metadown (org-at-table-p)]
-- 
1.9.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-27 21:35               ` Thierry Banel
@ 2014-08-27 23:28                 ` Nicolas Goaziou
  2014-08-28 20:46                   ` Thierry Banel
  0 siblings, 1 reply; 31+ messages in thread
From: Nicolas Goaziou @ 2014-08-27 23:28 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Thierry Banel <tbanelwebmin@free.fr> writes:

> Hereafter is an enhanced version of orgtbl-ascii-plot.
>
> Thanks, Nicolas, for your feedback. Enhancements you suggested include:
> - let-binding (instead of setq)
> - better support for table headers (correct parsing of 'hline)
> - no dependency on cl-lib (hopefully achieving Emacs 23 support)
> - use dolist (instead of mapc)
> - clean up doc-strings

Thank you.

> +(defun orgtbl-ascii-plot (&optional ask)
> +  "Draws an ascii bars plot in a column.
> +With cursor in a column containing numerical values, this
> +function will draw a plot in a new column. ASK, if given, is a

You forgot a space at the end of the sentence. Actually, this is the
case in all your docstrings.

> +numeric prefix to override the default 12 characters width of the
> +plot. ASK may also be the C-u prefix, which will prompt for the
> +width."

Use "\\[universal-argument]" instead of "C-u".

> +    (dolist (x 
> +	     (let ((t1 ;; skip table header
> +		    (if (eq (car table) 'hline)
> +			(cdr table)
> +		      table)))

Just to be sure to catch the following (odd) table

 |--------|
 |--------|
 | header |
 |--------|
 | values |

I suggest the following

  (while (eq (car table) 'hline) (setq table (cdr table)))
  (dolist (x (or (cdr (memq 'hline table)) table))
    (when (consp x)
     (setq x (nth (1- col) x))
     (when (string-match "^[-+]?\\([0-9]*[.]\\)?[0-9]*\\([eE][+-]?[0-9]+\\)?$" x)
       (setq x (string-to-number x))
       (when (> min x) (setq min x))
       (when (< max x) (setq max x)))))

> +(defun orgtbl-uc-draw-grid (value min max &optional width)
> +  "Draws an ascii bar in a table. It is a variant of

The second sentence should start a new line.

> +(defun orgtbl-uc-draw-cont (value min max &optional width)
> +  "Draws an ascii bar in a table. It is a variant of

Ditto.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-27 23:28                 ` Nicolas Goaziou
@ 2014-08-28 20:46                   ` Thierry Banel
  2014-08-29  9:54                     ` Nicolas Goaziou
  0 siblings, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-08-28 20:46 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi Nicolas.

This new patch takes into account all your feedback.
Thanks again for the time spent !

Thierry


Le 28/08/2014 01:28, Nicolas Goaziou a écrit :
>
> You forgot a space at the end of the sentence. Actually, this is the
> case in all your docstrings.
Right. Fixed.

>
> Use "\\[universal-argument]" instead of "C-u".
I didn't knew this macro. Applied.

> Just to be sure to catch the following (odd) table
>
>  |--------|
>  |--------|
>  | header |
>  |--------|
>  | values |
>
> I suggest the following
>
>   (while (eq (car table) 'hline) (setq table (cdr table)))
>   (dolist (x (or (cdr (memq 'hline table)) table))
This is a strengthened algorithm, and it is shorter than the previous
version. Applied!

> The second sentence should start a new line.
Right. Fixed.


[-- Attachment #2: 0001-Add-ascii-plotting-in-tables.patch --]
[-- Type: text/x-diff, Size: 7044 bytes --]

From fac4561630c229fdb2356a93a0b575376c80bb7e Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelwebmin@free.fr>
Date: Thu, 28 Aug 2014 22:28:27 +0200
Subject: [PATCH] Add ascii plotting in tables

* org-table.el (orgtbl-ascii-plot): top-level function.
(orgtbl-ascii-draw), (orgtbl-uc-draw-grid), (orgtbl-uc-draw-cont):
functions which go in table formulas for drawing bars.
* org.el: key binding and menu binding

Thanks to Michael Brand and Nicolas Goaziou for feedback and
enhancements.
---
 lisp/org-table.el | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lisp/org.el       |   4 ++-
 2 files changed, 107 insertions(+), 2 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 06a1008..4be95bc 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -4326,7 +4326,8 @@ to execute outside of tables."
 	 ["Move Column Left" org-metaleft :active (org-at-table-p) :keys "M-<left>"]
 	 ["Move Column Right" org-metaright :active (org-at-table-p) :keys "M-<right>"]
 	 ["Delete Column" org-shiftmetaleft :active (org-at-table-p) :keys "M-S-<left>"]
-	 ["Insert Column" org-shiftmetaright :active (org-at-table-p) :keys "M-S-<right>"])
+	 ["Insert Column" org-shiftmetaright :active (org-at-table-p) :keys "M-S-<right>"]
+	 ["Ascii plot" orgtbl-ascii-plot :active (org-at-table-p) :keys "C-c p"])
 	("Row"
 	 ["Move Row Up" org-metaup :active (org-at-table-p) :keys "M-<up>"]
 	 ["Move Row Down" org-metadown :active (org-at-table-p) :keys "M-<down>"]
@@ -5008,6 +5009,108 @@ it here: http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el."
       (user-error "Please download ascii-art-to-unicode.el (use C-c C-l to insert the link to it)"))
     (buffer-string)))
 
+;; Put the cursor in a column containing numerical values
+;; of an Org-Mode table,
+;; type C-c p
+;; A new column is added with a bar plot.
+;; When the table is refreshed (C-u C-c *),
+;; the plot is updated to reflect the new values.
+
+(defun orgtbl-ascii-draw (value min max &optional width characters)
+  "Draws an ascii bar in a table.
+VALUE is a the value to plot, the width of the bar to draw.  A
+value equal to MIN will be displayed as empty (zero width bar).
+A value equal to MAX will draw a bar filling all the WIDTH.
+WIDTH is the expected width in characters of the column.
+CHARACTERS is a string that will compose the bar, with shades of
+grey from pure white to pure black.  It defaults to a 10
+characters string of regular ascii characters."
+  (let* ((characters (or characters " .:;c!lhVHW"))
+	 (width (or width 12))
+	 (value (if (numberp value) value (string-to-number value)))
+	 (value (* (/ (- (+ value 0.0) min) (- max min)) width)))
+    (cond
+     ((< value     0) "too small")
+     ((> value width) "too large")
+     (t
+      (let ((len (1- (length characters))))
+	(concat
+	 (make-string (floor value) (elt characters len))
+	 (string (elt characters
+		      (floor (* (- value (floor value)) len))))))))))
+  
+;;;###autoload
+(defun orgtbl-ascii-plot (&optional ask)
+  "Draws an ascii bar plot in a column.
+With cursor in a column containing numerical values, this
+function will draw a plot in a new column.
+ASK, if given, is a numeric prefix to override the default 12
+characters width of the plot.  ASK may also be the
+\\[universal-argument] prefix, which will prompt for the width."
+  (interactive "P")
+  (let ((col (org-table-current-column))
+	(min  1e999) ;; 1e999 will be converted to infinity
+	(max -1e999) ;; which is the desired result
+	(table (org-table-to-lisp))
+	(length
+	 (cond ((consp ask)
+		(read-number "Length of column " 12))
+	       ((numberp ask) ask)
+	       (t 12))))
+    (while (eq (car table) 'hline) ;; skip any hline a the top of table
+      (setq table (cdr table)))
+    (dolist (x
+	     (or (cdr (memq 'hline table)) table)) ;; skip table header if any
+      (when (consp x)
+	(setq x (nth (1- col) x))
+	(when (string-match
+	       "^[-+]?\\([0-9]*[.]\\)?[0-9]*\\([eE][+-]?[0-9]+\\)?$"
+	       x)
+	  (setq x (string-to-number x))
+	  (when (> min x) (setq min x))
+	  (when (< max x) (setq max x)))))
+    (org-table-insert-column)
+    (org-table-move-column-right)
+    (org-table-store-formulas
+     (cons
+      (cons
+       (number-to-string (1+ col))
+       (format "'(%s $%s %s %s %s)"
+	       "orgtbl-ascii-draw" col min max length))
+      (org-table-get-stored-formulas)))
+    (org-table-recalculate t)))
+
+;; Example of extension: unicode characters
+;; Here are two examples of different styles.
+
+;; Unicode block characters are used to give a smooth effect.
+;; See http://en.wikipedia.org/wiki/Block_Elements
+;; Use one of those drawing functions
+;; - orgtbl-ascii-draw   (the default ascii)
+;; - orgtbl-uc-draw-grid (unicode with a grid effect)
+;; - orgtbl-uc-draw-cont (smooth unicode)
+
+;; This is best viewed with the "DejaVu Sans Mono" font
+;; (use M-x set-default-font).
+
+(defun orgtbl-uc-draw-grid (value min max &optional width)
+  "Draws a bar in a table using block unicode characters.
+It is a variant of orgtbl-ascii-draw with Unicode block
+characters, for a smooth display.  Bars appear as grids (to the
+extent the font allows)."
+  ;; http://en.wikipedia.org/wiki/Block_Elements
+  ;; best viewed with the "DejaVu Sans Mono" font
+  (orgtbl-ascii-draw value min max width
+		     " \u258F\u258E\u258D\u258C\u258B\u258A\u2589"))
+  
+(defun orgtbl-uc-draw-cont (value min max &optional width)
+  "Draws a bar in a table using block unicode characters.
+It is a variant of orgtbl-ascii-draw with Unicode block
+characters, for a smooth display.  Bars are solid (to the extent
+the font allows)."
+  (orgtbl-ascii-draw value min max width
+		     " \u258F\u258E\u258D\u258C\u258B\u258A\u2589\u2588"))
+
 (defun org-table-get-remote-range (name-or-id form)
   "Get a field value or a list of values in a range from table at ID.
 
diff --git a/lisp/org.el b/lisp/org.el
index 9fada32..e05a416 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19470,6 +19470,7 @@ boundaries."
 (org-defkey org-mode-map "\C-c="    'org-table-eval-formula)
 (org-defkey org-mode-map "\C-c'"    'org-edit-special)
 (org-defkey org-mode-map "\C-c`"    'org-table-edit-field)
+(org-defkey org-mode-map "\C-cp"    'orgtbl-ascii-plot)
 (org-defkey org-mode-map "\C-c|"    'org-table-create-or-convert-from-region)
 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
 (org-defkey org-mode-map "\C-c~"    'org-table-create-with-table.el)
@@ -21142,7 +21143,8 @@ on context.  See the individual commands for more information."
      ["Move Column Left" org-metaleft (org-at-table-p)]
      ["Move Column Right" org-metaright (org-at-table-p)]
      ["Delete Column" org-shiftmetaleft (org-at-table-p)]
-     ["Insert Column" org-shiftmetaright (org-at-table-p)])
+     ["Insert Column" org-shiftmetaright (org-at-table-p)]
+     ["Ascii plot" orgtbl-ascii-plot (org-at-table-p)])
     ("Row"
      ["Move Row Up" org-metaup (org-at-table-p)]
      ["Move Row Down" org-metadown (org-at-table-p)]
-- 
1.9.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-28 20:46                   ` Thierry Banel
@ 2014-08-29  9:54                     ` Nicolas Goaziou
  2014-08-29 17:20                       ` Thierry Banel
  2014-09-02 21:53                       ` [PATCH] " Thierry Banel
  0 siblings, 2 replies; 31+ messages in thread
From: Nicolas Goaziou @ 2014-08-29  9:54 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Hello,

Thierry Banel <tbanelwebmin@free.fr> writes:

> This new patch takes into account all your feedback.
> Thanks again for the time spent !

Patch applied (with tiny changes to comments formatting, and a few
trailing whitespaces).

Thank you for this work.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: make orgtbl-ascii-plot easier to install
  2014-08-29  9:54                     ` Nicolas Goaziou
@ 2014-08-29 17:20                       ` Thierry Banel
  2014-09-02 21:53                       ` [PATCH] " Thierry Banel
  1 sibling, 0 replies; 31+ messages in thread
From: Thierry Banel @ 2014-08-29 17:20 UTC (permalink / raw)
  To: emacs-orgmode

Le 29/08/2014 11:54, Nicolas Goaziou a écrit :
>
> Patch applied (with tiny changes to comments formatting, and a few
> trailing whitespaces).
>

Great!
I will now write a few words of documentation.
This page [[info:org#Org-Plot]] seems to be the right place, unless
someone has a better idea.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] make orgtbl-ascii-plot easier to install
  2014-08-29  9:54                     ` Nicolas Goaziou
  2014-08-29 17:20                       ` Thierry Banel
@ 2014-09-02 21:53                       ` Thierry Banel
  2014-09-03 18:22                         ` Nicolas Goaziou
  1 sibling, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-09-02 21:53 UTC (permalink / raw)
  To: emacs-orgmode

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

Le 29/08/2014 11:54, Nicolas Goaziou a écrit :
>
> Patch applied (with tiny changes to comments formatting, and a few
> trailing whitespaces).
>

Here is a patch for the info doc.
I added a few lines in the Org-Plot page.

Regards
Thierry



[-- Attachment #2: 0001-doc-org.texi-Org-Plot-add-ascii-plot.patch --]
[-- Type: text/x-diff, Size: 2493 bytes --]

From 96155719a26614f1abed7370ddd81f7238767597 Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelwebmin@free.fr>
Date: Tue, 2 Sep 2014 23:41:41 +0200
Subject: [PATCH] * doc/org.texi (Org-Plot): add ascii plot

---
 doc/org.texi | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index fafa93b..d0e1476 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -3258,8 +3258,13 @@ functions.
 @cindex plot tables using Gnuplot
 @cindex #+PLOT
 
-Org-Plot can produce 2D and 3D graphs of information stored in org tables
-using @file{Gnuplot} @uref{http://www.gnuplot.info/} and @file{gnuplot-mode}
+Org-Plot can produce graphs of information stored in org tables, either
+graphically or in ascii-art.
+
+@subheading Graphical plots using @file{Gnuplot}
+
+Org-Plot produces 2D and 3D graphs using @file{Gnuplot}
+@uref{http://www.gnuplot.info/} and @file{gnuplot-mode}
 @uref{http://xafs.org/BruceRavel/GnuplotMode}.  To see this in action, ensure
 that you have both Gnuplot and Gnuplot mode installed on your system, then
 call @code{org-plot/gnuplot} on the following table.
@@ -3337,6 +3342,42 @@ may still want to specify the plot type, as that can impact the content of
 the data file.
 @end table
 
+@subheading Ascii bar plots
+
+While the cursor is on a column, typing @kbd{C-c p} create a new column
+containing an ascii-art bars plot.  The plot is implemented through a regular
+column formula.  When the source column changes, the bar plot may be updated
+by refreshing the table, for example typing @kbd{C-u C-c *}.
+
+@example
+@group
+| Sede      | Max cites |              |
+|-----------+-----------+--------------|
+| Chile     |    257.72 | WWWWWWWWWWWW |
+| Leeds     |    165.77 | WWWWWWWh     |
+| Sao Paolo |     71.00 | WWW;         |
+| Stockholm |    134.19 | WWWWWW:      |
+| Morelia   |    257.56 | WWWWWWWWWWWH |
+#+TBLFM: $3='(orgtbl-ascii-draw $2 0 257.72 12)
+@end group
+@end example
+
+The formula is an elisp call:
+@lisp
+(orgtbl-ascii-draw COLUMN MIN MAX WIDTH)
+@end lisp
+
+@table @code
+@item COLUMN
+  is a reference to the source column.
+@item MIN MAX
+  are the minimal and maximal values displayed.  Sources values
+  outside this range are displayed as @code{too small}
+  or @code{too large}.
+@item WIDTH
+  is the width in characters of the bar-plot.  It default to @code{12}.
+@end table
+
 @node Hyperlinks
 @chapter Hyperlinks
 @cindex hyperlinks
-- 
1.9.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] make orgtbl-ascii-plot easier to install
  2014-09-02 21:53                       ` [PATCH] " Thierry Banel
@ 2014-09-03 18:22                         ` Nicolas Goaziou
  2014-09-03 20:10                           ` A key-binding for plotting Thierry Banel
  2014-09-06 14:35                           ` [PATCH] remap orgtbl-ascii-plot to C-c # Thierry Banel
  0 siblings, 2 replies; 31+ messages in thread
From: Nicolas Goaziou @ 2014-09-03 18:22 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Hello,

Thierry Banel <tbanelwebmin@free.fr> writes:

> Here is a patch for the info doc.
> I added a few lines in the Org-Plot page.

It looks good but I realized (a bit late) we cannot use "C-c p" as it is
reserved to users, as any "C-c LETTER" combination.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: A key-binding for plotting
  2014-09-03 18:22                         ` Nicolas Goaziou
@ 2014-09-03 20:10                           ` Thierry Banel
  2014-09-06 14:35                           ` [PATCH] remap orgtbl-ascii-plot to C-c # Thierry Banel
  1 sibling, 0 replies; 31+ messages in thread
From: Thierry Banel @ 2014-09-03 20:10 UTC (permalink / raw)
  To: emacs-orgmode

Le 03/09/2014 20:22, Nicolas Goaziou a écrit :
> Hello,
>
> Thierry Banel <tbanelwebmin@free.fr> writes:
>
>> Here is a patch for the info doc.
>> I added a few lines in the Org-Plot page.
> It looks good but I realized (a bit late) we cannot use "C-c p" as it is
> reserved to users, as any "C-c LETTER" combination.
>
>
> Regards,
>

Sorry, I was not aware of this rule.
But no worries, it is not late.
We will remove this key binding, and hopefully replace it with another one.

Maybe this could be an opportunity to define a dispatch key binding for
any past and future plotters,
beginning with Gnuplot and orgtbl-ascii-plot,
in the way org-agenda is a dispatcher for many information collectors.

Anyone, an idea for a key combination to plot data ?

Thierry

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] remap orgtbl-ascii-plot to C-c #
  2014-09-03 18:22                         ` Nicolas Goaziou
  2014-09-03 20:10                           ` A key-binding for plotting Thierry Banel
@ 2014-09-06 14:35                           ` Thierry Banel
  2014-09-08 16:30                             ` Nicolas Goaziou
  1 sibling, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-09-06 14:35 UTC (permalink / raw)
  To: emacs-orgmode

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

Le 03/09/2014 20:22, Nicolas Goaziou a écrit :
>
> It looks good but I realized (a bit late) we cannot use "C-c p" as it is
> reserved to users, as any "C-c LETTER" combination.
>
>

Here is a patch to change the key-binding of `orgtbl-ascii-plot'
from C-c p to C-c #
(The little grid symbol # seems appropriate for a plot).
(But of course another key combination is still possible).

C-c # is already mapped to `org-update-statistics-cookies'.
It makes sense only on a header with a cookie like this:
* Header [12/45]

Therefore I made this key-binding context-sensitive.
The current behavior remains unchanged.

(Many other Org key bindings are context-sensitive:
 C-c C-x L    `org-shiftmetaleft'
 C-c down    `org-shiftdown'
 C-c C-x M-w `org-copy-special'
 C-c *            `org-ctrl-c-star'
 and so on).

Have fun
Thierry



[-- Attachment #2: 0001-orgtbl-ascii-plot-remapped-from-C-c-p-to-C-c.patch --]
[-- Type: text/x-diff, Size: 3727 bytes --]

From 3b333fa06f706a06485a5795005b3d571cd1526b Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelwebmin@free.fr>
Date: Sat, 6 Sep 2014 15:59:18 +0200
Subject: [PATCH] orgtbl-ascii-plot remapped from C-c p to C-c #

* org-table.el (orgtbl-setup): change key-binding
from C-c p to C-c #
* org.el (orgtbl-ascii-plot): declare `orgtbl-ascii-plot'
(org-update-statistics-cookies-or-plot): a new dispatcher
function
(org-mode-map): remap C-c # from `org-update-statistics-cookies'
to `org-update-statistics-cookies-or-plot',
remove old C-c p key-binding
---
 lisp/org-table.el |  2 +-
 lisp/org.el       | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 547f933..4695745 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -4327,7 +4327,7 @@ to execute outside of tables."
 	 ["Move Column Right" org-metaright :active (org-at-table-p) :keys "M-<right>"]
 	 ["Delete Column" org-shiftmetaleft :active (org-at-table-p) :keys "M-S-<left>"]
 	 ["Insert Column" org-shiftmetaright :active (org-at-table-p) :keys "M-S-<right>"]
-	 ["Ascii plot" orgtbl-ascii-plot :active (org-at-table-p) :keys "C-c p"])
+	 ["Ascii plot" orgtbl-ascii-plot :active (org-at-table-p) :keys "C-c #"])
 	("Row"
 	 ["Move Row Up" org-metaup :active (org-at-table-p) :keys "M-<up>"]
 	 ["Move Row Down" org-metadown :active (org-at-table-p) :keys "M-<down>"]
diff --git a/lisp/org.el b/lisp/org.el
index 649808c..e6a13ef 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -163,6 +163,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
 (declare-function org-table-paste-rectangle "org-table" ())
 (declare-function org-table-maybe-eval-formula "org-table" ())
 (declare-function org-table-maybe-recalculate-line "org-table" ())
+(declare-function orgtbl-ascii-plot "org-table" (&optional ask))
 
 (declare-function org-element-at-point "org-element" ())
 (declare-function org-element-cache-reset "org-element" (&optional all))
@@ -12842,6 +12843,16 @@ This should be called with the cursor in a line with a statistics cookie."
 	(goto-char pos)
 	(move-marker pos nil)))))
 
+(defun org-update-statistics-cookies-or-plot (arg)
+  "Update statistic cookie or plot.
+Calls `orgtbl-ascii-plot' or `org-update-statistics-cookies',
+depending on context.
+See the individual commands for more information."
+  (interactive "P")
+  (if (org-at-table-p)
+      (orgtbl-ascii-plot arg)
+    (org-update-statistics-cookies arg)))
+
 (defvar org-entry-property-inherited-from) ;; defined below
 (defun org-update-parent-todo-statistics ()
   "Update any statistics cookie in the parent of the current headline.
@@ -19464,7 +19475,7 @@ boundaries."
 (org-defkey org-mode-map "\C-c^"    'org-sort)
 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
-(org-defkey org-mode-map "\C-c#"    'org-update-statistics-cookies)
+(org-defkey org-mode-map "\C-c#"    'org-update-statistics-cookies-or-plot)
 (org-defkey org-mode-map [remap open-line] 'org-open-line)
 (org-defkey org-mode-map [remap comment-dwim] 'org-comment-dwim)
 (org-defkey org-mode-map [remap forward-paragraph] 'org-forward-paragraph)
@@ -19477,7 +19488,6 @@ boundaries."
 (org-defkey org-mode-map "\C-c="    'org-table-eval-formula)
 (org-defkey org-mode-map "\C-c'"    'org-edit-special)
 (org-defkey org-mode-map "\C-c`"    'org-table-edit-field)
-(org-defkey org-mode-map "\C-cp"    'orgtbl-ascii-plot)
 (org-defkey org-mode-map "\C-c|"    'org-table-create-or-convert-from-region)
 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
 (org-defkey org-mode-map "\C-c~"    'org-table-create-with-table.el)
-- 
1.9.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] remap orgtbl-ascii-plot to C-c #
  2014-09-06 14:35                           ` [PATCH] remap orgtbl-ascii-plot to C-c # Thierry Banel
@ 2014-09-08 16:30                             ` Nicolas Goaziou
  2014-09-13 17:06                               ` key-binding for all plotting styles Thierry Banel
  0 siblings, 1 reply; 31+ messages in thread
From: Nicolas Goaziou @ 2014-09-08 16:30 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Thierry Banel <tbanelwebmin@free.fr> writes:

> Le 03/09/2014 20:22, Nicolas Goaziou a écrit :
>>
>> It looks good but I realized (a bit late) we cannot use "C-c p" as it is
>> reserved to users, as any "C-c LETTER" combination.
>>
>>
>
> Here is a patch to change the key-binding of `orgtbl-ascii-plot'
> from C-c p to C-c #
> (The little grid symbol # seems appropriate for a plot).
> (But of course another key combination is still possible).

It is better than C-c p, but I think a common prefix for plotting table
would be better. You need to also tell org.texi about this change.

> C-c # is already mapped to `org-update-statistics-cookies'.
> It makes sense only on a header with a cookie like this:
> * Header [12/45]

Note that there is no such limitation for statistics cookies:

 - My plan [1/2]
   - [X] Step 1
   - [ ] Step 2

It is even technically possible to have one in a table.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: key-binding for all plotting styles
  2014-09-08 16:30                             ` Nicolas Goaziou
@ 2014-09-13 17:06                               ` Thierry Banel
  2014-10-07 14:15                                 ` Nicolas Goaziou
  0 siblings, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-09-13 17:06 UTC (permalink / raw)
  To: emacs-orgmode

Le 08/09/2014 18:30, Nicolas Goaziou a écrit :
>
> It is better than C-c p, but I think a common prefix for plotting table
> would be better. You need to also tell org.texi about this change.
>

A common prefix for plotting is a good idea. Which common prefix?
C-c #    (should be shared with `org-update-statistics-cookies')
C-c :    (should be shared with `org-toggle-fixed-width')
C-c "    (currently unused)
C-c |    (currently does weird things within a table)

So for instance we could have the following (extensible) key-bindings:
C-c " a   insert an ascii plot column
C-c " g   insert a #+PLOT: line and run GnuPlot
C-c " r   insert a Babel R plotting block and run it

Any thoughts, People of the List?

> Note that there is no such limitation for statistics cookies:
>
>  - My plan [1/2]
>    - [X] Step 1
>    - [ ] Step 2
>
> It is even technically possible to have one in a table.
>
Ok then let us forget about C-c #
I will take care of the patch as soon as there is a consensus on what to do.

Have fun
Thierry

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: key-binding for all plotting styles
  2014-09-13 17:06                               ` key-binding for all plotting styles Thierry Banel
@ 2014-10-07 14:15                                 ` Nicolas Goaziou
  2014-10-07 21:40                                   ` Thierry Banel
  2014-10-11 17:46                                   ` [PATCH] " Thierry Banel
  0 siblings, 2 replies; 31+ messages in thread
From: Nicolas Goaziou @ 2014-10-07 14:15 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Hello,

Thierry Banel <tbanelwebmin@free.fr> writes:

> C-c "    (currently unused)
> C-c |    (currently does weird things within a table)

I'm fine with any of these, even though they may be shadowed by minor
modes.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: key-binding for all plotting styles
  2014-10-07 14:15                                 ` Nicolas Goaziou
@ 2014-10-07 21:40                                   ` Thierry Banel
  2014-10-11 17:46                                   ` [PATCH] " Thierry Banel
  1 sibling, 0 replies; 31+ messages in thread
From: Thierry Banel @ 2014-10-07 21:40 UTC (permalink / raw)
  To: emacs-orgmode

Le 07/10/2014 16:15, Nicolas Goaziou a écrit :
> Hello,
>
> Thierry Banel <tbanelwebmin@free.fr> writes:
>
>> C-c "    (currently unused)
>> C-c |    (currently does weird things within a table)
> I'm fine with any of these, even though they may be shadowed by minor
> modes.

Good! I will submit a patch shortly.

Have fun
Thierry

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] key-binding for all plotting styles
  2014-10-07 14:15                                 ` Nicolas Goaziou
  2014-10-07 21:40                                   ` Thierry Banel
@ 2014-10-11 17:46                                   ` Thierry Banel
  2014-10-12  9:28                                     ` Nicolas Goaziou
  1 sibling, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-10-11 17:46 UTC (permalink / raw)
  To: emacs-orgmode

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

Here is a patch which bindskeys:

  C-c " a   orgtbl-ascii-plot(creates an ascii plot for the column where
the cursor is)
  C-c " g   org-plot/gnuplot  (nicely launches Gnuplot for all columns)

It also adds a sub-menu named "Plot" in the "Tbl" menu with those two
entries.

Have fun
Thierry


Le 07/10/2014 16:15, Nicolas Goaziou a écrit :
> Hello,
>
> Thierry Banel <tbanelwebmin@free.fr> writes:
>
>> C-c "    (currently unused)
>> C-c |    (currently does weird things within a table)
> I'm fine with any of these, even though they may be shadowed by minor
> modes.
>
>
> Regards,
>


[-- Attachment #2: 0001-Ascii-and-Gnuplot-key-bindings.patch --]
[-- Type: text/x-diff, Size: 4628 bytes --]

From 41b262ca69636938bc894bc4b24d8de968e67c68 Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelwebmin@free.fr>
Date: Sat, 11 Oct 2014 15:59:17 +0200
Subject: [PATCH] Ascii and Gnuplot key-bindings

* org.el (org-mode-map): change key-binding
from C-c p to C-c " a
add C-c " g key-binding for Gnuplot
(org-tbl-menu): add sub-menu for plotting
featuring Gnuplot and ascii plot
* org-table.el (orgtbl-setup): add sub-menu
for plotting featuring Gnuplot and ascii plot
---
 lisp/org-table.el | 10 ++++++----
 lisp/org.el       | 14 ++++++++++----
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 7607ead..0f2fda3 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -4276,8 +4276,7 @@ to execute outside of tables."
 	 ["Move Column Left" org-metaleft :active (org-at-table-p) :keys "M-<left>"]
 	 ["Move Column Right" org-metaright :active (org-at-table-p) :keys "M-<right>"]
 	 ["Delete Column" org-shiftmetaleft :active (org-at-table-p) :keys "M-S-<left>"]
-	 ["Insert Column" org-shiftmetaright :active (org-at-table-p) :keys "M-S-<right>"]
-	 ["Ascii plot" orgtbl-ascii-plot :active (org-at-table-p) :keys "C-c p"])
+	 ["Insert Column" org-shiftmetaright :active (org-at-table-p) :keys "M-S-<right>"])
 	("Row"
 	 ["Move Row Up" org-metaup :active (org-at-table-p) :keys "M-<up>"]
 	 ["Move Row Down" org-metadown :active (org-at-table-p) :keys "M-<down>"]
@@ -4315,7 +4314,10 @@ to execute outside of tables."
 	 org-table-toggle-coordinate-overlays :active (org-at-table-p)
 	 :keys "C-c }"
 	 :style toggle :selected org-table-overlay-coordinates]
-	))
+	"--"
+	("Plot"
+	 ["Ascii plot" orgtbl-ascii-plot :active (org-at-table-p) :keys "C-c \" a"]
+	 ["Gnuplot" org-plot/gnuplot :active (org-at-table-p) :keys "C-c \" g"])))
     t))
 
 (defun orgtbl-ctrl-c-ctrl-c (arg)
@@ -5052,7 +5054,7 @@ supported.  It is also possible to use the following ones:
 
 ;; Put the cursor in a column containing numerical values
 ;; of an Org-Mode table,
-;; type C-c p
+;; type C-c " a
 ;; A new column is added with a bar plot.
 ;; When the table is refreshed (C-u C-c *),
 ;; the plot is updated to reflect the new values.
diff --git a/lisp/org.el b/lisp/org.el
index a6d8d1b..724fa62 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -163,6 +163,8 @@ Stars are put in group 1 and the trimmed body in group 2.")
 (declare-function org-table-paste-rectangle "org-table" ())
 (declare-function org-table-maybe-eval-formula "org-table" ())
 (declare-function org-table-maybe-recalculate-line "org-table" ())
+(declare-function orgtbl-ascii-plot "org-table" (&optional ask))
+(declare-function org-plot/gnuplot "org-plot" (&optional params))
 
 (declare-function org-element-at-point "org-element" ())
 (declare-function org-element-cache-reset "org-element" (&optional all))
@@ -19478,7 +19480,8 @@ boundaries."
 (org-defkey org-mode-map "\C-c="    'org-table-eval-formula)
 (org-defkey org-mode-map "\C-c'"    'org-edit-special)
 (org-defkey org-mode-map "\C-c`"    'org-table-edit-field)
-(org-defkey org-mode-map "\C-cp"    'orgtbl-ascii-plot)
+(org-defkey org-mode-map "\C-c\"a"  'orgtbl-ascii-plot)
+(org-defkey org-mode-map "\C-c\"g"  'org-plot/gnuplot)
 (org-defkey org-mode-map "\C-c|"    'org-table-create-or-convert-from-region)
 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
 (org-defkey org-mode-map "\C-c~"    'org-table-create-with-table.el)
@@ -21161,8 +21164,7 @@ on context.  See the individual commands for more information."
      ["Move Column Left" org-metaleft (org-at-table-p)]
      ["Move Column Right" org-metaright (org-at-table-p)]
      ["Delete Column" org-shiftmetaleft (org-at-table-p)]
-     ["Insert Column" org-shiftmetaright (org-at-table-p)]
-     ["Ascii plot" orgtbl-ascii-plot (org-at-table-p)])
+     ["Insert Column" org-shiftmetaright (org-at-table-p)])
     ("Row"
      ["Move Row Up" org-metaup (org-at-table-p)]
      ["Move Row Down" org-metadown (org-at-table-p)]
@@ -21205,7 +21207,11 @@ on context.  See the individual commands for more information."
     ["Import from File" org-table-import (not (org-at-table-p))]
     ["Export to File" org-table-export (org-at-table-p)]
     "--"
-    ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
+    ["Create/Convert from/to table.el" org-table-create-with-table.el t]
+    "--"
+    ("Plot"
+     ["Ascii plot" orgtbl-ascii-plot :active (org-at-table-p) :keys "C-c \" a"]
+     ["Gnuplot" org-plot/gnuplot :active (org-at-table-p) :keys "C-c \" g"])))
 
 (easy-menu-define org-org-menu org-mode-map "Org menu"
   '("Org"
-- 
1.9.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] key-binding for all plotting styles
  2014-10-11 17:46                                   ` [PATCH] " Thierry Banel
@ 2014-10-12  9:28                                     ` Nicolas Goaziou
  2014-10-12 10:00                                       ` Thierry Banel
  2014-10-12 14:05                                       ` Thierry Banel
  0 siblings, 2 replies; 31+ messages in thread
From: Nicolas Goaziou @ 2014-10-12  9:28 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Hello,

Thierry Banel <tbanelwebmin@free.fr> writes:

> Here is a patch which bindskeys:
>
>   C-c " a   orgtbl-ascii-plot(creates an ascii plot for the column where
> the cursor is)
>   C-c " g   org-plot/gnuplot  (nicely launches Gnuplot for all columns)
>
> It also adds a sub-menu named "Plot" in the "Tbl" menu with those two
> entries.

Applied. Thank you.

Would you mind providing some documentation about the feature in the
manual, and updating ORG-NEWS?

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] key-binding for all plotting styles
  2014-10-12  9:28                                     ` Nicolas Goaziou
@ 2014-10-12 10:00                                       ` Thierry Banel
  2014-10-12 14:05                                       ` Thierry Banel
  1 sibling, 0 replies; 31+ messages in thread
From: Thierry Banel @ 2014-10-12 10:00 UTC (permalink / raw)
  To: emacs-orgmode

Le 12/10/2014 11:28, Nicolas Goaziou a écrit :
> Applied. Thank you.
>
> Would you mind providing some documentation about the feature in the
> manual, and updating ORG-NEWS?
>
> Regards,
>
Sure! Will do that shortly.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] key-binding for all plotting styles
  2014-10-12  9:28                                     ` Nicolas Goaziou
  2014-10-12 10:00                                       ` Thierry Banel
@ 2014-10-12 14:05                                       ` Thierry Banel
  2014-10-13 16:24                                         ` Nicolas Goaziou
  1 sibling, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-10-12 14:05 UTC (permalink / raw)
  To: emacs-orgmode

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

Le 12/10/2014 11:28, Nicolas Goaziou a écrit :
> Would you mind providing some documentation about the feature in the
> manual, and updating ORG-NEWS?
>
>

Done.

To see the result:
- cd to org-mode tree root
- make info
- launch Emacs
- C-u C-h i doc/org RET
- search for "Org-Plot" chapter


Have fun
Thierry


[-- Attachment #2: 0001-Document-ascii-art-plot.patch --]
[-- Type: text/x-diff, Size: 4071 bytes --]

From 916f974ed4597e3d03124089d6ce90ccd3d235cf Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelwebmin@free.fr>
Date: Sun, 12 Oct 2014 15:23:12 +0200
Subject: [PATCH] Document ascii art plot

* doc/org.texi: Extend Gnuplot chapter to ascii art plotting.
* etc/ORG-NEWS: Document ascii art plot.
---
 doc/org.texi | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 etc/ORG-NEWS |  2 ++
 2 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index ad872a8..91fa211 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -3258,11 +3258,16 @@ functions.
 @cindex plot tables using Gnuplot
 @cindex #+PLOT
 
-Org-Plot can produce 2D and 3D graphs of information stored in org tables
-using @file{Gnuplot} @uref{http://www.gnuplot.info/} and @file{gnuplot-mode}
+Org-Plot can produce graphs of information stored in org tables, either
+graphically or in ascii-art.
+
+@subheading Graphical plots using @file{Gnuplot}
+
+Org-Plot produces 2D and 3D graphs using @file{Gnuplot}
+@uref{http://www.gnuplot.info/} and @file{gnuplot-mode}
 @uref{http://xafs.org/BruceRavel/GnuplotMode}.  To see this in action, ensure
 that you have both Gnuplot and Gnuplot mode installed on your system, then
-call @code{org-plot/gnuplot} on the following table.
+call @kbd{C-c " g} or @code{M-x org-plot/gnuplot RET} on the following table.
 
 @example
 @group
@@ -3280,8 +3285,8 @@ call @code{org-plot/gnuplot} on the following table.
 Notice that Org Plot is smart enough to apply the table's headers as labels.
 Further control over the labels, type, content, and appearance of plots can
 be exercised through the @code{#+PLOT:} lines preceding a table.  See below
-for a complete list of Org-plot options.  For more information and examples
-see the Org-plot tutorial at
+for a complete list of Org-plot options.  The @code{#+PLOT:} lines are
+optional.  For more information and examples see the Org-plot tutorial at
 @uref{http://orgmode.org/worg/org-tutorials/org-plot.html}.
 
 @subsubheading Plot Options
@@ -3337,6 +3342,47 @@ may still want to specify the plot type, as that can impact the content of
 the data file.
 @end table
 
+@subheading Ascii bar plots
+
+While the cursor is on a column, typing @kbd{C-c " a} or
+@code{M-x orgtbl-ascii-plot RET} create a new column containing an ascii-art
+bars plot.  The plot is implemented through a regular column formula.  When
+the source column changes, the bar plot may be updated by refreshing the
+table, for example typing @kbd{C-u C-c *}.
+
+@example
+@group
+| Sede          | Max cites |              |
+|---------------+-----------+--------------|
+| Chile         |    257.72 | WWWWWWWWWWWW |
+| Leeds         |    165.77 | WWWWWWWh     |
+| Sao Paolo     |     71.00 | WWW;         |
+| Stockholm     |    134.19 | WWWWWW:      |
+| Morelia       |    257.56 | WWWWWWWWWWWH |
+| Rochefourchat |      0.00 |              |
+#+TBLFM: $3='(orgtbl-ascii-draw $2 0.0 257.72 12)
+@end group
+@end example
+
+The formula is an elisp call:
+@lisp
+(orgtbl-ascii-draw COLUMN MIN MAX WIDTH)
+@end lisp
+
+@table @code
+@item COLUMN
+  is a reference to the source column.
+
+@item MIN MAX
+  are the minimal and maximal values displayed.  Sources values
+  outside this range are displayed as @code{too small}
+  or @code{too large}.
+
+@item WIDTH
+  is the width in characters of the bar-plot.  It defaults to @code{12}.
+
+@end table
+
 @node Hyperlinks
 @chapter Hyperlinks
 @cindex hyperlinks
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 0a5af68..a29eec6 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -96,6 +96,8 @@ would throw an error. A new variable
 ~org-table-formula-create-columns~ was added to adjust this
 behavior. It is now possible to silently add new columns, to do so
 with a warning or to explicitly ask the user each time.
+*** Ascii plot
+Ability to plot values in a column through ascii-art bars.
 ** Miscellaneous
 *** File names in links accept are now compatible with URI syntax
 Absolute file names can now start with =///= in addition to =/=. E.g.,
-- 
1.9.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] key-binding for all plotting styles
  2014-10-12 14:05                                       ` Thierry Banel
@ 2014-10-13 16:24                                         ` Nicolas Goaziou
  2014-10-13 21:16                                           ` Thierry Banel
  2014-10-14 20:48                                           ` Thierry Banel
  0 siblings, 2 replies; 31+ messages in thread
From: Nicolas Goaziou @ 2014-10-13 16:24 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Hello,

Thierry Banel <tbanelwebmin@free.fr> writes:

> Done.

Thank you.

> To see the result:
> - cd to org-mode tree root
> - make info
> - launch Emacs
> - C-u C-h i doc/org RET
> - search for "Org-Plot" chapter

Some comments follow.

> -call @code{org-plot/gnuplot} on the following table.
> +call @kbd{C-c " g} or @code{M-x org-plot/gnuplot RET} on the
> following table.

It should be

  @kbd{M-x org-plot/gnuplot @key{RET}}

Note there is also the macro

  @orgcmd{C-c " g,org-plot/gnuplot}

> +While the cursor is on a column, typing @kbd{C-c " a} or
> +@code{M-x orgtbl-ascii-plot RET} create a new column containing an
> ascii-art

  @kbd{M-x orgtbl-ascii-plot @key{RET}}

> +bars plot.  The plot is implemented through a regular column formula.  When
> +the source column changes, the bar plot may be updated by refreshing the
> +table, for example typing @kbd{C-u C-c *}.

> +@item MIN MAX
> +  are the minimal and maximal values displayed.  Sources values
> +  outside this range are displayed as @code{too small}
> +  or @code{too large}.

  @samp{too small} or @samp{too large}.

> +@item WIDTH
> +  is the width in characters of the bar-plot.  It defaults to
> @code{12}.

  @samp{12}

> +*** Ascii plot
> +Ability to plot values in a column through ascii-art bars.

BTW is-it ASCII-art or ascii-art?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] key-binding for all plotting styles
  2014-10-13 16:24                                         ` Nicolas Goaziou
@ 2014-10-13 21:16                                           ` Thierry Banel
  2014-10-14 20:48                                           ` Thierry Banel
  1 sibling, 0 replies; 31+ messages in thread
From: Thierry Banel @ 2014-10-13 21:16 UTC (permalink / raw)
  To: emacs-orgmode

Thanks Nicolas for your feedback.
I'll do the adjustments.

Le 13/10/2014 18:24, Nicolas Goaziou a écrit :
>
> Some comments follow.
>
> ...
> BTW is-it ASCII-art or ascii-art?
>
>

Good question!
When asking Google, we get every possible combination, in decreasing
order of occurrences:
  ASCII Art
  ASCII ART
  Ascii Art
  ASCII art
  ascii art
The Internet seems to vote for capitals.
The Emacs info pages capitalize the whole word: ASCII.
So, you are right, ASCII is the way to go.

jQQQQQQQQQQQQQQQQQWBVVVVVVVTVH$QQQQQQQQQQQQQQQQQQQ
jQQQQQQQQQQQQQQ@?nc?""-  - -""!<2Y$WQQQQQQQQQQQQQQ
jQQQQQQQQQQWVY+~^      .         "->YUWQQQQQQQQQQQ
jQQQQQQQQ@5)~     .   .   .........  ~{7$QQQQQQQQQ
jQQQQQQWT+'   .     ..      -"??9QQma. "i9QQQQQQQQ
jQQQQQDl~ .  .   <gmmmmmwwwwaas_awWQQL   +%$QQQQQQ
jQQQQDs'.   .    -QQQQQWVTTTVV$QWWQQW(    -%$QQQQQ
jQQQ@<'.   .    . -$QQm.         """       "%$QQQQ
jQQQt[   .        . ~9Qma.               .  ])QQQQ
jQQ@]  .      .    .  -?HQw,.      .  .     .zQQQQ
jQQk|      . _aawwgmmmywawdQQw,.  .     .  . (3QQQ
jQQk|  .   aQQQQQWQQQW@TTT?????! .    .      <jQQQ
jQQk<.    ]QWQQQQWT"~                .    .  zdQQQ
jQQQ),   . ?QQQQQf           .      .    .  _(QQQQ
jQQQL\ .    -4$QQQw,,.          .  .        JjQQQQ
jQQQQcs    .  --?VQQQmwwc__,.          .  .%{QQQQQ
jQQQQQ%\  .        -"?TT$QQQQQgaa,. .     /sQQWQQQ
jQQQQQQai_      . .________vvmQQQQ#c    _)wQWQQQQQ
jQQQQQQQmz(/  .  .-~"^"^""""""^^~`    _)nmQWQQQQQQ
jQQQQQQQQQg%s_.          .. .     .._%syQQQQQQQQQQ
jQQQQQQQQQQQmyac=_s            s.>)agmQQQQQQQQQQQQ
jQQQQQQQQQQQQQQWWwa%>T======T|swwBQQQQQQQQQQQQQQQQ
jQQQQQQQQQQQQQQQQQQQQQQmmmQQQQQWWWQQQQQQQQQQQQQQQQ

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] key-binding for all plotting styles
  2014-10-13 16:24                                         ` Nicolas Goaziou
  2014-10-13 21:16                                           ` Thierry Banel
@ 2014-10-14 20:48                                           ` Thierry Banel
  2014-10-14 21:08                                             ` Nicolas Goaziou
  1 sibling, 1 reply; 31+ messages in thread
From: Thierry Banel @ 2014-10-14 20:48 UTC (permalink / raw)
  To: emacs-orgmode

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

Here is the updated patch.

To see the result:
- cd to org-mode tree root
- make info
- launch Emacs
- C-u C-h i doc/org RET
- search for "Org-Plot" chapter

Regards
Thierry


Le 13/10/2014 18:24, Nicolas Goaziou a écrit :
>
> Some comments follow.
> ...
>
> It should be
>
>   @kbd{M-x org-plot/gnuplot @key{RET}}
>   @kbd{M-x orgtbl-ascii-plot @key{RET}}
>   @samp{too small} or @samp{too large}.
>   @samp{12}
Fixed

> Note there is also the macro
>
>   @orgcmd{C-c " g,org-plot/gnuplot}
This macro is used as bullet items in a @table
I cannot use it in the middle of a text.

> BTW is-it ASCII-art or ascii-art?
Changed to capitals.




[-- Attachment #2: 0001-Document-ASCII-art-plot.patch --]
[-- Type: text/x-diff, Size: 4084 bytes --]

From 5168483137640a896501c88740052fe5112bed54 Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelwebmin@free.fr>
Date: Tue, 14 Oct 2014 22:34:54 +0200
Subject: [PATCH] Document ASCII-art plot

* doc/org.texi: Extend Gnuplot chapter to ASCII-art plotting.
* etc/ORG-NEWS: Document ASCII-art plot.
---
 doc/org.texi | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 etc/ORG-NEWS |  2 ++
 2 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 05df0eb..767fa1a 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -3258,11 +3258,17 @@ functions.
 @cindex plot tables using Gnuplot
 @cindex #+PLOT
 
-Org-Plot can produce 2D and 3D graphs of information stored in org tables
-using @file{Gnuplot} @uref{http://www.gnuplot.info/} and @file{gnuplot-mode}
+Org-Plot can produce graphs of information stored in org tables, either
+graphically or in ASCII-art.
+
+@subheading Graphical plots using @file{Gnuplot}
+
+Org-Plot produces 2D and 3D graphs using @file{Gnuplot}
+@uref{http://www.gnuplot.info/} and @file{gnuplot-mode}
 @uref{http://xafs.org/BruceRavel/GnuplotMode}.  To see this in action, ensure
 that you have both Gnuplot and Gnuplot mode installed on your system, then
-call @code{org-plot/gnuplot} on the following table.
+call @kbd{C-c " g} or @kbd{M-x org-plot/gnuplot @key{RET}} on the following
+table.
 
 @example
 @group
@@ -3280,8 +3286,8 @@ call @code{org-plot/gnuplot} on the following table.
 Notice that Org Plot is smart enough to apply the table's headers as labels.
 Further control over the labels, type, content, and appearance of plots can
 be exercised through the @code{#+PLOT:} lines preceding a table.  See below
-for a complete list of Org-plot options.  For more information and examples
-see the Org-plot tutorial at
+for a complete list of Org-plot options.  The @code{#+PLOT:} lines are
+optional.  For more information and examples see the Org-plot tutorial at
 @uref{http://orgmode.org/worg/org-tutorials/org-plot.html}.
 
 @subsubheading Plot Options
@@ -3337,6 +3343,47 @@ may still want to specify the plot type, as that can impact the content of
 the data file.
 @end table
 
+@subheading ASCII bar plots
+
+While the cursor is on a column, typing @kbd{C-c \" a} or
+@kbd{M-x orgtbl-ascii-plot @key{RET}} create a new column containing an
+ASCII-art bars plot.  The plot is implemented through a regular column
+formula.  When the source column changes, the bar plot may be updated by
+refreshing the table, for example typing @kbd{C-u C-c *}.
+
+@example
+@group
+| Sede          | Max cites |              |
+|---------------+-----------+--------------|
+| Chile         |    257.72 | WWWWWWWWWWWW |
+| Leeds         |    165.77 | WWWWWWWh     |
+| Sao Paolo     |     71.00 | WWW;         |
+| Stockholm     |    134.19 | WWWWWW:      |
+| Morelia       |    257.56 | WWWWWWWWWWWH |
+| Rochefourchat |      0.00 |              |
+#+TBLFM: $3='(orgtbl-ascii-draw $2 0.0 257.72 12)
+@end group
+@end example
+
+The formula is an elisp call:
+@lisp
+(orgtbl-ascii-draw COLUMN MIN MAX WIDTH)
+@end lisp
+
+@table @code
+@item COLUMN
+  is a reference to the source column.
+
+@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}.
+
+@item WIDTH
+  is the width in characters of the bar-plot.  It defaults to @samp{12}.
+
+@end table
+
 @node Hyperlinks
 @chapter Hyperlinks
 @cindex hyperlinks
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 0a5af68..e94dec6 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -96,6 +96,8 @@ would throw an error. A new variable
 ~org-table-formula-create-columns~ was added to adjust this
 behavior. It is now possible to silently add new columns, to do so
 with a warning or to explicitly ask the user each time.
+*** ASCII plot
+Ability to plot values in a column through ASCII-art bars.
 ** Miscellaneous
 *** File names in links accept are now compatible with URI syntax
 Absolute file names can now start with =///= in addition to =/=. E.g.,
-- 
1.9.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] key-binding for all plotting styles
  2014-10-14 20:48                                           ` Thierry Banel
@ 2014-10-14 21:08                                             ` Nicolas Goaziou
  2014-10-14 21:26                                               ` Thierry Banel
  0 siblings, 1 reply; 31+ messages in thread
From: Nicolas Goaziou @ 2014-10-14 21:08 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Hello,

Thierry Banel <tbanelwebmin@free.fr> writes:

> Here is the updated patch.

[...]

>> BTW is-it ASCII-art or ascii-art?
> Changed to capitals.
    _                _ _          _   
   / \   _ __  _ __ | (_) ___  __| |  
  / _ \ | '_ \| '_ \| | |/ _ \/ _` |  
 / ___ \| |_) | |_) | | |  __/ (_| |_ 
/_/   \_\ .__/| .__/|_|_|\___|\__,_(_)
        |_|   |_|                     


Thank you.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] key-binding for all plotting styles
  2014-10-14 21:08                                             ` Nicolas Goaziou
@ 2014-10-14 21:26                                               ` Thierry Banel
  0 siblings, 0 replies; 31+ messages in thread
From: Thierry Banel @ 2014-10-14 21:26 UTC (permalink / raw)
  To: emacs-orgmode

Le 14/10/2014 23:08, Nicolas Goaziou a écrit :
>     _                _ _          _   
>    / \   _ __  _ __ | (_) ___  __| |  
>   / _ \ | '_ \| '_ \| | |/ _ \/ _` |  
>  / ___ \| |_) | |_) | | |  __/ (_| |_ 
> /_/   \_\ .__/| .__/|_|_|\___|\__,_(_)
>         |_|   |_|                     
>
>
>
        _
  _    (\
 (_)    \ \
         \ \
          ) )
 _     / /
 (_)    / /
       (_/

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2014-10-14 21:27 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-13 16:02 make orgtbl-ascii-plot easier to install Thierry Banel
2014-07-28 14:40 ` Bastien
2014-08-10 22:22   ` Thierry Banel
2014-08-26  8:29     ` Nicolas Goaziou
2014-08-26 19:52       ` Thierry Banel
2014-08-26 20:27         ` Nicolas Goaziou
2014-08-26 21:42           ` Thierry Banel
2014-08-26 22:09             ` Nicolas Goaziou
2014-08-26 22:21               ` Thierry Banel
2014-08-27 21:35               ` Thierry Banel
2014-08-27 23:28                 ` Nicolas Goaziou
2014-08-28 20:46                   ` Thierry Banel
2014-08-29  9:54                     ` Nicolas Goaziou
2014-08-29 17:20                       ` Thierry Banel
2014-09-02 21:53                       ` [PATCH] " Thierry Banel
2014-09-03 18:22                         ` Nicolas Goaziou
2014-09-03 20:10                           ` A key-binding for plotting Thierry Banel
2014-09-06 14:35                           ` [PATCH] remap orgtbl-ascii-plot to C-c # Thierry Banel
2014-09-08 16:30                             ` Nicolas Goaziou
2014-09-13 17:06                               ` key-binding for all plotting styles Thierry Banel
2014-10-07 14:15                                 ` Nicolas Goaziou
2014-10-07 21:40                                   ` Thierry Banel
2014-10-11 17:46                                   ` [PATCH] " Thierry Banel
2014-10-12  9:28                                     ` Nicolas Goaziou
2014-10-12 10:00                                       ` Thierry Banel
2014-10-12 14:05                                       ` Thierry Banel
2014-10-13 16:24                                         ` Nicolas Goaziou
2014-10-13 21:16                                           ` Thierry Banel
2014-10-14 20:48                                           ` Thierry Banel
2014-10-14 21:08                                             ` Nicolas Goaziou
2014-10-14 21:26                                               ` Thierry Banel

Code repositories for project(s) associated with this 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).