|
|
|
@ -399,6 +399,7 @@ window.nv.tooltip.* also has various helper methods.
|
|
|
|
|
, fixedTop = null //If not null, this fixes the top position of the tooltip.
|
|
|
|
|
, classes = null //Attaches additional CSS classes to the tooltip DIV that is created.
|
|
|
|
|
, chartContainer = null //Parent DIV, of the SVG Container that holds the chart.
|
|
|
|
|
, tooltipElem = null //actual DOM element representing the tooltip.
|
|
|
|
|
, position = {left: null, top: null} //Relative position of the tooltip inside chartContainer.
|
|
|
|
|
, enabled = true //True -> tooltips are rendered. False -> don't render tooltips.
|
|
|
|
|
//Generates a unique id when you create a new tooltip() object
|
|
|
|
@ -425,27 +426,51 @@ window.nv.tooltip.* also has various helper methods.
|
|
|
|
|
|
|
|
|
|
if (d == null) return '';
|
|
|
|
|
|
|
|
|
|
var html = "<table><thead><tr><td colspan='3'><strong class='x-value'>" + headerFormatter(d.value) + "</strong></td></tr></thead><tbody>";
|
|
|
|
|
if (d.series instanceof Array) {
|
|
|
|
|
d.series.forEach(function(item, i) {
|
|
|
|
|
if (item.highlight) {
|
|
|
|
|
html += "<tr class='highlight'>";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
html += "<tr>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html += "<td class='legend-color-guide'><div style='background-color: " + item.color + ";'></div></td>";
|
|
|
|
|
html += "<td class='key'>" + item.key + " </td>";
|
|
|
|
|
html += "<td class='value'>" + valueFormatter(item.value,i) + "</td></tr>";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
html += "</tbody>";
|
|
|
|
|
html += "</table>";
|
|
|
|
|
var table = d3.select(document.createElement("table"));
|
|
|
|
|
var theadEnter = table.selectAll("thead")
|
|
|
|
|
.data([d])
|
|
|
|
|
.enter().append("thead");
|
|
|
|
|
theadEnter.append("tr")
|
|
|
|
|
.append("td")
|
|
|
|
|
.attr("colspan",3)
|
|
|
|
|
.append("strong")
|
|
|
|
|
.classed("x-value",true)
|
|
|
|
|
.text(headerFormatter(d.value));
|
|
|
|
|
|
|
|
|
|
var tbodyEnter = table.selectAll("tbody")
|
|
|
|
|
.data([d])
|
|
|
|
|
.enter().append("tbody");
|
|
|
|
|
var trowEnter = tbodyEnter.selectAll("tr")
|
|
|
|
|
.data(function(p) { return p.series})
|
|
|
|
|
.enter()
|
|
|
|
|
.append("tr")
|
|
|
|
|
.classed("highlight", function(p) { return p.highlight})
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
trowEnter.append("td")
|
|
|
|
|
.classed("legend-color-guide",true)
|
|
|
|
|
.append("div")
|
|
|
|
|
.style("background-color", function(p) { return p.color});
|
|
|
|
|
trowEnter.append("td")
|
|
|
|
|
.classed("key",true)
|
|
|
|
|
.text(function(p) {return p.key});
|
|
|
|
|
trowEnter.append("td")
|
|
|
|
|
.classed("value",true)
|
|
|
|
|
.text(function(p,i) { return valueFormatter(p.value,i) });
|
|
|
|
|
|
|
|
|
|
trowEnter.selectAll("td").each(function(p) {
|
|
|
|
|
if (p.highlight)
|
|
|
|
|
d3.select(this)
|
|
|
|
|
.style("border-bottom","solid 1px " + p.color)
|
|
|
|
|
.style("border-top","solid 1px " + p.color)
|
|
|
|
|
;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var html = table.node().outerHTML;
|
|
|
|
|
if (d.footer !== undefined)
|
|
|
|
|
html += "<div class='footer'>" + d.footer + "</div>";
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var dataSeriesExists = function(d) {
|
|
|
|
@ -509,7 +534,7 @@ window.nv.tooltip.* also has various helper methods.
|
|
|
|
|
var left = position.left;
|
|
|
|
|
var top = (fixedTop != null) ? fixedTop : position.top;
|
|
|
|
|
var container = getTooltipContainer(contentGenerator(data));
|
|
|
|
|
|
|
|
|
|
tooltipElem = container;
|
|
|
|
|
if (chartContainer) {
|
|
|
|
|
var svgComp = chartContainer.getElementsByTagName("svg")[0];
|
|
|
|
|
var boundRect = (svgComp) ? svgComp.getBoundingClientRect() : chartContainer.getBoundingClientRect();
|
|
|
|
@ -552,6 +577,11 @@ window.nv.tooltip.* also has various helper methods.
|
|
|
|
|
return nvtooltip;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Returns tooltipElem...not able to set it.
|
|
|
|
|
nvtooltip.tooltipElem = function() {
|
|
|
|
|
return tooltipElem;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nvtooltip.contentGenerator = function(_) {
|
|
|
|
|
if (!arguments.length) return contentGenerator;
|
|
|
|
|
if (typeof _ === 'function') {
|
|
|
|
|