Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hierarchy comps #146

Merged
merged 4 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/vx-hierarchy/src/DefaultLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";

export default function DefaultLink({ link }) {
return (
<line
x1={link.source.x}
y1={link.source.y}
x2={link.target.x}
y2={link.target.y}
strokeWidth={2}
stroke="#999"
strokeOpacity={0.6}
/>
);
}
5 changes: 5 additions & 0 deletions packages/vx-hierarchy/src/DefaultNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from "react";

export default function DefaultNode({ node }) {
return <circle cx={node.x} cy={node.y} r={15} fill="#21D4FD" />;
}
48 changes: 26 additions & 22 deletions packages/vx-hierarchy/src/hierarchies/Cluster.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import cx from 'classnames';
import { Group } from '@vx/group';
import { cluster as d3cluster } from 'd3-hierarchy';
import React from "react";
import cx from "classnames";
import { Group } from "@vx/group";
import { cluster as d3cluster } from "d3-hierarchy";
import DefaultLink from "../DefaultLink";
import DefaultNode from "../DefaultNode";

export default function Cluster({
top,
Expand All @@ -11,8 +13,8 @@ export default function Cluster({
size,
nodeSize,
separation,
linkComponent,
nodeComponent,
linkComponent = DefaultLink,
nodeComponent = DefaultNode,
...restProps
}) {
const cluster = d3cluster();
Expand All @@ -23,21 +25,23 @@ export default function Cluster({
const links = data.links();
const descendants = root.descendants();
return (
<Group top={top} left={left}>
{linkComponent && links.map((link, i) => {
return (
<Group key={`cluster-link-${i}`}>
{React.createElement(linkComponent, { link })}
</Group>
);
})}
{nodeComponent && descendants.map((node, i) => {
return (
<Group key={`cluster-node-${i}`}>
{React.createElement(nodeComponent, { node })}
</Group>
);
})}
<Group top={top} left={left} className={cx("vx-cluster", className)}>
{linkComponent &&
links.map((link, i) => {
return (
<Group key={`cluster-link-${i}`}>
{React.createElement(linkComponent, { link })}
</Group>
);
})}
{nodeComponent &&
descendants.map((node, i) => {
return (
<Group key={`cluster-node-${i}`}>
{React.createElement(nodeComponent, { node })}
</Group>
);
})}
</Group>
);
}
}
48 changes: 26 additions & 22 deletions packages/vx-hierarchy/src/hierarchies/Tree.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import cx from 'classnames';
import { Group } from '@vx/group';
import { tree as d3tree } from 'd3-hierarchy';
import React from "react";
import cx from "classnames";
import { Group } from "@vx/group";
import { tree as d3tree } from "d3-hierarchy";
import DefaultLink from "../DefaultLink";
import DefaultNode from "../DefaultNode";

export default function Tree({
top,
Expand All @@ -11,8 +13,8 @@ export default function Tree({
size,
nodeSize,
separation,
linkComponent,
nodeComponent,
linkComponent = DefaultLink,
nodeComponent = DefaultNode,
...restProps
}) {
const tree = d3tree();
Expand All @@ -23,21 +25,23 @@ export default function Tree({
const links = data.links();
const descendants = root.descendants();
return (
<Group top={top} left={left}>
{linkComponent && links.map((link, i) => {
return (
<Group key={`tree-link-${i}`}>
{React.createElement(linkComponent, { link })}
</Group>
);
})}
{nodeComponent && descendants.map((node, i) => {
return (
<Group key={`tree-node-${i}`}>
{React.createElement(nodeComponent, { node })}
</Group>
);
})}
<Group top={top} left={left} className={cx("vx-tree", className)}>
{linkComponent &&
links.map((link, i) => {
return (
<Group key={`tree-link-${i}`}>
{React.createElement(linkComponent, { link })}
</Group>
);
})}
{nodeComponent &&
descendants.map((node, i) => {
return (
<Group key={`tree-node-${i}`}>
{React.createElement(nodeComponent, { node })}
</Group>
);
})}
</Group>
);
}
}
6 changes: 4 additions & 2 deletions packages/vx-hierarchy/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { default as Tree } from './hierarchies/Tree';
export { default as Cluster } from './hierarchies/Cluster';
export { default as Tree } from "./hierarchies/Tree";
export { default as Cluster } from "./hierarchies/Cluster";
export { default as DefaultLink } from "./DefaultLink";
export { default as DefaultNode } from "./DefaultNode";
13 changes: 13 additions & 0 deletions packages/vx-hierarchy/test/Defaults.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DefaultLink, DefaultNode } from "../src";

describe("<DefaultLink />", () => {
test("it should be defined", () => {
expect(DefaultLink).toBeDefined();
});
});

describe("<DefaultNode />", () => {
test("it should be defined", () => {
expect(DefaultNode).toBeDefined();
});
});