Skip to content

Instantly share code, notes, and snippets.

@AndrewBuntsev
Created May 10, 2020 22:04
Show Gist options
  • Save AndrewBuntsev/3775bec0974f207d8394e8dfebc71665 to your computer and use it in GitHub Desktop.
Save AndrewBuntsev/3775bec0974f207d8394e8dfebc71665 to your computer and use it in GitHub Desktop.
contents: function (d, defaultTitleFormat, defaultValueFormat, color) {
var $$ = this, config = $$.config,
titleFormat = config.tooltip_format_title || defaultTitleFormat,
nameFormat = config.tooltip_format_name || function (name) { return name; },
valueFormat = config.tooltip_format_value || defaultValueFormat,
text, i, title, value, name, bgcolor;
d.sort(function(a, b){
return a.value - b.value;
});
for (i = 0; i < d.length; i++) {
if (!(d[i] && (d[i].value || d[i].value === 0))) { continue; }
if (!text) {
title = titleFormat ? titleFormat(d[i].x) : d[i].x;
text = "" + (title || title === 0 ? "" : "");
}
name = nameFormat(d[i].name);
value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index);
bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id);
text += "";
text += "";
text += "";
text += "";
}
return text + "<table class="&quot; + $$.CLASS.tooltip + &quot;"><tbody>
<tr><th colspan="2">" + title + "</th></tr>
<tr class="&quot; + $$.CLASS.tooltipName + &quot;-&quot; + d[i].id + &quot;"><td class="name"><span style="background-color: &quot; + bgcolor + &quot;;"></span>" + name + "</td><td class="value">" + value + "</td></tr>
</tbody></table>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment