[Gnucash-changes] Add test-graphing.scm report to exercise graphing in a consistent,

Joshua Sled jsled at cvs.gnucash.org
Sat Feb 12 12:40:45 EST 2005


Log Message:
-----------
Add test-graphing.scm report to exercise graphing in a consistent, controlled way without a data-file.

Tags:
----
g2-gog-integ

Modified Files:
--------------
    gnucash/src/report/utility-reports:
        Makefile.am
        utility-reports.scm

Added Files:
-----------
    gnucash/src/report/utility-reports:
        test-graphing.scm

Revision Data
-------------
Index: utility-reports.scm
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/report/utility-reports/utility-reports.scm,v
retrieving revision 1.5
retrieving revision 1.5.6.1
diff -Lsrc/report/utility-reports/utility-reports.scm -Lsrc/report/utility-reports/utility-reports.scm -u -r1.5 -r1.5.6.1
--- src/report/utility-reports/utility-reports.scm
+++ src/report/utility-reports/utility-reports.scm
@@ -13,4 +13,6 @@
 (use-modules (gnucash report view-column))
 (use-modules (gnucash report welcome-to-gnucash))
 
+(use-modules (gnucash report test-graphing))
+
 (export gnc:make-welcome-report)
Index: Makefile.am
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/report/utility-reports/Makefile.am,v
retrieving revision 1.6.4.1
retrieving revision 1.6.4.1.2.1
diff -Lsrc/report/utility-reports/Makefile.am -Lsrc/report/utility-reports/Makefile.am -u -r1.6.4.1 -r1.6.4.1.2.1
--- src/report/utility-reports/Makefile.am
+++ src/report/utility-reports/Makefile.am
@@ -26,7 +26,8 @@
   iframe-url.scm \
   utility-reports.scm \
   view-column.scm \
-  welcome-to-gnucash.scm 
+  welcome-to-gnucash.scm \
+  test-graphing.scm
 
 EXTRA_DIST = ${gncscmmod_DATA}
 
--- /dev/null
+++ src/report/utility-reports/test-graphing.scm
@@ -0,0 +1,127 @@
+;; -*-scheme-*-
+
+;; This is a sample guile report generator for GnuCash.
+;; It illustrates the basic techniques used to create
+;; new reports for GnuCash.
+
+(define-module (gnucash report test-graphing))
+(use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing.
+(use-modules (gnucash gnc-module))
+
+(debug-enable 'debug)
+(debug-enable 'backtrace)
+
+(gnc:module-load "gnucash/report/report-system" 0)
+(gnc:module-load "gnucash/gnome-utils" 0) ;for gnc:html-build-url
+
+(define (simple-pie-chart)
+  (let ((chart (gnc:make-html-piechart)))
+    (gnc:html-piechart-set-title! chart "Pie Chart Title")
+    (gnc:html-piechart-set-subtitle! chart "Pie Chart SubTitle")
+    (gnc:html-piechart-set-width! chart "640")
+    (gnc:html-piechart-set-height! chart "480")
+    ;; (gnc:html-piechart-set-data! chart (unzip1 combined))
+    (gnc:html-piechart-set-data! chart '("25" "45" "30"))
+    ;; (gnc:html-piechart-set-labels! chart legend-labels))
+    (gnc:html-piechart-set-labels! chart '("foo" "bar" "baz"))
+    (gnc:html-piechart-set-colors! chart (gnc:assign-colors 3))
+    chart
+    )
+)
+
+(define (ultra-simple-pie-chart)
+  (gnc:make-html-text (gnc:html-markup-p "[pie goes here]"))
+)
+
+(define (simple-bar-chart)
+  (gnc:make-html-text (gnc:html-markup-p "[bar goes here]"))
+)
+
+(define (simple-scatter-chart)
+  (gnc:make-html-text (gnc:html-markup-p "[scatter goes here]"))
+)
+
+(define (options-generator)    
+  (let* ((options (gnc:new-options)))
+    (gnc:options-set-default-section options "Test Graphing")
+    options)
+  )
+
+;; This is the rendering function. It accepts a database of options
+;; and generates an object of type <html-document>.  See the file
+;; report-html.txt for documentation; the file report-html.scm
+;; includes all the relevant Scheme code. The option database passed
+;; to the function is one created by the options-generator function
+;; defined above.
+(define (test-graphing-renderer report-obj)
+  ;; These are some helper functions for looking up option values.
+  (define (get-op section name)
+    (gnc:lookup-option (gnc:report-options report-obj) section name))
+  
+  (define (op-value section name)
+    (gnc:option-value (get-op section name)))
+
+  (let ((document (gnc:make-html-document)))
+
+    (gnc:html-document-set-title! document (_ "Graphs"))
+
+    (gnc:html-document-add-object!
+     document
+     (gnc:make-html-text
+      (gnc:html-markup-p
+       (gnc:html-markup/format
+        (_ "Sample graphs:")))))
+
+    (gnc:html-document-add-object!
+     document
+     (gnc:make-html-text (gnc:html-markup-p "Pie:")))
+    (gnc:html-document-add-object! document (simple-pie-chart))
+
+    (gnc:html-document-add-object!
+     document
+     (gnc:make-html-text (gnc:html-markup-p "Bar:")))
+    (gnc:html-document-add-object! document (simple-bar-chart))
+
+    (gnc:html-document-add-object!
+     document
+     (gnc:make-html-text (gnc:html-markup-p "Scatter:")))
+    (gnc:html-document-add-object! document (simple-scatter-chart))
+    
+    (gnc:html-document-add-object! 
+     document 
+     (gnc:make-html-text 
+      (gnc:html-markup-p (_ "Done."))))
+      
+    document
+    )
+  )
+
+;; Here we define the actual report with gnc:define-report
+(gnc:define-report
+ 
+ ;; The version of this report.
+ 'version 1
+ 
+ ;; The name of this report. This will be used, among other things,
+ ;; for making its menu item in the main menu. You need to use the
+ ;; untranslated value here!
+ 'name (N_ "Test Graphing")
+
+ ;; The name in the menu
+ ;; (only necessary if it differs from the name)
+ 'menu-name (N_ "Sample graphs.")
+
+ ;; A tip that is used to provide additional information about the
+ ;; report to the user.
+ 'menu-tip (N_ "Sample graphs.")
+
+ ;; A path describing where to put the report in the menu system.
+ ;; In this case, it's going under the utility menu.
+ 'menu-path (list gnc:menuname-utility)
+
+ ;; The options generator function defined above.
+ 'options-generator options-generator
+ ;; 'options-generator gnc:new-options
+ 
+ ;; The rendering function defined above.
+ 'renderer test-graphing-renderer)


More information about the gnucash-changes mailing list