From 4cd03476c9a412577093ecaf17374b53d540af7f Mon Sep 17 00:00:00 2001 From: Yaniv Kessler Date: Wed, 30 Apr 2014 14:06:27 +0300 Subject: [PATCH 1/6] package.json --- package.json | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..a3f74b4 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "d3-tip", + "version": "0.6.4", + "description": "d3 tooltips (by Justin Palmer) http://labratrevenge.com/d3-tip", + "main": "index.js", + "directories": { + "doc": "docs", + "example": "examples" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/Caged/d3-tip" + }, + "keywords": [ + "d3", + "tooltip" + ], + "author": "Justin Palmer", + "license": "MIT", + "bugs": { + "url": "https://github.com/Caged/d3-tip/issues" + }, + "homepage": "https://github.com/Caged/d3-tip" +} From 29d76f4505747fe6dd308a9e8c895d22ae98d858 Mon Sep 17 00:00:00 2001 From: Yaniv Kessler Date: Wed, 30 Apr 2014 14:26:35 +0300 Subject: [PATCH 2/6] properly export itself in commonjs scenario --- index.js | 75 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index 8c9f4e0..b3cfd74 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,9 @@ if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module with d3 as a dependency. define(['d3'], factory) + } else if (module && module.exports !== undefined) { + // CommonJS + module.exports = factory } else { // Browser global. root.d3.tip = factory(root.d3) @@ -24,20 +27,20 @@ svg = null, point = null, target = null - + function tip(vis) { svg = getSVGNode(vis) point = svg.createSVGPoint() document.body.appendChild(node) } - + // Public - show the tooltip on the screen // // Returns a tip tip.show = function() { var args = Array.prototype.slice.call(arguments) if(args[args.length - 1] instanceof SVGElement) target = args.pop() - + var content = html.apply(this, args), poffset = offset.apply(this, args), dir = direction.apply(this, args), @@ -46,20 +49,20 @@ coords, scrollTop = document.documentElement.scrollTop || document.body.scrollTop, scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft - + nodel.html(content) .style({ opacity: 1, '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' }) - + return tip } - + // Public - hide the tooltip // // Returns a tip @@ -68,7 +71,7 @@ nodel.style({ opacity: 0, 'pointer-events': 'none' }) return tip } - + // Public: Proxy attr calls to the d3 tip container. Sets or gets attribute value. // // n - name of the attribute @@ -82,10 +85,10 @@ var args = Array.prototype.slice.call(arguments) d3.selection.prototype.attr.apply(d3.select(node), args) } - + return tip } - + // Public: Proxy style calls to the d3 tip container. Sets or gets a style value. // // n - name of the property @@ -99,10 +102,10 @@ var args = Array.prototype.slice.call(arguments) d3.selection.prototype.style.apply(d3.select(node), args) } - + return tip } - + // Public: Set or get the direction of the tooltip // // v - One of n(north), s(south), e(east), or w(west), nw(northwest), @@ -112,10 +115,10 @@ tip.direction = function(v) { if (!arguments.length) return direction direction = v == null ? v : d3.functor(v) - + return tip } - + // Public: Sets or gets the offset of the tip // // v - Array of [x, y] offset @@ -124,10 +127,10 @@ tip.offset = function(v) { if (!arguments.length) return offset offset = v == null ? v : d3.functor(v) - + return tip } - + // Public: sets or gets the html value of the tooltip // // v - String value of the tip @@ -136,14 +139,14 @@ tip.html = function(v) { if (!arguments.length) return html html = v == null ? v : d3.functor(v) - + return tip } - + function d3_tip_direction() { return 'n' } function d3_tip_offset() { return [0, 0] } function d3_tip_html() { return ' ' } - + var direction_callbacks = d3.map({ n: direction_n, s: direction_s, @@ -154,9 +157,9 @@ sw: direction_sw, se: direction_se }), - + directions = direction_callbacks.keys() - + function direction_n() { var bbox = getScreenBBox() return { @@ -164,7 +167,7 @@ left: bbox.n.x - node.offsetWidth / 2 } } - + function direction_s() { var bbox = getScreenBBox() return { @@ -172,7 +175,7 @@ left: bbox.s.x - node.offsetWidth / 2 } } - + function direction_e() { var bbox = getScreenBBox() return { @@ -180,7 +183,7 @@ left: bbox.e.x } } - + function direction_w() { var bbox = getScreenBBox() return { @@ -188,7 +191,7 @@ left: bbox.w.x - node.offsetWidth } } - + function direction_nw() { var bbox = getScreenBBox() return { @@ -196,7 +199,7 @@ left: bbox.nw.x - node.offsetWidth } } - + function direction_ne() { var bbox = getScreenBBox() return { @@ -204,7 +207,7 @@ left: bbox.ne.x } } - + function direction_sw() { var bbox = getScreenBBox() return { @@ -212,7 +215,7 @@ left: bbox.sw.x - node.offsetWidth } } - + function direction_se() { var bbox = getScreenBBox() return { @@ -220,7 +223,7 @@ left: bbox.e.x } } - + function initNode() { var node = d3.select(document.createElement('div')) node.style({ @@ -230,18 +233,18 @@ 'pointer-events': 'none', 'box-sizing': 'border-box' }) - + return node.node() } - + function getSVGNode(el) { el = el.node() if(el.tagName.toLowerCase() == 'svg') return el - + return el.ownerSVGElement } - + // Private - gets the screen coordinates of a shape // // Given a shape on the screen, will return an SVGPoint for the directions @@ -264,7 +267,7 @@ height = tbbox.height, x = tbbox.x, y = tbbox.y - + point.x = x point.y = y bbox.nw = point.matrixTransform(matrix) @@ -283,10 +286,10 @@ bbox.n = point.matrixTransform(matrix) point.y += height bbox.s = point.matrixTransform(matrix) - + return bbox } - + return tip }; From 02132e476299e97c5665d35b664334db66df80f0 Mon Sep 17 00:00:00 2001 From: Yaniv Kessler Date: Wed, 30 Apr 2014 15:17:31 +0300 Subject: [PATCH 3/6] properly inject d3.tip in cjs scenario --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index b3cfd74..c0fbd9d 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,10 @@ define(['d3'], factory) } else if (module && module.exports !== undefined) { // CommonJS - module.exports = factory + module.exports = function(d3) { + d3.tip = factory(d3) + return d3.tip + } } else { // Browser global. root.d3.tip = factory(root.d3) From 8b5924c908c058ccb27b3683b25b0b07cc8651a4 Mon Sep 17 00:00:00 2001 From: Justin Palmer Date: Tue, 21 Oct 2014 09:20:43 -0600 Subject: [PATCH 4/6] fix module check --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 87e2087..13b1e40 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module with d3 as a dependency. define(['d3'], factory) - } else if (module && module.exports !== undefined) { + } else if (typeof module === 'object' && module.exports) { // CommonJS module.exports = function(d3) { d3.tip = factory(d3) From d6f7e71ded38329d3806b9b7610f1f0710ea293e Mon Sep 17 00:00:00 2001 From: Justin Palmer Date: Tue, 21 Oct 2014 09:24:08 -0600 Subject: [PATCH 5/6] bump version, add author --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a3f74b4..73b6325 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "d3-tip", - "version": "0.6.4", - "description": "d3 tooltips (by Justin Palmer) http://labratrevenge.com/d3-tip", + "version": "0.6.5", + "description": "Tooltips for d3 svg visualizations", + "author": "Justin Palmer (http://labratrevenge.com/d3-tip)", "main": "index.js", "directories": { "doc": "docs", From 4c2a2489dea5d7cb1a512335951cab862df2b9da Mon Sep 17 00:00:00 2001 From: Justin Palmer Date: Tue, 21 Oct 2014 09:26:41 -0600 Subject: [PATCH 6/6] we're actually at 0.6.6 --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 73d3b0e..0c9d8b9 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "d3-tip", - "version": "0.6.5", + "version": "0.6.6", "main": "index.js", "ignore": [ "**/.*", diff --git a/package.json b/package.json index 73b6325..abc2323 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "d3-tip", - "version": "0.6.5", + "version": "0.6.6", "description": "Tooltips for d3 svg visualizations", "author": "Justin Palmer (http://labratrevenge.com/d3-tip)", "main": "index.js",