Skip to content

Commit

Permalink
[html-chart] bugfix: lists were incorrectly converted to vector
Browse files Browse the repository at this point in the history
thereby setting and getting a list of pairs would mangle the path's cdr
  • Loading branch information
christopherlam committed Sep 3, 2024
1 parent dc84e4d commit 4e32844
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gnucash/report/html-chart.scm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
(use-modules (gnucash core-utils))
(use-modules (gnucash json builder)) ;for building JSON options
(use-modules (gnucash report html-utilities))
(use-modules (gnucash report report-utilities))
(use-modules (srfi srfi-9))
(use-modules (ice-9 match))

Expand Down Expand Up @@ -274,10 +275,10 @@
(gnc:html-chart-get chart '(options title text)))

(define (gnc:html-chart-set-title! chart title)
(gnc:html-chart-set! chart '(options title text) title))
(gnc:html-chart-set! chart '(options title text) (list-to-vec title)))

(define (gnc:html-chart-set-data-labels! chart labels)
(gnc:html-chart-set! chart '(data labels) labels))
(gnc:html-chart-set! chart '(data labels) (list-to-vec labels)))

(define (gnc:html-chart-set-axes-display! chart display?)
(gnc:html-chart-set! chart '(options scales xAxes (0) display) display?)
Expand Down Expand Up @@ -337,9 +338,8 @@
(nested-alist-get options path)))

(define (gnc:html-chart-set! chart path val)
(let ((options (gnc:html-chart-get-options-internal chart))
(val-vec (list-to-vec val)))
(nested-alist-set! options path val-vec)
(let ((options (gnc:html-chart-get-options-internal chart)))
(nested-alist-set! options path val)
(gnc:html-chart-set-options-internal! chart options)))

(define JS-Number-to-String "
Expand Down
13 changes: 13 additions & 0 deletions gnucash/report/test/test-html-chart.scm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@
'abc
(gnc:html-chart-get chart '(options maintainAspectRatio)))

(test-equal "path doesn't exist"
#f
(gnc:html-chart-get chart '(options scales xAxes (0) time)))

(define a-list-of-pairs
'((unit . day) (displayFormats (day . "DD-MM-YYYY")) (tooltipFormat . "DD-MM-YYYY")))

(gnc:html-chart-set! chart '(options scales xAxes (0) time) a-list-of-pairs)

(test-equal "path exists and the list-of-pairs is intact"
a-list-of-pairs
(gnc:html-chart-get chart '(options scales xAxes (0) time)))

(gnc:html-chart-set! chart '(options legend position) 'de)
(test-equal "1st level option setter & getter"
'de
Expand Down

0 comments on commit 4e32844

Please sign in to comment.