diff --git a/src/gnome/gnc-html-guppi.c b/src/gnome/gnc-html-guppi.c
index c108d2cb94..566fab75b4 100644
--- a/src/gnome/gnc-html-guppi.c
+++ b/src/gnome/gnc-html-guppi.c
@@ -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;
diff --git a/src/scm/html-barchart.scm b/src/scm/html-barchart.scm
index 7547f4b5f8..a3a19bf6ce 100644
--- a/src/scm/html-barchart.scm
+++ b/src/scm/html-barchart.scm
@@ -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 " \n"))
- " ")
+ (begin
+ (gnc:warn "barchart has no non-zero data.")
+ " "))
retval))
diff --git a/src/scm/html-piechart.scm b/src/scm/html-piechart.scm
index 4f37acd0ac..068ecc6103 100644
--- a/src/scm/html-piechart.scm
+++ b/src/scm/html-piechart.scm
@@ -259,7 +259,8 @@
(push "\">\n")))
(push "Unable to display pie chart\n")
(push " \n"))
- " ")
+ (begin (gnc:warn "null-data, not rendering piechart")
+ " "))
retval))
diff --git a/src/scm/html-utilities.scm b/src/scm/html-utilities.scm
index 287affbcce..3047501ece 100644
--- a/src/scm/html-utilities.scm
+++ b/src/scm/html-utilities.scm
@@ -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))
\ No newline at end of file
diff --git a/src/scm/report/category-barchart.scm b/src/scm/report/category-barchart.scm
index 91f0cd61d0..00c8498f3d 100644
--- a/src/scm/report/category-barchart.scm
+++ b/src/scm/report/category-barchart.scm
@@ -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
diff --git a/src/scm/report/net-barchart.scm b/src/scm/report/net-barchart.scm
index 531eaf796c..72eea6d9c3 100644
--- a/src/scm/report/net-barchart.scm
+++ b/src/scm/report/net-barchart.scm
@@ -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 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") '())))
+ (if
+ (not (null? accounts))
+ (begin
+
+ (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