Linting d3-hexbin and d3-hierarchy (#25325)

This commit is contained in:
denisname 2018-04-26 19:31:47 +02:00 committed by Wesley Wigham
parent c3257dd16c
commit c853ba2651
6 changed files with 94 additions and 267 deletions

View File

@ -22,22 +22,21 @@ interface Point {
b.y()([41, 42]); // === 42;
b.radius(); // === 1;
// hexbin(points) bins the specified points into hexagonal bins
const bins = d3Hexbin.hexbin()([
[0, 0], [0, 1], [0, 2],
[1, 0], [1, 1], [1, 2],
[2, 0], [2, 1], [2, 2]
])
]);
bins.map((bin: any) => {})
bins.map((bin: any) => {});
}
{
// hexbin(points) observes the current x- and y-accessors
const x = function(d: any) { return d.x; },
y = function(d: any) { return d.y; },
bins = d3Hexbin.hexbin<Point>().x(x).y(y)([
const x = (d: any) => d.x;
const y = (d: any) => d.y;
const bins = d3Hexbin.hexbin<Point>().x(x).y(y)([
{x0: 0, y0: 0}, {x0: 0, y0: 1}, {x0: 0, y0: 2},
{x0: 1, y0: 0}, {x0: 1, y0: 1}, {x0: 1, y0: 2},
{x0: 2, y0: 0}, {x0: 2, y0: 1}, {x0: 2, y0: 2}
@ -52,7 +51,7 @@ interface Point {
[1, 0], [1, 1], [1, 2],
[2, 0], [2, 1], [2, 2]
]);
bins.map((bin: any)=> {});
bins.map((bin: any) => {});
}
{
@ -62,15 +61,15 @@ interface Point {
}
// hexbin.x(x) sets the x-coordinate accessor
const x = function(d: PointX) { return d.x; },
b = d3Hexbin.hexbin<PointX>().x(x),
bins = b([{x: 1, 1: 2}]);
const x = (d: PointX) => d.x;
const b = d3Hexbin.hexbin<PointX>().x(x);
const bins = b([{x: 1, 1: 2}]);
b.x(); // should be x;
bins.length; // should be 1;
bins[0].x; // should be 0.8660254037844386;
bins[0].y; // should be 1.5;
bins[0].length // should be 1;
bins[0].length; // should be 1;
}
{
@ -79,9 +78,9 @@ interface Point {
[key: number]: number;
}
// hexbin.y(y) sets the y-coordinate accessor
const y = function(d: PointY) { return d.y; },
b = d3Hexbin.hexbin<PointY>().y(y),
bins = b([{0: 1, y: 2}]);
const y = (d: PointY) => d.y;
const b = d3Hexbin.hexbin<PointY>().y(y);
const bins = b([{0: 1, y: 2}]);
bins.length; // should be 1;
bins[0].x; // should be 0.8660254037844386;
@ -148,9 +147,8 @@ interface Point {
}
{
let hb: d3Hexbin.Hexbin<Point>;
let bins: d3Hexbin.HexbinBin<Point>[];
let bins: Array<d3Hexbin.HexbinBin<Point>>;
// Create generator =======================================
@ -160,8 +158,8 @@ interface Point {
// x Accessor ----------------------------------------------
let x: (d:Point) => number;
x = function (d: Point) { return d.x0; };
let x: (d: Point) => number;
x = (d: Point) => d.x0;
// test setter
hb = hb.x(x);
@ -171,8 +169,8 @@ interface Point {
// y Accessor ----------------------------------------------
let y: (d:Point) => number;
y = function (d: Point) { return d.y0; };
let y: (d: Point) => number;
y = (d: Point) => d.y0;
// test setter
hb = hb.y(y);
@ -193,7 +191,7 @@ interface Point {
points: Point[];
}
let remappedBins: Array<RemappedBin>;
let remappedBins: RemappedBin[];
remappedBins = bins.map(bin => {
const x: number = bin.x; // x-coordinate of bin

View File

@ -1,8 +1,10 @@
// Type definitions for D3JS d3-hexbin module v0.2.1
// Type definitions for D3JS d3-hexbin module 0.2
// Project: https://github.com/d3/d3-hexbin/
// Definitions by: UNCOVER TRUTH Inc. <https://github.com/uncovertruth>, Tom Wanzek <https://github.com/tomwanzek>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Last module patch version validated against: 0.2.1
export interface HexbinBin<T> extends Array<T> {
x: number;
y: number;
@ -17,7 +19,7 @@ export interface Hexbin<T> {
* If either the x- or y-coordinate is NaN, the point is ignored and will
* not be in any of the returned bins.
*/
(points: T[]): HexbinBin<T>[];
(points: T[]): Array<HexbinBin<T>>;
/**
* Returns the SVG path string for the hexagon centered at the origin 0,0.
@ -27,7 +29,7 @@ export interface Hexbin<T> {
* If radius is specified, a hexagon with the specified radius is returned;
* this is useful for area-encoded bivariate hexbins.
*
* @param {number} radius Radius number
* @param radius Radius number
*/
hexagon(radius?: number): string;
@ -78,7 +80,7 @@ export interface Hexbin<T> {
* of each point. The default value assumes each point is specified as
* a two-element array of numbers [x, y].
*/
y(y: (d: T) => number): Hexbin<T>
y(y: (d: T) => number): Hexbin<T>;
/**
* If y is not specified, returns the current y-coordinate accessor,

View File

@ -1,79 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
"no-unnecessary-generics": false
}
}

View File

@ -8,7 +8,6 @@
import * as d3Hierarchy from 'd3-hierarchy';
// -----------------------------------------------------------------------
// Preparatory Steps
// -----------------------------------------------------------------------
@ -24,11 +23,9 @@ let idString: string;
interface HierarchyDatum {
name: string;
val: number;
children?: Array<HierarchyDatum>;
children?: HierarchyDatum[];
}
let hierarchyRootDatum: HierarchyDatum = {
name: 'n0',
val: 10,
@ -68,7 +65,7 @@ let hierarchyRootNode: d3Hierarchy.HierarchyNode<HierarchyDatum>;
hierarchyRootNode = d3Hierarchy.hierarchy(hierarchyRootDatum);
hierarchyRootNode = d3Hierarchy.hierarchy(hierarchyRootDatum, function (d) {
hierarchyRootNode = d3Hierarchy.hierarchy(hierarchyRootDatum, (d) => {
return d.children || null;
});
@ -82,7 +79,6 @@ num = hierarchyRootNode.height;
// children, parent ------------------------------------------------------
hierarchyNodeArray = hierarchyRootNode.children;
let parentNode: d3Hierarchy.HierarchyNode<HierarchyDatum>;
@ -94,8 +90,8 @@ idString = hierarchyRootNode.id;
// ancestors(), descendants() --------------------------------------------
let ancestors: Array<d3Hierarchy.HierarchyNode<HierarchyDatum>> = hierarchyRootNode.ancestors();
let descendants: Array<d3Hierarchy.HierarchyNode<HierarchyDatum>> = hierarchyRootNode.descendants();
const ancestors: Array<d3Hierarchy.HierarchyNode<HierarchyDatum>> = hierarchyRootNode.ancestors();
const descendants: Array<d3Hierarchy.HierarchyNode<HierarchyDatum>> = hierarchyRootNode.descendants();
// leaves() ---------------------------------------------------------------
@ -105,7 +101,7 @@ hierarchyNodeArray = hierarchyRootNode.leaves();
hierarchyNode = descendants[descendants.length - 1];
let path: Array<d3Hierarchy.HierarchyNode<HierarchyDatum>> = hierarchyRootNode.path(hierarchyNode);
const path: Array<d3Hierarchy.HierarchyNode<HierarchyDatum>> = hierarchyRootNode.path(hierarchyNode);
// links() and HierarchyLink<...> ------------------------------------------
@ -121,7 +117,7 @@ hierarchyNode = link.target;
// sum() and value ----------------------------------------------------------
hierarchyRootNode = hierarchyRootNode.sum(function (d) { return d.val; });
hierarchyRootNode = hierarchyRootNode.sum((d) => d.val);
num = hierarchyRootNode.value;
@ -131,29 +127,28 @@ hierarchyRootNode = hierarchyRootNode.count();
num = hierarchyRootNode.value;
// sort ---------------------------------------------------------------------
hierarchyRootNode = hierarchyRootNode.sort(function (a, b) {
console.log(' Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyNode<HierarchyDatum>
hierarchyRootNode = hierarchyRootNode.sort((a, b) => {
console.log('Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyNode<HierarchyDatum>
return b.height - a.height || b.value - a.value;
});
// each(), eachAfter(), eachBefore() ----------------------------------------
hierarchyRootNode = hierarchyRootNode.each(function (node) {
console.log(' Raw value of node:', node.data.val); // node type is HierarchyNode<HierarchyDatum>
console.log(' Aggregated value of node:', node.value); // node type is HierarchyNode<HierarchyDatum>
hierarchyRootNode = hierarchyRootNode.each((node) => {
console.log('Raw value of node:', node.data.val); // node type is HierarchyNode<HierarchyDatum>
console.log('Aggregated value of node:', node.value); // node type is HierarchyNode<HierarchyDatum>
});
hierarchyRootNode = hierarchyRootNode.eachAfter(function (node) {
console.log(' Raw value of node:', node.data.val); // node type is HierarchyNode<HierarchyDatum>
console.log(' Aggregated value of node:', node.value); // node type is HierarchyNode<HierarchyDatum>
hierarchyRootNode = hierarchyRootNode.eachAfter((node) => {
console.log('Raw value of node:', node.data.val); // node type is HierarchyNode<HierarchyDatum>
console.log('Aggregated value of node:', node.value); // node type is HierarchyNode<HierarchyDatum>
});
hierarchyRootNode = hierarchyRootNode.eachBefore(function (node) {
console.log(' Raw value of node:', node.data.val); // node type is HierarchyNode<HierarchyDatum>
console.log(' Aggregated value of node:', node.value); // node type is HierarchyNode<HierarchyDatum>
hierarchyRootNode = hierarchyRootNode.eachBefore((node) => {
console.log('Raw value of node:', node.data.val); // node type is HierarchyNode<HierarchyDatum>
console.log('Aggregated value of node:', node.value); // node type is HierarchyNode<HierarchyDatum>
});
// copy() --------------------------------------------------------------------
@ -175,7 +170,7 @@ interface TabularHierarchyDatum {
val: number;
}
let tabularData: Array<TabularHierarchyDatum>;
let tabularData: TabularHierarchyDatum[];
tabularData = [
{ name: 'n0', parentId: null, val: 10 },
{ name: 'n11', parentId: 'n0', val: 5 },
@ -183,7 +178,7 @@ tabularData = [
{ name: 'n121', parentId: 'n12', val: 30 }
];
let idStringAccessor: (d: TabularHierarchyDatum, i?: number, data?: Array<TabularHierarchyDatum>) => (string | null | '' | undefined);
let idStringAccessor: (d: TabularHierarchyDatum, i?: number, data?: TabularHierarchyDatum[]) => (string | null | '' | undefined);
// Create Stratify Operator ---------------------------------------------
@ -194,7 +189,7 @@ stratificatorizer = d3Hierarchy.stratify<TabularHierarchyDatum>();
// id(...)
stratificatorizer = stratificatorizer.id(function (d, i, data) {
stratificatorizer = stratificatorizer.id((d, i, data) => {
console.log('Length of tabular array: ', data.length);
console.log('Name of first entry in tabular array: ', data[0].name); // data of type Array<TabularHierarchyDatum>
return d.name; // d is of type TabularHierarchyDatum
@ -204,7 +199,7 @@ idStringAccessor = stratificatorizer.id();
// parentId(...)
stratificatorizer = stratificatorizer.parentId(function (d, i, data) {
stratificatorizer = stratificatorizer.parentId((d, i, data) => {
console.log('Length of tabular array: ', data.length);
console.log('Name of first entry in tabular array: ', data[0].name); // data of type Array<TabularHierarchyDatum>
return d.parentId; // d is of type TabularHierarchyDatum
@ -214,7 +209,7 @@ idStringAccessor = stratificatorizer.parentId();
// Use Stratify Operator ------------------------------------------------
let stratifiedRootNode: d3Hierarchy.HierarchyNode<HierarchyDatumWithParentId> = stratificatorizer(tabularData);
const stratifiedRootNode: d3Hierarchy.HierarchyNode<HierarchyDatumWithParentId> = stratificatorizer(tabularData);
// -----------------------------------------------------------------------
// Cluster
@ -265,13 +260,12 @@ num = clusterRootNode.y;
// data, depth, height ---------------------------------------------------
let clusterDatum: HierarchyDatumWithParentId = clusterRootNode.data;
const clusterDatum: HierarchyDatumWithParentId = clusterRootNode.data;
num = clusterRootNode.depth;
num = clusterRootNode.height;
// children, parent ------------------------------------------------------
hierarchyPointNodeArray = clusterRootNode.children;
let parentPointNode: d3Hierarchy.HierarchyPointNode<HierarchyDatumWithParentId>;
@ -283,8 +277,8 @@ idString = clusterRootNode.id;
// ancestors(), descendants() --------------------------------------------
let pointNodeAncestors: Array<d3Hierarchy.HierarchyPointNode<HierarchyDatumWithParentId>> = clusterRootNode.ancestors();
let pointNodeDescendants: Array<d3Hierarchy.HierarchyPointNode<HierarchyDatumWithParentId>> = clusterRootNode.descendants();
const pointNodeAncestors: Array<d3Hierarchy.HierarchyPointNode<HierarchyDatumWithParentId>> = clusterRootNode.ancestors();
const pointNodeDescendants: Array<d3Hierarchy.HierarchyPointNode<HierarchyDatumWithParentId>> = clusterRootNode.descendants();
// leaves() ---------------------------------------------------------------
@ -294,7 +288,7 @@ hierarchyPointNodeArray = clusterRootNode.leaves();
hierarchyPointNode = pointNodeDescendants[pointNodeDescendants.length - 1];
let clusterPath: Array<d3Hierarchy.HierarchyPointNode<HierarchyDatumWithParentId>> = clusterRootNode.path(hierarchyPointNode);
const clusterPath: Array<d3Hierarchy.HierarchyPointNode<HierarchyDatumWithParentId>> = clusterRootNode.path(hierarchyPointNode);
// links() and HierarchyPointLink<...> ------------------------------------------
@ -310,7 +304,7 @@ hierarchyPointNode = pointLink.target;
// sum() and value ----------------------------------------------------------
clusterRootNode = clusterRootNode.sum(function (d) { return d.val; });
clusterRootNode = clusterRootNode.sum((d) => d.val);
num = clusterRootNode.value;
@ -322,25 +316,25 @@ num = clusterRootNode.value;
// sort ---------------------------------------------------------------------
clusterRootNode = clusterRootNode.sort(function (a, b) {
console.log(' x-coordinates of a:', a.x, ' and b:', b.x); // a and b are of type HierarchyPointNode<HierarchyDatumWithParentId>
console.log(' Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyPointNode<HierarchyDatumWithParentId>
clusterRootNode = clusterRootNode.sort((a, b) => {
console.log('x-coordinates of a:', a.x, ' and b:', b.x); // a and b are of type HierarchyPointNode<HierarchyDatumWithParentId>
console.log('Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyPointNode<HierarchyDatumWithParentId>
return b.height - a.height || b.value - a.value;
});
// each(), eachAfter(), eachBefore() ----------------------------------------
clusterRootNode = clusterRootNode.each(function (node) {
clusterRootNode = clusterRootNode.each((node) => {
console.log('ParentId:', node.data.parentId); // node type is HierarchyPointNode<HierarchyDatumWithParentId>
console.log('X-coordinate of node:', node.x); // node type is HierarchyPointNode<HierarchyDatumWithParentId>
});
clusterRootNode = clusterRootNode.eachAfter(function (node) {
clusterRootNode = clusterRootNode.eachAfter((node) => {
console.log('ParentId:', node.data.parentId); // node type is HierarchyPointNode<HierarchyDatumWithParentId>
console.log('X-coordinate of node:', node.x); // node type is HierarchyPointNode<HierarchyDatumWithParentId>
});
clusterRootNode = clusterRootNode.eachBefore(function (node) {
clusterRootNode = clusterRootNode.eachBefore((node) => {
console.log('ParentId:', node.data.parentId); // node type is HierarchyPointNode<HierarchyDatumWithParentId>
console.log('X-coordinate of node:', node.x); // node type is HierarchyPointNode<HierarchyDatumWithParentId>
});
@ -405,8 +399,7 @@ treemapLayout = d3Hierarchy.treemap<HierarchyDatumWithParentId>();
// tile() ----------------------------------------------------------------
treemapLayout = treemapLayout.tile(function (node, x0, y0, x1, y1) {
let n: number;
treemapLayout = treemapLayout.tile((node, x0, y0, x1, y1) => {
console.log('x0 coordinate of node: ', node.x0);
console.log('Node parent id: ', node.data.parentId); // type of node is HierarchyRectangularNode<HierarchyDatumWithParentId>
num = x0; // number
@ -437,7 +430,7 @@ let roundFlag: boolean = treemapLayout.round();
// padding() ----------------------------------------------------------------
treemapLayout = treemapLayout.padding(1);
treemapLayout = treemapLayout.padding(function (node) {
treemapLayout = treemapLayout.padding((node) => {
console.log('Node parent id: ', node.data.parentId); // type of node is HierarchyRectangularNode<HierarchyDatumWithParentId>
return node.x0 > 10 ? 2 : 1;
});
@ -447,7 +440,7 @@ numberRectangularNodeAccessor = treemapLayout.padding();
// paddingInner() ----------------------------------------------------------------
treemapLayout = treemapLayout.paddingInner(1);
treemapLayout = treemapLayout.paddingInner(function (node) {
treemapLayout = treemapLayout.paddingInner((node) => {
console.log('Node parent id: ', node.data.parentId); // type of node is HierarchyRectangularNode<HierarchyDatumWithParentId>
return node.x0 > 10 ? 2 : 1;
});
@ -457,7 +450,7 @@ numberRectangularNodeAccessor = treemapLayout.paddingInner();
// paddingOuter() ----------------------------------------------------------------
treemapLayout = treemapLayout.paddingOuter(1);
treemapLayout = treemapLayout.paddingOuter(function (node) {
treemapLayout = treemapLayout.paddingOuter((node) => {
console.log('Node parent id: ', node.data.parentId); // type of node is HierarchyRectangularNode<HierarchyDatumWithParentId>
return node.x0 > 10 ? 2 : 1;
});
@ -467,7 +460,7 @@ numberRectangularNodeAccessor = treemapLayout.paddingOuter();
// paddingTop() ----------------------------------------------------------------
treemapLayout = treemapLayout.paddingTop(1);
treemapLayout = treemapLayout.paddingTop(function (node) {
treemapLayout = treemapLayout.paddingTop((node) => {
console.log('Node parent id: ', node.data.parentId); // type of node is HierarchyRectangularNode<HierarchyDatumWithParentId>
return node.x0 > 10 ? 2 : 1;
});
@ -477,7 +470,7 @@ numberRectangularNodeAccessor = treemapLayout.paddingTop();
// paddingRight() ----------------------------------------------------------------
treemapLayout = treemapLayout.paddingRight(1);
treemapLayout = treemapLayout.paddingRight(function (node) {
treemapLayout = treemapLayout.paddingRight((node) => {
console.log('Node parent id: ', node.data.parentId); // type of node is HierarchyRectangularNode<HierarchyDatumWithParentId>
return node.x0 > 10 ? 2 : 1;
});
@ -487,7 +480,7 @@ numberRectangularNodeAccessor = treemapLayout.paddingRight();
// paddingBottom() ----------------------------------------------------------------
treemapLayout = treemapLayout.paddingBottom(1);
treemapLayout = treemapLayout.paddingBottom(function (node) {
treemapLayout = treemapLayout.paddingBottom((node) => {
console.log('Node parent id: ', node.data.parentId); // type of node is HierarchyRectangularNode<HierarchyDatumWithParentId>
return node.x0 > 10 ? 2 : 1;
});
@ -497,21 +490,19 @@ numberRectangularNodeAccessor = treemapLayout.paddingBottom();
// paddingLeft() ----------------------------------------------------------------
treemapLayout = treemapLayout.paddingLeft(1);
treemapLayout = treemapLayout.paddingLeft(function (node) {
treemapLayout = treemapLayout.paddingLeft((node) => {
console.log('Node parent id: ', node.data.parentId); // type of node is HierarchyRectangularNode<HierarchyDatumWithParentId>
return node.x0 > 10 ? 2 : 1;
});
numberRectangularNodeAccessor = treemapLayout.paddingLeft();
// Use treemap layout generator ==========================================
let treemapRootNode: d3Hierarchy.HierarchyRectangularNode<HierarchyDatumWithParentId>;
treemapRootNode = treemapLayout(stratifiedRootNode);
// Tiling functions ======================================================
tilingFn = d3Hierarchy.treemapBinary;
@ -536,7 +527,6 @@ tilingFactoryFn = d3Hierarchy.treemapResquarify.ratio(2);
treemapLayout.tile(d3Hierarchy.treemapResquarify.ratio(2));
// Use HierarchyRectangularNode ================================================
// x and y coordinates ---------------------------------------------------
@ -548,13 +538,12 @@ num = treemapRootNode.y1;
// data, depth, height ---------------------------------------------------
let treemapDatum: HierarchyDatumWithParentId = treemapRootNode.data;
const treemapDatum: HierarchyDatumWithParentId = treemapRootNode.data;
num = treemapRootNode.depth;
num = treemapRootNode.height;
// children, parent ------------------------------------------------------
hierarchyRectangularNodeArray = treemapRootNode.children;
let parentRectangularNode: d3Hierarchy.HierarchyRectangularNode<HierarchyDatumWithParentId>;
@ -566,8 +555,8 @@ idString = treemapRootNode.id;
// ancestors(), descendants() --------------------------------------------
let rectangularNodeAncestors: Array<d3Hierarchy.HierarchyRectangularNode<HierarchyDatumWithParentId>> = treemapRootNode.ancestors();
let rectangularNodeDescendants: Array<d3Hierarchy.HierarchyRectangularNode<HierarchyDatumWithParentId>> = treemapRootNode.descendants();
const rectangularNodeAncestors: Array<d3Hierarchy.HierarchyRectangularNode<HierarchyDatumWithParentId>> = treemapRootNode.ancestors();
const rectangularNodeDescendants: Array<d3Hierarchy.HierarchyRectangularNode<HierarchyDatumWithParentId>> = treemapRootNode.descendants();
// leaves() ---------------------------------------------------------------
@ -577,7 +566,7 @@ hierarchyRectangularNodeArray = treemapRootNode.leaves();
hierarchyRectangularNode = rectangularNodeDescendants[rectangularNodeDescendants.length - 1];
let treemapPath: Array<d3Hierarchy.HierarchyRectangularNode<HierarchyDatumWithParentId>> = treemapRootNode.path(hierarchyRectangularNode);
const treemapPath: Array<d3Hierarchy.HierarchyRectangularNode<HierarchyDatumWithParentId>> = treemapRootNode.path(hierarchyRectangularNode);
// links() and HierarchyRectangulerLink<...> ------------------------------------------
@ -593,7 +582,7 @@ hierarchyRectangularNode = rectangularLink.target;
// sum() and value ----------------------------------------------------------
treemapRootNode = treemapRootNode.sum(function (d) { return d.val; });
treemapRootNode = treemapRootNode.sum((d) => d.val);
num = treemapRootNode.value;
@ -604,25 +593,25 @@ treemapRootNode = treemapRootNode.count();
num = treemapRootNode.value;
// sort ---------------------------------------------------------------------
treemapRootNode = treemapRootNode.sort(function (a, b) {
console.log(' x0-coordinates of a:', a.x0, ' and b:', b.x0); // a and b are of type HierarchyRectangularNode<HierarchyDatumWithParentId>
console.log(' Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyRectangularNode<HierarchyDatumWithParentId>
treemapRootNode = treemapRootNode.sort((a, b) => {
console.log('x0-coordinates of a:', a.x0, ' and b:', b.x0); // a and b are of type HierarchyRectangularNode<HierarchyDatumWithParentId>
console.log('Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyRectangularNode<HierarchyDatumWithParentId>
return b.height - a.height || b.value - a.value;
});
// each(), eachAfter(), eachBefore() ----------------------------------------
treemapRootNode = treemapRootNode.each(function (node) {
treemapRootNode = treemapRootNode.each((node) => {
console.log('ParentId:', node.data.parentId); // node type is HierarchyRectangularNode<HierarchyDatumWithParentId>
console.log('X0-coordinate of node:', node.x0); // node type is HierarchyRectangularNode<HierarchyDatumWithParentId>
});
treemapRootNode = treemapRootNode.eachAfter(function (node) {
treemapRootNode = treemapRootNode.eachAfter((node) => {
console.log('ParentId:', node.data.parentId); // node type is HierarchyRectangularNode<HierarchyDatumWithParentId>
console.log('X0-coordinate of node:', node.x0); // node type is HierarchyRectangularNode<HierarchyDatumWithParentId>
});
treemapRootNode = treemapRootNode.eachBefore(function (node) {
treemapRootNode = treemapRootNode.eachBefore((node) => {
console.log('ParentId:', node.data.parentId); // node type is HierarchyRectangularNode<HierarchyDatumWithParentId>
console.log('X0-coordinate of node:', node.x0); // node type is HierarchyRectangularNode<HierarchyDatumWithParentId>
});
@ -632,8 +621,6 @@ treemapRootNode = treemapRootNode.eachBefore(function (node) {
let copiedTreemapNode: d3Hierarchy.HierarchyRectangularNode<HierarchyDatumWithParentId>;
copiedTreemapNode = treemapRootNode.copy();
// -----------------------------------------------------------------------
// Partition
// -----------------------------------------------------------------------
@ -646,7 +633,6 @@ partitionLayout = d3Hierarchy.partition<HierarchyDatumWithParentId>();
// Configure partition layout generator ====================================
// size() ----------------------------------------------------------------
partitionLayout = partitionLayout.size(null);
@ -666,7 +652,6 @@ partitionLayout = partitionLayout.padding(1);
num = partitionLayout.padding();
// Use partition layout generator ==========================================
let partitionRootNode: d3Hierarchy.HierarchyRectangularNode<HierarchyDatumWithParentId>;
@ -687,7 +672,6 @@ packLayout = d3Hierarchy.pack<HierarchyDatumWithParentId>();
// Configure pack layout generator ====================================
// size() ----------------------------------------------------------------
packLayout = packLayout.size(null);
@ -697,7 +681,7 @@ size = packLayout.size();
// radius() ------------------------------------------------------------
packLayout = packLayout.radius(function (node) {
packLayout = packLayout.radius((node) => {
console.log('Radius property of node before completing accessor: ', node.r); // node is of type HierarchyCircularNode<HierarchyDatumWithParentId>
console.log('Parent id of node: ', node.data.parentId); // node is of type HierarchyCircularNode<HierarchyDatumWithParentId>
return node.value;
@ -709,7 +693,7 @@ numberCircularNodeAccessor = packLayout.radius();
packLayout = packLayout.padding(1);
packLayout = packLayout.padding(function (node) {
packLayout = packLayout.padding((node) => {
console.log('Radius property of node: ', node.r); // node is of type HierarchyCircularNode<HierarchyDatumWithParentId>
console.log('Parent id of node: ', node.data.parentId); // node is of type HierarchyCircularNode<HierarchyDatumWithParentId>
return node.value > 10 ? 2 : 1;
@ -717,14 +701,12 @@ packLayout = packLayout.padding(function (node) {
numberCircularNodeAccessor = packLayout.padding();
// Use partition layout generator ==========================================
let packRootNode: d3Hierarchy.HierarchyCircularNode<HierarchyDatumWithParentId>;
packRootNode = packLayout(stratifiedRootNode);
// Use HierarchyCircularNode ================================================
// x and y coordinates and radius r ------------------------------------------
@ -735,13 +717,12 @@ num = packRootNode.r;
// data, depth, height ---------------------------------------------------
let packDatum: HierarchyDatumWithParentId = packRootNode.data;
const packDatum: HierarchyDatumWithParentId = packRootNode.data;
num = packRootNode.depth;
num = packRootNode.height;
// children, parent ------------------------------------------------------
hierarchyCircularNodeArray = packRootNode.children;
let parentCircularNode: d3Hierarchy.HierarchyCircularNode<HierarchyDatumWithParentId>;
@ -753,8 +734,8 @@ idString = packRootNode.id;
// ancestors(), descendants() --------------------------------------------
let circularNodeAncestors: Array<d3Hierarchy.HierarchyCircularNode<HierarchyDatumWithParentId>> = packRootNode.ancestors();
let circularNodeDescendants: Array<d3Hierarchy.HierarchyCircularNode<HierarchyDatumWithParentId>> = packRootNode.descendants();
const circularNodeAncestors: Array<d3Hierarchy.HierarchyCircularNode<HierarchyDatumWithParentId>> = packRootNode.ancestors();
const circularNodeDescendants: Array<d3Hierarchy.HierarchyCircularNode<HierarchyDatumWithParentId>> = packRootNode.descendants();
// leaves() ---------------------------------------------------------------
@ -764,7 +745,7 @@ hierarchyCircularNodeArray = packRootNode.leaves();
hierarchyCircularNode = circularNodeDescendants[circularNodeDescendants.length - 1];
let packPath: Array<d3Hierarchy.HierarchyCircularNode<HierarchyDatumWithParentId>> = packRootNode.path(hierarchyCircularNode);
const packPath: Array<d3Hierarchy.HierarchyCircularNode<HierarchyDatumWithParentId>> = packRootNode.path(hierarchyCircularNode);
// links() and HierarchyRectangulerLink<...> ------------------------------------------
@ -780,7 +761,7 @@ hierarchyCircularNode = circularLink.target;
// sum() and value ----------------------------------------------------------
packRootNode = packRootNode.sum(function (d) { return d.val; });
packRootNode = packRootNode.sum((d) => d.val);
num = packRootNode.value;
@ -791,25 +772,25 @@ packRootNode = packRootNode.count();
num = packRootNode.value;
// sort ---------------------------------------------------------------------
packRootNode = packRootNode.sort(function (a, b) {
packRootNode = packRootNode.sort((a, b) => {
console.log('radius of a:', a.r, ' and b:', b.r); // a and b are of type HierarchyCircularNode<HierarchyDatumWithParentId>
console.log(' Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyCircularNode<HierarchyDatumWithParentId>
console.log('Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyCircularNode<HierarchyDatumWithParentId>
return b.height - a.height || b.value - a.value;
});
// each(), eachAfter(), eachBefore() ----------------------------------------
packRootNode = packRootNode.each(function (node) {
packRootNode = packRootNode.each((node) => {
console.log('ParentId:', node.data.parentId); // node type is HierarchyCircularNode<HierarchyDatumWithParentId>
console.log('Radius of node:', node.r); // node type is HierarchyCircularNode<HierarchyDatumWithParentId>
});
packRootNode = packRootNode.eachAfter(function (node) {
packRootNode = packRootNode.eachAfter((node) => {
console.log('ParentId:', node.data.parentId); // node type is HierarchyCircularNode<HierarchyDatumWithParentId>
console.log('Radius of node:', node.r); // node type is HierarchyCircularNode<HierarchyDatumWithParentId>
});
packRootNode = packRootNode.eachBefore(function (node) {
packRootNode = packRootNode.eachBefore((node) => {
console.log('ParentId:', node.data.parentId); // node type is HierarchyCircularNode<HierarchyDatumWithParentId>
console.log('Radius of node:', node.r); // node type is HierarchyCircularNode<HierarchyDatumWithParentId>
});
@ -819,7 +800,6 @@ packRootNode = packRootNode.eachBefore(function (node) {
let copiedPackNode: d3Hierarchy.HierarchyCircularNode<HierarchyDatumWithParentId>;
copiedPackNode = packRootNode.copy();
// -----------------------------------------------------------------------
// Pack Siblings and Enclosure
// -----------------------------------------------------------------------
@ -828,7 +808,7 @@ interface CircleData extends d3Hierarchy.PackCircle {
v: string;
}
let circles: Array<CircleData> = [
let circles: CircleData[] = [
{ r: 10, v: 'a' },
{ r: 1, v: 'b' },
{ r: 20, v: 'c' }

View File

@ -9,7 +9,6 @@
// Hierarchy
// -----------------------------------------------------------------------
export interface HierarchyLink<Datum> {
source: HierarchyNode<Datum>;
target: HierarchyNode<Datum>;
@ -45,7 +44,6 @@ export interface HierarchyNode<Datum> {
copy(): HierarchyNode<Datum>;
}
export function hierarchy<Datum>(data: Datum, children?: (d: Datum) => (Datum[] | null)): HierarchyNode<Datum>;
// -----------------------------------------------------------------------
@ -54,7 +52,6 @@ export function hierarchy<Datum>(data: Datum, children?: (d: Datum) => (Datum[]
// 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<Datum> {
(data: Datum[]): HierarchyNode<Datum>;
id(): (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined);
@ -212,7 +209,6 @@ export function treemap<Datum>(): TreemapLayout<Datum>;
// Tiling functions ---------------------------------------------------------------------------------
export function treemapBinary(node: HierarchyRectangularNode<any>, x0: number, y0: number, x1: number, y1: number): void;
export function treemapDice(node: HierarchyRectangularNode<any>, x0: number, y0: number, x1: number, y1: number): void;
export function treemapSlice(node: HierarchyRectangularNode<any>, x0: number, y0: number, x1: number, y1: number): void;
@ -224,9 +220,8 @@ export interface RatioSquarifyTilingFactory {
ratio(ratio: number): RatioSquarifyTilingFactory;
}
export var treemapSquarify: RatioSquarifyTilingFactory;
export var treemapResquarify: RatioSquarifyTilingFactory;
export const treemapSquarify: RatioSquarifyTilingFactory;
export const treemapResquarify: RatioSquarifyTilingFactory;
// -----------------------------------------------------------------------
// Partition
@ -286,7 +281,6 @@ export interface HierarchyCircularNode<Datum> {
copy(): HierarchyCircularNode<Datum>;
}
export interface PackLayout<Datum> {
(root: HierarchyNode<Datum>): HierarchyCircularNode<Datum>;
radius(): null | ((node: HierarchyCircularNode<Datum>) => number);
@ -300,7 +294,6 @@ export interface PackLayout<Datum> {
export function pack<Datum>(): PackLayout<Datum>;
// -----------------------------------------------------------------------
// Pack Siblings and Enclosure
// -----------------------------------------------------------------------

View File

@ -1,79 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
"no-unnecessary-generics": false
}
}