Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components):add EdgeBundling demos
- Loading branch information
1 parent
b9d86fb
commit 24d471d
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
packages/graphin-components/src/EdgeBundling/demos/index.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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import Graphin, { Utils, GraphinContext } from '@antv/graphin'; | ||
import { ContextMenu, EdgeBundling } from '@antv/graphin-components'; | ||
import G6 from '@antv/g6'; | ||
|
||
// Do not forget to import CSS | ||
import '@antv/graphin/dist/index.css'; | ||
|
||
const data = Utils.mock(5).graphin(); | ||
const { edges } = data; | ||
data.edges = [ | ||
...edges.map((edge) => { | ||
return { | ||
...edge, | ||
// label: Math.random(), | ||
}; | ||
}), | ||
...edges.map((edge) => { | ||
return { | ||
...edge, | ||
// label: Math.random() * 2, | ||
}; | ||
}), | ||
...edges.map((edge) => { | ||
return { | ||
...edge, | ||
// label: Math.random() * 5, | ||
}; | ||
}), | ||
...edges.map((edge) => { | ||
return { | ||
...edge, | ||
// label: Math.random() * 10, | ||
}; | ||
}), | ||
]; | ||
|
||
G6.Util.processParallelEdges(data.edges); | ||
|
||
console.log('edge', data.edges); | ||
const App = () => { | ||
return ( | ||
<div className="App"> | ||
<Graphin | ||
data={data} | ||
layout={{ type: 'circle' }} | ||
defaultEdge={{ | ||
type: 'quadratic', | ||
labelCfg: { | ||
autoRotate: true, | ||
}, | ||
}} | ||
> | ||
<EdgeBundling /> | ||
</Graphin> | ||
</div> | ||
); | ||
}; | ||
export default App; |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: EdgeBundling 边绑定 | ||
group: | ||
path: /analysis | ||
title: 分析组件 | ||
nav: | ||
title: Components | ||
path: /components | ||
order: 1 | ||
--- | ||
|
||
# EdgeBundling | ||
|
||
<code src='./demos/index.tsx'> | ||
|
||
## 用法 | ||
|
||
```tsx | pure | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import Graphin, { Utils } from '@antv/graphin'; | ||
import { EdgeBundling } from '@antv/graphin-components'; | ||
import '@antv/graphin/dist/index.css'; | ||
import '@antv/graphin-components/dist/index.css'; | ||
|
||
const App = () => { | ||
const handleCloseCallback = () => {}; | ||
|
||
return ( | ||
<div className="App"> | ||
<Graphin data={Utils.mock(10).graphin()}> | ||
<EdgeBundling /> | ||
</Graphin> | ||
</div> | ||
); | ||
}; | ||
|
||
const rootElement = document.getElementById('root'); | ||
ReactDOM.render(<App />, rootElement); | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
|
||
import { GraphinContext, G6 } from '@antv/graphin'; | ||
|
||
interface IEdgeBundlingProps {} | ||
let edgeBundling; | ||
const EdgeBundling: React.FunctionComponent<IEdgeBundlingProps> = (props) => { | ||
const { graph } = React.useContext(GraphinContext); | ||
|
||
React.useEffect(() => { | ||
edgeBundling = new G6.Bundling({ | ||
bundleThreshold: 0.6, | ||
K: 100, | ||
}); | ||
const data = graph.save(); | ||
graph.addPlugin(edgeBundling); | ||
edgeBundling.bundling(data); | ||
graph.data(data); | ||
graph.render(); | ||
}, []); | ||
|
||
return null; | ||
}; | ||
|
||
export default EdgeBundling; |
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