Skip to content

Commit

Permalink
Merge pull request #194 from techniq/master
Browse files Browse the repository at this point in the history
Add support for step, curve, and line links.  Issue #174
  • Loading branch information
hshoff authored Nov 13, 2017
2 parents a4def35 + 6b344bd commit fb39f0c
Show file tree
Hide file tree
Showing 13 changed files with 397 additions and 6 deletions.
15 changes: 12 additions & 3 deletions packages/vx-shape/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ export { default as Pie } from './shapes/Pie';
export { default as Line } from './shapes/Line';
export { default as LinePath } from './shapes/LinePath';
export { default as LineRadial } from './shapes/LineRadial';
export { default as LinkHorizontal } from './shapes/LinkHorizontal';
export { default as LinkVertical } from './shapes/LinkVertical';
export { default as LinkRadial } from './shapes/LinkRadial';
export { default as LinkHorizontal } from './shapes/link/diagonal/LinkHorizontal';
export { default as LinkVertical } from './shapes/link/diagonal/LinkVertical';
export { default as LinkRadial } from './shapes/link/diagonal/LinkRadial';
export { default as LinkHorizontalCurve } from './shapes/link/curve/LinkHorizontalCurve';
export { default as LinkVerticalCurve } from './shapes/link/curve/LinkVerticalCurve';
export { default as LinkRadialCurve } from './shapes/link/curve/LinkRadialCurve';
export { default as LinkHorizontalLine } from './shapes/link/line/LinkHorizontalLine';
export { default as LinkVerticalLine } from './shapes/link/line/LinkVerticalLine';
export { default as LinkRadialLine } from './shapes/link/line/LinkRadialLine';
export { default as LinkHorizontalStep } from './shapes/link/step/LinkHorizontalStep';
export { default as LinkVerticalStep } from './shapes/link/step/LinkVerticalStep';
export { default as LinkRadialStep } from './shapes/link/step/LinkRadialStep';
export { default as Area } from './shapes/Area';
export { default as AreaClosed } from './shapes/AreaClosed';
export { default as AreaStack } from './shapes/AreaStack';
Expand Down
46 changes: 46 additions & 0 deletions packages/vx-shape/src/shapes/link/curve/LinkHorizontalCurve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { pointRadial } from 'd3-shape';
import additionalProps from '../../../util/additionalProps';

LinkHorizontalCurve.propTypes = {
innerRef: PropTypes.func
};

export default function LinkHorizontalCurve({
className,
innerRef,
data,
x = d => d.y,
y = d => d.x,
...restProps
}) {

const curve = (source, target) => {
const sx = x(source);
const sy = y(source);
const tx = x(target);
const ty = y(target);

const dx = tx - sx;
const dy = ty - sy;
const ix = 0.2 * (dx + dy);
const iy = 0.2 * (dy - dx);

return `M${sx},${sy}
C${sx + ix},${sy + iy}
${tx + iy},${ty - ix}
${tx},${ty}
`;
};

return (
<path
ref={innerRef}
className={cx('vx-link', className)}
d={curve(data.source, data.target)}
{...restProps}
/>
);
}
56 changes: 56 additions & 0 deletions packages/vx-shape/src/shapes/link/curve/LinkRadialCurve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { pointRadial } from 'd3-shape';
import additionalProps from '../../../util/additionalProps';

LinkRadialCurve.propTypes = {
innerRef: PropTypes.func
};

export default function LinkRadialCurve({
className,
innerRef,
data,
x = d => d.x,
y = d => d.y,
...restProps
}) {

const curve = (source, target) => {
const sa = x(source) - Math.PI / 2;
const sr = y(source);
const ta = x(target) - Math.PI / 2;
const tr = y(target);

const sc = Math.cos(sa);
const ss = Math.sin(sa);
const tc = Math.cos(ta);
const ts = Math.sin(ta);

const sx = sr * sc;
const sy = sr * ss;
const tx = tr * tc;
const ty = tr * ts;

const dx = tx - sx;
const dy = ty - sy;
const ix = 0.2 * (dx + dy);
const iy = 0.2 * (dy - dx);

return `M${sx},${sy}
C${sx + ix},${sy + iy}
${tx + iy},${ty - ix}
${tx},${ty}
`;
};

return (
<path
ref={innerRef}
className={cx('vx-link', className)}
d={curve(data.source, data.target)}
{...restProps}
/>
);
}
46 changes: 46 additions & 0 deletions packages/vx-shape/src/shapes/link/curve/LinkVerticalCurve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { pointRadial } from 'd3-shape';
import additionalProps from '../../../util/additionalProps';

LinkVerticalCurve.propTypes = {
innerRef: PropTypes.func
};

