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