diff --git a/d3-box/d3-box-tests.ts b/d3-box/d3-box-tests.ts new file mode 100644 index 0000000000..191962ff13 --- /dev/null +++ b/d3-box/d3-box-tests.ts @@ -0,0 +1,26 @@ +/// +/// + +// Inspired by http://bl.ocks.org/mbostock/4061502 + +function iqr(k: number) { + return function(d: any) { + var q1 = d.quartiles[0], + q3 = d.quartiles[2], + iqr = (q3 - q1) * k; + let i = -1, + j = d.length; + while (d[++i] < q1 - iqr); + while (d[--j] > q3 + iqr); + return [i, j]; + }; +} + +var chart = d3.box() + .whiskers(iqr(1.5)) + .width(100) + .height(100); + +chart.domain([1, 30]); + +d3.selectAll("sth.").call(chart.duration(1000)); diff --git a/d3-box/d3-box.d.ts b/d3-box/d3-box.d.ts new file mode 100644 index 0000000000..4bc837df31 --- /dev/null +++ b/d3-box/d3-box.d.ts @@ -0,0 +1,31 @@ +// Type definitions for d3-box +// Project: https://github.com/JacksonGariety/d3-box +// Definitions by: Linkun Chen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare namespace d3 { + export function box(): Box; + + interface Box { + (sel: d3.Selection): void; + width(): number; + width(x: number): Box; + height(): number; + height(x: number): Box; + tickFormat(): (n: number) => string; + tickFormat(fun: (n: number) => string): Box; + duration(): number; + duration(x: number): Box; + domain(): () => number[]; + domain(x: number[]): Box; + value(): (d: any) => number; + value(x: (d: any) => number): Box; + whiskers(): (d: any[], i?: number) => number[]; + whiskers(x: (d: any[], i?: number) => number[]): Box; + quartiles(): (d: any[]) => number[]; + quantiles(x: (d: any[]) => number[]): Box; + } +} +