1
1
'use strict' ;
2
2
3
- import React from 'react' ;
3
+ import React , { useState , useEffect } from 'react' ;
4
4
import ReactDOM from 'react-dom' ;
5
- import { BrowserRouter as Router } from 'react-router-dom' ;
6
- import { Layout , Pagination , Input } from 'antd' ;
7
- import { CloseCircleOutlined , CheckOutlined } from '@ant-design/icons' ;
5
+ import { BrowserRouter as Router } from 'react-router-dom' ;
6
+ import { Layout , Pagination , Input } from 'antd' ;
7
+ import { CloseCircleOutlined , CheckOutlined } from '@ant-design/icons' ;
8
8
import MonitorDag from '../src/index.tsx' ;
9
9
import mockData from './mock_data/data' ;
10
+ import _ from 'lodash' ;
10
11
import 'antd/dist/antd.css' ;
11
12
import './index.less' ;
12
13
13
- const { Header} = Layout ;
14
+ const { Header } = Layout ;
14
15
const { Search } = Input ;
15
16
16
- const nodeMenu = [ {
17
- key : 'detail' ,
18
- title : '节点信息' ,
19
- onClick : ( key , data ) => {
20
- console . log ( 'click detail info' )
21
- }
22
- } , {
23
- key : 'run' ,
24
- render : ( key , data ) => {
25
- return < span > 节点运行</ span >
26
- } ,
27
- onClick : ( key , data ) => {
28
- console . log ( 'run node' ) ;
29
- }
30
- } ]
31
-
32
17
const edgeMenu = [ {
33
18
key : 'detail' ,
34
19
title : '线段信息' ,
35
20
onClick : ( key , data ) => {
36
- console . log ( 'click detail info' , data )
21
+ console . log ( 'click detail info' , data )
37
22
}
38
23
} , {
39
24
key : '监控流程' ,
@@ -60,74 +45,92 @@ const groupMenu = [{
60
45
console . log ( 'run node' ) ;
61
46
}
62
47
} ]
63
-
48
+ const Demo = ( ) => {
49
+ const [ canvasData , setCanvasData ] = useState ( mockData ) ;
50
+ const nodeMenu = [ {
51
+ key : 'detail' ,
52
+ title : '节点信息' ,
53
+ onClick : ( key , data ) => {
54
+ console . log ( 'click detail info' ) ;
55
+ }
56
+ } , {
57
+ key : 'run' ,
58
+ render : ( key , data ) => {
59
+ return < span > 节点运行</ span >
60
+ } ,
61
+ onClick : ( key , data ) => {
62
+ console . log ( 'run node' ) ;
63
+ }
64
+ } ] ;
65
+ return < MonitorDag
66
+ data = { canvasData }
67
+ nodeMenu = { nodeMenu }
68
+ edgeMenu = { edgeMenu }
69
+ groupMenu = { groupMenu }
70
+ config = { {
71
+ focusCenter : true ,
72
+ direction : 'top-bottom' ,
73
+ autoLayout : {
74
+ enable : false ,
75
+ isAlways : false ,
76
+ } ,
77
+ labelRender : ( label , info ) => {
78
+ return label ;
79
+ } ,
80
+ labelTipsRender : ( label , info ) => {
81
+ return `${ label } : 自定义label tips` ;
82
+ } ,
83
+ nodeRender : ( nodeOpts ) => {
84
+ return (
85
+ < span className = "node-text" > { nodeOpts . title + nodeOpts . id + nodeOpts . status } </ span >
86
+ )
87
+ } ,
88
+ // diffOptions: ['status'],
89
+ // statusNote: {
90
+ // notes: [{
91
+ // code: 'fail',
92
+ // render: () => {
93
+ // return <span><CloseCircleOutlined />失败</span>
94
+ // }
95
+ // }, {
96
+ // code: 'success',
97
+ // render: () => {
98
+ // return <span><CheckOutlined />成功</span>
99
+ // }
100
+ // }]
101
+ // },
102
+ nodeTipsRender : ( nodeOpts ) => {
103
+ return < span > { nodeOpts . title } : 自定义节点tips</ span >
104
+ } ,
105
+ endpointTipsRender : ( pointOpts ) => {
106
+ return < span > 自定义锚点tips</ span >
107
+ } ,
108
+ group : {
109
+ enablePagination : true ,
110
+ enableSearch : true
111
+ } ,
112
+ minimap : {
113
+ enable : true ,
114
+ config : {
115
+ nodeColor : 'rgba(216, 216, 216, 0.13)' ,
116
+ activeNodeColor : '#F66902' ,
117
+ viewportStyle : {
118
+ 'background-color' : 'rgba(216, 216, 216, 0.07)'
119
+ } ,
120
+ groups : mockData . groups ,
121
+ nodes : mockData . nodes
122
+ }
123
+ } ,
124
+ } }
125
+ />
126
+ }
64
127
65
128
ReactDOM . render ( (
66
129
< Router >
67
130
< Layout >
68
131
< Header className = 'header' > DTDesign-React运维/监控图</ Header >
69
132
< Layout >
70
- < MonitorDag
71
- data = { mockData }
72
- nodeMenu = { nodeMenu }
73
- edgeMenu = { edgeMenu }
74
- groupMenu = { groupMenu }
75
- config = { {
76
- focusCenter : true ,
77
- direction : 'top-bottom' ,
78
- autoLayout : {
79
- enable : false ,
80
- isAlways : false ,
81
- } ,
82
- labelRender : ( label , info ) => {
83
- return label ;
84
- } ,
85
- labelTipsRender : ( label , info ) => {
86
- return `${ label } : 自定义label tips` ;
87
- } ,
88
- // nodeRender: (nodeOpts) => {
89
- // return (
90
- // <span className="node-text">{nodeOpts.title + nodeOpts
91
- // .id }</span>
92
- // )
93
- // },
94
- // statusNote: {
95
- // notes: [{
96
- // code: 'fail',
97
- // render: () => {
98
- // return <span><CloseCircleOutlined />失败</span>
99
- // }
100
- // }, {
101
- // code: 'success',
102
- // render: () => {
103
- // return <span><CheckOutlined />成功</span>
104
- // }
105
- // }]
106
- // },
107
- nodeTipsRender : ( nodeOpts ) => {
108
- return < span > { nodeOpts . title } : 自定义节点tips</ span >
109
- } ,
110
- endpointTipsRender : ( pointOpts ) => {
111
- return < span > 自定义锚点tips</ span >
112
- } ,
113
- group : {
114
- enablePagination : true ,
115
- enableSearch : true
116
- } ,
117
- minimap : {
118
- enable : true ,
119
- config : {
120
- nodeColor : 'rgba(216, 216, 216, 0.13)' ,
121
- activeNodeColor : '#F66902' ,
122
- viewportStyle : {
123
- 'background-color' : 'rgba(216, 216, 216, 0.07)'
124
- } ,
125
- groups : mockData . groups ,
126
- nodes : mockData . nodes
127
- }
128
- } ,
129
- } }
130
- />
133
+ < Demo />
131
134
</ Layout >
132
135
</ Layout >
133
136
</ Router >
0 commit comments