@redsift/d3-rs-tip
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -7,3 +7,3 @@ (function (global, factory) { | ||
var version = "0.2.0"; | ||
var version = "0.2.1"; | ||
@@ -25,3 +25,2 @@ function tip() { | ||
}; | ||
var arrowSizePx = 7; | ||
var defaultTipStyle = ['.d3-tip {line-height: 1;font-weight: bold;padding: 12px;background: rgba(0, 0, 0, 0.8);color: #fff;border-radius: 2px;pointer-events: none;}', '/* Creates a small triangle extender for the tooltip */', '.d3-tip:after {box-sizing: border-box;display: inline;font-size: 10px;width: 100%;line-height: 1;color: rgba(0, 0, 0, 0.8);position: absolute;pointer-events: none;}', '/* Northward tooltips */', '.d3-tip.n:after {content: "\\25bc";margin: -1px 0 0 0;top: 100%;left: 0;text-align: center;}', '/* Eastward tooltips */', '.d3-tip.e:after {content: "\\25C0";margin: -4px 0 0 0;top: 50%;left: -8px;}', '/* Southward tooltips */', '.d3-tip.s:after {content: "\\25B2";margin: 0 0 1px 0;top: -7px;left: 0;text-align: center;}', '/* Westward tooltips */', '.d3-tip.w:after {content: "\\25B6";margin: -4px 0 0 -1px;top: 50%;left: 100%;}'].join('\n'); | ||
@@ -222,3 +221,3 @@ | ||
return { | ||
top: bbox.s.y + node.offsetHeight / 2, | ||
top: bbox.s.y, | ||
left: bbox.s.x - node.offsetWidth / 2 | ||
@@ -232,3 +231,3 @@ }; | ||
top: bbox.e.y - node.offsetHeight / 2, | ||
left: bbox.e.x + arrowSizePx | ||
left: bbox.e.x | ||
}; | ||
@@ -241,3 +240,3 @@ } | ||
top: bbox.w.y - node.offsetHeight / 2, | ||
left: bbox.w.x - node.offsetWidth - arrowSizePx | ||
left: bbox.w.x - node.offsetWidth | ||
}; | ||
@@ -244,0 +243,0 @@ } |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-selection")):"function"==typeof define&&define.amd?define(["exports","d3-selection"],e):e(t.d3_rs_tip=t.d3_rs_tip||{},t.d3)}(this,function(t,e){"use strict";function n(){function t(){var t=e.select(document.createElement("div"));return t.style("position","absolute").style("top",0).style("left",0).style("opacity",0).style("pointer-events","none").style("box-sizing","border-box"),t.node()}function n(t){return(t=t.node())?"svg"===t.tagName.toLowerCase()?t:t.ownerSVGElement:void 0}function r(){return null===C&&(C=t(),_.appendChild(C)),e.select(C)}function o(t){if(H=n(t)){S=H.createSVGPoint(),H=e.select(H),H.append("defs");var r=H.select("defs"),o=r.selectAll("style").data(B?[B]:[]);o.exit().remove(),o=o.enter().append("style").attr("type","text/css").merge(o),o.text(B)}}function i(){var t=d();return{top:t.n.y-C.offsetHeight,left:t.n.x-C.offsetWidth/2}}function l(){var t=d();return{top:t.s.y+C.offsetHeight/2,left:t.s.x-C.offsetWidth/2}}function s(){var t=d();return{top:t.e.y-C.offsetHeight/2,left:t.e.x+m}}function f(){var t=d();return{top:t.w.y-C.offsetHeight/2,left:t.w.x-C.offsetWidth-m}}function a(){var t=d();return{top:t.nw.y-C.offsetHeight,left:t.nw.x-C.offsetWidth}}function p(){var t=d();return{top:t.ne.y-C.offsetHeight,left:t.ne.x}}function u(){var t=d();return{top:t.sw.y,left:t.sw.x-C.offsetWidth}}function c(){var t=d();return{top:t.se.y,left:t.se.x}}function d(){for(var t=W||e.event.target;"undefined"==typeof t.getScreenCTM&&"undefined"===t.parentNode;)t=t.parentNode;var n={},r=t.getScreenCTM(),o=t.getBBox(),i=o.width,l=o.height,s=o.x,f=o.y;return S.x=s,S.y=f,n.nw=S.matrixTransform(r),S.x+=i,n.ne=S.matrixTransform(r),S.y+=l,n.se=S.matrixTransform(r),S.x-=i,n.sw=S.matrixTransform(r),S.y-=l/2,n.w=S.matrixTransform(r),S.x+=i,n.e=S.matrixTransform(r),S.x-=i/2,S.y-=l/2,n.n=S.matrixTransform(r),S.y+=l,n.s=S.matrixTransform(r),n}var y=function(t){return"function"==typeof t?t:function(){return t}},x=function(){return"n"},g=function(){return[0,0]},h=function(){return" "},m=7,v=[".d3-tip {line-height: 1;font-weight: bold;padding: 12px;background: rgba(0, 0, 0, 0.8);color: #fff;border-radius: 2px;pointer-events: none;}","/* Creates a small triangle extender for the tooltip */",".d3-tip:after {box-sizing: border-box;display: inline;font-size: 10px;width: 100%;line-height: 1;color: rgba(0, 0, 0, 0.8);position: absolute;pointer-events: none;}","/* Northward tooltips */",'.d3-tip.n:after {content: "\\25bc";margin: -1px 0 0 0;top: 100%;left: 0;text-align: center;}',"/* Eastward tooltips */",'.d3-tip.e:after {content: "\\25C0";margin: -4px 0 0 0;top: 50%;left: -8px;}',"/* Southward tooltips */",'.d3-tip.s:after {content: "\\25B2";margin: 0 0 1px 0;top: -7px;left: 0;text-align: center;}',"/* Westward tooltips */",'.d3-tip.w:after {content: "\\25B6";margin: -4px 0 0 -1px;top: 50%;left: 100%;}'].join("\n"),w=x,b=g,T=h,C=t(),H=null,S=null,W=null,_=null,B=v;o.show=function(){_||o.parent(document.body);var t=[].slice.call(arguments);t[t.length-1]instanceof SVGElement&&(W=t.pop());var e,n=T.apply(this,t),i=b.apply(this,t),l=w.apply(this,t),s=r(),f=E.length,a=C.offsetParent.getBoundingClientRect();for(s.html(n).style("opacity",1).style("pointer-events","all");f--;)s.classed(E[f],!1);return e=j[l].apply(this),s.classed(l,!0).style("top",e.top+i[0]-a.top+"px").style("left",e.left+i[1]-a.left+"px"),o},o.hide=function(){var t=r();return t.style("opacity",0).style("pointer-events","none"),o},o.attr=function(t){if(arguments.length<2&&"string"==typeof t)return r().attr(t);var n=[].slice.call(arguments);return e.selection.prototype.attr.apply(r(),n),o},o.style=function(t){if(arguments.length<2&&"string"==typeof t)return r().style(t);var n=[].slice.call(arguments);return e.selection.prototype.style.apply(r(),n),o},o.direction=function(t){return arguments.length?(w=null==t?t:y(t),o):w},o.offset=function(t){return arguments.length?(b=null==t?t:y(t),o):b},o.html=function(t){return arguments.length?(T=null==t?t:y(t),o):T},o.destroy=function(){return C&&(r().remove(),C=null),o},o.style=function(t){return arguments.length?(B=v+t,o):B},o.parent=function(t){if(!arguments.length)return _;_=t||document.body,_.appendChild(C);var n=e.select(C.offsetParent);return"static"===n.style("position")&&n.style("position","relative"),o};var j={n:i,s:l,e:s,w:f,nw:a,ne:p,sw:u,se:c},E=Object.keys(j);return o}var r="0.2.0";t.version=r,t.tip=n,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-selection")):"function"==typeof define&&define.amd?define(["exports","d3-selection"],e):e(t.d3_rs_tip=t.d3_rs_tip||{},t.d3)}(this,function(t,e){"use strict";function n(){function t(){var t=e.select(document.createElement("div"));return t.style("position","absolute").style("top",0).style("left",0).style("opacity",0).style("pointer-events","none").style("box-sizing","border-box"),t.node()}function n(t){return(t=t.node())?"svg"===t.tagName.toLowerCase()?t:t.ownerSVGElement:void 0}function r(){return null===T&&(T=t(),_.appendChild(T)),e.select(T)}function o(t){if(C=n(t)){S=C.createSVGPoint(),C=e.select(C),C.append("defs");var r=C.select("defs"),o=r.selectAll("style").data(B?[B]:[]);o.exit().remove(),o=o.enter().append("style").attr("type","text/css").merge(o),o.text(B)}}function i(){var t=d();return{top:t.n.y-T.offsetHeight,left:t.n.x-T.offsetWidth/2}}function l(){var t=d();return{top:t.s.y,left:t.s.x-T.offsetWidth/2}}function s(){var t=d();return{top:t.e.y-T.offsetHeight/2,left:t.e.x}}function f(){var t=d();return{top:t.w.y-T.offsetHeight/2,left:t.w.x-T.offsetWidth}}function a(){var t=d();return{top:t.nw.y-T.offsetHeight,left:t.nw.x-T.offsetWidth}}function p(){var t=d();return{top:t.ne.y-T.offsetHeight,left:t.ne.x}}function u(){var t=d();return{top:t.sw.y,left:t.sw.x-T.offsetWidth}}function c(){var t=d();return{top:t.se.y,left:t.se.x}}function d(){for(var t=W||e.event.target;"undefined"==typeof t.getScreenCTM&&"undefined"===t.parentNode;)t=t.parentNode;var n={},r=t.getScreenCTM(),o=t.getBBox(),i=o.width,l=o.height,s=o.x,f=o.y;return S.x=s,S.y=f,n.nw=S.matrixTransform(r),S.x+=i,n.ne=S.matrixTransform(r),S.y+=l,n.se=S.matrixTransform(r),S.x-=i,n.sw=S.matrixTransform(r),S.y-=l/2,n.w=S.matrixTransform(r),S.x+=i,n.e=S.matrixTransform(r),S.x-=i/2,S.y-=l/2,n.n=S.matrixTransform(r),S.y+=l,n.s=S.matrixTransform(r),n}var y=function(t){return"function"==typeof t?t:function(){return t}},x=function(){return"n"},g=function(){return[0,0]},h=function(){return" "},m=[".d3-tip {line-height: 1;font-weight: bold;padding: 12px;background: rgba(0, 0, 0, 0.8);color: #fff;border-radius: 2px;pointer-events: none;}","/* Creates a small triangle extender for the tooltip */",".d3-tip:after {box-sizing: border-box;display: inline;font-size: 10px;width: 100%;line-height: 1;color: rgba(0, 0, 0, 0.8);position: absolute;pointer-events: none;}","/* Northward tooltips */",'.d3-tip.n:after {content: "\\25bc";margin: -1px 0 0 0;top: 100%;left: 0;text-align: center;}',"/* Eastward tooltips */",'.d3-tip.e:after {content: "\\25C0";margin: -4px 0 0 0;top: 50%;left: -8px;}',"/* Southward tooltips */",'.d3-tip.s:after {content: "\\25B2";margin: 0 0 1px 0;top: -7px;left: 0;text-align: center;}',"/* Westward tooltips */",'.d3-tip.w:after {content: "\\25B6";margin: -4px 0 0 -1px;top: 50%;left: 100%;}'].join("\n"),v=x,w=g,b=h,T=t(),C=null,S=null,W=null,_=null,B=m;o.show=function(){_||o.parent(document.body);var t=[].slice.call(arguments);t[t.length-1]instanceof SVGElement&&(W=t.pop());var e,n=b.apply(this,t),i=w.apply(this,t),l=v.apply(this,t),s=r(),f=j.length,a=T.offsetParent.getBoundingClientRect();for(s.html(n).style("opacity",1).style("pointer-events","all");f--;)s.classed(j[f],!1);return e=H[l].apply(this),s.classed(l,!0).style("top",e.top+i[0]-a.top+"px").style("left",e.left+i[1]-a.left+"px"),o},o.hide=function(){var t=r();return t.style("opacity",0).style("pointer-events","none"),o},o.attr=function(t){if(arguments.length<2&&"string"==typeof t)return r().attr(t);var n=[].slice.call(arguments);return e.selection.prototype.attr.apply(r(),n),o},o.style=function(t){if(arguments.length<2&&"string"==typeof t)return r().style(t);var n=[].slice.call(arguments);return e.selection.prototype.style.apply(r(),n),o},o.direction=function(t){return arguments.length?(v=null==t?t:y(t),o):v},o.offset=function(t){return arguments.length?(w=null==t?t:y(t),o):w},o.html=function(t){return arguments.length?(b=null==t?t:y(t),o):b},o.destroy=function(){return T&&(r().remove(),T=null),o},o.style=function(t){return arguments.length?(B=m+t,o):B},o.parent=function(t){if(!arguments.length)return _;_=t||document.body,_.appendChild(T);var n=e.select(T.offsetParent);return"static"===n.style("position")&&n.style("position","relative"),o};var H={n:i,s:l,e:s,w:f,nw:a,ne:p,sw:u,se:c},j=Object.keys(H);return o}var r="0.2.1";t.version=r,t.tip=n,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=d3-rs-tip.umd-es2015.min.js.map |
export var name = "@redsift/d3-rs-tip"; | ||
export var version = "0.2.0"; | ||
export var version = "0.2.1"; | ||
export var description = "Tip for graphs using D3v4."; | ||
@@ -4,0 +4,0 @@ export var keywords = ["redsift","d3","tip"]; |
{ | ||
"name": "@redsift/d3-rs-tip", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Tip for graphs using D3v4.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,1 +0,43 @@ | ||
# d3-rs-tip | ||
# d3-rs-tip | ||
`d3-rs-tip` is a component for adding tooltips in charts made with D3, an extension of Justin Palmer's [d3-tip](https://github.com/Caged/d3-tip). This component is dependent on D3 v4 (Alpha). | ||
## Builds | ||
[![Circle CI](https://circleci.com/gh/Redsift/d3-rs-tip.svg?style=svg)](https://circleci.com/gh/Redsift/d3-rs-tip) | ||
UMD from //static.redsift.io/reusable/d3-rs-tip/latest/d3-rs-tip.umd-es2015.min.js | ||
## Usage | ||
### ES6 | ||
``` | ||
import { tip } from "@redsift/d3-rs-tip"; | ||
var rtip = tip() | ||
.attr('class', 'd3-tip') | ||
.html(d => d.text) | ||
elmS.call(rtip); | ||
node.on('mouseover', rtip.show) | ||
.on('mouseout', rtip.hide) | ||
... | ||
``` | ||
If using rollup.js for a browser target, ensure `d3-rs-tip` is part of the global map. | ||
### Require | ||
``` | ||
var d3Tip = require("@redsift/d3-rs-tip"); | ||
var eml = d3Tip.tip(); | ||
... | ||
``` | ||
### Parameters | ||
|Name|Description| Expected Value| | ||
|----|-----------| --------------| | ||
|attr|Sets or gets attribute value| same as d3 e.g. attr('key',`value|function`) | ||
|style| Sets or gets a style value| same as d3 e.g. style('key',`value|function`) | ||
|direction| Sets or gets direction of the tooltip| one of `n`,`s`,`e`,`w`,`nw`,`sw`,`ne`,`se` | ||
|style| Sets or gets the CSS wrapped with the component| string of CSS properties | ||
|parent| Sets or gets the parent element the tip will be appended to| DOM Node (default: `body`) |
@@ -0,1 +1,6 @@ | ||
/** | ||
* Extension of work by Justin Palmer (https://github.com/Caged/d3-tip) | ||
* | ||
* Copyright (c) 2016 Redsift Limited. All rights reserved. | ||
*/ | ||
// d3.tip | ||
@@ -5,7 +10,2 @@ // Copyright (c) 2013 Justin Palmer | ||
// Tooltips for d3.js SVG visualizations | ||
/** | ||
* Heavily based on work by Justin Palmer | ||
* | ||
* Copyright (c) 2016 Redsift Limited. All rights reserved. | ||
*/ | ||
@@ -19,3 +19,2 @@ import { select, selection, event } from 'd3-selection'; | ||
var d3_tip_html = () => ' '; | ||
var arrowSizePx = 7; | ||
var defaultTipStyle = [ | ||
@@ -239,3 +238,3 @@ '.d3-tip {line-height: 1;font-weight: bold;padding: 12px;background: rgba(0, 0, 0, 0.8);color: #fff;border-radius: 2px;pointer-events: none;}', | ||
return { | ||
top: bbox.s.y + node.offsetHeight / 2, | ||
top: bbox.s.y, | ||
left: bbox.s.x - node.offsetWidth / 2 | ||
@@ -249,3 +248,3 @@ } | ||
top: bbox.e.y - node.offsetHeight / 2, | ||
left: bbox.e.x + arrowSizePx | ||
left: bbox.e.x | ||
} | ||
@@ -258,3 +257,3 @@ } | ||
top: bbox.w.y - node.offsetHeight / 2, | ||
left: bbox.w.x - node.offsetWidth - arrowSizePx | ||
left: bbox.w.x - node.offsetWidth | ||
} | ||
@@ -261,0 +260,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60291
44
733