From 1269e656d668f9ed5d2b254f6f9018ee3ac4b59a Mon Sep 17 00:00:00 2001 From: JSDurand Date: Wed, 13 Dec 2023 14:33:37 +0800 Subject: 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. --- account.el | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'account.el') 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 -- cgit v1.2.3-18-g5258