2021-05-29 07:40:06 +00:00
|
|
|
#+TITLE: chronometrist-spark
|
2021-05-30 19:31:25 +00:00
|
|
|
#+SUBTITLE: Show sparklines in Chronometrist
|
2021-06-01 13:07:29 +00:00
|
|
|
#+PROPERTY: header-args :tangle yes :load yes
|
2021-05-29 07:40:06 +00:00
|
|
|
|
|
|
|
* chronometrist-spark
|
|
|
|
** Library headers and commentary
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2021-05-29 12:14:51 +00:00
|
|
|
;;; chronometrist-spark.el --- Show sparklines in Chronometrist -*- lexical-binding: t; -*-
|
2021-05-29 07:40:06 +00:00
|
|
|
|
2021-06-01 13:07:29 +00:00
|
|
|
;; Author: contrapunctus <xmpp:contrapunctus@jabjab.de>
|
|
|
|
;; Maintainer: contrapunctus <xmpp:contrapunctus@jabjab.de>
|
2021-05-29 07:40:06 +00:00
|
|
|
;; Keywords: calendar
|
|
|
|
;; Homepage: https://tildegit.org/contrapunctus/chronometrist
|
2021-06-01 13:07:29 +00:00
|
|
|
;; Package-Requires: ((chronometrist "0.7.0") (spark "0.1"))
|
2021-05-29 07:40:06 +00:00
|
|
|
;; Version: 0.1.0
|
|
|
|
|
|
|
|
;; This is free and unencumbered software released into the public domain.
|
|
|
|
;;
|
|
|
|
;; Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
|
|
;; distribute this software, either in source code form or as a compiled
|
|
|
|
;; binary, for any purpose, commercial or non-commercial, and by any
|
|
|
|
;; means.
|
|
|
|
;;
|
|
|
|
;; For more information, please refer to <https://unlicense.org>
|
2021-06-01 13:07:29 +00:00
|
|
|
|
2021-05-29 07:40:06 +00:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
"Commentary" is displayed when the user clicks on the package's entry in =M-x list-packages=.
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; This package adds a column to Chronometrist displaying sparklines for each task.
|
|
|
|
#+END_SRC
|
|
|
|
** Dependencies
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
;;; Code:
|
|
|
|
(require 'chronometrist)
|
|
|
|
(require 'spark)
|
|
|
|
#+END_SRC
|
|
|
|
** Code
|
2021-05-29 11:41:05 +00:00
|
|
|
*** length :custom:variable:
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defcustom chronometrist-spark-length 7
|
|
|
|
"Length of each sparkline in number of days.")
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
*** TODO row-transformer :function:
|
|
|
|
if larger than 7
|
|
|
|
add space after (% length 7)th element
|
|
|
|
then add space after every 7 elements
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defun chronometrist-spark-row-transformer (row)
|
|
|
|
"Add a sparkline cell to ROW.
|
|
|
|
Used to add a sparkline column to `chronometrist-rows'.
|
|
|
|
|
|
|
|
ROW must be a valid element of the list specified by
|
|
|
|
`tabulated-list-entries'."
|
2021-06-01 13:07:29 +00:00
|
|
|
(-let* (((task vector) row)
|
|
|
|
(sparkline (cl-loop with today = (ts-now)
|
|
|
|
for day from (- (- chronometrist-spark-length 1)) to 0
|
|
|
|
collect (chronometrist-task-time-one-day
|
|
|
|
task (ts-adjust 'day day today))
|
|
|
|
into durations
|
|
|
|
finally return (spark durations))))
|
2021-05-29 11:41:05 +00:00
|
|
|
(list task (vconcat vector `[,sparkline]))))
|
|
|
|
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
*** TODO schema-transformer :function:
|
|
|
|
calculate length while accounting for space
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defun chronometrist-spark-schema-transformer (schema)
|
|
|
|
"Add a sparkline column to SCHEMA.
|
|
|
|
Used to add a sparkline column to `chronometrist-schema-transformers'.
|
|
|
|
SCHEMA should be a vector as specified by `tabulated-list-format'."
|
|
|
|
(vconcat schema `[("Graph" ,chronometrist-spark-length t)]))
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
*** setup :writer:
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defun chronometrist-spark-setup ()
|
|
|
|
"Add `chronometrist-sparkline' functions to `chronometrist' hooks."
|
|
|
|
(add-to-list 'chronometrist-row-transformers #'chronometrist-spark-row-transformer)
|
2021-05-29 15:25:38 +00:00
|
|
|
(add-to-list 'chronometrist-schema-transformers #'chronometrist-spark-schema-transformer))
|
2021-05-29 11:41:05 +00:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
*** teardown :writer:
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defun chronometrist-spark-teardown ()
|
|
|
|
"Remove `chronometrist-sparkline' functions from `chronometrist' hooks."
|
|
|
|
(setq chronometrist-row-transformers
|
|
|
|
(remove #'chronometrist-spark-row-transformer chronometrist-row-transformers)
|
|
|
|
chronometrist-schema-transformers
|
2021-05-29 15:25:38 +00:00
|
|
|
(remove #'chronometrist-spark-schema-transformer chronometrist-schema-transformers)))
|
2021-05-29 11:41:05 +00:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
*** minor-mode :minor:mode:
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(define-minor-mode chronometrist-spark-minor-mode
|
|
|
|
nil nil nil nil
|
|
|
|
;; when being enabled/disabled, `chronometrist-spark-minor-mode' will already be t/nil here
|
|
|
|
(if chronometrist-spark-minor-mode (chronometrist-spark-setup) (chronometrist-spark-teardown)))
|
|
|
|
#+END_SRC
|
|
|
|
|
2021-05-29 07:40:06 +00:00
|
|
|
** Provide
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(provide 'chronometrist-spark)
|
|
|
|
;;; chronometrist-spark.el ends here
|
|
|
|
#+END_SRC
|
|
|
|
** Local Variables :noexport:
|
|
|
|
# Local Variables:
|
|
|
|
# org-html-self-link-headlines: t
|
2021-06-01 13:07:29 +00:00
|
|
|
# eval: (org-indent-mode)
|
2021-05-29 07:40:06 +00:00
|
|
|
# eval: (visual-fill-column-mode -1)
|
|
|
|
# eval: (nameless-mode)
|
2021-06-01 13:07:29 +00:00
|
|
|
# eval: (progn (make-local-variable (quote before-save-hook)) (add-hook (quote before-save-hook) (lambda () (start-process "chronometrist-tangle" (generate-new-buffer-name "chronometrist-tangle") "emacs" "-q" "-Q" "--batch" "--eval=(require 'ob-tangle)" "--eval=(org-babel-tangle-file \"chronometrist-spark.org\" \"chronometrist-spark.el\")"))))
|
2021-05-29 07:40:06 +00:00
|
|
|
# End:
|