Comparing version 0.6.7 to 0.7.1
{ | ||
"name": "d3-tip", | ||
"version": "0.6.6", | ||
"version": "0.7.1", | ||
"main": "index.js", | ||
@@ -15,4 +15,4 @@ "ignore": [ | ||
"dependencies": { | ||
"d3": "3.4" | ||
"d3": "^4.2" | ||
} | ||
} |
79
index.js
@@ -12,6 +12,4 @@ // d3.tip | ||
// CommonJS | ||
module.exports = function(d3) { | ||
d3.tip = factory(d3) | ||
return d3.tip | ||
} | ||
var d3 = require('d3') | ||
module.exports = factory(d3) | ||
} else { | ||
@@ -51,3 +49,3 @@ // Browser global. | ||
dir = direction.apply(this, args), | ||
nodel = d3.select(node), | ||
nodel = getNodeEl(), | ||
i = directions.length, | ||
@@ -59,13 +57,12 @@ coords, | ||
nodel.html(content) | ||
.style({ opacity: 1, 'pointer-events': 'all' }) | ||
.style('opacity', 1).style('pointer-events', 'all') | ||
while(i--) nodel.classed(directions[i], false) | ||
coords = direction_callbacks.get(dir).apply(this) | ||
nodel.classed(dir, true).style({ | ||
top: (coords.top + poffset[0]) + scrollTop + 'px', | ||
left: (coords.left + poffset[1]) + scrollLeft + 'px' | ||
}) | ||
nodel.classed(dir, true) | ||
.style('top', (coords.top + poffset[0]) + scrollTop + 'px') | ||
.style('left', (coords.left + poffset[1]) + scrollLeft + 'px') | ||
return tip | ||
} | ||
return tip; | ||
}; | ||
@@ -76,4 +73,4 @@ // Public - hide the tooltip | ||
tip.hide = function() { | ||
var nodel = d3.select(node) | ||
nodel.style({ opacity: 0, 'pointer-events': 'none' }) | ||
var nodel = getNodeEl() | ||
nodel.style('opacity', 0).style('pointer-events', 'none') | ||
return tip | ||
@@ -90,6 +87,6 @@ } | ||
if (arguments.length < 2 && typeof n === 'string') { | ||
return d3.select(node).attr(n) | ||
return getNodeEl().attr(n) | ||
} else { | ||
var args = Array.prototype.slice.call(arguments) | ||
d3.selection.prototype.attr.apply(d3.select(node), args) | ||
d3.selection.prototype.attr.apply(getNodeEl(), args) | ||
} | ||
@@ -108,6 +105,6 @@ | ||
if (arguments.length < 2 && typeof n === 'string') { | ||
return d3.select(node).style(n) | ||
return getNodeEl().style(n) | ||
} else { | ||
var args = Array.prototype.slice.call(arguments) | ||
d3.selection.prototype.style.apply(d3.select(node), args) | ||
var args = Array.prototype.slice.call(arguments) | ||
d3.selection.prototype.style.apply(getNodeEl(), args) | ||
} | ||
@@ -126,3 +123,3 @@ | ||
if (!arguments.length) return direction | ||
direction = v == null ? v : d3.functor(v) | ||
direction = v == null ? v : functor(v) | ||
@@ -139,3 +136,3 @@ return tip | ||
if (!arguments.length) return offset | ||
offset = v == null ? v : d3.functor(v) | ||
offset = v == null ? v : functor(v) | ||
@@ -152,3 +149,3 @@ return tip | ||
if (!arguments.length) return html | ||
html = v == null ? v : d3.functor(v) | ||
html = v == null ? v : functor(v) | ||
@@ -158,2 +155,13 @@ return tip | ||
// Public: destroys the tooltip and removes it from the DOM | ||
// | ||
// Returns a tip | ||
tip.destroy = function() { | ||
if(node) { | ||
getNodeEl().remove(); | ||
node = null; | ||
} | ||
return tip; | ||
} | ||
function d3_tip_direction() { return 'n' } | ||
@@ -241,10 +249,5 @@ function d3_tip_offset() { return [0, 0] } | ||
function initNode() { | ||
var node = d3.select(document.createElement('div')) | ||
node.style({ | ||
position: 'absolute', | ||
top: 0, | ||
opacity: 0, | ||
'pointer-events': 'none', | ||
'box-sizing': 'border-box' | ||
}) | ||
var node = d3.select(document.createElement('div')); | ||
node.style('position', 'absolute').style('top', 0).style('opacity', 0) | ||
.style('pointer-events', 'none').style('box-sizing', 'border-box') | ||
@@ -262,2 +265,11 @@ return node.node() | ||
function getNodeEl() { | ||
if(node === null) { | ||
node = initNode(); | ||
// re-add node to DOM | ||
document.body.appendChild(node); | ||
}; | ||
return d3.select(node); | ||
} | ||
// Private - gets the screen coordinates of a shape | ||
@@ -312,2 +324,9 @@ // | ||
} | ||
// Private - replace D3JS 3.X d3.functor() function | ||
function functor(v) { | ||
return typeof v === "function" ? v : function() { | ||
return v | ||
} | ||
} | ||
@@ -314,0 +333,0 @@ return tip |
{ | ||
"name": "d3-tip", | ||
"version": "0.6.7", | ||
"version": "0.7.1", | ||
"description": "Tooltips for d3 svg visualizations", | ||
@@ -22,3 +22,2 @@ "author": "Justin Palmer <justin@labratrevenge.com> (http://labratrevenge.com/d3-tip)", | ||
], | ||
"author": "Justin Palmer", | ||
"license": "MIT", | ||
@@ -28,3 +27,6 @@ "bugs": { | ||
}, | ||
"homepage": "https://github.com/Caged/d3-tip" | ||
"homepage": "https://github.com/Caged/d3-tip", | ||
"dependencies": { | ||
"d3": "^4.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
51109
346
1
1
+ Addedd3@^4.2
+ Addedcommander@2.20.3(transitive)
+ Addedd3@4.13.0(transitive)
+ Addedd3-array@1.2.1(transitive)
+ Addedd3-axis@1.0.8(transitive)
+ Addedd3-brush@1.0.4(transitive)
+ Addedd3-chord@1.0.4(transitive)
+ Addedd3-collection@1.0.4(transitive)
+ Addedd3-color@1.0.3(transitive)
+ Addedd3-dispatch@1.0.3(transitive)
+ Addedd3-drag@1.2.1(transitive)
+ Addedd3-dsv@1.0.8(transitive)
+ Addedd3-ease@1.0.3(transitive)
+ Addedd3-force@1.1.0(transitive)
+ Addedd3-format@1.2.2(transitive)
+ Addedd3-geo@1.9.1(transitive)
+ Addedd3-hierarchy@1.1.5(transitive)
+ Addedd3-interpolate@1.1.6(transitive)
+ Addedd3-path@1.0.5(transitive)
+ Addedd3-polygon@1.0.3(transitive)
+ Addedd3-quadtree@1.0.3(transitive)
+ Addedd3-queue@3.0.7(transitive)
+ Addedd3-random@1.1.0(transitive)
+ Addedd3-request@1.0.6(transitive)
+ Addedd3-scale@1.0.7(transitive)
+ Addedd3-selection@1.3.0(transitive)
+ Addedd3-shape@1.2.0(transitive)
+ Addedd3-time@1.0.8(transitive)
+ Addedd3-time-format@2.1.1(transitive)
+ Addedd3-timer@1.0.7(transitive)
+ Addedd3-transition@1.1.1(transitive)
+ Addedd3-voronoi@1.1.2(transitive)
+ Addedd3-zoom@1.7.1(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedrw@1.3.3(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedxmlhttprequest@1.8.0(transitive)