GnuCash
Contact   Instructions
Bug 798154 - Tooltips wrong when multiple charts in one report
Summary: Tooltips wrong when multiple charts in one report
Status: RESOLVED FIXED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: Reports (show other bugs)
Version: 4.4
Hardware: PC Linux
: Normal normal
Target Milestone: ---
Assignee: reports
QA Contact: reports
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-23 13:42 EDT by dries.hoet+bugzilla
Modified: 2021-03-31 06:16 EDT (History)
3 users (show)

See Also:


Attachments

Description dries.hoet+bugzilla 2021-03-23 13:42:51 EDT
Due to a bug in the generated JavaScript code, tooltips get messed up if multiple graphs are displayed in one report (also in multi-column reports). Concretely, it always shows the tooltips of the last graphs on the page.

The offending code is in the tooltipTitle method: https://github.com/Gnucash/gnucash/blob/maint/gnucash/report/html-chart.scm#L360

Instead of using the globally defined variable 'chartjsoptions', it should use the argument 'data', i.e.

return chartjsoptions.data.labels[array[0].index]; }

should become

return data.labels[array[0].index]; }
Comment 1 Christopher Lam 2021-03-23 18:59:50 EDT
Nice bug report :) This is now committed in 7c323b22 and will be in 4.5 due soon! There's also use global chartjsoptions in xAxisDisplay which may be similarly wrong.

Maybe the following is an appropriate fix?

modified   gnucash/report/html-chart.scm
@@ -462,7 +462,7 @@ document.getElementById(chartid).onclick = function(evt) {
       (push "function yAxisDisplay(value,index,values) { return numformat(value); };\n"))
     (when (gnc:html-chart-custom-x-axis-ticks? chart)
       (push "chartjsoptions.options.scales.xAxes[0].ticks.callback = xAxisDisplay;\n")
-      (push "function xAxisDisplay(value,index,values) { return chartjsoptions.data.labels[index]; };\n"))
+      (push "function xAxisDisplay(value,index,values) { return value; };\n"))
 
     (push "chartjsoptions.options.tooltips.callbacks.label = tooltipLabel;\n")
     (push "chartjsoptions.options.tooltips.callbacks.title = tooltipTitle;\n")
Comment 2 dries.hoet+bugzilla 2021-03-30 15:58:39 EDT
I tried reproducing the problem with the xAxisDisplay method, but I couldn't. Although I have multiple graphs on my report, and I switched custom-x-axis-ticks on (it seems to be always on, even when I don't set it?), the x-axis labels were always correct.

I'm not sure why -- maybe the xAxisDisplay method is only called from within the "new Chart(...)" call? In that case, the JavaScript for following graphs would not yet been interpreted and there would be no conflict of the chartjsoptions variable.

I am a bit puzzled about the whole 'html-chart-custom-x-axis-ticks'-feature though. It seems as it does not do a lot? If I understand the chartjs library correctly, it takes its labels from the "options.data.labels" list anyways, so setting a callback for the x-axis ticks that does exactly that seems to be unneeded. It worked for me too when I dropped the whole 'when' block.

I also tested with your fix applied, which also worked fine in my case.
Comment 3 Christopher Lam 2021-03-31 06:16:41 EDT
(In reply to dries.hoet+bugzilla from comment #2)
> I tried reproducing the problem with the xAxisDisplay method, but I
> couldn't. Although I have multiple graphs on my report, and I switched
> custom-x-axis-ticks on (it seems to be always on, even when I don't set
> it?), the x-axis labels were always correct.
> 
> I'm not sure why -- maybe the xAxisDisplay method is only called from within
> the "new Chart(...)" call? In that case, the JavaScript for following graphs
> would not yet been interpreted and there would be no conflict of the
> chartjsoptions variable.
> 
> I am a bit puzzled about the whole 'html-chart-custom-x-axis-ticks'-feature
> though. It seems as it does not do a lot? If I understand the chartjs
> library correctly, it takes its labels from the "options.data.labels" list
> anyways, so setting a callback for the x-axis ticks that does exactly that
> seems to be unneeded. It worked for me too when I dropped the whole 'when'
> block.

Thank you for testing; tou're probably right. The custom-y-axis-ticks is useful to label yAxes with monetary eg USD 100,000; the custom-x-axis-ticks is used only for the price-scatter but seems to not matter at all.

To remove it may cause unwanted side effects so I'm inclined to leave it untouched.

Note You need to log in before you can comment on or make changes to this bug.