|
|
|
@ -336,7 +336,7 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
|
|
|
|
|
, snapDistance = 25 //Tolerance allowed before tooltip is moved from its current position (creates 'snapping' effect)
|
|
|
|
|
, 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 //SVG Container that holds the chart.
|
|
|
|
|
, chartContainer = null //Parent DIV, of the SVG Container that holds the chart.
|
|
|
|
|
, position = {left: null, top: null} //Relative position of the tooltip inside chartContainer.
|
|
|
|
|
, enabled = true //True -> tooltips are rendered. False -> don't render tooltips.
|
|
|
|
|
;
|
|
|
|
@ -393,26 +393,24 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
|
|
|
|
|
|
|
|
|
|
//Creates new tooltip container, or uses existing one on DOM.
|
|
|
|
|
function getTooltipContainer(newContent) {
|
|
|
|
|
var container = document.getElementsByClassName("nvtooltip");
|
|
|
|
|
if (container.length === 0) {
|
|
|
|
|
var body;
|
|
|
|
|
if (chartContainer)
|
|
|
|
|
body = d3.select(chartContainer);
|
|
|
|
|
else
|
|
|
|
|
body = d3.select("body");
|
|
|
|
|
|
|
|
|
|
var container = body.select(".nvtooltip");
|
|
|
|
|
if (container.node() === null) {
|
|
|
|
|
//Create new tooltip div if it doesn't exist on DOM.
|
|
|
|
|
container = document.createElement('div');
|
|
|
|
|
container.className = 'nvtooltip ' + (classes ? classes : 'xy-tooltip');
|
|
|
|
|
var body;
|
|
|
|
|
if (chartContainer)
|
|
|
|
|
body = chartContainer;
|
|
|
|
|
else
|
|
|
|
|
body = document.getElementsByTagName('body')[0];
|
|
|
|
|
|
|
|
|
|
body.appendChild(container);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//Element already exists on DOM, so reuse it.
|
|
|
|
|
container = container[0];
|
|
|
|
|
container = body.append("div")
|
|
|
|
|
.attr("class", "nvtooltip " + (classes? classes: "xy-tooltip"))
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
container.innerHTML = newContent;
|
|
|
|
|
return container;
|
|
|
|
|
container.node().innerHTML = newContent;
|
|
|
|
|
container.style("top",0).style("left",0);
|
|
|
|
|
return container.node();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -426,23 +424,27 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
|
|
|
|
|
|
|
|
|
|
var left = position.left;
|
|
|
|
|
var top = (fixedTop != null) ? fixedTop : position.top;
|
|
|
|
|
var container = getTooltipContainer(contentGenerator(data));
|
|
|
|
|
|
|
|
|
|
if (chartContainer) {
|
|
|
|
|
var svgComp = chartContainer.getElementsByTagName("svg")[0];
|
|
|
|
|
var boundRect = (svgComp) ? svgComp.getBoundingClientRect() : chartContainer.getBoundingClientRect();
|
|
|
|
|
|
|
|
|
|
left += boundRect.left + window.pageXOffset;
|
|
|
|
|
top += boundRect.top + window.pageYOffset;
|
|
|
|
|
var svgOffset = {left:0,top:0};
|
|
|
|
|
if (svgComp) {
|
|
|
|
|
var svgBound = svgComp.getBoundingClientRect();
|
|
|
|
|
var chartBound = chartContainer.getBoundingClientRect();
|
|
|
|
|
svgOffset.top = Math.abs(svgBound.top - chartBound.top);
|
|
|
|
|
svgOffset.left = Math.abs(svgBound.left - chartBound.left);
|
|
|
|
|
}
|
|
|
|
|
left += chartContainer.offsetLeft + svgOffset.left;
|
|
|
|
|
top += chartContainer.offsetTop + svgOffset.top;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (snapDistance && snapDistance > 0) {
|
|
|
|
|
top = Math.floor(top/snapDistance) * snapDistance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var container = getTooltipContainer(contentGenerator(data));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nv.tooltip.calcTooltipPosition([left,top], gravity, distance, container, true);
|
|
|
|
|
nv.tooltip.calcTooltipPosition([left,top], gravity, distance, container, false);
|
|
|
|
|
return nvtooltip;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|