From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Banel Subject: Re: make orgtbl-ascii-plot easier to install Date: Mon, 11 Aug 2014 00:22:00 +0200 Message-ID: <53E7F088.8010401@free.fr> References: <53C2ADB0.2010404@free.fr> <87oaw9wg3s.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070702050602010201010801" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XGbV9-0001Ex-Nu for emacs-orgmode@gnu.org; Sun, 10 Aug 2014 18:22:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XGbV5-0007G0-FG for emacs-orgmode@gnu.org; Sun, 10 Aug 2014 18:22:07 -0400 Received: from smtp2-g21.free.fr ([212.27.42.2]:27505) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XGbV5-0007Fg-5N for emacs-orgmode@gnu.org; Sun, 10 Aug 2014 18:22:03 -0400 Received: from [IPv6:2a01:e35:2e21:def0:18fd:f067:cd84:5209] (unknown [IPv6:2a01:e35:2e21:def0:18fd:f067:cd84:5209]) by smtp2-g21.free.fr (Postfix) with ESMTP id 5F4D04B0028 for ; Mon, 11 Aug 2014 00:22:01 +0200 (CEST) In-Reply-To: <87oaw9wg3s.fsf@bzg.ath.cx> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------070702050602010201010801 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Le 28/07/2014 16:40, Bastien a =E9crit : >> 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 --------------070702050602010201010801 Content-Type: text/x-diff; name="0001-org-table.el-add-ascii-plotting-in-tables.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-org-table.el-add-ascii-plotting-in-tables.patch" >From 5fddaba2208c2cb4ce3b6bc24d0d10571124fb39 Mon Sep 17 00:00:00 2001 From: Thierry Banel 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 --------------070702050602010201010801--