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
228241e
commit ad46384
Showing
4 changed files
with
85 additions
and
11 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
import React from 'react'; | ||
import Graphin, { IG6GraphEvent, Utils, GraphinData } from '@antv/graphin'; | ||
import { INode, NodeConfig } from '@antv/g6'; | ||
|
||
const data: GraphinData = Utils.mock(8) | ||
.circle() | ||
.graphin(); | ||
|
||
Graphin.registerBehavior('sampleBehavior', { | ||
getEvents() { | ||
return { | ||
'node:click': 'onClick', | ||
}; | ||
}, | ||
onClick(evt: IG6GraphEvent) { | ||
const node = evt.item as INode; | ||
const model = node.getModel() as NodeConfig; | ||
console.log(model); | ||
// TODO | ||
}, | ||
}); | ||
|
||
/** | ||
* @example | ||
* https://g6.antv.vision/zh/docs/api/Behavior | ||
*/ | ||
export default () => { | ||
return <Graphin data={data} layout={{ type: 'concentric' }} modes={{ default: ['sampleBehavior'] }} />; | ||
}; |
37 changes: 37 additions & 0 deletions
37
packages/graphin/docs/register/behaviors/graphin-style.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,37 @@ | ||
import React, { useContext, useEffect } from 'react'; | ||
import Graphin, { IG6GraphEvent, Utils, GraphinData, GraphinContext } from '@antv/graphin'; | ||
import { INode, NodeConfig } from '@antv/g6'; | ||
|
||
const data: GraphinData = Utils.mock(8) | ||
.circle() | ||
.graphin(); | ||
|
||
const SampleBehavior = () => { | ||
const { graph } = useContext(GraphinContext); | ||
|
||
useEffect(() => { | ||
const handleClick = (evt: IG6GraphEvent) => { | ||
const node = evt.item as INode; | ||
const model = node.getModel() as NodeConfig; | ||
console.log(model); | ||
// TODO | ||
}; | ||
graph.on('node:click', handleClick); | ||
return () => { | ||
graph.off('node:click', handleClick); | ||
}; | ||
}, []); | ||
return null; | ||
}; | ||
|
||
/** | ||
* @example | ||
* https://g6.antv.vision/zh/docs/api/Behavior | ||
*/ | ||
export default () => { | ||
return ( | ||
<Graphin data={data} layout={{ type: 'concentric' }}> | ||
<SampleBehavior /> | ||
</Graphin> | ||
); | ||
}; |
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,19 @@ | ||
--- | ||
title: 注册Behaviors | ||
order: 0 | ||
group: | ||
path: /register | ||
title: 注册机制 | ||
nav: | ||
title: Graphin | ||
path: /graphin | ||
order: 5 | ||
--- | ||
|
||
## 【推荐】 Graphin 注册 Behavior | ||
|
||
<code src='./graphin-style.tsx'> | ||
|
||
## 【兼容】 G6 注册 Behavior 的写法 | ||
|
||
<code src='./g6-style.tsx'> |