Rebuilt nv.d3.js

master
Robin Hu 11 years ago
parent 1a6b5dab13
commit 4c3554db5d

@ -295,17 +295,22 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
return index;
else
return nextIndex
};
/*****
* A no-frills tooltip implementation.
*****/
};/* Tooltip rendering model for nvd3 charts.
window.nv.models.tooltip is the updated,new way to render tooltips.
window.nv.tooltip.show is the old tooltip code.
window.nv.tooltip.* also has various helper methods.
*/
(function() {
window.nv.tooltip = {};
/* Model which can be instantiated to handle tooltip rendering.
Example usage:
var tip = nv.models.tooltip().gravity('w').distance(23)
.data(myDataObject);
tip(); //just invoke the returned function to render tooltip.
*/
window.nv.models.tooltip = function() {
var content = null //HTML contents of the tooltip. If null, the content is generated via the data variable.
@ -313,8 +318,7 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
Format of data:
{
key: "Date",
value: "August 2009",
seriesSelectedKey: "Series 2",
value: "August 2009",
series: [
{
key: "Series 1",
@ -351,6 +355,8 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
return d;
};
//By default, the tooltip model renders a beautiful table inside a DIV.
//You can override this function if a custom tooltip is desired.
var contentGenerator = function(d) {
if (content != null) return content;
@ -359,8 +365,7 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
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) {
var isSelected = (item.key === d.seriesSelectedKey) ? "selected" : "";
html += "<tr class='" + isSelected + "'>";
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>";
@ -444,7 +449,7 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
top = Math.floor(top/snapDistance) * snapDistance;
}
nv.tooltip.calcTooltipPosition([left,top], gravity, distance, container, false);
nv.tooltip.calcTooltipPosition([left,top], gravity, distance, container);
return nvtooltip;
};
@ -560,6 +565,7 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
nv.tooltip.calcTooltipPosition(pos, gravity, dist, container);
};
//Looks up the ancestry of a DOM element, and returns the first NON-svg node.
nv.tooltip.findFirstNonSVGParent = function(Elem) {
while(Elem.tagName.match(/^g|svg$/i) !== null) {
Elem = Elem.parentNode;
@ -567,10 +573,11 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
return Elem;
};
//Finds the total offsetTop of a given DOM element.
//Looks up the entire ancestry of an element, up to the first relatively positioned element.
nv.tooltip.findTotalOffsetTop = function ( Elem, initialTop ) {
var offsetTop = initialTop;
do {
if( !isNaN( Elem.offsetTop ) ) {
offsetTop += (Elem.offsetTop);
@ -579,10 +586,11 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
return offsetTop;
};
//Finds the total offsetLeft of a given DOM element.
//Looks up the entire ancestry of an element, up to the first relatively positioned element.
nv.tooltip.findTotalOffsetLeft = function ( Elem, initialLeft) {
var offsetLeft = initialLeft;
do {
if( !isNaN( Elem.offsetLeft ) ) {
offsetLeft += (Elem.offsetLeft);
@ -592,7 +600,11 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
};
//Global utility function to render a tooltip on the DOM.
nv.tooltip.calcTooltipPosition = function(pos, gravity, dist, container, skipOffsetCalc) {
//pos = [X,Y] coordinates of where to place the tooltip, relative to the SVG chart container.
//gravity = how to orient the tooltip
//dist = how far away from the mouse to place tooltip
//container = tooltip DIV
nv.tooltip.calcTooltipPosition = function(pos, gravity, dist, container) {
var height = parseInt(container.offsetHeight),
width = parseInt(container.offsetWidth),
@ -609,12 +621,10 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
dist = dist || 20;
var tooltipTop = function ( Elem ) {
if (skipOffsetCalc === true) return top;
return nv.tooltip.findTotalOffsetTop(Elem, top);
};
var tooltipLeft = function ( Elem ) {
if (skipOffsetCalc === true) return left;
return nv.tooltip.findTotalOffsetLeft(Elem,left);
};
@ -661,8 +671,8 @@ nv.interactiveBisect = function (values, searchVal, xAccessor) {
container.style.left = left+'px';
container.style.top = top+'px';
container.style.opacity = 1;
container.style.position = 'absolute'; //fix scroll bar issue
container.style.pointerEvents = 'none'; //fix scroll bar issue
container.style.position = 'absolute';
container.style.pointerEvents = 'none';
return container;
};

12
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save