Function: orgtbl-ascii-draw

orgtbl-ascii-draw is a byte-compiled function defined in org-table.el.gz.

Signature

(orgtbl-ascii-draw VALUE MIN MAX &optional WIDTH CHARACTERS)

Documentation

Draw an ascii bar in a table.

VALUE is the value to plot, it determines the width of the bar to draw. MIN is the value that will be displayed as empty (zero width bar). MAX is the value that will draw a bar filling all the WIDTH. WIDTH is the span in characters from MIN to MAX. 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.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
;; Put the cursor in a column containing numerical values
;; of an Org table,
;; 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.

(defun orgtbl-ascii-draw (value min max &optional width characters)
  "Draw an ascii bar in a table.
VALUE is the value to plot, it determines the width of the bar to draw.
MIN is the value that will be displayed as empty (zero width bar).
MAX is the value that will draw a bar filling all the WIDTH.
WIDTH is the span in characters from MIN to MAX.
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* ((width      (ceiling (or width 12)))
	 (characters (or characters " .:;c!lhVHW"))
	 (len        (1- (length characters)))
	 (value      (float (if (numberp value)
				value (string-to-number value))))
	 (relative   (/ (- value min) (- max min)))
	 (steps      (round (* relative width len))))
    (cond ((< steps             0) "too small")
	  ((> steps (* width len)) "too large")
	  (t (let* ((int-division (/ steps len))
		    (remainder    (- steps (* int-division len))))
	       (concat (make-string int-division (elt characters len))
		       (string (elt characters remainder))))))))