Skip to content

Commit

Permalink
[reports] rendering is more responsive by pulsing progressbar
Browse files Browse the repository at this point in the history
previously the renderer (html-document object to html-string) would
attempt to update progressbar. However the html-object is a deeply
nested hierarchical object, (length object) is not suitable to
calculate progressbar fraction. Therefore we change update by pulsing
progressbar instead every 2500 loops in html-document, html-table and
html-text renderers.
  • Loading branch information
christopherlam committed Sep 12, 2020
1 parent d0b8cd2 commit 63ec05d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 1 addition & 4 deletions gnucash/report/html-document.scm
Expand Up @@ -110,8 +110,6 @@
(let* ((retval '())
(push (lambda (l) (set! retval (cons l retval))))
(objs (gnc:html-document-objects doc))
(work-to-do (length objs))
(work-done 0)
(title (gnc:html-document-title doc)))
;; compile the doc style
(gnc:html-style-table-compile (gnc:html-document-style doc)
Expand Down Expand Up @@ -144,8 +142,7 @@
(for-each
(lambda (child)
(push (gnc:html-object-render child doc))
(set! work-done (+ 1 work-done))
(gnc:report-percent-done (* 100 (/ work-done work-to-do))))
(gnc:pulse-progress-bar))
objs)

(when headers?
Expand Down
2 changes: 2 additions & 0 deletions gnucash/report/html-table.scm
Expand Up @@ -168,6 +168,7 @@
(format #f "colspan=\"~a\"" (gnc:html-table-cell-colspan cell))))
(for-each
(lambda (child)
(gnc:pulse-progress-bar)
(push (gnc:html-object-render child doc)))
cell-data)
(push (gnc:html-document-markup-end doc cell-tag))
Expand Down Expand Up @@ -475,6 +476,7 @@
(push (gnc:html-document-markup-end doc rowmarkup))
(when rowstyle (gnc:html-document-pop-style doc))

(gnc:pulse-progress-bar)
(rowloop (cdr rows) (1+ rownum)))))
(push (gnc:html-document-markup-end doc "tbody"))

Expand Down
1 change: 1 addition & 0 deletions gnucash/report/html-text.scm
Expand Up @@ -202,6 +202,7 @@
(gnc:html-document-push-style doc (gnc:html-text-style p))
(for-each
(lambda (elt)
(gnc:pulse-progress-bar)
(cond ((procedure? elt)
(push (elt doc)))
(#t
Expand Down
8 changes: 8 additions & 0 deletions gnucash/report/report-utilities.scm
Expand Up @@ -623,6 +623,14 @@
(gnc:warn "report more than 100% finished. " percent))
(gnc-window-show-progress "" percent))

(define-public gnc:pulse-progress-bar
(let ((pulse-idx 0))
(lambda ()
(set! pulse-idx (1+ pulse-idx))
(when (= pulse-idx 2500)
(set! pulse-idx 0)
(gnc-window-show-progress "" 105)))))

(define (gnc:report-finished)
(gnc-window-show-progress "" -1))

Expand Down

1 comment on commit 63ec05d

@christopherlam
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This progress bar function is designed to pulse every 2500 calls which means my transaction report with 1 year of transactions generates 8 pulses only, therefore not too onerous.

Please sign in to comment.