Merge d3tooltip package (#423)

* Merge d3tooltip from romseguy/d3tooltip

* Dependences and npm package config

* Add credits
This commit is contained in:
Mihail Diordiev 2018-12-19 15:16:11 +02:00 committed by GitHub
parent fb9d826f61
commit d2084892b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 8119 additions and 7 deletions

View File

@ -0,0 +1,3 @@
{
"presets": ["es2015-loose", "stage-0"]
}

View File

@ -0,0 +1,4 @@
lib
**/node_modules
**/webpack.config.js
examples/**/server.js

View File

@ -0,0 +1,16 @@
{
"extends": "eslint-config-airbnb",
"env": {
"browser": true,
"mocha": true,
"node": true
},
"rules": {
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2
},
"plugins": [
"react"
]
}

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 romseguy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,55 @@
d3tooltip
=========================
This tooltip aims for a minimal yet highly configurable API. It has a long way to go, but the essentials are there.
It was created by [@romseguy](https://github.com/romseguy) and merged from [`romseguy/d3tooltip`](https://github.com/romseguy/d3tooltip).
## Installation
`npm install d3-state-visualizer`
## Quick usage
```javascript
import d3 from 'd3';
import d3tooltip from 'd3tooltip';
const DOMNode = document.getElementById('chart');
const root = d3.select(DOMNode);
const vis = root.append('svg');
let options = {
offset: {left: 30, top: 10}
};
vis.selectAll('circle').data(someData).enter()
.append('circle')
.attr('r', 10)
.call(
d3tooltip(d3, 'tooltipClassName', options)
.text((d, i) => toStringOrHtml(d))
.attr({ 'class': 'anotherClassName' })
.style({ 'min-width': '50px', 'border-radius: 5px' })
)
.on({
mouseover(d, i) {
d3.select(this).style({
fill: 'skyblue'
});
},
mouseout(d, i) {
d3.select(this).style({
fill: 'black'
});
}
});
```
## API
Option | Type | Default | Description
--------------------------|--------------|---------------------|--------------------------------------------------------------
`root` | DOM.Element | `body` | The tooltip will be added as a child of that element. You can also use a D3 [selection](https://github.com/mbostock/d3/wiki/Selections#d3_select)
`left` | Number | `undefined` | Sets the tooltip `x` absolute position instead of the mouse `x` position, relative to the `root` element
`top` | Number | `undefined` | Sets the tooltip `y` absolute position instead of the mouse `y` position, relative to the `root` element
`offset` | Object | `{left: 0, top: 0}` | Sets the distance, starting from the cursor position, until the tooltip is rendered. **Warning**: only applicable if you don't provide a `left` or `top` option

7736
packages/d3tooltip/dist/d3tooltip.js vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,54 @@
{
"name": "d3tooltip",
"version": "1.2.2",
"description": "A highly configurable tooltip for d3",
"main": "lib/index.js",
"scripts": {
"clean": "rimraf lib dist",
"lint": "eslint src",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
"build:lib": "babel src --out-dir lib",
"build:umd": "webpack src/index.js dist/d3tooltip.js --config webpack.config.development.js",
"build:umd:min": "webpack src/index.js dist/d3tooltip.min.js --config webpack.config.production.js",
"version": "npm run build",
"postversion": "git push && git push --tags && npm run clean",
"prepare": "npm run clean && npm run build",
"prepublishOnly": "npm run lint && npm run clean && npm run build"
},
"files": [
"lib",
"dist",
"src"
],
"repository": {
"type": "git",
"url": "https://github.com/reduxjs/redux-devtools.git"
},
"keywords": [
"d3",
"tooltip"
],
"author": "romseguy",
"license": "MIT",
"bugs": {
"url": "https://github.com/reduxjs/redux-devtools/issues"
},
"homepage": "https://github.com/reduxjs/redux-devtools",
"devDependencies": {
"babel-cli": "^6.3.15",
"babel-core": "^6.1.20",
"babel-eslint": "^5.0.0-beta4",
"babel-loader": "^6.2.0",
"babel-preset-es2015-loose": "^6.1.3",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"eslint": "^0.24",
"eslint-config-airbnb": "0.0.6",
"eslint-plugin-react": "^3.6.3",
"rimraf": "^2.3.4",
"webpack": "^1.9.6"
},
"dependencies": {
"ramda": "^0.17.1"
}
}

84
packages/d3tooltip/src/index.js vendored Normal file
View File

@ -0,0 +1,84 @@
import { is } from 'ramda';
import utils from './utils';
const { prependClass, functor } = utils.default || utils;
const defaultOptions = {
left: undefined, // mouseX
top: undefined, // mouseY
offset: {left: 0, top: 0},
root: undefined
};
export default function tooltip(d3, className = 'tooltip', options = {}) {
const {
left,
top,
offset,
root
} = {...defaultOptions, ...options};
let attrs = {'class': className};
let text = () => '';
let styles = {};
let el;
const anchor = root || d3.select('body');
const rootNode = anchor.node();
function tip(selection) {
selection.on({
'mouseover.tip': node => {
let [mouseX, mouseY] = d3.mouse(rootNode);
let [x, y] = [left || mouseX + offset.left, top || mouseY - offset.top];
anchor.selectAll(`div.${className}`).remove();
el = anchor.append('div')
.attr(prependClass(className)(attrs))
.style({
position: 'absolute',
'z-index': 1001,
left: x + 'px',
top: y + 'px',
...styles
})
.html(() => text(node));
},
'mousemove.tip': node => {
let [mouseX, mouseY] = d3.mouse(rootNode);
let [x, y] = [left || mouseX + offset.left, top || mouseY - offset.top];
el
.style({
left: x + 'px',
top: y + 'px'
})
.html(() => text(node));
},
'mouseout.tip': () => el.remove()
});
}
tip.attr = function setAttr(d) {
if (is(Object, d)) {
attrs = {...attrs, ...d};
}
return this;
};
tip.style = function setStyle(d) {
if (is(Object, d)) {
styles = {...styles, ...d};
}
return this;
};
tip.text = function setText(d) {
text = functor(d);
return this;
};
return tip;
}

View File

@ -0,0 +1,5 @@
import { is } from 'ramda';
export default function functor(v) {
return is(Function, v) ? v : () => v;
}

7
packages/d3tooltip/src/utils/index.js vendored Normal file
View File

@ -0,0 +1,7 @@
import prependClass from './prependClass';
import functor from './functor';
export default {
prependClass,
functor
};

View File

@ -0,0 +1,20 @@
import { mapObjIndexed, join } from 'ramda';
import functor from './functor';
export default function prependClass(className) {
return mapObjIndexed((value, key) => {
if (key === 'class') {
const fn = functor(value);
return (d, i) => {
const classNames = fn(d, i);
if (classNames !== className) {
return join(' ', [className, classNames]);
}
return classNames;
};
}
return value;
});
}

View File

@ -0,0 +1,16 @@
'use strict';
module.exports = {
module: {
loaders: [
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ }
]
},
output: {
library: 'd3tooltip',
libraryTarget: 'umd'
},
resolve: {
extensions: ['', '.js']
}
};

View File

@ -0,0 +1,14 @@
'use strict';
var webpack = require('webpack');
var baseConfig = require('./webpack.config.base');
var config = Object.create(baseConfig);
config.plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
];
module.exports = config;

View File

@ -0,0 +1,20 @@
'use strict';
var webpack = require('webpack');
var baseConfig = require('./webpack.config.base');
var config = Object.create(baseConfig);
config.plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
compressor: {
screw_ie8: true,
warnings: false
}
})
];
module.exports = config;

