|
1 | 1 | import React from 'react';
|
2 | 2 | import ReactDOM from 'react-dom';
|
3 |
| -import GGEditor, { Flow, RegisterNode, EditableLabel } from '@/index'; |
| 3 | +import GGEditor, { Flow, RegisterNode, EditableLabel, setAnchorPointsState } from '@/index'; |
4 | 4 | import data from '../mock/flow.json';
|
5 | 5 | import styles from './index.less';
|
6 | 6 |
|
7 | 7 | class Index extends React.Component {
|
8 | 8 | render() {
|
9 | 9 | return (
|
10 | 10 | <GGEditor className={styles.editor}>
|
11 |
| - <Flow className={styles.editorBd} data={data} graphConfig={{ defaultNode: { shape: 'customNode' } }} /> |
| 11 | + <Flow |
| 12 | + className={styles.editorBd} |
| 13 | + data={data} |
| 14 | + // graphConfig={{ defaultNode: { type: 'customNode' } }} |
| 15 | + // graphConfig={{ defaultNode: { type: 'customStartNode' } }} |
| 16 | + graphConfig={{ defaultNode: { type: 'customInternalNode', size: 50 } }} |
| 17 | + /> |
12 | 18 | <RegisterNode
|
13 | 19 | name="customNode"
|
14 | 20 | config={{
|
@@ -40,11 +46,58 @@ class Index extends React.Component {
|
40 | 46 | };
|
41 | 47 | },
|
42 | 48 | getAnchorPoints() {
|
43 |
| - return [[0.5, 1]]; |
| 49 | + return [ |
| 50 | + [0.5, 0], |
| 51 | + [0.5, 1], |
| 52 | + [0, 0.5], |
| 53 | + [1, 0.5], |
| 54 | + ]; |
44 | 55 | },
|
45 | 56 | }}
|
46 | 57 | extend="bizFlowNode"
|
47 | 58 | />
|
| 59 | + <RegisterNode |
| 60 | + name="customInternalNode" |
| 61 | + config={{ |
| 62 | + setState(name, value, item) { |
| 63 | + setAnchorPointsState.call( |
| 64 | + this, |
| 65 | + name, |
| 66 | + value, |
| 67 | + item, |
| 68 | + (item, anchorPoint) => { |
| 69 | + const { width, height } = item.getKeyShape().getBBox(); |
| 70 | + |
| 71 | + const [x, y] = anchorPoint; |
| 72 | + |
| 73 | + return { |
| 74 | + x: width * x - width / 2, |
| 75 | + y: height * y - height / 2, |
| 76 | + }; |
| 77 | + }, |
| 78 | + (item, anchorPoint) => { |
| 79 | + const { width, height } = item.getKeyShape().getBBox(); |
| 80 | + |
| 81 | + const [x, y] = anchorPoint; |
| 82 | + |
| 83 | + return { |
| 84 | + x: width * x - width / 2, |
| 85 | + y: height * y - height / 2, |
| 86 | + }; |
| 87 | + }, |
| 88 | + ); |
| 89 | + }, |
| 90 | + getAnchorPoints() { |
| 91 | + return [ |
| 92 | + [0.5, 0], |
| 93 | + [0.5, 1], |
| 94 | + [0, 0.5], |
| 95 | + [1, 0.5], |
| 96 | + ]; |
| 97 | + }, |
| 98 | + }} |
| 99 | + extend="circle" |
| 100 | + /> |
48 | 101 | <EditableLabel />
|
49 | 102 | </GGEditor>
|
50 | 103 | );
|
|
0 commit comments