Merge pull request #33599 from locknono/master

add types for `d3-cloud`
This commit is contained in:
Gabriela Britto
2019-03-05 09:42:32 -08:00
committed by GitHub
2 changed files with 23 additions and 2 deletions

View File

@@ -27,8 +27,11 @@ d3.layout.cloud().size([300, 300])
.font("Impact")
.fontSize(function(d:ICompTextSize) { return d.size; })
.on("end", draw)
.random()
.canvas()
.start();
function draw(words:ICompTextSize[]) {
d3.select("body").append("svg")
.attr("width", 300)

View File

@@ -1,6 +1,6 @@
// Type definitions for d3JS cloud layout plugin by Jason Davies v1.2.2
// Type definitions for d3JS cloud layout plugin by Jason Davies v1.2.5
// Project: https://github.com/jasondavies/d3-cloud
// Definitions by: hans windhoff <https://github.com/hansrwindhoff>
// Definitions by: hans windhoff <https://github.com/hansrwindhoff>, locknono <https://github.com/locknono>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as d3 from 'd3';
@@ -71,6 +71,24 @@ declare module 'd3' {
padding(padding: number): Cloud<T>;
padding(padding: (datum: T, index: number) => number): Cloud<T>;
/**
* If specified, sets the internal random number generator,used for selecting the initial position of each word,
* and the clockwise/counterclockwise direction of the spiral for each word.
*
* @param randomFunction should return a number in the range [0, 1).The default is Math.random.
*/
random(): Cloud<T>;
random(randomFunction: () => number): Cloud<T>;
/**
* If specified, sets the canvas generator function, which is used internally to draw text.
* When using Node.js, you will almost definitely override the default, e.g. using the canvas module.
* @param canvasGenerator should return a HTMLCanvasElement.The default is: ()=>{document.createElement("canvas");}
*
*/
canvas():Cloud<T>;
canvas(canvasGenerator: () => HTMLCanvasElement): Cloud<T>;
on(type: "word", listener: (word: T) => void): Cloud<T>;
on(type: "end", listener: (tags: T[], bounds: { x: number; y: number }[]) => void): Cloud<T>;
on(type: string, listener: (...args: any[]) => void): Cloud<T>;