// 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 // ----------------------------------------------------------------------- export interface HierarchyLink { source: HierarchyNode; target: HierarchyNode; } export interface HierarchyNode { data: Datum; readonly depth: number; readonly height: number; parent: HierarchyNode | null; children?: Array>; /** * Aggregated numeric value as calculated by sum(value) or count(), * if previously invoked. */ readonly value?: number; /** * Optional Node Id string set by StratifyOperator, if * hierarchical data was created from tabular data using stratify() */ readonly id?: string; ancestors(): Array>; descendants(): Array>; leaves(): Array>; 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; eachBefore(func: (node: HierarchyNode) => void): this; copy(): HierarchyNode; } export function hierarchy(data: Datum, children?: (d: Datum) => (Datum[] | null)): HierarchyNode; // ----------------------------------------------------------------------- // Stratify // ----------------------------------------------------------------------- // TODO: Review the comment in the API documentation related to 'reserved properties': id, parentId, children. If this is refering to the element on node, it should be 'parent'? export interface StratifyOperator { (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; // ----------------------------------------------------------------------- // Cluster // ----------------------------------------------------------------------- export interface HierarchyPointLink { source: HierarchyPointNode; target: HierarchyPointNode; } export interface HierarchyPointNode { x: number; y: number; data: Datum; readonly depth: number; readonly height: number; parent: HierarchyPointNode | null; children?: Array>; /** * Aggregated numeric value as calculated by sum(value) or count(), * if previously invoked. */ readonly value?: number; /** * Optional Node Id string set by StratifyOperator, if * hierarchical data was created from tabular data using stratify() */ readonly id?: string; ancestors(): Array>; descendants(): Array>; leaves(): Array>; 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; eachBefore(func: (node: HierarchyPointNode) => void): this; copy(): HierarchyPointNode; } export interface ClusterLayout { (root: HierarchyNode): HierarchyPointNode; size(): [number, number] | null; size(size: [number, number]): this; nodeSize(): [number, number] | null; nodeSize(size: [number, number]): this; separation(): (a: HierarchyPointNode, b: HierarchyPointNode) => number; separation(separation: (a: HierarchyPointNode, b: HierarchyPointNode) => number): this; } export function cluster(): ClusterLayout; // ----------------------------------------------------------------------- // Tree // ----------------------------------------------------------------------- export interface TreeLayout { (root: HierarchyNode): HierarchyPointNode; size(): [number, number] | null; size(size: [number, number]): this; nodeSize(): [number, number] | null; nodeSize(size: [number, number]): this; separation(): (a: HierarchyPointNode, b: HierarchyPointNode) => number; separation(separation: (a: HierarchyPointNode, b: HierarchyPointNode) => number): this; } export function tree(): TreeLayout; // ----------------------------------------------------------------------- // Treemap // ----------------------------------------------------------------------- export interface HierarchyRectangularLink { source: HierarchyRectangularNode; target: HierarchyRectangularNode; } export interface HierarchyRectangularNode { x0: number; y0: number; x1: number; y1: number; data: Datum; readonly depth: number; readonly height: number; parent: HierarchyRectangularNode | null; children?: Array>; /** * Aggregated numeric value as calculated by sum(value) or count(), * if previously invoked. */ readonly value?: number; /** * Optional Node Id string set by StratifyOperator, if * hierarchical data was created from tabular data using stratify() */ readonly id?: string; ancestors(): Array>; descendants(): Array>; leaves(): Array>; 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; eachBefore(func: (node: HierarchyRectangularNode) => void): this; copy(): HierarchyRectangularNode; } export interface TreemapLayout { (root: HierarchyNode): HierarchyRectangularNode; tile(): (node: HierarchyRectangularNode, x0: number, y0: number, x1: number, y1: number) => void; tile(tile: (node: HierarchyRectangularNode, x0: number, y0: number, x1: number, y1: number) => void): this; size(): [number, number]; size(size: [number, number]): this; round(): boolean; round(round: boolean): this; padding(): (node: HierarchyRectangularNode) => number; padding(padding: number): this; padding(padding: (node: HierarchyRectangularNode) => number): this; paddingInner(): (node: HierarchyRectangularNode) => number; paddingInner(padding: number): this; paddingInner(padding: (node: HierarchyRectangularNode) => number): this; paddingOuter(): (node: HierarchyRectangularNode) => number; paddingOuter(padding: number): this; paddingOuter(padding: (node: HierarchyRectangularNode) => number): this; paddingTop(): (node: HierarchyRectangularNode) => number; paddingTop(padding: number): this; paddingTop(padding: (node: HierarchyRectangularNode) => number): this; paddingRight(): (node: HierarchyRectangularNode) => number; paddingRight(padding: number): this; paddingRight(padding: (node: HierarchyRectangularNode) => number): this; paddingBottom(): (node: HierarchyRectangularNode) => number; paddingBottom(padding: number): this; paddingBottom(padding: (node: HierarchyRectangularNode) => number): this; paddingLeft(): (node: HierarchyRectangularNode) => number; paddingLeft(padding: number): this; paddingLeft(padding: (node: HierarchyRectangularNode) => number): this; } export function treemap(): TreemapLayout; // Tiling functions --------------------------------------------------------------------------------- export function treemapBinary(node: HierarchyRectangularNode, x0: number, y0: number, x1: number, y1: number): void; export function treemapDice(node: HierarchyRectangularNode, x0: number, y0: number, x1: number, y1: number): void; export function treemapSlice(node: HierarchyRectangularNode, x0: number, y0: number, x1: number, y1: number): void; export function treemapSliceDice(node: HierarchyRectangularNode, x0: number, y0: number, x1: number, y1: number): void; // TODO: Test Factory code export interface RatioSquarifyTilingFactory { (node: HierarchyRectangularNode, x0: number, y0: number, x1: number, y1: number): void; ratio(ratio: number): RatioSquarifyTilingFactory; } export var treemapSquarify: RatioSquarifyTilingFactory; export var treemapResquarify: RatioSquarifyTilingFactory; // ----------------------------------------------------------------------- // Partition // ----------------------------------------------------------------------- export interface PartitionLayout { (root: HierarchyNode): HierarchyRectangularNode; size(): [number, number]; size(size: [number, number]): this; round(): boolean; round(round: boolean): this; padding(): number; padding(padding: number): this; } export function partition(): PartitionLayout; // ----------------------------------------------------------------------- // Pack // ----------------------------------------------------------------------- export interface HierarchyCircularLink { source: HierarchyCircularNode; target: HierarchyCircularNode; } export interface HierarchyCircularNode { x: number; y: number; r: number; data: Datum; readonly depth: number; readonly height: number; parent: HierarchyCircularNode | null; children?: Array>; /** * Aggregated numeric value as calculated by sum(value) or count(), * if previously invoked. */ readonly value?: number; /** * Optional Node Id string set by StratifyOperator, if * hierarchical data was created from tabular data using stratify() */ readonly id?: string; ancestors(): Array>; descendants(): Array>; leaves(): Array>; 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; eachBefore(func: (node: HierarchyCircularNode) => void): this; copy(): HierarchyCircularNode; } export interface PackLayout { (root: HierarchyNode): HierarchyCircularNode; radius(): null | ((node: HierarchyCircularNode) => number); radius(radius: (node: HierarchyCircularNode) => number): this; size(): [number, number]; size(size: [number, number]): this; padding(): (node: HierarchyCircularNode) => number; padding(padding: number): this; padding(padding: (node: HierarchyCircularNode) => number): this; } export function pack(): PackLayout; // ----------------------------------------------------------------------- // Pack Siblings and Enclosure // ----------------------------------------------------------------------- export interface PackCircle { r: number; x?: number; y?: number; } // TODO: Since packSiblings manipulates the circles array in place, technically the x and y properties // are optional on invocation, but will be created after execution for each entry. // 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: Datum[]): Datum[]; export function packEnclose(circles: Datum[]): { r: number, x: number, y: number };