-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
179dad8
commit 8477320
Showing
3 changed files
with
66 additions
and
83 deletions.
There are no files selected for viewing
131 changes: 49 additions & 82 deletions
131
packages/graphin/docs/render/element/demos/edge-default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,64 @@ | ||
import React, { useEffect } from 'react'; | ||
import Graphin, { Utils, Behaviors, GraphinContext } from '@antv/graphin'; | ||
import React from 'react'; | ||
import Graphin, { Utils } from '@antv/graphin'; | ||
|
||
const { ZoomCanvas } = Behaviors; | ||
const nodes = [ | ||
{ | ||
id: 'node-0', | ||
x: 100, | ||
y: 200, | ||
}, | ||
{ | ||
id: 'node-1', | ||
x: 600, | ||
y: 200, | ||
}, | ||
]; | ||
|
||
const EventCenter = () => { | ||
const { graph } = React.useContext(GraphinContext); | ||
useEffect(() => { | ||
// graph.on('edge:mouseenter', evt => { | ||
// graph.setItemState(evt.item, 'selected', true); | ||
// }); | ||
|
||
// graph.on('edge:mouseleave', evt => { | ||
// graph.setItemState(evt.item, 'selected', false); | ||
// }); | ||
|
||
graph.on('edge:click', evt => { | ||
graph.setItemState(evt.item, 'selected', true); | ||
graph.updateItem(evt.item, { | ||
keyshape: { | ||
lineWidth: 15, | ||
stroke: 'red', | ||
}, | ||
}); | ||
}); | ||
}, []); | ||
|
||
return null; | ||
}; | ||
|
||
const data = Utils.mock(10) | ||
.circle() | ||
.graphin(); | ||
const layout = { | ||
type: 'circular', | ||
type: 'preset', | ||
}; | ||
|
||
// const edgeStateStyles = { | ||
// status: { | ||
// selected: { | ||
// stroke: 'red', | ||
// animation: { | ||
// repeat: true, | ||
// }, | ||
// }, | ||
// }, | ||
// }; | ||
const edges1 = Array.from({ length: 5 }).map(() => { | ||
return { | ||
source: 'node-0', | ||
target: 'node-1', | ||
}; | ||
}); | ||
|
||
const edges2 = Array.from({ length: 6 }).map(() => { | ||
return { | ||
source: 'node-1', | ||
target: 'node-0', | ||
}; | ||
}); | ||
|
||
// const defaultEdge = { | ||
// type: 'graphin-edge', | ||
// style: { | ||
// keyshape: { | ||
// stroke: '#000', | ||
// lineWidth: 2, | ||
// }, | ||
// status: { | ||
// selected: { | ||
// halo: { | ||
// visible: true, | ||
// }, | ||
// keyshape: { | ||
// stroke: '#1890ff', | ||
// opacity: 1, | ||
// }, | ||
// }, | ||
// hover: { | ||
// halo: { | ||
// visible: true, | ||
// }, | ||
// }, | ||
// }, | ||
// }, | ||
// }; | ||
const edgesLoop1 = Array.from({ length: 2 }).map(() => { | ||
return { | ||
source: 'node-0', | ||
target: 'node-0', | ||
}; | ||
}); | ||
const edgesLoop2 = Array.from({ length: 3 }).map(() => { | ||
return { | ||
source: 'node-1', | ||
target: 'node-1', | ||
}; | ||
}); | ||
|
||
data.edges.forEach(edge => { | ||
edge.type = 'graphin-edge'; | ||
edge.style = { | ||
label: { | ||
value: `${edge.source} - ${edge.target} `, | ||
}, | ||
const edges = Utils.processEdges([...edges1, ...edges2, ...edgesLoop1, ...edgesLoop2], { poly: 50, loop: 10 }); | ||
edges.forEach((edge, index) => { | ||
const { source, target } = edge; | ||
edge.style.label = { | ||
value: `${index}th:${source}-${target}`, | ||
}; | ||
}); | ||
|
||
const data = { nodes, edges }; | ||
|
||
export default () => { | ||
return ( | ||
<div> | ||
<Graphin | ||
data={data} | ||
layout={layout} | ||
// defaultEdge={defaultEdge} | ||
// edgeStateStyles={edgeStateStyles} | ||
> | ||
<ZoomCanvas /> | ||
<EventCenter /> | ||
</Graphin> | ||
<Graphin data={data} layout={layout} fitView /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
--- | ||
title: 节点样式 | ||
order: 2 | ||
group: | ||
path: /render | ||
|
||
nav: | ||
title: Graphin | ||
path: /graphin | ||
|