Skip to content

Commit

Permalink
feat(markers): add option to control orientation of markers
Browse files Browse the repository at this point in the history
  • Loading branch information
chrtze committed Oct 15, 2021
1 parent 1b73c8f commit b08809d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .release-it.json
Expand Up @@ -7,6 +7,6 @@
},
"hooks": {
"after:bump": "npm run build",
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
"after:release": "echo Successfully released ${name} v${version}."
}
}
58 changes: 31 additions & 27 deletions example/src/Edges/index.tsx
Expand Up @@ -41,33 +41,6 @@ const initialElements: Elements = [
{ id: 'e3-4', source: '3', target: '4', type: 'straight', label: 'straight edge' },
{ id: 'e3-3a', source: '3', target: '3a', type: 'straight', label: 'label only edge', style: { stroke: 'none' } },
{ id: 'e3-5', source: '4', target: '5', animated: true, label: 'animated styled edge', style: { stroke: 'red' } },
{
id: 'e5-6',
source: '5',
target: '6',
label: (
<>
<tspan>i am using</tspan>
<tspan dy={10} x={0}>
{'<tspan>'}
</tspan>
</>
),
labelStyle: { fill: 'red', fontWeight: 700 },
style: { stroke: '#ffcc00' },
markerEnd: {
type: ArrowHeadType.Arrow,
color: '#FFCC00',
units: 'userSpaceOnUse',
width: 20,
height: 20,
strokeWidth: 2,
},
markerStart: {
type: ArrowHeadType.Arrow,
color: '#FFCC00',
},
},
{
id: 'e5-7',
source: '5',
Expand All @@ -94,6 +67,37 @@ const initialElements: Elements = [
type: 'custom2',
data: { text: 'custom edge 2' },
},
{
id: 'e5-6',
source: '5',
target: '6',
label: (
<>
<tspan>i am using</tspan>
<tspan dy={10} x={0}>
{'<tspan>'}
</tspan>
</>
),
labelStyle: { fill: 'red', fontWeight: 700 },
style: { stroke: '#ffcc00' },
markerEnd: {
type: ArrowHeadType.Arrow,
color: '#FFCC00',
units: 'userSpaceOnUse',
width: 20,
height: 20,
strokeWidth: 2,
},
markerStart: {
type: ArrowHeadType.ArrowClosed,
color: '#FFCC00',
orient: 'auto-start-reverse',
units: 'userSpaceOnUse',
width: 20,
height: 20,
},
},
];

const edgeTypes: EdgeTypesType = {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "react-flow-renderer",
"version": "9.6.9",
"version": "10.0.0-next.1",
"engines": {
"node": ">=12"
},
Expand Down Expand Up @@ -28,7 +28,7 @@
"cy:open": "cypress open",
"release": "npm run test && release-it",
"release:notest": "release-it",
"release:next": "release-it --preRelease=next"
"release:next": "release-it --preRelease=next --no-git"
},
"dependencies": {
"@babel/runtime": "^7.15.4",
Expand Down
14 changes: 12 additions & 2 deletions src/container/EdgeRenderer/MarkerDefinitions.tsx
Expand Up @@ -42,7 +42,16 @@ const markerSymbols = {
[ArrowHeadType.ArrowClosed]: ArrowClosedSymbol,
};

const Marker = ({ id, type, color, width = 12.5, height = 12.5, units = 'strokeWidth', strokeWidth }: MarkerProps) => {
const Marker = ({
id,
type,
color,
width = 12.5,
height = 12.5,
units = 'strokeWidth',
strokeWidth,
orient = 'auto',
}: MarkerProps) => {
const Symbol = markerSymbols[type];

return (
Expand All @@ -53,7 +62,7 @@ const Marker = ({ id, type, color, width = 12.5, height = 12.5, units = 'strokeW
markerWidth={`${width}`}
markerHeight={`${height}`}
viewBox="-10 -10 20 20"
orient="auto"
orient={orient}
refX="0"
refY="0"
>
Expand Down Expand Up @@ -93,6 +102,7 @@ const MarkerDefinitions = ({ defaultColor }: MarkerDefinitionsProps) => {
height={marker.height}
units={marker.units}
strokeWidth={marker.strokeWidth}
orient={marker.orient}
/>
))}
</defs>
Expand Down
3 changes: 2 additions & 1 deletion src/types/index.ts
Expand Up @@ -62,7 +62,8 @@ export interface EdgeMarker {
color?: string;
width?: number;
height?: number;
units?: 'userSpaceOnUse' | 'strokeWidth';
units?: string;
orient?: string;
strokeWidth?: number;
}

Expand Down

0 comments on commit b08809d

Please sign in to comment.