-
Notifications
You must be signed in to change notification settings - Fork 730
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
Add support for step, curve, and line links. Issue #174 #194
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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} | ||
/> | ||
); | ||
} |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I played around with this but I didn't see much benefit as this is being built using cubic bezier curves ( I took a quick stab at using a simpler quadratic curve ( I've kicked around the idea in my head a bit and part of me thinks exposing const step = (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 sf = Math.abs(ta - sa) > Math.PI ? ta <= sa : ta > sa;
return `
M${sr * sc},${sr * ss}
A${sr},${sr} 0 0,${sf ? 1 : 0}
${sr * tc},${sr * ts}
L${tr * tc},${tr * ts}
`;
}; I haven't looked to much into the details on how to implement this (looks like you you're supposed to use the custom curves api). This might also be overkill for 2 points... I still think exposing the simple |
||
|
||
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 |
---|---|---|
@@ -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 |
---|---|---|
@@ -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} | ||
/> | ||
); | ||
} |
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} | ||
/> | ||
); | ||
} |
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} | ||
/> | ||
); | ||
} |
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} | ||
/> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will probably need to export
./shapes/link/diagonal/{LinkHorizontal, LinkVertical, LinkRadial}
from./shapes/{LinkHorizontal, LinkVertical, LinkRadial}
else it's a breaking change for folks deep linking to the componentsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to fix this but was running into problems (I don't know if it was from Lerna or something else).
For example, I recreated
src/shapes/LinkHorizontal.js
and addedexport * from './link/diagonal/LinkHorizontal';
to re-export from this location, but when I tried up update the reference invx-demo
tree.js
fromto
I'm getting a dependency error.
I tried running
npm run build
withinvx-shape
and restartingnpm run dev
on `vx-demo.Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this work?
then run
npm run build
invx-shape
againThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not.
After that change, I also tried importing using
and
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, i'll take a look after merging.