mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[category-barchart] simplify code
This commit is contained in:
parent
b79dffc5f4
commit
5f06fc99fd
@ -328,23 +328,21 @@ developing over time"))
|
||||
;; created.
|
||||
(other-anchor ""))
|
||||
|
||||
;; Converts a commodity-collector into gnc-monetary in the report's
|
||||
;; currency using the exchange-fn calculated above. Returns a gnc-monetary
|
||||
;; Converts a commodity-collector into amount in the report's
|
||||
;; currency using the exchange-fn calculated above. Returns an amount
|
||||
;; multiplied by the averaging-multiplier (smaller than one; multiplication
|
||||
;; instead of division to avoid division-by-zero issues) in case
|
||||
;; the user wants to see the amounts averaged over some value.
|
||||
(define (collector->monetary c date)
|
||||
(gnc:make-gnc-monetary
|
||||
report-currency
|
||||
(* averaging-multiplier
|
||||
(gnc:gnc-monetary-amount
|
||||
(gnc:sum-collector-commodity
|
||||
c report-currency
|
||||
(lambda (a b) (exchange-fn a b date)))))))
|
||||
(define (collector->report-currency-amount c date)
|
||||
(* averaging-multiplier
|
||||
(gnc:gnc-monetary-amount
|
||||
(gnc:sum-collector-commodity
|
||||
c report-currency
|
||||
(lambda (a b) (exchange-fn a b date))))))
|
||||
|
||||
(define (all-zeros data)
|
||||
(cond
|
||||
((gnc:gnc-monetary? data) (zero? (gnc:gnc-monetary-amount data)))
|
||||
((number? data) (zero? data))
|
||||
((pair? data) (every all-zeros data))
|
||||
(else (error 'huh))))
|
||||
|
||||
@ -396,11 +394,11 @@ developing over time"))
|
||||
(loop (cdr list-of-mon-collectors)
|
||||
(cdr dates-list)
|
||||
(cons (if do-intervals?
|
||||
(collector->monetary
|
||||
(collector->report-currency-amount
|
||||
(gnc:collector- (cadr list-of-mon-collectors)
|
||||
(car list-of-mon-collectors))
|
||||
(cadr dates-list))
|
||||
(collector->monetary
|
||||
(collector->report-currency-amount
|
||||
(car list-of-mon-collectors)
|
||||
(car dates-list)))
|
||||
result))))))
|
||||
@ -462,9 +460,7 @@ developing over time"))
|
||||
;; Sort the account list according to the account code field.
|
||||
(set! all-data
|
||||
(sort
|
||||
(filter (lambda (l)
|
||||
(not (zero? (gnc:gnc-monetary-amount
|
||||
(apply gnc:monetary+ (cadr l))))))
|
||||
(filter (lambda (l) (not (zero? (apply + (cadr l)))))
|
||||
(traverse-accounts 1 topl-accounts))
|
||||
(case sort-method
|
||||
((alphabetical)
|
||||
@ -480,8 +476,8 @@ developing over time"))
|
||||
(xaccAccountGetCode (car b)))))
|
||||
((amount)
|
||||
(lambda (a b)
|
||||
(> (gnc:gnc-monetary-amount (apply gnc:monetary+ (cadr a)))
|
||||
(gnc:gnc-monetary-amount (apply gnc:monetary+ (cadr b)))))))))
|
||||
(> (apply + (cadr a))
|
||||
(apply + (cadr b))))))))
|
||||
|
||||
(cond
|
||||
((or (null? all-data) (all-zeros (map cadr all-data)))
|
||||
@ -494,7 +490,8 @@ developing over time"))
|
||||
(let* ((dates-list (if do-intervals?
|
||||
(list-head dates-list (1- (length dates-list)))
|
||||
dates-list))
|
||||
(date-string-list (map qof-print-date dates-list)))
|
||||
(date-string-list (map qof-print-date dates-list))
|
||||
(list-of-rows (apply zip (map cadr all-data))))
|
||||
|
||||
;; Set chart title, subtitle etc.
|
||||
(gnc:html-chart-set-type!
|
||||
@ -523,7 +520,7 @@ developing over time"))
|
||||
(let* ((start (take all-data (1- max-slices)))
|
||||
(finish (drop all-data (1- max-slices)))
|
||||
(other-sum (map
|
||||
(lambda (l) (apply gnc:monetary+ l))
|
||||
(lambda (l) (apply + l))
|
||||
(apply zip (map cadr finish)))))
|
||||
(set! all-data
|
||||
(append start
|
||||
@ -551,7 +548,7 @@ developing over time"))
|
||||
((string? acct) (car series))
|
||||
(show-fullname? (gnc-account-get-full-name acct))
|
||||
(else (xaccAccountGetName acct))))
|
||||
(amounts (map gnc:gnc-monetary-amount (cadr series)))
|
||||
(amounts (cadr series))
|
||||
(stack (if stacked? "default" (number->string stack)))
|
||||
(fill (eq? chart-type 'barchart))
|
||||
(urls (cond
|
||||
@ -601,18 +598,20 @@ developing over time"))
|
||||
(define (make-cell contents)
|
||||
(gnc:make-html-table-cell/markup "number-cell" contents))
|
||||
|
||||
(define (make-monetary-cell amount)
|
||||
(make-cell (gnc:make-gnc-monetary report-currency amount)))
|
||||
|
||||
(for-each
|
||||
(lambda (date row)
|
||||
(gnc:html-table-append-row!
|
||||
table
|
||||
(append (list (make-cell date))
|
||||
(map make-cell row)
|
||||
(map make-monetary-cell row)
|
||||
(if cols>1?
|
||||
(list
|
||||
(make-cell (apply gnc:monetary+ row)))
|
||||
(list (make-monetary-cell (apply + row)))
|
||||
'()))))
|
||||
date-string-list
|
||||
(apply zip (map cadr all-data)))
|
||||
list-of-rows)
|
||||
|
||||
(gnc:html-table-set-col-headers!
|
||||
table
|
||||
@ -655,10 +654,10 @@ developing over time"))
|
||||
(list date)
|
||||
row
|
||||
(if (pair? (cdr all-data))
|
||||
(list (apply gnc:monetary+ row))
|
||||
(list (apply + row))
|
||||
'())))
|
||||
(map (cut gnc-print-time64 <> iso-date) dates-list)
|
||||
(apply zip (map cadr all-data)))))))))))))))
|
||||
list-of-rows)))))))))))))
|
||||
|
||||
(unless (gnc:html-document-export-string document)
|
||||
(gnc:html-document-set-export-error document (G_ "No exportable data")))
|
||||
|
Loading…
Reference in New Issue
Block a user