-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
10 changed files
with
686 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if (typeof window !== 'undefined') { | ||
window.onresize = () => { | ||
const { graph, container } = window as any; | ||
if (!graph || graph.destroyed) return; | ||
if (!container || !container.scrollWidth || !container.scrollHeight) return; | ||
graph.setSize([container.scrollWidth, container.scrollHeight]); | ||
}; | ||
} |
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,55 @@ | ||
import { Graph, extend } from '@antv/g6'; | ||
import { createReactGNode, Rect, Text } from '@antv/g6-react-node'; | ||
|
||
const Node = ({ model }) => { | ||
const { data } = model; | ||
const { | ||
value, | ||
size: [width, height], | ||
} = data; | ||
|
||
return ( | ||
<Rect width={width} height={height} fill="#f1f0ff"> | ||
<Text text={`${(value * 100).toFixed(2)}%`}></Text> | ||
<Rect y={4} width={value * width} height={height - 8} fill="#6395fa" /> | ||
</Rect> | ||
); | ||
}; | ||
|
||
const ReactGNode = createReactGNode(Node); | ||
|
||
const ExtendGraph = extend(Graph, { | ||
nodes: { | ||
'react-g-node': ReactGNode, | ||
}, | ||
}); | ||
|
||
const container = document.getElementById('container'); | ||
const width = container.scrollWidth; | ||
const height = container.scrollHeight || 500; | ||
|
||
window.graph = new ExtendGraph({ | ||
container: 'container', | ||
width, | ||
height, | ||
autoFit: 'center', | ||
modes: { | ||
default: [{ type: 'drag-node', enableTransient: false }], | ||
}, | ||
data: { | ||
nodes: [ | ||
{ id: 'node1', data: { size: [100, 30], value: 0.5 } }, | ||
{ id: 'node2', data: { size: [100, 30], value: 0.8 } }, | ||
], | ||
edges: [ | ||
{ | ||
source: 'node1', | ||
target: 'node2', | ||
}, | ||
], | ||
}, | ||
node: { | ||
type: 'react-g-node', | ||
otherShapes: {}, | ||
}, | ||
}); |
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,47 @@ | ||
import { Graph, extend } from '@antv/g6'; | ||
import { createReactNode } from '@antv/g6-react-node'; | ||
import { Alert } from 'antd'; | ||
|
||
const Node = ({ model }) => { | ||
const { data } = model; | ||
const { message, nodeType } = data; | ||
return <Alert message={message} type={nodeType} showIcon />; | ||
}; | ||
|
||
const ReactNode = createReactNode(Node); | ||
|
||
const ExtendGraph = extend(Graph, { | ||
nodes: { | ||
'react-node': ReactNode, | ||
}, | ||
}); | ||
|
||
const container = document.getElementById('container'); | ||
const width = container.scrollWidth; | ||
const height = container.scrollHeight || 500; | ||
|
||
window.graph = new ExtendGraph({ | ||
container: 'container', | ||
width, | ||
height, | ||
autoFit: 'center', | ||
modes: { | ||
default: [{ type: 'drag-node', enableTransient: false }], | ||
}, | ||
data: { | ||
nodes: [ | ||
{ id: 'node1', data: { size: [120, 40], message: 'Success', nodeType: 'success' } }, | ||
{ id: 'node2', data: { size: [120, 40], message: 'Warning', nodeType: 'warning' } }, | ||
], | ||
edges: [ | ||
{ | ||
source: 'node1', | ||
target: 'node2', | ||
}, | ||
], | ||
}, | ||
node: { | ||
type: 'react-node', | ||
otherShapes: {}, | ||
}, | ||
}); |
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 |
---|---|---|
|
@@ -16,5 +16,9 @@ declare global { | |
g2: any; | ||
React: any; | ||
ReactDOM: any; | ||
antd: any; | ||
|
||
graph: any; | ||
container: any; | ||
} | ||
} |
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
Oops, something went wrong.