mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fixes for empty barcharts.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4136 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include "gnc-html-guppi.h"
|
||||
#include "gnc-ui-util.h"
|
||||
|
||||
static short module = MOD_GUI;
|
||||
|
||||
static int handle_piechart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d);
|
||||
static int handle_barchart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d);
|
||||
@@ -196,6 +197,31 @@ free_strings(char ** strings, int nstrings) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* if at least one is non-zero, return TRUE
|
||||
* ie TRUE==good
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
check_doubles(double *numbers, int size)
|
||||
{
|
||||
int count;
|
||||
|
||||
for(count = 0;count < size; count++)
|
||||
{
|
||||
/* FIXME: floating point equalities are strictly evil but
|
||||
* it shouldn't catch us here
|
||||
*/
|
||||
if(numbers[count] != 0.0)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
struct guppi_chart_data {
|
||||
GtkWidget * widget;
|
||||
GuppiObject * guppiobject;
|
||||
|
||||
@@ -228,6 +228,17 @@
|
||||
(set! rownum (+ 1 rownum)))
|
||||
newcol)))
|
||||
|
||||
(define (gnc:not-all-zeros data)
|
||||
(define (myor list)
|
||||
(begin
|
||||
(gnc:debug "list" list)
|
||||
(if (null? list) #f
|
||||
(or (car list) (myor (cdr list))))))
|
||||
|
||||
(cond ((number? data) (not (= 0 data)))
|
||||
((list? data) (myor (map gnc:not-all-zeros data)))
|
||||
(else #f)))
|
||||
|
||||
(define (gnc:html-barchart-prepend-column! barchart newcol)
|
||||
(let ((rows (gnc:html-barchart-data barchart))
|
||||
(this-row #f)
|
||||
@@ -309,6 +320,7 @@
|
||||
(x-label (gnc:html-barchart-x-axis-label barchart))
|
||||
(y-label (gnc:html-barchart-y-axis-label barchart))
|
||||
(data (gnc:html-barchart-data barchart))
|
||||
(dummy1 (gnc:debug "data " data))
|
||||
(row-labels (catenate-escaped-strings
|
||||
(gnc:html-barchart-row-labels barchart)))
|
||||
(col-labels (catenate-escaped-strings
|
||||
@@ -316,7 +328,8 @@
|
||||
(col-colors (catenate-escaped-strings
|
||||
(gnc:html-barchart-col-colors barchart))))
|
||||
(if (and (list? data)
|
||||
(not (null? data)))
|
||||
(not (null? data))
|
||||
(gnc:not-all-zeros data))
|
||||
(begin
|
||||
(push "<object classid=\"gnc-guppi-bar\" width=")
|
||||
(push (gnc:html-barchart-width barchart))
|
||||
@@ -421,5 +434,7 @@
|
||||
"0\">\n"))
|
||||
(push "Unable to push bar chart\n")
|
||||
(push "</object> \n"))
|
||||
" ")
|
||||
(begin
|
||||
(gnc:warn "barchart has no non-zero data.")
|
||||
" "))
|
||||
retval))
|
||||
|
||||
@@ -259,7 +259,8 @@
|
||||
(push "\">\n")))
|
||||
(push "Unable to display pie chart\n")
|
||||
(push "</object> \n"))
|
||||
" ")
|
||||
(begin (gnc:warn "null-data, not rendering piechart")
|
||||
" "))
|
||||
retval))
|
||||
|
||||
|
||||
|
||||
@@ -661,4 +661,13 @@
|
||||
(gnc:html-markup-h2 (_ "No accounts selected"))
|
||||
(gnc:html-markup-p
|
||||
(_ "This report requires accounts to be selected.")))
|
||||
p))
|
||||
|
||||
(define (gnc:html-make-empty-data-warning)
|
||||
(let ((p (gnc:make-html-text)))
|
||||
(gnc:html-text-append!
|
||||
p
|
||||
(gnc:html-markup-h2 (_ "No data"))
|
||||
(gnc:html-markup-p
|
||||
(_ "The selected accounts contain no data for the selected time period")))
|
||||
p))
|
||||
@@ -314,67 +314,72 @@ developing over time"))
|
||||
;; choose sorting.
|
||||
|
||||
|
||||
;;(warn "all-data" all-data)
|
||||
(gnc:warn "all-data" all-data)
|
||||
|
||||
;; Set chart title, subtitle etc.
|
||||
(gnc:html-barchart-set-title! chart report-title)
|
||||
(gnc:html-barchart-set-subtitle!
|
||||
chart (sprintf #f
|
||||
(if do-intervals?
|
||||
(_ "%s to %s")
|
||||
(_ "Balances %s to %s"))
|
||||
(gnc:timepair-to-datestring from-date-tp)
|
||||
(gnc:timepair-to-datestring to-date-tp)))
|
||||
(gnc:html-barchart-set-width! chart width)
|
||||
(gnc:html-barchart-set-height! chart height)
|
||||
(let ((all-data-amounts (map cadr all-data)))
|
||||
(if
|
||||
(and (not (null? all-data-amounts))
|
||||
(gnc:not-all-zeros all-data-amounts))
|
||||
;; Set chart title, subtitle etc.
|
||||
(begin
|
||||
(gnc:html-barchart-set-title! chart report-title)
|
||||
(gnc:html-barchart-set-subtitle!
|
||||
chart (sprintf #f
|
||||
(if do-intervals?
|
||||
(_ "%s to %s")
|
||||
(_ "Balances %s to %s"))
|
||||
(gnc:timepair-to-datestring from-date-tp)
|
||||
(gnc:timepair-to-datestring to-date-tp)))
|
||||
(gnc:html-barchart-set-width! chart width)
|
||||
(gnc:html-barchart-set-height! chart height)
|
||||
|
||||
;; row labels etc.
|
||||
(gnc:html-barchart-set-row-labels! chart date-string-list)
|
||||
;; FIXME: why doesn't the y-axis label get printed?!?
|
||||
(gnc:html-barchart-set-y-axis-label!
|
||||
chart (gnc:commodity-get-mnemonic report-currency))
|
||||
(gnc:html-barchart-set-row-labels-rotated?! chart #t)
|
||||
(gnc:html-barchart-set-stacked?! chart stacked?)
|
||||
;; If this is a stacked barchart, then reverse the legend.
|
||||
(gnc:html-barchart-set-legend-reversed?! chart stacked?)
|
||||
|
||||
;; If we have too many categories, we sum them into a new
|
||||
;; 'other' category and add a link to a new report with just
|
||||
;; those accounts.
|
||||
(if (> (length all-data) max-slices)
|
||||
(let* ((start (take all-data (- max-slices 1)))
|
||||
(finish (drop all-data (- max-slices 1)))
|
||||
(other-sum (map
|
||||
(lambda (l) (apply + l))
|
||||
(apply zip (map cadr finish)))))
|
||||
(set! all-data
|
||||
(append start
|
||||
(list (list (_ "Other") other-sum))))
|
||||
(let* ((options (gnc:make-report-options reportname))
|
||||
(id #f))
|
||||
;; now copy all the options
|
||||
(gnc:options-copy-values
|
||||
(gnc:report-options report-obj) options)
|
||||
;; and set the destination accounts
|
||||
(gnc:option-set-value
|
||||
(gnc:lookup-option options gnc:pagename-accounts
|
||||
optname-accounts)
|
||||
(map car finish))
|
||||
;; Set the URL to point to this report.
|
||||
(set! id (gnc:make-report reportname options))
|
||||
(gnc:report-add-child-by-id! report-obj id)
|
||||
(gnc:report-set-parent! (gnc:find-report id) report-obj)
|
||||
(set! other-anchor (gnc:report-anchor-text id)))))
|
||||
|
||||
|
||||
;; This adds the data. Note the apply-zip stuff: This
|
||||
;; transposes the data, i.e. swaps rows and columns. Pretty
|
||||
;; cool, eh? Courtesy of dave_p.
|
||||
(if (not (null? all-data))
|
||||
(gnc:html-barchart-set-data! chart
|
||||
(apply zip all-data-amounts)))
|
||||
|
||||
;; row labels etc.
|
||||
(gnc:html-barchart-set-row-labels! chart date-string-list)
|
||||
;; FIXME: why doesn't the y-axis label get printed?!?
|
||||
(gnc:html-barchart-set-y-axis-label!
|
||||
chart (gnc:commodity-get-mnemonic report-currency))
|
||||
(gnc:html-barchart-set-row-labels-rotated?! chart #t)
|
||||
(gnc:html-barchart-set-stacked?! chart stacked?)
|
||||
;; If this is a stacked barchart, then reverse the legend.
|
||||
(gnc:html-barchart-set-legend-reversed?! chart stacked?)
|
||||
|
||||
;; If we have too many categories, we sum them into a new
|
||||
;; 'other' category and add a link to a new report with just
|
||||
;; those accounts.
|
||||
(if (> (length all-data) max-slices)
|
||||
(let* ((start (take all-data (- max-slices 1)))
|
||||
(finish (drop all-data (- max-slices 1)))
|
||||
(other-sum (map
|
||||
(lambda (l) (apply + l))
|
||||
(apply zip (map cadr finish)))))
|
||||
(set! all-data
|
||||
(append start
|
||||
(list (list (_ "Other") other-sum))))
|
||||
(let* ((options (gnc:make-report-options reportname))
|
||||
(id #f))
|
||||
;; now copy all the options
|
||||
(gnc:options-copy-values
|
||||
(gnc:report-options report-obj) options)
|
||||
;; and set the destination accounts
|
||||
(gnc:option-set-value
|
||||
(gnc:lookup-option options gnc:pagename-accounts
|
||||
optname-accounts)
|
||||
(map car finish))
|
||||
;; Set the URL to point to this report.
|
||||
(set! id (gnc:make-report reportname options))
|
||||
(gnc:report-add-child-by-id! report-obj id)
|
||||
(gnc:report-set-parent! (gnc:find-report id) report-obj)
|
||||
(set! other-anchor (gnc:report-anchor-text id)))))
|
||||
|
||||
|
||||
;; This adds the data. Note the apply-zip stuff: This
|
||||
;; transposes the data, i.e. swaps rows and columns. Pretty
|
||||
;; cool, eh? Courtesy of dave_p.
|
||||
(if (not (null? all-data))
|
||||
(gnc:html-barchart-set-data! chart
|
||||
(apply zip (map cadr all-data))))
|
||||
|
||||
;; Labels and colors
|
||||
;; Labels and colors
|
||||
(gnc:html-barchart-set-col-labels!
|
||||
chart (map (lambda (pair)
|
||||
(if (string? (car pair))
|
||||
@@ -443,14 +448,19 @@ if that account doesn't have subaccounts, the register for the account.")
|
||||
(gnc:html-markup-p "Remove this text by disabling \
|
||||
the global Preference \"Display Tip of the Day\".")))))
|
||||
|
||||
;; else if empty data
|
||||
(gnc:html-document-add-object!
|
||||
document
|
||||
(gnc:html-make-empty-data-warning)))))
|
||||
|
||||
;; else if no accounts selected
|
||||
(gnc:html-document-add-object!
|
||||
document
|
||||
(gnc:html-make-no-account-warning)))
|
||||
|
||||
|
||||
document))
|
||||
|
||||
|
||||
|
||||
document))
|
||||
|
||||
(for-each
|
||||
(lambda (l)
|
||||
(gnc:define-report
|
||||
|
||||
@@ -236,103 +236,122 @@
|
||||
(gnc:timepair-to-datestring
|
||||
(car date-list-item)))
|
||||
gnc:timepair-to-datestring)
|
||||
dates-list)))
|
||||
dates-list))
|
||||
(non-zeros #f))
|
||||
(define (add-column! data-list)
|
||||
(begin
|
||||
(gnc:html-barchart-append-column! chart data-list)
|
||||
(if (gnc:not-all-zeros data-list) (set! non-zeros #t))
|
||||
#f))
|
||||
|
||||
(gnc:html-barchart-set-title!
|
||||
chart (if inc-exp? (_ "Income/Expense Chart")
|
||||
(_ "Net Worth Chart")))
|
||||
(gnc:html-barchart-set-subtitle!
|
||||
chart (sprintf #f
|
||||
(_ "%s to %s")
|
||||
(gnc:timepair-to-datestring from-date-tp)
|
||||
(gnc:timepair-to-datestring to-date-tp)))
|
||||
(gnc:html-barchart-set-width! chart width)
|
||||
(gnc:html-barchart-set-height! chart height)
|
||||
(gnc:html-barchart-set-row-labels! chart date-string-list)
|
||||
(gnc:html-barchart-set-y-axis-label!
|
||||
chart (gnc:commodity-get-mnemonic report-currency))
|
||||
;; Determine whether we have enough space for horizontal labels
|
||||
;; -- kind of a hack. Assumptions: y-axis labels and legend
|
||||
;; require 200 pixels, and each x-axes label needs 60 pixels.
|
||||
(gnc:html-barchart-set-row-labels-rotated?!
|
||||
chart (< (/ (- width 200)
|
||||
(length date-string-list)) 60))
|
||||
(if
|
||||
(not (null? accounts))
|
||||
(begin
|
||||
|
||||
(if show-sep?
|
||||
(begin
|
||||
(gnc:html-barchart-append-column! chart assets-list)
|
||||
(gnc:html-barchart-append-column! chart
|
||||
;;(if inc-exp?
|
||||
(map - liability-list)
|
||||
;;liability-list)
|
||||
)))
|
||||
(if show-net?
|
||||
(gnc:html-barchart-append-column!
|
||||
chart net-list))
|
||||
(gnc:html-barchart-set-col-labels!
|
||||
chart (append
|
||||
(if show-sep?
|
||||
(if inc-exp?
|
||||
(list (_ "Income") (_ "Expense"))
|
||||
(list (_ "Assets") (_ "Liabilities")))
|
||||
'())
|
||||
(if show-net?
|
||||
(if inc-exp?
|
||||
(list (_ "Net Profit"))
|
||||
(list (_ "Net Worth")))
|
||||
'())))
|
||||
(gnc:html-barchart-set-col-colors!
|
||||
chart (append
|
||||
(if show-sep?
|
||||
'("blue" "red") '())
|
||||
(if show-net?
|
||||
'("green") '())))
|
||||
(gnc:html-barchart-set-title!
|
||||
chart (if inc-exp? (_ "Income/Expense Chart")
|
||||
(_ "Net Worth Chart")))
|
||||
(gnc:html-barchart-set-subtitle!
|
||||
chart (sprintf #f
|
||||
(_ "%s to %s")
|
||||
(gnc:timepair-to-datestring from-date-tp)
|
||||
(gnc:timepair-to-datestring to-date-tp)))
|
||||
(gnc:html-barchart-set-width! chart width)
|
||||
(gnc:html-barchart-set-height! chart height)
|
||||
(gnc:html-barchart-set-row-labels! chart date-string-list)
|
||||
(gnc:html-barchart-set-y-axis-label!
|
||||
chart (gnc:commodity-get-mnemonic report-currency))
|
||||
;; Determine whether we have enough space for horizontal labels
|
||||
;; -- kind of a hack. Assumptions: y-axis labels and legend
|
||||
;; require 200 pixels, and each x-axes label needs 60 pixels.
|
||||
(gnc:html-barchart-set-row-labels-rotated?!
|
||||
chart (< (/ (- width 200)
|
||||
(length date-string-list)) 60))
|
||||
|
||||
(if show-sep?
|
||||
(begin
|
||||
(add-column! assets-list)
|
||||
(add-column! ;;(if inc-exp?
|
||||
(map - liability-list)
|
||||
;;liability-list)
|
||||
)))
|
||||
(if show-net?
|
||||
(add-column! net-list))
|
||||
(gnc:html-barchart-set-col-labels!
|
||||
chart (append
|
||||
(if show-sep?
|
||||
(if inc-exp?
|
||||
(list (_ "Income") (_ "Expense"))
|
||||
(list (_ "Assets") (_ "Liabilities")))
|
||||
'())
|
||||
(if show-net?
|
||||
(if inc-exp?
|
||||
(list (_ "Net Profit"))
|
||||
(list (_ "Net Worth")))
|
||||
'())))
|
||||
(gnc:html-barchart-set-col-colors!
|
||||
chart (append
|
||||
(if show-sep?
|
||||
'("blue" "red") '())
|
||||
(if show-net?
|
||||
'("green") '())))
|
||||
|
||||
(if show-sep?
|
||||
(let ((urls
|
||||
(list
|
||||
(gnc:make-report-anchor
|
||||
(if inc-exp?
|
||||
"Income Over Time"
|
||||
"Assets Over Time")
|
||||
report-obj
|
||||
(list
|
||||
(list gnc:pagename-display
|
||||
"Use Stacked Bars" #t)
|
||||
(list gnc:pagename-general
|
||||
gnc:optname-reportname
|
||||
(if inc-exp?
|
||||
(_ "Income Chart")
|
||||
(_ "Asset Chart")))))
|
||||
(gnc:make-report-anchor
|
||||
(if inc-exp?
|
||||
"Expense Over Time"
|
||||
"Liabilities Over Time")
|
||||
report-obj
|
||||
(list
|
||||
(list gnc:pagename-display
|
||||
"Use Stacked Bars" #t)
|
||||
(list gnc:pagename-general
|
||||
gnc:optname-reportname
|
||||
(if inc-exp?
|
||||
(_ "Expense Chart")
|
||||
(_ "Liability Chart"))))))))
|
||||
(gnc:html-barchart-set-button-1-bar-urls!
|
||||
chart urls)
|
||||
(gnc:html-barchart-set-button-1-legend-urls!
|
||||
chart urls)))
|
||||
|
||||
(if non-zeros
|
||||
(gnc:html-document-add-object! document chart)
|
||||
(gnc:html-document-add-object!
|
||||
document
|
||||
(gnc:html-make-empty-data-warning))))
|
||||
|
||||
;; else no accounts selected
|
||||
|
||||
(gnc:html-document-add-object!
|
||||
document
|
||||
(gnc:html-make-no-account-warning)))
|
||||
|
||||
|
||||
document))
|
||||
|
||||
(if show-sep?
|
||||
(let ((urls
|
||||
(list
|
||||
(gnc:make-report-anchor
|
||||
(if inc-exp?
|
||||
"Income Over Time"
|
||||
"Assets Over Time")
|
||||
report-obj
|
||||
(list
|
||||
(list gnc:pagename-display
|
||||
"Use Stacked Bars" #t)
|
||||
(list gnc:pagename-general
|
||||
gnc:optname-reportname
|
||||
(if inc-exp?
|
||||
(_ "Income Chart")
|
||||
(_ "Asset Chart")))))
|
||||
(gnc:make-report-anchor
|
||||
(if inc-exp?
|
||||
"Expense Over Time"
|
||||
"Liabilities Over Time")
|
||||
report-obj
|
||||
(list
|
||||
(list gnc:pagename-display
|
||||
"Use Stacked Bars" #t)
|
||||
(list gnc:pagename-general
|
||||
gnc:optname-reportname
|
||||
(if inc-exp?
|
||||
(_ "Expense Chart")
|
||||
(_ "Liability Chart"))))))))
|
||||
(gnc:html-barchart-set-button-1-bar-urls!
|
||||
chart urls)
|
||||
(gnc:html-barchart-set-button-1-legend-urls!
|
||||
chart urls)))
|
||||
|
||||
(gnc:html-document-add-object! document chart)
|
||||
|
||||
document))
|
||||
|
||||
;; Here we define the actual report
|
||||
(gnc:define-report
|
||||
'version 1
|
||||
'name (N_ "Net Worth Barchart")
|
||||
'menu-path (list gnc:menuname-asset-liability)
|
||||
'options-generator (lambda () (options-generator #f))
|
||||
'renderer (lambda (report-obj) (net-renderer report-obj #f)))
|
||||
;; Here we define the actual report
|
||||
(gnc:define-report
|
||||
'version 1
|
||||
'name (N_ "Net Worth Barchart")
|
||||
'menu-path (list gnc:menuname-asset-liability)
|
||||
'options-generator (lambda () (options-generator #f))
|
||||
'renderer (lambda (report-obj) (net-renderer report-obj #f)))
|
||||
|
||||
(gnc:define-report
|
||||
'version 1
|
||||
|
||||
Reference in New Issue
Block a user