I'm having issues customizing the tooltip for sparkline line graphs using the sparkline wrapper for R.
ATTEMPT #1:
While I was having some success customizing the tooltip for bar charts via the following link:
https://github.com/htmlwidgets/sparkline/issues/14
The tooltipformatter stops appearing when I specify the "line" for the chart type (tooltip doesn't even get created). I believe it has to do with the fact that sparkline will only accept "color", "fillColor", "x", "y", and "isNull" as parameters (see jquery link below) and I then began to realize the "offset" doesn't work with this specific type of sparkline.
https://omnipotent.net/jquery.sparkline/#tooltips
ATTEMPT #2: I then began to look at ways to construct string representations of the javascript that I then feed into a datatable render function:
spark3 <- sparkline::spk_chr(value=as.character(tst$monthly_trend),
xvalues = 1:length(tst$monthly_trend),
tooltipFormat = paste0('<b>Months After ', min_year_mon,': {{x:levels}}</b> <br><b>KPI:</b> {{y}}'),
tooltipValueLookups = tooltip_lvls,
chartRangeMin = min(unlist(df$monthly_trend[i])),
chartRangeMax = max(unlist(df$monthly_trend[i])),
lineColor=color,
fillColor=fillcolor,
highlightSpotColor="white",
highlightLineColor="white",
width = "100%",
height = "50%")
The following is the output (includes the string-constructed tooltipValueLookups:)
<span id="htmlwidget-c6f3e471432dcfbe2431" class="sparkline html-widget"></span>
<script type="application/json" data-for="htmlwidget-c6f3e471432dcfbe2431">{"x":{"values":["56.6","146.5","975.3","208.8","154.6","513.7","210.8","137.5","null","null","null","164","135.9","null","166.7"],
"options":{"xvalues":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],
"tooltipFormat":"<b>Months After 2021-05: {{x:levels}}<\/b> <br><b>KPI:<\/b> {{y}}",
"tooltipValueLookups":"{ levels: {1: \"2021-05\", 2: \"2021-06\", 3: \"2021-07\", 4: \"2021-08\", 5: \"2021-09\", 6: \"2021-10\", 7: \"2021-11\", 8: \"2021-12\", 9: \"2022-01\", 10: \"2022-02\", 11: \"2022-03\", 12: \"2022-04\", 13: \"2022-05\", 14: \"2022-06\", 15: \"2022-07\"}",
"chartRangeMin":"135.9",
"chartRangeMax":"NaN",
"lineColor":"#6c757d",
"fillColor":"#6c757d",
"highlightSpotColor":"white",
"highlightLineColor":"white",
"height":"50%",
"width":"100%"},
"width":"100%",
"height":"50%"},
"evals":[],"jsHooks":[]}</script>
In this case, I do get 99% of the way there:
QUESTION:
Based off the R spk_chr wrapper and the resulting output, how do I get the x values to map to strings in the tooltip via tooltipValueLookups? At this point, I'm even open to string-parsing the resulting "spark3" output to get the formatting in the correct realm. I know that {{x:levels}} isn't mapping x to the corresponding levels, but am at a loss with the current documentation available to get this right.
