Skip to content

Commit

Permalink
✨ feat: edge border raduis type
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangchu committed Sep 19, 2023
1 parent 96e3b7c commit 92a900f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/BasicEdge/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { BaseEdge, EdgeProps, getSmoothStepPath } from 'reactflow';

export default function RadiusEdge({
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
style = {},
markerEnd,
}: EdgeProps) {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
borderRadius: 50,
});

return (
<>
<BaseEdge path={edgePath} markerEnd={markerEnd} style={style} />
</>
);
}
23 changes: 23 additions & 0 deletions src/ProFlow/demos/ProFlowDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ const nodes: ProFlowNode[] = [
describe: 'XXX_XXX_XXX_API',
},
},
{
id: 'b1',
select: NodeSelect.DANGER,
data: {
title: 'XXX_API',
logo: 'https://mdn.alipayobjects.com/huamei_ntgeqc/afts/img/A*kgyiRKi04eUAAAAAAAAAAAAADvuvAQ/original',
describe: 'XXX_XXX_XXX_API',
},
},
{
id: 'a3',
select: NodeSelect.WARNING,
Expand Down Expand Up @@ -115,6 +124,20 @@ const edges = [
id: 'a1-a2',
source: 'a1',
target: 'a2',
type: 'smoothstep',
pathOptions: {
borderRadius: 20,
},
},
{
id: 'a1-b1',
source: 'a1',
target: 'b1',
type: 'smoothstep',
pathOptions: {
offset: 20,
borderRadius: 20,
},
},
{
id: 'a2-a3',
Expand Down
5 changes: 3 additions & 2 deletions src/ProFlow/helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ function getEdgeClsFromNodeSelect(select: NodeSelect) {
}
}

function getRenderEdge(node: NodeMapItem, targetNode: NodeMapItem): Edge {
function getRenderEdge(node: NodeMapItem, targetNode: NodeMapItem) {
const { id } = node;
const { id: targetId, select = NodeSelect.DEFAULT } = targetNode;

return {
id: `${id}-${targetId}`,
source: id!,
target: targetId!,
type: 'smoothstep',
type: 'radiusEdge',
className: getEdgeClsFromNodeSelect(select),
};
}
Expand Down
10 changes: 9 additions & 1 deletion src/ProFlow/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import RadiusEdge from '@/BasicEdge';
import ProFlowController from '@/ProFlowController';
import React, { useMemo, type CSSProperties, type MouseEvent as ReactMouseEvent } from 'react';
import ReactFlow, { Background, BackgroundVariant, Edge, Node } from 'reactflow';
import ReactFlow, { Background, BackgroundVariant, Edge, Node, useEdgesState } from 'reactflow';
import { ProFLowEdge, ProFlowNode } from './constants';
import { convertMappingFrom, getRenderData } from './helper';
import { useStyles } from './styles';
Expand Down Expand Up @@ -40,6 +41,10 @@ const ProFlow: React.FC<Partial<ProFlowProps>> = (props) => {
};
}
}, [mapping]);
const [_edges] = useEdgesState(renderData.edges);

console.log(renderData.edges);
console.log(_edges);

return (
<ReactFlow
Expand All @@ -49,6 +54,9 @@ const ProFlow: React.FC<Partial<ProFlowProps>> = (props) => {
onNodeClick={onNodeClick}
nodes={renderData.nodes}
edges={renderData.edges}
edgeTypes={{
radiusEdge: RadiusEdge,
}}
panOnScroll
fitView
minZoom={MIN_ZOOM}
Expand Down

0 comments on commit 92a900f

Please sign in to comment.