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
Showing
2 changed files
with
100 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react' | ||
import { Graph } from '@antv/x6' | ||
import '../index.less' | ||
|
||
export default class Example extends React.Component { | ||
private container: HTMLDivElement | ||
|
||
componentDidMount() { | ||
const graph = new Graph({ | ||
container: this.container, | ||
width: 800, | ||
height: 600, | ||
grid: true, | ||
}) | ||
|
||
const source = graph.addNode({ | ||
shape: 'html', | ||
x: 80, | ||
y: 80, | ||
width: 160, | ||
height: 60, | ||
html: () => { | ||
const wrap = document.createElement('div') | ||
wrap.style.width = '100%' | ||
wrap.style.height = '100%' | ||
wrap.style.background = '#f0f0f0' | ||
wrap.style.display = 'flex' | ||
wrap.style.justifyContent = 'center' | ||
wrap.style.alignItems = 'center' | ||
|
||
wrap.innerText = 'hello' | ||
|
||
return wrap | ||
}, | ||
}) | ||
|
||
const wrap = document.createElement('div') | ||
wrap.style.width = '100%' | ||
wrap.style.height = '100%' | ||
wrap.style.background = '#f0f0f0' | ||
wrap.style.display = 'flex' | ||
wrap.style.justifyContent = 'center' | ||
wrap.style.alignItems = 'center' | ||
|
||
wrap.innerText = 'world' | ||
|
||
const target = graph.addNode({ | ||
shape: 'html', | ||
x: 320, | ||
y: 320, | ||
width: 160, | ||
height: 60, | ||
html: wrap, | ||
}) | ||
|
||
graph.addEdge({ | ||
source, | ||
target, | ||
}) | ||
} | ||
|
||
refContainer = (container: HTMLDivElement) => { | ||
this.container = container | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="x6-graph-wrap"> | ||
<div ref={this.refContainer} className="x6-graph" /> | ||
</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