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

allow dashed links #397

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
7 changes: 7 additions & 0 deletions src/components/graph/graph.builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ function buildLinkProps(link, nodes, links, config, linkCallbacks, highlightedNo
stroke = config.link.highlightColor === CONST.KEYWORDS.SAME ? config.link.color : config.link.highlightColor;
}

const strokeDasharray = link.strokeDasharray || config.link.strokeDasharray;
const strokeDashoffset = link.strokeDashoffset || config.link.strokeDashoffset;
const strokeLinecap = link.strokeLinecap || config.link.strokeLinecap;

let strokeWidth = (link.strokeWidth || config.link.strokeWidth) * (1 / transform);

if (config.link.semanticStrokeWidth) {
Expand Down Expand Up @@ -142,6 +146,9 @@ function buildLinkProps(link, nodes, links, config, linkCallbacks, highlightedNo
source,
stroke,
strokeWidth,
strokeDasharray,
strokeDashoffset,
strokeLinecap,
target,
onClickLink: linkCallbacks.onClickLink,
onMouseOutLink: linkCallbacks.onMouseOutLink,
Expand Down
13 changes: 13 additions & 0 deletions src/components/graph/graph.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@
* - "CURVE_FULL" - a semicircumference trajectory unites source and target nodes.
* </br>
* <img src="https://github.com/danielcaldas/react-d3-graph/blob/master/docs/rd3g-bend.gif?raw=true" width="820" height="480"/>
* @param {number} [link.strokeDasharray=0] - <a id="link-stroke-dasharray" href="#link-stroke-dasharray">🔗</a> <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray">stroke-dasharray</a>
* The stroke-dasharray attribute defines the pattern of dashes and gaps used to paint the link.
* @param {number} [link.strokeDashoffset=0] - <a id="link-stroke-dashoffset" href="#link-stroke-dashoffset">🔗</a> <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dashoffset">stroke-dashoffset</a>
* The stroke-dashoffset attribute defines an offset on the rendering of the associated dash array.
* @param {string} [link.strokeLinecap="butt"] - <a id="link-stroke-linecap" href="#link-stroke-linecap">🔗</a> <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linecap">stroke-linecap</a>
* The stroke-linecap attribute defines the shape to be used at the start and end of the link.
* The stroke-linecap options are:
* - "butt"
* - "round"
* - "square"
*
* @example
* // A simple config that uses some properties
Expand Down Expand Up @@ -303,5 +313,8 @@ export default {
markerHeight: 6,
markerWidth: 6,
type: "STRAIGHT",
strokeDasharray: 0,
lironhl marked this conversation as resolved.
Show resolved Hide resolved
strokeDashoffset: 0,
strokeLinecap: "butt",
},
};
6 changes: 6 additions & 0 deletions src/components/link/Link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import React from "react";
* markerId="marker-small"
* strokeWidth=1.5
* stroke="green"
* strokeDasharray="5 1"
* strokeDashoffset="3"
* strokeLinecap="round"
* className="link"
* opacity=1
* mouseCursor="pointer"
Expand Down Expand Up @@ -70,6 +73,9 @@ export default class Link extends React.Component {
opacity: this.props.opacity,
fill: "none",
cursor: this.props.mouseCursor,
strokeDasharray: this.props.strokeDasharray,
strokeDashoffset: this.props.strokeDasharray,
strokeLinecap: this.props.strokeLinecap,
};

const lineProps = {
Expand Down
84 changes: 84 additions & 0 deletions test/graph/__snapshots__/graph.snapshot.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -150,6 +153,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -170,6 +176,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -190,6 +199,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -210,6 +222,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -230,6 +245,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -250,6 +268,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -270,6 +291,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -290,6 +314,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -310,6 +337,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -330,6 +360,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -350,6 +383,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -370,6 +406,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -390,6 +429,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -410,6 +452,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -430,6 +475,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -450,6 +498,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -470,6 +521,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -490,6 +544,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -510,6 +567,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -530,6 +590,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -550,6 +613,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -570,6 +636,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -590,6 +659,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -610,6 +682,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -630,6 +705,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -650,6 +728,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand All @@ -670,6 +751,9 @@ exports[`Snapshot - Graph Component should match snapshot 1`] = `
"fill": "none",
"opacity": 1,
"stroke": "#d3d3d3",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": 1.5,
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/link/__snapshots__/link.snapshot.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ exports[`Snapshot - Link Component should match snapshot 1`] = `
"fill": "none",
"opacity": "1",
"stroke": "red",
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt",
"strokeWidth": "2",
}
}
Expand Down
14 changes: 13 additions & 1 deletion test/link/link.snapshot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ describe("Snapshot - Link Component", () => {
that.callbackMock = jest.fn();

that.link = renderer.create(
<Link x1="2" y1="2" x2="4" y2="4" opacity="1" stroke="red" strokeWidth="2" onClickLink={that.callbackMock} />
<Link
x1="2"
y1="2"
x2="4"
y2="4"
opacity="1"
stroke="red"
strokeWidth="2"
onClickLink={that.callbackMock}
strokeDasharray={0}
strokeDashoffset={0}
strokeLinecap="butt"
/>
);

that.tree = that.link.toJSON();
Expand Down