diff --git a/d3.cloud.layout/d3.cloud.layout.d.ts b/d3.cloud.layout/d3.cloud.layout.d.ts index 5ac3aced8..1e41ecbc2 100644 --- a/d3.cloud.layout/d3.cloud.layout.d.ts +++ b/d3.cloud.layout/d3.cloud.layout.d.ts @@ -5,41 +5,77 @@ /// -declare module D3 { - export module Layout { - export interface IRotate { - (number:number) : CloudLayout; - (number:()=>number) : CloudLayout; +declare module d3 { + module layout { + export function cloud(): Cloud; + export function cloud(): Cloud; + + module cloud { + interface Word { + text?: string; + font?: string; + style?: string; + weight?: string | number; + rotate?: number; + size?: number; + padding?: number; + x?: number; + y?: number; + } } + interface Cloud { + start(): Cloud; + stop(): Cloud; + timeInterval(): number; + timeInterval(interval: number): Cloud; - export interface CloudLayout { - (layers: any[], index?: number): any[]; - values(accessor?: (d: any) => any): CloudLayout; - offset(offset: string): CloudLayout; - size: { - /** - * Gets the available layout size - */ - (): Array; - /** - * Sets the available layout size - */ - (size: Array): CloudLayout; - }; - words: (inputArray: Array) => CloudLayout; - rotate:IRotate; - padding: (number:number) => CloudLayout; - font: (string:string) => CloudLayout; - fontSize(fctn: (d: any) => number): CloudLayout; - on: (eventname: string, callee: (words: any[]) => void) => CloudLayout; - start: () => CloudLayout; + words(): T[]; + words(words: T[]): Cloud; + + size(): [number, number]; + size(size: [number, number]): Cloud; + + font(): (datum: T, index: number) => string; + font(font: string): Cloud; + font(font: (datum: T, index: number) => string): Cloud; + + fontStyle(): (datum: T, index: number) => string; + fontStyle(style: string): Cloud; + fontStyle(style: (datum: T, index: number) => string): Cloud; + + fontWeight(): (datum: T, index: number) => string | number; + fontWeight(weight: string | number): Cloud; + fontWeight(weight: (datum: T, index: number) => string | number): Cloud; + + rotate(): (datum: T, index: number) => number; + rotate(rotate: number): Cloud; + rotate(rotate: (datum: T, index: number) => number): Cloud; + + text(): (datum: T, index: number) => string; + text(text: string): Cloud; + text(text: (datum: T, index: number) => string): Cloud; + + spiral(): (size: number) => (t: number) => [number, number]; + spiral(name: string): Cloud; + spiral(spiral: (size: number) => (t: number) => [number, number]): Cloud; + + fontSize(): (datum: T, index: number) => number; + fontSize(size: number): Cloud; + fontSize(size: (datum: T, index: number) => number): Cloud; + + padding(): (datum: T, index: number) => number; + padding(padding: number): Cloud; + padding(padding: (datum: T, index: number) => number): Cloud; + + on(type: "word", listener: (word: T) => void): Cloud; + on(type: "end", listener: (tags: T[], bounds: { x: number; y: number }[]) => void): Cloud; + on(type: string, listener: (...args: any[]) => void): Cloud; + + on(type: "word"): (word: T) => void; + on(type: "end"): (tags: T[], bounds: { x: number; y: number }[]) => void; + on(type: string): (...args: any[]) => void; + } } - - - export interface Layout { - cloud(): CloudLayout; - } - } -} \ No newline at end of file +} diff --git a/d3/d3-tests.ts b/d3/d3-tests.ts index 51c51f608..70e4036dd 100644 --- a/d3/d3-tests.ts +++ b/d3/d3-tests.ts @@ -1,19 +1,23 @@ /// //Example from http://bl.ocks.org/3887235 +interface TestPieChartData { + population: number; + age: string; +} function testPieChart() { var width = 960, height = 500, radius = Math.min(width, height) / 2; - var color = d3.scale.ordinal() + var color = d3.scale.ordinal() .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]); - var arc = d3.svg.arc() + var arc = d3.svg.arc>() .outerRadius(radius - 10) .innerRadius(0); - var pie = d3.layout.pie() + var pie = d3.layout.pie() .sort(null) .value(function (d) { return d.population; }); @@ -23,12 +27,7 @@ function testPieChart() { .append("g") .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); - d3.csv("data.csv", function (error, data) { - - data.forEach(function (d) { - d.population = +d.population; - }); - + d3.csv("data.csv", d => ({ population: +d['population'], age: d['age'] }), function (error, data) { var g = svg.selectAll(".arc") .data(pie(data)) .enter().append("g") @@ -91,12 +90,12 @@ function groupedBarChart() { var x0 = d3.scale.ordinal() .rangeRoundBands([0, width], .1); - var x1 = d3.scale.ordinal(); + var x1 = d3.scale.ordinal(); var y = d3.scale.linear() .range([height, 0]); - var color = d3.scale.ordinal() + var color = d3.scale.ordinal() .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]); var xAxis = d3.svg.axis() @@ -114,7 +113,7 @@ function groupedBarChart() { .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); - d3.csv("data.csv", function (error, data: Array) { + d3.csv("data.csv", function (error, data: Array) { var ageNames = d3.keys(data[0]).filter(function (key) { return key !== "State"; }); data.forEach(function (d) { @@ -146,7 +145,7 @@ function groupedBarChart() { .attr("class", "g") .attr("transform", function (d) { return "translate(" + x0(d.State) + ",0)"; }); - state.selectAll("rect") + state.selectAll("rect") .data(function (d) { return d.ages; }) .enter().append("rect") .attr("width", x1.rangeBand()) @@ -189,7 +188,7 @@ function stackedBarChart() { var y = d3.scale.linear() .rangeRound([height, 0]); - var color = d3.scale.ordinal() + var color = d3.scale.ordinal() .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]); var xAxis = d3.svg.axis() @@ -207,7 +206,7 @@ function stackedBarChart() { .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); - d3.csv("data.csv", function (error, data) { + d3.csv("data.csv", function (error, data: any) { color.domain(d3.keys(data[0]).filter(function (key) { return key !== "State"; })); data.forEach(function (d) { @@ -219,7 +218,7 @@ function stackedBarChart() { data.sort(function (a, b) { return b.total - a.total; }); x.domain(data.map(function (d) { return d.State; })); - y.domain([0, d3.max(data, function (d) { return d.total; })]); + y.domain([0, d3.max(data, function (d: { total: number }) { return d.total; })]); svg.append("g") .attr("class", "x axis") @@ -240,15 +239,15 @@ function stackedBarChart() { .data(data) .enter().append("g") .attr("class", "g") - .attr("transform", function (d) { return "translate(" + x(d.State) + ",0)"; }); + .attr("transform", function (d: any) { return "translate(" + x(d.State) + ",0)"; }); state.selectAll("rect") - .data(function (d) { return d.ages; }) + .data(function (d: any) { return d.ages; }) .enter().append("rect") .attr("width", x.rangeBand()) - .attr("y", function (d) { return y(d.y1); }) - .attr("height", function (d) { return y(d.y0) - y(d.y1); }) - .style("fill", function (d) { return color(d.name); }); + .attr("y", function (d: any) { return y(d.y1); }) + .attr("height", function (d: any) { return y(d.y0) - y(d.y1); }) + .style("fill", function (d: any) { return color(d.name); }); var legend = svg.selectAll(".legend") .data(color.domain().reverse()) @@ -284,7 +283,7 @@ function normalizedBarChart() { var y = d3.scale.linear() .rangeRound([height, 0]); - var color = d3.scale.ordinal() + var color = d3.scale.ordinal() .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]); var xAxis = d3.svg.axis() @@ -328,21 +327,21 @@ function normalizedBarChart() { .data(data) .enter().append("g") .attr("class", "state") - .attr("transform", function (d) { return "translate(" + x(d.State) + ",0)"; }); + .attr("transform", function (d: any) { return "translate(" + x(d.State) + ",0)"; }); state.selectAll("rect") .data(function (d) { return d.ages; }) .enter().append("rect") .attr("width", x.rangeBand()) - .attr("y", function (d) { return y(d.y1); }) - .attr("height", function (d) { return y(d.y0) - y(d.y1); }) - .style("fill", function (d) { return color(d.name); }); + .attr("y", function (d: any) { return y(d.y1); }) + .attr("height", function (d: any) { return y(d.y0) - y(d.y1); }) + .style("fill", function (d: any) { return color(d.name); }); var legend = svg.select(".state:last-child").selectAll(".legend") - .data(function (d) { return d.ages; }) + .data(function (d: any) { return d.ages; }) .enter().append("g") .attr("class", "legend") - .attr("transform", function (d) { return "translate(" + x.rangeBand() / 2 + "," + y((d.y0 + d.y1) / 2) + ")"; }); + .attr("transform", function (d: any) { return "translate(" + x.rangeBand() / 2 + "," + y((d.y0 + d.y1) / 2) + ")"; }); legend.append("line") .attr("x2", 10); @@ -350,7 +349,7 @@ function normalizedBarChart() { legend.append("text") .attr("x", 13) .attr("dy", ".35em") - .text(function (d) { return d.name; }); + .text(function (d: any) { return d.name; }); }); } @@ -384,14 +383,14 @@ function sortablebarChart() { .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); - d3.tsv("data.tsv", function (error, data) { + d3.tsv("data.tsv", function (error, data: any) { data.forEach(function (d) { d.frequency = +d.frequency; }); x.domain(data.map(function (d) { return d.letter; })); - y.domain([0, d3.max(data, function (d) { return d.frequency; })]); + y.domain([0, d3.max(data, function (d: any) { return d.frequency; })]); svg.append("g") .attr("class", "x axis") @@ -412,10 +411,10 @@ function sortablebarChart() { .data(data) .enter().append("rect") .attr("class", "bar") - .attr("x", function (d) { return x(d.letter); }) + .attr("x", function (d: any) { return x(d.letter); }) .attr("width", x.rangeBand()) - .attr("y", function (d) { return y(d.frequency); }) - .attr("height", function (d) { return height - y(d.frequency); }); + .attr("y", function (d: any) { return y(d.frequency); }) + .attr("height", function (d: any) { return height - y(d.frequency); }); d3.select("input").on("change", change); @@ -497,8 +496,8 @@ function callenderView() { d3.csv("dji.csv", function (error, csv) { var data = d3.nest() - .key(function (d) { return d.Date; }) - .rollup(function (d) { return (d[0].Close - d[0].Open) / d[0].Open; }) + .key(function (d: any) { return d.Date; }) + .rollup(function (d: any) { return (d[0].Close - d[0].Open) / d[0].Open; }) .map(csv); rect.filter(function (d) { return d in data; }) @@ -529,7 +528,7 @@ function lineChart() { var parseDate = d3.time.format("%d-%b-%y").parse; - var x = d3.time.scale() + var x = d3.time.scale() .range([0, width]); var y = d3.scale.linear() @@ -543,7 +542,7 @@ function lineChart() { .scale(y) .orient("left"); - var line = d3.svg.line() + var line = d3.svg.line<{ date: Date; close: number }>() .x(function (d) { return x(d.date); }) .y(function (d) { return y(d.close); }); @@ -559,8 +558,8 @@ function lineChart() { d.close = +d.close; }); - x.domain(d3.extent(data, function (d) { return d.date; })); - y.domain(d3.extent(data, function (d) { return d.close; })); + x.domain(d3.extent(data, function (d: any) { return d.date; })); + y.domain(d3.extent(data, function (d: any) { return d.close; })); svg.append("g") .attr("class", "x axis") @@ -606,7 +605,7 @@ function bivariateAreaChart() { .scale(y) .orient("left"); - var area = d3.svg.area() + var area = d3.svg.area<{ date: Date; low: number; high: number }>() .x(function (d) { return x(d.date); }) .y0(function (d) { return y(d.low); }) .y1(function (d) { return y(d.high); }); @@ -617,15 +616,15 @@ function bivariateAreaChart() { .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); - d3.tsv("data.tsv", function (error, data) { + d3.tsv("data.tsv", function (error, data: any) { data.forEach(function (d) { d.date = parseDate(d.date); d.low = +d.low; d.high = +d.high; }); - x.domain(d3.extent(data, function (d) { return d.date; })); - y.domain([d3.min(data, function (d) { return d.low; }), d3.max(data, function (d) { return d.high; })]); + x.domain(d3.extent(data, function (d: any) { return d.date; })); + y.domain([d3.min(data, function (d: any) { return d.low; }), d3.max(data, function (d: any) { return d.high; })]); svg.append("path") .datum(data) @@ -673,8 +672,8 @@ function dragMultiples() { function dragmove(d) { d3.select(this) - .attr("cx", d.x = Math.max(radius, Math.min(width - radius, d3.event.x))) - .attr("cy", d.y = Math.max(radius, Math.min(height - radius, d3.event.y))); + .attr("cx", d.x = Math.max(radius, Math.min(width - radius, ( d3.event).x))) + .attr("cy", d.y = Math.max(radius, Math.min(height - radius, ( d3.event).y))); } } @@ -806,31 +805,31 @@ function populationPyramid() { .attr("dy", ".71em") .text(2000); - d3.csv("population.csv", function (error, data: Array) { + d3.csv("population.csv", function (error, rows: Array) { // Convert strings to numbers. - data.forEach(function (d) { + rows.forEach(function (d) { d.people = +d.people; d.year = +d.year; d.age = +d.age; } ); // Compute the extent of the data set in age and years. - var age1 = d3.max(data, function (d) { return d.age; } ), - year0 = d3.min(data, function (d) { return d.year; } ), - year1 = d3.max(data, function (d) { return d.year; } ), + var age1 = d3.max(rows, function (d) { return d.age; } ), + year0 = d3.min(rows, function (d) { return d.year; } ), + year1 = d3.max(rows, function (d) { return d.year; } ), year = year1; // Update the scale domains. x.domain([year1 - age1, year1]); - y.domain([0, d3.max(data, function (d) { return d.people; } )]); + y.domain([0, d3.max(rows, function (d) { return d.people; } )]); // Produce a map from year and birthyear to [male, female]. - data = d3.nest() - .key(function (d) { return d.year; } ) + var data = d3.nest() + .key(function (d) { return '' + d.year; } ) .key(function (d) { return '' + (d.year - d.age); } ) .rollup(function (v) { return v.map(function (d) { return d.people; } ); } ) - .map(data); + .map(rows); // Add an axis to show the population values. svg.append("g") @@ -849,7 +848,7 @@ function populationPyramid() { .attr("transform", function (birthyear) { return "translate(" + x(birthyear) + ",0)"; } ); birthyear.selectAll("rect") - .data(function (birthyear) { return data[year][birthyear] || [0, 0]; } ) + .data(function (birthyear): number[] { return data[year][birthyear] || [0, 0]; } ) .enter().append("rect") .attr("x", -barWidth / 2) .attr("width", barWidth) @@ -874,7 +873,7 @@ function populationPyramid() { // Allow the arrow keys to change the displayed year. window.focus(); d3.select(window).on("keydown", function () { - switch (d3.event.keyCode) { + switch (( d3.event).keyCode) { case 37: year = Math.max(year0, year - 10); break; case 39: year = Math.min(year1, year + 10); break; } @@ -890,7 +889,7 @@ function populationPyramid() { .attr("transform", "translate(" + (x(year1) - x(year)) + ",0)"); birthyear.selectAll("rect") - .data(function (birthyear) { return data[year][birthyear] || [0, 0]; } ) + .data(function (birthyear): number[] { return data[year][birthyear] || [0, 0]; } ) .transition() .duration(750) .attr("y", y) @@ -900,17 +899,31 @@ function populationPyramid() { } //Example from http://bl.ocks.org/MoritzStefaner/1377729 -function forcedBasedLabelPlacemant() { +module forcedBasedLabelPlacemant { + interface Node extends d3.layout.force.Node { + label: string; + } + + interface LabelAnchor extends d3.layout.force.Node { + node: Node; + } + + interface LabelAnchorLink extends d3.layout.force.Link { + source: Node; + target: Node; + weight: number; + } + var w = 960, h = 500; var labelDistance = 0; var vis = d3.select("body").append("svg:svg").attr("width", w).attr("height", h); - var nodes = []; - var labelAnchors = []; - var labelAnchorLinks = []; - var links = []; + var nodes: Node[] = []; + var labelAnchors: LabelAnchor[] = []; + var labelAnchorLinks: { source: number; target: number }[] = []; + var links: typeof labelAnchorLinks = []; for (var i = 0; i < 30; i++) { var nodeLabel = { @@ -941,14 +954,14 @@ function forcedBasedLabelPlacemant() { }); }; - var force = d3.layout.force().size([w, h]).nodes(nodes).links(links).gravity(1).linkDistance(50).charge(-3000).linkStrength(function (x) { + var force = d3.layout.force().size([w, h]).nodes(nodes).links(links).gravity(1).linkDistance(50).charge(-3000).linkStrength(function (x) { return x.weight * 10 } ); force.start(); - var force2 = d3.layout.force().nodes(labelAnchors).links(labelAnchorLinks).gravity(0).linkDistance(0).linkStrength(8).charge(-100).size([w, h]); + var force2 = d3.layout.force().nodes(labelAnchors).links(labelAnchorLinks).gravity(0).linkDistance(0).linkStrength(8).charge(-100).size([w, h]); force2.start(); var link = vis.selectAll("line.link").data(links).enter().append("svg:line").attr("class", "link").style("stroke", "#CCC"); @@ -1021,14 +1034,21 @@ function forcedBasedLabelPlacemant() { } //Example from http://bl.ocks.org/mbostock/1125997 -function forceCollapsable() { +module forceCollapsable { + interface Node extends d3.layout.force.Node { + id: string; + _children: Node[]; + children?: Node[]; + size: number; + } + var w = 1280, h = 800, node, link, root; - var force = d3.layout.force() + var force = d3.layout.force() .on("tick", tick) .charge(function (d) { return d._children ? -d.size / 100 : -30; } ) .linkDistance(function (d) { return d.target._children ? 80 : 30; } ) @@ -1048,7 +1068,7 @@ function forceCollapsable() { function update() { var nodes = flatten(root), - links = d3.layout.tree().links(nodes); + links = d3.layout.tree().links(nodes); // Restart the force layout. force @@ -1195,7 +1215,7 @@ function voronoiTesselation() { var width = 960, height = 500; - var vertices = >d3.range(100).map(function (d) { + var vertices = d3.range(100).map(function (d): [number, number] { return [Math.random() * width, Math.random() * height]; } ); @@ -1208,7 +1228,7 @@ function voronoiTesselation() { .attr("class", "PiYG") .on("mousemove", function () { vertices[0] = d3.mouse(this); redraw(); } ); - var path = svg.append("g").selectAll("path"); + var path = >svg.append("g").selectAll("path"); svg.selectAll("circle") .data(vertices.slice(1)) @@ -1234,50 +1254,50 @@ function forceDirectedVoronoi() { links = [], simulate = true, zoomToAdd = true, - color = d3.scale.quantize().domain([10000, 7250]).range(["#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]) + color = d3.scale.quantize().domain([10000, 7250]).range(["#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]) var numVertices = (w*h) / 3000; var vertices = d3.range(numVertices).map(function(i) { var angle = radius * (i+10); - return {x: angle*Math.cos(angle)+(w/2), y: angle*Math.sin(angle)+(h/2)}; + return {x: angle*Math.cos(angle)+(w/2), y: angle*Math.sin(angle)+(h/2)}; }); - var d3_geom_voronoi = d3.geom.voronoi() + var d3_geom_voronoi = d3.geom.voronoi<{ x: number; y: number }>() .x(function(d) { return d.x; }) .y(function(d) { return d.y; }) var prevEventScale = 1; var zoom = d3.behavior.zoom().on("zoom", function(d,i) { if (zoomToAdd){ - if (d3.event.scale > prevEventScale) { + if (( d3.event).scale > prevEventScale) { var angle = radius * vertices.length; - vertices.push({x: angle*Math.cos(angle)+(w/2), y: angle*Math.sin(angle)+(h/2)}) - } else if (vertices.length > 2 && d3.event.scale != prevEventScale) { + vertices.push({x: angle*Math.cos(angle)+(w/2), y: angle*Math.sin(angle)+(h/2)}) + } else if (vertices.length > 2 && ( d3.event).scale != prevEventScale) { vertices.pop(); } force.nodes(vertices).start() } else { - if (d3.event.scale > prevEventScale) { + if (( d3.event).scale > prevEventScale) { radius+= .01 } else { radius -= .01 } vertices.forEach(function(d, i) { var angle = radius * (i+10); - vertices[i] = {x: angle*Math.cos(angle)+(w/2), y: angle*Math.sin(angle)+(h/2)}; + vertices[i] = {x: angle*Math.cos(angle)+(w/2), y: angle*Math.sin(angle)+(h/2)}; }); force.nodes(vertices).start() } - prevEventScale = d3.event.scale; + prevEventScale = ( d3.event).scale; }); d3.select(window) .on("keydown", function() { // shift - if(d3.event.keyCode == 16) { + if(( d3.event).keyCode == 16) { zoomToAdd = false } // s - if(d3.event.keyCode == 83) { + if(( d3.event).keyCode == 83) { simulate = !simulate if(simulate) { force.start() @@ -1303,9 +1323,9 @@ function forceDirectedVoronoi() { force.nodes(vertices).start(); - var circle = svg.selectAll("circle"); - var path = svg.selectAll("path"); - var link = svg.selectAll("line"); + var circle = > svg.selectAll("circle"); + var path = > svg.selectAll("path"); + var link = > svg.selectAll("line"); function update() { path = path.data(d3_geom_voronoi(vertices)); @@ -1313,7 +1333,7 @@ function forceDirectedVoronoi() { // drag node by dragging cell .call(d3.behavior.drag() .on("drag", function(d, i) { - vertices[i] = {x: vertices[i].x + d3.event.dx, y: vertices[i].y + d3.event.dy} + vertices[i] = {x: vertices[i].x + ( d3.event).dx, y: vertices[i].y + ( d3.event).dy} }) ) .style("fill", function(d, i) { return color(0) }) @@ -1347,7 +1367,7 @@ function delaunayTesselation() { var width = 960, height = 500; - var vertices = >d3.range(100).map(function (d) { + var vertices = d3.range(100).map(function (d): [number, number] { return [Math.random() * width, Math.random() * height]; } ); @@ -1357,7 +1377,7 @@ function delaunayTesselation() { .attr("class", "PiYG") .on("mousemove", function () { vertices[0] = d3.mouse(this); redraw(); } ); - var path = svg.append("g").selectAll("path"); + var path = >svg.append("g").selectAll("path"); svg.selectAll("circle") .data(vertices.slice(1)) @@ -1379,11 +1399,13 @@ function quadtree() { var width = 960, height = 500; - var data = d3.range(5000).map(function () { - return { x: Math.random() * width, y: Math.random() * width }; - } ); + var data = d3.range(5000).map(function(): [number, number] { + return [Math.random() * width, Math.random() * width]; + }); - var quadtree = d3.geom.quadtree(data, -1, -1, width + 1, height + 1); + var quadtree = d3.geom.quadtree() + .extent([[-1, -1], [width + 1, height + 1]]) + (data); var brush = d3.svg.brush() .x(d3.scale.identity().domain([0, width])) @@ -1405,11 +1427,11 @@ function quadtree() { .attr("height", function (d) { return d.height; } ); var point = svg.selectAll(".point") - .data(data) + .data(<{ scanned?: boolean; selected?: boolean; 0: number; 1: number }[]> data) .enter().append("circle") .attr("class", "point") - .attr("cx", function (d) { return d.x; } ) - .attr("cy", function (d) { return d.y; } ) + .attr("cx", function (d) { return d[0]; } ) + .attr("cy", function (d) { return d[1]; } ) .attr("r", 4); svg.append("g") @@ -1455,7 +1477,7 @@ function convexHull() { var randomX = d3.random.normal(width / 2, 60), randomY = d3.random.normal(height / 2, 60), - vertices = d3.range(100).map(function () { return [randomX(), randomY()]; } ); + vertices = d3.range(100).map(function (): [number, number] { return [randomX(), randomY()]; } ); var svg = d3.select("body").append("svg") .attr("width", width) @@ -1470,7 +1492,7 @@ function convexHull() { var hull = svg.append("path") .attr("class", "hull"); - var circle = svg.selectAll("circle"); + var circle = > svg.selectAll("circle"); redraw(); @@ -1483,19 +1505,25 @@ function convexHull() { } // example from http://bl.ocks.org/mbostock/1044242 -function hierarchicalEdgeBundling() { +module hierarchicalEdgeBundling { + interface Result extends d3.layout.cluster.Result { + parent: Result; + size: number; + key: string; + } + var diameter = 960, radius = diameter / 2, innerRadius = radius - 120; - var cluster = d3.layout.cluster() + var cluster = d3.layout.cluster() .size([360, innerRadius]) .sort(null) .value(function (d) { return d.size; } ); - var bundle = d3.layout.bundle(); + var bundle = d3.layout.bundle(); - var line = d3.svg.line.radial() + var line = d3.svg.line.radial() .interpolate("bundle") .tension(.85) .radius(function (d) { return d.y; } ) @@ -1604,7 +1632,7 @@ function roundedRectangles() { .attr("transform", function (d, i) { return "scale(" + (1 - d / 25) * 20 + ")"; } ) .style("fill", d3.scale.category20c()); - g.map(function (d) { + var g0 = g.datum(function (d) { return { center: [0, 0], angle: 0 }; } ); @@ -1614,7 +1642,7 @@ function roundedRectangles() { d3.timer(function () { count++; - g.attr("transform", function (d, i) { + g0.attr("transform", function (d, i) { d.center[0] += (mouse[0] - d.center[0]) / (i + 5); d.center[1] += (mouse[1] - d.center[1]) / (i + 5); d.angle += Math.sin((count + i) / 10) * 7; @@ -1643,10 +1671,10 @@ function streamGraph() { .domain([0, d3.max(layers0.concat(layers1), function (layer) { return d3.max(layer, function (d) { return d.y0 + d.y; }); })]) .range([height, 0]); - var color = d3.scale.linear() + var color = d3.scale.linear() .range(["#aad", "#556"]); - var area = d3.svg.area() + var area = d3.svg.area<{ x: number; y: number; y0: number }>() .x(function (d) { return x(d.x); }) .y0(function (d) { return y(d.y0); }) .y1(function (d) { return y(d.y0 + d.y); }); @@ -1694,14 +1722,20 @@ function streamGraph() { } // example from http://mbostock.github.io/d3/talk/20111116/force-collapsible.html -function forceCollapsable2() { +module forceCollapsable2 { + interface Node extends d3.layout.force.Node { + _children: Node[]; + size: number; + id: string; + } + var w = 1280, h = 800, node, link, root; - var force = d3.layout.force() + var force = d3.layout.force() .on("tick", tick) .charge(function (d) { return d._children ? -d.size / 100 : -30; } ) .linkDistance(function (d) { return d.target._children ? 80 : 30; } ) @@ -1721,7 +1755,7 @@ function forceCollapsable2() { function update() { var nodes = flatten(root), - links = d3.layout.tree().links(nodes); + links = d3.layout.tree().links(nodes); // Restart the force layout. force @@ -1828,7 +1862,7 @@ function chordDiagram() { innerRadius = Math.min(width, height) * .41, outerRadius = innerRadius * 1.1; - var fill = d3.scale.ordinal() + var fill = d3.scale.ordinal() .domain(d3.range(4)) .range(["#000000", "#FFDD89", "#957244", "#F26223"]); @@ -1843,7 +1877,7 @@ function chordDiagram() { .enter().append("path") .style("fill", function (d) { return fill(d.index); } ) .style("stroke", function (d) { return fill(d.index); } ) - .attr("d", d3.svg.arc().innerRadius(innerRadius).outerRadius(outerRadius)) + .attr("d", d3.svg.arc().innerRadius(innerRadius).outerRadius(outerRadius)) .on("mouseover", fade(.1)) .on("mouseout", fade(1)); @@ -1876,7 +1910,7 @@ function chordDiagram() { .selectAll("path") .data(chord.chords) .enter().append("path") - .attr("d", d3.svg.chord().radius(innerRadius)) + .attr("d", d3.svg.chord().radius(innerRadius)) .style("fill", function (d) { return fill(d.target.index); } ) .style("opacity", 1); @@ -1925,14 +1959,12 @@ function irisParallel() { .attr("transform", "translate(" + m[3] + "," + m[0] + ")"); d3.csv("iris.csv", function (flowers) { + var i: number; // Create a scale and brush for each trait. traits.forEach(function (d) { - // Coerce values to numbers. - flowers.forEach(function (p) { p[d] = +p[d]; } ); - - y[d] = d3.scale.linear() - .domain(d3.extent(flowers, function (p) { return p[d]; } )) + y[d] = d3.scale.linear() + .domain(d3.extent(flowers, function (p) { return +p[d]; } )) .range([h, 0]); y[d].brush = d3.svg.brush() @@ -1963,7 +1995,7 @@ function irisParallel() { .data(flowers) .enter().append("svg:path") .attr("d", path) - .attr("class", function (d) { return d.species; } ); + .attr("class", function (d) { return d['species']; } ); // Add a group element for each trait. var g = svg.selectAll(".trait") @@ -1971,8 +2003,8 @@ function irisParallel() { .enter().append("svg:g") .attr("class", "trait") .attr("transform", function (d) { return "translate(" + x(d) + ")"; } ) - .call(d3.behavior.drag() - .origin(function (d) { return { x: x(d) }; } ) + .call(d3.behavior.drag() + .origin(function (d) { return { x: x(d), y: undefined }; } ) .on("dragstart", dragstart) .on("drag", drag) .on("dragend", dragend)); @@ -1994,12 +2026,12 @@ function irisParallel() { .attr("x", -8) .attr("width", 16); - function dragstart(d, i?) { + function dragstart(d) { i = traits.indexOf(d); } - function drag(d, i?) { - x.range()[i] = d3.event.x; + function drag(d) { + x.range()[i] = ( d3.event).x; traits.sort(function (a, b) { return x(a) - x(b); } ); g.attr("transform", function (d) { return "translate(" + x(d) + ")"; } ); foreground.attr("d", path); @@ -2015,7 +2047,7 @@ function irisParallel() { // Returns the path for a given data point. function path(d) { - return line(traits.map(function (p) { return [x(p), y[p](d[p])]; } )); + return line(traits.map(function (p): [number, number] { return [x(p), y[p](d[p])]; } )); } // Handles a brush event, toggling the display of foreground lines. @@ -2098,7 +2130,7 @@ function healthAndWealth() { .text(1800); // Load the data. - d3.json("nations.json", function (nations) { + d3.json("nations.json", function (nations: any[]) { // A bisector since many nation's data is sparsely-defined. var bisect = d3.bisector(function (d) { return d[0]; } ); @@ -2219,7 +2251,7 @@ function healthAndWealth() { // Test for d3.functor function functorTest () { - var f = d3.functor(10); + var f: (n: number) => number = d3.functor(10); var g = d3.functor(function (v) { return v; }); return f(10) === g(10); @@ -2243,68 +2275,68 @@ function nestTest () { } ]; - var n1 = d3.nest() - .key(function (d) { return d.a; }) + var n1 = d3.nest<{a: number; b: number[] }>() + .key(function (d) { return String(d.a); }) .sortKeys(d3.descending) .rollup(function (vals) { - return d3.sum(vals); + return d3.sum(vals[0].b); }); n1.map(data); n1.entries(data); - var n2 = d3.nest() - .key(function (d) { return d.a; }) + var n2 = d3.nest<{ a: number; b: number[] }>() + .key(function (d) { return String(d.a); }) .sortValues(function (x1, x2) { return x1[0] < x1[1] ? -1 : (x1[0] > x1[0] ? 1 : 0); }); n2.map(data); n2.entries(data); // Tests adopted from d3's tests. - var keys = d3.nest() - .key(function(d) { return d.foo; }) + var keys = d3.nest<{ foo: number; }>() + .key(function(d) { return String(d.foo); }) .entries([{foo: 1}, {foo: 1}, {foo: 2}]) .map(function(d) { return d.key; }) .sort(d3.ascending); - var entries = d3.nest() - .key(function(d) { return d.foo; }) + var entries = d3.nest<{foo: number; bar?: number}>() + .key(function(d) { return String(d.foo); }) .entries([{foo: 1, bar: 0}, {foo: 2}, {foo: 1, bar: 1}]); - keys = d3.nest() - .key(function(d) { return d.foo; }).sortKeys(d3.descending) + keys = d3.nest<{foo: number}>() + .key(function(d) { return String(d.foo); }).sortKeys(d3.descending) .entries([{foo: 1}, {foo: 1}, {foo: 2}]) .map(function(d) { return d.key; }); - entries = d3.nest() - .key(function(d) { return d.foo; }) + entries = d3.nest<{ foo: number; bar?: number }>() + .key(function(d) { return String(d.foo); }) .sortValues(function(a, b) { return a.bar - b.bar; }) .entries([{foo: 1, bar: 2}, {foo: 1, bar: 0}, {foo: 1, bar: 1}, {foo: 2}]); - entries = d3.nest() - .key(function(d) { return d.foo; }) + entries = d3.nest<{ foo: number; bar?: number }>() + .key(function(d) { return String(d.foo); }) .rollup(function(values) { return d3.sum(values, function(d) { return d.bar; }); }) .entries([{foo: 1, bar: 2}, {foo: 1, bar: 0}, {foo: 1, bar: 1}, {foo: 2}]); - entries = d3.nest() - .key(function(d) { return d[0]; }).sortKeys(d3.ascending) - .key(function(d) { return d[1]; }).sortKeys(d3.ascending) + entries = d3.nest<[number, number]>() + .key(function(d) { return String(d[0]); }).sortKeys(d3.ascending) + .key(function(d) { return String(d[1]); }).sortKeys(d3.ascending) .entries([[0, 1], [0, 2], [1, 1], [1, 2], [0, 2]]); - entries = d3.nest() - .key(function(d) { return d[0]; }).sortKeys(d3.ascending) - .key(function(d) { return d[1]; }).sortKeys(d3.ascending) + entries = d3.nest<[number, number]>() + .key(function(d) { return String(d[0]); }).sortKeys(d3.ascending) + .key(function(d) { return String(d[1]); }).sortKeys(d3.ascending) .rollup(function(values) { return values.length; }) .entries([[0, 1], [0, 2], [1, 1], [1, 2], [0, 2]]); - entries = d3.nest() - .key(function(d) { return d[0]; }).sortKeys(d3.ascending) - .key(function(d) { return d[1]; }).sortKeys(d3.ascending) + entries = d3.nest<{ 0: number; 1: number; 2?: number }>() + .key(function(d) { return String(d[0]); }).sortKeys(d3.ascending) + .key(function(d) { return String(d[1]); }).sortKeys(d3.ascending) .sortValues(function(a, b) { return a[2] - b[2]; }) .entries([[0, 1], [0, 2, 1], [1, 1], [1, 2], [0, 2, 0]]); - var map = d3.nest() - .key(function(d) { return d[0]; }).sortKeys(d3.ascending) - .key(function(d) { return d[1]; }).sortKeys(d3.ascending) + var map = d3.nest<{ 0: number; 1: number; 2?: number }>() + .key(function(d) { return String(d[0]); }).sortKeys(d3.ascending) + .key(function(d) { return String(d[1]); }).sortKeys(d3.ascending) .sortValues(function(a, b) { return a[2] - b[2]; }) .map([[0, 1], [0, 2, 1], [1, 1], [1, 2], [0, 2, 0]]); } @@ -2344,7 +2376,7 @@ function brushTest() { var brush1 = d3.svg.brush() .x(xScale) .on('brush', function () { - var extent = brush1.extent(); + var extent = <[number, number]> brush1.extent(); xMin = Math.max(extent[0], 0); xMax = Math.min(extent[1], 1); brush1.extent([xMin, xMax]); @@ -2373,186 +2405,155 @@ function brushTest() { // Tests for area // Adopted from: https://github.com/mbostock/d3/blob/master/test/svg/area-test.js function svgAreaTest () { - var a = d3.svg.area(); + var a = d3.svg.area(), + f: () => number, + n: number; - a.x()([0, 1]); - a.x()([0, 1], 1); + a.x(f).x() === f; + a.x(n).x() === n; a.x(0); - a.x(function (d) { return d.x * 10; }); + a.x(function (d) { return d[0] * 10; }); a.x(function (d, i) { return i * 10; }); - a.x0()([0, 1]); - a.x0()([0, 1], 1); + a.x(f).x0() === f; + a.x(n).x0() === n; a.x0(0); - a.x0(function (d) { return d.x * 10; }); + a.x0(function (d) { return d[0] * 10; }); a.x0(function (d, i) { return i * 10; }); - a.x1()([0, 1]); - a.x1()([0, 1], 1); + a.x(f).x1() === f; + a.x(n).x1() === n; a.x1(0); - a.x1(function (d) { return d.x * 10; }); + a.x1(function (d) { return d[0] * 10; }); a.x1(function (d, i) { return i * 10; }); - a.y()([0, 1]); - a.y()([0, 1], 1); + a.y(f).y() === f; + a.y(n).y() === n; a.y(0); - a.y(function (d) { return d.x * 10; }); + a.y(function (d) { return d[0] * 10; }); a.y(function (d, i) { return i * 10; }); - a.y0()([0, 1]); - a.y0()([0, 1], 1); + a.y(f).y0() === f; + a.y(n).y0() === n; a.y0(0); - a.y0(function (d) { return d.x * 10; }); + a.y0(function (d) { return d[0] * 10; }); a.y0(function (d, i) { return i * 10; }); - a.y1()([0, 1]); - a.y1()([0, 1], 1); + a.y(f).y1() === f; + a.y(n).y1() === n; a.y1(0); - a.y1(function (d) { return d.x * 10; }); + a.y1(function (d) { return d[0] * 10; }); a.y1(function (d, i) { return i * 10; }); } // Tests for areaRadial // Adopted from: https://github.com/mbostock/d3/blob/master/test/svg/area-radial-test.js function svgAreaRadialTest () { - var a = d3.svg.area.radial(); + var a = d3.svg.area.radial(), + f: () => number, + n: number; - a.x()([0, 1]); - a.x()([0, 1], 1); - a.x(0); - a.x(function (d) { return d.x * 10; }); - a.x(function (d, i) { return i * 10; }); - - a.x0()([0, 1]); - a.x0()([0, 1], 1); - a.x0(0); - a.x0(function (d) { return d.x * 10; }); - a.x0(function (d, i) { return i * 10; }); - - a.x1()([0, 1]); - a.x1()([0, 1], 1); - a.x1(0); - a.x1(function (d) { return d.x * 10; }); - a.x1(function (d, i) { return i * 10; }); - - a.y()([0, 1]); - a.y()([0, 1], 1); - a.y(0); - a.y(function (d) { return d.x * 10; }); - a.y(function (d, i) { return i * 10; }); - - a.y0()([0, 1]); - a.y0()([0, 1], 1); - a.y0(0); - a.y0(function (d) { return d.x * 10; }); - a.y0(function (d, i) { return i * 10; }); - - a.y1()([0, 1]); - a.y1()([0, 1], 1); - a.y1(0); - a.y1(function (d) { return d.x * 10; }); - a.y1(function (d, i) { return i * 10; }); - - a.radius(function () { return 10; }); - a.radius(function (d) { return d.x * 10; }); + a.radius(f).radius() === f; + a.radius(n).radius() === n; + a.radius(0); + a.radius(function (d) { return d[0] * 10; }); a.radius(function (d, i) { return i * 10; }); - a.innerRadius(function () { return 10; }); - a.innerRadius(function (d) { return d.x * 10; }); + a.radius(f).innerRadius() === f; + a.radius(n).innerRadius() === n; + a.innerRadius(0); + a.innerRadius(function (d) { return d[0] * 10; }); a.innerRadius(function (d, i) { return i * 10; }); - a.outerRadius(function () { return 10; }); - a.outerRadius(function (d) { return d.x * 10; }); + a.radius(f).outerRadius() === f; + a.radius(n).outerRadius() === n; + a.outerRadius(0); + a.outerRadius(function (d) { return d[1] * 10; }); a.outerRadius(function (d, i) { return i * 10; }); - a.angle(function () { return 10; }); - a.angle(function (d) { return d.x * 10; }); + a.angle(f).angle() === f; + a.angle(n).angle() === n; + a.angle(0); + a.angle(function (d) { return d[0] * 10; }); a.angle(function (d, i) { return i * 10; }); - a.startAngle(function () { return 10; }); - a.startAngle(function (d) { return d.x * 10; }); + a.angle(f).startAngle() === f; + a.angle(n).startAngle() === n; + a.startAngle(0); + a.startAngle(function (d) { return d[0] * 10; }); a.startAngle(function (d, i) { return i * 10; }); - a.endAngle(function () { return 10; }); - a.endAngle(function (d) { return d.x * 10; }); + a.angle(f).endAngle() === f; + a.angle(n).endAngle() === n; + a.endAngle(0); + a.endAngle(function (d) { return d[1] * 10; }); a.endAngle(function (d, i) { return i * 10; }); } // Tests for d3.svg.line // Adopted from: https://github.com/mbostock/d3/blob/master/test/svg/line-test.js function svgLineTest () { - var l = d3.svg.line(); + var l = d3.svg.line(), + f: () => number, + n: number; - l.x()([0, 1]); - l.x()([0, 1], 0); + l.x(f).x() === f; + l.x(n).x() === n; l.x(0); - l.x(function (d) { return d.x; }); + l.x(function (d) { return d[0]; }); l.x(function (d, i) { return i; }); - l.y()([0, 1]); - l.y()([0, 1], 0); + l.y(f).y() === f; + l.y(n).y() === n; l.y(0); - l.y(function (d) { return d.y; }); + l.y(function (d) { return d[1]; }); l.y(function (d, i) { return i; }); } // Tests for d3.svg.line.radial // Adopted from: https://github.com/mbostock/d3/blob/master/test/svg/line-radial-test.js function svgLineRadialTest () { - var l = d3.svg.line.radial(); + var l = d3.svg.line.radial(), + f: () => number, + n: number; - l.x()([0, 1]); - l.x()([0, 1], 0); - l.x(0); - l.x(function (d) { return d.x; }); - l.x(function (d, i) { return i; }); - - l.y()([0, 1]); - l.y()([0, 1], 0); - l.y(0); - l.y(function (d) { return d.y; }); - l.y(function (d, i) { return i; }); - - l.radius()([0, 1]); - l.radius()([0, 1], 0); + l.radius(f).radius() === f; + l.radius(n).radius() === n; l.radius(0); - l.radius(function (d) { return d.x; }); + l.radius(function (d) { return d[0]; }); l.radius(function (d, i) { return i; }); - l.angle()([0, 1]); - l.angle()([0, 1], 0); + l.angle(f).angle() === f; + l.angle(n).angle() === n; l.angle(0); - l.angle(function (d) { return d.y; }); + l.angle(function (d) { return d[1]; }); l.angle(function (d, i) { return i; }); } // Tests for d3.svg.arc // Adopted from: https://github.com/mbostock/d3/blob/master/test/svg/arc-test.js function svgArcTest () { - var l = d3.svg.arc(); + var l = d3.svg.arc(), + f: () => number; - l.innerRadius()([0, 1]); - l.innerRadius()([0, 1], 0); + l.innerRadius(f).innerRadius() === f; l.innerRadius(0); - l.innerRadius(function (d) { return d.x; }); + l.innerRadius(function (d) { return d[0]; }); l.innerRadius(function (d, i) { return i; }); - l.outerRadius()([0, 1]); - l.outerRadius()([0, 1], 0); + l.outerRadius(f).outerRadius() === f; l.outerRadius(0); - l.outerRadius(function (d) { return d.x; }); + l.outerRadius(function (d) { return d[1]; }); l.outerRadius(function (d, i) { return i; }); - l.startAngle()([0, 1]); - l.startAngle()([0, 1], 0); + l.startAngle(f).startAngle() === f; l.startAngle(0); - l.startAngle(function (d) { return d.x; }); + l.startAngle(function (d) { return d[0]; }); l.startAngle(function (d, i) { return i; }); - l.endAngle()([0, 1]); - l.endAngle()([0, 1], 0); + l.endAngle(f).endAngle() === f; l.endAngle(0); - l.endAngle(function (d) { return d.x; }); + l.endAngle(function (d) { return d[1]; }); l.endAngle(function (d, i) { return i; }); } @@ -2561,28 +2562,28 @@ function svgArcTest () { function svgDiagonalTest () { var d = d3.svg.diagonal(); - d.projection()({ x: 0, y: 1}); d.projection()({ x: 0, y: 1}, 0); d.projection(function (d) { return [d.x, d.y]; }); d.projection(function (d, i) { return [i, i + 1]; }); - d.source()({x: 0, y: 1}); - d.source()({x: 0, y: 1}, 0); + d.source()({ source: {x: 0, y: 1}, target: null }, 0); d.source({x: 0, y: 1}); - d.source(function (d) { return {x: d.x, y: d.y}; }); - d.source(function (d, i) { return {x: d.x * i, y: d.y * i}; }); + d.source(function (d) { return {x: d.source.x, y: d.source.y}; }); + d.source(function (d, i) { return {x: d.source.x * i, y: d.source.y * i}; }); - d.target()({x: 0, y: 1}); - d.target()({x: 0, y: 1}, 0); + d.target()({ target: {x: 0, y: 1}, source: null }, 0); d.target({x: 0, y: 1}); - d.target(function (d) { return {x: d.x, y: d.y}; }); - d.target(function (d, i) { return {x: d.x * i, y: d.y * i}; }); + d.target(function (d) { return {x: d.target.x, y: d.target.y}; }); + d.target(function (d, i) { return {x: d.target.x * i, y: d.target.y * i}; }); } // Tests for d3.extent // Adopted from: https://github.com/mbostock/d3/blob/master/test/arrays/extent-test.js function extentTest() { + // usages of `o' suppressed as well as mixed-type comparisons + // see https://github.com/Microsoft/TypeScript/commit/c0db7ffe8f55b6ec335880482ca43b93b066689d var o = { valueOf: function () { return NaN; } }; + d3.extent([1]); d3.extent([5, 1, 2, 3, 4]); d3.extent([20, 3]); @@ -2591,15 +2592,15 @@ function extentTest() { d3.extent(["20", "3"]); d3.extent(["3", "20"]); d3.extent([NaN, 1, 2, 3, 4, 5]); - d3.extent([o, 1, 2, 3, 4, 5]); + // d3.extent([o, 1, 2, 3, 4, 5]); d3.extent([1, 2, 3, 4, 5, NaN]); - d3.extent([1, 2, 3, 4, 5, o]); + // d3.extent([1, 2, 3, 4, 5, o]); d3.extent([10, null, 3, undefined, 5, NaN]); d3.extent([-1, null, -3, undefined, -5, NaN]); - d3.extent([20, "3"]); - d3.extent(["20", 3]); - d3.extent([3, "20"]); - d3.extent(["3", 20]); + // d3.extent([20, "3"]); + // d3.extent(["20", 3]); + // d3.extent([3, "20"]); + // d3.extent(["3", 20]); d3.extent([1], (d) => { return d; }); d3.extent([5, 1, 2, 3, 4], (d) => { return d; }); @@ -2609,28 +2610,28 @@ function extentTest() { d3.extent(["20", "3"], (d) => { return d; }); d3.extent(["3", "20"], (d) => { return d; }); d3.extent([NaN, 1, 2, 3, 4, 5], (d) => { return d; }); - d3.extent([o, 1, 2, 3, 4, 5], (d) => { return d; }); + // d3.extent([o, 1, 2, 3, 4, 5], (d) => { return d; }); d3.extent([1, 2, 3, 4, 5, NaN], (d) => { return d; }); - d3.extent([1, 2, 3, 4, 5, o], (d) => { return d; }); + // d3.extent([1, 2, 3, 4, 5, o], (d) => { return d; }); d3.extent([10, null, 3, undefined, 5, NaN], (d) => { return d; }); d3.extent([-1, null, -3, undefined, -5, NaN], (d) => { return d; }); - d3.extent([20, "3"], (d) => { return d; }); - d3.extent(["20", 3], (d) => { return d; }); - d3.extent([3, "20"], (d) => { return d; }); - d3.extent(["3", 20], (d) => { return d; }); + // d3.extent([20, "3"], (d) => { return d; }); + // d3.extent(["20", 3], (d) => { return d; }); + // d3.extent([3, "20"], (d) => { return d; }); + // d3.extent(["3", 20], (d) => { return d; }); } // Tests for d3.time.format.multi // Adopted from http://bl.ocks.org/mbostock/4149176 function multiTest() { var customTimeFormat = d3.time.format.multi([ - [".%L", function(d) { return d.getMilliseconds(); }], - [":%S", function(d) { return d.getSeconds(); }], - ["%I:%M", function(d) { return d.getMinutes(); }], - ["%I %p", function(d) { return d.getHours(); }], - ["%a %d", function(d) { return d.getDay() && d.getDate() != 1; }], + [".%L", function(d) { return !!d.getMilliseconds(); }], + [":%S", function(d) { return !!d.getSeconds(); }], + ["%I:%M", function(d) { return !!d.getMinutes(); }], + ["%I %p", function(d) { return !!d.getHours(); }], + ["%a %d", function(d) { return !!d.getDay() && d.getDate() != 1; }], ["%b %d", function(d) { return d.getDate() != 1; }], - ["%B", function(d) { return d.getMonth(); }], + ["%B", function(d) { return !!d.getMonth(); }], ["%Y", function() { return true; }] ]); @@ -2656,4 +2657,4 @@ function multiTest() { .attr("class", "x axis") .attr("transform", "translate(0," + height + ")") .call(xAxis); -} \ No newline at end of file +} diff --git a/d3/d3.d.ts b/d3/d3.d.ts index 57e817818..dddef751b 100644 --- a/d3/d3.d.ts +++ b/d3/d3.d.ts @@ -1,3451 +1,3278 @@ -// Type definitions for d3JS -// Project: http://d3js.org/ -// Definitions by: Boris Yankov -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -declare module D3 { - export interface Selectors { - /** - * Select an element from the current document - */ - select: { - /** - * Returns the empty selection - */ - (): Selection; - /** - * Selects the first element that matches the specified selector string - * - * @param selector Selection String to match - */ - (selector: string): Selection; - /** - * Selects the specified node - * - * @param element Node element to select - */ - (element: EventTarget): Selection; - }; - - /** - * Select multiple elements from the current document - */ - selectAll: { - /** - * Selects all elements that match the specified selector - * - * @param selector Selection String to match - */ - (selector: string): Selection; - /** - * Selects the specified array of elements - * - * @param elements Array of node elements to select - */ - (elements: EventTarget[]): Selection; - }; - } - - export interface D3Event extends Event{ - dx: number; - dy: number; - clientX: number; - clientY: number; - translate: number[]; - scale: number; - sourceEvent: D3Event; - x: number; - y: number; - keyCode: number; - altKey: any; - type: string; - } - - export interface Base extends Selectors { - /** - * Create a behavior - */ - behavior: Behavior.Behavior; - /** - * Access the current user event for interaction - */ - event: D3Event; - - /** - * Compare two values for sorting. - * Returns -1 if a is less than b, or 1 if a is greater than b, or 0 - * - * @param a First value - * @param b Second value - */ - ascending(a: T, b: T): number; - /** - * Compare two values for sorting. - * Returns -1 if a is greater than b, or 1 if a is less than b, or 0 - * - * @param a First value - * @param b Second value - */ - descending(a: T, b: T): number; - /** - * Find the minimum value in an array - * - * @param arr Array to search - * @param map Accsessor function - */ - min(arr: T[], map: (v?: T, i?: number) => U): U; - /** - * Find the minimum value in an array - * - * @param arr Array to search - */ - min(arr: T[]): T; - /** - * Find the maximum value in an array - * - * @param arr Array to search - * @param map Accsessor function - */ - max(arr: T[], map: (v?: T, i?: number) => U): U; - /** - * Find the maximum value in an array - * - * @param arr Array to search - */ - max(arr: T[]): T; - /** - * Find the minimum and maximum value in an array - * - * @param arr Array to search - * @param map Accsessor function - */ - extent(arr: T[], map: (v: T) => U): U[]; - /** - * Find the minimum and maximum value in an array - * - * @param arr Array to search - */ - extent(arr: T[]): T[]; - /** - * Compute the sum of an array of numbers - * - * @param arr Array to search - * @param map Accsessor function - */ - sum(arr: T[], map: (v: T) => number): number; - /** - * Compute the sum of an array of numbers - * - * @param arr Array to search - */ - sum(arr: number[]): number; - /** - * Compute the arithmetic mean of an array of numbers - * - * @param arr Array to search - * @param map Accsessor function - */ - mean(arr: T[], map: (v: T) => number): number; - /** - * Compute the arithmetic mean of an array of numbers - * - * @param arr Array to search - */ - mean(arr: number[]): number; - /** - * Compute the median of an array of numbers (the 0.5-quantile). - * - * @param arr Array to search - * @param map Accsessor function - */ - median(arr: T[], map: (v: T) => number): number; - /** - * Compute the median of an array of numbers (the 0.5-quantile). - * - * @param arr Array to search - */ - median(arr: number[]): number; - /** - * Compute a quantile for a sorted array of numbers. - * - * @param arr Array to search - * @param p The quantile to return - */ - quantile: (arr: number[], p: number) => number; - /** - * Locate the insertion point for x in array to maintain sorted order - * - * @param arr Array to search - * @param x Value to search for insertion point - * @param low Minimum value of array subset - * @param hihg Maximum value of array subset - */ - bisect(arr: T[], x: T, low?: number, high?: number): number; - /** - * Locate the insertion point for x in array to maintain sorted order - * - * @param arr Array to search - * @param x Value to serch for insertion point - * @param low Minimum value of array subset - * @param high Maximum value of array subset - */ - bisectLeft(arr: T[], x: T, low?: number, high?: number): number; - /** - * Locate the insertion point for x in array to maintain sorted order - * - * @param arr Array to search - * @param x Value to serch for insertion point - * @param low Minimum value of array subset - * @param high Maximum value of array subset - */ - bisectRight(arr: T[], x: T, low?: number, high?: number): number; - /** - * Bisect using an accessor. - * - * @param accessor Accessor function - */ - bisector(accessor: (data: any, index: number) => any): any; - /** - * Randomize the order of an array. - * - * @param arr Array to randomize - */ - shuffle(arr: T[]): T[]; - /** - * Reorder an array of elements according to an array of indexes - * - * @param arr Array to reorder - * @param indexes Array containing the order the elements should be returned in - */ - permute(arr: any[], indexes: any[]): any[]; - /** - * Transpose a variable number of arrays. - * - * @param arrs Arrays to transpose - */ - zip(...arrs: any[]): any[]; - /** - * Parse the given 2D affine transform string, as defined by SVG's transform attribute. - * - * @param definition 2D affine transform string - */ - transform(definition: string): any; - /** - * Transpose an array of arrays. - * - * @param matrix Two dimensional array to transpose - */ - transpose(matrix: any[]): any[]; - /** - * Creates an array containing tuples of adjacent pairs - * - * @param arr An array containing entries to pair - * @returns any[][] An array of 2-element tuples for each pair - */ - pairs(arr: any[]): any[][]; - /** - * List the keys of an associative array. - * - * @param map Array of objects to get the key values from - */ - keys(map: any): string[]; - /** - * List the values of an associative array. - * - * @param map Array of objects to get the values from - */ - values(map: any): any[]; - /** - * List the key-value entries of an associative array. - * - * @param map Array of objects to get the key-value pairs from - */ - entries(map: any): any[]; - /** - * merge multiple arrays into one array - * - * @param map Arrays to merge - */ - merge(...map: any[]): any[]; - /** - * Generate a range of numeric values. - */ - range: { - /** - * Generate a range of numeric values from 0. - * - * @param stop Value to generate the range to - * @param step Step between each value - */ - (stop: number, step?: number): number[]; - /** - * Generate a range of numeric values. - * - * @param start Value to start - * @param stop Value to generate the range to - * @param step Step between each value - */ - (start: number, stop?: number, step?: number): number[]; - }; - /** - * Create new nest operator - */ - nest(): Nest; - /** - * Request a resource using XMLHttpRequest. - */ - xhr: { - /** - * Creates an asynchronous request for specified url - * - * @param url Url to request - * @param callback Function to invoke when resource is loaded or the request fails - */ - (url: string, callback?: (xhr: XMLHttpRequest) => void ): Xhr; - /** - * Creates an asynchronous request for specified url - * - * @param url Url to request - * @param mime MIME type to request - * @param callback Function to invoke when resource is loaded or the request fails - */ - (url: string, mime: string, callback?: (xhr: XMLHttpRequest) => void ): Xhr; - }; - /** - * Request a text file - */ - text: { - /** - * Request a text file - * - * @param url Url to request - * @param callback Function to invoke when resource is loaded or the request fails - */ - (url: string, callback?: (response: string) => void ): Xhr; - /** - * Request a text file - * - * @param url Url to request - * @param mime MIME type to request - * @param callback Function to invoke when resource is loaded or the request fails - */ - (url: string, mime: string, callback?: (response: string) => void ): Xhr; - }; - /** - * Request a JSON blob - * - * @param url Url to request - * @param callback Function to invoke when resource is loaded or the request fails - */ - json: (url: string, callback?: (error: any, data: any) => void ) => Xhr; - /** - * Request an HTML document fragment. - */ - xml: { - /** - * Request an HTML document fragment. - * - * @param url Url to request - * @param callback Function to invoke when resource is loaded or the request fails - */ - (url: string, callback?: (response: Document) => void ): Xhr; - /** - * Request an HTML document fragment. - * - * @param url Url to request - * @param mime MIME type to request - * @param callback Function to invoke when resource is loaded or the request fails - */ - (url: string, mime: string, callback?: (response: Document) => void ): Xhr; - }; - /** - * Request an XML document fragment. - * - * @param url Url to request - * @param callback Function to invoke when resource is loaded or the request fails - */ - html: (url: string, callback?: (response: DocumentFragment) => void ) => Xhr; - /** - * Request a comma-separated values (CSV) file. - */ - csv: Dsv; - /** - * Request a tab-separated values (TSV) file - */ - tsv: Dsv; - /** - * Time Functions - */ - time: Time.Time; - /** - * Scales - */ - scale: Scale.ScaleBase; - /* - * Interpolate two values - */ - interpolate: Transition.BaseInterpolate; - /* - * Interpolate two numbers - */ - interpolateNumber: Transition.BaseInterpolate; - /* - * Interpolate two integers - */ - interpolateRound: Transition.BaseInterpolate; - /* - * Interpolate two strings - */ - interpolateString: Transition.BaseInterpolate; - /* - * Interpolate two RGB colors - */ - interpolateRgb: Transition.BaseInterpolate; - /* - * Interpolate two HSL colors - */ - interpolateHsl: Transition.BaseInterpolate; - /* - * Interpolate two HCL colors - */ - interpolateHcl: Transition.BaseInterpolate; - /* - * Interpolate two L*a*b* colors - */ - interpolateLab: Transition.BaseInterpolate; - /* - * Interpolate two arrays of values - */ - interpolateArray: Transition.BaseInterpolate; - /* - * Interpolate two arbitary objects - */ - interpolateObject: Transition.BaseInterpolate; - /* - * Interpolate two 2D matrix transforms - */ - interpolateTransform: Transition.BaseInterpolate; - /* - * The array of built-in interpolator factories - */ - interpolators: Transition.InterpolateFactory[]; - /** - * Layouts - */ - layout: Layout.Layout; - /** - * Svg's - */ - svg: Svg.Svg; - /** - * Random number generators - */ - random: Random; - /** - * Create a function to format a number as a string - * - * @param specifier The format specifier to use - */ - format(specifier: string): (value: number) => string; - /** - * Returns the SI prefix for the specified value at the specified precision - */ - formatPrefix(value: number, precision?: number): MetricPrefix; - /** - * The version of the d3 library - */ - version: string; - /** - * Returns the root selection - */ - selection(): Selection; - ns: { - /** - * The map of registered namespace prefixes - */ - prefix: { - svg: string; - xhtml: string; - xlink: string; - xml: string; - xmlns: string; - }; - /** - * Qualifies the specified name - */ - qualify(name: string): { space: string; local: string; }; - }; - /** - * Returns a built-in easing function of the specified type - */ - ease: (type: string, ...arrs: any[]) => D3.Transition.Transition; - /** - * Constructs a new RGB color. - */ - rgb: { - /** - * Constructs a new RGB color with the specified r, g and b channel values - */ - (r: number, g: number, b: number): D3.Color.RGBColor; - /** - * Constructs a new RGB color by parsing the specified color string - */ - (color: string): D3.Color.RGBColor; - }; - /** - * Constructs a new HCL color. - */ - hcl: { - /** - * Constructs a new HCL color. - */ - (h: number, c: number, l: number): Color.HCLColor; - /** - * Constructs a new HCL color by parsing the specified color string - */ - (color: string): Color.HCLColor; - }; - /** - * Constructs a new HSL color. - */ - hsl: { - /** - * Constructs a new HSL color with the specified hue h, saturation s and lightness l - */ - (h: number, s: number, l: number): Color.HSLColor; - /** - * Constructs a new HSL color by parsing the specified color string - */ - (color: string): Color.HSLColor; - }; - /** - * Constructs a new RGB color. - */ - lab: { - /** - * Constructs a new LAB color. - */ - (l: number, a: number, b: number): Color.LABColor; - /** - * Constructs a new LAB color by parsing the specified color string - */ - (color: string): Color.LABColor; - }; - geo: Geo.Geo; - geom: Geom.Geom; - /** - * gets the mouse position relative to a specified container. - */ - mouse(container: any): number[]; - /** - * gets the touch positions relative to a specified container. - */ - touches(container: any): number[][]; - - /** - * If the specified value is a function, returns the specified value. - * Otherwise, returns a function that returns the specified value. - */ - functor(value: (p : R) => T): (p : R) => T; - functor(value: T): (p : any) => T; - - map: { - (): Map; - (object: {[key: string]: T; }): Map; - (map: Map): Map; - (array: T[]): Map; - (array: T[], keyFn: (object: T, index?: number) => string): Map; - }; - set: { - (): Set; - (array: T[]): Set; - }; - dispatch(...types: string[]): Dispatch; - rebind(target: any, source: any, ...names: any[]): any; - requote(str: string): string; - timer: { - (funct: () => boolean, delay?: number, mark?: number): void; - flush(): void; - } - transition(): Transition.Transition; - - round(x: number, n: number): number; - } - - export interface Dispatch { - [event: string]: any; - on: { - (type: string): any; - (type: string, listener: any): any; - } - } - - export interface MetricPrefix { - /** - * the scale function, for converting numbers to the appropriate prefixed scale. - */ - scale: (d: number) => number; - /** - * the prefix symbol - */ - symbol: string; - } - - export interface Xhr { - /** - * Get or set request header - */ - header: { - /** - * Get the value of specified request header - * - * @param name Name of header to get the value for - */ - (name: string): string; - /** - * Set the value of specified request header - * - * @param name Name of header to set the value for - * @param value Value to set the header to - */ - (name: string, value: string): Xhr; - }; - /** - * Get or set MIME Type - */ - mimeType: { - /** - * Get the current MIME Type - */ - (): string; - /** - * Set the MIME Type for the request - * - * @param type The MIME type for the request - */ - (type: string): Xhr; - }; - /* - * Get or Set the function used to map the response to the associated data value - */ - response: { - /** - * Get function used to map the response to the associated data value - */ - (): (xhr: XMLHttpRequest) => any; - /** - * Set function used to map the response to the associated data value - * - * @param value The function used to map the response to a data value - */ - (value: (xhr: XMLHttpRequest) => any): Xhr; - }; - /** - * Issue the request using the GET method - * - * @param callback Function to invoke on completion of request - */ - get(callback?: (xhr: XMLHttpRequest) => void ): Xhr; - /** - * Issue the request using the POST method - */ - post: { - /** - * Issue the request using the POST method - * - * @param callback Function to invoke on completion of request - */ - (callback?: (xhr: XMLHttpRequest) => void ): Xhr; - /** - * Issue the request using the POST method - * - * @param data Data to post back in the request - * @param callback Function to invoke on completion of request - */ - (data: any, callback?: (xhr: XMLHttpRequest) => void ): Xhr; - }; - /** - * Issues this request using the specified method - */ - send: { - /** - * Issues this request using the specified method - * - * @param method Method to use to make the request - * @param callback Function to invoke on completion of request - */ - (method: string, callback?: (xhr: XMLHttpRequest) => void ): Xhr; - /** - * Issues this request using the specified method - * - * @param method Method to use to make the request - * @param data Data to post back in the request - * @param callback Function to invoke on completion of request - */ - (method: string, data: any, callback?: (xhr: XMLHttpRequest) => void ): Xhr; - }; - /** - * Aborts this request, if it is currently in-flight - */ - abort(): Xhr; - /** - * Registers a listener to receive events - * - * @param type Enent name to attach the listener to - * @param listener Function to attach to event - */ - on: (type: string, listener: (data: any, index?: number) => any) => Xhr; - } - - export interface Dsv { - /** - * Request a delimited values file - * - * @param url Url to request - * @param callback Function to invoke when resource is loaded or the request fails - */ - (url: string, callback?: (error: any, response: any[]) => void ): Xhr; - /** - * Parse a delimited string into objects using the header row. - * - * @param string delimited formatted string to parse - * @param accessor to modify properties of each row - */ - parse(string: string, accessor?: (row: any, index?: number) => any): any[]; - /** - * Parse a delimited string into tuples, ignoring the header row. - * - * @param string delimited formatted string to parse - */ - parseRows(string: string, accessor: (row: any[], index: number) => any): any; - /** - * Format an array of tuples into a delimited string. - * - * @param rows Array to convert to a delimited string - */ - format(rows: any[]): string; - } - - export interface Selection extends Selectors, Array { - attr: { - (name: string): string; - (name: string, value: any): Selection; - (name: string, valueFunction: (data: any, index: number) => any): Selection; - (attrValueMap : Object): Selection; - }; - - classed: { - (name: string): boolean; - (name: string, value: any): Selection; - (name: string, valueFunction: (data: any, index: number) => any): Selection; - (classValueMap: Object): Selection; - }; - - style: { - (name: string): string; - (name: string, value: any, priority?: string): Selection; - (name: string, valueFunction: (data: any, index: number) => any, priority?: string): Selection; - (styleValueMap : Object): Selection; - }; - - property: { - (name: string): void; - (name: string, value: any): Selection; - (name: string, valueFunction: (data: any, index: number) => any): Selection; - (propertyValueMap : Object): Selection; - }; - - text: { - (): string; - (value: any): Selection; - (valueFunction: (data: any, index: number) => any): Selection; - }; - - html: { - (): string; - (value: any): Selection; - (valueFunction: (data: any, index: number) => any): Selection; - }; - - append: (name: string) => Selection; - insert: (name: string, before: string) => Selection; - remove: () => Selection; - empty: () => boolean; - - data: { - (values: (data: any, index?: number) => any[], key?: (data: any, index?: number) => any): UpdateSelection; - (values: any[], key?: (data: any, index?: number) => any): UpdateSelection; - (): any[]; - }; - - datum: { - /** - * Sets the element's bound data to the return value of the specified function evaluated - * for each selected element. - * Unlike the D3.Selection.data method, this method does not compute a join (and thus - * does not compute enter and exit selections). - * @param values The function to be evaluated for each selected element, being passed the - * previous datum d and the current index i, with the this context as the current DOM - * element. The function is then used to set each element's data. A null value will - * delete the bound data. This operator has no effect on the index. - */ - (values: (data: any, index: number) => any): UpdateSelection; - /** - * Sets the element's bound data to the specified value on all selected elements. - * Unlike the D3.Selection.data method, this method does not compute a join (and thus - * does not compute enter and exit selections). - * @param values The same data to be given to all elements. - */ - (values: any): UpdateSelection; - /** - * Returns the bound datum for the first non-null element in the selection. - * This is generally useful only if you know the selection contains exactly one element. - */ - (): any; - /** - * Returns the bound datum for the first non-null element in the selection. - * This is generally useful only if you know the selection contains exactly one element. - */ - (): T; - }; - - filter: { - (filter: (data: any, index: number) => boolean, thisArg?: any): UpdateSelection; - (filter: string): UpdateSelection; - }; - - call(callback: (selection: Selection, ...args: any[]) => void, ...args: any[]): Selection; - each(eachFunction: (data: any, index: number) => any): Selection; - on: { - (type: string): (data: any, index: number) => any; - (type: string, listener: (data: any, index: number) => any, capture?: boolean): Selection; - }; - - /** - * Returns the total number of elements in the current selection. - */ - size(): number; - - /** - * Starts a transition for the current selection. Transitions behave much like selections, - * except operators animate smoothly over time rather than applying instantaneously. - */ - transition(): Transition.Transition; - - /** - * Sorts the elements in the current selection according to the specified comparator - * function. - * - * @param comparator a comparison function, which will be passed two data elements a and b - * to compare, and should return either a negative, positive, or zero value to indicate - * their relative order. - */ - sort(comparator?: (a: T, b: T) => number): Selection; - - /** - * Re-inserts elements into the document such that the document order matches the selection - * order. This is equivalent to calling sort() if the data is already sorted, but much - * faster. - */ - order: () => Selection; - - /** - * Returns the first non-null element in the current selection. If the selection is empty, - * returns null. - */ - node: () => T; - } - - export interface EnterSelection { - append: (name: string) => Selection; - insert: (name: string, before?: string) => Selection; - select: (selector: string) => Selection; - empty: () => boolean; - node: () => Element; - call: (callback: (selection: EnterSelection) => void) => EnterSelection; - size: () => number; - } - - export interface UpdateSelection extends Selection { - enter: () => EnterSelection; - update: () => Selection; - exit: () => Selection; - } - - export interface NestKeyValue { - key: string; - values: any; - } - - export interface Nest { - key(keyFunction: (data: any, index: number) => string): Nest; - sortKeys(comparator: (d1: any, d2: any) => number): Nest; - sortValues(comparator: (d1: any, d2: any) => number): Nest; - rollup(rollupFunction: (data: any, index: number) => any): Nest; - map(values: any[], mapType?: any): any; - entries(values: any[]): NestKeyValue[]; - } - - export interface MapKeyValue { - key: string; - value: T; - } - - export interface Map { - has(key: string): boolean; - get(key: string): T; - set(key: string, value: T): T; - remove(key: string): boolean; - keys(): string[]; - values(): T[]; - entries(): MapKeyValue[]; - forEach(func: (key: string, value: T) => void ): void; - empty(): boolean; - size(): number; - } - - export interface Set { - has(value: T): boolean; - add(value: T): T; - remove(value: T): boolean; - values(): string[]; - forEach(func: (value: string) => void ): void; - empty(): boolean; - size(): number; - } - - export interface Random { - /** - * Returns a function for generating random numbers with a normal distribution - * - * @param mean The expected value of the generated pseudorandom numbers - * @param deviation The given standard deviation - */ - normal(mean?: number, deviation?: number): () => number; - /** - * Returns a function for generating random numbers with a log-normal distribution - * - * @param mean The expected value of the generated pseudorandom numbers - * @param deviation The given standard deviation - */ - logNormal(mean?: number, deviation?: number): () => number; - /** - * Returns a function for generating random numbers with an Irwin-Hall distribution - * - * @param count The number of independent variables - */ - irwinHall(count: number): () => number; - } - - // Transitions - export module Transition { - export interface Transition { - duration: { - (duration: number): Transition; - (duration: (data: any, index: number) => any): Transition; - }; - delay: { - (delay: number): Transition; - (delay: (data: any, index: number) => any): Transition; - }; - attr: { - (name: string): string; - (name: string, value: any): Transition; - (name: string, valueFunction: (data: any, index: number) => any): Transition; - (attrValueMap : any): Transition; - }; - style: { - (name: string): string; - (name: string, value: any, priority?: string): Transition; - (name: string, valueFunction: (data: any, index: number) => any, priority?: string): Transition; - }; - call(callback: (transition: Transition, ...args: any[]) => void, ...args: any[]): Transition; - /** - * Select an element from the current document - */ - select: { - /** - * Selects the first element that matches the specified selector string - * - * @param selector Selection String to match - */ - (selector: string): Transition; - /** - * Selects the specified node - * - * @param element Node element to select - */ - (element: EventTarget): Transition; - }; - - /** - * Select multiple elements from the current document - */ - selectAll: { - /** - * Selects all elements that match the specified selector - * - * @param selector Selection String to match - */ - (selector: string): Transition; - /** - * Selects the specified array of elements - * - * @param elements Array of node elements to select - */ - (elements: EventTarget[]): Transition; - } - each: { - /** - * Immediately invokes the specified function for each element in the current - * transition, passing in the current datum and index, with the this context - * of the current DOM element. Similar to D3.Selection.each. - * - * @param eachFunction The function to be invoked for each element in the - * current transition, passing in the current datum and index, with the this - * context of the current DOM element. - */ - (eachFunction: (data: any, index: number) => any): Transition; - /** - * Adds a listener for transition events, supporting "start", "end" and - * "interrupt" events. The listener will be invoked for each individual - * element in the transition. - * - * @param type Type of transition event. Supported values are "start", "end" - * and "interrupt". - * @param listener The listener to be invoked for each individual element in - * the transition. - */ - (type: string, listener: (data: any, index: number) => any): Transition; - } - transition: () => Transition; - ease: (value: string, ...arrs: any[]) => Transition; - attrTween(name: string, tween: (d: any, i: number, a: any) => BaseInterpolate): Transition; - styleTween(name: string, tween: (d: any, i: number, a: any) => BaseInterpolate, priority?: string): Transition; - text: { - (text: string): Transition; - (text: (d: any, i: number) => string): Transition; - } - tween(name: string, factory: InterpolateFactory): Transition; - filter: { - (selector: string): Transition; - (selector: (data: any, index: number) => boolean): Transition; - }; - remove(): Transition; - } - - export interface InterpolateFactory { - (a?: any, b?: any): BaseInterpolate; - } - - export interface BaseInterpolate { - (a: any, b?: any): any; - } - - export interface Interpolate { - (t: any): any; - } - } - - //Time - export module Time { - export interface Time { - second: Interval; - minute: Interval; - hour: Interval; - day: Interval; - week: Interval; - sunday: Interval; - monday: Interval; - tuesday: Interval; - wednesday: Interval; - thursday: Interval; - friday: Interval; - saturday: Interval; - month: Interval; - year: Interval; - - seconds: Range; - minutes: Range; - hours: Range; - days: Range; - weeks: Range; - months: Range; - years: Range; - - sundays: Range; - mondays: Range; - tuesdays: Range; - wednesdays: Range; - thursdays: Range; - fridays: Range; - saturdays: Range; - format: { - /** - * Constructs a new local time formatter using the given specifier. - */ - (specifier: string): TimeFormat; - /** - * Returns a new multi-resolution time format given the specified array of predicated formats. - */ - multi: (formats: any[][]) => TimeFormat; - - utc: { - /** - * Constructs a new local time formatter using the given specifier. - */ - (specifier: string): TimeFormat; - /** - * Returns a new multi-resolution UTC time format given the specified array of predicated formats. - */ - multi: (formats: any[][]) => TimeFormat; - }; - - /** - * The full ISO 8601 UTC time format: "%Y-%m-%dT%H:%M:%S.%LZ". - */ - iso: TimeFormat; - }; - - scale: { - /** - * Constructs a new time scale with the default domain and range; - * the ticks and tick format are configured for local time. - */ - (): Scale.TimeScale; - /** - * Constructs a new time scale with the default domain and range; - * the ticks and tick format are configured for UTC time. - */ - utc(): Scale.TimeScale; - }; - } - - export interface Range { - (start: Date, end: Date, step?: number): Date[]; - } - - export interface Interval { - (date: Date): Date; - floor: (date: Date) => Date; - round: (date: Date) => Date; - ceil: (date: Date) => Date; - range: Range; - offset: (date: Date, step: number) => Date; - utc?: Interval; - } - - export interface TimeFormat { - (date: Date): string; - parse: (string: string) => Date; - } - } - - // Layout - export module Layout { - export interface Layout { - /** - * Creates a new Stack layout - */ - stack(): StackLayout; - /** - * Creates a new pie layout - */ - pie(): PieLayout; - /** - * Creates a new force layout - */ - force(): ForceLayout; - /** - * Creates a new tree layout - */ - tree(): TreeLayout; - bundle(): BundleLayout; - chord(): ChordLayout; - cluster(): ClusterLayout; - hierarchy(): HierarchyLayout; - histogram(): HistogramLayout; - pack(): PackLayout; - partition(): PartitionLayout; - treemap(): TreeMapLayout; - } - - export interface StackLayout { - (layers: T[], index?: number): T[]; - values(accessor?: (d: any) => any): StackLayout; - offset(offset: string): StackLayout; - x(accessor: (d: any, i: number) => any): StackLayout; - y(accessor: (d: any, i: number) => any): StackLayout; - out(setter: (d: any, y0: number, y: number) => void): StackLayout; - } - - export interface TreeLayout { - /** - * Gets or sets the sort order of sibling nodes for the layout using the specified comparator function - */ - sort: { - /** - * Gets the sort order function of sibling nodes for the layout - */ - (): (d1: any, d2: any) => number; - /** - * Sets the sort order of sibling nodes for the layout using the specified comparator function - */ - (comparator: (d1: any, d2: any) => number): TreeLayout; - }; - /** - * Gets or sets the specified children accessor function - */ - children: { - /** - * Gets the children accessor function - */ - (): (d: any) => any; - /** - * Sets the specified children accessor function - */ - (children: (d: any) => any): TreeLayout; - }; - /** - * Runs the tree layout - */ - nodes(root: GraphNode): GraphNode[]; - /** - * Given the specified array of nodes, such as those returned by nodes, returns an array of objects representing the links from parent to child for each node - */ - links(nodes: GraphNode[]): GraphLink[]; - /** - * If separation is specified, uses the specified function to compute separation between neighboring nodes. If separation is not specified, returns the current separation function - */ - separation: { - /** - * Gets the current separation function - */ - (): (a: GraphNode, b: GraphNode) => number; - /** - * Sets the specified function to compute separation between neighboring nodes - */ - (separation: (a: GraphNode, b: GraphNode) => number): TreeLayout; - }; - /** - * Gets or sets the available layout size - */ - size: { - /** - * Gets the available layout size - */ - (): number[]; - /** - * Sets the available layout size - */ - (size: number[]): TreeLayout; - }; - /** - * Gets or sets the available node size - */ - nodeSize: { - /** - * Gets the available node size - */ - (): number[]; - /** - * Sets the available node size - */ - (size: number[]): TreeLayout; - }; - } - - export interface PieLayout { - (values: any[], index?: number): ArcDescriptor[]; - value: { - (): (d: any, index: number) => number; - (accessor: (d: any, index: number) => number): PieLayout; - }; - sort: { - (): (d1: any, d2: any) => number; - (comparator: (d1: any, d2: any) => number): PieLayout; - }; - startAngle: { - (): number; - (angle: number): PieLayout; - (angle: () => number): PieLayout; - (angle: (d : any) => number): PieLayout; - (angle: (d : any, i: number) => number): PieLayout; - }; - endAngle: { - (): number; - (angle: number): PieLayout; - (angle: () => number): PieLayout; - (angle: (d : any) => number): PieLayout - (angle: (d : any, i: number) => number): PieLayout; - }; - } - - export interface ArcDescriptor { - value: any; - data: any; - startAngle: number; - endAngle: number; - index: number; - } - - export interface GraphNode { - id?: number; - index?: number; - name?: string; - px?: number; - py?: number; - size?: number; - weight?: number; - x?: number; - y?: number; - subindex?: number; - startAngle?: number; - endAngle?: number; - value?: number; - fixed?: boolean; - children?: GraphNode[]; - _children?: GraphNode[]; - parent?: GraphNode; - depth?: number; - } - - export interface GraphLink { - source: GraphNode; - target: GraphNode; - } - - export interface GraphNodeForce { - index?: number; - x?: number; - y?: number; - px?: number; - py?: number; - fixed?: boolean; - weight?: number; - } - - export interface GraphLinkForce { - source: GraphNodeForce; - target: GraphNodeForce; - } - - export interface ForceLayout { - (): ForceLayout; - size: { - (): number[]; - (mysize: number[]): ForceLayout; - }; - linkDistance: { - (): number; - (number:number): ForceLayout; - (accessor: (d: any, index: number) => number): ForceLayout; - }; - linkStrength: - { - (): number; - (number:number): ForceLayout; - (accessor: (d: any, index: number) => number): ForceLayout; - }; - friction: - { - (): number; - (number:number): ForceLayout; - (accessor: (d: any, index: number) => number): ForceLayout; - }; - alpha: { - (): number; - (number:number): ForceLayout; - (accessor: (d: any, index: number) => number): ForceLayout; - }; - charge: { - (): number; - (number:number): ForceLayout; - (accessor: (d: any, index: number) => number): ForceLayout; - }; - - theta: { - (): number; - (number:number): ForceLayout; - (accessor: (d: any, index: number) => number): ForceLayout; - }; - - gravity: { - (): number; - (number:number): ForceLayout; - (accessor: (d: any, index: number) => number): ForceLayout; - }; - - links: { - (): GraphLinkForce[]; - (arLinks: GraphLinkForce[]): ForceLayout; - - }; - nodes: - { - (): GraphNodeForce[]; - (arNodes: GraphNodeForce[]): ForceLayout; - - }; - start(): ForceLayout; - resume(): ForceLayout; - stop(): ForceLayout; - tick(): ForceLayout; - on(type: string, listener: () => void ): ForceLayout; - drag(): ForceLayout; - } - - export interface BundleLayout{ - (links: GraphLink[]): GraphNode[][]; - } - - export interface ChordLayout { - matrix: { - (): number[][]; - (matrix: number[][]): ChordLayout; - } - padding: { - (): number; - (padding: number): ChordLayout; - } - sortGroups: { - (): (a: number, b: number) => number; - (comparator: (a: number, b: number) => number): ChordLayout; - } - sortSubgroups: { - (): (a: number, b: number) => number; - (comparator: (a: number, b: number) => number): ChordLayout; - } - sortChords: { - (): (a: number, b: number) => number; - (comparator: (a: number, b: number) => number): ChordLayout; - } - chords(): GraphLink[]; - groups(): ArcDescriptor[]; - } - - export interface ClusterLayout{ - sort: { - (): (a: GraphNode, b: GraphNode) => number; - (comparator: (a: GraphNode, b: GraphNode) => number): ClusterLayout; - } - children: { - (): (d: any, i?: number) => GraphNode[]; - (children: (d: any, i?: number) => GraphNode[]): ClusterLayout; - } - nodes(root: GraphNode): GraphNode[]; - links(nodes: GraphNode[]): GraphLink[]; - separation: { - (): (a: GraphNode, b: GraphNode) => number; - (separation: (a: GraphNode, b: GraphNode) => number): ClusterLayout; - } - size: { - (): number[]; - (size: number[]): ClusterLayout; - } - value: { - (): (node: GraphNode) => number; - (value: (node: GraphNode) => number): ClusterLayout; - } - } - - export interface HierarchyLayout { - sort: { - (): (a: GraphNode, b: GraphNode) => number; - (comparator: (a: GraphNode, b: GraphNode) => number): HierarchyLayout; - } - children: { - (): (d: any, i?: number) => GraphNode[]; - (children: (d: any, i?: number) => GraphNode[]): HierarchyLayout; - } - nodes(root: GraphNode): GraphNode[]; - links(nodes: GraphNode[]): GraphLink[]; - value: { - (): (node: GraphNode) => number; - (value: (node: GraphNode) => number): HierarchyLayout; - } - reValue(root: GraphNode): HierarchyLayout; - } - - export interface Bin extends Array { - x: number; - dx: number; - y: number; - } - - export interface HistogramLayout { - (values: any[], index?: number): Bin[]; - value: { - (): (value: any) => any; - (accessor: (value: any) => any): HistogramLayout - } - range: { - (): (value: any, index: number) => number[]; - (range: (value: any, index: number) => number[]): HistogramLayout; - (range: number[]): HistogramLayout; - } - bins: { - (): (range: any[], index: number) => number[]; - (bins: (range: any[], index: number) => number[]): HistogramLayout; - (bins: number): HistogramLayout; - (bins: number[]): HistogramLayout; - } - frequency: { - (): boolean; - (frequency: boolean): HistogramLayout; - } - } - - export interface PackLayout { - sort: { - (): (a: GraphNode, b: GraphNode) => number; - (comparator: (a: GraphNode, b: GraphNode) => number): PackLayout; - } - children: { - (): (d: any, i?: number) => GraphNode[]; - (children: (d: any, i?: number) => GraphNode[]): PackLayout; - } - nodes(root: GraphNode): GraphNode[]; - links(nodes: GraphNode[]): GraphLink[]; - value: { - (): (node: GraphNode) => number; - (value: (node: GraphNode) => number): PackLayout; - } - size: { - (): number[]; - (size: number[]): PackLayout; - } - padding: { - (): number; - (padding: number): PackLayout; - } - } - - export interface PartitionLayout { - sort: { - (): (a: GraphNode, b: GraphNode) => number; - (comparator: (a: GraphNode, b: GraphNode) => number): PackLayout; - } - children: { - (): (d: any, i?: number) => GraphNode[]; - (children: (d: any, i?: number) => GraphNode[]): PackLayout; - } - nodes(root: GraphNode): GraphNode[]; - links(nodes: GraphNode[]): GraphLink[]; - value: { - (): (node: GraphNode) => number; - (value: (node: GraphNode) => number): PackLayout; - } - size: { - (): number[]; - (size: number[]): PackLayout; - } - } - - export interface TreeMapLayout { - sort: { - (): (a: GraphNode, b: GraphNode) => number; - (comparator: (a: GraphNode, b: GraphNode) => number): TreeMapLayout; - } - children: { - (): (d: any, i?: number) => GraphNode[]; - (children: (d: any, i?: number) => GraphNode[]): TreeMapLayout; - } - nodes(root: GraphNode): GraphNode[]; - links(nodes: GraphNode[]): GraphLink[]; - value: { - (): (node: GraphNode) => number; - (value: (node: GraphNode) => number): TreeMapLayout; - } - size: { - (): number[]; - (size: number[]): TreeMapLayout; - } - padding: { - (): number; - (padding: number): TreeMapLayout; - } - round: { - (): boolean; - (round: boolean): TreeMapLayout; - } - sticky: { - (): boolean; - (sticky: boolean): TreeMapLayout; - } - mode: { - (): string; - (mode: string): TreeMapLayout; - } - } - } - - // Color - export module Color { - export interface Color { - /** - * increase lightness by some exponential factor (gamma) - */ - brighter(k?: number): Color; - /** - * decrease lightness by some exponential factor (gamma) - */ - darker(k?: number): Color; - /** - * convert the color to a string. - */ - toString(): string; - } - - export interface RGBColor extends Color{ - /** - * the red color channel. - */ - r: number; - /** - * the green color channel. - */ - g: number; - /** - * the blue color channel. - */ - b: number; - /** - * convert from RGB to HSL. - */ - hsl(): HSLColor; - } - - export interface HSLColor extends Color{ - /** - * hue - */ - h: number; - /** - * saturation - */ - s: number; - /** - * lightness - */ - l: number; - /** - * convert from HSL to RGB. - */ - rgb(): RGBColor; - } - - export interface LABColor extends Color{ - /** - * lightness - */ - l: number; - /** - * a-dimension - */ - a: number; - /** - * b-dimension - */ - b: number; - /** - * convert from LAB to RGB. - */ - rgb(): RGBColor; - } - - export interface HCLColor extends Color{ - /** - * hue - */ - h: number; - /** - * chroma - */ - c: number; - /** - * luminance - */ - l: number; - /** - * convert from HCL to RGB. - */ - rgb(): RGBColor; - } - } - - // SVG - export module Svg { - export interface Svg { - /** - * Create a new symbol generator - */ - symbol(): Symbol; - /** - * Create a new axis generator - */ - axis(): Axis; - /** - * Create a new arc generator - */ - arc(): Arc; - /** - * Create a new line generator - */ - line: { - (): Line; - radial(): LineRadial; - } - /** - * Create a new area generator - */ - area: { - (): Area; - radial(): AreaRadial; - } - /** - * Create a new brush generator - */ - brush(): Brush; - /** - * Create a new chord generator - */ - chord(): Chord; - /** - * Create a new diagonal generator - */ - diagonal: { - (): Diagonal; - radial(): Diagonal; - } - /** - * The array of supported symbol types. - */ - symbolTypes: string[]; - } - - export interface Symbol { - type: (symbolType: string | ((datum: any, index: number) => string)) => Symbol; - size: (size: number | ((datum: any, index: number) => number)) => Symbol; - (datum:any, index:number): string; - } - - export interface Brush { - /** - * Draws or redraws this brush into the specified selection of elements - */ - (selection: Selection): void; - /** - * Gets or sets the x-scale associated with the brush - */ - x: { - /** - * Gets the x-scale associated with the brush - */ - (): D3.Scale.Scale; - /** - * Sets the x-scale associated with the brush - * - * @param accessor The new Scale - */ - (scale: D3.Scale.Scale): Brush; - }; - /** - * Gets or sets the x-scale associated with the brush - */ - y: { - /** - * Gets the x-scale associated with the brush - */ - (): D3.Scale.Scale; - /** - * Sets the x-scale associated with the brush - * - * @param accessor The new Scale - */ - (scale: D3.Scale.Scale): Brush; - }; - /** - * Gets or sets the current brush extent - */ - extent: { - /** - * Gets the current brush extent - */ - (): any[]; - /** - * Sets the current brush extent - */ - (values: any[]): Brush; - }; - /** - * Clears the extent, making the brush extent empty. - */ - clear(): Brush; - /** - * Returns true if and only if the brush extent is empty - */ - empty(): boolean; - /** - * Gets or sets the listener for the specified event type - */ - on: { - /** - * Gets the listener for the specified event type - */ - (type: string): (data: any, index: number) => any; - /** - * Sets the listener for the specified event type - */ - (type: string, listener: (data: any, index: number) => any, capture?: boolean): Brush; - }; - } - - export interface Axis { - (selection: Selection): void; - (transition: Transition.Transition): void; - - scale: { - (): any; - (scale: any): Axis; - }; - - orient: { - (): string; - (orientation: string): Axis; - }; - - ticks: { - (): any[]; - (...arguments: any[]): Axis; - }; - - tickPadding: { - (): number; - (padding: number): Axis; - }; - - tickValues: { - (): any[]; - (values: any[]): Axis; - }; - tickSubdivide(count: number): Axis; - tickSize: { - (): number; - (inner: number, outer?: number): Axis; - } - innerTickSize: { - (): number; - (value: number): Axis; - } - outerTickSize: { - (): number; - (value: number): Axis; - } - tickFormat(formatter: (value: any, index?: number) => string): Axis; - nice(count?: number): Axis; - } - - export interface Arc { - /** - * Returns the path data string - * - * @param data Array of data elements - * @param index Optional index - */ - (data: any, index?: number): string; - innerRadius: { - (): (data: any, index?: number) => number; - (radius: number): Arc; - (radius: () => number): Arc; - (radius: (data: any) => number): Arc; - (radius: (data: any, index: number) => number): Arc; - }; - outerRadius: { - (): (data: any, index?: number) => number; - (radius: number): Arc; - (radius: () => number): Arc; - (radius: (data: any) => number): Arc; - (radius: (data: any, index: number) => number): Arc; - }; - startAngle: { - (): (data: any, index?: number) => number; - (angle: number): Arc; - (angle: () => number): Arc; - (angle: (data: any) => number): Arc; - (angle: (data: any, index: number) => number): Arc; - }; - endAngle: { - (): (data: any, index?: number) => number; - (angle: number): Arc; - (angle: () => number): Arc; - (angle: (data: any) => number): Arc; - (angle: (data: any, index: number) => number): Arc; - }; - centroid(data: any, index?: number): number[]; - } - - export interface Line { - /** - * Returns the path data string - * - * @param data Array of data elements - * @param index Optional index - */ - (data: any[], index?: number): string; - /** - * Get or set the x-coordinate accessor. - */ - x: { - /** - * Get the x-coordinate accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the x-coordinate accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): Line; - (accessor: (data: any, index: number) => number): Line; - /** - * Set the x-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): Line; - }; - /** - * Get or set the y-coordinate accessor. - */ - y: { - /** - * Get the y-coordinate accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the y-coordinate accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): Line; - (accessor: (data: any, index: number) => number): Line; - /** - * Set the y-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): Line; - }; - /** - * Get or set the interpolation mode. - */ - interpolate: { - /** - * Get the interpolation accessor. - */ - (): string; - /** - * Set the interpolation accessor. - * - * @param interpolate The interpolation mode - */ - (interpolate: string): Line; - }; - /** - * Get or set the cardinal spline tension. - */ - tension: { - /** - * Get the cardinal spline accessor. - */ - (): number; - /** - * Set the cardinal spline accessor. - * - * @param tension The Cardinal spline interpolation tension - */ - (tension: number): Line; - }; - /** - * Control whether the line is defined at a given point. - */ - defined: { - /** - * Get the accessor function that controls where the line is defined. - */ - (): (data: any, index?: number) => boolean; - /** - * Set the accessor function that controls where the area is defined. - * - * @param defined The new accessor function - */ - (defined: (data: any, index?: number) => boolean): Line; - }; - } - - export interface LineRadial { - /** - * Returns the path data string - * - * @param data Array of data elements - * @param index Optional index - */ - (data: any[], index?: number): string; - /** - * Get or set the x-coordinate accessor. - */ - x: { - /** - * Get the x-coordinate accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the x-coordinate accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): LineRadial; - (accessor: (data: any, index: number) => number): LineRadial; - - /** - * Set the x-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): LineRadial; - }; - /** - * Get or set the y-coordinate accessor. - */ - y: { - /** - * Get the y-coordinate accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the y-coordinate accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): LineRadial; - (accessor: (data: any, index: number) => number): LineRadial; - /** - * Set the y-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): LineRadial; - }; - /** - * Get or set the interpolation mode. - */ - interpolate: { - /** - * Get the interpolation accessor. - */ - (): string; - /** - * Set the interpolation accessor. - * - * @param interpolate The interpolation mode - */ - (interpolate: string): LineRadial; - }; - /** - * Get or set the cardinal spline tension. - */ - tension: { - /** - * Get the cardinal spline accessor. - */ - (): number; - /** - * Set the cardinal spline accessor. - * - * @param tension The Cardinal spline interpolation tension - */ - (tension: number): LineRadial; - }; - /** - * Control whether the line is defined at a given point. - */ - defined: { - /** - * Get the accessor function that controls where the line is defined. - */ - (): (data: any) => any; - /** - * Set the accessor function that controls where the area is defined. - * - * @param defined The new accessor function - */ - (defined: (data: any) => any): LineRadial; - }; - radius: { - (): (d: any, i?: number) => number; - (radius: number): LineRadial; - (radius: (d: any) => number): LineRadial; - (radius: (d: any, i: number) => number): LineRadial; - } - angle: { - (): (d: any, i?: any) => number; - (angle: number): LineRadial; - (angle: (d: any) => number): LineRadial; - (angle: (d: any, i: any) => number): LineRadial; - } - } - - export interface Area { - /** - * Generate a piecewise linear area, as in an area chart. - */ - (data: any[], index?: number): string; - /** - * Get or set the x-coordinate accessor. - */ - x: { - /** - * Get the x-coordinate accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the x-coordinate accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): Area; - (accessor: (data: any, index: number) => number): Area; - /** - * Set the x-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): Area; - }; - /** - * Get or set the x0-coordinate (baseline) accessor. - */ - x0: { - /** - * Get the x0-coordinate (baseline) accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the x0-coordinate (baseline) accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): Area; - (accessor: (data: any, index: number) => number): Area; - /** - * Set the x0-coordinate (baseline) to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): Area; - }; - /** - * Get or set the x1-coordinate (topline) accessor. - */ - x1: { - /** - * Get the x1-coordinate (topline) accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the x1-coordinate (topline) accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): Area; - (accessor: (data: any, index: number) => number): Area; - /** - * Set the x1-coordinate (topline) to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): Area; - }; - /** - * Get or set the y-coordinate accessor. - */ - y: { - /** - * Get the y-coordinate accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the y-coordinate accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): Area; - (accessor: (data: any, index: number) => number): Area; - /** - * Set the y-coordinate to a constant. - * - * @param cnst The constant value - */ - (cnst: number): Area; - }; - /** - * Get or set the y0-coordinate (baseline) accessor. - */ - y0: { - /** - * Get the y0-coordinate (baseline) accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the y0-coordinate (baseline) accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): Area; - (accessor: (data: any, index: number) => number): Area; - /** - * Set the y0-coordinate (baseline) to a constant. - * - * @param cnst The constant value - */ - (cnst: number): Area; - }; - /** - * Get or set the y1-coordinate (topline) accessor. - */ - y1: { - /** - * Get the y1-coordinate (topline) accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the y1-coordinate (topline) accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): Area; - (accessor: (data: any, index: number) => number): Area; - /** - * Set the y1-coordinate (baseline) to a constant. - * - * @param cnst The constant value - */ - (cnst: number): Area; - }; - /** - * Get or set the interpolation mode. - */ - interpolate: { - /** - * Get the interpolation accessor. - */ - (): string; - /** - * Set the interpolation accessor. - * - * @param interpolate The interpolation mode - */ - (interpolate: string): Area; - }; - /** - * Get or set the cardinal spline tension. - */ - tension: { - /** - * Get the cardinal spline accessor. - */ - (): number; - /** - * Set the cardinal spline accessor. - * - * @param tension The Cardinal spline interpolation tension - */ - (tension: number): Area; - }; - /** - * Control whether the area is defined at a given point. - */ - defined: { - /** - * Get the accessor function that controls where the area is defined. - */ - (): (data: any, index?: number) => any; - /** - * Set the accessor function that controls where the area is defined. - * - * @param defined The new accessor function - */ - (defined: (data: any, index?: number) => any): Area; - }; - } - - export interface AreaRadial { - /** - * Generate a piecewise linear area, as in an area chart. - */ - (data: any[], index?: number): string; - /** - * Get or set the x-coordinate accessor. - */ - x: { - /** - * Get the x-coordinate accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the x-coordinate accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): AreaRadial; - (accessor: (data: any, index: number) => number): AreaRadial; - /** - * Set the x-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): AreaRadial; - }; - /** - * Get or set the x0-coordinate (baseline) accessor. - */ - x0: { - /** - * Get the x0-coordinate (baseline) accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the x0-coordinate (baseline) accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): AreaRadial; - (accessor: (data: any, index: number) => number): AreaRadial; - /** - * Set the x0-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): AreaRadial; - }; - /** - * Get or set the x1-coordinate (topline) accessor. - */ - x1: { - /** - * Get the x1-coordinate (topline) accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the x1-coordinate (topline) accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): AreaRadial; - (accessor: (data: any, index: number) => number): AreaRadial; - /** - * Set the x1-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): AreaRadial; - }; - /** - * Get or set the y-coordinate accessor. - */ - y: { - /** - * Get the y-coordinate accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the y-coordinate accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): AreaRadial; - (accessor: (data: any, index: number) => number): AreaRadial; - /** - * Set the y-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): AreaRadial; - }; - /** - * Get or set the y0-coordinate (baseline) accessor. - */ - y0: { - /** - * Get the y0-coordinate (baseline) accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the y0-coordinate (baseline) accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): AreaRadial; - (accessor: (data: any, index: number) => number): AreaRadial; - /** - * Set the y0-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): AreaRadial; - }; - /** - * Get or set the y1-coordinate (topline) accessor. - */ - y1: { - /** - * Get the y1-coordinate (topline) accessor. - */ - (): (data: any, index ?: number) => number; - /** - * Set the y1-coordinate (topline) accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: any) => number): AreaRadial; - (accessor: (data: any, index: number) => number): AreaRadial; - /** - * Set the y1-coordinate to a constant. - * - * @param cnst The new constant value. - */ - (cnst: number): AreaRadial; - }; - /** - * Get or set the interpolation mode. - */ - interpolate: { - /** - * Get the interpolation accessor. - */ - (): string; - /** - * Set the interpolation accessor. - * - * @param interpolate The interpolation mode - */ - (interpolate: string): AreaRadial; - }; - /** - * Get or set the cardinal spline tension. - */ - tension: { - /** - * Get the cardinal spline accessor. - */ - (): number; - /** - * Set the cardinal spline accessor. - * - * @param tension The Cardinal spline interpolation tension - */ - (tension: number): AreaRadial; - }; - /** - * Control whether the area is defined at a given point. - */ - defined: { - /** - * Get the accessor function that controls where the area is defined. - */ - (): (data: any) => any; - /** - * Set the accessor function that controls where the area is defined. - * - * @param defined The new accessor function - */ - (defined: (data: any) => any): AreaRadial; - }; - radius: { - (): number; - (radius: number): AreaRadial; - (radius: () => number): AreaRadial; - (radius: (data: any) => number): AreaRadial; - (radius: (data: any, index: number) => number): AreaRadial; - }; - innerRadius: { - (): number; - (radius: number): AreaRadial; - (radius: () => number): AreaRadial; - (radius: (data: any) => number): AreaRadial; - (radius: (data: any, index: number) => number): AreaRadial; - }; - outerRadius: { - (): number; - (radius: number): AreaRadial; - (radius: () => number): AreaRadial; - (radius: (data: any) => number): AreaRadial; - (radius: (data: any, index: number) => number): AreaRadial; - }; - angle: { - (): number; - (angle: number): AreaRadial; - (angle: () => number): AreaRadial; - (angle: (data: any) => number): AreaRadial; - (angle: (data: any, index: number) => number): AreaRadial; - }; - startAngle: { - (): number; - (angle: number): AreaRadial; - (angle: () => number): AreaRadial; - (angle: (data: any) => number): AreaRadial; - (angle: (data: any, index: number) => number): AreaRadial; - }; - endAngle: { - (): number; - (angle: number): AreaRadial; - (angle: () => number): AreaRadial; - (angle: (data: any) => number): AreaRadial; - (angle: (data: any, index: number) => number): AreaRadial; - }; - } - - export interface Chord { - (datum: any, index?: number): string; - radius: { - (): number; - (radius: number): Chord; - (radius: () => number): Chord; - }; - startAngle: { - (): number; - (angle: number): Chord; - (angle: () => number): Chord; - }; - endAngle: { - (): number; - (angle: number): Chord; - (angle: () => number): Chord; - }; - source: { - (): any; - (angle: any): Chord; - (angle: (d: any, i?: number) => any): Chord; - }; - target: { - (): any; - (angle: any): Chord; - (angle: (d: any, i?: number) => any): Chord; - }; - } - - export interface Diagonal { - (datum: any, index?: number): string; - projection: { - (): (datum: any, index?: number) => number[]; - (proj: (datum: any) => number[]): Diagonal; - (proj: (datum: any, index: number) => number[]): Diagonal; - }; - source: { - (): (datum: any, index?: number) => any; - (src: (datum: any) => any): Diagonal; - (src: (datum: any, index: number) => any): Diagonal; - (src: any): Diagonal; - }; - target: { - (): (datum: any, index?: number) => any; - (target: (d: any) => any): Diagonal; - (target: (d: any, i: number) => any): Diagonal; - (target: any): Diagonal; - }; - } - } - - // Scales - export module Scale { - export interface ScaleBase { - /** - * Construct a linear quantitative scale. - */ - linear(): LinearScale; - /* - * Construct an ordinal scale. - */ - ordinal(): OrdinalScale; - /** - * Construct a linear quantitative scale with a discrete output range. - */ - quantize(): QuantizeScale; - /* - * Construct an ordinal scale with ten categorical colors. - */ - category10(): OrdinalScale; - /* - * Construct an ordinal scale with twenty categorical colors - */ - category20(): OrdinalScale; - /* - * Construct an ordinal scale with twenty categorical colors - */ - category20b(): OrdinalScale; - /* - * Construct an ordinal scale with twenty categorical colors - */ - category20c(): OrdinalScale; - /* - * Construct a linear identity scale. - */ - identity(): IdentityScale; - /* - * Construct a quantitative scale with an logarithmic transform. - */ - log(): LogScale; - /* - * Construct a quantitative scale with an exponential transform. - */ - pow(): PowScale; - /* - * Construct a quantitative scale mapping to quantiles. - */ - quantile(): QuantileScale; - /* - * Construct a quantitative scale with a square root transform. - */ - sqrt(): SqrtScale; - /* - * Construct a threshold scale with a discrete output range. - */ - threshold(): ThresholdScale; - } - - export interface GenericScale { - (value: any): any; - domain: { - (values: any[]): S; - (): any[]; - }; - range: { - (values: any[]): S; - (): any[]; - }; - invertExtent?(y: any): any[]; - copy(): S; - } - - export interface Scale extends GenericScale { } - - export interface GenericQuantitativeScale extends GenericScale { - /** - * Get the range value corresponding to a given domain value. - * - * @param value Domain Value - */ - (value: number): number; - /** - * Get the domain value corresponding to a given range value. - * - * @param value Range Value - */ - invert(value: number): number; - /** - * Set the scale's output range, and enable rounding. - * - * @param value The output range. - */ - rangeRound: (values: any[]) => S; - /** - * get or set the scale's output interpolator. - */ - interpolate: { - (): D3.Transition.Interpolate; - (factory: D3.Transition.Interpolate): S; - }; - /** - * enable or disable clamping of the output range. - * - * @param clamp Enable or disable - */ - clamp: { - (): boolean; - (clamp: boolean): S; - } - /** - * extend the scale domain to nice round numbers. - * - * @param count Optional number of ticks to exactly fit the domain - */ - nice(count?: number): S; - /** - * get representative values from the input domain. - * - * @param count Aproximate representative values to return. - */ - ticks(count: number): any[]; - /** - * get a formatter for displaying tick values - * - * @param count Aproximate representative values to return - */ - tickFormat(count: number, format?: string): (n: number) => string; - } - - export interface QuantitativeScale extends GenericQuantitativeScale { } - - export interface LinearScale extends GenericQuantitativeScale { } - - export interface IdentityScale extends GenericScale { - /** - * Get the range value corresponding to a given domain value. - * - * @param value Domain Value - */ - (value: number): number; - /** - * Get the domain value corresponding to a given range value. - * - * @param value Range Value - */ - invert(value: number): number; - /** - * get representative values from the input domain. - * - * @param count Aproximate representative values to return. - */ - ticks(count: number): any[]; - /** - * get a formatter for displaying tick values - * - * @param count Aproximate representative values to return - */ - tickFormat(count: number): (n: number) => string; - } - - export interface SqrtScale extends GenericQuantitativeScale { } - - export interface PowScale extends GenericQuantitativeScale { } - - export interface LogScale extends GenericQuantitativeScale { } - - export interface OrdinalScale extends GenericScale { - rangePoints(interval: any[], padding?: number): OrdinalScale; - rangeBands(interval: any[], padding?: number, outerPadding?: number): OrdinalScale; - rangeRoundBands(interval: any[], padding?: number, outerPadding?: number): OrdinalScale; - rangeBand(): number; - rangeExtent(): any[]; - } - - export interface QuantizeScale extends GenericScale { } - - export interface ThresholdScale extends GenericScale { } - - export interface QuantileScale extends GenericScale { - quantiles(): any[]; - } - - export interface TimeScale extends GenericScale { - (value: Date): number; - invert(value: number): Date; - rangeRound: (values: any[]) => TimeScale; - interpolate: { - (): D3.Transition.Interpolate; - (factory: D3.Transition.InterpolateFactory): TimeScale; - }; - clamp(clamp: boolean): TimeScale; - ticks: { - (count: number): any[]; - (range: D3.Time.Range, count: number): any[]; - }; - tickFormat(count: number): (n: number) => string; - nice(count?: number): TimeScale; - } - } - - // Behaviour - export module Behavior { - export interface Behavior{ - /** - * Constructs a new drag behaviour - */ - drag(): Drag; - /** - * Constructs a new zoom behaviour - */ - zoom(): Zoom; - } - - export interface Zoom { - /** - * Applies the zoom behavior to the specified selection, - * registering the necessary event listeners to support - * panning and zooming. - */ - (selection: Selection): void; - - /** - * Registers a listener to receive events - * - * @param type Enent name to attach the listener to - * @param listener Function to attach to event - */ - on: (type: string, listener: (data: any, index?: number) => any) => Zoom; - - /** - * Gets or set the current zoom scale - */ - scale: { - /** - * Get the current current zoom scale - */ - (): number; - /** - * Set the current current zoom scale - * - * @param origin Zoom scale - */ - (scale: number): Zoom; - }; - - /** - * Gets or set the current zoom translation vector - */ - translate: { - /** - * Get the current zoom translation vector - */ - (): number[]; - /** - * Set the current zoom translation vector - * - * @param translate Tranlation vector - */ - (translate: number[]): Zoom; - }; - - /** - * Gets or set the allowed scale range - */ - scaleExtent: { - /** - * Get the current allowed zoom range - */ - (): number[]; - /** - * Set the allowable zoom range - * - * @param extent Allowed zoom range - */ - (extent: number[]): Zoom; - }; - - /** - * Gets or set the X-Scale that should be adjusted when zooming - */ - x: { - /** - * Get the X-Scale - */ - (): D3.Scale.Scale; - /** - * Set the X-Scale to be adjusted - * - * @param x The X Scale - */ - (x: D3.Scale.Scale): Zoom; - - }; - - /** - * Gets or set the Y-Scale that should be adjusted when zooming - */ - y: { - /** - * Get the Y-Scale - */ - (): D3.Scale.Scale; - /** - * Set the Y-Scale to be adjusted - * - * @param y The Y Scale - */ - (y: D3.Scale.Scale): Zoom; - }; - } - - export interface Drag { - /** - * Execute drag method - */ - (): any; - - /** - * Registers a listener to receive events - * - * @param type Enent name to attach the listener to - * @param listener Function to attach to event - */ - on: (type: string, listener: (data: any, index?: number) => any) => Drag; - - /** - * Gets or set the current origin accessor function - */ - origin: { - /** - * Get the current origin accessor function - */ - (): any; - /** - * Set the origin accessor function - * - * @param origin Accessor function - */ - (origin?: any): Drag; - }; - } - } - - // Geography - export module Geo { - export interface Geo { - /** - * create a new geographic path generator - */ - path(): Path; - /** - * create a circle generator. - */ - circle(): Circle; - /** - * compute the spherical area of a given feature. - */ - area(feature: any): number; - /** - * compute the latitude-longitude bounding box for a given feature. - */ - bounds(feature: any): number[][]; - /** - * compute the spherical centroid of a given feature. - */ - centroid(feature: any): number[]; - /** - * compute the great-arc distance between two points. - */ - distance(a: number[], b: number[]): number; - /** - * interpolate between two points along a great arc. - */ - interpolate(a: number[], b: number[]): (t: number) => number[]; - /** - * compute the length of a line string or the circumference of a polygon. - */ - length(feature: any): number; - /** - * create a standard projection from a raw projection. - */ - projection(raw: RawProjection): Projection; - /** - * create a standard projection from a mutable raw projection. - */ - projectionMutator(rawFactory: RawProjection): ProjectionMutator; - /** - * the Albers equal-area conic projection. - */ - albers(): Projection; - /** - * a composite Albers projection for the United States. - */ - albersUsa(): Projection; - /** - * the azimuthal equal-area projection. - */ - azimuthalEqualArea: { - (): Projection; - raw: RawProjection; - } - /** - * the azimuthal equidistant projection. - */ - azimuthalEquidistant: { - (): Projection; - raw: RawProjection; - } - /** - * the conic conformal projection. - */ - conicConformal: { - (): Projection; - raw(phi1:number, phi2:number): RawProjection; - } - /** - * the conic equidistant projection. - */ - conicEquidistant: { - (): Projection; - raw(phi1:number, phi2:number): RawProjection; - } - /** - * the conic equal-area (a.k.a. Albers) projection. - */ - conicEqualArea: { - (): Projection; - raw(phi1:number, phi2:number): RawProjection; - } - /** - * the equirectangular (plate carreé) projection. - */ - equirectangular: { - (): Projection; - raw: RawProjection; - } - /** - * the gnomonic projection. - */ - gnomonic: { - (): Projection; - raw: RawProjection; - } - /** - * the spherical Mercator projection. - */ - mercator: { - (): Projection; - raw: RawProjection; - } - /** - * the azimuthal orthographic projection. - */ - orthographic: { - (): Projection; - raw: RawProjection; - } - /** - * the azimuthal stereographic projection. - */ - stereographic: { - (): Projection; - raw: RawProjection; - } - /** - * the transverse Mercator projection. - */ - transverseMercator: { - (): Projection; - raw: RawProjection; - } - /** - * convert a GeoJSON object to a geometry stream. - */ - stream(object: GeoJSON, listener: Stream): void; - /** - * - */ - graticule(): Graticule; - /** - * - */ - greatArc(): GreatArc; - /** - * - */ - rotation(rotation: number[]): Rotation; - } - - export interface Path { - /** - * Returns the path data string for the given feature - */ - (feature: any, index?: any): string; - /** - * get or set the geographic projection. - */ - projection: { - /** - * get the geographic projection. - */ - (): Projection; - /** - * set the geographic projection. - */ - (projection: Projection): Path; - } - /** - * get or set the render context. - */ - context: { - /** - * return an SVG path string invoked on the given feature. - */ - (): string; - /** - * sets the render context and returns the path generator - */ - (context: Context): Path; - } - /** - * Computes the projected area - */ - area(feature: any): any; - /** - * Computes the projected centroid - */ - centroid(feature: any): any; - /** - * Computes the projected bounding box - */ - bounds(feature: any): any; - /** - * get or set the radius to display point features. - */ - pointRadius: { - /** - * returns the current radius - */ - (): number; - /** - * sets the radius used to display Point and MultiPoint features to the specified number - */ - (radius: number): Path; - /** - * sets the radius used to display Point and MultiPoint features to the specified number - */ - (radius: (feature: any, index: number) => number): Path; - } - } - - export interface Context { - beginPath(): any; - moveTo(x: number, y: number): any; - lineTo(x: number, y: number): any; - arc(x: number, y: number, radius: number, startAngle: number, endAngle: number): any; - closePath(): any; - } - - export interface Circle { - (...args: any[]): GeoJSON; - origin: { - (): number[]; - (origin: number[]): Circle; - (origin: (...args: any[]) => number[]): Circle; - } - angle: { - (): number; - (angle: number): Circle; - } - precision: { - (): number; - (precision: number): Circle; - } - } - - export interface Graticule{ - (): GeoJSON; - lines(): GeoJSON[]; - outline(): GeoJSON; - extent: { - (): number[][]; - (extent: number[][]): Graticule; - } - minorExtent: { - (): number[][]; - (extent: number[][]): Graticule; - } - majorExtent: { - (): number[][]; - (extent: number[][]): Graticule; - } - step: { - (): number[][]; - (extent: number[][]): Graticule; - } - minorStep: { - (): number[][]; - (extent: number[][]): Graticule; - } - majorStep: { - (): number[][]; - (extent: number[][]): Graticule; - } - precision: { - (): number; - (precision: number): Graticule; - } - } - - export interface GreatArc { - (): GeoJSON; - distance(): number; - source: { - (): any; - (source: any): GreatArc; - } - target: { - (): any; - (target: any): GreatArc; - } - precision: { - (): number; - (precision: number): GreatArc; - } - } - - export interface GeoJSON { - coordinates: number[][]; - type: string; - } - - export interface RawProjection { - (lambda: number, phi: number): number[]; - invert?(x: number, y: number): number[]; - } - - export interface Projection { - (coordinates: number[]): number[]; - invert?(point: number[]): number[]; - rotate: { - (): number[]; - (rotation: number[]): Projection; - }; - center: { - (): number[]; - (location: number[]): Projection; - }; - parallels: { - (): number[]; - (location: number[]): Projection; - }; - translate: { - (): number[]; - (point: number[]): Projection; - }; - scale: { - (): number; - (scale: number): Projection; - }; - clipAngle: { - (): number; - (angle: number): Projection; - }; - clipExtent: { - (): number[][]; - (extent: number[][]): Projection; - }; - precision: { - (): number; - (precision: number): Projection; - }; - stream(listener?: Stream): Stream; - } - - export interface Stream { - point(x: number, y: number, z?: number): void; - lineStart(): void; - lineEnd(): void; - polygonStart(): void; - polygonEnd(): void; - sphere(): void; - } - - export interface Rotation extends Array { - (location: number[]): Rotation; - invert(location: number[]): Rotation; - } - - export interface ProjectionMutator { - (lambda: number, phi: number): Projection; - } - } - - // Geometry - export module Geom { - export interface Geom { - voronoi(): Voronoi; - /** - * compute the Voronoi diagram for the specified points. - */ - voronoi(vertices: Vertice[]): Polygon[]; - /** - * compute the Delaunay triangulation for the specified points. - */ - delaunay(vertices?: Vertice[]): Polygon[]; - /** - * constructs a quadtree for an array of points. - */ - quadtree(): QuadtreeFactory; - /** - * Constructs a new quadtree for the specified array of points. - */ - quadtree(points: Point[], x1: number, y1: number, x2: number, y2: number): Quadtree; - /** - * Constructs a new quadtree for the specified array of points. - */ - quadtree(points: Point[], width: number, height: number): Quadtree; - /** - * Returns the input array of vertices with additional methods attached - */ - polygon(vertices:Vertice[]): Polygon; - /** - * creates a new hull layout with the default settings. - */ - hull(): Hull; - - hull(vertices:Vertice[]): Vertice[]; - } - - export interface Vertice extends Array { - /** - * Returns the angle of the vertice - */ - angle?: number; - } - - export interface Polygon extends Array { - /** - * Returns the signed area of this polygon - */ - area(): number; - /** - * Returns a two-element array representing the centroid of this polygon. - */ - centroid(): number[]; - /** - * Clips the subject polygon against this polygon - */ - clip(subject: Polygon): Polygon; - } - - export interface QuadtreeFactory { - /** - * Constructs a new quadtree for the specified array of points. - */ - (): Quadtree; - /** - * Constructs a new quadtree for the specified array of points. - */ - (points: Point[], x1: number, y1: number, x2: number, y2: number): Quadtree; - /** - * Constructs a new quadtree for the specified array of points. - */ - (points: Point[], width: number, height: number): Quadtree; - - x: { - (): (d: any) => any; - (accesor: (d: any) => any): QuadtreeFactory; - - } - y: { - (): (d: any) => any; - (accesor: (d: any) => any): QuadtreeFactory; - - } - size(): number[]; - size(size: number[]): QuadtreeFactory; - extent(): number[][]; - extent(points: number[][]): QuadtreeFactory; - } - - export interface Quadtree { - /** - * Adds a new point to the quadtree. - */ - add(point: Point): void; - visit(callback: any): void; - } - - export interface Point { - x: number; - y: number; - } - - export interface Voronoi { - /** - * Compute the Voronoi diagram for the specified data. - */ - (data: T[]): Polygon[]; - /** - * Compute the graph links for the Voronoi diagram for the specified data. - */ - links(data: T[]): Layout.GraphLink[]; - /** - * Compute the triangles for the Voronoi diagram for the specified data. - */ - triangles(data: T[]): number[][]; - x: { - /** - * Get the x-coordinate accessor. - */ - (): (data: T, index ?: number) => number; - - /** - * Set the x-coordinate accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: T, index: number) => number): Voronoi; - - /** - * Set the x-coordinate to a constant. - * - * @param constant The new constant value. - */ - (constant: number): Voronoi; - } - y: { - /** - * Get the y-coordinate accessor. - */ - (): (data: T, index ?: number) => number; - - /** - * Set the y-coordinate accessor. - * - * @param accessor The new accessor function - */ - (accessor: (data: T, index: number) => number): Voronoi; - - /** - * Set the y-coordinate to a constant. - * - * @param constant The new constant value. - */ - (constant: number): Voronoi; - } - clipExtent: { - /** - * Get the clip extent. - */ - (): number[][]; - /** - * Set the clip extent. - * - * @param extent The new clip extent. - */ - (extent: number[][]): Voronoi; - } - size: { - /** - * Get the size. - */ - (): number[]; - /** - * Set the size, equivalent to a clip extent starting from (0,0). - * - * @param size The new size. - */ - (size: number[]): Voronoi; - } - } - - export interface Hull { - (vertices: Vertice[]): Vertice[]; - x: { - (): (d: any) => any; - (accesor: (d: any) => any): any; - } - y: { - (): (d: any) => any; - (accesor: (d: any) => any): any; - } - } - } -} - -declare var d3: D3.Base; - -declare module "d3" { - export = d3; -} +// Type definitions for d3JS +// Project: http://d3js.org/ +// Definitions by: Boris Yankov +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module d3 { + /** + * The current version of D3.js. + */ + export var version: string; + + /** + * Find the first element that matches the given selector string. + */ + export function select(selector: string): Selection; + + /** + * Create a selection from the given node reference. + */ + export function select(node: EventTarget): Selection; + + /** + * Find all elements that match the given selector string. + */ + export function selectAll(selector: string): Selection; + + /** + * Create a selection from the given list of nodes. + */ + export function selectAll(nodes: EventTarget[]): Selection; + + /** + * 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. + */ + export function selection(): Selection; + + module selection { + export var prototype: Selection; + + /** + * Selections are grouped into arrays of nodes, with the parent tracked in the 'parentNode' property. + */ + interface Group extends Array { + parentNode: EventTarget; + } + + interface Update { + /** + * Retrieve a grouped selection. + */ + [index: number]: Group; + + /** + * The number of groups in this selection. + */ + length: number; + + /** + * Retrieve the value of the given attribute for the first node in the selection. + * + * @param name The attribute name to query. May be prefixed (see d3.ns.prefix). + */ + attr(name: string): string; + + /** + * For all nodes, set the attribute to the specified constant value. Use null to remove. + * + * @param name The attribute name, optionally prefixed. + * @param value The attribute value to use. Note that this is coerced to a string automatically. + */ + attr(name: string, value: Primitive): Update; + + /** + * Derive an attribute value for each node in the selection based on bound data. + * + * @param name The attribute name, optionally prefixed. + * @param value The function of the datum (the bound data item) and index (the position in the subgrouping) which computes the attribute value. If the function returns null, the attribute is removed. + */ + attr(name: string, value: (datum: Datum, index: number) => Primitive): Update; + + /** + * 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. + * + * @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. + */ + attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number) => Primitive) }): Update; + + /** + * 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. + * + * @param name The class list to query. + */ + classed(name: string): boolean; + + /** + * Adds (or removes) the given class list. + * + * @param name The class list to toggle. Spaces separate class names: "foo bar" is a list of two classes. + * @param value If true, add the classes. If false, remove them. + */ + classed(name: string, value: boolean): Update; + + /** + * Determine if the given class list should be toggled for each node in the selection. + * + * @param name The class list. Spaces separate multiple class names. + * @param value The function to run for each node. Should return true to add the class to the node, or false to remove it. + */ + classed(name: string, value: (datum: Datum, index: number) => boolean): Update; + + /** + * Set or derive classes for multiple class lists at once. + * + * @param obj An Object mapping class lists to values that are either plain booleans or functions that return booleans. + */ + classed(obj: { [key: string]: boolean | ((datum: Datum, index: number) => boolean) }): Update; + + /** + * Retrieve the computed style value for the first node in the selection. + * @param name The CSS property name to query + */ + style(name: string): string; + + /** + * Set a style property for all nodes in the selection. + * @param name the CSS property name + * @param value the property value + * @param priority if specified, either null or the string "important" (no exclamation mark) + */ + style(name: string, value: Primitive, priority?: string): Update; + + /** + * Derive a property value for each node in the selection. + * @param name the CSS property name + * @param value the function to derive the value + * @param priority if specified, either null or the string "important" (no exclamation mark) + */ + style(name: string, value: (datum: Datum, index: number) => Primitive, priority?: string): Update; + + /** + * Set a large number of CSS properties from an object. + * + * @param obj an Object whose keys correspond to CSS property names and values are either constants or functions that derive property values + * @param priority if specified, either null or the string "important" (no exclamation mark) + */ + style(obj: { [key: string]: Primitive | ((datum: Datum, index: number) => Primitive) }, priority?: string): Update; + + /** + * Retrieve an arbitrary node property such as the 'checked' property of checkboxes, or the 'value' of text boxes. + * + * @param name the node's property to retrieve + */ + property(name: string): any; + + /** + * 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__. + * + * @param name the property name + * @param value the property value + */ + property(name: string, value: any): Update; + + /** + * 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__. + * + * @param name the property name + * @param value the function used to derive the property's value + */ + property(name: string, value: (datum: Datum, index: number) => any): Update; + + /** + * Set multiple node properties. Caveats apply: take care not to mutate special properties like __proto__. + * + * @param obj an Object whose keys correspond to node properties and values are either constants or functions that will compute a value. + */ + property(obj: { [key: string]: any | ((datum: Datum, index: number) => any) }): Update; + + /** + * Retrieve the textContent of the first node in the selection. + */ + text(): string; + + /** + * Set the textContent of each node in the selection. + * @param value the text to use for all nodes + */ + text(value: Primitive): Update; + + /** + * Compute the textContent of each node in the selection. + * @param value the function which will compute the text + */ + text(value: (datum: Datum, index: number) => Primitive): Update; + + /** + * 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. + */ + html(): string; + + /** + * 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. + * @param value the HTML content to use. + */ + html(value: string): Selection; + + /** + * 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. + * @param value the function to compute HTML content + */ + html(value: (datum: Datum, index: number) => string): Selection; + + /** + * 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. + * + * @param name the element name to append. May be prefixed (see d3.ns.prefix). + */ + append(name: string): Selection; + + /** + * 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. + * + * @param name the function to compute a new element + */ + append(name: (datum: Datum, index: number) => EventTarget): Update; + + /** + * 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. + * @param name the element name to append. May be prefixed (see d3.ns.prefix). + * @param before the selector to determine position (e.g., ":first-child") + */ + insert(name: string, before: string): Update; + + /** + * 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. + * @param name the element name to append. May be prefixed (see d3.ns.prefix). + * @param before a function to determine the node to use as the next sibling + */ + insert(name: string, before: (datum: Datum, index: number) => EventTarget): Update; + + /** + * 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. + * @param name the function to compute a new child + * @param before the selector to determine position (e.g., ":first-child") + */ + insert(name: (datum: Datum, index: number) => EventTarget, before: string): Update; + + /** + * 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. + * @param name the function to compute a new child + * @param before a function to determine the node to use as the next sibling + */ + insert(name: (datum: Datum, index: number) => EventTarget, before: (datum: Datum, index: number) => EventTarget): Update; + + /** + * 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). + */ + remove(): Update; + + /** + * Retrieves the data bound to the first group in this selection. + */ + data(): Datum[]; + + /** + * Binds data to this selection. + * @param data the array of data to bind to this selection + * @param key the optional function to determine the unique key for each piece of data. When unspecified, uses the index of the element. + */ + data(data: NewDatum[], key?: (datum: NewDatum, index: number) => string): Update; + + /** + * Derives data to bind to this selection. + * @param data the function to derive data. Must return an array. + * @param key the optional function to determine the unique key for each data item. When unspecified, uses the index of the element. + */ + data(data: (datum: Datum, index: number) => NewDatum[], key?: (datum: NewDatum, index: number) => string): Update; + + /** + * Filters the selection, returning only those nodes that match the given CSS selector. + * @param selector the CSS selector + */ + filter(selector: string): Update; + + /** + * Filters the selection, returning only those nodes for which the given function returned true. + * @param selector the filter function + */ + filter(selector: (datum: Datum, index: number) => boolean): Update; + + /** + * Return the data item bound to the first element in the selection. + */ + datum(): Datum; + + /** + * Set the data item for each node in the selection. + * @param value the constant element to use for each node + */ + datum(value: NewDatum): Update; + + /** + * Derive the data item for each node in the selection. Useful for situations such as the HTML5 'dataset' attribute. + * @param value the function to compute data for each node + */ + datum(value: (datum: Datum, index: number) => NewDatum): Update; + + /** + * Reorders nodes in the selection based on the given comparator. Nodes are re-inserted into the document once sorted. + * @param comparator the comparison function, which defaults to d3.ascending + */ + sort(comparator?: (a: Datum, b: Datum) => number): Update; + + /** + * Reorders nodes in the document to match the selection order. More efficient than calling sort() if the selection is already ordered. + */ + order(): Update; + + /** + * Returns the listener (if any) for the given event. + * @param type the type of event to load the listener for. May have a namespace (e.g., ".foo") at the end. + */ + on(type: string): (datum: Datum, index: number) => any; + + /** + * 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. + * @param type the of event to listen to. May have a namespace (e.g., ".foo") at the end. + * @param listener an event listener function, or null to unregister + * @param capture sets the DOM useCapture flag + */ + on(type: string, listener: (datum: Datum, index: number) => any, capture?: boolean): Update; + + /** + * Begins a new transition. Interrupts any active transitions of the same name. + * @param name the transition name (defaults to "") + */ + transition(name?: string): Transition; + + /** + * Interrupts the active transition of the provided name. Does not cancel scheduled transitions. + * @param name the transition name (defaults to "") + */ + interrupt(name?: string): Update; + + /** + * Creates a subselection by finding the first descendent matching the selector string. Bound data is inherited. + * @param selector the CSS selector to match against + */ + select(selector: string): Update; + + /** + * Creates a subselection by using a function to find descendent elements. Bound data is inherited. + * @param selector the function to find matching descendants + */ + select(selector: (datum: Datum, index: number) => EventTarget): Update; + + /** + * Creates a subselection by finding all descendents that match the given selector. Bound data is not inherited. + * @param selector the CSS selector to match against + */ + selectAll(selector: string): Update; + + /** + * Creates a subselection by using a function to find descendent elements. Bound data is not inherited. + * @param selector the function to find matching descendents + */ + selectAll(selector: (datum: Datum, index: number) => Array | NodeList): Update; + + /** + * Invoke the given function for each element in the selection. The return value of the function is ignored. + * @param func the function to invoke + */ + each(func: (datum: Datum, index: number) => any): Update; + + /** + * Call a function on the selection. sel.call(foo) is equivalent to foo(sel). + * @param func the function to call on the selection + * @param args any optional args + */ + call(func: (sel: Update, ...args: any[]) => any, ...args: any[]): Update; + + /** + * Returns true if the current selection is empty. + */ + empty(): boolean; + + /** + * Returns the first non-null element in the selection, or null otherwise. + */ + node(): EventTarget; + + /** + * Returns the total number of elements in the selection. + */ + size(): number; + + /** + * Returns the placeholder nodes for each data element for which no corresponding DOM element was found. + */ + enter(): Enter; + + /** + * Returns a selection for those DOM nodes for which no new data element was found. + */ + exit(): Selection; + } + + interface Enter { + append(name: string): Selection; + append(name: (datum: Datum, index: number) => EventTarget): Selection; + + insert(name: string, before?: string): Selection; + insert(name: string, before: (datum: Datum, index: number) => EventTarget): Selection; + insert(name: (datum: Datum, index: number) => EventTarget, before?: string): Selection; + insert(name: (datum: Datum, index: number) => EventTarget, before: (datum: Datum, index: number) => EventTarget): Selection; + + select(name: (datum: Datum, index: number) => EventTarget): Selection; + call(func: (selection: Enter, ...args: any[]) => any, ...args: any[]): Enter; + } + } + + /** + * Administrivia: JavaScript primitive types, or "things that toString() predictably". + */ + export type Primitive = number | string | boolean; + + /** + * Administrivia: anything with a valueOf(): number method is comparable, so we allow it in numeric operations + */ + interface Numeric { + valueOf(): number; + } + + /** + * A grouped array of nodes. + * @param Datum the data bound to this selection. + */ + interface Selection { + /** + * Retrieve a grouped selection. + */ + [index: number]: selection.Group; + + /** + * The number of groups in this selection. + */ + length: number; + + /** + * Retrieve the value of the given attribute for the first node in the selection. + * + * @param name The attribute name to query. May be prefixed (see d3.ns.prefix). + */ + attr(name: string): string; + + /** + * For all nodes, set the attribute to the specified constant value. Use null to remove. + * + * @param name The attribute name, optionally prefixed. + * @param value The attribute value to use. Note that this is coerced to a string automatically. + */ + attr(name: string, value: Primitive): Selection; + + /** + * Derive an attribute value for each node in the selection based on bound data. + * + * @param name The attribute name, optionally prefixed. + * @param value The function of the datum (the bound data item) and index (the position in the subgrouping) which computes the attribute value. If the function returns null, the attribute is removed. + */ + attr(name: string, value: (datum: Datum, index: number) => Primitive): Selection; + + /** + * 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. + * + * @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. + */ + attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number) => Primitive) }): Selection; + + /** + * 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. + * + * @param name The class list to query. + */ + classed(name: string): boolean; + + /** + * Adds (or removes) the given class list. + * + * @param name The class list to toggle. Spaces separate class names: "foo bar" is a list of two classes. + * @param value If true, add the classes. If false, remove them. + */ + classed(name: string, value: boolean): Selection; + + /** + * Determine if the given class list should be toggled for each node in the selection. + * + * @param name The class list. Spaces separate multiple class names. + * @param value The function to run for each node. Should return true to add the class to the node, or false to remove it. + */ + classed(name: string, value: (datum: Datum, index: number) => boolean): Selection; + + /** + * Set or derive classes for multiple class lists at once. + * + * @param obj An Object mapping class lists to values that are either plain booleans or functions that return booleans. + */ + classed(obj: { [key: string]: boolean | ((datum: Datum, index: number) => boolean) }): Selection; + + /** + * Retrieve the computed style value for the first node in the selection. + * @param name The CSS property name to query + */ + style(name: string): string; + + /** + * Set a style property for all nodes in the selection. + * @param name the CSS property name + * @param value the property value + * @param priority if specified, either null or the string "important" (no exclamation mark) + */ + style(name: string, value: Primitive, priority?: string): Selection; + + /** + * Derive a property value for each node in the selection. + * @param name the CSS property name + * @param value the function to derive the value + * @param priority if specified, either null or the string "important" (no exclamation mark) + */ + style(name: string, value: (datum: Datum, index: number) => Primitive, priority?: string): Selection; + + /** + * Set a large number of CSS properties from an object. + * + * @param obj an Object whose keys correspond to CSS property names and values are either constants or functions that derive property values + * @param priority if specified, either null or the string "important" (no exclamation mark) + */ + style(obj: { [key: string]: Primitive | ((datum: Datum, index: number) => Primitive) }, priority?: string): Selection; + + /** + * Retrieve an arbitrary node property such as the 'checked' property of checkboxes, or the 'value' of text boxes. + * + * @param name the node's property to retrieve + */ + property(name: string): any; + + /** + * 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__. + * + * @param name the property name + * @param value the property value + */ + property(name: string, value: any): Selection; + + /** + * 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__. + * + * @param name the property name + * @param value the function used to derive the property's value + */ + property(name: string, value: (datum: Datum, index: number) => any): Selection; + + /** + * Set multiple node properties. Caveats apply: take care not to mutate special properties like __proto__. + * + * @param obj an Object whose keys correspond to node properties and values are either constants or functions that will compute a value. + */ + property(obj: { [key: string]: any | ((datum: Datum, index: number) => any) }): Selection; + + /** + * Retrieve the textContent of the first node in the selection. + */ + text(): string; + + /** + * Set the textContent of each node in the selection. + * @param value the text to use for all nodes + */ + text(value: Primitive): Selection; + + /** + * Compute the textContent of each node in the selection. + * @param value the function which will compute the text + */ + text(value: (datum: Datum, index: number) => Primitive): Selection; + + /** + * 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. + */ + html(): string; + + /** + * 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. + * @param value the HTML content to use. + */ + html(value: string): Selection; + + /** + * 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. + * @param value the function to compute HTML content + */ + html(value: (datum: Datum, index: number) => string): Selection; + + /** + * 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. + * + * @param name the element name to append. May be prefixed (see d3.ns.prefix). + */ + append(name: string): Selection; + + /** + * 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. + * + * @param name the function to compute a new element + */ + append(name: (datum: Datum, index: number) => EventTarget): Selection; + + /** + * 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. + * @param name the element name to append. May be prefixed (see d3.ns.prefix). + * @param before the selector to determine position (e.g., ":first-child") + */ + insert(name: string, before: string): Selection; + + /** + * 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. + * @param name the element name to append. May be prefixed (see d3.ns.prefix). + * @param before a function to determine the node to use as the next sibling + */ + insert(name: string, before: (datum: Datum, index: number) => EventTarget): Selection; + + /** + * 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. + * @param name the function to compute a new child + * @param before the selector to determine position (e.g., ":first-child") + */ + insert(name: (datum: Datum, index: number) => EventTarget, before: string): Selection; + + /** + * 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. + * @param name the function to compute a new child + * @param before a function to determine the node to use as the next sibling + */ + insert(name: (datum: Datum, index: number) => EventTarget, before: (datum: Datum, index: number) => EventTarget): Selection; + + /** + * 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). + */ + remove(): Selection; + + /** + * Retrieves the data bound to the first group in this selection. + */ + data(): Datum[]; + + /** + * Binds data to this selection. + * @param data the array of data to bind to this selection + * @param key the optional function to determine the unique key for each piece of data. When unspecified, uses the index of the element. + */ + data(data: NewDatum[], key?: (datum: NewDatum, index: number) => string): selection.Update; + + /** + * Derives data to bind to this selection. + * @param data the function to derive data. Must return an array. + * @param key the optional function to determine the unique key for each data item. When unspecified, uses the index of the element. + */ + data(data: (datum: Datum, index: number) => NewDatum[], key?: (datum: NewDatum, index: number) => string): selection.Update; + + /** + * Filters the selection, returning only those nodes that match the given CSS selector. + * @param selector the CSS selector + */ + filter(selector: string): Selection; + + /** + * Filters the selection, returning only those nodes for which the given function returned true. + * @param selector the filter function + */ + filter(selector: (datum: Datum, index: number) => boolean): Selection; + + /** + * Return the data item bound to the first element in the selection. + */ + datum(): Datum; + + /** + * Derive the data item for each node in the selection. Useful for situations such as the HTML5 'dataset' attribute. + * @param value the function to compute data for each node + */ + datum(value: (datum: Datum, index: number) => NewDatum): Selection; + + /** + * Set the data item for each node in the selection. + * @param value the constant element to use for each node + */ + datum(value: NewDatum): Selection; + + /** + * Reorders nodes in the selection based on the given comparator. Nodes are re-inserted into the document once sorted. + * @param comparator the comparison function, which defaults to d3.ascending + */ + sort(comparator?: (a: Datum, b: Datum) => number): Selection; + + /** + * Reorders nodes in the document to match the selection order. More efficient than calling sort() if the selection is already ordered. + */ + order(): Selection; + + /** + * Returns the listener (if any) for the given event. + * @param type the type of event to load the listener for. May have a namespace (e.g., ".foo") at the end. + */ + on(type: string): (datum: Datum, index: number) => any; + + /** + * 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. + * @param type the of event to listen to. May have a namespace (e.g., ".foo") at the end. + * @param listener an event listener function, or null to unregister + * @param capture sets the DOM useCapture flag + */ + on(type: string, listener: (datum: Datum, index: number) => any, capture?: boolean): Selection; + + /** + * Begins a new transition. Interrupts any active transitions of the same name. + * @param name the transition name (defaults to "") + */ + transition(name?: string): Transition; + + /** + * Interrupts the active transition of the provided name. Does not cancel scheduled transitions. + * @param name the transition name (defaults to "") + */ + interrupt(name?: string): Selection; + + /** + * Creates a subselection by finding the first descendent matching the selector string. Bound data is inherited. + * @param selector the CSS selector to match against + */ + select(selector: string): Selection; + + /** + * Creates a subselection by using a function to find descendent elements. Bound data is inherited. + * @param selector the function to find matching descendants + */ + select(selector: (datum: Datum, index: number) => EventTarget): Selection; + + /** + * Creates a subselection by finding all descendents that match the given selector. Bound data is not inherited. + * @param selector the CSS selector to match against + */ + selectAll(selector: string): Selection; + + /** + * Creates a subselection by finding all descendants that match the given selector. Bound data is not inherited. + * + * Use this overload when data-binding a subselection (that is, sel.selectAll('.foo').data(d => ...)). The type will carry over. + */ + selectAll(selector: string): Selection; + + /** + * Creates a subselection by using a function to find descendent elements. Bound data is not inherited. + * @param selector the function to find matching descendents + */ + selectAll(selector: (datum: Datum, index: number) => Array | NodeList): Selection; + + /** + * Creates a subselection by using a function to find descendent elements. Bound data is not inherited. + * + * Use this overload when data-binding a subselection (that is, sel.selectAll('.foo').data(d => ...)). The type will carry over. + * @param selector the function to find matching descendents + */ + selectAll(selector: (datum: Datum, index: number) => Array | NodeList): Selection; + + /** + * Invoke the given function for each element in the selection. The return value of the function is ignored. + * @param func the function to invoke + */ + each(func: (datum: Datum, index: number) => any): Selection; + + /** + * Call a function on the selection. sel.call(foo) is equivalent to foo(sel). + * @param func the function to call on the selection + * @param args any optional args + */ + call(func: (sel: Selection, ...args: any[]) => any, ...args: any[]): Selection; + + /** + * Returns true if the current selection is empty. + */ + empty(): boolean; + + /** + * Returns the first non-null element in the selection, or null otherwise. + */ + node(): EventTarget; + + /** + * Returns the total number of elements in the selection. + */ + size(): number; + } + + export function transition(): Transition; + module transition { + export var prototype: Transition; + } + + interface Transition { + delay(): number; + delay(delay: number): Transition; + delay(delay: (datum: Datum, index: number) => number): Transition; + + duration(): number; + duration(duration: number): Transition; + duration(duration: (datum: Datum, index: number) => number): Transition; + + ease(): (t: number) => number; + ease(value: string, ...args: any[]): Transition; + ease(value: (t: number) => number): Transition; + + attr(name: string, value: Primitive): Transition; + attr(name: string, value: (datum: Datum, index: number) => Primitive): Transition; + attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number) => Primitive) }): Transition; + + attrTween(name: string, tween: (datum: Datum, index: number, attr: string) => Primitive): Transition; + + style(name: string, value: Primitive, priority?: string): Transition; + style(name: string, value: (datum: Datum, index: number) => Primitive, priority?: string): Transition; + style(obj: { [key: string]: Primitive | ((datum: Datum, index: number) => Primitive) }, priority?: string): Transition; + + styleTween(name: string, tween: (datum: Datum, index: number, attr: string) => Primitive, priority?: string): Transition; + + text(value: Primitive): Transition; + text(value: (datum: Datum, index: number) => Primitive): Transition; + + tween(name: string, factory: () => (t: number) => any): Transition; + + remove(): Transition; + + select(selector: string): Transition; + select(selector: (d: Datum, i: number) => EventTarget): Transition; + + selectAll(selector: string): Transition; + selectAll(selector: (d: Datum, i: number) => EventTarget[]): Transition; + + filter(selector: string): Transition; + filter(selector: (d: Datum, i: number) => boolean): Transition; + + each(type: string, listener: (d: Datum, i: number) => any): Transition; + each(listener: (d: Datum, i: number) => any): Transition; + + call(func: (transition: Transition, ...args: any[]) => any, ...args: any[]): Transition; + + empty(): boolean; + node(): EventTarget; + size(): number; + } + + export function ease(type: 'linear'): (t: number) => number; + export function ease(type: 'linear-in'): (t: number) => number; + export function ease(type: 'linear-out'): (t: number) => number; + export function ease(type: 'linear-in-out'): (t: number) => number; + export function ease(type: 'linear-out-in'): (t: number) => number; + + export function ease(type: 'poly', k: number): (t: number) => number; + export function ease(type: 'poly-in', k: number): (t: number) => number; + export function ease(type: 'poly-out', k: number): (t: number) => number; + export function ease(type: 'poly-in-out', k: number): (t: number) => number; + export function ease(type: 'poly-out-in', k: number): (t: number) => number; + + export function ease(type: 'quad'): (t: number) => number; + export function ease(type: 'quad-in'): (t: number) => number; + export function ease(type: 'quad-out'): (t: number) => number; + export function ease(type: 'quad-in-out'): (t: number) => number; + export function ease(type: 'quad-out-in'): (t: number) => number; + + export function ease(type: 'cubic'): (t: number) => number; + export function ease(type: 'cubic-in'): (t: number) => number; + export function ease(type: 'cubic-out'): (t: number) => number; + export function ease(type: 'cubic-in-out'): (t: number) => number; + export function ease(type: 'cubic-out-in'): (t: number) => number; + + export function ease(type: 'sin'): (t: number) => number; + export function ease(type: 'sin-in'): (t: number) => number; + export function ease(type: 'sin-out'): (t: number) => number; + export function ease(type: 'sin-in-out'): (t: number) => number; + export function ease(type: 'sin-out-in'): (t: number) => number; + + export function ease(type: 'circle'): (t: number) => number; + export function ease(type: 'circle-in'): (t: number) => number; + export function ease(type: 'circle-out'): (t: number) => number; + export function ease(type: 'circle-in-out'): (t: number) => number; + export function ease(type: 'circle-out-in'): (t: number) => number; + + export function ease(type: 'elastic', a?: number, b?: number): (t: number) => number; + export function ease(type: 'elastic-in', a?: number, b?: number): (t: number) => number; + export function ease(type: 'elastic-out', a?: number, b?: number): (t: number) => number; + export function ease(type: 'elastic-in-out', a?: number, b?: number): (t: number) => number; + export function ease(type: 'elastic-out-in', a?: number, b?: number): (t: number) => number; + + export function ease(type: 'back', s: number): (t: number) => number; + export function ease(type: 'back-in', s: number): (t: number) => number; + export function ease(type: 'back-out', s: number): (t: number) => number; + export function ease(type: 'back-in-out', s: number): (t: number) => number; + export function ease(type: 'back-out-in', s: number): (t: number) => number; + + export function ease(type: 'bounce'): (t: number) => number; + export function ease(type: 'bounce-in'): (t: number) => number; + export function ease(type: 'bounce-out'): (t: number) => number; + export function ease(type: 'bounce-in-out'): (t: number) => number; + export function ease(type: 'bounce-out-in'): (t: number) => number; + + export function ease(type: string, ...args: any[]): (t: number) => number; + + export function timer(func: () => any, delay?: number, time?: number): void; + + module timer { + export function flush(): void; + } + + /** + * The current event's value. Use this variable in a handler registered with selection.on. + */ + export var event: Event; + + /** + * 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. + * @param container the container element (e.g. an SVG element) + */ + export function mouse(container: EventTarget): [number, number]; + + /** + * Given a container element and a touch identifier, determine the x and y coordinates of the touch. + * @param container the container element (e.g., an SVG element) + * @param identifier the given touch identifier + */ + export function touch(container: EventTarget, identifer: number): [number, number]; + + /** + * Given a container element, a list of touches, and a touch identifier, determine the x and y coordinates of the touch. + * @param container the container element (e.g., an SVG element) + * @param identifier the given touch identifier + */ + export function touch(container: EventTarget, touches: TouchList, identifer: number): [number, number]; + + /** + * Given a container element and an optional list of touches, return the position of every touch relative to the container. + * @param container the container element + * @param touches an optional list of touches (defaults to d3.event.touches) + */ + export function touches(container: EventTarget, touches?: TouchList): Array<[number, number]>; + + // NB. this is limited to primitive values due to D3's use of the <, >, and >= operators. Results get weird for object instances. + /** + * Compares two primitive values for sorting (in ascending order). + */ + export function ascending(a: Primitive, b: Primitive): number; + + /** + * Compares two primitive values for sorting (in ascending order). + */ + export function descending(a: Primitive, b: Primitive): number; + + /** + * Return the minimum value in the array using natural order. + */ + export function min(array: number[]): number; + + /** + * Return the minimum value in the array using natural order. + */ + export function min(array: string[]): string; + + /** + * Return the minimum value in the array using natural order. + */ + export function min(array: T[]): T; + + /** + * Return the minimum value in the array using natural order. + */ + export function min(array: T[], accessor: (datum: T, index: number) => number): number; + + /** + * Return the minimum value in the array using natural order. + */ + export function min(array: T[], accessor: (datum: T, index: number) => string): string; + + /** + * Return the minimum value in the array using natural order. + */ + export function min(array: T[], accessor: (datum: T, index: number) => U): U; + + /** + * Return the maximum value in the array of numbers using natural order. + */ + export function max(array: number[]): number; + + /** + * Return the maximum value in the array of strings using natural order. + */ + export function max(array: string[]): string; + + /** + * Return the maximum value in the array of numbers using natural order. + */ + export function max(array: T[]): T; + + /** + * Return the maximum value in the array using natural order and a projection function to map values to numbers. + */ + export function max(array: T[], accessor: (datum: T, index: number) => number): number; + + /** + * Return the maximum value in the array using natural order and a projection function to map values to strings. + */ + export function max(array: T[], accessor: (datum: T, index: number) => string): string; + + /** + * Return the maximum value in the array using natural order and a projection function to map values to easily-sorted values. + */ + export function max(array: T[], accessor: (datum: T, index: number) => U): U; + + /** + * Return the min and max simultaneously. + */ + export function extent(array: number[]): [number, number]; + + /** + * Return the min and max simultaneously. + */ + export function extent(array: string[]): [string, string]; + + /** + * Return the min and max simultaneously. + */ + export function extent(array: T[]): [T, T]; + + /** + * Return the min and max simultaneously. + */ + export function extent(array: Array): [T | Primitive, T | Primitive]; + + /** + * Return the min and max simultaneously. + */ + export function extent(array: T[], accessor: (datum: T, index: number) => number): [number, number]; + + /** + * Return the min and max simultaneously. + */ + export function extent(array: T[], accessor: (datum: T, index: number) => string): [string, string]; + + /** + * Return the min and max simultaneously. + */ + export function extent(array: U[], accessor: (datum: T, index: number) => U): [U | Primitive, U | Primitive]; + + /** + * Compute the sum of an array of numbers. + */ + export function sum(array: number[]): number; + + /** + * Compute the sum of an array, using the given accessor to convert values to numbers. + */ + export function sum(array: T[], accessor: (datum: T, index: number) => number): number; + + export function mean(array: number[]): number; + export function mean(array: T[], accessor: (datum: T, index: number) => number): number; + + export function quantile(array: number[], p: number): number; + + export function variance(array: number[]): number; + export function variance(array: T[], accessor: (datum: T, index: number) => number): number; + + export function deviation(array: number[]): number; + export function deviation(array: T[], accessor: (datum: T, index: number) => number): number; + + export function bisectLeft(array: number[], x: number, lo?: number, hi?: number): number; + export function bisectLeft(array: string[], x: string, lo?: number, hi?: number): number; + + export var bisect: typeof bisectRight; + + export function bisectRight(array: T[], x: T, lo?: number, hi?: number): number; + + export function bisector(accessor: (x: T) => U): { + left: (array: T[], x: T, lo?: number, hi?: number) => number; + right: (array: T[], x: T, lo?: number, hi?: number) => number; + } + + export function bisector(comparator: (a: T, b: U) => number): { + left: (array: T[], x: U, lo?: number, hi?: number) => number; + right: (array: T[], x: U, lo?: number, hi?: number) => number; + } + + export function shuffle(array: T[], lo?: number, hi?: number): T[]; + + /** + * Returns the enumerable property names of the specified object. + * @param object a JavaScript object + */ + export function keys(object: Object): string[]; + + /** + * Returns an array containing the property values of the specified object. + */ + export function values(object: { [key: string]: T }): T[]; + /** + * Returns an array containing the property values of the specified object. + */ + export function values(object: { [key: number]: T }): T[]; + /** + * Returns an array containing the property values of the specified object. + */ + export function values(object: Object): any[]; + + /** + * Returns an array of key-value pairs containing the property values of the specified object. + */ + export function entries(object: { [key: string]: T }): { key: string; value: T }[]; + + /** + * Returns an array of key-value pairs containing the property values of the specified object. + */ + export function entries(object: { [key: number]: T }): { key: string; value: T }[]; + + /** + * Returns an array of key-value pairs containing the property values of the specified object. + */ + export function entries(object: Object): { key: string; value: any }[]; + + /** + * A shim for ES6 maps. The implementation uses a JavaScript object internally, and thus keys are limited to strings. + */ + interface Map { + /** + * Does the map contain the given key? + */ + has(key: string): boolean; + + /** + * Retrieve the value for the given key. Returns undefined if there is no value stored. + */ + get(key: string): T; + + /** + * Set the value for the given key. Returns the new value. + */ + set(key: string, value: T): T; + + /** + * Remove the value for the given key. Returns true if there was a value and false otherwise. + */ + remove(key: string): boolean; + + /** + * Returns an array of all keys in arbitrary order. + */ + keys(): string[]; + + /** + * Returns an array of all values in arbitrary order. + */ + values(): T[]; + + /** + * Returns an array of key-value objects in arbitrary order. + */ + entries(): { key: string; value: T }[]; + + /** + * Calls the function for each key and value pair in the map. The 'this' context is the map itself. + */ + forEach(func: (key: string, value: T) => any): void; + + /** + * Is this map empty? + */ + empty(): boolean; + + /** + * Returns the number of elements stored in the map. + */ + size(): number; + } + + /** + * Constructs an initially empty map. + */ + export function map(): Map; + + /** + * Construct a new map by copying keys and values from the given one. + */ + export function map(object: Map): Map; + + /** + * Construct a new map by copying enumerable properties and values from the given object. + */ + export function map(object: { [key: string]: T }): Map; + + /** + * Construct a new map by copying enumerable properties and values from the given object. + */ + export function map(object: { [key: number]: T }): Map; + + /** + * Construct a new map by copying elements from the array. The key function is used to identify each object. + */ + export function map(array: T[], key: (datum: T, index: number) => string): Map; + + /** + * Construct a new map by copying enumerable properties and values from the given object. + */ + export function map(object: Object): Map; + + /** + * A shim for ES6 sets. Is only able to store strings. + */ + interface Set { + /** + * Is the given string stored in this set? + */ + has(value: string): boolean; + + /** + * Add the string to this set. Returns the value. + */ + add(value: string): string; + + /** + * Remove the given value from the set. Returns true if it was stored, and false otherwise. + */ + remove(value: string): boolean; + + /** + * Returns an array of the strings stored in this set. + */ + values(): string[]; + + /** + * 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. + */ + forEach(func: (value: string) => any): void; + + /** + * Is this set empty? + */ + empty(): boolean; + + /** + * Returns the number of values stored in this set. + */ + size(): number; + } + + /** + * Creates an initially-empty set. + */ + export function set(): Set; + + /** + * Initializes a set from the given array of strings. + */ + export function set(array: string[]): Set; + + /** + * Merges the specified arrays into a single array. + */ + export function merge(arrays: T[][]): T[]; + + /** + * Generates a 0-based numeric sequence. The output range does not include 'stop'. + */ + export function range(stop: number): number[]; + + /** + * Generates a numeric sequence starting from the given start and stop values. 'step' defaults to 1. The output range does not include 'stop'. + */ + export function range(start: number, stop: number, step?: number): number[]; + + /** + * Given the specified array, return an array corresponding to the list of indices in 'keys'. + */ + export function permute(array: { [key: number]: T }, keys: number[]): T[]; + + /** + * Given the specified object, return an array corresponding to the list of property names in 'keys'. + */ + export function permute(object: { [key: string]: T }, keys: string[]): T[]; + + // TODO construct n-tuples from n input arrays + export function zip(...arrays: T[][]): T[][]; + + export function transpose(matrix: T[][]): T[][]; + + /** + * For each adjacent pair of elements in the specified array, returns a new array of tuples of elements i and i - 1. + * Returns the empty array if the input array has fewer than two elements. + */ + export function pairs(array: T[]): Array<[T, T]>; + + interface Nest { + key(func: (datum: T) => string): Nest; + sortKeys(comparator: (a: string, b: string) => number): Nest; + sortValues(comparator: (a: T, b: T) => number): Nest; + rollup(func: (values: T[]) => U): Nest; + map(array: T[]): { [key: string]: any }; + map(array: T[], mapType: typeof d3.map): Map; + entries(array: T[]): { key: string; values: any }[]; + } + + export function nest(): Nest; + + export module random { + export function normal(mean?: number, deviation?: number): () => number; + export function logNormal(mean?: number, deviation?: number): () => number; + export function bates(count: number): () => number; + export function irwinHall(count: number): () => number; + } + + interface Transform { + rotate: number; + translate: [number, number]; + skew: number; + scale: [number, number]; + toString(): string; + } + + export function transform(transform: string): Transform; + + export function format(specifier: string): (n: number) => string; + + interface FormatPrefix { + symbol: string; + scale(n: number): number; + } + + export function formatPrefix(value: number, precision?: number): FormatPrefix; + + export function round(x: number, n?: number): number; + + export function requote(string: string): string; + + export var rgb: { + new (r: number, g: number, b: number): Rgb; + new (color: string): Rgb; + + (r: number, g: number, b: number): Rgb; + (color: string): Rgb; + }; + + interface Rgb extends Color { + r: number; + g: number; + b: number; + + brighter(k?: number): Rgb; + darker(k?: number): Rgb; + + hsl(): Hsl; + + toString(): string; + } + + export var hsl: { + new (h: number, s: number, l: number): Hsl; + new (color: string): Hsl; + + (h: number, s: number, l: number): Hsl; + (color: string): Hsl; + }; + + interface Hsl extends Color { + h: number; + s: number; + l: number; + + brighter(k?: number): Hsl; + darker(k?: number): Hsl; + + rgb(): Rgb; + + toString(): string; + } + + export var hcl: { + new (h: number, c: number, l: number): Hcl; + new (color: string): Hcl; + + (h: number, c: number, l: number): Hcl; + (color: string): Hcl; + }; + + interface Hcl extends Color { + h: number; + c: number; + l: number; + + brighter(k?: number): Hcl; + darker(k?: number): Hcl; + } + + export var lab: { + new (l: number, a: number, b: number): Lab; + new (color: string): Lab; + + (l: number, a: number, b: number): Lab; + (color: string): Lab; + } + + interface Lab extends Color { + l: number; + a: number; + b: number; + + brighter(k?: number): Lab; + darker(k?: number): Lab; + + rgb(): Rgb; + toString(): string; + } + + export var color: { + (): Color; + new (): Color; + }; + + interface Color { + rgb(): Rgb; + } + + export module ns { + interface Qualified { + space: string; + local: string; + } + + export var prefix: { [key: string]: string }; + export function qualify(name: string): Qualified | string; + } + + export function functor(value: T): T; + export function functor(value: T): () => T; + + export function rebind(target: {}, source: {}, ...names: string[]): any; + + export function dispatch(...names: string[]): Dispatch; + + interface Dispatch { + on(type: string): (...args: any[]) => void; + on(type: string, listener: (...args: any[]) => any): Dispatch; + [event: string]: (...args: any[]) => void; + } + + export module scale { + export function identity(): Identity; + + interface Identity { + (n: number): number; + invert(n: number): number; + + domain(): number[]; + domain(numbers: number[]): Identity; + + range(): number[]; + range(numbers: number[]): Identity; + + ticks(count?: number): number[]; + + tickFormat(count?: number, format?: string): (n: number) => string; + + copy(): Identity; + } + + export function linear(): Linear; + export function linear(): Linear; + export function linear(): Linear; + + interface Linear { + (x: number): Output; + invert(y: number): number; + + domain(): number[]; + domain(numbers: number[]): Linear; + + range(): Range[]; + range(values: Range[]): Linear; + + rangeRound(values: number[]): Linear; + + interpolate(): (a: Range, b: Range) => (t: number) => Output; + interpolate(factory: (a: Range, b: Range) => (t: number) => Output): Linear; + + clamp(): boolean; + clamp(clamp: boolean): Linear; + + ticks(count?: number): number[]; + + tickFormat(count?: number, format?: string): (n: number) => string; + + copy(): Linear; + } + + export function sqrt(): Pow; + export function sqrt(): Pow; + export function pow(): Pow; + export function pow(): Pow; + + interface Pow { + (x: number): Output; + + invert(y: number): number; + + domain(): number[]; + domain(numbers: number[]): Pow; + + range(): Range[]; + range(values: Range[]): Pow; + + rangeRound(values: number[]): Pow; + + exponent(): number; + exponent(k: number): Pow; + + interpolate(): (a: Range, b: Range) => (t: number) => Output; + interpolate(factory: (a: Range, b: Range) => (t: number) => Output): Pow; + + clamp(): boolean; + clamp(clamp: boolean): Pow; + + nice(m?: number): Pow; + + ticks(count?: number): number[]; + + tickFormat(count?: number, format?: string): (n: number) => string; + + copy(): Pow; + } + + export function log(): Log; + export function log(): Log; + + interface Log { + (x: number): Output; + + invert(y: number): number; + + domain(): number[]; + domain(numbers: number[]): Log; + + range(): Range[]; + range(values: Range[]): Log; + + rangeRound(values: number[]): Log; + + base(): number; + base(base: number): Log; + + interpolate(): (a: Range, b: Range) => (t: number) => Output; + interpolate(factory: (a: Range, b: Range) => (t: number) => Output): Log; + + clamp(): boolean; + clamp(clamp: boolean): Log; + + nice(): Log; + + ticks(): number[]; + + tickFormat(count?: number, format?: string): (t: number) => string; + + copy(): Log; + } + + export function quantize(): Quantize; + + interface Quantize { + (x: number): T; + + invertExtent(y: T): [number, number]; + + domain(): number[]; + domain(numbers: number[]): Quantize; + + range(): T[]; + range(values: T[]): Quantize; + + copy(): Quantize; + } + + export function quantile(): Quantile; + + interface Quantile { + (x: number): T; + + invertExtent(y: T): [number, number]; + + domain(): number[]; + domain(numbers: number[]): Quantile; + + range(): T[]; + range(values: T[]): Quantile; + + quantiles(): number[]; + + copy(): Quantile; + } + + export function threshold(): Threshold; + export function threshold(): Threshold; + + interface Threshold { + (x: number): Range; + + invertExtent(y: Range): [Domain, Domain]; + + domain(): Domain[]; + domain(domain: Domain[]): Threshold; + + range(): Range[]; + range(values: Range[]): Threshold; + + copy(): Threshold; + } + + export function ordinal(): Ordinal; + export function category10(): Ordinal; + export function category20(): Ordinal; + export function category20b(): Ordinal; + export function category20c(): Ordinal; + + interface Ordinal { + (x: Primitive): T; + + domain(): string[]; + domain(values: Primitive[]): Ordinal; + + range(): T[]; + range(values: T[]): Ordinal; + + rangePoints(interval: [number, number], padding?: number): Ordinal; + rangeRoundPoints(interval: [number, number], padding?: number): Ordinal; + + rangeBands(interval: [number, number], padding?: number, outerPadding?: number): Ordinal; + rangeRoundBands(interval: [number, number], padding?: number, outerPadding?: number): Ordinal; + + rangeBand(): number; + rangeExtent(): [number, number]; + + copy(): Ordinal; + } + } + + export function interpolate(a: number, b: number): (t: number) => number; + export function interpolate(a: string, b: string): (t: number) => string; + export function interpolate(a: string | Color, b: Color): (t: number) => string; + export function interpolate(a: Array, b: Color[]): (t: number) => string; + export function interpolate(a: Range[], b: Output[]): (t: number) => Output[]; + export function interpolate(a: Range[], b: Range[]): (t: number) => Output[]; + export function interpolate(a: { [key: string]: string | Color }, b: { [key: string]: Color }): (t: number) => { [key: string]: string }; + export function interpolate(a: { [key: string]: Range }, b: { [key: string]: Output }): (t: number) => { [key: string]: Output }; + export function interpolate(a: { [key: string]: Range }, b: { [key: string]: Range }): (t: number) => { [key: string]: Output }; + + export function interpolateNumber(a: number, b: number): (t: number) => number; + + export function interpolateRound(a: number, b: number): (t: number) => number; + + export function interpolateString(a: string, b: string): (t: number) => string; + + export function interpolateRgb(a: string | Color, b: string | Color): (t: number) => string; + + export function interpolateHsl(a: string | Color, b: string | Color): (t: number) => string; + + export function interpolateLab(a: string | Color, b: string | Color): (t: number) => string; + + export function interpolateHcl(a: string | Color, b: string | Color): (t: number) => string; + + export function interpolateArray(a: Array, b: Color[]): (t: number) => string[]; + export function interpolateArray(a: Range[], b: Range[]): (t: number) => Output[]; + export function interpolateArray(a: Range[], b: Output[]): (t: number) => Output[]; + + export function interpolateObject(a: { [key: string]: string | Color }, b: { [key: string]: Color }): (t: number) => { [key: string]: string }; + export function interpolateObject(a: { [key: string]: Range }, b: { [key: string]: Output }): (t: number) => { [key: string]: Output }; + export function interpolateObject(a: { [key: string]: Range }, b: { [key: string]: Range }): (t: number) => { [key: string]: Output }; + + export function interpolateTransform(a: string | Transform, b: string | Transform): (t: number) => string; + + export function interpolateZoom(a: [number, number, number], b: [number, number, number]): { + (t: number): [number, number, number]; + duration: number; + }; + + export var interpolators: Array<(a: any, b: any) => (t: number) => any>; + + export module time { + export var second: Interval; + export var minute: Interval; + export var hour: Interval; + export var day: Interval; + export var week: Interval; + export var sunday: Interval; + export var monday: Interval; + export var tuesday: Interval; + export var wednesday: Interval; + export var thursday: Interval; + export var friday: Interval; + export var saturday: Interval; + export var month: Interval; + export var year: Interval; + + interface Interval { + (d: Date): Date; + + floor(d: Date): Date; + + round(d: Date): Date; + + ceil(d: Date): Date; + + range(start: Date, stop: Date, step?: number): Date[]; + + offset(date: Date, step: Date): Date; + + utc: { + (d: Date): Date; + + floor(d: Date): Date; + + round(d: Date): Date; + + ceil(d: Date): Date; + + range(start: Date, stop: Date, step?: number): Date[]; + + offset(date: Date, step: Date): Date; + } + } + + export function seconds(start: Date, stop: Date, step?: number): Date[]; + export function minutes(start: Date, stop: Date, step?: number): Date[]; + export function hours(start: Date, stop: Date, step?: number): Date[]; + export function days(start: Date, stop: Date, step?: number): Date[]; + export function weeks(start: Date, stop: Date, step?: number): Date[]; + export function sundays(start: Date, stop: Date, step?: number): Date[]; + export function mondays(start: Date, stop: Date, step?: number): Date[]; + export function tuesdays(start: Date, stop: Date, step?: number): Date[]; + export function wednesdays(start: Date, stop: Date, step?: number): Date[]; + export function thursdays(start: Date, stop: Date, step?: number): Date[]; + export function fridays(start: Date, stop: Date, step?: number): Date[]; + export function saturdays(start: Date, stop: Date, step?: number): Date[]; + export function months(start: Date, stop: Date, step?: number): Date[]; + export function years(start: Date, stop: Date, step?: number): Date[]; + + export function dayOfYear(d: Date): number; + export function weekOfYear(d: Date): number; + export function sundayOfYear(d: Date): number; + export function mondayOfYear(d: Date): number; + export function tuesdayOfYear(d: Date): number; + export function wednesdayOfYear(d: Date): number; + export function fridayOfYear(d: Date): number; + export function saturdayOfYear(d: Date): number; + + export function format(specifier: string): Format; + + export module format { + export function multi(formats: Array<[string, (d: Date) => boolean]>): Format; + export function utc(specifier: string): Format; + export var iso: Format; + } + + interface Format { + (d: Date): string; + parse(input: string): Date; + } + + export function scale(): Scale; + export function scale(): Scale; + export function scale(): Scale; + + export module scale { + export function utc(): Scale; + export function utc(): Scale; + export function utc(): Scale; + } + + + interface Scale { + (x: Date): Output; + + invert(y: number): Date; + + domain(): Date[]; + domain(dates: number[]): Scale; + domain(dates: Date[]): Scale; + + nice(): Scale; + nice(interval: Interval, step?: number): Scale; + + range(): Range[]; + range(values: Range[]): Scale; + + rangeRound(values: number[]): Scale; + + interpolate(): (a: Range, b: Range) => (t: number) => Output; + interpolate(factory: (a: Range, b: Range) => (t: number) => Output): Scale; + + clamp(): boolean; + clamp(clamp: boolean): Scale; + + ticks(): Date[]; + ticks(interval: Interval, step?: number): Date[]; + ticks(count: number): Date[]; + + tickFormat(count: number): (d: Date) => string; + + copy(): Scale; + } + } + + export module behavior { + export function drag(): Drag; + + interface Drag { + (selection: Selection): void; + + on(type: string): (d: Datum, i: number) => any; + on(type: string, listener: (d: Datum, i: number) => any): Drag; + + origin(): (d: Datum, i: number) => { x: number; y: number }; + origin(accessor: (d: Datum, i: number) => { x: number; y: number }): Drag; + } + + export function zoom(): Zoom; + + module zoom { + interface Scale { + domain(): number[]; + domain(values: number[]): Scale; + + invert(y: number): number; + + range(values: number[]): Scale; + range(): number[]; + } + } + + interface Zoom { + (selection: Selection): void; + + translate(): [number, number]; + translate(translate: [number, number]): Zoom; + + scale(): number; + scale(scale: number): Zoom; + + scaleExtent(): [number, number]; + scaleExtent(extent: [number, number]): Zoom; + + center(): [number, number]; + center(center: [number, number]): Zoom; + + size(): [number, number]; + size(size: [number, number]): Zoom; + + x(): zoom.Scale; + x(x: zoom.Scale): Zoom; + + y(): zoom.Scale; + y(y: zoom.Scale): Zoom; + + on(type: string): (d: Datum, i: number) => any; + on(type: string, listener: (d: Datum, i: number) => any): Zoom; + + event(selection: Selection): void; + event(transition: Transition): void; + } + } + + export module geo { + export function path(): Path; + + interface Path { + (feature: any, index?: number): string; + + area(feature: any): number; + + centroid(feature: any): [number, number]; + + bounds(feature: any): [[number, number], [number, number]]; + + projection(): Transform | ((coordinates: [number, number]) => [number, number]); + projection(stream: Transform): Path; + projection(projection: (coordinates: [number, number]) => [number, number]): Path; + + pointRadius(): number | ((datum: any, index: number) => number); + pointRadius(radius: number): Path; + pointRadius(radius: (datum: any, index: number) => number): Path; + + context(): CanvasRenderingContext2D; + context(context: CanvasRenderingContext2D): Path; + } + + export function graticule(): Graticule; + + interface Graticule { + (): any; + + lines(): any[]; + + outline(): any; + + extent(): [[number, number], [number, number]]; + extent(extent: [[number, number], [number, number]]): Graticule; + + majorExtent(): [[number, number], [number, number]]; + majorExtent(extent: [[number, number], [number, number]]): Graticule; + + minorExtent(): [[number, number], [number, number]]; + minorExtent(extent: [[number, number], [number, number]]): Graticule; + + step(): [number, number]; + step(step: [number, number]): Graticule; + + majorStep(): [number, number]; + majorStep(step: [number, number]): Graticule; + + minorStep(): [number, number]; + minorStep(step: [number, number]): Graticule; + + precision(): number; + precision(precision: number): Graticule; + } + + export function circle(): Circle; + + interface Circle { + (...args: any[]): any; + + origin(): [number, number] | ((...args: any[]) => [number, number]); + origin(origin: [number, number]): Circle; + origin(origin: (...args: any[]) => [number, number]): Circle; + + angle(): number; + angle(angle: number): Circle; + + precision(): number; + precision(precision: number): Circle; + } + + export function area(feature: any): number; + export function centroid(feature: any): [number, number]; + export function bounds(feature: any): [[number, number], [number, number]]; + export function distance(a: [number, number], b: [number, number]): number; + export function length(feature: any): number; + export function interpolate(a: [number, number], b: [number, number]): (t: number) => [number, number]; + + export function rotation(rotate: [number, number] | [number, number, number]): Rotation; + + interface Rotation { + (location: [number, number]): [number, number]; + invert(location: [number, number]): [number, number]; + } + + export function stream(object: any, listener: Listener): void; + + interface Listener { + point(x: number, y: number, z: number): void; + lineStart(): void; + lineEnd(): void; + polygonStart(): void; + polygonEnd(): void; + sphere(): void; + } + + export function transform(methods: TransformMethods): Transform; + + interface TransformMethods { + point?(x: number, y: number, z: number): void; + lineStart?(): void; + lineEnd?(): void; + polygonStart?(): void; + polygonEnd?(): void; + sphere?(): void; + } + + interface Transform { + stream(stream: Listener): Listener; + } + + export function clipExtent(): ClipExtent; + + interface ClipExtent extends Transform { + extent(): [[number, number], [number, number]]; + extent(extent: [[number, number], [number, number]]): ClipExtent; + } + + export function projection(raw: RawInvertibleProjection): InvertibleProjection; + export function projection(raw: RawProjection): Projection; + + export function projectionMutator(factory: (...args: any[]) => RawInvertibleProjection): (...args: any[]) => InvertibleProjection; + export function projectionMutator(factory: (...args: any[]) => RawProjection): (...args: any[]) => Projection; + + export function albers(): ConicProjection; + export function albersUsa(): ConicProjection; + export function azimuthalEqualArea(): InvertibleProjection; + module azimuthalEqualArea { + export function raw(lambda: number, phi: number): [number, number]; + module raw { + export function invert(x: number, y: number): [number, number]; + } + } + + export function azimuthalEquidistant(): InvertibleProjection; + module azimuthalEquidistant { + export function raw(lambda: number, phi: number): [number, number]; + module raw { + export function invert(x: number, y: number): [number, number]; + } + } + + export function conicConformal(): ConicProjection; + module conicConformal { + export function raw(phi0: number, phi1: number): RawInvertibleProjection; + } + + export function conicEqualArea(): ConicProjection; + module conicEqualArea { + export function raw(phi0: number, phi1: number): RawInvertibleProjection; + } + + export function conicEquidistant(): ConicProjection; + module conicEquidistant { + export function raw(phi0: number, phi1: number): RawInvertibleProjection; + } + + export function equirectangular(): InvertibleProjection; + module equirectangular { + export function raw(lambda: number, phi: number): [number, number]; + module raw { + export function invert(x: number, y: number): [number, number]; + } + } + + export function gnomonic(): InvertibleProjection; + module gnomonic { + export function raw(lambda: number, phi: number): [number, number]; + module raw { + export function invert(x: number, y: number): [number, number]; + } + } + + export function mercator(): InvertibleProjection; + module mercator { + export function raw(lambda: number, phi: number): [number, number]; + module raw { + export function invert(x: number, y: number): [number, number]; + } + } + + export function orthographic(): InvertibleProjection; + module orthographic { + export function raw(lambda: number, phi: number): [number, number]; + module raw { + export function invert(x: number, y: number): [number, number]; + } + } + + export function stereographic(): InvertibleProjection; + module stereographic { + export function raw(lambda: number, phi: number): [number, number]; + module raw { + export function invert(x: number, y: number): [number, number]; + } + } + + export function transverseMercator(): InvertibleProjection; + module transverseMercator { + export function raw(lambda: number, phi: number): [number, number]; + module raw { + export function invert(x: number, y: number): [number, number]; + } + } + + interface Projection { + (location: [number, number]): [number, number]; + + rotate(): [number, number, number]; + rotate(rotation: [number, number, number]): Projection; + + center(): [number, number]; + center(location: [number, number]): Projection; + + translate(): [number, number]; + translate(point: [number, number]): Projection; + + scale(): number; + scale(scale: number): Projection; + + clipAngle(): number; + clipAngle(angle: number): Projection; + + clipExtent(): [[number, number], [number, number]]; + clipExtent(extent: [[number, number], [number, number]]): Projection; + + precision(): number; + precision(precision: number): Projection; + + stream(listener: Listener): Listener; + } + + interface InvertibleProjection extends Projection { + invert(point: [number, number]): [number, number]; + } + + interface ConicProjection extends InvertibleProjection { + parallels(): [number, number]; + parallels(parallels: [number, number]): ConicProjection; + + rotate(): [number, number, number]; + rotate(rotation: [number, number, number]): ConicProjection; + + center(): [number, number]; + center(location: [number, number]): ConicProjection; + + translate(): [number, number]; + translate(point: [number, number]): ConicProjection; + + scale(): number; + scale(scale: number): ConicProjection; + + clipAngle(): number; + clipAngle(angle: number): ConicProjection; + + clipExtent(): [[number, number], [number, number]]; + clipExtent(extent: [[number, number], [number, number]]): ConicProjection; + + precision(): number; + precision(precision: number): ConicProjection; + } + + interface RawProjection { + (lambda: number, phi: number): [number, number]; + } + + interface RawInvertibleProjection extends RawProjection { + invert(x: number, y: number): [number, number]; + } + } + + module svg { + export function line(): Line<[number, number]>; + export function line(): Line; + + interface Line { + (data: T[]): string; + + x(): number | ((d: T, i: number) => number); + x(x: number): Line; + x(x: (d: T, i: number) => number): Line; + + y(): number | ((d: T, i: number) => number); + y(x: number): Line; + y(y: (d: T, i: number) => number): Line; + + interpolate(): string | ((points: Array<[number, number]>) => string); + interpolate(interpolate: "linear"): Line; + interpolate(interpolate: "linear-closed"): Line; + interpolate(interpolate: "step"): Line; + interpolate(interpolate: "step-before"): Line; + interpolate(interpolate: "step-after"): Line; + interpolate(interpolate: "basis"): Line; + interpolate(interpolate: "basis-open"): Line; + interpolate(interpolate: "basis-closed"): Line; + interpolate(interpolate: "bundle"): Line; + interpolate(interpolate: "cardinal"): Line; + interpolate(interpolate: "cardinal-open"): Line; + interpolate(interpolate: "cardinal-closed"): Line; + interpolate(interpolate: "monotone"): Line; + interpolate(interpolate: string): Line; + interpolate(interpolate: (points: Array<[number, number]>) => string): Line; + + tension(): number; + tension(tension: number): Line; + + defined(): (d: T, i: number) => boolean; + defined(defined: (d: T, i: number) => boolean): Line; + } + + module line { + export function radial(): Radial<[number, number]>; + export function radial(): Radial; + + interface Radial { + (data: T[]): string; + + radius(): number | ((d: T, i: number) => number); + radius(radius: number): Radial; + radius(radius: (d: T, i: number) => number): Radial; + + angle(): number | ((d: T, i: number) => number); + angle(angle: number): Radial; + angle(angle: (d: T, i: number) => number): Radial; + + interpolate(): string | ((points: Array<[number, number]>) => string); + interpolate(interpolate: "linear"): Radial; + interpolate(interpolate: "linear-closed"): Radial; + interpolate(interpolate: "step"): Radial; + interpolate(interpolate: "step-before"): Radial; + interpolate(interpolate: "step-after"): Radial; + interpolate(interpolate: "basis"): Radial; + interpolate(interpolate: "basis-open"): Radial; + interpolate(interpolate: "basis-closed"): Radial; + interpolate(interpolate: "bundle"): Radial; + interpolate(interpolate: "cardinal"): Radial; + interpolate(interpolate: "cardinal-open"): Radial; + interpolate(interpolate: "cardinal-closed"): Radial; + interpolate(interpolate: "monotone"): Radial; + interpolate(interpolate: string): Radial; + interpolate(interpolate: (points: Array<[number, number]>) => string): Radial; + + tension(): number; + tension(tension: number): Radial; + + defined(): (d: T, i: number) => boolean; + defined(defined: (d: T, i: number) => boolean): Radial; + } + } + + export function area(): Area<[number, number]>; + export function area(): Area; + + interface Area { + (data: T[]): string; + + x(): number | ((d: T, i: number) => number); + x(x: number): Area; + x(x: (d: T, i: number) => number): Area; + + x0(): number | ((d: T, i: number) => number); + x0(x0: number): Area; + x0(x0: (d: T, i: number) => number): Area; + + x1(): number | ((d: T, i: number) => number); + x1(x1: number): Area; + x1(x1: (d: T, i: number) => number): Area; + + y(): number | ((d: T, i: number) => number); + y(y: number): Area; + y(y: (d: T, i: number) => number): Area; + + y0(): number | ((d: T, i: number) => number); + y0(y0: number): Area; + y0(y0: (d: T, i: number) => number): Area; + + y1(): number | ((d: T, i: number) => number); + y1(y1: number): Area; + y1(y1: (d: T, i: number) => number): Area; + + interpolate(): string | ((points: Array<[number, number]>) => string); + interpolate(interpolate: "linear"): Area; + interpolate(interpolate: "step"): Area; + interpolate(interpolate: "step-before"): Area; + interpolate(interpolate: "step-after"): Area; + interpolate(interpolate: "basis"): Area; + interpolate(interpolate: "basis-open"): Area; + interpolate(interpolate: "cardinal"): Area; + interpolate(interpolate: "cardinal-open"): Area; + interpolate(interpolate: "monotone"): Area; + interpolate(interpolate: string): Area; + + tension(): number; + tension(tension: number): Area; + + defined(): (d: T, i: number) => boolean; + defined(): (d: T, i: number) => boolean; + } + + module area { + export function radial(): Radial<[number, number]>; + export function radial(): Radial; + + interface Radial { + (data: T[]): string; + + radius(): number | ((d: T, i: number) => number); + radius(radius: number): Radial; + radius(radius: (d: T, i: number) => number): Radial; + + innerRadius(): number | ((d: T, i: number) => number); + innerRadius(innerRadius: number): Radial; + innerRadius(innerRadius: (d: T, i: number) => number): Radial; + + outerRadius(): number | ((d: T, i: number) => number); + outerRadius(outerRadius: number): Radial; + outerRadius(outerRadius: (d: T, i: number) => number): Radial; + + angle(): number | ((d: T, i: number) => number); + angle(angle: number): Radial; + angle(angle: (d: T, i: number) => number): Radial; + + startAngle(): number | ((d: T, i: number) => number); + startAngle(startAngle: number): Radial; + startAngle(startAngle: (d: T, i: number) => number): Radial; + + endAngle(): number | ((d: T, i: number) => number); + endAngle(endAngle: number): Radial; + endAngle(endAngle: (d: T, i: number) => number): Radial; + + interpolate(): string | ((points: Array<[number, number]>) => string); + interpolate(interpolate: "linear"): Radial; + interpolate(interpolate: "step"): Radial; + interpolate(interpolate: "step-before"): Radial; + interpolate(interpolate: "step-after"): Radial; + interpolate(interpolate: "basis"): Radial; + interpolate(interpolate: "basis-open"): Radial; + interpolate(interpolate: "cardinal"): Radial; + interpolate(interpolate: "cardinal-open"): Radial; + interpolate(interpolate: "monotone"): Radial; + interpolate(interpolate: string): Radial; + interpolate(interpolate: (points: Array<[number, number]>) => string): Radial; + + tension(): number; + tension(tension: number): Radial; + + defined(): (d: T, i: number) => boolean; + defined(): (d: T, i: number) => boolean; + } + } + + export function arc(): Arc; + export function arc(): Arc; + + module arc { + interface Arc { + innerRadius: number; + outerRadius: number; + startAngle: number; + endAngle: number; + padAngle: number + } + } + + interface Arc { + (d: T, i: number): string; + + innerRadius(): (d: T, i: number) => number; + innerRadius(radius: number): Arc; + innerRadius(radius: (d: T, i: number) => number): Arc; + + outerRadius(): (d: T, i: number) => number; + outerRadius(radius: number): Arc; + outerRadius(radius: (d: T, i: number) => number): Arc; + + cornerRadius(): (d: T, i: number) => number; + cornerRadius(radius: number): Arc; + cornerRadius(radius: (d: T, i: number) => number): Arc; + + padRadius(): string | ((d: T, i: number) => number); + padRadius(radius: "auto"): Arc; + padRadius(radius: string): Arc; + padRadius(radius: (d: T, i: number) => number): Arc; + + startAngle(): (d: T, i: number) => number; + startAngle(angle: number): Arc; + startAngle(angle: (d: T, i: number) => number): Arc; + + endAngle(): (d: T, i: number) => number; + endAngle(angle: number): Arc; + endAngle(angle: (d: T, i: number) => number): Arc; + + padAngle(): (d: T, i: number) => number; + padAngle(angle: number): Arc; + padAngle(angle: (d: T, i: number) => number): Arc; + + centroid(d: T, i?: number): [number, number]; + } + + export function symbol(): Symbol<{}>; + export function symbol(): Symbol; + + interface Symbol { + (d: T, i: number): string; + + type(): (d: T, i: number) => string; + type(type: string): Symbol; + type(type: (d: T, i: number) => string): Symbol; + + size(): (d: T, i: string) => number; + size(size: number): Symbol; + size(size: (d: T, i: number) => number): Symbol; + } + + export var symbolTypes: string[]; + + export function chord(): Chord, chord.Node>; + export function chord(): Chord, Node>; + export function chord(): Chord; + + module chord { + interface Link { + source: Node; + target: Node; + } + + interface Node { + radius: number; + startAngle: number; + endAngle: number + } + } + + interface Chord { + (d: Link, i: number): string; + + source(): (d: Link, i: number) => Node; + source(source: Node): Chord; + source(source: (d: Link, i: number) => Node): Chord; + + target(): (d: Link, i: number) => Node; + target(target: Node): Chord; + target(target: (d: Link, i: number) => Node): Chord; + + radius(): (d: Node, i: number) => number; + radius(radius: number): Chord; + radius(radius: (d: Node, i: number) => number): Chord; + + startAngle(): (d: Node, i: number) => number; + startAngle(angle: number): Chord; + startAngle(angle: (d: Node, i: number) => number): Chord; + + endAngle(): (d: Node, i: number) => number; + endAngle(angle: number): Chord; + endAngle(angle: (d: Node, i: number) => number): Chord; + } + + export function diagonal(): Diagonal, diagonal.Node>; + export function diagonal(): Diagonal, Node>; + export function diagonal(): Diagonal; + + module diagonal { + interface Link { + source: Node; + target: Node; + } + + interface Node { + x: number; + y: number; + } + } + + interface Diagonal { + (d: Link, i: number): string; + + source(): (d: Link, i: number) => Node; + source(source: Node): Diagonal; + source(source: (d: Link, i: number) => Node): Diagonal; + + target(): (d: Link, i: number) => Node; + target(target: Node): Diagonal; + target(target: (d: Link, i: number) => Node): Diagonal; + + projection(): (d: Node, i: number) => [number, number]; + projection(projection: (d: Node, i: number) => [number, number]): Diagonal; + } + + module diagonal { + export function radial(): Radial, Node>; + export function radial(): Radial, Node>; + export function radial(): Radial; + + interface Radial { + (d: Link, i: number): string; + + source(): (d: Link, i: number) => Node; + source(source: Node): Radial; + source(source: (d: Link, i: number) => Node): Radial; + + target(): (d: Link, i: number) => Node; + target(target: Node): Radial; + target(target: (d: Link, i: number) => Node): Radial; + + projection(): (d: Node, i: number) => [number, number]; + projection(projection: (d: Node, i: number) => [number, number]): Radial; + } + } + + export function axis(): Axis; + + interface Axis { + (selection: Selection): void; + (selection: Transition): void; + + scale(): any; + scale(scale: any): Axis; + + orient(): string; + orient(orientation: string): Axis; + + ticks(): any[]; + ticks(...args: any[]): Axis; + + tickValues(): any[]; + tickValues(values: any[]): Axis; + + tickSize(): number; + tickSize(size: number): Axis; + tickSize(inner: number, outer: number): Axis; + + innerTickSize(): number; + innerTickSize(size: number): Axis; + + outerTickSize(): number; + outerTickSize(size: number): Axis; + + tickPadding(): number; + tickPadding(padding: number): Axis; + + tickFormat(): (t: any) => string; + tickFormat(format: (t: any) => string): Axis; + } + + export function brush(): Brush; + export function brush(): Brush; + + module brush { + interface Scale { + domain(): number[]; + domain(domain: number[]): Scale; + + range(): number[]; + range(range: number[]): Scale; + + invert?(y: number): number; + } + } + + interface Brush { + (selection: Selection): void; + (selection: Transition): void; + + event(selection: Selection): void; + event(selection: Transition): void; + + x(): brush.Scale; + x(x: brush.Scale): Brush; + + y(): brush.Scale; + y(y: brush.Scale): Brush; + + extent(): [number, number] | [[number, number], [number, number]]; + extent(extent: [number, number] | [[number, number], [number, number]]): Brush; + + clamp(): boolean | [boolean, boolean]; + clamp(clamp: boolean | [boolean, boolean]): Brush; + + clear(): void; + + empty(): boolean; + + on(type: 'brushstart'): (datum: T, index: number) => void; + on(type: 'brush'): (datum: T, index: number) => void; + on(type: 'brushend'): (datum: T, index: number) => void; + on(type: string): (datum: T, index: number) => void; + + on(type: 'brushstart', listener: (datum: T, index: number) => void): Brush; + on(type: 'brush', listener: (datum: T, index: number) => void): Brush; + on(type: 'brushend', listener: (datum: T, index: number) => void): Brush; + on(type: string, listener: (datum: T, index: number) => void): Brush; + } + } + + export function xhr(url: string, mimeType?: string, callback?: (err: any, data: any) => void): Xhr; + export function xhr(url: string, callback: (err: any, data: any) => void): Xhr; + + interface Xhr { + header(name: string): string; + header(name: string, value: string): Xhr; + + mimeType(): string; + mimeType(type: string): Xhr; + + responseType(): string; + responseType(type: string): Xhr; + + response(): (request: XMLHttpRequest) => any; + response(value: (request: XMLHttpRequest) => any): Xhr; + + get(callback?: (err: any, data: any) => void): Xhr; + + post(data?: any, callback?: (err: any, data: any) => void): Xhr; + post(callback: (err: any, data: any) => void): Xhr; + + send(method: string, data?: any, callback?: (err: any, data: any) => void): Xhr; + send(method: string, callback: (err: any, data: any) => void): Xhr; + + abort(): Xhr; + + on(type: "beforesend"): (request: XMLHttpRequest) => void; + on(type: "progress"): (request: XMLHttpRequest) => void; + on(type: "load"): (response: any) => void; + on(type: "error"): (err: any) => void; + on(type: string): (...args: any[]) => void; + + on(type: "beforesend", listener: (request: XMLHttpRequest) => void): Xhr; + on(type: "progress", listener: (request: XMLHttpRequest) => void): Xhr; + on(type: "load", listener: (response: any) => void): Xhr; + on(type: "error", listener: (err: any) => void): Xhr; + on(type: string, listener: (...args: any[]) => void): Xhr; + } + + export function text(url: string, mimeType?: string, callback?: (err: any, data: string) => void): Xhr; + export function text(url: string, callback: (err: any, data: string) => void): Xhr; + + export function json(url: string, callback?: (err: any, data: any) => void): Xhr; + + export function xml(url: string, mimeType?: string, callback?: (err: any, data: any) => void): Xhr; + export function xml(url: string, callback: (err: any, data: any) => void): Xhr; + + export function html(url: string, callback?: (err: any, data: DocumentFragment) => void): Xhr; + + export var csv: Dsv; + export var tsv: Dsv; + export function dsv(delimiter: string, mimeType: string): Dsv; + + interface Dsv { + (url: string, callback: (rows: { [key: string]: string }[]) => void): DsvXhr<{ [key: string]: string }>; + (url: string, callback: (error: any, rows: { [key: string]: string }[]) => void): DsvXhr<{ [key: string]: string }>; + (url: string): DsvXhr<{ [key: string]: string }>; + (url: string, accessor: (row: { [key: string]: string }) => T, callback: (rows: T[]) => void): DsvXhr; + (url: string, accessor: (row: { [key: string]: string }) => T, callback: (error: any, rows: T[]) => void): DsvXhr; + (url: string, accessor: (row: { [key: string]: string }) => T): DsvXhr; + + parse(string: string): { [key: string]: string }[]; + parse(string: string, accessor: (row: { [key: string]: string }, index: number) => T): T[]; + + parseRows(string: string): string[][]; + parseRows(string: string, accessor: (row: string[], index: number) => T): T[]; + + format(rows: Object[]): string; + + formatRows(rows: string[][]): string; + } + + interface DsvXhr extends Xhr { + row(): (row: { [key: string]: string }) => T; + row(accessor: (row: { [key: string]: string }) => U): DsvXhr; + + header(name: string): string; + header(name: string, value: string): DsvXhr; + + mimeType(): string; + mimeType(type: string): DsvXhr; + + responseType(): string; + responseType(type: string): DsvXhr; + + response(): (request: XMLHttpRequest) => any; + response(value: (request: XMLHttpRequest) => any): DsvXhr; + + get(callback?: (err: any, data: T) => void): DsvXhr; + post(data?: any, callback?: (err: any, data: T) => void): DsvXhr; + post(callback: (err: any, data: T) => void): DsvXhr; + + send(method: string, data?: any, callback?: (err: any, data: T) => void): DsvXhr; + send(method: string, callback: (err: any, data: T) => void): DsvXhr; + + abort(): DsvXhr; + + on(type: "beforesend"): (request: XMLHttpRequest) => void; + on(type: "progress"): (request: XMLHttpRequest) => void; + on(type: "load"): (response: T) => void; + on(type: "error"): (err: any) => void; + on(type: string): (...args: any[]) => void; + + on(type: "beforesend", listener: (request: XMLHttpRequest) => void): DsvXhr; + on(type: "progress", listener: (request: XMLHttpRequest) => void): DsvXhr; + on(type: "load", listener: (response: T) => void): DsvXhr; + on(type: "error", listener: (err: any) => void): DsvXhr; + on(type: string, listener: (...args: any[]) => void): DsvXhr; + } + + export function locale(definition: LocaleDefinition): Locale; + + interface LocaleDefinition { + decimal: string; + thousands: string; + grouping: number[]; + currency: [string, string]; + dateTime: string; + date: string; + time: string; + periods: [string, string]; + days: [string, string, string, string, string, string, string]; + shortDays: [string, string, string, string, string, string, string]; + months: [string, string, string, string, string, string, string, string, string, string, string, string]; + shortMonths: [string, string, string, string, string, string, string, string, string, string, string, string]; + } + + interface Locale { + numberFormat(specifier: string): (n: number) => string; + timeFormat: { + (specifier: string): time.Format; + utc(specifier: string): time.Format; + } + } + + module layout { + export function bundle(): Bundle; + export function bundle(): Bundle + + module bundle { + interface Node { + parent: Node; + } + + interface Link { + source: T; + target: T; + } + } + + interface Bundle { + (links: bundle.Link[]): T[][]; + } + + export function chord(): Chord; + + module chord { + interface Link { + source: Node; + target: Node; + } + + interface Node { + index: number; + subindex: number; + startAngle: number; + endAngle: number; + value: number; + } + + interface Group { + index: number; + startAngle: number; + endAngle: number; + value: number; + } + } + + interface Chord { + matrix(): number[][]; + matrix(matrix: number[][]): Chord; + + padding(): number; + padding(padding: number): Chord; + + sortGroups(): (a: number, b: number) => number; + sortGroups(comparator: (a: number, b: number) => number): Chord; + + sortSubgroups(): (a: number, b: number) => number; + sortSubgroups(comparator: (a: number, b: number) => number): Chord; + + sortChords(): (a: number, b: number) => number; + sortChords(comparator: (a: number, b: number) => number): Chord; + + chords(): chord.Link[]; + groups(): chord.Group[]; + } + + export function cluster(): Cluster; + export function cluster(): Cluster; + + module cluster { + interface Result { + parent?: Result; + children?: Result[]; + depth?: number; + x?: number; + y?: number; + } + + interface Link { + source: T; + target: T; + } + } + + interface Cluster { + (root: T): T[]; + + nodes(root: T): T[]; + + links(nodes: T[]): cluster.Link; + + children(): (node: T) => T[]; + children(accessor: (node: T) => T[]): Cluster; + + sort(): (a: T, b: T) => number; + sort(comparator: (a: T, b: T) => number): Cluster; + + separation(): (a: T, b: T) => number; + separation(separation: (a: T, b: T) => number): Cluster; + + size(): [number, number]; + size(size: [number, number]): Cluster; + + nodeSize(): [number, number]; + nodeSize(nodeSize: [number, number]): Cluster; + + value(): (a: T) => number; + value(value: (a: T) => number): Cluster; + } + + export function force(): Force, force.Node>; + export function force(): Force, Node>; + export function force, Node extends force.Node>(): Force; + + module force { + interface Link { + source: T; + target: T; + } + + interface Node { + index?: number; + x?: number; + y?: number; + px?: number; + py?: number; + fixed?: boolean; + weight?: number; + } + + interface Event { + type: string; + alpha: number; + } + } + + interface Force, Node extends force.Node> { + size(): [number, number]; + size(size: [number, number]): Force; + + linkDistance(): number | ((link: Link, index: number) => number); + linkDistance(distance: number): Force; + linkDistance(distance: (link: Link, index: number) => number): Force; + + linkStrength(): number | ((link: Link, index: number) => number); + linkStrength(strength: number): Force; + linkStrength(strength: (link: Link, index: number) => number): Force; + + friction(): number; + friction(friction: number): Force; + + charge(): number | ((node: Node, index: number) => number); + charge(charge: number): Force; + charge(charge: (node: Node, index: number) => number): Force; + + chargeDistance(): number; + chargeDistance(distance: number): Force; + + theta(): number; + theta(theta: number): Force; + + gravity(): number; + gravity(gravity: number): Force; + + nodes(): Node[]; + nodes(nodes: Node[]): Force; + + links(): Link[]; + links(links: { source: number; target: number }[]): Force; + links(links: Link[]): Force; + + start(): Force; + + alpha(): number; + alpha(value: number): Force; + + resume(): Force; + + stop(): Force; + + on(type: string): (event: force.Event) => void; + on(type: string, listener: (event: force.Event) => void): Force; + + drag(): behavior.Drag; + drag(selection: Selection): void; + } + + export function hierarchy(): Hierarchy; + export function hierarchy(): Hierarchy; + + module hierarchy { + interface Result { + parent?: Result; + children?: Result[]; + value?: number; + depth?: number; + } + } + + interface Hierarchy { + (root: T): T[]; + + children(): (node: T) => T[]; + children(accessor: (node: T) => T[]): Hierarchy; + + sort(): (a: T, b: T) => number; + sort(comparator: (a: T, b: T) => number): Hierarchy; + + value(): (node: T) => number; + value(accessor: (node: T) => number): Hierarchy; + + revalue(root: T): T[]; + } + + export function histogram(): Histogram; + export function histogram(): Histogram; + + module histogram { + interface Bin extends Array { + x: number; + dx: number; + y: number; + } + } + + interface Histogram { + (values: T[], index?: number): histogram.Bin[]; + + value(): (datum: T, index: number) => number; + value(value: (datum: T, index: number) => number): Histogram; + + range(): (values: T[], index: number) => [number, number]; + range(range: (values: T[], index: number) => [number, number]): Histogram; + + bins(): (range: [number, number], values: T[], index: number) => number[]; + bins(count: number): Histogram; + bins(thresholds: number[]): Histogram; + bins(func: (range: [number, number], values: T[], index: number) => number[]): Histogram; + + frequency(): boolean; + frequency(frequency: boolean): Histogram; + } + + export function pack(): Pack; + export function pack(): Pack; + + module pack { + interface Node { + parent?: Node; + children?: Node[]; + value?: number; + depth?: number; + x?: number; + y?: number; + r?: number; + } + + interface Link { + source: Node; + target: Node; + } + } + + interface Pack { + (root: T): T[]; + + nodes(root: T): T[]; + + links(nodes: T[]): pack.Link[]; + + children(): (node: T, depth: number) => T[]; + children(children: (node: T, depth: number) => T[]): Pack; + + sort(): (a: T, b: T) => number; + sort(comparator: (a: T, b: T) => number): Pack; + + value(): (node: T) => number; + value(value: (node: T) => number): Pack; + + size(): [number, number]; + size(size: [number, number]): Pack; + + radius(): number | ((node: T) => number); + radius(radius: number): Pack; + radius(radius: (node: T) => number): Pack; + + padding(): number; + padding(padding: number): Pack; + } + + export function pie(): Pie; + export function pie(): Pie; + + module pie { + interface Arc { + value: number; + startAngle: number; + endAngle: number; + padAngle: number; + data: T; + } + } + + interface Pie { + (data: T[], index?: number): pie.Arc[]; + + value(): (datum: T, index: number) => number; + value(accessor: (datum: T, index: number) => number): Pie; + + sort(): (a: T, b: T) => number; + sort(comparator: (a: T, b: T) => number): Pie; + + startAngle(): number | ((data: T[], index: number) => number); + startAngle(angle: number): Pie; + startAngle(angle: (data: T[], index: number) => number): Pie; + + endAngle(): number | ((data: T[], index: number) => number); + endAngle(angle: number): Pie; + endAngle(angle: (data: T[], index: number) => number): Pie; + + padAngle(): number | ((data: T[], index: number) => number); + padAngle(angle: number): Pie; + padAngle(angle: (data: T[], index: number) => number): Pie; + } + + export function stack(): Stack; + export function stack(): Stack; + export function stack(): Stack; + module stack { + interface Value { + x: number; + y: number; + y0?: number; + } + } + + interface Stack { + (layers: Series[], index?: number): Series[]; + + values(): (layer: Series, index: number) => Value[]; + values(accessor: (layer: Series, index: number) => Value[]): Stack; + + offset(): (data: Array<[number, number]>) => number[]; + offset(offset: "silhouette"): Stack; + offset(offset: "wiggle"): Stack; + offset(offset: "expand"): Stack; + offset(offset: "zero"): Stack; + offset(offset: string): Stack; + offset(offset: (data: Array<[number, number]>) => number[]): Stack; + + order(): (data: Array<[number, number]>) => number[]; + order(order: "inside-out"): Stack; + order(order: "reverse"): Stack; + order(order: "default"): Stack; + order(order: string): Stack; + order(order: (data: Array<[number, number]>) => number[]): Stack; + + x(): (value: Value, index: number) => number; + x(accessor: (value: Value, index: number) => number): Stack; + + y(): (value: Value, index: number) => number; + y(accesor: (value: Value, index: number) => number): Stack; + + out(): (value: Value, y0: number, y: number) => void; + out(setter: (value: Value, y0: number, y: number) => void): Stack; + } + + export function tree(): Tree; + export function tree(): Tree; + + module tree { + interface Link { + source: T; + target: T; + } + + interface Node { + parent?: Node; + children?: Node[]; + depth?: number; + x?: number; + y?: number; + } + } + + interface Tree { + (root: T, index?: number): T[]; + + nodes(root: T, index?: number): T[]; + + links(nodes: T[]): tree.Link[]; + + children(): (datum: T, index: number) => T[]; + children(children: (datum: T, index: number) => T[]): Tree; + + separation(): (a: T, b: T) => number; + separation(separation: (a: T, b: T) => number): Tree; + + size(): [number, number]; + size(size: [number, number]): Tree; + + nodeSize(): [number, number]; + nodeSize(size: [number, number]): Tree; + + sort(): (a: T, b: T) => number; + sort(comparator: (a: T, b: T) => number): Tree; + + value(): (datum: T, index: number) => number; + value(value: (datum: T, index: number) => number): Tree; + } + + export function treemap(): Treemap; + export function treemap(): Treemap; + + module treemap { + interface Node { + parent?: Node; + children?: Node[]; + value?: number; + depth?: number; + x?: number; + y?: number; + dx?: number; + dy?: number; + } + + interface Link { + source: T; + target: T; + } + + type Padding = number | [number, number, number, number]; + } + + interface Treemap { + (root: T, index?: number): T[]; + + nodes(root: T, index?: number): T[]; + + links(nodes: T[]): treemap.Link[]; + + children(): (node: T, depth: number) => T[]; + children(children: (node: T, depth: number) => T[]): Treemap; + + sort(): (a: T, b: T) => number; + sort(comparator: (a: T, b: T) => number): Treemap; + + value(): (node: T, index: number) => number; + value(value: (node: T, index: number) => number): Treemap; + + size(): [number, number]; + size(size: [number, number]): Treemap; + + padding(): (node: T, depth: number) => treemap.Padding; + padding(padding: treemap.Padding): Treemap; + padding(padding: (node: T, depth: number) => treemap.Padding): Treemap; + + round(): boolean; + round(round: boolean): Treemap; + + sticky(): boolean; + sticky(sticky: boolean): boolean; + + mode(): string; + mode(mode: "squarify"): Treemap; + mode(mode: "slice"): Treemap; + mode(mode: "dice"): Treemap; + mode(mode: "slice-dice"): Treemap; + mode(mode: string): Treemap; + + ratio(): number; + ratio(ratio: number): Treemap; + } + } + + module geom { + export function voronoi(): Voronoi<[number, number]>; + export function voronoi(): Voronoi; + + module voronoi { + interface Link { + source: T; + target: T; + } + } + + interface Voronoi { + (data: T[]): Array<[number, number]>; + + x(): (vertex: T) => number; + x(x: (vertex: T) => number): Voronoi; + + y(): (vertex: T) => number; + y(y: (vertex: T) => number): Voronoi; + + clipExtent(): [[number, number], [number, number]]; + clipExtent(extent: [[number, number], [number, number]]): Voronoi; + + links(data: T[]): voronoi.Link[]; + + triangles(data: T[]): Array<[T, T, T]>; + } + + /** + * @deprecated use d3.geom.voronoi().triangles() instead + */ + export function delaunay(vertices: Array<[number, number]>): Array<[[number, number], [number, number], [number, number]]>; + + export function quadtree(): Quadtree<[number, number]>; + export function quadtree(): Quadtree; + + module quadtree { + interface Node { + nodes: [Node, Node, Node, Node]; + leaf: boolean; + point: T; + x: number; + y: number; + } + + interface Quadtree extends Node { + add(point: T): void; + visit(callback: (node: Node, x1: number, y1: number, x2: number, y2: number) => boolean | void): void; + find(point: [number, number]): T; + } + } + + interface Quadtree { + (points: T[]): quadtree.Quadtree; + + x(): (datum: T, index: number) => number; + x(x: number): Quadtree; + x(x: (datum: T, index: number) => number): Quadtree; + + y(): (datum: T, index: number) => number; + y(y: number): Quadtree; + y(y: (datum: T, index: number) => number): Quadtree; + + extent(): [[number, number], [number, number]]; + extent(extent: [[number, number], [number, number]]): Quadtree; + } + + export function hull(vertices: Array<[number, number]>): Array<[number, number]>; + export function hull(): Hull<[number, number]>; + export function hull(): Hull; + + interface Hull { + (vertices: T[]): Array<[number, number]>; + + x(): (datum: T) => number; + x(x: (datum: T) => number): Hull; + + y(): (datum: T) => number; + y(y: (datum: T) => number): Hull; + } + + export function polygon(vertices: Array<[number, number]>): Polygon; + + interface Polygon { + area(): number; + + centroid(): [number, number]; + + clip(subject: Array<[number, number]>): Array<[number, number]>; + } + } +} + +// we need this to exist +interface TouchList { } + +declare module 'd3' { + export = d3; +} diff --git a/d3/plugins/d3.superformula-tests.ts b/d3/plugins/d3.superformula-tests.ts index 3e7dd4d58..432ea214c 100644 --- a/d3/plugins/d3.superformula-tests.ts +++ b/d3/plugins/d3.superformula-tests.ts @@ -12,7 +12,7 @@ function superformula() { .attr("width", 960) .attr("height", 500); - var small = d3.superformula() + var small = d3.superformula() .type(function (d) { return d; } ) .size(size); @@ -37,4 +37,4 @@ function superformula() { .attr("class", "big") .attr("transform", "translate(450,250)") .attr("d", big); -} \ No newline at end of file +} diff --git a/d3/plugins/d3.superformula.d.ts b/d3/plugins/d3.superformula.d.ts index 6f5c59b07..d9252a45d 100644 --- a/d3/plugins/d3.superformula.d.ts +++ b/d3/plugins/d3.superformula.d.ts @@ -1,38 +1,37 @@ /// +declare module d3 { + export function superformula(): Superformula; -declare module D3 { - interface SuperformulaPath - { - superformulaPath(params: number[], n: number, diameter: number): Superformula; + module superformula { + interface Type { + m: number; + n1: number; + n2: number; + n3: number; + a: number; + b: number; + } } + interface Superformula { + (datum: T, index: number): string; - interface SuperformulaType - { - (any: any): any;//hans - m: number; - n1: number; - n2: number; - n3: number; - a: number; - b: number; + type(): (datum: T, index: number) => string; + type(type: string): Superformula; + type(type: (datum: T, index: number) => string): Superformula; + + size(): (datum: T, index: number) => number; + size(size: number): Superformula; + size(size: (datum: T, index: number) => number): Superformula; + + segments(): (datum: T, index: number) => number; + segments(segments: number): Superformula; + segments(segments: (datum: T, index: number) => number): Superformula; + + param(name: string): number; + param(name: string, value: number): Superformula; } - interface Superformula - { - (): any; - type(any: any): any; - param(name: string, value: number): Superformula; - size(x: number): Superformula; - segments(x: number): Superformula; - } - - - interface Base extends Selectors - { - superformula: Superformula; - superformulaPath: SuperformulaPath; - superformulaTypes: SuperformulaType[]; - } + export var superformulaTypes: string[]; }