annotate lisp/emacs-lisp/chart.el @ 105755:cc6727b235b0

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