From 09c62bd0897c4dabf3dfa79c71dafcd02708d899 Mon Sep 17 00:00:00 2001 From: denisname Date: Mon, 15 Oct 2018 20:20:09 +0200 Subject: [PATCH] Add deprecated ThresholdArrayGenerator (#29616) Also improve permute typing and doing some spell checking. --- types/d3-array/d3-array-tests.ts | 8 ++++++-- types/d3-array/index.d.ts | 23 ++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/types/d3-array/d3-array-tests.ts b/types/d3-array/d3-array-tests.ts index 1c6cbcaea8..11f208f869 100644 --- a/types/d3-array/d3-array-tests.ts +++ b/types/d3-array/d3-array-tests.ts @@ -596,6 +596,7 @@ numbersArray = d3Array.pairs(readonlyMergedArray, (a, b) => { // getting a permutation of array elements mergedArray = d3Array.permute(mergedArray, [1, 0, 2, 5, 3, 4, 6]); mergedArray = d3Array.permute(readonlyMergedArray, [1, 0, 2, 5, 3, 4, 6]); +mergedArray = d3Array.permute(readonlyMergedArray, nums); // Getting an ordered array with object properties @@ -606,7 +607,10 @@ const testObject = { more: [10, 30, 40] }; -const x: Array = d3Array.permute(testObject, ['name', 'val', 'when', 'more']); +const p1: Array = d3Array.permute(testObject, ['name', 'val', 'when', 'more']); +const p2: Array = d3Array.permute(testObject, ['when', 'more']); +// $ExpectError +const p3 = d3Array.permute(testObject, ['when', 'unknown']); // range() --------------------------------------------------------------------- @@ -913,7 +917,7 @@ mixedObject = binMixedObject_DateOrUndefined[0]; dateOrUndefined = binMixedObject_DateOrUndefined.x0; dateOrUndefined = binMixedObject_DateOrUndefined.x1; -// Histogram Tresholds ========================================================= +// Histogram Thresholds ======================================================== numbersArray = [-1, 0, 1, 1, 3, 20, 234]; typedArray = new Uint8Array(numbersArray); diff --git a/types/d3-array/index.d.ts b/types/d3-array/index.d.ts index 45bd86a704..391e2786be 100644 --- a/types/d3-array/index.d.ts +++ b/types/d3-array/index.d.ts @@ -228,19 +228,23 @@ export function pairs(array: ArrayLike): Array<[T, T]>; * Returns the empty array if the input array has fewer than two elements. * * @param array Array of input elements - * @param reducer A reducer function taking as input to adjecent elements of the input array and returning a reduced value. + * @param reducer A reducer function taking as input to adjacent elements of the input array and returning a reduced value. */ export function pairs(array: ArrayLike, reducer: (a: T, b: T) => U): U[]; /** - * Given the specified array, return an array corresponding to the list of indices in 'keys'. + * Returns a permutation of the specified array using the specified array of indexes. + * The returned array contains the corresponding element in array for each index in indexes, in order. + * For example, `permute(["a", "b", "c"], [1, 2, 0]) // ["b", "c", "a"]` */ export function permute(array: { [key: number]: T }, keys: ArrayLike): T[]; /** - * Given the specified object, return an array corresponding to the list of property names in 'keys'. + * Extract the values from an object into an array with a stable order. For example: + * `var object = {yield: 27, year: 1931, site: "University Farm"};` + * `d3.permute(object, ["site", "yield"]); // ["University Farm", 27]` */ -export function permute(object: { [key: string]: T }, keys: ArrayLike): T[]; +export function permute(object: T, keys: ArrayLike): Array; /** * Generates a 0-based numeric sequence. The output range does not include 'stop'. @@ -347,6 +351,11 @@ export type ThresholdNumberArrayGenerator = export type ThresholdDateArrayGenerator = (values: ArrayLike, min: Date, max: Date) => Value[]; +/** + * @deprecated Use ThresholdNumberArrayGenerator or ThresholdDateArrayGenerator. + */ +export type ThresholdArrayGenerator = ThresholdNumberArrayGenerator; + /** * @deprecated Use `HistogramGeneratorNumber` for `number` values and `HistogramGeneratorDate for `Date` values. */ @@ -403,7 +412,7 @@ export interface HistogramGeneratorDate e * and the last bin.x1 is always equal to the maximum domain value. * * @param thresholds A function which accepts as arguments the array of materialized values, and - * optionally the domain minimum and maximum. The function calcutates and returns the array of values to be used as + * optionally the domain minimum and maximum. The function calculates and returns the array of values to be used as * thresholds in determining the bins. */ thresholds(thresholds: ThresholdDateArrayGenerator): this; @@ -434,7 +443,7 @@ export interface HistogramGeneratorNumber): this; @@ -456,7 +465,7 @@ export interface HistogramGeneratorNumber): this;