summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-12-13 14:33:37 +0800
committerJSDurand <mmemmew@gmail.com>2023-12-13 14:33:37 +0800
commit1269e656d668f9ed5d2b254f6f9018ee3ac4b59a (patch)
treebb6f5dd647aa32dc80723b35f33943c618a44a3d
parent01b2557cbfba56971d2c71cc3ee4d96638f966e2 (diff)
account: Add misc purpose and chart exporting option.
* account.el (account-purposes-list): Add misc purpose (account-agenda-export-to-chart): This function uses the built-in chart library for exporting to charts. I still prefer the svg display, though.
-rw-r--r--account.el70
1 files changed, 70 insertions, 0 deletions
diff --git a/account.el b/account.el
index c6b01bf..ca0b0a1 100644
--- a/account.el
+++ b/account.el
@@ -86,6 +86,7 @@ The first capture group is the name of the item.")
(list
"breakfast" "brunch" "brunverage" "lunch"
"dinner" "beverage" "snack" "fruit" "book"
+ "misc"
"transportation")
"The list of purposes of accounts.")
@@ -1002,5 +1003,74 @@ a match."
(cons 'window-width 0.75)))
(select-window (get-buffer-window svg-buffer-name))))))))
+(defun account-agenda-export-to-chart ()
+ "Export the current agenda into a plain-text chart."
+ (interactive)
+ (let ((chart-buffer-name "account-chart")
+ prop cost date result)
+ (save-restriction
+ (save-excursion
+ (save-match-data
+ (widen)
+ (goto-char (point-min))
+ (while (setq
+ prop
+ (text-property-search-forward
+ 'daily-cost nil
+ (lambda (_ val)
+ (and (numberp val) (>= val 0)))
+ t))
+ (forward-char -1)
+ (setq cost (prop-match-value prop))
+ (setq date (get-text-property (point) 'date))
+ (cond
+ ((= cost 0))
+ ((setq result
+ (cons (cons date cost)
+ result))))))))
+ (require 'chart)
+ (let ((nc (make-instance
+ 'chart-bar
+ :title chart-buffer-name
+ :key-label "8-m"
+ :direction 'horizontal)))
+ (chart-add-sequence
+ nc
+ (make-instance
+ 'chart-sequence
+ :data (mapcar
+ (lambda (cell)
+ (account-agenda-format-date (car cell)))
+ result)
+ :name "Dates")
+ 'y-axis)
+ (chart-add-sequence
+ nc
+ (make-instance
+ 'chart-sequence
+ :data (mapcar #'cdr result)
+ :name "Costs")
+ 'x-axis)
+ (let ((buffer (get-buffer-create
+ (format "*%s*" chart-buffer-name))))
+ (display-buffer
+ buffer
+ (list
+ (list #'display-buffer-in-direction)
+ (cons 'direction 'right)
+ (cons 'window 'main)
+ (cons 'window-width 0.75)))
+ (select-window (get-buffer-window buffer))
+ (switch-to-buffer buffer)
+ (chart-mode)
+ (setq chart-local-object nc)
+ (oset
+ nc x-width
+ (- (window-width (get-buffer-window buffer)) 10))
+ (oset
+ nc y-width
+ (* 3 (length result)))
+ (chart-draw nc)))))
+
(provide 'account)
;;; account.el ends here