comparison lisp/calc/calc-graph.el @ 82247:c94005a91774

(calc-graph-format-data,calc-graph-add-curve): Check for error forms. (calc-graph-set-styles): Add option for error forms.
author Jay Belanger <jay.p.belanger@gmail.com>
date Fri, 03 Aug 2007 05:22:48 +0000
parents 095d08e7d6bb
children 107ccd98fa12 cd5e99697764
comparison
equal deleted inserted replaced
82246:5dbe5cf5ad96 82247:c94005a91774
216 (calc-graph-set-styles 216 (calc-graph-set-styles
217 (or (and (Math-num-integerp lstyle) (math-trunc lstyle)) 217 (or (and (Math-num-integerp lstyle) (math-trunc lstyle))
218 0) 218 0)
219 (or (and (Math-num-integerp pstyle) (math-trunc pstyle)) 219 (or (and (Math-num-integerp pstyle) (math-trunc pstyle))
220 (if (eq (car-safe (calc-var-value (nth 2 ydata))) 'vec) 220 (if (eq (car-safe (calc-var-value (nth 2 ydata))) 'vec)
221 0 -1))))) 221 0 -1))
222 (math-contains-sdev-p (eval (nth 2 ydata))))))
222 223
223 (defun calc-graph-lookup (thing) 224 (defun calc-graph-lookup (thing)
224 (if (and (eq (car-safe thing) 'var) 225 (if (and (eq (car-safe thing) 'var)
225 (calc-var-value (nth 2 thing))) 226 (calc-var-value (nth 2 thing)))
226 thing 227 thing
790 calc-graph-zp (cons (math-evaluate-expr calc-graph-yvalue) calc-graph-zp)))) 791 calc-graph-zp (cons (math-evaluate-expr calc-graph-yvalue) calc-graph-zp))))
791 (setq calc-graph-zp (nreverse calc-graph-zp) 792 (setq calc-graph-zp (nreverse calc-graph-zp)
792 calc-graph-numsteps (1- (* calc-graph-numsteps (1+ calc-graph-numsteps3)))))) 793 calc-graph-numsteps (1- (* calc-graph-numsteps (1+ calc-graph-numsteps3))))))
793 794
794 (defun calc-graph-format-data () 795 (defun calc-graph-format-data ()
796 (if (math-contains-sdev-p calc-graph-yp)
797 (let ((yp calc-graph-yp))
798 (setq calc-graph-yp (cons 'vec (mapcar 'math-get-value (cdr yp))))
799 (setq calc-graph-zp (cons 'vec (mapcar 'math-get-sdev (cdr yp))))))
795 (while (<= (setq calc-graph-stepcount (1+ calc-graph-stepcount)) calc-graph-numsteps) 800 (while (<= (setq calc-graph-stepcount (1+ calc-graph-stepcount)) calc-graph-numsteps)
796 (if calc-graph-xvec 801 (if calc-graph-xvec
797 (setq calc-graph-xp (cdr calc-graph-xp) 802 (setq calc-graph-xp (cdr calc-graph-xp)
798 calc-graph-xval (car calc-graph-xp) 803 calc-graph-xval (car calc-graph-xp)
799 calc-graph-yp (cdr calc-graph-yp) 804 calc-graph-yp (cdr calc-graph-yp)
1057 1062
1058 (defun calc-graph-point-style (style) 1063 (defun calc-graph-point-style (style)
1059 (interactive "P") 1064 (interactive "P")
1060 (calc-graph-set-styles t (and style (prefix-numeric-value style)))) 1065 (calc-graph-set-styles t (and style (prefix-numeric-value style))))
1061 1066
1062 (defun calc-graph-set-styles (lines points) 1067 (defun calc-graph-set-styles (lines points &optional yerr)
1063 (calc-graph-init) 1068 (calc-graph-init)
1064 (save-excursion 1069 (save-excursion
1065 (set-buffer calc-gnuplot-input) 1070 (set-buffer calc-gnuplot-input)
1066 (or (calc-graph-find-plot nil nil) 1071 (or (calc-graph-find-plot nil nil)
1067 (error "No data points have been set!")) 1072 (error "No data points have been set!"))
1068 (let ((base (point)) 1073 (let ((base (point))
1069 (mode nil) (lstyle nil) (pstyle nil) 1074 (mode nil) (lstyle nil) (pstyle nil)
1070 start end lenbl penbl) 1075 start end lenbl penbl errform)
1071 (re-search-forward "[,\n]") 1076 (re-search-forward "[,\n]")
1072 (forward-char -1) 1077 (forward-char -1)
1073 (setq end (point) start end) 1078 (setq end (point) start end)
1074 (goto-char base) 1079 (goto-char base)
1075 (if (looking-at "[^,\n]*[^,\n \t]\\([ \t]+with\\)") 1080 (if (looking-at "[^,\n]*[^,\n \t]\\([ \t]+with\\)")
1085 (match-end 1))))) 1090 (match-end 1)))))
1086 (if (looking-at "[ \ta-z]+[0-9]+[ \t]+\\([0-9]+\\)") 1091 (if (looking-at "[ \ta-z]+[0-9]+[ \t]+\\([0-9]+\\)")
1087 (setq pstyle (string-to-number 1092 (setq pstyle (string-to-number
1088 (buffer-substring (match-beginning 1) 1093 (buffer-substring (match-beginning 1)
1089 (match-end 1))))))) 1094 (match-end 1)))))))
1090 (setq lenbl (or (equal mode "lines") (equal mode "linespoints")) 1095 (unless yerr
1091 penbl (or (equal mode "points") (equal mode "linespoints"))) 1096 (setq lenbl (or (equal mode "lines")
1092 (if lines 1097 (equal mode "linespoints"))
1093 (or (eq lines t) 1098 penbl (or (equal mode "points")
1094 (setq lstyle lines 1099 (equal mode "linespoints")))
1095 lenbl (>= lines 0))) 1100 (if lines
1096 (setq lenbl (not lenbl))) 1101 (or (eq lines t)
1097 (if points 1102 (setq lstyle lines
1098 (or (eq points t) 1103 lenbl (>= lines 0)))
1099 (setq pstyle points 1104 (setq lenbl (not lenbl)))
1100 penbl (>= points 0))) 1105 (if points
1101 (setq penbl (not penbl))) 1106 (or (eq points t)
1102 (delete-region start end) 1107 (setq pstyle points
1108 penbl (>= points 0)))
1109 (setq penbl (not penbl))))
1110 (delete-region start end)
1103 (goto-char start) 1111 (goto-char start)
1104 (insert " with " 1112 (setq errform
1105 (if lenbl 1113 (condition-case nil
1106 (if penbl "linespoints" "lines") 1114 (math-contains-sdev-p
1107 (if penbl "points" "dots"))) 1115 (eval (intern
1108 (if (and pstyle (> pstyle 0)) 1116 (concat "var-"
1109 (insert " " (if (and lstyle (> lstyle 0)) (int-to-string lstyle) "1") 1117 (save-excursion
1110 " " (int-to-string pstyle)) 1118 (re-search-backward ":\\(.*\\)\\}")
1111 (if (and lstyle (> lstyle 0)) 1119 (match-string 1))))))
1112 (insert " " (int-to-string lstyle)))))) 1120 (error nil)))
1121 (if yerr
1122 (insert " with yerrorbars")
1123 (insert " with "
1124 (if (and errform
1125 (equal mode "dots")
1126 (eq lines t))
1127 "yerrorbars"
1128 (if lenbl
1129 (if penbl "linespoints" "lines")
1130 (if penbl "points" "dots"))))
1131 (if (and pstyle (> pstyle 0))
1132 (insert " "
1133 (if (and lstyle (> lstyle 0)) (int-to-string lstyle) "1")
1134 " " (int-to-string pstyle))
1135 (if (and lstyle (> lstyle 0))
1136 (insert " " (int-to-string lstyle)))))))
1113 (calc-graph-view-commands)) 1137 (calc-graph-view-commands))
1114 1138
1115 (defun calc-graph-zero-x (flag) 1139 (defun calc-graph-zero-x (flag)
1116 (interactive "P") 1140 (interactive "P")
1117 (calc-graph-set-command "noxzeroaxis" 1141 (calc-graph-set-command "noxzeroaxis"