From e1cd2ae0026c09c633cecf2e432ee0f927f54259 Mon Sep 17 00:00:00 2001 From: Tom Wanzek Date: Sun, 29 Jan 2017 13:39:36 -0500 Subject: [PATCH] Update d3-hierarchy 1.1/d3 4.5 * [d3-hierarchy] Add `count()` method to hierarchy node interfaces * [d3-hierarchy] Update header to reflect v1.1 minor version * [d3] Bump minor version to 4.5 --- d3-hierarchy/d3-hierarchy-tests.ts | 23 +++++++++++++++++++++ d3-hierarchy/index.d.ts | 32 ++++++++++++++++++------------ d3/index.d.ts | 2 +- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/d3-hierarchy/d3-hierarchy-tests.ts b/d3-hierarchy/d3-hierarchy-tests.ts index ce7354afe3..7079fae827 100644 --- a/d3-hierarchy/d3-hierarchy-tests.ts +++ b/d3-hierarchy/d3-hierarchy-tests.ts @@ -125,6 +125,13 @@ hierarchyRootNode = hierarchyRootNode.sum(function (d) { return d.val; }); num = hierarchyRootNode.value; +// count() and value ---------------------------------------------------------- + +hierarchyRootNode = hierarchyRootNode.count(); + +num = hierarchyRootNode.value; + + // sort --------------------------------------------------------------------- hierarchyRootNode = hierarchyRootNode.sort(function (a, b) { @@ -307,6 +314,12 @@ clusterRootNode = clusterRootNode.sum(function (d) { return d.val; }); num = clusterRootNode.value; +// count() and value ---------------------------------------------------------- + +clusterRootNode = clusterRootNode.count(); + +num = clusterRootNode.value; + // sort --------------------------------------------------------------------- clusterRootNode = clusterRootNode.sort(function (a, b) { @@ -584,6 +597,11 @@ treemapRootNode = treemapRootNode.sum(function (d) { return d.val; }); num = treemapRootNode.value; +// count() and value ---------------------------------------------------------- + +treemapRootNode = treemapRootNode.count(); + +num = treemapRootNode.value; // sort --------------------------------------------------------------------- treemapRootNode = treemapRootNode.sort(function (a, b) { @@ -766,6 +784,11 @@ packRootNode = packRootNode.sum(function (d) { return d.val; }); num = packRootNode.value; +// count() and value ---------------------------------------------------------- + +packRootNode = packRootNode.count(); + +num = packRootNode.value; // sort --------------------------------------------------------------------- packRootNode = packRootNode.sort(function (a, b) { diff --git a/d3-hierarchy/index.d.ts b/d3-hierarchy/index.d.ts index 7eef444875..bfe750b31e 100644 --- a/d3-hierarchy/index.d.ts +++ b/d3-hierarchy/index.d.ts @@ -1,8 +1,10 @@ -// Type definitions for D3JS d3-hierarchy module v1.0.2 +// Type definitions for D3JS d3-hierarchy module 1.1 // Project: https://github.com/d3/d3-hierarchy/ // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Last module patch version validated against: 1.1.1 + // ----------------------------------------------------------------------- // Hierarchy // ----------------------------------------------------------------------- @@ -20,7 +22,7 @@ export interface HierarchyNode { parent: HierarchyNode | null; children?: Array>; /** - * Aggregated numeric value as calculated by sum(value), + * Aggregated numeric value as calculated by sum(value) or count(), * if previously invoked. */ readonly value?: number; @@ -35,6 +37,7 @@ export interface HierarchyNode { path(target: HierarchyNode): Array>; links(): Array>; sum(value: (d: Datum) => number): this; + count(): this; sort(compare: (a: HierarchyNode, b: HierarchyNode) => number): this; each(func: (node: HierarchyNode) => void): this; eachAfter(func: (node: HierarchyNode) => void): this; @@ -43,7 +46,7 @@ export interface HierarchyNode { } -export function hierarchy(data: Datum, children?: (d: Datum) => (Array | null)): HierarchyNode; +export function hierarchy(data: Datum, children?: (d: Datum) => (Datum[] | null)): HierarchyNode; // ----------------------------------------------------------------------- // Stratify @@ -53,11 +56,11 @@ export function hierarchy(data: Datum, children?: (d: Datum) => (Array { - (data: Array): HierarchyNode; - id(): (d: Datum, i: number, data: Array) => (string | null | '' | undefined); - id(id: (d: Datum, i?: number, data?: Array) => (string | null | '' | undefined)): this; - parentId(): (d: Datum, i: number, data: Array) => (string | null | '' | undefined); - parentId(parentId: (d: Datum, i?: number, data?: Array) => (string | null | '' | undefined)): this; + (data: Datum[]): HierarchyNode; + id(): (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined); + id(id: (d: Datum, i?: number, data?: Datum[]) => (string | null | '' | undefined)): this; + parentId(): (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined); + parentId(parentId: (d: Datum, i?: number, data?: Datum[]) => (string | null | '' | undefined)): this; } export function stratify(): StratifyOperator; @@ -80,7 +83,7 @@ export interface HierarchyPointNode { parent: HierarchyPointNode | null; children?: Array>; /** - * Aggregated numeric value as calculated by sum(value), + * Aggregated numeric value as calculated by sum(value) or count(), * if previously invoked. */ readonly value?: number; @@ -95,6 +98,7 @@ export interface HierarchyPointNode { path(target: HierarchyPointNode): Array>; links(): Array>; sum(value: (d: Datum) => number): this; + count(): this; sort(compare: (a: HierarchyPointNode, b: HierarchyPointNode) => number): this; each(func: (node: HierarchyPointNode) => void): this; eachAfter(func: (node: HierarchyPointNode) => void): this; @@ -150,7 +154,7 @@ export interface HierarchyRectangularNode { parent: HierarchyRectangularNode | null; children?: Array>; /** - * Aggregated numeric value as calculated by sum(value), + * Aggregated numeric value as calculated by sum(value) or count(), * if previously invoked. */ readonly value?: number; @@ -165,6 +169,7 @@ export interface HierarchyRectangularNode { path(target: HierarchyRectangularNode): Array>; links(): Array>; sum(value: (d: Datum) => number): this; + count(): this; sort(compare: (a: HierarchyRectangularNode, b: HierarchyRectangularNode) => number): this; each(func: (node: HierarchyRectangularNode) => void): this; eachAfter(func: (node: HierarchyRectangularNode) => void): this; @@ -258,7 +263,7 @@ export interface HierarchyCircularNode { parent: HierarchyCircularNode | null; children?: Array>; /** - * Aggregated numeric value as calculated by sum(value), + * Aggregated numeric value as calculated by sum(value) or count(), * if previously invoked. */ readonly value?: number; @@ -273,6 +278,7 @@ export interface HierarchyCircularNode { path(target: HierarchyCircularNode): Array>; links(): Array>; sum(value: (d: Datum) => number): this; + count(): this; sort(compare: (a: HierarchyCircularNode, b: HierarchyCircularNode) => number): this; each(func: (node: HierarchyCircularNode) => void): this; eachAfter(func: (node: HierarchyCircularNode) => void): this; @@ -310,6 +316,6 @@ export interface PackCircle { // For invocation of packEnclose the x and y coordinates are mandatory. It seems easier to just comment // on the mandatory nature, then to create separate interfaces and having to deal with recasting. -export function packSiblings(circles: Array): Array; +export function packSiblings(circles: Datum[]): Datum[]; -export function packEnclose(circles: Array): { r: number, x: number, y: number }; +export function packEnclose(circles: Datum[]): { r: number, x: number, y: number }; diff --git a/d3/index.d.ts b/d3/index.d.ts index 61953fe148..bf7fa8e6b6 100644 --- a/d3/index.d.ts +++ b/d3/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for D3JS d3 standard bundle 4.4 +// Type definitions for D3JS d3 standard bundle 4.5 // Project: https://github.com/d3/d3 // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped