Skip to content

Commit

Permalink
✨ feat: edge 展示level区分优先级
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangchu committed Oct 23, 2023
1 parent ad13b27 commit 67e2b38
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/ProFlow/demos/ProFlowDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const nodes: ProFlowNode[] = [
{
id: 'd1',
group: true,
select: NodeSelect.WARNING,
select: NodeSelect.SUB_SELECT,
label: '456',
data: [
{
Expand Down Expand Up @@ -198,7 +198,7 @@ const edges = [
{
id: 'a1-b1',
source: 'a1',
select: NodeSelect.WARNING,
select: NodeSelect.SUB_WARNING,
target: 'b1',
type: EdgeType.default,
},
Expand Down
48 changes: 37 additions & 11 deletions src/ProFlow/helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,44 @@ function getEdgeClsFromNodeSelect(select: NodeSelect) {
}
}

function getEdgeLevel(select: NodeSelect) {
switch (select) {
case NodeSelect.SELECT:
return 6;
case NodeSelect.SUB_SELECT:
return 5;
case NodeSelect.DANGER:
return 4;
case NodeSelect.SUB_DANGER:
return 3;
case NodeSelect.WARNING:
return 2;
case NodeSelect.SUB_WARNING:
return 1;
default:
return 0;
}
}

export function getRenderEdges(edges: ProFlowEdge[]) {
return edges.map((edge) => {
const { source, target, select = NodeSelect.DEFAULT } = edge;

return {
id: `${source}-${target}`,
source,
target,
type: 'radiusEdge',
className: getEdgeClsFromNodeSelect(select),
};
});
console.log(edges);
return edges
.sort((a, b) => {
const aLevel = a.select ? getEdgeLevel(a.select) : 0;
const bLevel = b.select ? getEdgeLevel(b.select) : 0;
return aLevel - bLevel;
})
.map((edge) => {
const { source, target, select = NodeSelect.DEFAULT } = edge;

return {
id: `${source}-${target}`,
source,
target,
type: 'radiusEdge',
className: getEdgeClsFromNodeSelect(select),
};
});
}

export const getRenderData = (
Expand Down

0 comments on commit 67e2b38

Please sign in to comment.