diff options
-rw-r--r-- | account.el | 70 |
1 files changed, 70 insertions, 0 deletions
@@ -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 |