diff --git a/package.json b/package.json index 5e10e54a0..bdbc4ecfc 100644 --- a/package.json +++ b/package.json @@ -6,18 +6,30 @@ "scripts": { "test": "lerna exec npm install && jest", "docs": "node ./scripts/docs/index.js", - "prepare-release": - "git checkout master && git pull --rebase origin master && npm run docs && lerna updated", + "prepare-release": "git checkout master && git pull --rebase origin master && npm run docs && lerna updated", "release": "npm run prepare-release && lerna publish --exact" }, "jest": { - "projects": ["/packages/*"], + "projects": [ + "/packages/*" + ], "collectCoverage": true, "coverageDirectory": "/coverage", - "coveragePathIgnorePatterns": ["/node_modules/"], - "coverageReporters": ["text", "lcov"] + "coveragePathIgnorePatterns": [ + "/node_modules/" + ], + "coverageReporters": [ + "text", + "lcov" + ] }, - "keywords": ["react", "d3", "visualization", "vx", "charts"], + "keywords": [ + "react", + "d3", + "visualization", + "vx", + "charts" + ], "author": "@hshoff", "license": "MIT", "devDependencies": { diff --git a/packages/vx-hierarchy/src/hierarchies/Cluster.js b/packages/vx-hierarchy/src/hierarchies/Cluster.js index 3d4d123aa..753049289 100644 --- a/packages/vx-hierarchy/src/hierarchies/Cluster.js +++ b/packages/vx-hierarchy/src/hierarchies/Cluster.js @@ -28,9 +28,8 @@ export default function Cluster({ if (size) cluster.size(size); if (nodeSize) cluster.nodeSize(nodeSize); if (separation) cluster.separation(separation); + const data = cluster(root); - const links = data.links(); - const descendants = root.descendants(); if (!!children) { return ( @@ -39,7 +38,7 @@ export default function Cluster({ left={left} className={cx('vx-cluster', className)} > - {children({ data, links, root, descendants })} + {children({ data })} ); } @@ -51,7 +50,7 @@ export default function Cluster({ className={cx('vx-cluster', className)} > {linkComponent && - links.map((link, i) => { + data.links().map((link, i) => { return ( {React.createElement(linkComponent, { link })} @@ -59,7 +58,7 @@ export default function Cluster({ ); })} {nodeComponent && - descendants.map((node, i) => { + data.descendants().map((node, i) => { return ( {React.createElement(nodeComponent, { node })} diff --git a/packages/vx-hierarchy/src/hierarchies/Pack.js b/packages/vx-hierarchy/src/hierarchies/Pack.js new file mode 100644 index 000000000..362017be2 --- /dev/null +++ b/packages/vx-hierarchy/src/hierarchies/Pack.js @@ -0,0 +1,52 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import cx from 'classnames'; +import { Group } from '@vx/group'; +import { pack as d3pack } from 'd3-hierarchy'; +import DefaultNode from '../HierarchyDefaultNode'; + +Pack.propTypes = { + root: PropTypes.object.isRequired, + children: PropTypes.func +}; + +export default function Pack({ + top, + left, + className, + root, + radius, + size, + padding, + children, + nodeComponent = DefaultNode, + ...restProps +}) { + const pack = d3pack(); + if (size) pack.size(size); + if (radius) pack.radius(radius); + if (padding) pack.padding(padding); + + const data = pack(root); + + if (!!children) { + return ( + + {children({ data })} + + ); + } + + return ( + + {nodeComponent && + data.descendants().map((node, i) => { + return ( + + {React.createElement(nodeComponent, { node })} + + ); + })} + + ); +} diff --git a/packages/vx-hierarchy/src/hierarchies/Partition.js b/packages/vx-hierarchy/src/hierarchies/Partition.js new file mode 100644 index 000000000..78d55f18b --- /dev/null +++ b/packages/vx-hierarchy/src/hierarchies/Partition.js @@ -0,0 +1,52 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import cx from 'classnames'; +import { Group } from '@vx/group'; +import { partition as d3partition } from 'd3-hierarchy'; +import DefaultNode from '../HierarchyDefaultNode'; + +Partition.propTypes = { + root: PropTypes.object.isRequired, + children: PropTypes.func +}; + +export default function Partition({ + top, + left, + className, + root, + size, + round, + padding, + children, + nodeComponent = DefaultNode, + ...restProps +}) { + const partition = d3partition(); + if (size) partition.size(size); + if (round) partition.round(round); + if (padding) partition.padding(padding); + + const data = partition(root); + + if (!!children) { + return ( + + {children({ data })} + + ); + } + + return ( + + {nodeComponent && + data.descendants().map((node, i) => { + return ( + + {React.createElement(nodeComponent, { node })} + + ); + })} + + ); +} diff --git a/packages/vx-hierarchy/src/hierarchies/Tree.js b/packages/vx-hierarchy/src/hierarchies/Tree.js index 361df9ccc..a5b989bbc 100644 --- a/packages/vx-hierarchy/src/hierarchies/Tree.js +++ b/packages/vx-hierarchy/src/hierarchies/Tree.js @@ -30,8 +30,6 @@ export default function Tree({ if (separation) tree.separation(separation); const data = tree(root); - const links = data.links(); - const descendants = root.descendants(); if (!!children) { return ( @@ -40,7 +38,7 @@ export default function Tree({ left={left} className={cx('vx-tree', className)} > - {children({ data, links, root, descendants })} + {children({ data })} ); } @@ -48,7 +46,7 @@ export default function Tree({ return ( {linkComponent && - links.map((link, i) => { + data.links().map((link, i) => { return ( {React.createElement(linkComponent, { link })} @@ -56,7 +54,7 @@ export default function Tree({ ); })} {nodeComponent && - descendants.map((node, i) => { + data.descendants().map((node, i) => { return ( {React.createElement(nodeComponent, { node })} diff --git a/packages/vx-hierarchy/src/hierarchies/Treemap.js b/packages/vx-hierarchy/src/hierarchies/Treemap.js new file mode 100644 index 000000000..0bfa463ab --- /dev/null +++ b/packages/vx-hierarchy/src/hierarchies/Treemap.js @@ -0,0 +1,66 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import cx from 'classnames'; +import { Group } from '@vx/group'; +import { treemap as d3treemap } from 'd3-hierarchy'; +import DefaultNode from '../HierarchyDefaultNode'; + +Treemap.propTypes = { + root: PropTypes.object.isRequired, + children: PropTypes.func +}; + +export default function Treemap({ + top, + left, + className, + root, + tile, + size, + round, + padding, + paddingInner, + paddingOuter, + paddingTop, + paddingRight, + paddingBottom, + paddingLeft, + children, + nodeComponent = DefaultNode, + ...restProps +}) { + const treemap = d3treemap(); + if (tile) treemap.tile(tile); + if (size) treemap.size(size); + if (round) treemap.round(round); + if (padding) treemap.padding(padding); + if (paddingInner) treemap.paddingInner(paddingInner); + if (paddingOuter) treemap.paddingOuter(paddingOuter); + if (paddingTop) treemap.paddingTop(paddingTop); + if (paddingRight) treemap.paddingRight(paddingRight); + if (paddingBottom) treemap.paddingBottom(paddingBottom); + if (paddingLeft) treemap.paddingLeft(paddingLeft); + + const data = treemap(root); + + if (!!children) { + return ( + + {children({ data })} + + ); + } + + return ( + + {nodeComponent && + data.descendants().map((node, i) => { + return ( + + {React.createElement(nodeComponent, { node })} + + ); + })} + + ); +}