-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from techniq/master
Add support for step, curve, and line links. Issue #174
- Loading branch information
Showing
13 changed files
with
397 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/vx-shape/src/shapes/link/curve/LinkHorizontalCurve.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
packages/vx-shape/src/shapes/link/curve/LinkRadialCurve.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
packages/vx-shape/src/shapes/link/curve/LinkVerticalCurve.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/vx-shape/src/shapes/link/line/LinkHorizontalLine.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
packages/vx-shape/src/shapes/link/line/LinkVerticalLine.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
packages/vx-shape/src/shapes/link/step/LinkHorizontalStep.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
/> | ||
); | ||
} |
Oops, something went wrong.