From 471dae5d9e08998f85239a632e67cb5971d1cd56 Mon Sep 17 00:00:00 2001 From: lkchen-x1c Date: Sun, 23 Oct 2016 23:36:55 -0400 Subject: [PATCH 1/4] add init files --- d3-box/d3-box-tests.ts | 2 ++ d3-box/d3-box.d.ts | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 d3-box/d3-box-tests.ts create mode 100644 d3-box/d3-box.d.ts diff --git a/d3-box/d3-box-tests.ts b/d3-box/d3-box-tests.ts new file mode 100644 index 0000000000..9c92e1b886 --- /dev/null +++ b/d3-box/d3-box-tests.ts @@ -0,0 +1,2 @@ +/// +/// diff --git a/d3-box/d3-box.d.ts b/d3-box/d3-box.d.ts new file mode 100644 index 0000000000..0db7316cb3 --- /dev/null +++ b/d3-box/d3-box.d.ts @@ -0,0 +1,6 @@ +// Type definitions for d3-slider +// Project: https://github.com/JacksonGariety/d3-box +// Definitions by: Linkun Chen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// From 34a477e0f0ac0376d77c2936c0b7644251269647 Mon Sep 17 00:00:00 2001 From: lkchen-x1c Date: Mon, 24 Oct 2016 01:16:44 -0400 Subject: [PATCH 2/4] finish .d.ts --- d3-box/d3-box.d.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/d3-box/d3-box.d.ts b/d3-box/d3-box.d.ts index 0db7316cb3..4b702123d8 100644 --- a/d3-box/d3-box.d.ts +++ b/d3-box/d3-box.d.ts @@ -4,3 +4,28 @@ // 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[]) => number[]; + whiskers(x: (d: any[]) => number[]): Box; + quartiles(): (d: any[]) => number[]; + quantiles(x: (d: any[]) => number[]): Box; + } +} + From 5ec5db5e07af91df8a3e869abda13e286de26a81 Mon Sep 17 00:00:00 2001 From: lkchen-x1c Date: Mon, 24 Oct 2016 01:39:55 -0400 Subject: [PATCH 3/4] finish d3-box --- d3-box/d3-box-tests.ts | 24 ++++++++++++++++++++++++ d3-box/d3-box.d.ts | 6 +++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/d3-box/d3-box-tests.ts b/d3-box/d3-box-tests.ts index 9c92e1b886..acbd928d6f 100644 --- a/d3-box/d3-box-tests.ts +++ b/d3-box/d3-box-tests.ts @@ -1,2 +1,26 @@ /// /// + +// Inspired by http://bl.ocks.org/mbostock/4061502 + +function iqr(k) { + return function(d) { + 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 index 4b702123d8..4bc837df31 100644 --- a/d3-box/d3-box.d.ts +++ b/d3-box/d3-box.d.ts @@ -1,4 +1,4 @@ -// Type definitions for d3-slider +// Type definitions for d3-box // Project: https://github.com/JacksonGariety/d3-box // Definitions by: Linkun Chen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -22,8 +22,8 @@ declare namespace d3 { domain(x: number[]): Box; value(): (d: any) => number; value(x: (d: any) => number): Box; - whiskers(): (d: any[]) => number[]; - whiskers(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; } From 7f0d226ee19e8bb7eb81dec34ceb4a58fb3bc8d7 Mon Sep 17 00:00:00 2001 From: lkchen-x1c Date: Mon, 24 Oct 2016 02:38:28 -0400 Subject: [PATCH 4/4] fix implicit error --- d3-box/d3-box-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/d3-box/d3-box-tests.ts b/d3-box/d3-box-tests.ts index acbd928d6f..191962ff13 100644 --- a/d3-box/d3-box-tests.ts +++ b/d3-box/d3-box-tests.ts @@ -3,8 +3,8 @@ // Inspired by http://bl.ocks.org/mbostock/4061502 -function iqr(k) { - return function(d) { +function iqr(k: number) { + return function(d: any) { var q1 = d.quartiles[0], q3 = d.quartiles[2], iqr = (q3 - q1) * k;