本文整理匯總了TypeScript中d3.quantile函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript quantile函數的具體用法?TypeScript quantile怎麽用?TypeScript quantile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了quantile函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getQuartiles
getQuartiles(arr) {
arr.sort((el1, el2) => el1 - el2);
let quartiles = [];
for (let i = 0; i <= 1; i += 0.25) {
quartiles.push(d3.quantile(arr, i));
}
return quartiles;
}
示例2: computeDomain
export function computeDomain(values: number[], ignoreOutliers: boolean) {
// Don't include infinities and NaNs in the domain computation.
values = values.filter(z => isFinite(z));
if (values.length === 0) {
return [-0.1, 1.1];
}
let a: number;
let b: number;
if (ignoreOutliers) {
let sorted = _.sortBy(values);
a = d3.quantile(sorted, 0.05);
b = d3.quantile(sorted, 0.95);
} else {
a = d3.min(values);
b = d3.max(values);
}
let padding: number;
let span = b - a;
if (span === 0) {
// If b===a, we would create an empty range. We instead select the range
// [0, 2*a] if a > 0, or [-2*a, 0] if a < 0, plus a little bit of
// extra padding on the top and bottom of the plot.
padding = Math.abs(a) * 1.1 + 1.1;
} else {
padding = span * 0.2;
}
let lower: number;
if (a >= 0 && a < span) {
// We include the intercept (y = 0) if doing so less than doubles the span
// of the y-axis. (We actually select a lower bound that's slightly less
// than 0 so that 0.00 will clearly be written on the lower edge of the
// chart. The label on the lowest tick is often filtered out.)
lower = -0.1 * b;
} else {
lower = a - padding;
}
let domain = [lower, b + padding];
domain = d3.scaleLinear().domain(domain).nice().domain();
return domain;
}
示例3: expect
summaries.forEach((summary: ScoreFunctionDataSummary, i: number) => {
expect(summary.element).to.equal(elements[i]);
let scores = _.map(scoreFunctions, (scoreFunction) => {
return scoreFunction.getScore(summary.element);
});
scores.sort((a: number, b: number) => {
if (a < b)
return -1;
else
return 1;
});
expect(summary.min).to.equal(_.min(scores));
expect(summary.max).to.equal(_.max(scores));
expect(summary.median).to.equal(d3.median(scores));
expect(summary.firstQuartile).to.equal(d3.quantile(scores, 0.25));
expect(summary.thirdQuartile).to.equal(d3.quantile(scores, 0.75));
});