-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update ActivateRelations asset
- Loading branch information
1 parent
4f5c5e7
commit 3683a99
Showing
8 changed files
with
75 additions
and
14 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { extend, Graph } from '@antv/g6'; | ||
|
||
/** | ||
* | ||
* @param type 交互名称 | ||
* @param instance 交互实例 | ||
*/ | ||
const registerBehavior = (name, instance) => { | ||
extend(Graph, { | ||
behaviors: { | ||
[name]: instance, | ||
}, | ||
}); | ||
}; | ||
export default registerBehavior; |
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,44 @@ | ||
import { isEmpty } from 'lodash-es'; | ||
import React from 'react'; | ||
import { GraphinContext } from '../useGraphin'; | ||
|
||
interface Props { | ||
type: string; | ||
defaultConfig: Record<string, unknown>; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
userProps: any; | ||
mode?: string; | ||
} | ||
|
||
const useBehaviorHook = (params: Props) => { | ||
const { type, defaultConfig, userProps, mode = 'default' } = params; | ||
const { graph } = React.useContext(GraphinContext); | ||
const { disabled, ...otherConfig } = userProps; | ||
|
||
React.useEffect(() => { | ||
if (!graph || graph.destroyed || isEmpty(graph)) { | ||
return; | ||
} | ||
/** 保持单例 */ | ||
graph.removeBehaviors([type], mode); | ||
|
||
if (disabled) { | ||
return; | ||
} | ||
graph.addBehaviors( | ||
{ | ||
type, | ||
...defaultConfig, | ||
...otherConfig, | ||
}, | ||
mode, | ||
); | ||
return () => { | ||
if (!graph.destroyed) { | ||
graph.removeBehaviors(type, mode); | ||
} | ||
}; | ||
}, []); | ||
}; | ||
|
||
export default useBehaviorHook; |
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