├── .nvmrc ├── .npmignore ├── .gitignore ├── media └── screenshot.png ├── tsconfig.json ├── css └── style.css ├── .editorconfig ├── bower.json ├── webpack.config.js ├── index.d.ts ├── demo ├── second.js ├── first.ts └── index.html ├── LICENSE ├── package.json ├── index.js ├── index.ts ├── dist └── d3scription.js ├── README.md └── d └── d3.d.ts /.nvmrc: -------------------------------------------------------------------------------- 1 | 6.3 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | .git/ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /dist/demo.js 4 | -------------------------------------------------------------------------------- /media/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalWebIndex/d3scription/HEAD/media/screenshot.png -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "AMD", 5 | "sourceMap": true 6 | }, 7 | "exclude": [ 8 | "node_modules" 9 | ], 10 | "compileOnSave": false 11 | } 12 | -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | .d3scription-tip { 2 | font-size: 11px; 3 | color: white; 4 | background: #283645; 5 | box-shadow: 0 0 10px rgba(0,0,0,.7); 6 | border-radius: 3px; 7 | padding: 5px 10px; 8 | min-width: 190px; 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | end_of_line = lf 8 | insert_final_newline = true 9 | charset = utf-8 10 | indent_style = space 11 | 12 | # 2 space indentation 13 | [*.{json,js}] 14 | indent_size = 2 15 | 16 | # 4 space indentation 17 | [*.ts] 18 | indent_size = 4 19 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "d3scription", 3 | "description": "D3.js tooltip plugin made simple. With single-page apps in mind.", 4 | "main": "dist/d3scription.js", 5 | "authors": [ 6 | "GlobalWebIndex / Marek Fajkus" 7 | ], 8 | "license": "MIT", 9 | "keywords": [ 10 | "d3", 11 | "tip", 12 | "tooltip", 13 | "description" 14 | ], 15 | "homepage": "https://github.com/GlobalWebIndex/d3scription", 16 | "ignore": [ 17 | "**/.*", 18 | "node_modules", 19 | "bower_components", 20 | "test", 21 | "tests" 22 | ], 23 | "dependencies": { 24 | "d3": "^4.2.1" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | module.exports = { 4 | entry: { 5 | d3scription: ['./index.ts'], 6 | demo: './demo/first.ts' 7 | }, 8 | output: { 9 | path: 'dist/', 10 | filename: "[name].js", 11 | library: ["d3scription", "[name]"] 12 | }, 13 | resolve: { 14 | // Add `.ts` as a resolvable extension. 15 | extensions: ['', '.webpack.js', '.web.js', '.ts', '.js'] 16 | }, 17 | module: { 18 | loaders: [ 19 | // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader` 20 | { test: /\.ts/, loader: 'ts-loader' } 21 | ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export interface Offset { 3 | top?: number; 4 | left?: number; 5 | } 6 | export interface Options { 7 | zIndex?: number; 8 | class?: string; 9 | offset?: Offset; 10 | } 11 | export interface ContentGetter extends Function { 12 | (data: T): string; 13 | } 14 | export interface Tip { 15 | element(element: d3.Selection): Tip; 16 | show(data: T): Tip; 17 | update(data: T): Tip; 18 | hide(): Tip; 19 | remove(): void; 20 | } 21 | export interface TipFactory extends Function { 22 | (): Tip; 23 | } 24 | export default function d3scription(contentGetter: ContentGetter, options?: Options): TipFactory; 25 | -------------------------------------------------------------------------------- /demo/second.js: -------------------------------------------------------------------------------- 1 | var data = [ 2 | { 3 | x: 30*Math.random()+50, 4 | y: 100*Math.random()+50, 5 | desc: 'We are your friends...' 6 | }, 7 | { 8 | x: 300*Math.random()+50, 9 | y: 70*Math.random()+50, 10 | desc: 'I love it!' 11 | } 12 | ]; 13 | 14 | var el = d3.select('#second-example') 15 | .append('g'); 16 | 17 | var tipFactory = d3scription(function(d) { return d.desc; }); 18 | var tip = tipFactory() 19 | .element(el); 20 | 21 | var circles = el.selectAll('.circle') 22 | .data(data); 23 | 24 | var cEnter = circles.enter() 25 | .append('circle') 26 | .attr('class', 'circle') 27 | .attr('r', 30) 28 | .attr('cx', function(d) { return d.x; }) 29 | .attr('cy', function(d) { return d.y; }) 30 | .on('mouseover', tip.show) 31 | .on('mouseout', tip.hide); 32 | -------------------------------------------------------------------------------- /demo/first.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import d3scription from '../index'; 3 | 4 | interface D { 5 | x : number; 6 | y : number; 7 | desc : string; 8 | } 9 | 10 | const data : D[] = [ 11 | { 12 | x: 30*Math.random()+50, 13 | y: 100*Math.random()+50, 14 | desc: 'We are your friends...' 15 | }, 16 | { 17 | x: 300*Math.random()+50, 18 | y: 70*Math.random()+50, 19 | desc: 'I love it!' 20 | } 21 | ] 22 | const el = d3.select('#first-example') 23 | .append('g'); 24 | 25 | const tipFactory = d3scription((d : D) => d.desc); 26 | const tip = tipFactory() 27 | .element(el); 28 | 29 | const circles = el.selectAll('.circle') 30 | .data(data); 31 | 32 | const cEnter = circles.enter() 33 | .append('circle') 34 | .attr('class', 'circle') 35 | .attr('r', 30) 36 | .attr('cx', d => d.x) 37 | .attr('cy', d => d.y) 38 | .on('mouseover', tip.show) 39 | .on('mouseout', tip.hide); 40 | -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | D3scription D3 tooltip demo 5 | 6 | 7 | 23 | 24 | 25 | 26 |
27 |

d3scription Demos

28 | 29 |

Typescript demo

30 | 31 | 32 | 33 | 34 |

Javascript demo

35 | 36 | 37 | 38 | 39 |
40 | 41 | 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 GlobalWebIndex Ltd 3 | 4 | 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: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | 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. 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "d3scription", 3 | "version": "1.1.0", 4 | "description": "D3.js tooltip plugin made simple. With single-page apps in mind. ", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "prepublish": "npm run compile", 9 | "watch": "node_modules/webpack/bin/webpack.js --watch", 10 | "compile": "node_modules/typescript/bin/tsc index.ts -m commonjs -d && node_modules/webpack/bin/webpack.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/GlobalWebIndex/d3scription.git" 15 | }, 16 | "keywords": [ 17 | "d3", 18 | "tip", 19 | "tooltip", 20 | "description" 21 | ], 22 | "author": "GlobalWebIndex / Marek Fajkus", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/GlobalWebIndex/d3scription/issues" 26 | }, 27 | "homepage": "https://github.com/GlobalWebIndex/d3scription#readme", 28 | "devDependencies": { 29 | "ts-loader": "^0.8.2", 30 | "typescript": "^2.1.0-dev.20160804", 31 | "webpack": "^1.13.1" 32 | }, 33 | "dependencies": { 34 | "d3": "^4.2.1" 35 | }, 36 | "publishConfig": { 37 | "registry":"https://npm.pkg.github.com" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | exports.__esModule = true; 4 | var windowDimensions = { 5 | width: window.innerWidth, 6 | height: window.innerHeight 7 | }; 8 | function setWindowDimmensions() { 9 | windowDimensions = { 10 | width: window.innerWidth, 11 | height: window.innerHeight 12 | }; 13 | } 14 | var windowResize = window.addEventListener('resize', setWindowDimmensions); 15 | function getOffset(event, bounds, offset) { 16 | var collideVertically = (windowDimensions.height + window.scrollY) - event.pageY - offset.top - bounds.height < 0; 17 | var collideHorizontally = (windowDimensions.width + window.scrollX) - event.pageX - offset.left - bounds.width < 0; 18 | return { 19 | top: collideVertically ? event.pageY - bounds.height - offset.top : offset.top + event.pageY, 20 | left: collideHorizontally ? event.pageX - bounds.width - offset.left : event.pageX + offset.left 21 | }; 22 | } 23 | var defaultOffset = { top: 10, left: 10 }; 24 | function getOffsetSettings(offset) { 25 | if (!offset) 26 | return defaultOffset; 27 | return { 28 | top: offset.top === undefined ? defaultOffset.top : offset.top, 29 | left: offset.left === undefined ? defaultOffset.left : offset.left 30 | }; 31 | } 32 | function d3scription(contentGetter, options) { 33 | if (options === void 0) { options = {}; } 34 | var offsetSettings = getOffsetSettings(options.offset); 35 | return function () { 36 | var tip = d3.select('body') 37 | .append('div') 38 | .attr('class', options["class"] || 'd3scription-tip') 39 | .style('position', 'absolute') 40 | .style('z-index', options.zIndex || 100) 41 | .style('visibility', 'hidden'); 42 | function updateTipPosition() { 43 | var bounds = tip.node().getBoundingClientRect(); 44 | var position = getOffset(d3.event, bounds, offsetSettings); 45 | tip 46 | .style("top", position.top + "px") 47 | .style("left", position.left + "px"); 48 | } 49 | function setupTracking(element) { 50 | element.on('mousemove', updateTipPosition); 51 | } 52 | var publicMethods = { 53 | element: function (element) { 54 | setupTracking(element); 55 | return publicMethods; 56 | }, 57 | show: function (data) { 58 | updateTipPosition(); 59 | tip.html(contentGetter(data)); 60 | tip.style('visibility', 'visible'); 61 | return publicMethods; 62 | }, 63 | update: function (data) { 64 | tip.html(contentGetter(data)); 65 | return publicMethods; 66 | }, 67 | hide: function () { 68 | tip.style('visibility', 'hidden'); 69 | return publicMethods; 70 | }, 71 | remove: function () { 72 | tip.remove(); 73 | } 74 | }; 75 | return publicMethods; 76 | }; 77 | } 78 | exports["default"] = d3scription; 79 | // export as Global Object 80 | if (typeof window === 'object') { 81 | window['d3scription'] = d3scription; 82 | } 83 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | export interface Offset { 4 | top? : number; 5 | left? : number; 6 | } 7 | 8 | export interface Options { 9 | zIndex? : number; 10 | class? : string; 11 | offset? : Offset; 12 | } 13 | 14 | export interface ContentGetter extends Function { 15 | (data : T) : string; 16 | } 17 | 18 | export interface Tip { 19 | element(element : d3.Selection) : Tip; 20 | show(data : T) : Tip; 21 | update(data : T) : Tip; 22 | hide() : Tip; 23 | remove() : void; 24 | } 25 | 26 | export interface TipFactory extends Function { 27 | () : Tip 28 | } 29 | 30 | interface WindowDimensions { 31 | width : number, 32 | height : number 33 | } 34 | 35 | interface Position { 36 | top : number, 37 | left : number, 38 | } 39 | 40 | let windowDimensions : WindowDimensions = { 41 | width: window.innerWidth, 42 | height: window.innerHeight 43 | } 44 | 45 | function setWindowDimmensions() : void { 46 | windowDimensions = { 47 | width: window.innerWidth, 48 | height: window.innerHeight 49 | } 50 | } 51 | 52 | const windowResize = window.addEventListener('resize', setWindowDimmensions); 53 | 54 | function getOffset(event : MouseEvent, bounds : ClientRect, offset : Position) : Position { 55 | const collideVertically : boolean = (windowDimensions.height + window.scrollY) - event.pageY - offset.top - bounds.height < 0; 56 | const collideHorizontally : boolean = (windowDimensions.width + window.scrollX) - event.pageX - offset.left - bounds.width < 0; 57 | 58 | return { 59 | top: collideVertically ? event.pageY - bounds.height - offset.top : offset.top + event.pageY, 60 | left: collideHorizontally ? event.pageX - bounds.width - offset.left : event.pageX + offset.left 61 | }; 62 | } 63 | 64 | const defaultOffset : Position = { top: 10, left: 10 }; 65 | function getOffsetSettings(offset? : Offset) : Position { 66 | if (!offset) return defaultOffset; 67 | return { 68 | top: offset.top === undefined ? defaultOffset.top : offset.top, 69 | left: offset.left === undefined ? defaultOffset.left : offset.left 70 | }; 71 | } 72 | 73 | export default function d3scription (contentGetter : ContentGetter, options:Options = {}) : TipFactory { 74 | const offsetSettings : Position = getOffsetSettings(options.offset); 75 | 76 | return function () : Tip { 77 | const tip : d3.Selection = d3.select('body') 78 | .append('div') 79 | .attr('class', options.class || 'd3scription-tip') 80 | .style('position', 'absolute') 81 | .style('z-index', options.zIndex || 100) 82 | .style('visibility', 'hidden'); 83 | 84 | function updateTipPosition() { 85 | const bounds : ClientRect = tip.node().getBoundingClientRect(); 86 | const position : Position = getOffset(d3.event, bounds, offsetSettings) 87 | 88 | tip 89 | .style("top", `${position.top}px`) 90 | .style("left", `${position.left}px`); 91 | } 92 | 93 | function setupTracking(element : d3.Selection) : void { 94 | element.on('mousemove', updateTipPosition); 95 | } 96 | 97 | const publicMethods : Tip = { 98 | element(element : d3.Selection) : Tip { 99 | setupTracking(element); 100 | 101 | return publicMethods; 102 | }, 103 | show(data : T) : Tip { 104 | updateTipPosition(); 105 | tip.html(contentGetter(data)); 106 | tip.style('visibility', 'visible'); 107 | 108 | return publicMethods; 109 | }, 110 | update(data : T) : Tip { 111 | tip.html(contentGetter(data)); 112 | 113 | return publicMethods; 114 | }, 115 | hide() : Tip { 116 | tip.style('visibility', 'hidden'); 117 | 118 | return publicMethods; 119 | }, 120 | remove() : void { 121 | tip.remove(); 122 | } 123 | }; 124 | 125 | return publicMethods; 126 | }; 127 | } 128 | 129 | // export as Global Object 130 | if (typeof window === 'object') { 131 | window['d3scription'] = d3scription; 132 | } 133 | -------------------------------------------------------------------------------- /dist/d3scription.js: -------------------------------------------------------------------------------- 1 | var d3scription = d3scription || {}; d3scription["d3scription"] = 2 | /******/ (function(modules) { // webpackBootstrap 3 | /******/ // The module cache 4 | /******/ var installedModules = {}; 5 | 6 | /******/ // The require function 7 | /******/ function __webpack_require__(moduleId) { 8 | 9 | /******/ // Check if module is in cache 10 | /******/ if(installedModules[moduleId]) 11 | /******/ return installedModules[moduleId].exports; 12 | 13 | /******/ // Create a new module (and put it into the cache) 14 | /******/ var module = installedModules[moduleId] = { 15 | /******/ exports: {}, 16 | /******/ id: moduleId, 17 | /******/ loaded: false 18 | /******/ }; 19 | 20 | /******/ // Execute the module function 21 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 22 | 23 | /******/ // Flag the module as loaded 24 | /******/ module.loaded = true; 25 | 26 | /******/ // Return the exports of the module 27 | /******/ return module.exports; 28 | /******/ } 29 | 30 | 31 | /******/ // expose the modules object (__webpack_modules__) 32 | /******/ __webpack_require__.m = modules; 33 | 34 | /******/ // expose the module cache 35 | /******/ __webpack_require__.c = installedModules; 36 | 37 | /******/ // __webpack_public_path__ 38 | /******/ __webpack_require__.p = ""; 39 | 40 | /******/ // Load entry module and return exports 41 | /******/ return __webpack_require__(0); 42 | /******/ }) 43 | /************************************************************************/ 44 | /******/ ([ 45 | /* 0 */ 46 | /***/ (function(module, exports, __webpack_require__) { 47 | 48 | module.exports = __webpack_require__(1); 49 | 50 | 51 | /***/ }), 52 | /* 1 */ 53 | /***/ (function(module, exports, __webpack_require__) { 54 | 55 | var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/// 56 | !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports], __WEBPACK_AMD_DEFINE_RESULT__ = function (require, exports) { 57 | "use strict"; 58 | Object.defineProperty(exports, "__esModule", { value: true }); 59 | var windowDimensions = { 60 | width: window.innerWidth, 61 | height: window.innerHeight 62 | }; 63 | function setWindowDimmensions() { 64 | windowDimensions = { 65 | width: window.innerWidth, 66 | height: window.innerHeight 67 | }; 68 | } 69 | var windowResize = window.addEventListener('resize', setWindowDimmensions); 70 | function getOffset(event, bounds, offset) { 71 | var collideVertically = (windowDimensions.height + window.scrollY) - event.pageY - offset.top - bounds.height < 0; 72 | var collideHorizontally = (windowDimensions.width + window.scrollX) - event.pageX - offset.left - bounds.width < 0; 73 | return { 74 | top: collideVertically ? event.pageY - bounds.height - offset.top : offset.top + event.pageY, 75 | left: collideHorizontally ? event.pageX - bounds.width - offset.left : event.pageX + offset.left 76 | }; 77 | } 78 | var defaultOffset = { top: 10, left: 10 }; 79 | function getOffsetSettings(offset) { 80 | if (!offset) 81 | return defaultOffset; 82 | return { 83 | top: offset.top === undefined ? defaultOffset.top : offset.top, 84 | left: offset.left === undefined ? defaultOffset.left : offset.left 85 | }; 86 | } 87 | function d3scription(contentGetter, options) { 88 | if (options === void 0) { options = {}; } 89 | var offsetSettings = getOffsetSettings(options.offset); 90 | return function () { 91 | var tip = d3.select('body') 92 | .append('div') 93 | .attr('class', options.class || 'd3scription-tip') 94 | .style('position', 'absolute') 95 | .style('z-index', options.zIndex || 100) 96 | .style('visibility', 'hidden'); 97 | function updateTipPosition() { 98 | var bounds = tip.node().getBoundingClientRect(); 99 | var position = getOffset(d3.event, bounds, offsetSettings); 100 | tip 101 | .style("top", position.top + "px") 102 | .style("left", position.left + "px"); 103 | } 104 | function setupTracking(element) { 105 | element.on('mousemove', updateTipPosition); 106 | } 107 | var publicMethods = { 108 | element: function (element) { 109 | setupTracking(element); 110 | return publicMethods; 111 | }, 112 | show: function (data) { 113 | updateTipPosition(); 114 | tip.html(contentGetter(data)); 115 | tip.style('visibility', 'visible'); 116 | return publicMethods; 117 | }, 118 | update: function (data) { 119 | tip.html(contentGetter(data)); 120 | return publicMethods; 121 | }, 122 | hide: function () { 123 | tip.style('visibility', 'hidden'); 124 | return publicMethods; 125 | }, 126 | remove: function () { 127 | tip.remove(); 128 | } 129 | }; 130 | return publicMethods; 131 | }; 132 | } 133 | exports.default = d3scription; 134 | // export as Global Object 135 | if (typeof window === 'object') { 136 | window['d3scription'] = d3scription; 137 | } 138 | }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); 139 | 140 | 141 | /***/ }) 142 | /******/ ]); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # d3scription 2 | 3 | D3 tooltip description following mouse cursor. With window edge collision solved. 4 | 5 | ![screenshot](media/screenshot.png) 6 | 7 | This plugin tries to be as universal and simple as possible. 8 | You can install it using your favorite dependency manager - doesn't matter if it is [NPM](http://npmjs.org/) or [bower](https://bower.io/). 9 | You can also **directly download distribution** if you do not use any of these. It supports many module systems (commonjs, AMD, TypeScript). 10 | You can easily customize look in your css and overwrite all default values by providing your own. 11 | 12 | # Instalation 13 | 14 | ## NPM 15 | 16 | This will install npm package with **commonjs** module system: 17 | 18 | ``` 19 | npm install d3scription --save 20 | ``` 21 | 22 | ## Bower 23 | 24 | This will install bower package with **AMD** module and **global `d3scription` variable**: 25 | 26 | ``` 27 | bower install d3scription --save 28 | ``` 29 | 30 | ## Direct download 31 | 32 | If you do not want to use any dependency manager in your project you can simply download [distribution](dist/d3scription.js) 33 | and place it in your project. This is exactly the same file as installed using bower. It supports **AMD modules or global `d3scription` function**. 34 | 35 | ``` 36 | curl https://raw.githubusercontent.com/GlobalWebIndex/d3scription/master/dist/d3scription.js > d3scription.js 37 | ``` 38 | 39 | # Usage 40 | You can use this plugin with both **JavaScript and TypeScript**. Please see [demos](demo/) for some example usage. 41 | 42 | ## JavaScript 43 | 44 | Assume you have d3scription.js file already loaded in browser together with d3.js or AMD manager is used you're able to use this plugin in similar fashion. 45 | Don't forget, that this plugin itself is dependent on D3 so you need to include d3 before you load d3scription! 46 | 47 | ```js 48 | // define some example data 49 | var data = [ 50 | { 51 | x: 50, 52 | y: 100, 53 | desc: 'We are your friends...' 54 | }, 55 | { 56 | x: 200, 57 | y: 50, 58 | desc: 'I love it!' 59 | } 60 | ] 61 | 62 | // select SVG element and create main group 63 | var el = d3.select('svg') 64 | .append('g'); 65 | 66 | // setup plugin with description getter function and default options. 67 | // if you want to overwrite default z-index, offset or class name please see `api:setup:options section` 68 | var tipFactory = d3scription(function(d) { return d.desc; }); 69 | 70 | // create tip for our main group element 71 | var tip = tipFactory() 72 | .element(el); 73 | 74 | // set data to circles 75 | var circles = el.selectAll('.circle') 76 | .data(data); 77 | 78 | // draw circles 79 | var cEnter = circles.enter() 80 | .append('circle') 81 | .attr('class', 'circle') 82 | .attr('r', 30) 83 | .attr('cx', function(d) { return d.x; }) 84 | .attr('cy', function(d) { return d.y; }) 85 | // setup show and hide action on mouse events 86 | .on('mouseover', tip.show) 87 | .on('mouseout', tip.hide); 88 | ``` 89 | 90 | ## Typescript 91 | 92 | Usage with typescript is quite simmilar as usage with any other module system. 93 | 94 | ```typescript 95 | import d3scription from 'd3scription'; 96 | 97 | interface Data { 98 | x : number; 99 | y : number; 100 | desc : string; 101 | } 102 | 103 | // define some example data 104 | const data : Data[] = [ 105 | { 106 | x: 50, 107 | y: 100, 108 | desc: 'We are your friends...' 109 | }, 110 | { 111 | x: 200, 112 | y: 50, 113 | desc: 'I love it!' 114 | } 115 | ] 116 | 117 | // select SVG element and create main group 118 | const el = d3.select('#first-example') 119 | .append('g'); 120 | 121 | // setup plugin with description getter function and default options. 122 | // if you want to overwrite default z-index, offset or class name please see `api:setup:options section` 123 | const tipFactory = d3scription((d : Data) => d.desc); 124 | 125 | // create tip for our main group element 126 | const tip = tipFactory() 127 | .element(el); 128 | 129 | // set data to circles 130 | const circles = el.selectAll('.circle') 131 | .data(data); 132 | 133 | // draw circles 134 | const cEnter = circles.enter() 135 | .append('circle') 136 | .attr('class', 'circle') 137 | .attr('r', 30) 138 | .attr('cx', d => d.x) 139 | .attr('cy', d => d.y) 140 | // setup show and hide action on mouse events 141 | .on('mouseover', tip.show) 142 | .on('mouseout', tip.hide); 143 | ``` 144 | 145 | # Styles 146 | 147 | You can import or copy [default styles](css/style.css) to your project if you want. 148 | Anyway as you can see writing your own styles for tooltip is really simple. 149 | 150 | # API 151 | 152 | Api is design as three steps process to make reuse and flow as clean as possible. 153 | These steps are `setup` > `initialize` > `use`. Folloving paragraphs describes each step individually. 154 | 155 | ## Setup 156 | 157 | First you need to setup new Tip factory (you can think about it as alternative to subclassing base class with necessary options even it's not really uses classes at all). 158 | This is done using the only public function provided by d3scription out of the box - `de3scription([contentGetter], [optionalOptions])`. 159 | 160 | This function accept two parameters - `contentGetter` and `options`. 161 | 162 | **Content getter** is just regular function which takes `data` and returns `string` content of tip. 163 | This works the same way as many d3 methods like `.attr('x', [getter])` or `.style('fill', [getter])`. 164 | 165 | ### Options 166 | 167 | Are used for overwriting default settings of plugin. It's a **hash** where every key is optional. 168 | For typescript plugin exports this interface under name `Options`. 169 | There are all possible values: 170 | 171 | * `zIndex` sets css z-index of tip element (default is 100). 172 | * `class` set custom class name for element (default is `d3scription-tip`). 173 | * `offset["top"]` top offset of tip (default is `-10`). 174 | * `offset["left"]` left offset of tip (default is `10`). 175 | 176 | You can create one settuped tipFactory and reuse it on multiple places or create as many of these factories as you wish. 177 | 178 | ### Example 179 | 180 | ```js 181 | function getDescription(data) { 182 | return data.toolTipText; 183 | } 184 | var options = { 185 | zIndex: 1000, 186 | class: 'my-tooltip', 187 | offset: { 188 | top: 20, 189 | left: 20 190 | } 191 | } 192 | var myD3scription = d3Scription(getDescription, options); 193 | var defaultD3scription = d3scription(getDescription); 194 | ``` 195 | 196 | ## Factory 197 | 198 | Settup function return another function which takes **element** in which tip should be active. 199 | This is element in which tip will follow mouse. This function also creates final tip. 200 | You can create many tips from one factory using this function. 201 | 202 | ### Example 203 | 204 | ```js 205 | var element = d3.select('svg').append('g'); 206 | var tip = myD3scription().element(element); // this function was returned by setup 207 | ``` 208 | 209 | ## Tip 210 | 211 | Finally you'll have a tip instance returned by from factory (after passing element). 212 | Now you can call methods on this tip as you wish. Most common case is to `show(data)` and `hide()` 213 | on mouse events. you can also take advantage of `element(element)` for changing orginal element of tip 214 | or using `destroy()`. 215 | 216 | ## Tip API 217 | 218 | * `show(data)` sets content of tip and displays it. 219 | * `hide()` hides tip 220 | * `element(element)` sets new element for tip 221 | * `destroy()` removes tip from dom 222 | 223 | ## Basic Example of usage 224 | 225 | ```js 226 | // define circle elements and bind data for them 227 | var circles = el.selectAll('.circle') 228 | .data(data); 229 | 230 | // create circles and add tips actions to them 231 | var cEnter = circles.enter() 232 | .append('circle') 233 | .attr('class', 'circle') 234 | .attr('r', 30) 235 | .attr('cx', function(d) { return d.x; }) 236 | .attr('cy', function(d) { return d.y; }) 237 | // show tip on mouseover 238 | // NOTE: will use binded data for setting content of tip 239 | .on('mouseover', tip.show) 240 | // hide tip on mouseout event 241 | .on('mouseout', tip.hide); 242 | ``` 243 | # Changelog 244 | 245 | - v1.0.1 - update position on show (fixes situations where `show` is called but `mouseMove` event doesn't happen) 246 | - v1.0.0 - improve API 247 | - v0.0.2 - window edge collision detections 248 | - v0.0.1 - initial release 249 | 250 | # Building localy 251 | 252 | All PRs are welcome! This is why we tried to made whole development setup as simple as possible. 253 | 254 | Clone repository: 255 | 256 | ``` 257 | git clone git@github.com:GlobalWebIndex/d3scription.git 258 | ``` 259 | 260 | Install all dependecies via NPM and Bower: 261 | 262 | ``` 263 | npm install && bower install 264 | ``` 265 | 266 | The main file you want to work with is [index.ts](index.ts). There are also [demo examples](demo/) where you can play with plugin. 267 | 268 | ## Building project 269 | 270 | There are few handy npm scripts already settuped up. 271 | 272 | If you want to run project as watch run: 273 | 274 | ``` 275 | npm run watch 276 | ``` 277 | 278 | you can then open [demo/index.html](examples) in browser. Project will be compiled in background if you made any change to source. 279 | 280 | For building distribution please run following. 281 | 282 | ``` 283 | npm run compile 284 | ``` 285 | 286 | This will compile all versions of plugin (including commonjs for usage with NPM). 287 | 288 | # License 289 | 290 | MIT 291 | 292 | ## About GlobalWebIndex 293 | 294 | ![globalwebindex](https://pbs.twimg.com/profile_images/468332770624679937/wd2TMi0i_400x400.png) 295 | 296 | d3scription is maintained by GlobalWebIndex Ltd. 297 | 298 | See more about us at [www.globalwebindex.net](https://www.globalwebindex.net). 299 | -------------------------------------------------------------------------------- /d/d3.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for d3JS 2 | // Project: http://d3js.org/ 3 | // Definitions by: Alex Ford , Boris Yankov 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | declare namespace d3 { 7 | /** 8 | * The current version of D3.js. 9 | */ 10 | export var version: string; 11 | 12 | /** 13 | * Find the first element that matches the given selector string. 14 | */ 15 | export function select(selector: string): Selection; 16 | 17 | /** 18 | * Create a selection from the given node reference. 19 | */ 20 | export function select(node: EventTarget): Selection; 21 | 22 | /** 23 | * Find all elements that match the given selector string. 24 | */ 25 | export function selectAll(selector: string): Selection; 26 | 27 | /** 28 | * Create a selection from the given list of nodes. 29 | */ 30 | export function selectAll(nodes: EventTarget[]): Selection; 31 | 32 | /** 33 | * Returns the root selection (as if by d3.select(document.documentElement)). This function may be used for 'instanceof' tests, and extending its prototype will add properties to all selections. 34 | */ 35 | export function selection(): Selection; 36 | 37 | namespace selection { 38 | export var prototype: Selection; 39 | 40 | /** 41 | * Selections are grouped into arrays of nodes, with the parent tracked in the 'parentNode' property. 42 | */ 43 | interface Group extends Array { 44 | parentNode: EventTarget; 45 | } 46 | 47 | interface Update { 48 | /** 49 | * Retrieve a grouped selection. 50 | */ 51 | [index: number]: Group; 52 | 53 | /** 54 | * The number of groups in this selection. 55 | */ 56 | length: number; 57 | 58 | /** 59 | * Retrieve the value of the given attribute for the first node in the selection. 60 | * 61 | * @param name The attribute name to query. May be prefixed (see d3.ns.prefix). 62 | */ 63 | attr(name: string): string; 64 | 65 | /** 66 | * For all nodes, set the attribute to the specified constant value. Use null to remove. 67 | * 68 | * @param name The attribute name, optionally prefixed. 69 | * @param value The attribute value to use. Note that this is coerced to a string automatically. 70 | */ 71 | attr(name: string, value: Primitive): Update; 72 | 73 | /** 74 | * Derive an attribute value for each node in the selection based on bound data. 75 | * 76 | * @param name The attribute name, optionally prefixed. 77 | * @param value The function of the datum (the bound data item), index (the position in the subgrouping), and outer index (overall position in nested selections) which computes the attribute value. If the function returns null, the attribute is removed. 78 | */ 79 | attr(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive): Update; 80 | 81 | /** 82 | * Set multiple properties at once using an Object. D3 iterates over all enumerable properties and either sets or computes the attribute's value based on the corresponding entry in the Object. 83 | * 84 | * @param obj A key-value mapping corresponding to attributes and values. If the value is a simple string or number, it is taken as a constant. Otherwise, it is a function that derives the attribute value. 85 | */ 86 | attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }): Update; 87 | 88 | /** 89 | * Returns true if the first node in this selection has the given class list. If multiple classes are specified (i.e., "foo bar"), then returns true only if all classes match. 90 | * 91 | * @param name The class list to query. 92 | */ 93 | classed(name: string): boolean; 94 | 95 | /** 96 | * Adds (or removes) the given class list. 97 | * 98 | * @param name The class list to toggle. Spaces separate class names: "foo bar" is a list of two classes. 99 | * @param value If true, add the classes. If false, remove them. 100 | */ 101 | classed(name: string, value: boolean): Update; 102 | 103 | /** 104 | * Determine if the given class list should be toggled for each node in the selection. 105 | * 106 | * @param name The class list. Spaces separate multiple class names. 107 | * @param value The function to run for each node. Should return true to add the class to the node, or false to remove it. 108 | */ 109 | classed(name: string, value: (datum: Datum, index: number, outerIndex: number) => boolean): Update; 110 | 111 | /** 112 | * Set or derive classes for multiple class lists at once. 113 | * 114 | * @param obj An Object mapping class lists to values that are either plain booleans or functions that return booleans. 115 | */ 116 | classed(obj: { [key: string]: boolean | ((datum: Datum, index: number, outerIndex: number) => boolean) }): Update; 117 | 118 | /** 119 | * Retrieve the computed style value for the first node in the selection. 120 | * @param name The CSS property name to query 121 | */ 122 | style(name: string): string; 123 | 124 | /** 125 | * Set a style property for all nodes in the selection. 126 | * @param name the CSS property name 127 | * @param value the property value 128 | * @param priority if specified, either null or the string "important" (no exclamation mark) 129 | */ 130 | style(name: string, value: Primitive, priority?: string): Update; 131 | 132 | /** 133 | * Derive a property value for each node in the selection. 134 | * @param name the CSS property name 135 | * @param value the function to derive the value 136 | * @param priority if specified, either null or the string "important" (no exclamation mark) 137 | */ 138 | style(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive, priority?: string): Update; 139 | 140 | /** 141 | * Set a large number of CSS properties from an object. 142 | * 143 | * @param obj an Object whose keys correspond to CSS property names and values are either constants or functions that derive property values 144 | * @param priority if specified, either null or the string "important" (no exclamation mark) 145 | */ 146 | style(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }, priority?: string): Update; 147 | 148 | /** 149 | * Retrieve an arbitrary node property such as the 'checked' property of checkboxes, or the 'value' of text boxes. 150 | * 151 | * @param name the node's property to retrieve 152 | */ 153 | property(name: string): any; 154 | 155 | /** 156 | * For each node, set the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__. 157 | * 158 | * @param name the property name 159 | * @param value the property value 160 | */ 161 | property(name: string, value: any): Update; 162 | 163 | /** 164 | * For each node, derive the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__. 165 | * 166 | * @param name the property name 167 | * @param value the function used to derive the property's value 168 | */ 169 | property(name: string, value: (datum: Datum, index: number, outerIndex: number) => any): Update; 170 | 171 | /** 172 | * Set multiple node properties. Caveats apply: take care not to mutate special properties like __proto__. 173 | * 174 | * @param obj an Object whose keys correspond to node properties and values are either constants or functions that will compute a value. 175 | */ 176 | property(obj: { [key: string]: any | ((datum: Datum, index: number, outerIndex: number) => any) }): Update; 177 | 178 | /** 179 | * Retrieve the textContent of the first node in the selection. 180 | */ 181 | text(): string; 182 | 183 | /** 184 | * Set the textContent of each node in the selection. 185 | * @param value the text to use for all nodes 186 | */ 187 | text(value: Primitive): Update; 188 | 189 | /** 190 | * Compute the textContent of each node in the selection. 191 | * @param value the function which will compute the text 192 | */ 193 | text(value: (datum: Datum, index: number, outerIndex: number) => Primitive): Update; 194 | 195 | /** 196 | * Retrieve the HTML content of the first node in the selection. Uses 'innerHTML' internally and will not work with SVG or other elements without a polyfill. 197 | */ 198 | html(): string; 199 | 200 | /** 201 | * Set the HTML content of every node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill. 202 | * @param value the HTML content to use. 203 | */ 204 | html(value: string): Selection; 205 | 206 | /** 207 | * Compute the HTML content for each node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill. 208 | * @param value the function to compute HTML content 209 | */ 210 | html(value: (datum: Datum, index: number, outerIndex: number) => string): Selection; 211 | 212 | /** 213 | * Appends a new child to each node in the selection. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children. 214 | * 215 | * @param name the element name to append. May be prefixed (see d3.ns.prefix). 216 | */ 217 | append(name: string): Selection; 218 | 219 | /** 220 | * Appends a new child to each node in the selection by computing a new node. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children. 221 | * 222 | * @param name the function to compute a new element 223 | */ 224 | append(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update; 225 | 226 | /** 227 | * Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. 228 | * @param name the element name to append. May be prefixed (see d3.ns.prefix). 229 | * @param before the selector to determine position (e.g., ":first-child") 230 | */ 231 | insert(name: string, before: string): Update; 232 | 233 | /** 234 | * Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. 235 | * @param name the element name to append. May be prefixed (see d3.ns.prefix). 236 | * @param before a function to determine the node to use as the next sibling 237 | */ 238 | insert(name: string, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update; 239 | 240 | /** 241 | * Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. 242 | * @param name the function to compute a new child 243 | * @param before the selector to determine position (e.g., ":first-child") 244 | */ 245 | insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: string): Update; 246 | 247 | /** 248 | * Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. 249 | * @param name the function to compute a new child 250 | * @param before a function to determine the node to use as the next sibling 251 | */ 252 | insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update; 253 | 254 | /** 255 | * Removes the elements from the DOM. They are in a detached state and may be re-added (though there is currently no dedicated API for doing so). 256 | */ 257 | remove(): Update; 258 | 259 | /** 260 | * Retrieves the data bound to the first group in this selection. 261 | */ 262 | data(): Datum[]; 263 | 264 | /** 265 | * Binds data to this selection. 266 | * @param data the array of data to bind to this selection 267 | * @param key the optional function to determine the unique key for each piece of data. When unspecified, uses the index of the element. 268 | */ 269 | data(data: NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): Update; 270 | 271 | /** 272 | * Derives data to bind to this selection. 273 | * @param data the function to derive data. Must return an array. 274 | * @param key the optional function to determine the unique key for each data item. When unspecified, uses the index of the element. 275 | */ 276 | data(data: (datum: Datum, index: number, outerIndex: number) => NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): Update; 277 | 278 | /** 279 | * Filters the selection, returning only those nodes that match the given CSS selector. 280 | * @param selector the CSS selector 281 | */ 282 | filter(selector: string): Update; 283 | 284 | /** 285 | * Filters the selection, returning only those nodes for which the given function returned true. 286 | * @param selector the filter function 287 | */ 288 | filter(selector: (datum: Datum, index: number, outerIndex: number) => boolean): Update; 289 | 290 | /** 291 | * Return the data item bound to the first element in the selection. 292 | */ 293 | datum(): Datum; 294 | 295 | /** 296 | * Derive the data item for each node in the selection. Useful for situations such as the HTML5 'dataset' attribute. 297 | * @param value the function to compute data for each node 298 | */ 299 | datum(value: (datum: Datum, index: number, outerIndex: number) => NewDatum): Update; 300 | 301 | /** 302 | * Set the data item for each node in the selection. 303 | * @param value the constant element to use for each node 304 | */ 305 | datum(value: NewDatum): Update; 306 | 307 | /** 308 | * Reorders nodes in the selection based on the given comparator. Nodes are re-inserted into the document once sorted. 309 | * @param comparator the comparison function, which defaults to d3.ascending 310 | */ 311 | sort(comparator?: (a: Datum, b: Datum) => number): Update; 312 | 313 | /** 314 | * Reorders nodes in the document to match the selection order. More efficient than calling sort() if the selection is already ordered. 315 | */ 316 | order(): Update; 317 | 318 | /** 319 | * Returns the listener (if any) for the given event. 320 | * @param type the type of event to load the listener for. May have a namespace (e.g., ".foo") at the end. 321 | */ 322 | on(type: string): (datum: Datum, index: number, outerIndex: number) => any; 323 | 324 | /** 325 | * Adds a listener for the specified event. If one was already registered, it is removed before the new listener is added. The return value of the listener function is ignored. 326 | * @param type the of event to listen to. May have a namespace (e.g., ".foo") at the end. 327 | * @param listener an event listener function, or null to unregister 328 | * @param capture sets the DOM useCapture flag 329 | */ 330 | on(type: string, listener: (datum: Datum, index: number, outerIndex: number) => any, capture?: boolean): Update; 331 | 332 | /** 333 | * Begins a new transition. Interrupts any active transitions of the same name. 334 | * @param name the transition name (defaults to "") 335 | */ 336 | transition(name?: string): Transition; 337 | 338 | /** 339 | * Interrupts the active transition of the provided name. Does not cancel scheduled transitions. 340 | * @param name the transition name (defaults to "") 341 | */ 342 | interrupt(name?: string): Update; 343 | 344 | /** 345 | * Creates a subselection by finding the first descendent matching the selector string. Bound data is inherited. 346 | * @param selector the CSS selector to match against 347 | */ 348 | select(selector: string): Update; 349 | 350 | /** 351 | * Creates a subselection by using a function to find descendent elements. Bound data is inherited. 352 | * @param selector the function to find matching descendants 353 | */ 354 | select(selector: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update; 355 | 356 | /** 357 | * Creates a subselection by finding all descendents that match the given selector. Bound data is not inherited. 358 | * @param selector the CSS selector to match against 359 | */ 360 | selectAll(selector: string): Update; 361 | 362 | /** 363 | * Creates a subselection by using a function to find descendent elements. Bound data is not inherited. 364 | * @param selector the function to find matching descendents 365 | */ 366 | selectAll(selector: (datum: Datum, index: number, outerIndex: number) => Array | NodeList): Update; 367 | 368 | /** 369 | * Invoke the given function for each element in the selection. The return value of the function is ignored. 370 | * @param func the function to invoke 371 | */ 372 | each(func: (datum: Datum, index: number, outerIndex: number) => any): Update; 373 | 374 | /** 375 | * Call a function on the selection. sel.call(foo) is equivalent to foo(sel). 376 | * @param func the function to call on the selection 377 | * @param args any optional args 378 | */ 379 | call(func: (sel: Update, ...args: any[]) => any, ...args: any[]): Update; 380 | 381 | /** 382 | * Returns true if the current selection is empty. 383 | */ 384 | empty(): boolean; 385 | 386 | /** 387 | * Returns the first non-null element in the selection, or null otherwise. 388 | */ 389 | node(): MyNode; 390 | 391 | /** 392 | * Returns the total number of elements in the selection. 393 | */ 394 | size(): number; 395 | 396 | /** 397 | * Returns the placeholder nodes for each data element for which no corresponding DOM element was found. 398 | */ 399 | enter(): Enter; 400 | 401 | /** 402 | * Returns a selection for those DOM nodes for which no new data element was found. 403 | */ 404 | exit(): Selection; 405 | } 406 | 407 | interface Enter { 408 | append(name: string): Selection; 409 | append(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection; 410 | 411 | insert(name: string, before?: string): Selection; 412 | insert(name: string, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection; 413 | insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before?: string): Selection; 414 | insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection; 415 | 416 | select(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection; 417 | call(func: (selection: Enter, ...args: any[]) => any, ...args: any[]): Enter; 418 | 419 | empty(): boolean; 420 | size(): number; 421 | } 422 | } 423 | 424 | /** 425 | * Administrivia: JavaScript primitive types, or "things that toString() predictably". 426 | */ 427 | export type Primitive = number | string | boolean; 428 | 429 | /** 430 | * Administrivia: anything with a valueOf(): number method is comparable, so we allow it in numeric operations 431 | */ 432 | interface Numeric { 433 | valueOf(): number; 434 | } 435 | 436 | /** 437 | * A grouped array of nodes. 438 | * @param Datum the data bound to this selection. 439 | */ 440 | interface Selection { 441 | /** 442 | * Retrieve a grouped selection. 443 | */ 444 | [index: number]: selection.Group; 445 | 446 | /** 447 | * The number of groups in this selection. 448 | */ 449 | length: number; 450 | 451 | /** 452 | * Retrieve the value of the given attribute for the first node in the selection. 453 | * 454 | * @param name The attribute name to query. May be prefixed (see d3.ns.prefix). 455 | */ 456 | attr(name: string): string; 457 | 458 | /** 459 | * For all nodes, set the attribute to the specified constant value. Use null to remove. 460 | * 461 | * @param name The attribute name, optionally prefixed. 462 | * @param value The attribute value to use. Note that this is coerced to a string automatically. 463 | */ 464 | attr(name: string, value: Primitive): Selection; 465 | 466 | /** 467 | * Derive an attribute value for each node in the selection based on bound data. 468 | * 469 | * @param name The attribute name, optionally prefixed. 470 | * @param value The function of the datum (the bound data item), index (the position in the subgrouping), and outer index (overall position in nested selections) which computes the attribute value. If the function returns null, the attribute is removed. 471 | */ 472 | attr(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive): Selection; 473 | 474 | /** 475 | * Set multiple properties at once using an Object. D3 iterates over all enumerable properties and either sets or computes the attribute's value based on the corresponding entry in the Object. 476 | * 477 | * @param obj A key-value mapping corresponding to attributes and values. If the value is a simple string or number, it is taken as a constant. Otherwise, it is a function that derives the attribute value. 478 | */ 479 | attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }): Selection; 480 | 481 | /** 482 | * Returns true if the first node in this selection has the given class list. If multiple classes are specified (i.e., "foo bar"), then returns true only if all classes match. 483 | * 484 | * @param name The class list to query. 485 | */ 486 | classed(name: string): boolean; 487 | 488 | /** 489 | * Adds (or removes) the given class list. 490 | * 491 | * @param name The class list to toggle. Spaces separate class names: "foo bar" is a list of two classes. 492 | * @param value If true, add the classes. If false, remove them. 493 | */ 494 | classed(name: string, value: boolean): Selection; 495 | 496 | /** 497 | * Determine if the given class list should be toggled for each node in the selection. 498 | * 499 | * @param name The class list. Spaces separate multiple class names. 500 | * @param value The function to run for each node. Should return true to add the class to the node, or false to remove it. 501 | */ 502 | classed(name: string, value: (datum: Datum, index: number, outerIndex: number) => boolean): Selection; 503 | 504 | /** 505 | * Set or derive classes for multiple class lists at once. 506 | * 507 | * @param obj An Object mapping class lists to values that are either plain booleans or functions that return booleans. 508 | */ 509 | classed(obj: { [key: string]: boolean | ((datum: Datum, index: number, outerIndex: number) => boolean) }): Selection; 510 | 511 | /** 512 | * Retrieve the computed style value for the first node in the selection. 513 | * @param name The CSS property name to query 514 | */ 515 | style(name: string): string; 516 | 517 | /** 518 | * Set a style property for all nodes in the selection. 519 | * @param name the CSS property name 520 | * @param value the property value 521 | * @param priority if specified, either null or the string "important" (no exclamation mark) 522 | */ 523 | style(name: string, value: Primitive, priority?: string): Selection; 524 | 525 | /** 526 | * Derive a property value for each node in the selection. 527 | * @param name the CSS property name 528 | * @param value the function to derive the value 529 | * @param priority if specified, either null or the string "important" (no exclamation mark) 530 | */ 531 | style(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive, priority?: string): Selection; 532 | 533 | /** 534 | * Set a large number of CSS properties from an object. 535 | * 536 | * @param obj an Object whose keys correspond to CSS property names and values are either constants or functions that derive property values 537 | * @param priority if specified, either null or the string "important" (no exclamation mark) 538 | */ 539 | style(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }, priority?: string): Selection; 540 | 541 | /** 542 | * Retrieve an arbitrary node property such as the 'checked' property of checkboxes, or the 'value' of text boxes. 543 | * 544 | * @param name the node's property to retrieve 545 | */ 546 | property(name: string): any; 547 | 548 | /** 549 | * For each node, set the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__. 550 | * 551 | * @param name the property name 552 | * @param value the property value 553 | */ 554 | property(name: string, value: any): Selection; 555 | 556 | /** 557 | * For each node, derive the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__. 558 | * 559 | * @param name the property name 560 | * @param value the function used to derive the property's value 561 | */ 562 | property(name: string, value: (datum: Datum, index: number, outerIndex: number) => any): Selection; 563 | 564 | /** 565 | * Set multiple node properties. Caveats apply: take care not to mutate special properties like __proto__. 566 | * 567 | * @param obj an Object whose keys correspond to node properties and values are either constants or functions that will compute a value. 568 | */ 569 | property(obj: { [key: string]: any | ((datum: Datum, index: number, innerInder: number) => any) }): Selection; 570 | 571 | /** 572 | * Retrieve the textContent of the first node in the selection. 573 | */ 574 | text(): string; 575 | 576 | /** 577 | * Set the textContent of each node in the selection. 578 | * @param value the text to use for all nodes 579 | */ 580 | text(value: Primitive): Selection; 581 | 582 | /** 583 | * Compute the textContent of each node in the selection. 584 | * @param value the function which will compute the text 585 | */ 586 | text(value: (datum: Datum, index: number, outerIndex: number) => Primitive): Selection; 587 | 588 | /** 589 | * Retrieve the HTML content of the first node in the selection. Uses 'innerHTML' internally and will not work with SVG or other elements without a polyfill. 590 | */ 591 | html(): string; 592 | 593 | /** 594 | * Set the HTML content of every node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill. 595 | * @param value the HTML content to use. 596 | */ 597 | html(value: string): Selection; 598 | 599 | /** 600 | * Compute the HTML content for each node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill. 601 | * @param value the function to compute HTML content 602 | */ 603 | html(value: (datum: Datum, index: number, outerIndex: number) => string): Selection; 604 | 605 | /** 606 | * Appends a new child to each node in the selection. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children. 607 | * 608 | * @param name the element name to append. May be prefixed (see d3.ns.prefix). 609 | */ 610 | append(name: string): Selection; 611 | 612 | /** 613 | * Appends a new child to each node in the selection by computing a new node. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children. 614 | * 615 | * @param name the function to compute a new element 616 | */ 617 | append(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection; 618 | 619 | /** 620 | * Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. 621 | * @param name the element name to append. May be prefixed (see d3.ns.prefix). 622 | * @param before the selector to determine position (e.g., ":first-child") 623 | */ 624 | insert(name: string, before: string): Selection; 625 | 626 | /** 627 | * Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. 628 | * @param name the element name to append. May be prefixed (see d3.ns.prefix). 629 | * @param before a function to determine the node to use as the next sibling 630 | */ 631 | insert(name: string, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection; 632 | 633 | /** 634 | * Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. 635 | * @param name the function to compute a new child 636 | * @param before the selector to determine position (e.g., ":first-child") 637 | */ 638 | insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: string): Selection; 639 | 640 | /** 641 | * Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. 642 | * @param name the function to compute a new child 643 | * @param before a function to determine the node to use as the next sibling 644 | */ 645 | insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection; 646 | 647 | /** 648 | * Removes the elements from the DOM. They are in a detached state and may be re-added (though there is currently no dedicated API for doing so). 649 | */ 650 | remove(): Selection; 651 | 652 | /** 653 | * Retrieves the data bound to the first group in this selection. 654 | */ 655 | data(): Datum[]; 656 | 657 | /** 658 | * Binds data to this selection. 659 | * @param data the array of data to bind to this selection 660 | * @param key the optional function to determine the unique key for each piece of data. When unspecified, uses the index of the element. 661 | */ 662 | data(data: NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): selection.Update; 663 | 664 | /** 665 | * Derives data to bind to this selection. 666 | * @param data the function to derive data. Must return an array. 667 | * @param key the optional function to determine the unique key for each data item. When unspecified, uses the index of the element. 668 | */ 669 | data(data: (datum: Datum, index: number, outerIndex: number) => NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): selection.Update; 670 | 671 | /** 672 | * Filters the selection, returning only those nodes that match the given CSS selector. 673 | * @param selector the CSS selector 674 | */ 675 | filter(selector: string): Selection; 676 | 677 | /** 678 | * Filters the selection, returning only those nodes for which the given function returned true. 679 | * @param selector the filter function 680 | */ 681 | filter(selector: (datum: Datum, index: number, outerIndex: number) => boolean): Selection; 682 | 683 | /** 684 | * Return the data item bound to the first element in the selection. 685 | */ 686 | datum(): Datum; 687 | 688 | /** 689 | * Derive the data item for each node in the selection. Useful for situations such as the HTML5 'dataset' attribute. 690 | * @param value the function to compute data for each node 691 | */ 692 | datum(value: (datum: Datum, index: number, outerIndex: number) => NewDatum): Selection; 693 | 694 | /** 695 | * Set the data item for each node in the selection. 696 | * @param value the constant element to use for each node 697 | */ 698 | datum(value: NewDatum): Selection; 699 | 700 | /** 701 | * Reorders nodes in the selection based on the given comparator. Nodes are re-inserted into the document once sorted. 702 | * @param comparator the comparison function, which defaults to d3.ascending 703 | */ 704 | sort(comparator?: (a: Datum, b: Datum) => number): Selection; 705 | 706 | /** 707 | * Reorders nodes in the document to match the selection order. More efficient than calling sort() if the selection is already ordered. 708 | */ 709 | order(): Selection; 710 | 711 | /** 712 | * Returns the listener (if any) for the given event. 713 | * @param type the type of event to load the listener for. May have a namespace (e.g., ".foo") at the end. 714 | */ 715 | on(type: string): (datum: Datum, index: number, outerIndex: number) => any; 716 | 717 | /** 718 | * Adds a listener for the specified event. If one was already registered, it is removed before the new listener is added. The return value of the listener function is ignored. 719 | * @param type the of event to listen to. May have a namespace (e.g., ".foo") at the end. 720 | * @param listener an event listener function, or null to unregister 721 | * @param capture sets the DOM useCapture flag 722 | */ 723 | on(type: string, listener: (datum: Datum, index: number, outerIndex: number) => any, capture?: boolean): Selection; 724 | 725 | /** 726 | * Begins a new transition. Interrupts any active transitions of the same name. 727 | * @param name the transition name (defaults to "") 728 | */ 729 | transition(name?: string): Transition; 730 | 731 | /** 732 | * Interrupts the active transition of the provided name. Does not cancel scheduled transitions. 733 | * @param name the transition name (defaults to "") 734 | */ 735 | interrupt(name?: string): Selection; 736 | 737 | /** 738 | * Creates a subselection by finding the first descendent matching the selector string. Bound data is inherited. 739 | * @param selector the CSS selector to match against 740 | */ 741 | select(selector: string): Selection; 742 | 743 | /** 744 | * Creates a subselection by using a function to find descendent elements. Bound data is inherited. 745 | * @param selector the function to find matching descendants 746 | */ 747 | select(selector: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection; 748 | 749 | /** 750 | * Creates a subselection by finding all descendents that match the given selector. Bound data is not inherited. 751 | * @param selector the CSS selector to match against 752 | */ 753 | selectAll(selector: string): Selection; 754 | 755 | /** 756 | * Creates a subselection by finding all descendants that match the given selector. Bound data is not inherited. 757 | * 758 | * Use this overload when data-binding a subselection (that is, sel.selectAll('.foo').data(d => ...)). The type will carry over. 759 | */ 760 | selectAll(selector: string): Selection; 761 | 762 | /** 763 | * Creates a subselection by using a function to find descendent elements. Bound data is not inherited. 764 | * @param selector the function to find matching descendents 765 | */ 766 | selectAll(selector: (datum: Datum, index: number, outerIndex: number) => Array | NodeList): Selection; 767 | 768 | /** 769 | * Creates a subselection by using a function to find descendent elements. Bound data is not inherited. 770 | * 771 | * Use this overload when data-binding a subselection (that is, sel.selectAll('.foo').data(d => ...)). The type will carry over. 772 | * @param selector the function to find matching descendents 773 | */ 774 | selectAll(selector: (datum: Datum, index: number, outerIndex: number) => Array | NodeList): Selection; 775 | 776 | /** 777 | * Invoke the given function for each element in the selection. The return value of the function is ignored. 778 | * @param func the function to invoke 779 | */ 780 | each(func: (datum: Datum, index: number, outerIndex: number) => any): Selection; 781 | 782 | /** 783 | * Call a function on the selection. sel.call(foo) is equivalent to foo(sel). 784 | * @param func the function to call on the selection 785 | * @param args any optional args 786 | */ 787 | call(func: (sel: Selection, ...args: any[]) => any, ...args: any[]): Selection; 788 | 789 | /** 790 | * Returns true if the current selection is empty. 791 | */ 792 | empty(): boolean; 793 | 794 | /** 795 | * Returns the first non-null element in the selection, or null otherwise. 796 | */ 797 | node(): MyNode; 798 | 799 | /** 800 | * Returns the total number of elements in the selection. 801 | */ 802 | size(): number; 803 | } 804 | 805 | export function transition(): Transition; 806 | namespace transition { 807 | export var prototype: Transition; 808 | } 809 | 810 | interface Transition { 811 | 812 | transition(): Transition; 813 | 814 | delay(): number; 815 | delay(delay: number): Transition; 816 | delay(delay: (datum: Datum, index: number, outerIndex: number) => number): Transition; 817 | 818 | duration(): number; 819 | duration(duration: number): Transition; 820 | duration(duration: (datum: Datum, index: number, outerIndex: number) => number): Transition; 821 | 822 | ease(): (t: number) => number; 823 | ease(value: string, ...args: any[]): Transition; 824 | ease(value: (t: number) => number): Transition; 825 | 826 | attr(name: string, value: Primitive): Transition; 827 | attr(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive): Transition; 828 | attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }): Transition; 829 | 830 | attrTween(name: string, tween: (datum: Datum, index: number, attr: string) => (t: number) => Primitive): Transition; 831 | 832 | style(name: string, value: Primitive, priority?: string): Transition; 833 | style(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive, priority?: string): Transition; 834 | style(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }, priority?: string): Transition; 835 | 836 | styleTween(name: string, tween: (datum: Datum, index: number, attr: string) => (t: number) => Primitive, priority?: string): Transition; 837 | 838 | text(value: Primitive): Transition; 839 | text(value: (datum: Datum, index: number, outerIndex: number) => Primitive): Transition; 840 | 841 | tween(name: string, factory: () => (t: number) => any): Transition; 842 | 843 | remove(): Transition; 844 | 845 | select(selector: string): Transition; 846 | select(selector: (d: Datum, i: number) => EventTarget): Transition; 847 | 848 | selectAll(selector: string): Transition; 849 | selectAll(selector: (d: Datum, i: number) => EventTarget[]): Transition; 850 | 851 | filter(selector: string): Transition; 852 | filter(selector: (d: Datum, i: number) => boolean): Transition; 853 | 854 | each(type: string, listener: (d: Datum, i: number) => any): Transition; 855 | each(listener: (d: Datum, i: number) => any): Transition; 856 | 857 | call(func: (transition: Transition, ...args: any[]) => any, ...args: any[]): Transition; 858 | 859 | empty(): boolean; 860 | node(): MyNode; 861 | size(): number; 862 | } 863 | 864 | export function ease(type: 'linear'): (t: number) => number; 865 | export function ease(type: 'linear-in'): (t: number) => number; 866 | export function ease(type: 'linear-out'): (t: number) => number; 867 | export function ease(type: 'linear-in-out'): (t: number) => number; 868 | export function ease(type: 'linear-out-in'): (t: number) => number; 869 | 870 | export function ease(type: 'poly', k: number): (t: number) => number; 871 | export function ease(type: 'poly-in', k: number): (t: number) => number; 872 | export function ease(type: 'poly-out', k: number): (t: number) => number; 873 | export function ease(type: 'poly-in-out', k: number): (t: number) => number; 874 | export function ease(type: 'poly-out-in', k: number): (t: number) => number; 875 | 876 | export function ease(type: 'quad'): (t: number) => number; 877 | export function ease(type: 'quad-in'): (t: number) => number; 878 | export function ease(type: 'quad-out'): (t: number) => number; 879 | export function ease(type: 'quad-in-out'): (t: number) => number; 880 | export function ease(type: 'quad-out-in'): (t: number) => number; 881 | 882 | export function ease(type: 'cubic'): (t: number) => number; 883 | export function ease(type: 'cubic-in'): (t: number) => number; 884 | export function ease(type: 'cubic-out'): (t: number) => number; 885 | export function ease(type: 'cubic-in-out'): (t: number) => number; 886 | export function ease(type: 'cubic-out-in'): (t: number) => number; 887 | 888 | export function ease(type: 'sin'): (t: number) => number; 889 | export function ease(type: 'sin-in'): (t: number) => number; 890 | export function ease(type: 'sin-out'): (t: number) => number; 891 | export function ease(type: 'sin-in-out'): (t: number) => number; 892 | export function ease(type: 'sin-out-in'): (t: number) => number; 893 | 894 | export function ease(type: 'circle'): (t: number) => number; 895 | export function ease(type: 'circle-in'): (t: number) => number; 896 | export function ease(type: 'circle-out'): (t: number) => number; 897 | export function ease(type: 'circle-in-out'): (t: number) => number; 898 | export function ease(type: 'circle-out-in'): (t: number) => number; 899 | 900 | export function ease(type: 'elastic', a?: number, b?: number): (t: number) => number; 901 | export function ease(type: 'elastic-in', a?: number, b?: number): (t: number) => number; 902 | export function ease(type: 'elastic-out', a?: number, b?: number): (t: number) => number; 903 | export function ease(type: 'elastic-in-out', a?: number, b?: number): (t: number) => number; 904 | export function ease(type: 'elastic-out-in', a?: number, b?: number): (t: number) => number; 905 | 906 | export function ease(type: 'back', s: number): (t: number) => number; 907 | export function ease(type: 'back-in', s: number): (t: number) => number; 908 | export function ease(type: 'back-out', s: number): (t: number) => number; 909 | export function ease(type: 'back-in-out', s: number): (t: number) => number; 910 | export function ease(type: 'back-out-in', s: number): (t: number) => number; 911 | 912 | export function ease(type: 'bounce'): (t: number) => number; 913 | export function ease(type: 'bounce-in'): (t: number) => number; 914 | export function ease(type: 'bounce-out'): (t: number) => number; 915 | export function ease(type: 'bounce-in-out'): (t: number) => number; 916 | export function ease(type: 'bounce-out-in'): (t: number) => number; 917 | 918 | export function ease(type: string, ...args: any[]): (t: number) => number; 919 | 920 | export function timer(func: () => any, delay?: number, time?: number): void; 921 | 922 | namespace timer { 923 | export function flush(): void; 924 | } 925 | 926 | interface BaseEvent { 927 | type: string; 928 | sourceEvent?: Event; 929 | } 930 | 931 | /** 932 | * Define a D3-specific ZoomEvent per https://github.com/mbostock/d3/wiki/Zoom-Behavior#event 933 | */ 934 | interface ZoomEvent extends BaseEvent { 935 | scale: number; 936 | translate: [number, number]; 937 | } 938 | 939 | /** 940 | * Define a D3-specific DragEvent per https://github.com/mbostock/d3/wiki/Drag-Behavior#on 941 | */ 942 | interface DragEvent extends BaseEvent { 943 | x: number; 944 | y: number; 945 | dx: number; 946 | dy: number; 947 | } 948 | 949 | interface MEvent extends MouseEvent { 950 | pageX : number; 951 | pageY : number; 952 | } 953 | 954 | /** 955 | * The current event's value. Use this variable in a handler registered with `selection.on`. 956 | */ 957 | export var event: MEvent; 958 | 959 | /** 960 | * Returns the x and y coordinates of the mouse relative to the provided container element, using d3.event for the mouse's position on the page. 961 | * @param container the container element (e.g. an SVG element) 962 | */ 963 | export function mouse(container: EventTarget): [number, number]; 964 | 965 | /** 966 | * Given a container element and a touch identifier, determine the x and y coordinates of the touch. 967 | * @param container the container element (e.g., an SVG element) 968 | * @param identifier the given touch identifier 969 | */ 970 | export function touch(container: EventTarget, identifer: number): [number, number]; 971 | 972 | /** 973 | * Given a container element, a list of touches, and a touch identifier, determine the x and y coordinates of the touch. 974 | * @param container the container element (e.g., an SVG element) 975 | * @param identifier the given touch identifier 976 | */ 977 | export function touch(container: EventTarget, touches: TouchList, identifer: number): [number, number]; 978 | 979 | /** 980 | * Given a container element and an optional list of touches, return the position of every touch relative to the container. 981 | * @param container the container element 982 | * @param touches an optional list of touches (defaults to d3.event.touches) 983 | */ 984 | export function touches(container: EventTarget, touches?: TouchList): Array<[number, number]>; 985 | 986 | // NB. this is limited to primitive values due to D3's use of the <, >, and >= operators. Results get weird for object instances. 987 | /** 988 | * Compares two primitive values for sorting (in ascending order). 989 | */ 990 | export function ascending(a: Primitive, b: Primitive): number; 991 | 992 | /** 993 | * Compares two primitive values for sorting (in ascending order). 994 | */ 995 | export function descending(a: Primitive, b: Primitive): number; 996 | 997 | /** 998 | * Return the minimum value in the array using natural order. 999 | */ 1000 | export function min(array: number[]): number; 1001 | 1002 | /** 1003 | * Return the minimum value in the array using natural order. 1004 | */ 1005 | export function min(array: string[]): string; 1006 | 1007 | /** 1008 | * Return the minimum value in the array using natural order. 1009 | */ 1010 | export function min(array: T[]): T; 1011 | 1012 | /** 1013 | * Return the minimum value in the array using natural order. 1014 | */ 1015 | export function min(array: T[], accessor: (datum: T, index: number) => number): number; 1016 | 1017 | /** 1018 | * Return the minimum value in the array using natural order. 1019 | */ 1020 | export function min(array: T[], accessor: (datum: T, index: number) => string): string; 1021 | 1022 | /** 1023 | * Return the minimum value in the array using natural order. 1024 | */ 1025 | export function min(array: T[], accessor: (datum: T, index: number) => U): U; 1026 | 1027 | /** 1028 | * Return the maximum value in the array of numbers using natural order. 1029 | */ 1030 | export function max(array: number[]): number; 1031 | 1032 | /** 1033 | * Return the maximum value in the array of strings using natural order. 1034 | */ 1035 | export function max(array: string[]): string; 1036 | 1037 | /** 1038 | * Return the maximum value in the array of numbers using natural order. 1039 | */ 1040 | export function max(array: T[]): T; 1041 | 1042 | /** 1043 | * Return the maximum value in the array using natural order and a projection function to map values to numbers. 1044 | */ 1045 | export function max(array: T[], accessor: (datum: T, index: number) => number): number; 1046 | 1047 | /** 1048 | * Return the maximum value in the array using natural order and a projection function to map values to strings. 1049 | */ 1050 | export function max(array: T[], accessor: (datum: T, index: number) => string): string; 1051 | 1052 | /** 1053 | * Return the maximum value in the array using natural order and a projection function to map values to easily-sorted values. 1054 | */ 1055 | export function max(array: T[], accessor: (datum: T, index: number) => U): U; 1056 | 1057 | /** 1058 | * Return the min and max simultaneously. 1059 | */ 1060 | export function extent(array: number[]): [number, number]; 1061 | 1062 | /** 1063 | * Return the min and max simultaneously. 1064 | */ 1065 | export function extent(array: string[]): [string, string]; 1066 | 1067 | /** 1068 | * Return the min and max simultaneously. 1069 | */ 1070 | export function extent(array: T[]): [T, T]; 1071 | 1072 | /** 1073 | * Return the min and max simultaneously. 1074 | */ 1075 | export function extent(array: Array): [T | Primitive, T | Primitive]; 1076 | 1077 | /** 1078 | * Return the min and max simultaneously. 1079 | */ 1080 | export function extent(array: T[], accessor: (datum: T, index: number) => number): [number, number]; 1081 | 1082 | /** 1083 | * Return the min and max simultaneously. 1084 | */ 1085 | export function extent(array: T[], accessor: (datum: T, index: number) => string): [string, string]; 1086 | 1087 | /** 1088 | * Return the min and max simultaneously. 1089 | */ 1090 | export function extent(array: T[], accessor: (datum: T, index: number) => Date): [Date, Date]; 1091 | 1092 | /** 1093 | * Return the min and max simultaneously. 1094 | */ 1095 | export function extent(array: T[], accessor: (datum: T, index: number) => U): [U | Primitive, U | Primitive]; 1096 | 1097 | /** 1098 | * Compute the sum of an array of numbers. 1099 | */ 1100 | export function sum(array: number[]): number; 1101 | 1102 | /** 1103 | * Compute the sum of an array, using the given accessor to convert values to numbers. 1104 | */ 1105 | export function sum(array: T[], accessor: (datum: T, index: number) => number): number; 1106 | 1107 | export function mean(array: number[]): number; 1108 | export function mean(array: T[], accessor: (datum: T, index: number) => number): number; 1109 | 1110 | /** 1111 | * Compute the median of an array of numbers (the 0.5-quantile). 1112 | */ 1113 | export function median(array: number[]): number; 1114 | export function median(datum: T[], accessor: (datum: T, index: number) => number): number; 1115 | 1116 | export function quantile(array: number[], p: number): number; 1117 | 1118 | export function variance(array: number[]): number; 1119 | export function variance(array: T[], accessor: (datum: T, index: number) => number): number; 1120 | 1121 | export function deviation(array: number[]): number; 1122 | export function deviation(array: T[], accessor: (datum: T, index: number) => number): number; 1123 | 1124 | export function bisectLeft(array: T[], x: T, lo?: number, hi?: number): number; 1125 | 1126 | export var bisect: typeof bisectRight; 1127 | 1128 | export function bisectRight(array: T[], x: T, lo?: number, hi?: number): number; 1129 | 1130 | export function bisector(accessor: (x: T) => U): { 1131 | left: (array: T[], x: U, lo?: number, hi?: number) => number; 1132 | right: (array: T[], x: U, lo?: number, hi?: number) => number; 1133 | } 1134 | 1135 | export function bisector(comparator: (a: T, b: U) => number): { 1136 | left: (array: T[], x: U, lo?: number, hi?: number) => number; 1137 | right: (array: T[], x: U, lo?: number, hi?: number) => number; 1138 | } 1139 | 1140 | export function shuffle(array: T[], lo?: number, hi?: number): T[]; 1141 | 1142 | /** 1143 | * Returns the enumerable property names of the specified object. 1144 | * @param object a JavaScript object 1145 | */ 1146 | export function keys(object: Object): string[]; 1147 | 1148 | /** 1149 | * Returns an array containing the property values of the specified object. 1150 | */ 1151 | export function values(object: { [key: string]: T }): T[]; 1152 | /** 1153 | * Returns an array containing the property values of the specified object. 1154 | */ 1155 | export function values(object: { [key: number]: T }): T[]; 1156 | /** 1157 | * Returns an array containing the property values of the specified object. 1158 | */ 1159 | export function values(object: Object): any[]; 1160 | 1161 | /** 1162 | * Returns an array of key-value pairs containing the property values of the specified object. 1163 | */ 1164 | export function entries(object: { [key: string]: T }): { key: string; value: T }[]; 1165 | 1166 | /** 1167 | * Returns an array of key-value pairs containing the property values of the specified object. 1168 | */ 1169 | export function entries(object: { [key: number]: T }): { key: string; value: T }[]; 1170 | 1171 | /** 1172 | * Returns an array of key-value pairs containing the property values of the specified object. 1173 | */ 1174 | export function entries(object: Object): { key: string; value: any }[]; 1175 | 1176 | /** 1177 | * A shim for ES6 maps. The implementation uses a JavaScript object internally, and thus keys are limited to strings. 1178 | */ 1179 | interface Map { 1180 | /** 1181 | * Does the map contain the given key? 1182 | */ 1183 | has(key: string): boolean; 1184 | 1185 | /** 1186 | * Retrieve the value for the given key. Returns undefined if there is no value stored. 1187 | */ 1188 | get(key: string): T; 1189 | 1190 | /** 1191 | * Set the value for the given key. Returns the new value. 1192 | */ 1193 | set(key: string, value: T): T; 1194 | 1195 | /** 1196 | * Remove the value for the given key. Returns true if there was a value and false otherwise. 1197 | */ 1198 | remove(key: string): boolean; 1199 | 1200 | /** 1201 | * Returns an array of all keys in arbitrary order. 1202 | */ 1203 | keys(): string[]; 1204 | 1205 | /** 1206 | * Returns an array of all values in arbitrary order. 1207 | */ 1208 | values(): T[]; 1209 | 1210 | /** 1211 | * Returns an array of key-value objects in arbitrary order. 1212 | */ 1213 | entries(): { key: string; value: T }[]; 1214 | 1215 | /** 1216 | * Calls the function for each key and value pair in the map. The 'this' context is the map itself. 1217 | */ 1218 | forEach(func: (key: string, value: T) => any): void; 1219 | 1220 | /** 1221 | * Is this map empty? 1222 | */ 1223 | empty(): boolean; 1224 | 1225 | /** 1226 | * Returns the number of elements stored in the map. 1227 | */ 1228 | size(): number; 1229 | } 1230 | 1231 | /** 1232 | * Constructs an initially empty map. 1233 | */ 1234 | export function map(): Map; 1235 | 1236 | /** 1237 | * Construct a new map by copying keys and values from the given one. 1238 | */ 1239 | export function map(object: Map): Map; 1240 | 1241 | /** 1242 | * Construct a new map by copying enumerable properties and values from the given object. 1243 | */ 1244 | export function map(object: { [key: string]: T }): Map; 1245 | 1246 | /** 1247 | * Construct a new map by copying enumerable properties and values from the given object. 1248 | */ 1249 | export function map(object: { [key: number]: T }): Map; 1250 | 1251 | /** 1252 | * Construct a new map by copying elements from the array. The key function is used to identify each object. 1253 | */ 1254 | export function map(array: T[], key: (datum: T, index: number) => string): Map; 1255 | 1256 | /** 1257 | * Construct a new map by copying enumerable properties and values from the given object. 1258 | */ 1259 | export function map(object: Object): Map; 1260 | 1261 | /** 1262 | * A shim for ES6 sets. Is only able to store strings. 1263 | */ 1264 | interface Set { 1265 | /** 1266 | * Is the given string stored in this set? 1267 | */ 1268 | has(value: string): boolean; 1269 | 1270 | /** 1271 | * Add the string to this set. Returns the value. 1272 | */ 1273 | add(value: string): string; 1274 | 1275 | /** 1276 | * Remove the given value from the set. Returns true if it was stored, and false otherwise. 1277 | */ 1278 | remove(value: string): boolean; 1279 | 1280 | /** 1281 | * Returns an array of the strings stored in this set. 1282 | */ 1283 | values(): string[]; 1284 | 1285 | /** 1286 | * Calls a given function for each value in the set. The return value of the function is ignored. The this context of the function is the set itself. 1287 | */ 1288 | forEach(func: (value: string) => any): void; 1289 | 1290 | /** 1291 | * Is this set empty? 1292 | */ 1293 | empty(): boolean; 1294 | 1295 | /** 1296 | * Returns the number of values stored in this set. 1297 | */ 1298 | size(): number; 1299 | } 1300 | 1301 | /** 1302 | * Creates an initially-empty set. 1303 | */ 1304 | export function set(): Set; 1305 | 1306 | /** 1307 | * Initializes a set from the given array of strings. 1308 | */ 1309 | export function set(array: string[]): Set; 1310 | 1311 | /** 1312 | * Merges the specified arrays into a single array. 1313 | */ 1314 | export function merge(arrays: T[][]): T[]; 1315 | 1316 | /** 1317 | * Generates a 0-based numeric sequence. The output range does not include 'stop'. 1318 | */ 1319 | export function range(stop: number): number[]; 1320 | 1321 | /** 1322 | * Generates a numeric sequence starting from the given start and stop values. 'step' defaults to 1. The output range does not include 'stop'. 1323 | */ 1324 | export function range(start: number, stop: number, step?: number): number[]; 1325 | 1326 | /** 1327 | * Given the specified array, return an array corresponding to the list of indices in 'keys'. 1328 | */ 1329 | export function permute(array: { [key: number]: T }, keys: number[]): T[]; 1330 | 1331 | /** 1332 | * Given the specified object, return an array corresponding to the list of property names in 'keys'. 1333 | */ 1334 | export function permute(object: { [key: string]: T }, keys: string[]): T[]; 1335 | 1336 | // TODO construct n-tuples from n input arrays 1337 | export function zip(...arrays: T[][]): T[][]; 1338 | 1339 | export function transpose(matrix: T[][]): T[][]; 1340 | 1341 | /** 1342 | * For each adjacent pair of elements in the specified array, returns a new array of tuples of elements i and i - 1. 1343 | * Returns the empty array if the input array has fewer than two elements. 1344 | */ 1345 | export function pairs(array: T[]): Array<[T, T]>; 1346 | 1347 | interface Nest { 1348 | key(func: (datum: T) => string): Nest; 1349 | sortKeys(comparator: (a: string, b: string) => number): Nest; 1350 | sortValues(comparator: (a: T, b: T) => number): Nest; 1351 | rollup(func: (values: T[]) => U): Nest; 1352 | map(array: T[]): { [key: string]: any }; 1353 | map(array: T[], mapType: typeof d3.map): Map; 1354 | entries(array: T[]): { key: string; values: any }[]; 1355 | } 1356 | 1357 | export function nest(): Nest; 1358 | 1359 | export module random { 1360 | export function normal(mean?: number, deviation?: number): () => number; 1361 | export function logNormal(mean?: number, deviation?: number): () => number; 1362 | export function bates(count: number): () => number; 1363 | export function irwinHall(count: number): () => number; 1364 | } 1365 | 1366 | interface Transform { 1367 | rotate: number; 1368 | translate: [number, number]; 1369 | skew: number; 1370 | scale: [number, number]; 1371 | toString(): string; 1372 | } 1373 | 1374 | export function transform(transform: string): Transform; 1375 | 1376 | export function format(specifier: string): (n: number) => string; 1377 | 1378 | interface FormatPrefix { 1379 | symbol: string; 1380 | scale(n: number): number; 1381 | } 1382 | 1383 | export function formatPrefix(value: number, precision?: number): FormatPrefix; 1384 | 1385 | export function round(x: number, n?: number): number; 1386 | 1387 | export function requote(string: string): string; 1388 | 1389 | export var rgb: { 1390 | new (r: number, g: number, b: number): Rgb; 1391 | new (color: string): Rgb; 1392 | 1393 | (r: number, g: number, b: number): Rgb; 1394 | (color: string): Rgb; 1395 | }; 1396 | 1397 | interface Rgb extends Color { 1398 | r: number; 1399 | g: number; 1400 | b: number; 1401 | 1402 | brighter(k?: number): Rgb; 1403 | darker(k?: number): Rgb; 1404 | 1405 | hsl(): Hsl; 1406 | 1407 | toString(): string; 1408 | } 1409 | 1410 | export var hsl: { 1411 | new (h: number, s: number, l: number): Hsl; 1412 | new (color: string): Hsl; 1413 | 1414 | (h: number, s: number, l: number): Hsl; 1415 | (color: string): Hsl; 1416 | }; 1417 | 1418 | interface Hsl extends Color { 1419 | h: number; 1420 | s: number; 1421 | l: number; 1422 | 1423 | brighter(k?: number): Hsl; 1424 | darker(k?: number): Hsl; 1425 | 1426 | rgb(): Rgb; 1427 | 1428 | toString(): string; 1429 | } 1430 | 1431 | export var hcl: { 1432 | new (h: number, c: number, l: number): Hcl; 1433 | new (color: string): Hcl; 1434 | 1435 | (h: number, c: number, l: number): Hcl; 1436 | (color: string): Hcl; 1437 | }; 1438 | 1439 | interface Hcl extends Color { 1440 | h: number; 1441 | c: number; 1442 | l: number; 1443 | 1444 | brighter(k?: number): Hcl; 1445 | darker(k?: number): Hcl; 1446 | } 1447 | 1448 | export var lab: { 1449 | new (l: number, a: number, b: number): Lab; 1450 | new (color: string): Lab; 1451 | 1452 | (l: number, a: number, b: number): Lab; 1453 | (color: string): Lab; 1454 | } 1455 | 1456 | interface Lab extends Color { 1457 | l: number; 1458 | a: number; 1459 | b: number; 1460 | 1461 | brighter(k?: number): Lab; 1462 | darker(k?: number): Lab; 1463 | 1464 | rgb(): Rgb; 1465 | toString(): string; 1466 | } 1467 | 1468 | export var color: { 1469 | (): Color; 1470 | new (): Color; 1471 | }; 1472 | 1473 | interface Color { 1474 | rgb(): Rgb; 1475 | } 1476 | 1477 | export module ns { 1478 | interface Qualified { 1479 | space: string; 1480 | local: string; 1481 | } 1482 | 1483 | export var prefix: { [key: string]: string }; 1484 | export function qualify(name: string): Qualified | string; 1485 | } 1486 | 1487 | export function functor(value: T): T; 1488 | export function functor(value: T): () => T; 1489 | 1490 | export function rebind(target: {}, source: {}, ...names: string[]): any; 1491 | 1492 | export function dispatch(...names: string[]): Dispatch; 1493 | 1494 | interface Dispatch { 1495 | on(type: string): (...args: any[]) => void; 1496 | on(type: string, listener: (...args: any[]) => any): Dispatch; 1497 | [event: string]: (...args: any[]) => void; 1498 | } 1499 | 1500 | export module scale { 1501 | export function identity(): Identity; 1502 | 1503 | interface Identity { 1504 | (n: number): number; 1505 | invert(n: number): number; 1506 | 1507 | domain(): number[]; 1508 | domain(numbers: number[]): Identity; 1509 | 1510 | range(): number[]; 1511 | range(numbers: number[]): Identity; 1512 | 1513 | ticks(count?: number): number[]; 1514 | 1515 | tickFormat(count?: number, format?: string): (n: number) => string; 1516 | 1517 | copy(): Identity; 1518 | } 1519 | 1520 | export function linear(): Linear; 1521 | export function linear(): Linear; 1522 | export function linear(): Linear; 1523 | 1524 | interface Linear { 1525 | (x: number): Output; 1526 | invert(y: number): number; 1527 | 1528 | domain(): number[]; 1529 | domain(numbers: number[]): Linear; 1530 | 1531 | range(): Range[]; 1532 | range(values: Range[]): Linear; 1533 | 1534 | rangeRound(values: number[]): Linear; 1535 | 1536 | interpolate(): (a: Range, b: Range) => (t: number) => Output; 1537 | interpolate(factory: (a: Range, b: Range) => (t: number) => Output): Linear; 1538 | 1539 | clamp(): boolean; 1540 | clamp(clamp: boolean): Linear; 1541 | 1542 | nice(count?: number): Linear; 1543 | 1544 | ticks(count?: number): number[]; 1545 | 1546 | tickFormat(count?: number, format?: string): (n: number) => string; 1547 | 1548 | copy(): Linear; 1549 | } 1550 | 1551 | export function sqrt(): Pow; 1552 | export function sqrt(): Pow; 1553 | export function sqrt(): Pow; 1554 | 1555 | export function pow(): Pow; 1556 | export function pow(): Pow; 1557 | export function pow(): Pow; 1558 | 1559 | interface Pow { 1560 | (x: number): Output; 1561 | 1562 | invert(y: number): number; 1563 | 1564 | domain(): number[]; 1565 | domain(numbers: number[]): Pow; 1566 | 1567 | range(): Range[]; 1568 | range(values: Range[]): Pow; 1569 | 1570 | rangeRound(values: number[]): Pow; 1571 | 1572 | exponent(): number; 1573 | exponent(k: number): Pow; 1574 | 1575 | interpolate(): (a: Range, b: Range) => (t: number) => Output; 1576 | interpolate(factory: (a: Range, b: Range) => (t: number) => Output): Pow; 1577 | 1578 | clamp(): boolean; 1579 | clamp(clamp: boolean): Pow; 1580 | 1581 | nice(m?: number): Pow; 1582 | 1583 | ticks(count?: number): number[]; 1584 | 1585 | tickFormat(count?: number, format?: string): (n: number) => string; 1586 | 1587 | copy(): Pow; 1588 | } 1589 | 1590 | export function log(): Log; 1591 | export function log(): Log; 1592 | export function log(): Log; 1593 | 1594 | interface Log { 1595 | (x: number): Output; 1596 | 1597 | invert(y: number): number; 1598 | 1599 | domain(): number[]; 1600 | domain(numbers: number[]): Log; 1601 | 1602 | range(): Range[]; 1603 | range(values: Range[]): Log; 1604 | 1605 | rangeRound(values: number[]): Log; 1606 | 1607 | base(): number; 1608 | base(base: number): Log; 1609 | 1610 | interpolate(): (a: Range, b: Range) => (t: number) => Output; 1611 | interpolate(factory: (a: Range, b: Range) => (t: number) => Output): Log; 1612 | 1613 | clamp(): boolean; 1614 | clamp(clamp: boolean): Log; 1615 | 1616 | nice(): Log; 1617 | 1618 | ticks(): number[]; 1619 | 1620 | tickFormat(count?: number, format?: string): (t: number) => string; 1621 | 1622 | copy(): Log; 1623 | } 1624 | 1625 | export function quantize(): Quantize; 1626 | 1627 | interface Quantize { 1628 | (x: number): T; 1629 | 1630 | invertExtent(y: T): [number, number]; 1631 | 1632 | domain(): number[]; 1633 | domain(numbers: number[]): Quantize; 1634 | 1635 | range(): T[]; 1636 | range(values: T[]): Quantize; 1637 | 1638 | copy(): Quantize; 1639 | } 1640 | 1641 | export function quantile(): Quantile; 1642 | 1643 | interface Quantile { 1644 | (x: number): T; 1645 | 1646 | invertExtent(y: T): [number, number]; 1647 | 1648 | domain(): number[]; 1649 | domain(numbers: number[]): Quantile; 1650 | 1651 | range(): T[]; 1652 | range(values: T[]): Quantile; 1653 | 1654 | quantiles(): number[]; 1655 | 1656 | copy(): Quantile; 1657 | } 1658 | 1659 | export function threshold(): Threshold; 1660 | export function threshold(): Threshold; 1661 | 1662 | interface Threshold { 1663 | (x: number): Range; 1664 | 1665 | invertExtent(y: Range): [Domain, Domain]; 1666 | 1667 | domain(): Domain[]; 1668 | domain(domain: Domain[]): Threshold; 1669 | 1670 | range(): Range[]; 1671 | range(values: Range[]): Threshold; 1672 | 1673 | copy(): Threshold; 1674 | } 1675 | 1676 | export function ordinal(): Ordinal; 1677 | export function ordinal(): Ordinal; 1678 | export function category10(): Ordinal; 1679 | export function category10(): Ordinal; 1680 | export function category20(): Ordinal; 1681 | export function category20(): Ordinal; 1682 | export function category20b(): Ordinal; 1683 | export function category20b(): Ordinal; 1684 | export function category20c(): Ordinal; 1685 | export function category20c(): Ordinal; 1686 | 1687 | interface Ordinal { 1688 | (x: Domain): Range; 1689 | 1690 | domain(): Domain[]; 1691 | domain(values: Domain[]): Ordinal; 1692 | 1693 | range(): Range[]; 1694 | range(values: Range[]): Ordinal; 1695 | 1696 | rangePoints(interval: [number, number], padding?: number): Ordinal; 1697 | rangeRoundPoints(interval: [number, number], padding?: number): Ordinal; 1698 | 1699 | rangeBands(interval: [number, number], padding?: number, outerPadding?: number): Ordinal; 1700 | rangeRoundBands(interval: [number, number], padding?: number, outerPadding?: number): Ordinal; 1701 | 1702 | rangeBand(): number; 1703 | rangeExtent(): [number, number]; 1704 | 1705 | copy(): Ordinal; 1706 | } 1707 | } 1708 | 1709 | export function interpolate(a: number, b: number): (t: number) => number; 1710 | export function interpolate(a: string, b: string): (t: number) => string; 1711 | export function interpolate(a: string | Color, b: Color): (t: number) => string; 1712 | export function interpolate(a: Array, b: Color[]): (t: number) => string; 1713 | export function interpolate(a: Range[], b: Output[]): (t: number) => Output[]; 1714 | export function interpolate(a: Range[], b: Range[]): (t: number) => Output[]; 1715 | export function interpolate(a: { [key: string]: string | Color }, b: { [key: string]: Color }): (t: number) => { [key: string]: string }; 1716 | export function interpolate(a: { [key: string]: Range }, b: { [key: string]: Output }): (t: number) => { [key: string]: Output }; 1717 | export function interpolate(a: { [key: string]: Range }, b: { [key: string]: Range }): (t: number) => { [key: string]: Output }; 1718 | 1719 | export function interpolateNumber(a: number, b: number): (t: number) => number; 1720 | 1721 | export function interpolateRound(a: number, b: number): (t: number) => number; 1722 | 1723 | export function interpolateString(a: string, b: string): (t: number) => string; 1724 | 1725 | export function interpolateRgb(a: string | Color, b: string | Color): (t: number) => string; 1726 | 1727 | export function interpolateHsl(a: string | Color, b: string | Color): (t: number) => string; 1728 | 1729 | export function interpolateLab(a: string | Color, b: string | Color): (t: number) => string; 1730 | 1731 | export function interpolateHcl(a: string | Color, b: string | Color): (t: number) => string; 1732 | 1733 | export function interpolateArray(a: Array, b: Color[]): (t: number) => string[]; 1734 | export function interpolateArray(a: Range[], b: Range[]): (t: number) => Output[]; 1735 | export function interpolateArray(a: Range[], b: Output[]): (t: number) => Output[]; 1736 | 1737 | export function interpolateObject(a: { [key: string]: string | Color }, b: { [key: string]: Color }): (t: number) => { [key: string]: string }; 1738 | export function interpolateObject(a: { [key: string]: Range }, b: { [key: string]: Output }): (t: number) => { [key: string]: Output }; 1739 | export function interpolateObject(a: { [key: string]: Range }, b: { [key: string]: Range }): (t: number) => { [key: string]: Output }; 1740 | 1741 | export function interpolateTransform(a: string | Transform, b: string | Transform): (t: number) => string; 1742 | 1743 | export function interpolateZoom(a: [number, number, number], b: [number, number, number]): { 1744 | (t: number): [number, number, number]; 1745 | duration: number; 1746 | }; 1747 | 1748 | export var interpolators: Array<(a: any, b: any) => (t: number) => any>; 1749 | 1750 | export module time { 1751 | export var second: Interval; 1752 | export var minute: Interval; 1753 | export var hour: Interval; 1754 | export var day: Interval; 1755 | export var week: Interval; 1756 | export var sunday: Interval; 1757 | export var monday: Interval; 1758 | export var tuesday: Interval; 1759 | export var wednesday: Interval; 1760 | export var thursday: Interval; 1761 | export var friday: Interval; 1762 | export var saturday: Interval; 1763 | export var month: Interval; 1764 | export var year: Interval; 1765 | 1766 | interface Interval { 1767 | (d: Date): Date; 1768 | 1769 | floor(d: Date): Date; 1770 | 1771 | round(d: Date): Date; 1772 | 1773 | ceil(d: Date): Date; 1774 | 1775 | range(start: Date, stop: Date, step?: number): Date[]; 1776 | 1777 | offset(date: Date, step: number): Date; 1778 | 1779 | utc: { 1780 | (d: Date): Date; 1781 | 1782 | floor(d: Date): Date; 1783 | 1784 | round(d: Date): Date; 1785 | 1786 | ceil(d: Date): Date; 1787 | 1788 | range(start: Date, stop: Date, step?: number): Date[]; 1789 | 1790 | offset(date: Date, step: number): Date; 1791 | } 1792 | } 1793 | 1794 | export function seconds(start: Date, stop: Date, step?: number): Date[]; 1795 | export function minutes(start: Date, stop: Date, step?: number): Date[]; 1796 | export function hours(start: Date, stop: Date, step?: number): Date[]; 1797 | export function days(start: Date, stop: Date, step?: number): Date[]; 1798 | export function weeks(start: Date, stop: Date, step?: number): Date[]; 1799 | export function sundays(start: Date, stop: Date, step?: number): Date[]; 1800 | export function mondays(start: Date, stop: Date, step?: number): Date[]; 1801 | export function tuesdays(start: Date, stop: Date, step?: number): Date[]; 1802 | export function wednesdays(start: Date, stop: Date, step?: number): Date[]; 1803 | export function thursdays(start: Date, stop: Date, step?: number): Date[]; 1804 | export function fridays(start: Date, stop: Date, step?: number): Date[]; 1805 | export function saturdays(start: Date, stop: Date, step?: number): Date[]; 1806 | export function months(start: Date, stop: Date, step?: number): Date[]; 1807 | export function years(start: Date, stop: Date, step?: number): Date[]; 1808 | 1809 | export function dayOfYear(d: Date): number; 1810 | export function weekOfYear(d: Date): number; 1811 | export function sundayOfYear(d: Date): number; 1812 | export function mondayOfYear(d: Date): number; 1813 | export function tuesdayOfYear(d: Date): number; 1814 | export function wednesdayOfYear(d: Date): number; 1815 | export function fridayOfYear(d: Date): number; 1816 | export function saturdayOfYear(d: Date): number; 1817 | 1818 | export function format(specifier: string): Format; 1819 | 1820 | export module format { 1821 | export function multi(formats: Array<[string, (d: Date) => boolean|number]>): Format; 1822 | export function utc(specifier: string): Format; 1823 | namespace utc { 1824 | export function multi(formats: Array<[string, (d: Date) => boolean|number]>): Format; 1825 | } 1826 | 1827 | export var iso: Format; 1828 | } 1829 | 1830 | interface Format { 1831 | (d: Date): string; 1832 | parse(input: string): Date; 1833 | } 1834 | 1835 | export function scale(): Scale; 1836 | export function scale(): Scale; 1837 | export function scale(): Scale; 1838 | 1839 | export module scale { 1840 | export function utc(): Scale; 1841 | export function utc(): Scale; 1842 | export function utc(): Scale; 1843 | } 1844 | 1845 | 1846 | interface Scale { 1847 | (x: Date): Output; 1848 | 1849 | invert(y: number): Date; 1850 | 1851 | domain(): Date[]; 1852 | domain(dates: number[]): Scale; 1853 | domain(dates: Date[]): Scale; 1854 | 1855 | nice(): Scale; 1856 | nice(interval: Interval, step?: number): Scale; 1857 | 1858 | range(): Range[]; 1859 | range(values: Range[]): Scale; 1860 | 1861 | rangeRound(values: number[]): Scale; 1862 | 1863 | interpolate(): (a: Range, b: Range) => (t: number) => Output; 1864 | interpolate(factory: (a: Range, b: Range) => (t: number) => Output): Scale; 1865 | 1866 | clamp(): boolean; 1867 | clamp(clamp: boolean): Scale; 1868 | 1869 | ticks(): Date[]; 1870 | ticks(interval: Interval, step?: number): Date[]; 1871 | ticks(count: number): Date[]; 1872 | 1873 | tickFormat(count: number): (d: Date) => string; 1874 | 1875 | copy(): Scale; 1876 | } 1877 | } 1878 | 1879 | export module behavior { 1880 | export function drag(): Drag; 1881 | 1882 | interface Drag { 1883 | (selection: Selection): void; 1884 | 1885 | on(type: string): (d: Datum, i: number) => any; 1886 | on(type: string, listener: (d: Datum, i: number) => any): Drag; 1887 | 1888 | origin(): (d: Datum, i: number) => { x: number; y: number }; 1889 | origin(accessor: (d: Datum, i: number) => { x: number; y: number }): Drag; 1890 | } 1891 | 1892 | export function zoom(): Zoom; 1893 | 1894 | namespace zoom { 1895 | interface Scale { 1896 | domain(): number[]; 1897 | domain(values: number[]): Scale; 1898 | 1899 | invert(y: number): number; 1900 | 1901 | range(values: number[]): Scale; 1902 | range(): number[]; 1903 | } 1904 | } 1905 | 1906 | interface Zoom { 1907 | (selection: Selection): void; 1908 | 1909 | translate(): [number, number]; 1910 | translate(translate: [number, number]): Zoom; 1911 | 1912 | scale(): number; 1913 | scale(scale: number): Zoom; 1914 | 1915 | scaleExtent(): [number, number]; 1916 | scaleExtent(extent: [number, number]): Zoom; 1917 | 1918 | center(): [number, number]; 1919 | center(center: [number, number]): Zoom; 1920 | 1921 | size(): [number, number]; 1922 | size(size: [number, number]): Zoom; 1923 | 1924 | x(): zoom.Scale; 1925 | x(x: zoom.Scale): Zoom; 1926 | 1927 | y(): zoom.Scale; 1928 | y(y: zoom.Scale): Zoom; 1929 | 1930 | on(type: string): (d: Datum, i: number) => any; 1931 | on(type: string, listener: (d: Datum, i: number) => any): Zoom; 1932 | 1933 | event(selection: Selection): void; 1934 | event(transition: Transition): void; 1935 | } 1936 | } 1937 | 1938 | export module geo { 1939 | export function path(): Path; 1940 | 1941 | interface Path { 1942 | (feature: any, index?: number): string; 1943 | 1944 | area(feature: any): number; 1945 | 1946 | centroid(feature: any): [number, number]; 1947 | 1948 | bounds(feature: any): [[number, number], [number, number]]; 1949 | 1950 | projection(): Transform | ((coordinates: [number, number]) => [number, number]); 1951 | projection(stream: Transform): Path; 1952 | projection(projection: (coordinates: [number, number]) => [number, number]): Path; 1953 | 1954 | pointRadius(): number | ((datum: any, index: number) => number); 1955 | pointRadius(radius: number): Path; 1956 | pointRadius(radius: (datum: any, index: number) => number): Path; 1957 | 1958 | context(): CanvasRenderingContext2D; 1959 | context(context: CanvasRenderingContext2D): Path; 1960 | } 1961 | 1962 | export function graticule(): Graticule; 1963 | 1964 | interface Graticule { 1965 | (): any; 1966 | 1967 | lines(): any[]; 1968 | 1969 | outline(): any; 1970 | 1971 | extent(): [[number, number], [number, number]]; 1972 | extent(extent: [[number, number], [number, number]]): Graticule; 1973 | 1974 | majorExtent(): [[number, number], [number, number]]; 1975 | majorExtent(extent: [[number, number], [number, number]]): Graticule; 1976 | 1977 | minorExtent(): [[number, number], [number, number]]; 1978 | minorExtent(extent: [[number, number], [number, number]]): Graticule; 1979 | 1980 | step(): [number, number]; 1981 | step(step: [number, number]): Graticule; 1982 | 1983 | majorStep(): [number, number]; 1984 | majorStep(step: [number, number]): Graticule; 1985 | 1986 | minorStep(): [number, number]; 1987 | minorStep(step: [number, number]): Graticule; 1988 | 1989 | precision(): number; 1990 | precision(precision: number): Graticule; 1991 | } 1992 | 1993 | export function circle(): Circle; 1994 | 1995 | interface Circle { 1996 | (...args: any[]): any; 1997 | 1998 | origin(): [number, number] | ((...args: any[]) => [number, number]); 1999 | origin(origin: [number, number]): Circle; 2000 | origin(origin: (...args: any[]) => [number, number]): Circle; 2001 | 2002 | angle(): number; 2003 | angle(angle: number): Circle; 2004 | 2005 | precision(): number; 2006 | precision(precision: number): Circle; 2007 | } 2008 | 2009 | export function area(feature: any): number; 2010 | export function centroid(feature: any): [number, number]; 2011 | export function bounds(feature: any): [[number, number], [number, number]]; 2012 | export function distance(a: [number, number], b: [number, number]): number; 2013 | export function length(feature: any): number; 2014 | export function interpolate(a: [number, number], b: [number, number]): (t: number) => [number, number]; 2015 | 2016 | export function rotation(rotate: [number, number] | [number, number, number]): Rotation; 2017 | 2018 | interface Rotation { 2019 | (location: [number, number]): [number, number]; 2020 | invert(location: [number, number]): [number, number]; 2021 | } 2022 | 2023 | export function stream(object: any, listener: Listener): void; 2024 | 2025 | interface Listener { 2026 | point(x: number, y: number, z: number): void; 2027 | lineStart(): void; 2028 | lineEnd(): void; 2029 | polygonStart(): void; 2030 | polygonEnd(): void; 2031 | sphere(): void; 2032 | } 2033 | 2034 | export function transform(methods: TransformMethods): Transform; 2035 | 2036 | interface TransformMethods { 2037 | point?(x: number, y: number, z: number): void; 2038 | lineStart?(): void; 2039 | lineEnd?(): void; 2040 | polygonStart?(): void; 2041 | polygonEnd?(): void; 2042 | sphere?(): void; 2043 | } 2044 | 2045 | interface Transform { 2046 | stream(stream: Listener): Listener; 2047 | } 2048 | 2049 | export function clipExtent(): ClipExtent; 2050 | 2051 | interface ClipExtent extends Transform { 2052 | extent(): [[number, number], [number, number]]; 2053 | extent(extent: [[number, number], [number, number]]): ClipExtent; 2054 | } 2055 | 2056 | export function projection(raw: RawInvertibleProjection): InvertibleProjection; 2057 | export function projection(raw: RawProjection): Projection; 2058 | 2059 | export function projectionMutator(factory: (...args: any[]) => RawInvertibleProjection): (...args: any[]) => InvertibleProjection; 2060 | export function projectionMutator(factory: (...args: any[]) => RawProjection): (...args: any[]) => Projection; 2061 | 2062 | export function albers(): ConicProjection; 2063 | export function albersUsa(): ConicProjection; 2064 | export function azimuthalEqualArea(): InvertibleProjection; 2065 | namespace azimuthalEqualArea { 2066 | export function raw(lambda: number, phi: number): [number, number]; 2067 | namespace raw { 2068 | export function invert(x: number, y: number): [number, number]; 2069 | } 2070 | } 2071 | 2072 | export function azimuthalEquidistant(): InvertibleProjection; 2073 | namespace azimuthalEquidistant { 2074 | export function raw(lambda: number, phi: number): [number, number]; 2075 | namespace raw { 2076 | export function invert(x: number, y: number): [number, number]; 2077 | } 2078 | } 2079 | 2080 | export function conicConformal(): ConicProjection; 2081 | namespace conicConformal { 2082 | export function raw(phi0: number, phi1: number): RawInvertibleProjection; 2083 | } 2084 | 2085 | export function conicEqualArea(): ConicProjection; 2086 | namespace conicEqualArea { 2087 | export function raw(phi0: number, phi1: number): RawInvertibleProjection; 2088 | } 2089 | 2090 | export function conicEquidistant(): ConicProjection; 2091 | namespace conicEquidistant { 2092 | export function raw(phi0: number, phi1: number): RawInvertibleProjection; 2093 | } 2094 | 2095 | export function equirectangular(): InvertibleProjection; 2096 | namespace equirectangular { 2097 | export function raw(lambda: number, phi: number): [number, number]; 2098 | namespace raw { 2099 | export function invert(x: number, y: number): [number, number]; 2100 | } 2101 | } 2102 | 2103 | export function gnomonic(): InvertibleProjection; 2104 | namespace gnomonic { 2105 | export function raw(lambda: number, phi: number): [number, number]; 2106 | namespace raw { 2107 | export function invert(x: number, y: number): [number, number]; 2108 | } 2109 | } 2110 | 2111 | export function mercator(): InvertibleProjection; 2112 | namespace mercator { 2113 | export function raw(lambda: number, phi: number): [number, number]; 2114 | namespace raw { 2115 | export function invert(x: number, y: number): [number, number]; 2116 | } 2117 | } 2118 | 2119 | export function orthographic(): InvertibleProjection; 2120 | namespace orthographic { 2121 | export function raw(lambda: number, phi: number): [number, number]; 2122 | namespace raw { 2123 | export function invert(x: number, y: number): [number, number]; 2124 | } 2125 | } 2126 | 2127 | export function stereographic(): InvertibleProjection; 2128 | namespace stereographic { 2129 | export function raw(lambda: number, phi: number): [number, number]; 2130 | namespace raw { 2131 | export function invert(x: number, y: number): [number, number]; 2132 | } 2133 | } 2134 | 2135 | export function transverseMercator(): InvertibleProjection; 2136 | namespace transverseMercator { 2137 | export function raw(lambda: number, phi: number): [number, number]; 2138 | namespace raw { 2139 | export function invert(x: number, y: number): [number, number]; 2140 | } 2141 | } 2142 | 2143 | interface Projection { 2144 | (location: [number, number]): [number, number]; 2145 | 2146 | rotate(): [number, number, number]; 2147 | rotate(rotation: [number, number, number]): Projection; 2148 | 2149 | center(): [number, number]; 2150 | center(location: [number, number]): Projection; 2151 | 2152 | translate(): [number, number]; 2153 | translate(point: [number, number]): Projection; 2154 | 2155 | scale(): number; 2156 | scale(scale: number): Projection; 2157 | 2158 | clipAngle(): number; 2159 | clipAngle(angle: number): Projection; 2160 | 2161 | clipExtent(): [[number, number], [number, number]]; 2162 | clipExtent(extent: [[number, number], [number, number]]): Projection; 2163 | 2164 | precision(): number; 2165 | precision(precision: number): Projection; 2166 | 2167 | stream(listener: Listener): Listener; 2168 | } 2169 | 2170 | interface InvertibleProjection extends Projection { 2171 | invert(point: [number, number]): [number, number]; 2172 | } 2173 | 2174 | interface ConicProjection extends InvertibleProjection { 2175 | parallels(): [number, number]; 2176 | parallels(parallels: [number, number]): ConicProjection; 2177 | 2178 | rotate(): [number, number, number]; 2179 | rotate(rotation: [number, number, number]): ConicProjection; 2180 | 2181 | center(): [number, number]; 2182 | center(location: [number, number]): ConicProjection; 2183 | 2184 | translate(): [number, number]; 2185 | translate(point: [number, number]): ConicProjection; 2186 | 2187 | scale(): number; 2188 | scale(scale: number): ConicProjection; 2189 | 2190 | clipAngle(): number; 2191 | clipAngle(angle: number): ConicProjection; 2192 | 2193 | clipExtent(): [[number, number], [number, number]]; 2194 | clipExtent(extent: [[number, number], [number, number]]): ConicProjection; 2195 | 2196 | precision(): number; 2197 | precision(precision: number): ConicProjection; 2198 | } 2199 | 2200 | interface RawProjection { 2201 | (lambda: number, phi: number): [number, number]; 2202 | } 2203 | 2204 | interface RawInvertibleProjection extends RawProjection { 2205 | invert(x: number, y: number): [number, number]; 2206 | } 2207 | } 2208 | 2209 | namespace svg { 2210 | export function line(): Line<[number, number]>; 2211 | export function line(): Line; 2212 | 2213 | interface Line { 2214 | (data: T[]): string; 2215 | 2216 | x(): number | ((d: T, i: number) => number); 2217 | x(x: number): Line; 2218 | x(x: (d: T, i: number) => number): Line; 2219 | 2220 | y(): number | ((d: T, i: number) => number); 2221 | y(x: number): Line; 2222 | y(y: (d: T, i: number) => number): Line; 2223 | 2224 | interpolate(): string | ((points: Array<[number, number]>) => string); 2225 | interpolate(interpolate: "linear"): Line; 2226 | interpolate(interpolate: "linear-closed"): Line; 2227 | interpolate(interpolate: "step"): Line; 2228 | interpolate(interpolate: "step-before"): Line; 2229 | interpolate(interpolate: "step-after"): Line; 2230 | interpolate(interpolate: "basis"): Line; 2231 | interpolate(interpolate: "basis-open"): Line; 2232 | interpolate(interpolate: "basis-closed"): Line; 2233 | interpolate(interpolate: "bundle"): Line; 2234 | interpolate(interpolate: "cardinal"): Line; 2235 | interpolate(interpolate: "cardinal-open"): Line; 2236 | interpolate(interpolate: "cardinal-closed"): Line; 2237 | interpolate(interpolate: "monotone"): Line; 2238 | interpolate(interpolate: string | ((points: Array<[number, number]>) => string)): Line; 2239 | 2240 | tension(): number; 2241 | tension(tension: number): Line; 2242 | 2243 | defined(): (d: T, i: number) => boolean; 2244 | defined(defined: (d: T, i: number) => boolean): Line; 2245 | } 2246 | 2247 | namespace line { 2248 | export function radial(): Radial<[number, number]>; 2249 | export function radial(): Radial; 2250 | 2251 | interface Radial { 2252 | (data: T[]): string; 2253 | 2254 | radius(): number | ((d: T, i: number) => number); 2255 | radius(radius: number): Radial; 2256 | radius(radius: (d: T, i: number) => number): Radial; 2257 | 2258 | angle(): number | ((d: T, i: number) => number); 2259 | angle(angle: number): Radial; 2260 | angle(angle: (d: T, i: number) => number): Radial; 2261 | 2262 | interpolate(): string | ((points: Array<[number, number]>) => string); 2263 | interpolate(interpolate: "linear"): Radial; 2264 | interpolate(interpolate: "linear-closed"): Radial; 2265 | interpolate(interpolate: "step"): Radial; 2266 | interpolate(interpolate: "step-before"): Radial; 2267 | interpolate(interpolate: "step-after"): Radial; 2268 | interpolate(interpolate: "basis"): Radial; 2269 | interpolate(interpolate: "basis-open"): Radial; 2270 | interpolate(interpolate: "basis-closed"): Radial; 2271 | interpolate(interpolate: "bundle"): Radial; 2272 | interpolate(interpolate: "cardinal"): Radial; 2273 | interpolate(interpolate: "cardinal-open"): Radial; 2274 | interpolate(interpolate: "cardinal-closed"): Radial; 2275 | interpolate(interpolate: "monotone"): Radial; 2276 | interpolate(interpolate: string | ((points: Array<[number, number]>) => string)): Radial; 2277 | 2278 | tension(): number; 2279 | tension(tension: number): Radial; 2280 | 2281 | defined(): (d: T, i: number) => boolean; 2282 | defined(defined: (d: T, i: number) => boolean): Radial; 2283 | } 2284 | } 2285 | 2286 | export function area(): Area<[number, number]>; 2287 | export function area(): Area; 2288 | 2289 | interface Area { 2290 | (data: T[]): string; 2291 | 2292 | x(): number | ((d: T, i: number) => number); 2293 | x(x: number): Area; 2294 | x(x: (d: T, i: number) => number): Area; 2295 | 2296 | x0(): number | ((d: T, i: number) => number); 2297 | x0(x0: number): Area; 2298 | x0(x0: (d: T, i: number) => number): Area; 2299 | 2300 | x1(): number | ((d: T, i: number) => number); 2301 | x1(x1: number): Area; 2302 | x1(x1: (d: T, i: number) => number): Area; 2303 | 2304 | y(): number | ((d: T, i: number) => number); 2305 | y(y: number): Area; 2306 | y(y: (d: T, i: number) => number): Area; 2307 | 2308 | y0(): number | ((d: T, i: number) => number); 2309 | y0(y0: number): Area; 2310 | y0(y0: (d: T, i: number) => number): Area; 2311 | 2312 | y1(): number | ((d: T, i: number) => number); 2313 | y1(y1: number): Area; 2314 | y1(y1: (d: T, i: number) => number): Area; 2315 | 2316 | interpolate(): string | ((points: Array<[number, number]>) => string); 2317 | interpolate(interpolate: "linear"): Area; 2318 | interpolate(interpolate: "step"): Area; 2319 | interpolate(interpolate: "step-before"): Area; 2320 | interpolate(interpolate: "step-after"): Area; 2321 | interpolate(interpolate: "basis"): Area; 2322 | interpolate(interpolate: "basis-open"): Area; 2323 | interpolate(interpolate: "cardinal"): Area; 2324 | interpolate(interpolate: "cardinal-open"): Area; 2325 | interpolate(interpolate: "monotone"): Area; 2326 | interpolate(interpolate: string | ((points: Array<[number, number]>) => string)): Area; 2327 | 2328 | tension(): number; 2329 | tension(tension: number): Area; 2330 | 2331 | defined(): (d: T, i: number) => boolean; 2332 | defined(defined: (d: T, i: number) => boolean): Area; 2333 | } 2334 | 2335 | namespace area { 2336 | export function radial(): Radial<[number, number]>; 2337 | export function radial(): Radial; 2338 | 2339 | interface Radial { 2340 | (data: T[]): string; 2341 | 2342 | radius(): number | ((d: T, i: number) => number); 2343 | radius(radius: number): Radial; 2344 | radius(radius: (d: T, i: number) => number): Radial; 2345 | 2346 | innerRadius(): number | ((d: T, i: number) => number); 2347 | innerRadius(innerRadius: number): Radial; 2348 | innerRadius(innerRadius: (d: T, i: number) => number): Radial; 2349 | 2350 | outerRadius(): number | ((d: T, i: number) => number); 2351 | outerRadius(outerRadius: number): Radial; 2352 | outerRadius(outerRadius: (d: T, i: number) => number): Radial; 2353 | 2354 | angle(): number | ((d: T, i: number) => number); 2355 | angle(angle: number): Radial; 2356 | angle(angle: (d: T, i: number) => number): Radial; 2357 | 2358 | startAngle(): number | ((d: T, i: number) => number); 2359 | startAngle(startAngle: number): Radial; 2360 | startAngle(startAngle: (d: T, i: number) => number): Radial; 2361 | 2362 | endAngle(): number | ((d: T, i: number) => number); 2363 | endAngle(endAngle: number): Radial; 2364 | endAngle(endAngle: (d: T, i: number) => number): Radial; 2365 | 2366 | interpolate(): string | ((points: Array<[number, number]>) => string); 2367 | interpolate(interpolate: "linear"): Radial; 2368 | interpolate(interpolate: "step"): Radial; 2369 | interpolate(interpolate: "step-before"): Radial; 2370 | interpolate(interpolate: "step-after"): Radial; 2371 | interpolate(interpolate: "basis"): Radial; 2372 | interpolate(interpolate: "basis-open"): Radial; 2373 | interpolate(interpolate: "cardinal"): Radial; 2374 | interpolate(interpolate: "cardinal-open"): Radial; 2375 | interpolate(interpolate: "monotone"): Radial; 2376 | interpolate(interpolate: string | ((points: Array<[number, number]>) => string)): Radial; 2377 | 2378 | tension(): number; 2379 | tension(tension: number): Radial; 2380 | 2381 | defined(): (d: T, i: number) => boolean; 2382 | defined(defined: (d: T, i: number) => boolean): Radial; 2383 | } 2384 | } 2385 | 2386 | export function arc(): Arc; 2387 | export function arc(): Arc; 2388 | 2389 | namespace arc { 2390 | interface Arc { 2391 | innerRadius: number; 2392 | outerRadius: number; 2393 | startAngle: number; 2394 | endAngle: number; 2395 | padAngle: number 2396 | } 2397 | } 2398 | 2399 | interface Arc { 2400 | (d: T, i?: number): string; 2401 | 2402 | innerRadius(): (d: T, i: number) => number; 2403 | innerRadius(radius: number): Arc; 2404 | innerRadius(radius: (d: T, i: number) => number): Arc; 2405 | 2406 | outerRadius(): (d: T, i: number) => number; 2407 | outerRadius(radius: number): Arc; 2408 | outerRadius(radius: (d: T, i: number) => number): Arc; 2409 | 2410 | cornerRadius(): (d: T, i: number) => number; 2411 | cornerRadius(radius: number): Arc; 2412 | cornerRadius(radius: (d: T, i: number) => number): Arc; 2413 | 2414 | padRadius(): string | ((d: T, i: number) => number); 2415 | padRadius(radius: "auto"): Arc; 2416 | padRadius(radius: string): Arc; 2417 | padRadius(radius: (d: T, i: number) => number): Arc; 2418 | 2419 | startAngle(): (d: T, i: number) => number; 2420 | startAngle(angle: number): Arc; 2421 | startAngle(angle: (d: T, i: number) => number): Arc; 2422 | 2423 | endAngle(): (d: T, i: number) => number; 2424 | endAngle(angle: number): Arc; 2425 | endAngle(angle: (d: T, i: number) => number): Arc; 2426 | 2427 | padAngle(): (d: T, i: number) => number; 2428 | padAngle(angle: number): Arc; 2429 | padAngle(angle: (d: T, i: number) => number): Arc; 2430 | 2431 | centroid(d: T, i?: number): [number, number]; 2432 | } 2433 | 2434 | export function symbol(): Symbol<{}>; 2435 | export function symbol(): Symbol; 2436 | 2437 | interface Symbol { 2438 | (d: T, i?: number): string; 2439 | 2440 | type(): (d: T, i: number) => string; 2441 | type(type: string): Symbol; 2442 | type(type: (d: T, i: number) => string): Symbol; 2443 | 2444 | size(): (d: T, i: string) => number; 2445 | size(size: number): Symbol; 2446 | size(size: (d: T, i: number) => number): Symbol; 2447 | } 2448 | 2449 | export var symbolTypes: string[]; 2450 | 2451 | export function chord(): Chord, chord.Node>; 2452 | export function chord(): Chord, Node>; 2453 | export function chord(): Chord; 2454 | 2455 | namespace chord { 2456 | interface Link { 2457 | source: Node; 2458 | target: Node; 2459 | } 2460 | 2461 | interface Node { 2462 | radius: number; 2463 | startAngle: number; 2464 | endAngle: number 2465 | } 2466 | } 2467 | 2468 | interface Chord { 2469 | (d: Link, i: number): string; 2470 | 2471 | source(): (d: Link, i: number) => Node; 2472 | source(source: Node): Chord; 2473 | source(source: (d: Link, i: number) => Node): Chord; 2474 | 2475 | target(): (d: Link, i: number) => Node; 2476 | target(target: Node): Chord; 2477 | target(target: (d: Link, i: number) => Node): Chord; 2478 | 2479 | radius(): (d: Node, i: number) => number; 2480 | radius(radius: number): Chord; 2481 | radius(radius: (d: Node, i: number) => number): Chord; 2482 | 2483 | startAngle(): (d: Node, i: number) => number; 2484 | startAngle(angle: number): Chord; 2485 | startAngle(angle: (d: Node, i: number) => number): Chord; 2486 | 2487 | endAngle(): (d: Node, i: number) => number; 2488 | endAngle(angle: number): Chord; 2489 | endAngle(angle: (d: Node, i: number) => number): Chord; 2490 | } 2491 | 2492 | export function diagonal(): Diagonal, diagonal.Node>; 2493 | export function diagonal(): Diagonal, Node>; 2494 | export function diagonal(): Diagonal; 2495 | 2496 | namespace diagonal { 2497 | interface Link { 2498 | source: Node; 2499 | target: Node; 2500 | } 2501 | 2502 | interface Node { 2503 | x: number; 2504 | y: number; 2505 | } 2506 | } 2507 | 2508 | interface Diagonal { 2509 | (d: Link, i?: number): string; 2510 | 2511 | source(): (d: Link, i: number) => Node; 2512 | source(source: Node): Diagonal; 2513 | source(source: (d: Link, i: number) => { x: number; y: number; }): Diagonal; 2514 | 2515 | target(): (d: Link, i: number) => Node; 2516 | target(target: Node): Diagonal; 2517 | target(target: (d: Link, i: number) => { x: number; y: number; }): Diagonal; 2518 | 2519 | projection(): (d: Node, i: number) => [number, number]; 2520 | projection(projection: (d: Node, i: number) => [number, number]): Diagonal; 2521 | } 2522 | 2523 | namespace diagonal { 2524 | export function radial(): Radial, Node>; 2525 | export function radial(): Radial, Node>; 2526 | export function radial(): Radial; 2527 | 2528 | interface Radial { 2529 | (d: Link, i: number): string; 2530 | 2531 | source(): (d: Link, i: number) => Node; 2532 | source(source: Node): Radial; 2533 | source(source: (d: Link, i: number) => Node): Radial; 2534 | 2535 | target(): (d: Link, i: number) => Node; 2536 | target(target: Node): Radial; 2537 | target(target: (d: Link, i: number) => Node): Radial; 2538 | 2539 | projection(): (d: Node, i: number) => [number, number]; 2540 | projection(projection: (d: Node, i: number) => [number, number]): Radial; 2541 | } 2542 | } 2543 | 2544 | export function axis(): Axis; 2545 | 2546 | interface Axis { 2547 | (selection: Selection): void; 2548 | (selection: Transition): void; 2549 | 2550 | scale(): any; 2551 | scale(scale: any): Axis; 2552 | 2553 | orient(): string; 2554 | orient(orientation: string): Axis; 2555 | 2556 | ticks(): any[]; 2557 | ticks(...args: any[]): Axis; 2558 | 2559 | tickValues(): any[]; 2560 | tickValues(values: any[]): Axis; 2561 | 2562 | tickSize(): number; 2563 | tickSize(size: number): Axis; 2564 | tickSize(inner: number, outer: number): Axis; 2565 | 2566 | innerTickSize(): number; 2567 | innerTickSize(size: number): Axis; 2568 | 2569 | outerTickSize(): number; 2570 | outerTickSize(size: number): Axis; 2571 | 2572 | tickPadding(): number; 2573 | tickPadding(padding: number): Axis; 2574 | 2575 | tickFormat(): (t: any) => string; 2576 | tickFormat(format: (t: any) => string): Axis; 2577 | tickFormat(format:string): Axis; 2578 | } 2579 | 2580 | export function brush(): Brush; 2581 | export function brush(): Brush; 2582 | 2583 | namespace brush { 2584 | interface Scale { 2585 | domain(): number[]; 2586 | domain(domain: number[]): Scale; 2587 | 2588 | range(): number[]; 2589 | range(range: number[]): Scale; 2590 | 2591 | invert?(y: number): number; 2592 | } 2593 | } 2594 | 2595 | interface Brush { 2596 | (selection: Selection): void; 2597 | (selection: Transition): void; 2598 | 2599 | event(selection: Selection): void; 2600 | event(selection: Transition): void; 2601 | 2602 | x(): brush.Scale; 2603 | x(x: brush.Scale): Brush; 2604 | 2605 | y(): brush.Scale; 2606 | y(y: brush.Scale): Brush; 2607 | 2608 | extent(): [number, number] | [[number, number], [number, number]]; 2609 | extent(extent: [number, number] | [[number, number], [number, number]]): Brush; 2610 | 2611 | clamp(): boolean | [boolean, boolean]; 2612 | clamp(clamp: boolean | [boolean, boolean]): Brush; 2613 | 2614 | clear(): void; 2615 | 2616 | empty(): boolean; 2617 | 2618 | on(type: 'brushstart'): (datum: T, index: number) => void; 2619 | on(type: 'brush'): (datum: T, index: number) => void; 2620 | on(type: 'brushend'): (datum: T, index: number) => void; 2621 | on(type: string): (datum: T, index: number) => void; 2622 | 2623 | on(type: 'brushstart', listener: (datum: T, index: number) => void): Brush; 2624 | on(type: 'brush', listener: (datum: T, index: number) => void): Brush; 2625 | on(type: 'brushend', listener: (datum: T, index: number) => void): Brush; 2626 | on(type: string, listener: (datum: T, index: number) => void): Brush; 2627 | } 2628 | } 2629 | 2630 | export function xhr(url: string, mimeType?: string, callback?: (err: any, data: any) => void): Xhr; 2631 | export function xhr(url: string, callback: (err: any, data: any) => void): Xhr; 2632 | 2633 | interface Xhr { 2634 | header(name: string): string; 2635 | header(name: string, value: string): Xhr; 2636 | 2637 | mimeType(): string; 2638 | mimeType(type: string): Xhr; 2639 | 2640 | responseType(): string; 2641 | responseType(type: string): Xhr; 2642 | 2643 | response(): (request: XMLHttpRequest) => any; 2644 | response(value: (request: XMLHttpRequest) => any): Xhr; 2645 | 2646 | get(callback?: (err: any, data: any) => void): Xhr; 2647 | 2648 | post(data?: any, callback?: (err: any, data: any) => void): Xhr; 2649 | post(callback: (err: any, data: any) => void): Xhr; 2650 | 2651 | send(method: string, data?: any, callback?: (err: any, data: any) => void): Xhr; 2652 | send(method: string, callback: (err: any, data: any) => void): Xhr; 2653 | 2654 | abort(): Xhr; 2655 | 2656 | on(type: "beforesend"): (request: XMLHttpRequest) => void; 2657 | on(type: "progress"): (request: XMLHttpRequest) => void; 2658 | on(type: "load"): (response: any) => void; 2659 | on(type: "error"): (err: any) => void; 2660 | on(type: string): (...args: any[]) => void; 2661 | 2662 | on(type: "beforesend", listener: (request: XMLHttpRequest) => void): Xhr; 2663 | on(type: "progress", listener: (request: XMLHttpRequest) => void): Xhr; 2664 | on(type: "load", listener: (response: any) => void): Xhr; 2665 | on(type: "error", listener: (err: any) => void): Xhr; 2666 | on(type: string, listener: (...args: any[]) => void): Xhr; 2667 | } 2668 | 2669 | export function text(url: string, mimeType?: string, callback?: (err: any, data: string) => void): Xhr; 2670 | export function text(url: string, callback: (err: any, data: string) => void): Xhr; 2671 | 2672 | export function json(url: string, callback?: (err: any, data: any) => void): Xhr; 2673 | 2674 | export function xml(url: string, mimeType?: string, callback?: (err: any, data: any) => void): Xhr; 2675 | export function xml(url: string, callback: (err: any, data: any) => void): Xhr; 2676 | 2677 | export function html(url: string, callback?: (err: any, data: DocumentFragment) => void): Xhr; 2678 | 2679 | export var csv: Dsv; 2680 | export var tsv: Dsv; 2681 | export function dsv(delimiter: string, mimeType: string): Dsv; 2682 | 2683 | interface Dsv { 2684 | (url: string, callback: (rows: { [key: string]: string }[]) => void): DsvXhr<{ [key: string]: string }>; 2685 | (url: string, callback: (error: any, rows: { [key: string]: string }[]) => void): DsvXhr<{ [key: string]: string }>; 2686 | (url: string): DsvXhr<{ [key: string]: string }>; 2687 | (url: string, accessor: (row: { [key: string]: string }) => T, callback: (rows: T[]) => void): DsvXhr; 2688 | (url: string, accessor: (row: { [key: string]: string }) => T, callback: (error: any, rows: T[]) => void): DsvXhr; 2689 | (url: string, accessor: (row: { [key: string]: string }) => T): DsvXhr; 2690 | 2691 | parse(string: string): { [key: string]: string }[]; 2692 | parse(string: string, accessor: (row: { [key: string]: string }, index: number) => T): T[]; 2693 | 2694 | parseRows(string: string): string[][]; 2695 | parseRows(string: string, accessor: (row: string[], index: number) => T): T[]; 2696 | 2697 | format(rows: Object[]): string; 2698 | 2699 | formatRows(rows: string[][]): string; 2700 | } 2701 | 2702 | interface DsvXhr extends Xhr { 2703 | row(): (row: { [key: string]: string }) => T; 2704 | row(accessor: (row: { [key: string]: string }) => U): DsvXhr; 2705 | 2706 | header(name: string): string; 2707 | header(name: string, value: string): DsvXhr; 2708 | 2709 | mimeType(): string; 2710 | mimeType(type: string): DsvXhr; 2711 | 2712 | responseType(): string; 2713 | responseType(type: string): DsvXhr; 2714 | 2715 | response(): (request: XMLHttpRequest) => any; 2716 | response(value: (request: XMLHttpRequest) => any): DsvXhr; 2717 | 2718 | get(callback?: (err: XMLHttpRequest, data: T[]) => void): DsvXhr; 2719 | post(data?: any, callback?: (err: XMLHttpRequest, data: T[]) => void): DsvXhr; 2720 | post(callback: (err: XMLHttpRequest, data: T[]) => void): DsvXhr; 2721 | 2722 | send(method: string, data?: any, callback?: (err: XMLHttpRequest, data: T[]) => void): DsvXhr; 2723 | send(method: string, callback: (err: XMLHttpRequest, data: T[]) => void): DsvXhr; 2724 | 2725 | abort(): DsvXhr; 2726 | 2727 | on(type: "beforesend"): (request: XMLHttpRequest) => void; 2728 | on(type: "progress"): (request: XMLHttpRequest) => void; 2729 | on(type: "load"): (response: T[]) => void; 2730 | on(type: "error"): (err: any) => void; 2731 | on(type: string): (...args: any[]) => void; 2732 | 2733 | on(type: "beforesend", listener: (request: XMLHttpRequest) => void): DsvXhr; 2734 | on(type: "progress", listener: (request: XMLHttpRequest) => void): DsvXhr; 2735 | on(type: "load", listener: (response: T[]) => void): DsvXhr; 2736 | on(type: "error", listener: (err: any) => void): DsvXhr; 2737 | on(type: string, listener: (...args: any[]) => void): DsvXhr; 2738 | } 2739 | 2740 | export function locale(definition: LocaleDefinition): Locale; 2741 | 2742 | interface LocaleDefinition { 2743 | decimal: string; 2744 | thousands: string; 2745 | grouping: number[]; 2746 | currency: [string, string]; 2747 | dateTime: string; 2748 | date: string; 2749 | time: string; 2750 | periods: [string, string]; 2751 | days: [string, string, string, string, string, string, string]; 2752 | shortDays: [string, string, string, string, string, string, string]; 2753 | months: [string, string, string, string, string, string, string, string, string, string, string, string]; 2754 | shortMonths: [string, string, string, string, string, string, string, string, string, string, string, string]; 2755 | } 2756 | 2757 | interface Locale { 2758 | numberFormat(specifier: string): (n: number) => string; 2759 | timeFormat: { 2760 | (specifier: string): time.Format; 2761 | utc(specifier: string): time.Format; 2762 | multi(formats: Array<[string, (d: Date) => boolean|number]>): time.Format; 2763 | } 2764 | } 2765 | 2766 | namespace layout { 2767 | export function bundle(): Bundle; 2768 | export function bundle(): Bundle 2769 | 2770 | namespace bundle { 2771 | interface Node { 2772 | parent: Node; 2773 | } 2774 | 2775 | interface Link { 2776 | source: T; 2777 | target: T; 2778 | } 2779 | } 2780 | 2781 | interface Bundle { 2782 | (links: bundle.Link[]): T[][]; 2783 | } 2784 | 2785 | export function chord(): Chord; 2786 | 2787 | namespace chord { 2788 | interface Link { 2789 | source: Node; 2790 | target: Node; 2791 | } 2792 | 2793 | interface Node { 2794 | index: number; 2795 | subindex: number; 2796 | startAngle: number; 2797 | endAngle: number; 2798 | value: number; 2799 | } 2800 | 2801 | interface Group { 2802 | index: number; 2803 | startAngle: number; 2804 | endAngle: number; 2805 | value: number; 2806 | } 2807 | } 2808 | 2809 | interface Chord { 2810 | matrix(): number[][]; 2811 | matrix(matrix: number[][]): Chord; 2812 | 2813 | padding(): number; 2814 | padding(padding: number): Chord; 2815 | 2816 | sortGroups(): (a: number, b: number) => number; 2817 | sortGroups(comparator: (a: number, b: number) => number): Chord; 2818 | 2819 | sortSubgroups(): (a: number, b: number) => number; 2820 | sortSubgroups(comparator: (a: number, b: number) => number): Chord; 2821 | 2822 | sortChords(): (a: number, b: number) => number; 2823 | sortChords(comparator: (a: number, b: number) => number): Chord; 2824 | 2825 | chords(): chord.Link[]; 2826 | groups(): chord.Group[]; 2827 | } 2828 | 2829 | export function cluster(): Cluster; 2830 | export function cluster(): Cluster; 2831 | 2832 | namespace cluster { 2833 | interface Result { 2834 | parent?: Result; 2835 | children?: Result[]; 2836 | depth?: number; 2837 | x?: number; 2838 | y?: number; 2839 | } 2840 | 2841 | interface Link { 2842 | source: T; 2843 | target: T; 2844 | } 2845 | } 2846 | 2847 | interface Cluster { 2848 | (root: T): T[]; 2849 | 2850 | nodes(root: T): T[]; 2851 | 2852 | links(nodes: T[]): cluster.Link[]; 2853 | 2854 | children(): (node: T) => T[]; 2855 | children(accessor: (node: T) => T[]): Cluster; 2856 | 2857 | sort(): (a: T, b: T) => number; 2858 | sort(comparator: (a: T, b: T) => number): Cluster; 2859 | 2860 | separation(): (a: T, b: T) => number; 2861 | separation(separation: (a: T, b: T) => number): Cluster; 2862 | 2863 | size(): [number, number]; 2864 | size(size: [number, number]): Cluster; 2865 | 2866 | nodeSize(): [number, number]; 2867 | nodeSize(nodeSize: [number, number]): Cluster; 2868 | 2869 | value(): (a: T) => number; 2870 | value(value: (a: T) => number): Cluster; 2871 | } 2872 | 2873 | export function force(): Force, force.Node>; 2874 | export function force(): Force, Node>; 2875 | export function force, Node extends force.Node>(): Force; 2876 | 2877 | namespace force { 2878 | interface Link { 2879 | source: T; 2880 | target: T; 2881 | } 2882 | 2883 | interface Node { 2884 | index?: number; 2885 | x?: number; 2886 | y?: number; 2887 | px?: number; 2888 | py?: number; 2889 | fixed?: boolean; 2890 | weight?: number; 2891 | } 2892 | 2893 | interface Event { 2894 | type: string; 2895 | alpha: number; 2896 | } 2897 | } 2898 | 2899 | interface Force, Node extends force.Node> { 2900 | size(): [number, number]; 2901 | size(size: [number, number]): Force; 2902 | 2903 | linkDistance(): number | ((link: Link, index: number) => number); 2904 | linkDistance(distance: number): Force; 2905 | linkDistance(distance: (link: Link, index: number) => number): Force; 2906 | 2907 | linkStrength(): number | ((link: Link, index: number) => number); 2908 | linkStrength(strength: number): Force; 2909 | linkStrength(strength: (link: Link, index: number) => number): Force; 2910 | 2911 | friction(): number; 2912 | friction(friction: number): Force; 2913 | 2914 | charge(): number | ((node: Node, index: number) => number); 2915 | charge(charge: number): Force; 2916 | charge(charge: (node: Node, index: number) => number): Force; 2917 | 2918 | chargeDistance(): number; 2919 | chargeDistance(distance: number): Force; 2920 | 2921 | theta(): number; 2922 | theta(theta: number): Force; 2923 | 2924 | gravity(): number; 2925 | gravity(gravity: number): Force; 2926 | 2927 | nodes(): Node[]; 2928 | nodes(nodes: Node[]): Force; 2929 | 2930 | links(): Link[]; 2931 | links(links: { source: number; target: number }[]): Force; 2932 | links(links: Link[]): Force; 2933 | 2934 | start(): Force; 2935 | 2936 | alpha(): number; 2937 | alpha(value: number): Force; 2938 | 2939 | resume(): Force; 2940 | 2941 | stop(): Force; 2942 | 2943 | on(type: string): (event: force.Event) => void; 2944 | on(type: string, listener: (event: force.Event) => void): Force; 2945 | 2946 | drag(): behavior.Drag; 2947 | drag(selection: Selection): void; 2948 | } 2949 | 2950 | export function hierarchy(): Hierarchy; 2951 | export function hierarchy(): Hierarchy; 2952 | 2953 | namespace hierarchy { 2954 | interface Result { 2955 | parent?: Result; 2956 | children?: Result[]; 2957 | value?: number; 2958 | depth?: number; 2959 | } 2960 | } 2961 | 2962 | interface Hierarchy { 2963 | (root: T): T[]; 2964 | 2965 | children(): (node: T) => T[]; 2966 | children(accessor: (node: T) => T[]): Hierarchy; 2967 | 2968 | sort(): (a: T, b: T) => number; 2969 | sort(comparator: (a: T, b: T) => number): Hierarchy; 2970 | 2971 | value(): (node: T) => number; 2972 | value(accessor: (node: T) => number): Hierarchy; 2973 | 2974 | revalue(root: T): T[]; 2975 | } 2976 | 2977 | export function histogram(): Histogram; 2978 | export function histogram(): Histogram; 2979 | 2980 | namespace histogram { 2981 | interface Bin extends Array { 2982 | x: number; 2983 | dx: number; 2984 | y: number; 2985 | } 2986 | } 2987 | 2988 | interface Histogram { 2989 | (values: T[], index?: number): histogram.Bin[]; 2990 | 2991 | value(): (datum: T, index: number) => number; 2992 | value(value: (datum: T, index: number) => number): Histogram; 2993 | 2994 | range(): (values: T[], index: number) => [number, number]; 2995 | range(range: (values: T[], index: number) => [number, number]): Histogram; 2996 | range(range: [number, number]): Histogram; 2997 | 2998 | bins(): (range: [number, number], values: T[], index: number) => number[]; 2999 | bins(count: number): Histogram; 3000 | bins(thresholds: number[]): Histogram; 3001 | bins(func: (range: [number, number], values: T[], index: number) => number[]): Histogram; 3002 | 3003 | frequency(): boolean; 3004 | frequency(frequency: boolean): Histogram; 3005 | } 3006 | 3007 | export function pack(): Pack; 3008 | export function pack(): Pack; 3009 | 3010 | namespace pack { 3011 | interface Node { 3012 | parent?: Node; 3013 | children?: Node[]; 3014 | value?: number; 3015 | depth?: number; 3016 | x?: number; 3017 | y?: number; 3018 | r?: number; 3019 | } 3020 | 3021 | interface Link { 3022 | source: Node; 3023 | target: Node; 3024 | } 3025 | } 3026 | 3027 | interface Pack { 3028 | (root: T): T[]; 3029 | 3030 | nodes(root: T): T[]; 3031 | 3032 | links(nodes: T[]): pack.Link[]; 3033 | 3034 | children(): (node: T, depth: number) => T[]; 3035 | children(children: (node: T, depth: number) => T[]): Pack; 3036 | 3037 | sort(): (a: T, b: T) => number; 3038 | sort(comparator: (a: T, b: T) => number): Pack; 3039 | 3040 | value(): (node: T) => number; 3041 | value(value: (node: T) => number): Pack; 3042 | 3043 | size(): [number, number]; 3044 | size(size: [number, number]): Pack; 3045 | 3046 | radius(): number | ((node: T) => number); 3047 | radius(radius: number): Pack; 3048 | radius(radius: (node: T) => number): Pack; 3049 | 3050 | padding(): number; 3051 | padding(padding: number): Pack; 3052 | } 3053 | 3054 | export function partition(): Partition; 3055 | export function partition(): Partition; 3056 | 3057 | namespace partition { 3058 | interface Link { 3059 | source: T; 3060 | target: T; 3061 | } 3062 | 3063 | interface Node { 3064 | parent?: Node; 3065 | children?: number; 3066 | value?: number; 3067 | depth?: number; 3068 | x?: number; 3069 | y?: number; 3070 | dx?: number; 3071 | dy?: number; 3072 | } 3073 | 3074 | } 3075 | 3076 | export interface Partition { 3077 | (root: T): T[]; 3078 | 3079 | nodes(root: T): T[]; 3080 | 3081 | links(nodes: T[]): partition.Link[]; 3082 | 3083 | children(): (node: T, depth: number) => T[]; 3084 | children(children: (node: T, depth: number) => T[]): Partition; 3085 | 3086 | sort(): (a: T, b: T) => number; 3087 | sort(comparator: (a: T, b: T) => number): Partition; 3088 | 3089 | value(): (node: T) => number; 3090 | value(value: (node: T) => number): Partition; 3091 | 3092 | size(): [number, number]; 3093 | size(size: [number, number]): Partition; 3094 | } 3095 | 3096 | export function pie(): Pie; 3097 | export function pie(): Pie; 3098 | 3099 | namespace pie { 3100 | interface Arc { 3101 | value: number; 3102 | startAngle: number; 3103 | endAngle: number; 3104 | padAngle: number; 3105 | data: T; 3106 | } 3107 | } 3108 | 3109 | interface Pie { 3110 | (data: T[], index?: number): pie.Arc[]; 3111 | 3112 | value(): (datum: T, index: number) => number; 3113 | value(accessor: (datum: T, index: number) => number): Pie; 3114 | 3115 | sort(): (a: T, b: T) => number; 3116 | sort(comparator: (a: T, b: T) => number): Pie; 3117 | 3118 | startAngle(): number | ((data: T[], index: number) => number); 3119 | startAngle(angle: number): Pie; 3120 | startAngle(angle: (data: T[], index: number) => number): Pie; 3121 | 3122 | endAngle(): number | ((data: T[], index: number) => number); 3123 | endAngle(angle: number): Pie; 3124 | endAngle(angle: (data: T[], index: number) => number): Pie; 3125 | 3126 | padAngle(): number | ((data: T[], index: number) => number); 3127 | padAngle(angle: number): Pie; 3128 | padAngle(angle: (data: T[], index: number) => number): Pie; 3129 | } 3130 | 3131 | export function stack(): Stack; 3132 | export function stack(): Stack; 3133 | export function stack(): Stack; 3134 | namespace stack { 3135 | interface Value { 3136 | x: number; 3137 | y: number; 3138 | y0?: number; 3139 | } 3140 | } 3141 | 3142 | interface Stack { 3143 | (layers: Series[], index?: number): Series[]; 3144 | 3145 | values(): (layer: Series, index: number) => Value[]; 3146 | values(accessor: (layer: Series, index: number) => Value[]): Stack; 3147 | 3148 | offset(): (data: Array<[number, number]>) => number[]; 3149 | offset(offset: "silhouette"): Stack; 3150 | offset(offset: "wiggle"): Stack; 3151 | offset(offset: "expand"): Stack; 3152 | offset(offset: "zero"): Stack; 3153 | offset(offset: string): Stack; 3154 | offset(offset: (data: Array<[number, number]>) => number[]): Stack; 3155 | 3156 | order(): (data: Array<[number, number]>) => number[]; 3157 | order(order: "inside-out"): Stack; 3158 | order(order: "reverse"): Stack; 3159 | order(order: "default"): Stack; 3160 | order(order: string): Stack; 3161 | order(order: (data: Array<[number, number]>) => number[]): Stack; 3162 | 3163 | x(): (value: Value, index: number) => number; 3164 | x(accessor: (value: Value, index: number) => number): Stack; 3165 | 3166 | y(): (value: Value, index: number) => number; 3167 | y(accesor: (value: Value, index: number) => number): Stack; 3168 | 3169 | out(): (value: Value, y0: number, y: number) => void; 3170 | out(setter: (value: Value, y0: number, y: number) => void): Stack; 3171 | } 3172 | 3173 | export function tree(): Tree; 3174 | export function tree(): Tree; 3175 | 3176 | namespace tree { 3177 | interface Link { 3178 | source: T; 3179 | target: T; 3180 | } 3181 | 3182 | interface Node { 3183 | parent?: Node; 3184 | children?: Node[]; 3185 | depth?: number; 3186 | x?: number; 3187 | y?: number; 3188 | } 3189 | } 3190 | 3191 | interface Tree { 3192 | (root: T, index?: number): T[]; 3193 | 3194 | nodes(root: T, index?: number): T[]; 3195 | 3196 | links(nodes: T[]): tree.Link[]; 3197 | 3198 | children(): (datum: T, index: number) => T[]; 3199 | children(children: (datum: T, index: number) => T[]): Tree; 3200 | 3201 | separation(): (a: T, b: T) => number; 3202 | separation(separation: (a: T, b: T) => number): Tree; 3203 | 3204 | size(): [number, number]; 3205 | size(size: [number, number]): Tree; 3206 | 3207 | nodeSize(): [number, number]; 3208 | nodeSize(size: [number, number]): Tree; 3209 | 3210 | sort(): (a: T, b: T) => number; 3211 | sort(comparator: (a: T, b: T) => number): Tree; 3212 | 3213 | value(): (datum: T, index: number) => number; 3214 | value(value: (datum: T, index: number) => number): Tree; 3215 | } 3216 | 3217 | export function treemap(): Treemap; 3218 | export function treemap(): Treemap; 3219 | 3220 | namespace treemap { 3221 | interface Node { 3222 | parent?: Node; 3223 | children?: Node[]; 3224 | value?: number; 3225 | depth?: number; 3226 | x?: number; 3227 | y?: number; 3228 | dx?: number; 3229 | dy?: number; 3230 | } 3231 | 3232 | interface Link { 3233 | source: T; 3234 | target: T; 3235 | } 3236 | 3237 | type Padding = number | [number, number, number, number]; 3238 | } 3239 | 3240 | interface Treemap { 3241 | (root: T, index?: number): T[]; 3242 | 3243 | nodes(root: T, index?: number): T[]; 3244 | 3245 | links(nodes: T[]): treemap.Link[]; 3246 | 3247 | children(): (node: T, depth: number) => T[]; 3248 | children(children: (node: T, depth: number) => T[]): Treemap; 3249 | 3250 | sort(): (a: T, b: T) => number; 3251 | sort(comparator: (a: T, b: T) => number): Treemap; 3252 | 3253 | value(): (node: T, index: number) => number; 3254 | value(value: (node: T, index: number) => number): Treemap; 3255 | 3256 | size(): [number, number]; 3257 | size(size: [number, number]): Treemap; 3258 | 3259 | padding(): (node: T, depth: number) => treemap.Padding; 3260 | padding(padding: treemap.Padding): Treemap; 3261 | padding(padding: (node: T, depth: number) => treemap.Padding): Treemap; 3262 | 3263 | round(): boolean; 3264 | round(round: boolean): Treemap; 3265 | 3266 | sticky(): boolean; 3267 | sticky(sticky: boolean): boolean; 3268 | 3269 | mode(): string; 3270 | mode(mode: "squarify"): Treemap; 3271 | mode(mode: "slice"): Treemap; 3272 | mode(mode: "dice"): Treemap; 3273 | mode(mode: "slice-dice"): Treemap; 3274 | mode(mode: string): Treemap; 3275 | 3276 | ratio(): number; 3277 | ratio(ratio: number): Treemap; 3278 | } 3279 | } 3280 | 3281 | namespace geom { 3282 | export function voronoi(): Voronoi<[number, number]>; 3283 | export function voronoi(): Voronoi; 3284 | 3285 | namespace voronoi { 3286 | interface Link { 3287 | source: T; 3288 | target: T; 3289 | } 3290 | } 3291 | 3292 | interface Voronoi { 3293 | (data: T[]): Array<[number, number]>; 3294 | 3295 | x(): (vertex: T) => number; 3296 | x(x: (vertex: T) => number): Voronoi; 3297 | 3298 | y(): (vertex: T) => number; 3299 | y(y: (vertex: T) => number): Voronoi; 3300 | 3301 | clipExtent(): [[number, number], [number, number]]; 3302 | clipExtent(extent: [[number, number], [number, number]]): Voronoi; 3303 | 3304 | links(data: T[]): voronoi.Link[]; 3305 | 3306 | triangles(data: T[]): Array<[T, T, T]>; 3307 | } 3308 | 3309 | /** 3310 | * @deprecated use d3.geom.voronoi().triangles() instead 3311 | */ 3312 | export function delaunay(vertices: Array<[number, number]>): Array<[[number, number], [number, number], [number, number]]>; 3313 | 3314 | export function quadtree(): Quadtree<[number, number]>; 3315 | export function quadtree(nodes: T[], x1?: number, y1?: number, x2?: number, y2?: number): quadtree.Quadtree; 3316 | 3317 | namespace quadtree { 3318 | interface Node { 3319 | nodes: [Node, Node, Node, Node]; 3320 | leaf: boolean; 3321 | point: T; 3322 | x: number; 3323 | y: number; 3324 | } 3325 | 3326 | interface Quadtree extends Node { 3327 | add(point: T): void; 3328 | visit(callback: (node: Node, x1: number, y1: number, x2: number, y2: number) => boolean | void): void; 3329 | find(point: [number, number]): T; 3330 | } 3331 | } 3332 | 3333 | interface Quadtree { 3334 | (points: T[]): quadtree.Quadtree; 3335 | 3336 | x(): (datum: T, index: number) => number; 3337 | x(x: number): Quadtree; 3338 | x(x: (datum: T, index: number) => number): Quadtree; 3339 | 3340 | y(): (datum: T, index: number) => number; 3341 | y(y: number): Quadtree; 3342 | y(y: (datum: T, index: number) => number): Quadtree; 3343 | 3344 | extent(): [[number, number], [number, number]]; 3345 | extent(extent: [[number, number], [number, number]]): Quadtree; 3346 | } 3347 | 3348 | export function hull(vertices: Array<[number, number]>): Array<[number, number]>; 3349 | export function hull(): Hull<[number, number]>; 3350 | export function hull(): Hull; 3351 | 3352 | interface Hull { 3353 | (vertices: T[]): Array<[number, number]>; 3354 | 3355 | x(): (datum: T) => number; 3356 | x(x: (datum: T) => number): Hull; 3357 | 3358 | y(): (datum: T) => number; 3359 | y(y: (datum: T) => number): Hull; 3360 | } 3361 | 3362 | export function polygon(vertices: Array<[number, number]>): Polygon; 3363 | 3364 | interface Polygon { 3365 | area(): number; 3366 | 3367 | centroid(): [number, number]; 3368 | 3369 | clip(subject: Array<[number, number]>): Array<[number, number]>; 3370 | } 3371 | } 3372 | } 3373 | 3374 | interface MyNode { 3375 | getBoundingClientRect() : ClientRect; 3376 | } 3377 | 3378 | // we need this to exist 3379 | interface TouchList { } 3380 | 3381 | declare module 'd3' { 3382 | export = d3; 3383 | } 3384 | --------------------------------------------------------------------------------