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
1182a32
commit c6fd5da
Showing
3 changed files
with
204 additions
and
32 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,110 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"position": { | ||
"x": 80, | ||
"y": 80 | ||
}, | ||
"size": { | ||
"width": 160, | ||
"height": 60 | ||
}, | ||
"attrs": { | ||
"text": { | ||
"text": "parent" | ||
} | ||
}, | ||
"shape": "rect", | ||
"portMarkup": [ | ||
{ | ||
"tagName": "circle", | ||
"selector": "portBody", | ||
"attrs": { | ||
"r": 6, | ||
"magnet": "true", | ||
"stroke": "#000", | ||
"fill": "#fff", | ||
"strokeWidth": 2, | ||
"stroke-width": 2 | ||
} | ||
} | ||
], | ||
"ports": { | ||
"groups": { | ||
"in": { | ||
"position": { | ||
"name": "top" | ||
} | ||
}, | ||
"out": { | ||
"position": { | ||
"name": "bottom" | ||
} | ||
} | ||
}, | ||
"items": [] | ||
}, | ||
"id": "1", | ||
"children": ["2"], | ||
"zIndex": 1 | ||
}, | ||
{ | ||
"position": { | ||
"x": 320, | ||
"y": 320 | ||
}, | ||
"size": { | ||
"width": 160, | ||
"height": 60 | ||
}, | ||
"attrs": { | ||
"text": { | ||
"text": "child" | ||
} | ||
}, | ||
"shape": "rect", | ||
"portMarkup": [ | ||
{ | ||
"tagName": "circle", | ||
"selector": "portBody", | ||
"attrs": { | ||
"r": 6, | ||
"magnet": "true", | ||
"stroke": "#000", | ||
"fill": "#fff", | ||
"strokeWidth": 2, | ||
"stroke-width": 2 | ||
} | ||
} | ||
], | ||
"ports": { | ||
"groups": { | ||
"in": { | ||
"position": { | ||
"name": "top" | ||
} | ||
}, | ||
"out": { | ||
"position": { | ||
"name": "bottom" | ||
} | ||
} | ||
}, | ||
"items": [] | ||
}, | ||
"id": "2", | ||
"zIndex": 2 | ||
}, | ||
{ | ||
"shape": "edge", | ||
"id": "8a15dd65-7dc1-4f89-b0b8-1e621dbc4cfd", | ||
"source": { | ||
"cell": "1" | ||
}, | ||
"target": { | ||
"cell": "2" | ||
}, | ||
"zIndex": 3 | ||
} | ||
] | ||
} |
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,66 @@ | ||
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 parent = graph.addNode({ | ||
id: '1', | ||
shape: 'rect', | ||
x: 80, | ||
y: 80, | ||
width: 160, | ||
height: 60, | ||
label: 'parent', | ||
}) | ||
const child1 = graph.addNode({ | ||
id: '2', | ||
shape: 'rect', | ||
x: 320, | ||
y: 320, | ||
width: 160, | ||
height: 60, | ||
label: 'child1', | ||
}) | ||
|
||
const child2 = graph.addNode({ | ||
id: '3', | ||
shape: 'rect', | ||
x: 520, | ||
y: 320, | ||
width: 160, | ||
height: 60, | ||
label: 'child2', | ||
}) | ||
|
||
parent.addChild(child1) | ||
child1.addChild(child2) | ||
|
||
console.log(graph.toJSON()) | ||
|
||
graph.fromJSON(graph.toJSON()) | ||
|
||
graph.removeNode('1') | ||
} | ||
|
||
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