Skip to content

Commit

Permalink
馃 Merge PR #60427 update to d3@7.4 by @Fil
Browse files Browse the repository at this point in the history
* update to d3-shape@3.1.0
https://github.com/d3/d3-shape/releases/tag/v3.1.0

Add d3.symbolsStroke.
Add d3.symbolsFill, replacing (deprecating) d3.symbols.
Add d3.symbolAsterisk.
Add d3.symbolDiamond2.
Add d3.symbolPlus.
Add d3.symbolSquare2.
Add d3.symbolTriangle2.
Add d3.symbolX.
Add d3.link.

* update d3-array to @3.1.6

d3.rank can now take a comparator in addition to an accessor

We don't need to change anything for "d3.rank, d3.sort, d3.bisector, and d3.groupSort now require comparators to have exactly two arguments", since that's how it was already typed (even though the code was actually more lax).

* update d3-hierarchy to 3.1.2

note: I'm not sure that the path function must have 3 arguments; most of the time people will use only 1 argument

* update d3-color to @3.1.0

- add rgb.clamp and hsl.clamp
- add color.formatHex8

* versions
  • Loading branch information
Fil committed May 22, 2022
1 parent 05ca376 commit cb9d8cc
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 58 deletions.
7 changes: 7 additions & 0 deletions types/d3-array/d3-array-tests.ts
Expand Up @@ -369,6 +369,13 @@ float64Array = d3Array.rank(mixedObjectArray, accessorMixedObjectToNum);
float64Array = d3Array.rank(mixedObjectOrUndefinedArray, accessorMixedObjectToNumOrUndefined);
float64Array = d3Array.rank(readonlyMixedObjectOrUndefinedArray, accessorReadOnlyMixedObjectToNumOrUndefined);

float64Array = d3Array.rank(mixedObjectArray, (a: any, b: any) =>
a.date.valueOf() - b.date.valueOf());
float64Array = d3Array.rank(mixedObjectOrUndefinedArray, (a: any, b: any) =>
a?.date.valueOf() - b?.date.valueOf());
float64Array = d3Array.rank(readonlyMixedObjectOrUndefinedArray, (a: any, b: any) =>
a?.date.valueOf() - b?.date.valueOf());

// variance() ------------------------------------------------------------------

numOrUndefined = d3Array.variance(numbersArray);
Expand Down
15 changes: 9 additions & 6 deletions types/d3-array/index.d.ts
Expand Up @@ -6,9 +6,10 @@
// denisname <https://github.com/denisname>
// Hugues Stefanski <https://github.com/ledragon>
// Nathan Bierema <https://github.com/Methuselah96>
// Fil <https://github.com/Fil>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

// Last module patch version validated against: 3.1.0
// Last module patch version validated against: 3.1.6

// --------------------------------------------------------------------------
// Shared Types and Interfaces
Expand Down Expand Up @@ -235,21 +236,23 @@ export function quantileSorted<T>(
): number | undefined;

/**
* Returns an array with the rank of each value in the iterable, i.e. the index of the value when the iterable is sorted.
* Returns an array with the rank of each value in the iterable, i.e. the zero-based index of the value when the iterable is sorted.
* Nullish values are sorted to the end and ranked NaN.
* An optional accessor function may be specified, which is equivalent to calling array.map(accessor) before computing the ranks.
* An optional comparator or accessor function may be specified; the latter is equivalent to calling array.map(accessor) before computing the ranks.
* If comparator is not specified, it defaults to ascending.
* Ties (equivalent values) all get the same rank, defined as the first time the value is found.
*/
export function rank(iterable: Iterable<Numeric | undefined | null>): Float64Array;
/**
* Returns an array with the rank of each value in the iterable, i.e. the index of the value when the iterable is sorted.
* Returns an array with the rank of each value in the iterable, i.e. the zero-based index of the value when the iterable is sorted.
* Nullish values are sorted to the end and ranked NaN.
* An optional accessor function may be specified, which is equivalent to calling array.map(accessor) before computing the ranks.
* An optional comparator or accessor function may be specified; the latter is equivalent to calling array.map(accessor) before computing the ranks.
* If comparator is not specified, it defaults to ascending.
* Ties (equivalent values) all get the same rank, defined as the first time the value is found.
*/
export function rank<T>(
iterable: Iterable<T>,
accessor: (datum: T, index: number, array: Iterable<T>) => number | undefined | null
accessorOrComparator: ((datum: T, index: number, array: Iterable<T>) => number | undefined | null) | ((a: T, b: T) => number | undefined | null)
): Float64Array;

