annotate lisp/emacs-lisp/chart.el @ 111502:df6573cbdd34

* lisp/emacs-lisp/pcase.el (pcase-let*, pcase-let): Add debug and indentation specs.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 11 Nov 2010 20:35:06 -0500
parents 05dc9dca8729
children 6e613fbf73d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1 ;;; chart.el --- Draw charts (bar charts, etc)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
2
111433
05dc9dca8729 Replace end-of-line, save-excursion etc with point-at-eol, point-at-bol.
Glenn Morris <rgm@gnu.org>
parents: 110909
diff changeset
3 ;; Copyright (C) 1996, 1998, 1999, 2001, 2004, 2005, 2007, 2008, 2009,
05dc9dca8729 Replace end-of-line, save-excursion etc with point-at-eol, point-at-bol.
Glenn Morris <rgm@gnu.org>
parents: 110909
diff changeset
4 ;; 2010 Free Software Foundation, Inc.
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
5
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
7 ;; Version: 0.2
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
8 ;; Keywords: OO, chart, graph
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
9
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
11
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
15 ;; (at your option) any later version.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
16
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
21
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
24
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25 ;;; Commentary:
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26 ;;
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27 ;; This package is an experiment of mine aiding in the debugging of
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28 ;; eieio, and proved to be neat enough that others may like to use
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
29 ;; it. To quickly see what you can do with chart, run the command
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
30 ;; `chart-test-it-all'.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
31 ;;
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32 ;; Chart current can display bar-charts in either of two
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
33 ;; directions. It also supports ranged (integer) axis, and axis
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34 ;; defined by some set of strings or names. These name can be
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35 ;; automatically derived from data sequences, which are just lists of
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
36 ;; anything encapsulated in a nice eieio object.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
37 ;;
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38 ;; Current example apps for chart can be accessed via these commands:
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39 ;; `chart-file-count' - count files w/ matching extensions
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
40 ;; `chart-space-usage' - display space used by files/directories
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41 ;; `chart-emacs-storage' - Emacs storage units used/free (garbage-collect)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42 ;; `chart-emacs-lists' - length of Emacs lists
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 ;; `chart-rmail-from' - who sends you the most mail (in -summary only)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
44 ;;
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45 ;; Customization:
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46 ;;
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 ;; If you find the default colors and pixmaps unpleasant, or too
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48 ;; short, you can change them. The variable `chart-face-color-list'
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49 ;; contains a list of colors, and `chart-face-pixmap-list' contains
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50 ;; all the pixmaps to use. The current pixmaps are those found on
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 ;; several systems I found. The two lists should be the same length,
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52 ;; as the long list will just be truncated.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 ;;
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54 ;; If you would like to draw your own stipples, simply create some
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 ;; xbm's and put them in a directory, then you can add:
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56 ;;
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57 ;; (setq x-bitmap-file-path (cons "~/mybitmaps" x-bitmap-file-path))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58 ;;
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59 ;; to your .emacs (or wherever) and load the `chart-face-pixmap-list'
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
60 ;; with all the bitmaps you want to use.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
61
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
62 (require 'eieio)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
63
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
64 ;;; Code:
110909
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106895
diff changeset
65 (defvar chart-map (make-sparse-keymap) "Keymap used in chart mode.")
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
66
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
67 (defvar chart-local-object nil
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
68 "Local variable containing the locally displayed chart object.")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
69 (make-variable-buffer-local 'chart-local-object)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
70
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
71 (defvar chart-face-list nil
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
72 "Faces used to colorize charts.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
73 List is limited currently, which is ok since you really can't display
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
74 too much in text characters anyways.")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
75
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
76 (defvar chart-face-color-list '("red" "green" "blue"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
77 "cyan" "yellow" "purple")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
78 "Colors to use when generating `chart-face-list'.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
79 Colors will be the background color.")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
80
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
81 (defvar chart-face-pixmap-list
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
82 (if (and (fboundp 'display-graphic-p)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
83 (display-graphic-p))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
84 '("dimple1" "scales" "dot" "cross_weave" "boxes" "dimple3"))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
85 "If pixmaps are allowed, display these background pixmaps.
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
86 Useful if new Emacs is used on B&W display.")
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
87
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
88 (defcustom chart-face-use-pixmaps nil
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
89 "*Non-nil to use fancy pixmaps in the background of chart face colors."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
90 :group 'eieio
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
91 :type 'boolean)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
92
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
93 (if (and (if (fboundp 'display-color-p)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
94 (display-color-p)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
95 window-system)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
96 (not chart-face-list))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
97 (let ((cl chart-face-color-list)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
98 (pl chart-face-pixmap-list)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
99 nf)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
100 (while cl
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
101 (setq nf (make-face (intern (concat "chart-" (car cl) "-" (car pl)))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
102 (if (condition-case nil
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
103 (> (x-display-color-cells) 4)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
104 (error t))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
105 (set-face-background nf (car cl))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
106 (set-face-background nf "white"))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
107 (set-face-foreground nf "black")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
108 (if (and chart-face-use-pixmaps
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
109 pl
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
110 (fboundp 'set-face-background-pixmap))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
111 (condition-case nil
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
112 (set-face-background-pixmap nf (car pl))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
113 (error (message "Cannot set background pixmap %s" (car pl)))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
114 (setq chart-face-list (cons nf chart-face-list))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
115 (setq cl (cdr cl)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
116 pl (cdr pl)))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
117
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
118 (defun chart-mode ()
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
119 "Define a mode in Emacs for displaying a chart."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
120 (kill-all-local-variables)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
121 (use-local-map chart-map)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
122 (setq major-mode 'chart-mode
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
123 mode-name "CHART")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
124 (buffer-disable-undo)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
125 (set (make-local-variable 'font-lock-global-modes) nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
126 (font-lock-mode -1)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
127 (run-hooks 'chart-mode-hook)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
128 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
129
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
130 (defun chart-new-buffer (obj)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
131 "Create a new buffer NAME in which the chart OBJ is displayed.
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
132 Returns the newly created buffer."
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 105474
diff changeset
133 (with-current-buffer (get-buffer-create (format "*%s*" (oref obj title)))
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
134 (chart-mode)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
135 (setq chart-local-object obj)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
136 (current-buffer)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
137
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
138 (defclass chart ()
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
139 ((title :initarg :title
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
140 :initform "Emacs Chart")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
141 (title-face :initarg :title-face
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
142 :initform 'bold-italic)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
143 (x-axis :initarg :x-axis
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
144 :initform nil )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
145 (x-margin :initarg :x-margin
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
146 :initform 5)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
147 (x-width :initarg :x-width
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
148 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
149 (y-axis :initarg :y-axis
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
150 :initform nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
151 (y-margin :initarg :y-margin
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
152 :initform 5)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
153 (y-width :initarg :y-width
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
154 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
155 (key-label :initarg :key-label
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
156 :initform "Key")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
157 (sequences :initarg :sequences
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
158 :initform nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
159 )
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
160 "Superclass for all charts to be displayed in an Emacs buffer.")
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
161
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
162 (defmethod initialize-instance :AFTER ((obj chart) &rest fields)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
163 "Initialize the chart OBJ being created with FIELDS.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
164 Make sure the width/height is correct."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
165 (oset obj x-width (- (window-width) 10))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
166 (oset obj y-width (- (window-height) 12)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
167
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
168 (defclass chart-axis ()
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
169 ((name :initarg :name
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
170 :initform "Generic Axis")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
171 (loweredge :initarg :loweredge
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
172 :initform t)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
173 (name-face :initarg :name-face
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
174 :initform 'bold)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
175 (labels-face :initarg :lables-face
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
176 :initform 'italic)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
177 (chart :initarg :chart
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
178 :initform nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
179 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
180 "Superclass used for display of an axis.")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
181
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
182 (defclass chart-axis-range (chart-axis)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
183 ((bounds :initarg :bounds
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
184 :initform '(0.0 . 50.0))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
185 )
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
186 "Class used to display an axis defined by a range of values.")
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
187
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
188 (defclass chart-axis-names (chart-axis)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
189 ((items :initarg :items
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
190 :initform nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
191 )
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
192 "Class used to display an axis which represents different named items.")
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
193
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
194 (defclass chart-sequece ()
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
195 ((data :initarg :data
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
196 :initform nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
197 (name :initarg :name
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
198 :initform "Data")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
199 )
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
200 "Class used for all data in different charts.")
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
201
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
202 (defclass chart-bar (chart)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
203 ((direction :initarg :direction
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
204 :initform vertical))
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
205 "Subclass for bar charts (vertical or horizontal).")
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
206
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
207 (defmethod chart-draw ((c chart) &optional buff)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
208 "Start drawing a chart object C in optional BUFF.
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
209 Erases current contents of buffer."
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
210 (save-excursion
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
211 (if buff (set-buffer buff))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
212 (erase-buffer)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
213 (insert (make-string 100 ?\n))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
214 ;; Start by displaying the axis
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
215 (chart-draw-axis c)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
216 ;; Display title
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
217 (chart-draw-title c)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
218 ;; Display data
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
219 (message "Rendering chart...")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
220 (sit-for 0)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
221 (chart-draw-data c)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
222 ;; Display key
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
223 ; (chart-draw-key c)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
224 (message "Rendering chart...done")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
225 ))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
226
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
227 (defmethod chart-draw-title ((c chart))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
228 "Draw a title upon the chart.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
229 Argument C is the chart object."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
230 (chart-display-label (oref c title) 'horizontal 0 0 (window-width)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
231 (oref c title-face)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
232
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
233 (defmethod chart-size-in-dir ((c chart) dir)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
234 "Return the physical size of chart C in direction DIR."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
235 (if (eq dir 'vertical)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
236 (oref c y-width)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
237 (oref c x-width)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
238
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
239 (defmethod chart-draw-axis ((c chart))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
240 "Draw axis into the current buffer defined by chart C."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
241 (let ((ymarg (oref c y-margin))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
242 (xmarg (oref c x-margin))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
243 (ylen (oref c y-width))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
244 (xlen (oref c x-width)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
245 (chart-axis-draw (oref c y-axis) 'vertical ymarg
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
246 (if (oref (oref c y-axis) loweredge) nil xlen)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
247 xmarg (+ xmarg ylen))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
248 (chart-axis-draw (oref c x-axis) 'horizontal xmarg
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
249 (if (oref (oref c x-axis) loweredge) nil ylen)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
250 ymarg (+ ymarg xlen)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
251 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
252
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
253 (defmethod chart-axis-draw ((a chart-axis) &optional dir margin zone start end)
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
254 "Draw some axis for A in direction DIR with MARGIN in boundary.
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
255 ZONE is a zone specification.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
256 START and END represent the boundary."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
257 (chart-draw-line dir (+ margin (if zone zone 0)) start end)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
258 (chart-display-label (oref a name) dir (if zone (+ zone margin 3)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
259 (if (eq dir 'horizontal)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
260 1 0))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
261 start end (oref a name-face)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
262
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
263 (defmethod chart-translate-xpos ((c chart) x)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
264 "Translate in chart C the coordinate X into a screen column."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
265 (let ((range (oref (oref c x-axis) bounds)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
266 (+ (oref c x-margin)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
267 (round (* (float (- x (car range)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
268 (/ (float (oref c x-width))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
269 (float (- (cdr range) (car range))))))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
270 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
271
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
272 (defmethod chart-translate-ypos ((c chart) y)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
273 "Translate in chart C the coordinate Y into a screen row."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
274 (let ((range (oref (oref c y-axis) bounds)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
275 (+ (oref c x-margin)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
276 (- (oref c y-width)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
277 (round (* (float (- y (car range)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
278 (/ (float (oref c y-width))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
279 (float (- (cdr range) (car range)))))))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
280 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
281
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
282 (defmethod chart-axis-draw ((a chart-axis-range) &optional dir margin zone start end)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
283 "Draw axis information based upon a range to be spread along the edge.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
284 A is the chart to draw. DIR is the direction.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
285 MARGIN, ZONE, START, and END specify restrictions in chart space."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
286 (call-next-method)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
287 ;; We prefer about 5 spaces between each value
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
288 (let* ((i (car (oref a bounds)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
289 (e (cdr (oref a bounds)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
290 (z (if zone zone 0))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
291 (s nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
292 (rng (- e i))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
293 ;; want to jump by units of 5 spaces or so
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
294 (j (/ rng (/ (chart-size-in-dir (oref a chart) dir) 4)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
295 p1)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
296 (if (= j 0) (setq j 1))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
297 (while (<= i e)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
298 (setq s
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
299 (cond ((> i 999999)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
300 (format "%dM" (/ i 1000000)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
301 ((> i 999)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
302 (format "%dK" (/ i 1000)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
303 (t
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
304 (format "%d" i))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
305 (if (eq dir 'vertical)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
306 (let ((x (+ (+ margin z) (if (oref a loweredge)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
307 (- (length s)) 1))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
308 (if (< x 1) (setq x 1))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
309 (chart-goto-xy x (chart-translate-ypos (oref a chart) i)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
310 (chart-goto-xy (chart-translate-xpos (oref a chart) i)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
311 (+ margin z (if (oref a loweredge) -1 1))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
312 (setq p1 (point))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
313 (insert s)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
314 (chart-zap-chars (length s))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
315 (put-text-property p1 (point) 'face (oref a labels-face))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
316 (setq i (+ i j))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
317 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
318
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
319 (defmethod chart-translate-namezone ((c chart) n)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
320 "Return a dot-pair representing a positional range for a name.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
321 The name in chart C of the Nth name resides.
106860
4cf58c2379f4 Mario Lang <mlang@delysid.org>: Remove some duplicated words.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
322 Automatically compensates for direction."
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
323 (let* ((dir (oref c direction))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
324 (w (if (eq dir 'vertical) (oref c x-width) (oref c y-width)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
325 (m (if (eq dir 'vertical) (oref c y-margin) (oref c x-margin)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
326 (ns (length
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
327 (oref (if (eq dir 'vertical) (oref c x-axis) (oref c y-axis))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
328 items)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
329 (lpn (/ (+ 1.0 (float w)) (float ns)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
330 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
331 (cons (+ m (round (* lpn (float n))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
332 (+ m -1 (round (* lpn (+ 1.0 (float n))))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
333 ))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
334
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
335 (defmethod chart-axis-draw ((a chart-axis-names) &optional dir margin zone start end)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
336 "Draw axis information based upon A range to be spread along the edge.
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
337 Optional argument DIR is the direction of the chart.
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
338 Optional arguments MARGIN, ZONE, START and END specify boundaries of the drawing."
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
339 (call-next-method)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
340 ;; We prefer about 5 spaces between each value
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
341 (let* ((i 0)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
342 (s (oref a items))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
343 (z (if zone zone 0))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
344 (r nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
345 (p nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
346 (odd nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
347 p1)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
348 (while s
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
349 (setq odd (= (% (length s) 2) 1))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
350 (setq r (chart-translate-namezone (oref a chart) i))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
351 (if (eq dir 'vertical)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
352 (setq p (/ (+ (car r) (cdr r)) 2))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
353 (setq p (- (+ (car r) (/ (- (cdr r) (car r)) 2))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
354 (/ (length (car s)) 2))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
355 (if (eq dir 'vertical)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
356 (let ((x (+ (+ margin z) (if (oref a loweredge)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
357 (- (length (car s)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
358 (length (car s))))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
359 (if (< x 1) (setq x 1))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
360 (if (> (length (car s)) (1- margin))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
361 (setq x (+ x margin)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
362 (chart-goto-xy x p))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
363 (chart-goto-xy p (+ (+ margin z) (if (oref a loweredge)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
364 (if odd -2 -1)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
365 (if odd 2 1)))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
366 (setq p1 (point))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
367 (insert (car s))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
368 (chart-zap-chars (length (car s)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
369 (put-text-property p1 (point) 'face (oref a labels-face))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
370 (setq i (+ i 1)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
371 s (cdr s))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
372 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
373
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
374 (defmethod chart-draw-data ((c chart-bar))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
375 "Display the data available in a bar chart C."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
376 (let* ((data (oref c sequences))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
377 (dir (oref c direction))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
378 (odir (if (eq dir 'vertical) 'horizontal 'vertical))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
379 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
380 (while data
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
381 (if (stringp (car (oref (car data) data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
382 ;; skip string lists...
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
383 nil
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
384 ;; display number lists...
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
385 (let ((i 0)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
386 (seq (oref (car data) data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
387 (while seq
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
388 (let* ((rng (chart-translate-namezone c i))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
389 (dp (if (eq dir 'vertical)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
390 (chart-translate-ypos c (car seq))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
391 (chart-translate-xpos c (car seq))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
392 (zp (if (eq dir 'vertical)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
393 (chart-translate-ypos c 0)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
394 (chart-translate-xpos c 0)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
395 (fc (if chart-face-list
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
396 (nth (% i (length chart-face-list)) chart-face-list)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
397 'default))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
398 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
399 (if (< dp zp)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
400 (progn
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
401 (chart-draw-line dir (car rng) dp zp)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
402 (chart-draw-line dir (cdr rng) dp zp))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
403 (chart-draw-line dir (car rng) zp (1+ dp))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
404 (chart-draw-line dir (cdr rng) zp (1+ dp)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
405 (if (= (car rng) (cdr rng)) nil
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
406 (chart-draw-line odir dp (1+ (car rng)) (cdr rng))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
407 (chart-draw-line odir zp (car rng) (1+ (cdr rng))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
408 (if (< dp zp)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
409 (chart-deface-rectangle dir rng (cons dp zp) fc)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
410 (chart-deface-rectangle dir rng (cons zp dp) fc))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
411 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
412 ;; find the bounds, and chart it!
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
413 ;; for now, only do one!
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
414 (setq i (1+ i)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
415 seq (cdr seq)))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
416 (setq data (cdr data))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
417 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
418
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
419 (defmethod chart-add-sequence ((c chart) &optional seq axis-label)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
420 "Add to chart object C the sequence object SEQ.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
421 If AXIS-LABEL, then the axis stored in C is updated with the bounds of SEQ,
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
422 or is created with the bounds of SEQ."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
423 (if axis-label
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
424 (let ((axis (eieio-oref c axis-label)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
425 (if (stringp (car (oref seq data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
426 (let ((labels (oref seq data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
427 (if (not axis)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
428 (setq axis (make-instance chart-axis-names
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
429 :name (oref seq name)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
430 :items labels
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
431 :chart c))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
432 (oset axis items labels)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
433 (let ((range (cons 0 1))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
434 (l (oref seq data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
435 (if (not axis)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
436 (setq axis (make-instance chart-axis-range
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
437 :name (oref seq name)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
438 :chart c)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
439 (while l
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
440 (if (< (car l) (car range)) (setcar range (car l)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
441 (if (> (car l) (cdr range)) (setcdr range (car l)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
442 (setq l (cdr l)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
443 (oset axis bounds range)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
444 (if (eq axis-label 'x-axis) (oset axis loweredge nil))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
445 (eieio-oset c axis-label axis)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
446 ))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
447 (oset c sequences (append (oref c sequences) (list seq))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
448
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
449 ;;; Charting optimizers
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
450
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
451 (defmethod chart-trim ((c chart) max)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
452 "Trim all sequences in chart C to be at most MAX elements long."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
453 (let ((s (oref c sequences)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
454 (while s
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
455 (let ((sl (oref (car s) data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
456 (if (> (length sl) max)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
457 (setcdr (nthcdr (1- max) sl) nil)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
458 (setq s (cdr s))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
459 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
460
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
461 (defmethod chart-sort ((c chart) pred)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
462 "Sort the data in chart C using predicate PRED.
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
463 See `chart-sort-matchlist' for more details."
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
464 (let* ((sl (oref c sequences))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
465 (s1 (car sl))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
466 (s2 (car (cdr sl)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
467 (s nil))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
468 (if (stringp (car (oref s1 data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
469 (progn
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
470 (chart-sort-matchlist s1 s2 pred)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
471 (setq s (oref s1 data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
472 (if (stringp (car (oref s2 data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
473 (progn
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
474 (chart-sort-matchlist s2 s1 pred)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
475 (setq s (oref s2 data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
476 (error "Sorting of chart %s not supported" (object-name c))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
477 (if (eq (oref c direction) 'horizontal)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
478 (oset (oref c y-axis) items s)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
479 (oset (oref c x-axis) items s)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
480 ))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
481 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
482
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
483 (defun chart-sort-matchlist (namelst numlst pred)
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
484 "Sort NAMELST and NUMLST (both sequence objects) based on predicate PRED.
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
485 PRED should be the equivalent of '<, except it must expect two
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
486 cons cells of the form (NAME . NUM). See `sort' for more details."
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
487 ;; 1 - create 1 list of cons cells
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
488 (let ((newlist nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
489 (alst (oref namelst data))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
490 (ulst (oref numlst data)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
491 (while alst
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
492 ;; this is reversed, but were are sorting anyway
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
493 (setq newlist (cons (cons (car alst) (car ulst)) newlist))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
494 (setq alst (cdr alst)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
495 ulst (cdr ulst)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
496 ;; 2 - Run sort routine on it
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
497 (setq newlist (sort newlist pred)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
498 alst nil
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
499 ulst nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
500 ;; 3 - Separate the lists
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
501 (while newlist
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
502 (setq alst (cons (car (car newlist)) alst)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
503 ulst (cons (cdr (car newlist)) ulst))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
504 (setq newlist (cdr newlist)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
505 ;; 4 - Store them back
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
506 (oset namelst data (reverse alst))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
507 (oset numlst data (reverse ulst))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
508
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
509 ;;; Utilities
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
510
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
511 (defun chart-goto-xy (x y)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
512 "Move cursor to position X Y in buffer, and add spaces and CRs if needed."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
513 (let ((indent-tabs-mode nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
514 (num (progn (goto-char (point-min)) (forward-line y))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
515 (if (and (= 0 num) (/= 0 (current-column))) (newline 1))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
516 (if (eobp) (newline num))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
517 (if (< x 0) (setq x 0))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
518 (if (< y 0) (setq y 0))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
519 ;; Now, a quicky column moveto/forceto method.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
520 (or (= (move-to-column x) x)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
521 (let ((p (point)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
522 (indent-to x)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
523 (remove-text-properties p (point) '(face))))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
524
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
525 (defun chart-zap-chars (n)
105327
dcbb3800a4e1 Doc/message fixes.
Glenn Morris <rgm@gnu.org>
parents: 105237
diff changeset
526 "Zap up to N chars without deleting EOLs."
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
527 (if (not (eobp))
111433
05dc9dca8729 Replace end-of-line, save-excursion etc with point-at-eol, point-at-bol.
Glenn Morris <rgm@gnu.org>
parents: 110909
diff changeset
528 (if (< n (- (point-at-eol) (point)))
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
529 (delete-char n)
111433
05dc9dca8729 Replace end-of-line, save-excursion etc with point-at-eol, point-at-bol.
Glenn Morris <rgm@gnu.org>
parents: 110909
diff changeset
530 (delete-region (point) (point-at-eol)))))
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
531
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
532 (defun chart-display-label (label dir zone start end &optional face)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
533 "Display LABEL in direction DIR in column/row ZONE between START and END.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
534 Optional argument FACE is the property we wish to place on this text."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
535 (if (eq dir 'horizontal)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
536 (let (p1)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
537 (chart-goto-xy (+ start (- (/ (- end start) 2) (/ (length label) 2)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
538 zone)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
539 (setq p1 (point))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
540 (insert label)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
541 (chart-zap-chars (length label))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
542 (put-text-property p1 (point) 'face face)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
543 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
544 (let ((i 0)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
545 (stz (+ start (- (/ (- end start) 2) (/ (length label) 2)))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
546 (while (< i (length label))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
547 (chart-goto-xy zone (+ stz i))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
548 (insert (aref label i))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
549 (chart-zap-chars 1)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
550 (put-text-property (1- (point)) (point) 'face face)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
551 (setq i (1+ i))))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
552
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
553 (defun chart-draw-line (dir zone start end)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
554 "Draw a line using line-drawing characters in direction DIR.
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
555 Use column or row ZONE between START and END."
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
556 (chart-display-label
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
557 (make-string (- end start) (if (eq dir 'vertical) ?| ?\-))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
558 dir zone start end))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
559
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
560 (defun chart-deface-rectangle (dir r1 r2 face)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
561 "Colorize a rectangle in direction DIR across range R1 by range R2.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
562 R1 and R2 are dotted pairs. Colorize it with FACE."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
563 (let* ((range1 (if (eq dir 'vertical) r1 r2))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
564 (range2 (if (eq dir 'vertical) r2 r1))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
565 (y (car range2)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
566 (while (<= y (cdr range2))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
567 (chart-goto-xy (car range1) y)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
568 (put-text-property (point) (+ (point) (1+ (- (cdr range1) (car range1))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
569 'face face)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
570 (setq y (1+ y)))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
571
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
572 ;;; Helpful `I don't want to learn eieio just now' washover functions
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
573
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
574 (defun chart-bar-quickie (dir title namelst nametitle numlst numtitle
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
575 &optional max sort-pred)
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
576 "Wash over the complex EIEIO stuff and create a nice bar chart.
105327
dcbb3800a4e1 Doc/message fixes.
Glenn Morris <rgm@gnu.org>
parents: 105237
diff changeset
577 Create it going in direction DIR ['horizontal 'vertical] with TITLE
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
578 using a name sequence NAMELST labeled NAMETITLE with values NUMLST
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
579 labeled NUMTITLE.
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
580 Optional arguments:
105474
0a64442c10e3 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105377
diff changeset
581 Set the chart's max element display to MAX, and sort lists with
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
582 SORT-PRED if desired."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
583 (let ((nc (make-instance chart-bar
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
584 :title title
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
585 :key-label "8-m" ; This is a text key pic
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
586 :direction dir
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
587 ))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
588 (iv (eq dir 'vertical)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
589 (chart-add-sequence nc
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
590 (make-instance chart-sequece
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
591 :data namelst
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
592 :name nametitle)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
593 (if iv 'x-axis 'y-axis))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
594 (chart-add-sequence nc
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
595 (make-instance chart-sequece
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
596 :data numlst
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
597 :name numtitle)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
598 (if iv 'y-axis 'x-axis))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
599 (if sort-pred (chart-sort nc sort-pred))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
600 (if (integerp max) (chart-trim nc max))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
601 (switch-to-buffer (chart-new-buffer nc))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
602 (chart-draw nc)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
603
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
604 ;;; Test code
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
605
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
606 (defun chart-test-it-all ()
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
607 "Test out various charting features."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
608 (interactive)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
609 (chart-bar-quickie 'vertical "Test Bar Chart"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
610 '( "U1" "ME2" "C3" "B4" "QT" "EZ") "Items"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
611 '( 5 -10 23 20 30 -3) "Values")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
612 )
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
613
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
614 ;;; Sample utility function
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
615
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
616 (defun chart-file-count (dir)
105327
dcbb3800a4e1 Doc/message fixes.
Glenn Morris <rgm@gnu.org>
parents: 105237
diff changeset
617 "Draw a chart displaying the number of different file extensions in DIR."
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
618 (interactive "DDirectory: ")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
619 (if (not (string-match "/$" dir))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
620 (setq dir (concat dir "/")))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
621 (message "Collecting statistics...")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
622 (let ((flst (directory-files dir nil nil t))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
623 (extlst (list "<dir>"))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
624 (cntlst (list 0)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
625 (while flst
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
626 (let* ((j (string-match "[^\\.]\\(\\.[a-zA-Z]+\\|~\\|#\\)$" (car flst)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
627 (s (if (file-accessible-directory-p (concat dir (car flst)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
628 "<dir>"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
629 (if j
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
630 (substring (car flst) (match-beginning 1) (match-end 1))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
631 nil)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
632 (m (member s extlst)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
633 (if (not s) nil
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
634 (if m
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
635 (let ((cell (nthcdr (- (length extlst) (length m)) cntlst)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
636 (setcar cell (1+ (car cell))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
637 (setq extlst (cons s extlst)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
638 cntlst (cons 1 cntlst)))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
639 (setq flst (cdr flst)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
640 ;; Lets create the chart!
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
641 (chart-bar-quickie 'vertical "Files Extension Distribution"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
642 extlst "File Extensions"
106895
181539c8b6a4 Fix typos in docstrings, error messages, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 106860
diff changeset
643 cntlst "# of occurrences"
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
644 10
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
645 '(lambda (a b) (> (cdr a) (cdr b))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
646 ))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
647
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
648 (defun chart-space-usage (d)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
649 "Display a top usage chart for directory D."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
650 (interactive "DDirectory: ")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
651 (message "Collecting statistics...")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
652 (let ((nmlst nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
653 (cntlst nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
654 (b (get-buffer-create " *du-tmp*")))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
655 (set-buffer b)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
656 (erase-buffer)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
657 (insert "cd " d ";du -sk * \n")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
658 (message "Running `cd %s;du -sk *'..." d)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
659 (call-process-region (point-min) (point-max) shell-file-name t
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
660 (current-buffer) nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
661 (goto-char (point-min))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
662 (message "Scanning output ...")
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
663 (while (re-search-forward "^\\([0-9]+\\)[ \t]+\\([^ \n]+\\)$" nil t)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
664 (let* ((nam (buffer-substring (match-beginning 2) (match-end 2)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
665 (num (buffer-substring (match-beginning 1) (match-end 1))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
666 (setq nmlst (cons nam nmlst)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
667 ;; * 1000 to put it into bytes
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
668 cntlst (cons (* (string-to-number num) 1000) cntlst))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
669 (if (not nmlst)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
670 (error "No files found!"))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
671 (chart-bar-quickie 'vertical (format "Largest files in %s" d)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
672 nmlst "File Name"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
673 cntlst "File Size"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
674 10
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
675 '(lambda (a b) (> (cdr a) (cdr b))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
676 ))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
677
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
678 (defun chart-emacs-storage ()
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
679 "Chart the current storage requirements of Emacs."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
680 (interactive)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
681 (let* ((data (garbage-collect))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
682 (names '("strings/2" "vectors"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
683 "conses" "free cons"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
684 "syms" "free syms"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
685 "markers" "free mark"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
686 ;; "floats" "free flt"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
687 ))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
688 (nums (list (/ (nth 3 data) 2)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
689 (nth 4 data)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
690 (car (car data)) ; conses
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
691 (cdr (car data))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
692 (car (nth 1 data)) ; syms
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
693 (cdr (nth 1 data))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
694 (car (nth 2 data)) ; markers
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
695 (cdr (nth 2 data))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
696 ;(car (nth 5 data)) ; floats are Emacs only
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
697 ;(cdr (nth 5 data))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
698 )))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
699 ;; Lets create the chart!
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
700 (chart-bar-quickie 'vertical "Emacs Runtime Storage Usage"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
701 names "Storage Items"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
702 nums "Objects")))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
703
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
704 (defun chart-emacs-lists ()
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
705 "Chart out the size of various important lists."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
706 (interactive)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
707 (let* ((names '("buffers" "frames" "processes" "faces"))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
708 (nums (list (length (buffer-list))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
709 (length (frame-list))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
710 (length (process-list))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
711 (length (face-list))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
712 )))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
713 (if (fboundp 'x-display-list)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
714 (setq names (append names '("x-displays"))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
715 nums (append nums (list (length (x-display-list))))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
716 ;; Lets create the chart!
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
717 (chart-bar-quickie 'vertical "Emacs List Size Chart"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
718 names "Various Lists"
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
719 nums "Objects")))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
720
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
721 (defun chart-rmail-from ()
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
722 "If we are in an rmail summary buffer, then chart out the froms."
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
723 (interactive)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
724 (if (not (eq major-mode 'rmail-summary-mode))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
725 (error "You must invoke chart-rmail-from in an rmail summary buffer"))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
726 (let ((nmlst nil)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
727 (cntlst nil))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
728 (save-excursion
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
729 (goto-char (point-min))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
730 (while (re-search-forward "\\-[A-Z][a-z][a-z] +\\(\\w+\\)@\\w+" nil t)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
731 (let* ((nam (buffer-substring (match-beginning 1) (match-end 1)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
732 (m (member nam nmlst)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
733 (message "Scanned username %s" nam)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
734 (if m
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
735 (let ((cell (nthcdr (- (length nmlst) (length m)) cntlst)))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
736 (setcar cell (1+ (car cell))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
737 (setq nmlst (cons nam nmlst)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
738 cntlst (cons 1 cntlst))))))
106895
181539c8b6a4 Fix typos in docstrings, error messages, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 106860
diff changeset
739 (chart-bar-quickie 'vertical "Username Occurrence in RMAIL box"
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
740 nmlst "User Names"
106895
181539c8b6a4 Fix typos in docstrings, error messages, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 106860
diff changeset
741 cntlst "# of occurrences"
105237
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
742 10
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
743 '(lambda (a b) (> (cdr a) (cdr b))))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
744 ))
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
745
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
746
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
747 (provide 'chart)
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
748
1a62d24e31a6 * emacs-lisp/chart.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
749 ;;; chart.el ends here