Add sorting options for barcharts and piecharts. Work around Guppi

problem by replacing the character "&" with the word "and".


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7760 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2003-01-03 07:10:36 +00:00
parent 2c0b8dae96
commit c1b10d5299
5 changed files with 108 additions and 22 deletions

View File

@ -1,5 +1,28 @@
2003-01-02 David Hampton <hampton@employees.org> 2003-01-02 David Hampton <hampton@employees.org>
* src/report/report-system/options-utilities.scm:
* src/report/report-system/report-system.scm: Add new option for
specifying sort critera for piecharts and barcharts.
* src/report/standard-reports/account-piecharts.scm: Add various
sorting options. Work around Guppi problem by replacing the
character "&" with the word "and".
* src/report/standard-reports/category-barchart.scm: Add various
sorting options. The default is now by ammount instead of by
account-code, which is a much more interesting report. #102342
Work around Guppi problem by replacing the character "&" with the
word "and". Don't "reverse" the barchart legend. Double-clicking
on the legend now opend the right child report.
* src/report/standard-reports/net-barchart.scm: The report title
should change when the report name field is changed in the
options. #102266
* src/report/standard-reports/pnl.scm: The report title should
change when the report name field is changed in the
options. #102267
* src/gnome-utils/window-help.c (helpWindow): Correctly pass on * src/gnome-utils/window-help.c (helpWindow): Correctly pass on
the label when first opening a help window. the label when first opening a help window.

View File