/**
Expand Down
7 changes: 7 additions & 0 deletions types/d3-color/d3-color-tests.ts
Expand Up @@ -36,10 +36,12 @@ cRGB = cRGB.darker(0.2);
cRGB = cRGB.copy();
cRGB = cRGB.copy({ r: 0.5 });
cRGB = cRGB.rgb();
cRGB = cRGB.clamp();
displayable = cRGB.displayable();
cString = cRGB.toString();
cString = cRGB.hex();
cString = cRGB.formatHex();
cString = cRGB.formatHex8();
cString = cRGB.formatHsl();
cString = cRGB.formatRgb();
console.log('Channels = (r : %d, g: %d, b: %d)', cRGB.r, cRGB.g, cRGB.b);
Expand All @@ -57,10 +59,12 @@ cHSL = cHSL.darker(0.2);
cHSL = cHSL.copy();
cHSL = cHSL.copy({ opacity: 0.5 });
cRGB = cHSL.rgb();
cHSL = cHSL.clamp();
displayable = cHSL.displayable();
cString = cHSL.toString();
cString = cHSL.hex();
cString = cHSL.formatHex();
cString = cHSL.formatHex8();
cString = cHSL.formatHsl();
cString = cHSL.formatRgb();
console.log('Channels = (h : %d, s: %d, l: %d)', cHSL.h, cHSL.s, cHSL.l);
Expand All @@ -86,6 +90,7 @@ displayable = cLab.displayable();
cString = cLab.toString();
cString = cLab.hex();
cString = cLab.formatHex();
cString = cLab.formatHex8();
cString = cLab.formatHsl();
cString = cLab.formatRgb();
console.log('Channels = (l : %d, a: %d, b: %d)', cLab.l, cLab.a, cLab.b);
Expand Down Expand Up @@ -115,6 +120,7 @@ displayable = cHcl.displayable();
cString = cHcl.toString();
cString = cHcl.hex();
cString = cHcl.formatHex();
cString = cHcl.formatHex8();
cString = cHcl.formatHsl();
cString = cHcl.formatRgb();
console.log('Channels = (h : %d, c: %d, l: %d)', cHcl.h, cHcl.c, cHcl.l);
Expand Down Expand Up @@ -146,6 +152,7 @@ displayable = cCubehelix.displayable();
cString = cCubehelix.toString();
cString = cCubehelix.hex();
cString = cCubehelix.formatHex();
cString = cCubehelix.formatHex8();
cString = cCubehelix.formatHsl();
cString = cCubehelix.formatRgb();
console.log('Channels = (h : %d, s: %d, l: %d)', cCubehelix.h, cCubehelix.s, cCubehelix.l);
Expand Down
20 changes: 18 additions & 2 deletions types/d3-color/index.d.ts
@@ -1,14 +1,15 @@
// Type definitions for D3JS d3-color module 3.0
// Type definitions for D3JS d3-color module 3.1
// Project: https://github.com/d3/d3-color/, https://d3js.org/d3-color
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>
// Alex Ford <https://github.com/gustavderdrache>
// Boris Yankov <https://github.com/borisyankov>
// denisname <https://github.com/denisname>
// Hugues Stefanski <https://github.com/ledragon>
// Nathan Bierema <https://github.com/Methuselah96>
// Fil <https://github.com/Fil>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

// Last module patch version validated against: 3.0.1
// Last module patch version validated against: 3.1.0

// ---------------------------------------------------------------------------
// Shared Type Definitions and Interfaces
Expand Down Expand Up @@ -85,6 +86,12 @@ export interface Color {
* For example, RGB channel values greater than 255 are clamped to 255.
*/
formatHex(): string;
/**
* Returns a hexadecimal string representing this color in RGBA space, such as #f7eaba90.
* If this color is not displayable, a suitable displayable color is returned instead.
* For example, RGB channel values greater than 255 are clamped to 255.
*/
formatHex8(): string;
/**
* Returns a string representing this color according to the CSS Color Module Level 3 specification, such as hsl(257, 50%, 80%) or hsla(257, 50%, 80%, 0.2).
* If this color is not displayable, a suitable displayable color is returned instead by clamping S and L channel values to the interval [0, 100].
Expand Down Expand Up @@ -168,6 +175,11 @@ export interface RGBColor extends Color {
* @param values If values is specified, any enumerable own properties of values are assigned to the new returned color.
*/
copy(values?: { r?: number | undefined; g?: number | undefined; b?: number | undefined; opacity?: number | undefined }): this;
/**
* Returns a new RGB color where the r, g, and b channels are clamped to the range [0, 255] and rounded to the nearest integer value,
* and the opacity is clamped to the range [0, 1].
*/
clamp(): this;
}