View File

@ -721,6 +721,11 @@ acorn-to-esprima@^1.0.5:
resolved "https://registry.yarnpkg.com/acorn-to-esprima/-/acorn-to-esprima-1.0.7.tgz#9436259760098f9ead9b9da2242fab2f4850281b"
integrity sha1-lDYll2AJj56tm52iJC+rL0hQKBs=
acorn-to-esprima@^2.0.4:
version "2.0.8"
resolved "https://registry.yarnpkg.com/acorn-to-esprima/-/acorn-to-esprima-2.0.8.tgz#003f0c642eb92132f417d3708f14ada82adf2eb1"
integrity sha1-AD8MZC65ITL0F9NwjxStqCrfLrE=
acorn-walk@^6.0.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-6.1.1.tgz#d363b66f5fac5f018ff9c3a1e7b6f8e310cc3913"
@ -1103,7 +1108,7 @@ axobject-query@^2.0.1:
dependencies:
ast-types-flow "0.0.7"
babel-cli@^6.10.1, babel-cli@^6.3.17:
babel-cli@^6.10.1, babel-cli@^6.3.15, babel-cli@^6.3.17:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-cli/-/babel-cli-6.26.0.tgz#502ab54874d7db88ad00b887a06383ce03d002f1"
integrity sha1-UCq1SHTX24itALiHoGODzgPQAvE=
@ -1186,7 +1191,7 @@ babel-core@^5.1.8, babel-core@^5.8.25, babel-core@^5.8.33:
trim-right "^1.0.0"
try-resolve "^1.0.0"
babel-core@^6.0.0, babel-core@^6.26.0, babel-core@^6.3.17:
babel-core@^6.0.0, babel-core@^6.1.20, babel-core@^6.26.0, babel-core@^6.3.17:
version "6.26.3"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.26.3.tgz#b2e2f09e342d0f0c88e2f02e067794125e75c207"
integrity sha512-6jyFLuDmeidKmUEb3NM+/yawG0M2bDZ9Z1qbZP59cyHLz8kYGKYwpJP0UwUKKUiTRNvxfLesJnTedqczP7cTDA==
@ -1241,6 +1246,18 @@ babel-eslint@^4.1.6:
lodash.assign "^3.2.0"
lodash.pick "^3.1.0"
babel-eslint@^5.0.0-beta4:
version "5.0.4"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-5.0.4.tgz#a6ba51ae582a1d4e25adfddbc2a61f8d5a9040b9"
integrity sha1-prpRrlgqHU4lrf3bwqYfjVqQQLk=
dependencies:
acorn-to-esprima "^2.0.4"
babel-traverse "^6.0.20"
babel-types "^6.0.19"
babylon "^6.0.18"
lodash.assign "^3.2.0"
lodash.pick "^3.1.0"
babel-generator@^6.18.0, babel-generator@^6.26.0:
version "6.26.1"
resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.26.1.tgz#1844408d3b8f0d35a404ea7ac180f087a601bd90"
@ -2155,7 +2172,7 @@ babel-preset-react-app@^3.1.2:
babel-preset-env "1.6.1"
babel-preset-react "6.24.1"
babel-preset-react@6.24.1, babel-preset-react@^6.5.0:
babel-preset-react@6.24.1, babel-preset-react@^6.3.13, babel-preset-react@^6.5.0:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-preset-react/-/babel-preset-react-6.24.1.tgz#ba69dfaea45fc3ec639b6a4ecea6e17702c91380"
integrity sha1-umnfrqRfw+xjm2pOzqbhdwLJE4A=
@ -2257,7 +2274,7 @@ babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.26.0, babel-te
babylon "^6.18.0"
lodash "^4.17.4"
babel-traverse@^6.0.0, babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-traverse@^6.26.0:
babel-traverse@^6.0.0, babel-traverse@^6.0.20, babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-traverse@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee"
integrity sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=
@ -2272,7 +2289,7 @@ babel-traverse@^6.0.0, babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-tra
invariant "^2.2.2"
lodash "^4.17.4"
babel-types@^6.0.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26.0:
babel-types@^6.0.0, babel-types@^6.0.19, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497"
integrity sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=
@ -2287,7 +2304,7 @@ babylon@^5.8.38:
resolved "https://registry.yarnpkg.com/babylon/-/babylon-5.8.38.tgz#ec9b120b11bf6ccd4173a18bf217e60b79859ffd"
integrity sha1-7JsSCxG/bM1Bc6GL8hfmC3mFn/0=
babylon@^6.18.0:
babylon@^6.0.18, babylon@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3"
integrity sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==
@ -3862,6 +3879,11 @@ eslint-plugin-react@^2.3.0:
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-2.7.1.tgz#5d6f1bca507d1387b6593c230998af04f0b9aed6"
integrity sha1-XW8bylB9E4e2WTwjCZivBPC5rtY=
eslint-plugin-react@^3.6.3:
version "3.16.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-3.16.1.tgz#262d96b77d7c4a42af809a73c0e527a58612293c"
integrity sha1-Ji2Wt318SkKvgJpzwOUnpYYSKTw=
eslint-scope@3.7.1:
version "3.7.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.1.tgz#3d63c3edfda02e06e01a452ad88caacc7cdcb6e8"
@ -3943,6 +3965,34 @@ eslint@^0.23:
user-home "^1.0.0"
xml-escape "~1.0.0"
eslint@^0.24:
version "0.24.1"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-0.24.1.tgz#54a50809855b9655721c6f2ee57b351edce28101"
integrity sha1-VKUICYVbllVyHG8u5Xs1HtzigQE=
dependencies:
chalk "^1.0.0"
concat-stream "^1.4.6"
debug "^2.1.1"
doctrine "^0.6.2"
escape-string-regexp "^1.0.2"
escope "^3.1.0"
espree "^2.0.1"
estraverse "^4.1.0"
estraverse-fb "^1.3.1"
globals "^8.0.0"
inquirer "^0.8.2"
is-my-json-valid "^2.10.0"
js-yaml "^3.2.5"
minimatch "^2.0.1"
mkdirp "^0.5.0"
object-assign "^2.0.0"
optionator "^0.5.0"
path-is-absolute "^1.0.0"
strip-json-comments "~1.0.1"
text-table "~0.2.0"
user-home "^1.0.0"
xml-escape "~1.0.0"
eslint@^5.0.0:
version "5.10.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-5.10.0.tgz#24adcbe92bf5eb1fc2d2f2b1eebe0c5e0713903a"
@ -7877,6 +7927,11 @@ railroad-diagrams@^1.0.0:
resolved "https://registry.yarnpkg.com/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz#eb7e6267548ddedfb899c1b90e57374559cddb7e"
integrity sha1-635iZ1SN3t+4mcG5Dlc3RVnN234=
ramda@^0.17.1:
version "0.17.1"
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.17.1.tgz#4c198147d3ab54e8c15255f11730e2116f6e6073"
integrity sha1-TBmBR9OrVOjBUlXxFzDiEW9uYHM=
randexp@0.4.6:
version "0.4.6"
resolved "https://registry.yarnpkg.com/randexp/-/randexp-0.4.6.tgz#e986ad5e5e31dae13ddd6f7b3019aa7c87f60ca3"
@ -9586,7 +9641,7 @@ webpack-core@~0.6.9:
source-list-map "~0.1.7"
source-map "~0.4.1"
webpack@^1.11.0:
webpack@^1.11.0, webpack@^1.9.6:
version "1.15.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-1.15.0.tgz#4ff31f53db03339e55164a9d468ee0324968fe98"
integrity sha1-T/MfU9sDM55VFkqdRo7gMklo/pg=