The most basic role of Graphin is the React component. The following table is the interface description of <Graphin />
.
Property name | type | Default value | Description |
---|---|---|---|
data | GraphinProps.data | - | Data Structure |
layout | Layout | {type:"grid"} | Set Layout |
theme | ThemeType | {mode:"#light",...} | Set theme |
ref | ReactRef | - | Graphin component Ref |
width | number | - | Graphin canvas width, it is recommended to set the width through the parent element container, the default width is 100% |
height | number | - | Graphin canvas height, it is recommended to set the width through the parent element container, the default minHeight is 500px |
style | React.CSSProperties | {height: '100%',width: '100%',background: '#fff'} | Graphin container stle |
containerId | string | graphin-container | Graphin container ID, It is used in multi-instance management scenarios |
containerStyle | React.CSSProperties | {height: '100%',width: '100%',position: 'relative'} | Graphin container style |
modes | G6.Modes | - | Recommended use Behaviors |
plugins | G6.Plugins | - | Recommended Components |
defaultNode | Default style configuration of node | ||
defaultEdge | Default edge style configuration | ||
defaultCombo | Combo's default style configuration | ||
nodeStateStyles | Node style configuration in different states | ||
edgeStateStyles | Edge style configuration in different states | ||
comboStateStyles | Combo style configuration in different states | ||
fitView | boolean | false | Whether to enable canvas adaptation. The image automatically adapts to the canvas size after opening |
fitCenter | boolean | false | After opening, the graph will be translated, the center of the graph will be aligned to the center of the canvas, but not zoomed. Priority is lower than fitView |
fitViewPadding | number[] | [0,0] | Take effect when fitView is true. When the figure adapts to the canvas, specify the space around it |
minZoom | number | 0.2 | Minimum zoom ratio |
maxZoom | number | 10 | Maximum zoom ratio |
enabledStack | boolean | false | Whether to enable stack, that is, whether to enable redo & undo function |
maxStep | number | 10 | redo & undo maximum number of steps, only works when enabledStack is true |
import React from 'react';import Graphin, { Utils } from '@antv/graphin';const data = Utils.mock(10).circle().graphin();const Demo = () => {const graphinRef = React.createRef();React.useEffect(() => {const {graph, // Graph instance of g6apis, // API interface provided by Graphin} = graphinRef.current;console.log('ref', graphinRef, graph, apis);}, []);return (<div className="App"><Graphin data={data} ref={graphinRef}></Graphin></div>);};export default Demo;
import React from 'react';import Graphin, { Utils, GraphinContext } from '@antv/graphin';const data = Utils.mock(10).circle().graphin();const CustomComponents = () => {// As long as the components wrapped in Graphin, you can obtain graph instances and apis provided by Graphin through Contextconst { graph, apis } = React.useContext(GraphinContext);return null;};const Demo = () => {return (<div className="App"><Graphin data={data} ref={graphinRef}><CustomComponents /></Graphin></div>);};export default Demo;
Refer to the instance of G6 graph: https://g6.antv.vision/en/docs/api/graphFunc/get_set
The commonly used methods are as follows:
In the future iterations of Graphin versions, commonly used interfaces will be aggregated on the upper layer of Graphin.
Name | Description | Type | Default |
---|---|---|---|
handleAutoZoom | -- | () => { text: string; ratio: number; } | (required) |
handleRealZoom | -- | () => { text: string; ratio: number; } | (required) |
handleChangeZoom | -- | () => { text: string; ratio: number; } | (required) |
handleZoomIn | -- | () => { text: string; ratio: number; } | (required) |
handleZoomOut | -- | () => { text: string; ratio: number; } | (required) |
focusNodeById | -- | (nodeId: string) => void | (required) |
highlightNodeById | -- | (nodeId: string[]) => void | (required) |