/**
Expand Down Expand Up @@ -249,6 +261,10 @@ export interface HSLColor extends Color {
* @param values If values is specified, any enumerable own properties of values are assigned to the new returned color.
*/
copy(values?: { h?: number | undefined; s?: number | undefined; l?: number | undefined; opacity?: number | undefined }): this;
/**
* Returns a new HSL color where the h channel is clamped to the range [0, 360), and the s, l, and opacity channels are clamped to the range [0, 1].
*/
clamp(): this;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions types/d3-hierarchy/d3-hierarchy-tests.ts
Expand Up @@ -250,6 +250,13 @@ stratificatorizer = stratificatorizer.parentId((d, i, data) => {

idStringAccessor = stratificatorizer.parentId();

// path(...)

stratificatorizer = stratificatorizer.path((d, i, data) => d.name);

let pathStringAccessor: ((d: TabularHierarchyDatum, i: number, data: TabularHierarchyDatum[]) => string) | null | undefined;
pathStringAccessor = stratificatorizer.path();

// Use Stratify Operator ------------------------------------------------

const stratifiedRootNode: d3Hierarchy.HierarchyNode<TabularHierarchyDatum> = stratificatorizer(tabularData);
Expand Down
20 changes: 18 additions & 2 deletions types/d3-hierarchy/index.d.ts
@@ -1,13 +1,14 @@
// Type definitions for D3JS d3-hierarchy module 3.0
// Type definitions for D3JS d3-hierarchy module 3.1
// Project: https://github.com/d3/d3-hierarchy/, https://d3js.org/d3-hierarchy
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>
// Alex Ford <https://github.com/gustavderdrache>
// Boris Yankov <https://github.com/borisyankov>
// denisname <https://github.com/denisname>
// Nathan Bierema <https://github.com/Methuselah96>
// Fil <https://github.com/Fil>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

// Last module patch version validated against: 3.0.1
// Last module patch version validated against: 3.1.2

// -----------------------------------------------------------------------
// Hierarchy
Expand Down Expand Up @@ -216,6 +217,21 @@ export interface StratifyOperator<Datum> {
* @param parentId The parent id accessor.
*/
parentId(parentId: (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined)): this;

/**
* Returns the current path accessor, which defaults to undefined.
*/
path(): ((d: Datum, i: number, data: Datum[]) => string) | null | undefined;
/**
* If path is specified, sets the path accessor to the given function and returns this stratify operator.
* Otherwise, returns the current path accessor, which defaults to undefined.
* If a path accessor is set, the id and parentId arguments are ignored,
* and a unix-like hierarchy is computed on the slash-delimited strings
* returned by the path accessor, imputing parent nodes and ids as necessary.
*
* @param path The path accessor.
*/
path(path: ((d: Datum, i: number, data: Datum[]) => string) | null | undefined): this;
}

/**
Expand Down
9 changes: 8 additions & 1 deletion types/d3-shape/d3-shape-tests.ts
Expand Up @@ -1384,15 +1384,22 @@ pathStringMaybe = sym.getPathString({ size: 10, type: 'circle' });

// Test pre-fab symbols ===============================================================

const symbolArray: d3Shape.SymbolType[] = d3Shape.symbols;
let symbolArray: d3Shape.SymbolType[] = d3Shape.symbolsFill;
symbolArray = d3Shape.symbolsStroke;

customSymbol = d3Shape.symbolAsterisk;
customSymbol = d3Shape.symbolCircle;
customSymbol = d3Shape.symbolCross;
customSymbol = d3Shape.symbolDiamond;
customSymbol = d3Shape.symbolDiamond2;
customSymbol = d3Shape.symbolPlus;
customSymbol = d3Shape.symbolSquare;
customSymbol = d3Shape.symbolSquare2;
customSymbol = d3Shape.symbolStar;
customSymbol = d3Shape.symbolTriangle;
customSymbol = d3Shape.symbolTriangle2;
customSymbol = d3Shape.symbolWye;
customSymbol = d3Shape.symbolX;

// -----------------------------------------------------------------------------------
// Test pointRadial
Expand Down

0 comments on commit cb9d8cc

Please sign in to comment.