Skip to content

Commit

Permalink
report: render barchart with requested bar colors
Browse files Browse the repository at this point in the history
A report can specify the bar colors of a barchart with a call to:
   (gnc:html-barchart-set-col-colors! chart (list "blue" "red"))
However, these colors were ignored when rendering the barchart.

This patch adds the jqplot option "seriesColors" to pass
the requested bar colors to jqplot. If no colors are requested,
we let jqplot use default colors by setting "seriesColors: false".
  • Loading branch information
jmarino committed Oct 12, 2017
1 parent 9472e93 commit 3926535
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions gnucash/report/report-system/html-barchart.scm
Expand Up @@ -353,8 +353,10 @@
(gnc:html-barchart-row-labels barchart)))
(col-labels (catenate-escaped-strings
(gnc:html-barchart-col-labels barchart)))
(col-colors (catenate-escaped-strings
(gnc:html-barchart-col-colors barchart)))
;; convert color list to string with valid js array of strings, example: "\"blue\", \"red\""
(colors-str (string-join (map (lambda (color)
(string-append "\"" color "\""))
(gnc:html-barchart-col-colors barchart)) ", "))
(series-data-start (lambda (series-index)
(push "var d")
(push series-index)
Expand Down Expand Up @@ -476,6 +478,7 @@
showTooltip: false,
zoom: true,
},
seriesColors: false,
};\n")

(push " options.stackSeries = ")
Expand Down Expand Up @@ -506,6 +509,13 @@
(push y-label)
(push "\";\n")))
(push " options.axes.xaxis.ticks = all_ticks;\n")
(if (not (equal? colors-str ""))
(begin ; example: options.seriesColors= ["blue", "red"];
(push "options.seriesColors = [")
(push colors-str)
(push "];\n")
)
)


(push "$.jqplot.config.enablePlugins = true;\n")
Expand Down

0 comments on commit 3926535

Please sign in to comment.