I need to have a custom tooltip displayed when a user hovers over a square in a treemap and I use this article as the basis.
The treemap must be built with R and googleVis library using a gvisTreeMap()
function. According to the mentioned article, I created a parameter generateTooltip
in the list of options of the function and assigned it with a code for creating an anonymous function. Here is a completed code for a gvisTreeMap()
invocation:
plot(gvisTreeMap(Data,
idvar="Name.of.the.Company",
parentvar="Name.of.the.Parent",
sizevar="Loan.Size..INR.in.million.",
options=list(width='*',
height=600,
minColorValue=0,
maxColorValue=0,
generateTooltip = "function(row, size, value) {
return '<div style=\"background:#fd9; padding:10px; border-style:solid\">' + 'Some text' + '</div>';
}"
)))
The resulting JS code in my HTML-page looks like this:
// jsDrawChart
...
var options = {};
options["height"] = 600;
options["minColorValue"] = 0;
options["maxColorValue"] = 0;
options["generateTooltip"] = "function(row, size, value) { return '<div style=\"background:#fd9; padding:10px; border-style:solid\">' + 'Some text' + '</div>'; }";
Here options["generateTooltip"]
is initialized with a string which causes an error (while I expected that the string would be automatically recognized as a function definition). So, I'd like to know are there ways to pass the function definition from R environment to the generateTooltip
property?