@ -273,3 +273,18 @@
(vector 'filledcircle "filled circle" "filled circle") (vector 'filledcircle "filled circle" "filled circle")
(vector 'filledsquare "filled square" "filled square"))))) (vector 'filledsquare "filled square" "filled square")))))
(define (gnc:options-add-sort-method!
options pagename optname sort-tag default)
(gnc:register-option
options
(gnc:make-multichoice-option
pagename optname
sort-tag
(N_ "Choose the method for sorting accounts.")
default
(list
(vector 'acct-code "Account Code" "Alphabetical by account code")
(vector 'alphabetical "Alphabetical" "Alphabetical by account name")
(vector 'amount "Amount" "By amount, largest to smallest")))))

View File

@ -67,6 +67,7 @@
(export gnc:options-add-price-source!) (export gnc:options-add-price-source!)
(export gnc:options-add-plot-size!) (export gnc:options-add-plot-size!)
(export gnc:options-add-marker-choice!) (export gnc:options-add-marker-choice!)
(export gnc:options-add-sort-method!)
;; html-utilities.scm ;; html-utilities.scm

View File

@ -28,6 +28,7 @@
(use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing. (use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing.
(use-modules (srfi srfi-1)) (use-modules (srfi srfi-1))
(use-modules (ice-9 slib)) (use-modules (ice-9 slib))
(use-modules (ice-9 regex))
(use-modules (gnucash gnc-module)) (use-modules (gnucash gnc-module))
(require 'printf) (require 'printf)
@ -72,6 +73,7 @@ balance at a given time"))
(define optname-slices (N_ "Maximum Slices")) (define optname-slices (N_ "Maximum Slices"))
(define optname-plot-width (N_ "Plot Width")) (define optname-plot-width (N_ "Plot Width"))
(define optname-plot-height (N_ "Plot Height")) (define optname-plot-height (N_ "Plot Height"))
(define optname-sort-method (N_ "Sort Method"))
;; The option-generator. The only dependance on the type of piechart ;; The option-generator. The only dependance on the type of piechart
;; is the list of account types that the account selection option ;; is the list of account types that the account selection option
@ -138,6 +140,10 @@ balance at a given time"))
options gnc:pagename-display options gnc:pagename-display
optname-plot-width optname-plot-height "d" 500 350) optname-plot-width optname-plot-height "d" 500 350)
(gnc:options-add-sort-method!
options gnc:pagename-display
optname-sort-method "e" 'amount)
(gnc:options-set-default-section options gnc:pagename-general) (gnc:options-set-default-section options gnc:pagename-general)
options)) options))
@ -182,6 +188,7 @@ balance at a given time"))
(max-slices (get-option gnc:pagename-display optname-slices)) (max-slices (get-option gnc:pagename-display optname-slices))
(height (get-option gnc:pagename-display optname-plot-height)) (height (get-option gnc:pagename-display optname-plot-height))
(width (get-option gnc:pagename-display optname-plot-width)) (width (get-option gnc:pagename-display optname-plot-width))
(sort-method (get-option gnc:pagename-display optname-sort-method))
(work-done 0) (work-done 0)
(work-to-do 0) (work-to-do 0)
@ -297,7 +304,21 @@ balance at a given time"))
(sort (filter (lambda (pair) (not (>= 0.0 (car pair)))) (sort (filter (lambda (pair) (not (>= 0.0 (car pair))))
(fix-signs (fix-signs
(traverse-accounts 1 topl-accounts))) (traverse-accounts 1 topl-accounts)))
(lambda (a b) (> (car a) (car b))))) (cond
((eq? sort-method 'acct-code)
(lambda (a b)
(string<? (gnc:account-get-code (cadr a))
(gnc:account-get-code (cadr b)))))
((eq? sort-method 'alphabetical)
(lambda (a b)
(string<? ((if show-fullname?
gnc:account-get-full-name
gnc:account-get-name) (cadr a))
((if show-fullname?
gnc:account-get-full-name
gnc:account-get-name) (cadr b)))))
(else
(lambda (a b) (> (car a) (car b)))))))
;; if too many slices, condense them to an 'other' slice ;; if too many slices, condense them to an 'other' slice
;; and add a link to a new pie report with just those ;; and add a link to a new pie report with just those
@ -397,11 +418,13 @@ balance at a given time"))
(map (map
(lambda (pair) (lambda (pair)
(string-append (string-append
(regexp-substitute/global #f "&"
(if (string? (cadr pair)) (if (string? (cadr pair))
(cadr pair) (cadr pair)
((if show-fullname? ((if show-fullname?
gnc:account-get-full-name gnc:account-get-full-name
gnc:account-get-name) (cadr pair))) gnc:account-get-name) (cadr pair)))
'pre " " (_ "and") " " 'post)
(if show-total? (if show-total?
(string-append (string-append
" - " " - "

View File

@ -27,6 +27,7 @@
(use-modules (srfi srfi-1)) (use-modules (srfi srfi-1))
(use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing. (use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing.
(use-modules (ice-9 slib)) (use-modules (ice-9 slib))
(use-modules (ice-9 regex))
(use-modules (gnucash gnc-module)) (use-modules (gnucash gnc-module))
(require 'printf) (require 'printf)
@ -79,6 +80,7 @@ developing over time"))
(define optname-slices (N_ "Maximum Bars")) (define optname-slices (N_ "Maximum Bars"))
(define optname-plot-width (N_ "Plot Width")) (define optname-plot-width (N_ "Plot Width"))
(define optname-plot-height (N_ "Plot Height")) (define optname-plot-height (N_ "Plot Height"))
(define optname-sort-method (N_ "Sort Method"))
(define (options-generator account-types) (define (options-generator account-types)
(let* ((options (gnc:new-options)) (let* ((options (gnc:new-options))
@ -142,7 +144,11 @@ developing over time"))
(gnc:options-add-plot-size! (gnc:options-add-plot-size!
options gnc:pagename-display options gnc:pagename-display
optname-plot-width optname-plot-height "c" 400 400) optname-plot-width optname-plot-height "d" 400 400)
(gnc:options-add-sort-method!
options gnc:pagename-display
optname-sort-method "e" 'amount)
(gnc:options-set-default-section options gnc:pagename-general) (gnc:options-set-default-section options gnc:pagename-general)
@ -193,6 +199,7 @@ developing over time"))
(max-slices (get-option gnc:pagename-display optname-slices)) (max-slices (get-option gnc:pagename-display optname-slices))
(height (get-option gnc:pagename-display optname-plot-height)) (height (get-option gnc:pagename-display optname-plot-height))
(width (get-option gnc:pagename-display optname-plot-width)) (width (get-option gnc:pagename-display optname-plot-width))
(sort-method (get-option gnc:pagename-display optname-sort-method))
(work-done 0) (work-done 0)
(work-to-do 0) (work-to-do 0)
@ -355,9 +362,23 @@ developing over time"))
(filter (lambda (l) (filter (lambda (l)
(not (= 0.0 (apply + (cadr l))))) (not (= 0.0 (apply + (cadr l)))))
(traverse-accounts 1 topl-accounts)) (traverse-accounts 1 topl-accounts))
(cond
((eq? sort-method 'acct-code)
(lambda (a b) (lambda (a b)
(string<? (gnc:account-get-code (car a)) (string<? (gnc:account-get-code (car a))
(gnc:account-get-code (car b)))))) (gnc:account-get-code (car b)))))
((eq? sort-method 'alphabetical)
(lambda (a b)
(string<? ((if show-fullname?
gnc:account-get-full-name
gnc:account-get-name) (car a))
((if show-fullname?
gnc:account-get-full-name
gnc:account-get-name) (car b)))))
(else
(lambda (a b)
(> (apply + (cadr a))
(apply + (cadr b))))))))
;; Or rather sort by total amount? ;; Or rather sort by total amount?
;;(< (apply + (cadr a)) ;;(< (apply + (cadr a))
;; (apply + (cadr b)))))) ;; (apply + (cadr b))))))
@ -394,7 +415,8 @@ developing over time"))
(gnc:html-barchart-set-row-labels-rotated?! chart #t) (gnc:html-barchart-set-row-labels-rotated?! chart #t)
(gnc:html-barchart-set-stacked?! chart stacked?) (gnc:html-barchart-set-stacked?! chart stacked?)
;; If this is a stacked barchart, then reverse the legend. ;; If this is a stacked barchart, then reverse the legend.
(gnc:html-barchart-set-legend-reversed?! chart stacked?) ;; Doesn't do what you'd expect. - DRH
;;(gnc:html-barchart-set-legend-reversed?! chart stacked?)
;; If we have too many categories, we sum them into a new ;; If we have too many categories, we sum them into a new
;; 'other' category and add a link to a new report with just ;; 'other' category and add a link to a new report with just
@ -436,11 +458,13 @@ developing over time"))
(gnc:report-percent-done 94) (gnc:report-percent-done 94)
(gnc:html-barchart-set-col-labels! (gnc:html-barchart-set-col-labels!
chart (map (lambda (pair) chart (map (lambda (pair)
(regexp-substitute/global #f "&"
(if (string? (car pair)) (if (string? (car pair))
(car pair) (car pair)
((if show-fullname? ((if show-fullname?
gnc:account-get-full-name gnc:account-get-full-name
gnc:account-get-name) (car pair)))) gnc:account-get-name) (car pair)))
'pre " " (_ "and") " " 'post))
all-data)) all-data))
(gnc:html-barchart-set-col-colors! (gnc:html-barchart-set-col-colors!
chart chart