gnucash maint: Revert to using numerical indexes for the x-axis on bar charts
Geert Janssens
gjanssens at code.gnucash.org
Tue Oct 21 11:14:54 EDT 2014
Updated via https://github.com/Gnucash/gnucash/commit/3b21aacb (commit)
from https://github.com/Gnucash/gnucash/commit/92fed5b8 (commit)
commit 3b21aacbc8476484f00a4558add9c198b0bdd306
Author: Geert Janssens <janssens-geert at telenet.be>
Date: Tue Oct 21 17:13:14 2014 +0200
Revert to using numerical indexes for the x-axis on bar charts
There is a bug in jqplot to prevents stacked charts from
rendering properly when using strings for x-axis categories:
https://bitbucket.org/cleonello/jqplot/issue/587/charts-disappear-by-enabling-stackseries
diff --git a/src/report/report-system/html-barchart.scm b/src/report/report-system/html-barchart.scm
index 60d4b92..0a04f62 100644
--- a/src/report/report-system/html-barchart.scm
+++ b/src/report/report-system/html-barchart.scm
@@ -359,12 +359,12 @@
(push "var d")
(push series-index)
(push " = [];\n")))
- (series-data-add (lambda (series-index date y)
+ (series-data-add (lambda (series-index x y)
(push (string-append
" d"
(number->string series-index)
".push(["
- "\"" date "\""
+ (number->string x)
", "
(number->string y)
"]);\n"))))
@@ -406,22 +406,22 @@
(if (and data (list? data))
(let ((rows (length data))
(cols 0))
- (let loop ((col 0) (rowcnt 0))
+ (let loop ((col 0) (rowcnt 1))
(series-data-start col)
(if (list? (car data))
(begin
(set! cols (length (car data)))))
(for-each
(lambda (row)
- (if (< rowcnt rows)
- (series-data-add col (list-ref (gnc:html-barchart-row-labels barchart) rowcnt)
+ (if (<= rowcnt rows)
+ (series-data-add col rowcnt
(ensure-numeric (list-ref-safe row col)))
)
(set! rowcnt (+ rowcnt 1)))
data)
(series-data-end col (list-ref-safe (gnc:html-barchart-col-labels barchart) col))
(if (< col (- cols 1))
- (loop (+ 1 col) 0)))))
+ (loop (+ 1 col) 1)))))
(push "var options = {
@@ -493,13 +493,25 @@
(push " options.axes.yaxis.label = \"")
(push y-label)
(push "\";\n")))
+ (if (and (string? row-labels) (> (string-length row-labels) 0))
+ (begin
+ (push " options.axes.xaxis.ticks = [")
+ (for-each (lambda (val)
+ (push "\"")
+ (push val)
+ (push "\","))
+ (gnc:html-barchart-row-labels barchart))
+ (push "];\n")))
(push "$.jqplot.config.enablePlugins = true;\n")
(push "var plot = $.jqplot('")(push chart-id)(push"', data, options);
function formatTooltip(str, seriesIndex, pointIndex) {
- x = data[seriesIndex][pointIndex][0];
+ if (options.axes.xaxis.ticks[pointIndex] !== undefined)
+ x = options.axes.xaxis.ticks[pointIndex];
+ else
+ x = pointIndex;
y = data[seriesIndex][pointIndex][1].toFixed(2);
return options.series[seriesIndex].label + '<br/>' + x + '<br/><b>' + y + '</b>';
}\n")
Summary of changes:
src/report/report-system/html-barchart.scm | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
More information about the gnucash-changes
mailing list