From b6746d73a2ddf103c6825449ee2b0953f716d994 Mon Sep 17 00:00:00 2001 From: Tom Wanzek Date: Tue, 25 Apr 2017 12:45:20 -0400 Subject: [PATCH] D3 Update to 4.8.0 (d3-array 1.2 [Feature/Fix] and d3-format 1.2 [Feature]) (#15904) * Update d3-format to v1.2 * [Feature] Adds support for optional "percent" suffix in locale definition. * Added tslint.json file * [d3-array] Update to version 1.2 * [Feature]: Add `tickIncrement(...)` * [Fix]: Fix incorrect return type of tickStep(...). The correct return type is `number` instead of `number[]` * [Chore]: Updated related comments * [d3] Update minor version to 4.8 * Fix d3-format related linting errors. --- types/d3-array/d3-array-tests.ts | 6 +++- types/d3-array/index.d.ts | 54 +++++++++++++++++++++++++++--- types/d3-format/d3-format-tests.ts | 14 ++++++-- types/d3-format/index.d.ts | 12 ++++--- types/d3-format/tslint.json | 3 ++ types/d3/index.d.ts | 2 +- 6 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 types/d3-format/tslint.json diff --git a/types/d3-array/d3-array-tests.ts b/types/d3-array/d3-array-tests.ts index bb713192e8..b95da5774f 100644 --- a/types/d3-array/d3-array-tests.ts +++ b/types/d3-array/d3-array-tests.ts @@ -389,9 +389,13 @@ mergedArray = d3Array.shuffle(mergedArray, 1, 3); numbersArray = d3Array.ticks(1, 10, 5); +// tickIncrement() ------------------------------------------------------------------ + +let numDiff: number = d3Array.tickIncrement(1, 10, 5); + // tickStep() ------------------------------------------------------------------ -numbersArray = d3Array.tickStep(1, 10, 5); +numDiff = d3Array.tickStep(1, 10, 5); // transpose() ----------------------------------------------------------------- diff --git a/types/d3-array/index.d.ts b/types/d3-array/index.d.ts index 74ecbb0e36..aee2ef38c7 100644 --- a/types/d3-array/index.d.ts +++ b/types/d3-array/index.d.ts @@ -1,9 +1,9 @@ -// Type definitions for D3JS d3-array module 1.1 +// Type definitions for D3JS d3-array module 1.2 // Project: https://github.com/d3/d3-array // Definitions by: Alex Ford , Boris Yankov , Tom Wanzek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last module patch version validated against: 1.1.0 +// Last module patch version validated against: 1.2.0 // -------------------------------------------------------------------------- // Shared Types and Interfaces @@ -246,14 +246,45 @@ export function shuffle(array: T[], lo?: number, hi?: number): T[]; /** * Generate an array of approximately count + 1 uniformly-spaced, nicely-rounded values between start and stop (inclusive). + * Each value is a power of ten multiplied by 1, 2 or 5. See also d3.tickIncrement, d3.tickStep and linear.ticks. + * + * Ticks are inclusive in the sense that they may include the specified start and stop values if (and only if) they are exact, + * nicely-rounded values consistent with the inferred step. More formally, each returned tick t satisfies start ≤ t and t ≤ stop. + * + * @param start Start value for ticks + * @param stop Stop value for ticks + * @param count count + 1 is the approximate number of ticks to be returned by d3.ticks. */ export function ticks(start: number, stop: number, count: number): number[]; /** - * Generate an array of with the differences between adjecent ticks, had the same arguments - * been passed to ticks(start, stop, count) + * Returns the difference between adjacent tick values if the same arguments were passed to d3.ticks: + * a nicely-rounded value that is a power of ten multiplied by 1, 2 or 5. + * + * Like d3.tickStep, except requires that start is always less than or equal to step, and if the tick step for the given start, + * stop and count would be less than one, returns the negative inverse tick step instead. + * + * This method is always guaranteed to return an integer, and is used by d3.ticks to avoid guarantee that the returned tick values + * are represented as precisely as possible in IEEE 754 floating point. + * + * @param start Start value for ticks + * @param stop Stop value for ticks + * @param count count + 1 is the approximate number of ticks to be returned by d3.ticks. */ -export function tickStep(start: number, stop: number, count: number): number[]; +export function tickIncrement(start: number, stop: number, count: number): number; + +/** + * Returns the difference between adjacent tick values if the same arguments were passed to d3.ticks: + * a nicely-rounded value that is a power of ten multiplied by 1, 2 or 5. + * + * Note that due to the limited precision of IEEE 754 floating point, the returned value may not be exact decimals; + * use d3-format to format numbers for human consumption. + * + * @param start Start value for ticks + * @param stop Stop value for ticks + * @param count count + 1 is the approximate number of ticks to be returned by d3.ticks. + */ +export function tickStep(start: number, stop: number, count: number): number; /** * Transpose a matrix provided in Array of Arrays format. @@ -298,6 +329,9 @@ export interface HistogramGenerator { * Divide the domain uniformly into approximately count bins. IMPORTANT: This threshold * setting approach only works, when the materialized values are numbers! * + * Any threshold values outside the domain are ignored. The first bin.x0 is always equal to the minimum domain value, + * and the last bin.x1 is always equal to the maximum domain value. + * * @param count The desired number of uniform bins. */ thresholds(count: number): this; @@ -306,6 +340,9 @@ export interface HistogramGenerator { * Divides the domain uniformly into approximately count bins. IMPORTANT: This threshold * setting approach only works, when the materialized values are numbers! * + * Any threshold values outside the domain are ignored. The first bin.x0 is always equal to the minimum domain value, + * and the last bin.x1 is always equal to the maximum domain value. + * * @param count A function which accepts as arguments the array of materialized values, and * optionally the domain minimum and maximum. The function calcutates and returns the suggested * number of bins. @@ -313,6 +350,10 @@ export interface HistogramGenerator { thresholds(count: ThresholdCountGenerator): this; /** * Set the array of values to be used as thresholds in determining the bins. + * + * Any threshold values outside the domain are ignored. The first bin.x0 is always equal to the minimum domain value, + * and the last bin.x1 is always equal to the maximum domain value. + * * @param thresholds Array of threshold values used for binning. The elements must * be of the same type as the materialized values of the histogram. */ @@ -321,6 +362,9 @@ export interface HistogramGenerator { * Set a threshold accessor function, which returns the array of values to be used as * thresholds in determining the bins. * + * Any threshold values outside the domain are ignored. The first bin.x0 is always equal to the minimum domain value, + * 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 * thresholds in determining the bins. diff --git a/types/d3-format/d3-format-tests.ts b/types/d3-format/d3-format-tests.ts index 57a98e26c6..9c11d07c70 100644 --- a/types/d3-format/d3-format-tests.ts +++ b/types/d3-format/d3-format-tests.ts @@ -48,7 +48,6 @@ let type: 'e' | 'f' | 'g' | 'r' | 's' | '%' | 'p' | 'b' | 'o' | 'd' | 'x' | 'X' let formatString: string = specifier.toString(); - // ---------------------------------------------------------------------- // Test Precision Suggestors // ---------------------------------------------------------------------- @@ -76,13 +75,22 @@ localeDef = { grouping: [3], currency: ["", ""], numerals : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] -} +}; + +localeDef = { + decimal: "\u066b", + thousands: "\u066c", + grouping: [3], + currency: ["", ""], + percent : "\u202f%" +}; let decimal: string = localeDef.decimal; let thousands: string = localeDef.thousands; -let grouping: Array = localeDef.grouping; +let grouping: number[] = localeDef.grouping; let currency: [string, string] = localeDef.currency; let numerals: string[] | undefined = localeDef.numerals; +let percent: string | undefined = localeDef.percent; localeObj = d3Format.formatLocale(localeDef); diff --git a/types/d3-format/index.d.ts b/types/d3-format/index.d.ts index be6c2b9a99..34cf80c047 100644 --- a/types/d3-format/index.d.ts +++ b/types/d3-format/index.d.ts @@ -1,9 +1,9 @@ -// Type definitions for D3JS d3-format module 1.1 +// Type definitions for D3JS d3-format module 1.2 // Project: https://github.com/d3/d3-format/ // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last module patch version validated against: 1.1.0 +// Last module patch version validated against: 1.2.0 /** * Specification of locale to use when creating a new FormatLocaleObject @@ -27,16 +27,19 @@ export interface FormatLocaleDefinition { */ currency: [string, string]; /** - * An array of ten strings to replace the numerals 0-9. + * An optional array of ten strings to replace the numerals 0-9. */ numerals?: string[]; + /** + * An optional symbol to replace the `percent` suffix; the percent suffix (defaults to "%") + */ + percent?: string; } /** * A Format Locale Object */ export interface FormatLocaleObject { - /** * Returns a new format function for the given string specifier. The returned function * takes a number as the only argument, and returns a string representing the formatted number. @@ -219,7 +222,6 @@ export function precisionFixed(step: number): number; */ export function precisionPrefix(step: number, value: number): number; - /** * Returns a suggested decimal precision for format types that round to significant digits * given the specified numeric step and max values. diff --git a/types/d3-format/tslint.json b/types/d3-format/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/d3-format/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/d3/index.d.ts b/types/d3/index.d.ts index 525c4dbfd3..29d4a7c861 100644 --- a/types/d3/index.d.ts +++ b/types/d3/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for D3JS d3 standard bundle 4.7 +// Type definitions for D3JS d3 standard bundle 4.8 // Project: https://github.com/d3/d3 // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped