branch: externals/svg-tag-mode commit 8533c6c174d6ff97065fec6bce15292c041c5be1 Author: Nicolas P. Rougier <nicolas.roug...@inria.fr> Commit: Nicolas P. Rougier <nicolas.roug...@inria.fr>
Added progress bar example. --- examples/example-2.el | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/examples/example-2.el b/examples/example-2.el index 90b66f59c4..b041af1f3a 100644 --- a/examples/example-2.el +++ b/examples/example-2.el @@ -19,6 +19,23 @@ (defconst time-re "[0-9]\\{2\\}:[0-9]\\{2\\}") (defconst day-re "[A-Za-z]\\{3\\}") +(defun svg-progress-percent (value) + (svg-image (svg-lib-concat + (svg-lib-progress-bar (/ (string-to-number value) 100.0) + nil :margin 0 :stroke 2 :radius 3 :padding 2 :width 11) + (svg-lib-tag (concat value "%") + nil :stroke 0 :margin 0)) :ascent 'center)) + +(defun svg-progress-count (value) + (let* ((seq (mapcar #'string-to-number (split-string value "/"))) + (count (float (car seq))) + (total (float (cadr seq)))) + (svg-image (svg-lib-concat + (svg-lib-progress-bar (/ count total) nil + :margin 0 :stroke 2 :radius 3 :padding 2 :width 11) + (svg-lib-tag value nil + :stroke 0 :margin 0)) :ascent 'center))) + (setq svg-tag-tags `( ;; Org tags @@ -27,18 +44,24 @@ :beg 2 :alignment 0)))) ("\\(:#[A-Za-z0-9]+:\\)$" . ((lambda (tag) (svg-tag-make tag :face 'org-tag - :beg 2 :end -1 + :beg 2 :end -1 :alignment 0)))) - ;; Org priority + ;; Task priority ("\\[#[A-Z]\\]" . ( (lambda (tag) (svg-tag-make tag :face 'org-priority :beg 2 :end -1 :margin 0)))) - ;; Org TODO / DONE + ;; Progress + ("\\(\\[[0-9]\\{1,3\\}%\\]\\)" . ((lambda (tag) + (svg-progress-percent (substring tag 1 -2))))) + ("\\(\\[[0-9]+/[0-9]+\\]\\)" . ((lambda (tag) + (svg-progress-count (substring tag 1 -1))))) + + ;; TODO / DONE ("TODO" . ((svg-tag-make "TODO" :face 'org-todo :inverse t :margin 0))) ("DONE" . ((svg-tag-make "DONE" :face 'org-done :margin 0))) - ;; Org date (without day name) + ;; Active date (without day name, with or without time) (,(format "\\(<%s>\\)" date-re) . ((lambda (tag) (svg-tag-make tag :beg 1 :end -1 :margin 0)))) @@ -49,6 +72,7 @@ ((lambda (tag) (svg-tag-make tag :end -1 :inverse t :crop-left t :margin 0)))) + ;; Inactive date (without day name, with or without time) (,(format "\\(\\[%s\\]\\)" date-re) . ((lambda (tag) (svg-tag-make tag :beg 1 :end -1 :margin 0 :face 'org-date)))) @@ -64,6 +88,8 @@ ;; To do: TODO DONE ;; Tags: :#MEETING:#NOTE: ;; Priorities: [#A] [#B] [#C] +;; Progress: [1/3] +;; [42%] ;; Active date: <2021-12-24> ;; <2021-12-24 14:00> ;; Inactive date: [2021-12-24]