finish d3-box

This commit is contained in:
lkchen-x1c
2016-10-24 01:39:55 -04:00
parent 34a477e0f0
commit 5ec5db5e07
2 changed files with 27 additions and 3 deletions

View File

@@ -1,2 +1,26 @@
/// <reference path="../d3/d3.d.ts" />
/// <reference path="d3-box.d.ts" />
// 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));

6
d3-box/d3-box.d.ts vendored
View File

@@ -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 <https://github.com/lk-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;
}