export default function LinkVerticalCurve({
className,
innerRef,
data,
x = d => d.x,
y = d => d.y,
...restProps
}) {

const curve = (source, target) => {
const sx = x(source);
const sy = y(source);
const tx = x(target);
const ty = y(target);

const dx = tx - sx;
const dy = ty - sy;
const ix = 0.2 * (dx + dy);
const iy = 0.2 * (dy - dx);

return `M${sx},${sy}
C${sx + ix},${sy + iy}
${tx + iy},${ty - ix}
${tx},${ty}
`;
};

return (
<path
ref={innerRef}
className={cx('vx-link', className)}
d={curve(data.source, data.target)}
{...restProps}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { linkHorizontal } from 'd3-shape';
import additionalProps from '../util/additionalProps';
import additionalProps from '../../../util/additionalProps';

LinkHorizontal.propTypes = {
innerRef: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { linkRadial } from 'd3-shape';
import additionalProps from '../util/additionalProps';
import additionalProps from '../../../util/additionalProps';

LinkRadial.propTypes = {
innerRef: PropTypes.func,
};

export default function LinkRadial({
className,
innerRef,
data,
angle = d => d.x,
radius = d => d.y,
Expand All @@ -15,6 +21,7 @@ export default function LinkRadial({
link.radius(radius);
return (
<path
ref={innerRef}
className={cx('vx-link-radius', className)}
d={link(data)}
{...additionalProps(restProps, data)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { linkVertical } from 'd3-shape';
import additionalProps from '../util/additionalProps';
import additionalProps from '../../../util/additionalProps';

LinkVertical.propTypes = {
innerRef: PropTypes.func,
Expand Down
31 changes: 31 additions & 0 deletions packages/vx-shape/src/shapes/link/line/LinkHorizontalLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import additionalProps from '../../../util/additionalProps';

LinkHorizontalLine.propTypes = {
innerRef: PropTypes.func
};

export default function LinkHorizontalLine({
className,
innerRef,
data,
x = d => d.y,
y = d => d.x,
...restProps
}) {
const line = (source, target) => `
M${x(source)},${y(source)}
L${x(target)},${y(target)}
`;

return (
<path
ref={innerRef}
className={cx('vx-link', className)}
d={line(data.source, data.target)}
{...restProps}
/>
);
}
45 changes: 45 additions & 0 deletions packages/vx-shape/src/shapes/link/line/LinkRadialLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { pointRadial } from 'd3-shape';
import additionalProps from '../../../util/additionalProps';

LinkRadialStep.propTypes = {
innerRef: PropTypes.func
};

export default function LinkRadialStep({
className,
innerRef,
data,
x = d => d.x,
y = d => d.y,
...restProps
}) {

const line = (source, target) => {
const sa = x(source) - Math.PI / 2;
const sr = y(source);
const ta = x(target) - Math.PI / 2;
const tr = y(target);

const sc = Math.cos(sa);
const ss = Math.sin(sa);
const tc = Math.cos(ta);
const ts = Math.sin(ta);

return `
M${sr * sc},${sr * ss}
L${tr * tc},${tr * ts}
`;
};

return (
<path
ref={innerRef}
className={cx('vx-link', className)}
d={line(data.source, data.target)}
{...restProps}
/>
);
}
31 changes: 31 additions & 0 deletions packages/vx-shape/src/shapes/link/line/LinkVerticalLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import additionalProps from '../../../util/additionalProps';

LinkVerticalLine.propTypes = {
innerRef: PropTypes.func
};

export default function LinkVerticalLine({
className,
innerRef,
data,
x = d => d.x,
y = d => d.y,
...restProps
}) {
const line = (source, target) => `
M${x(source)},${y(source)}
L${x(target)},${y(target)}
`;

return (
<path
ref={innerRef}
className={cx('vx-link', className)}
d={line(data.source, data.target)}
{...restProps}
/>
);
}
35 changes: 35 additions & 0 deletions packages/vx-shape/src/shapes/link/step/LinkHorizontalStep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import additionalProps from '../../../util/additionalProps';

LinkHorizontalStep.propTypes = {
innerRef: PropTypes.func,
percent: PropTypes.number
};

export default function LinkHorizontalStep({
className,
innerRef,
data,
percent = 0.5,
x = d => d.y,
y = d => d.x,
...restProps
}) {
const line = (source, target) => `
M${x(source)},${y(source)}
H${x(source) + (x(target) - x(source)) * percent}
V${y(target)}
H${x(target)}
`;

return (
<path
ref={innerRef}
className={cx('vx-link', className)}
d={line(data.source, data.target)}
{...restProps}
/>
);
}
Loading

0 comments on commit fb39f0c

Please sign in to comment.