1+ import * as echarts from "echarts" ;
2+
3+ const buildSankeyData = ( data ) => {
4+ const buildDataItem = ( item ) => {
5+ return { name : item . name }
6+ }
7+
8+ const lcd = data . find ( d => d [ "@type" ] . endsWith ( "ListenersConfigDump" ) )
9+ const rcd = data . find ( d => d [ "@type" ] . endsWith ( "v3.RoutesConfigDump" ) )
10+ console . log ( lcd ) ;
11+ console . log ( rcd ) ;
12+
13+ const result = new Array ( )
14+ // lcd.static_listeners.forEach(ln => { listeners.push(buildDataItem(ln.listener)) })
15+ lcd . dynamic_listeners . forEach ( item => { result . push ( buildDataItem ( item . active_state . listener ) ) } )
16+ rcd . dynamic_route_configs . forEach ( item => { result . push ( buildDataItem ( item . route_config ) ) } )
17+ console . log ( result ) ;
18+ return result
19+
20+ return [ { "name" : "outbound|8080||aws-map-tag-north.openfaas-fn.svc.cluster.local" } , { "name" : "10.21.230.4:8080" } , { "name" : "10.21.241.156:8080" } , { "name" : "10.21.248.81:8080" } , { "name" : "outbound|8080||cmdb-sync-baidu-spec-inventory.openfaas-fn.svc.cluster.local" } ]
21+ }
22+
23+ const buildSankeyLinks = ( raw_data ) => {
24+ const lcd = raw_data . find ( d => d [ "@type" ] . endsWith ( "ListenersConfigDump" ) )
25+ const rcd = raw_data . find ( d => d [ "@type" ] . endsWith ( "v3.RoutesConfigDump" ) )
26+ lcd . dynamic_listeners . forEach ( item => {
27+ console . log ( 'fc' , item . active_state . listener . filter_chains ) ;
28+ } )
29+
30+ const sankeyLinks = [ ] ;
31+
32+
33+ return sankeyLinks ;
34+ return [ { "source" : "0.0.0.0_8080" , "target" : "8080" , "value" : 58 } , { "source" : "8080" , "target" : "PassthroughCluster" , "value" : 1 } , { "source" : "8080" , "target" : "outbound|8080||apollo-api.openfaas-fn.svc.cluster.local" , "value" : 1 } , { "source" : "outbound|8080||apollo-api.openfaas-fn.svc.cluster.local" , "target" : "10.21.230.27:8080" , "value" : 1 } , { "source" : "8080" , "target" : "outbound|8080||app-api.openfaas-fn.svc.cluster.local" , "value" : 1 } ]
35+ }
36+
37+ export const build = ( domid , data ) => {
38+ var dom = document . getElementById ( domid ) ;
39+ var chart = echarts . init ( dom ) ;
40+ var app = { } ;
41+ var option ;
42+
43+ console . log ( data ) ;
44+ chart . setOption (
45+ ( option = {
46+ // title: {
47+ // text: 'Sankey Diagram'
48+ // },
49+ tooltip : {
50+ trigger : 'item' ,
51+ triggerOn : 'mousemove'
52+ } ,
53+ series : [
54+ {
55+ type : 'sankey' ,
56+ data : buildSankeyData ( data ) ,
57+ links : buildSankeyLinks ( data ) ,
58+ emphasis : {
59+ focus : 'adjacency'
60+ } ,
61+ nodeAlign : 'left' ,
62+ levels : [
63+ {
64+ depth : 0 ,
65+ itemStyle : {
66+ color : '#fbb4ae'
67+ } ,
68+ lineStyle : {
69+ color : 'source' ,
70+ opacity : 0.6
71+ }
72+ } ,
73+ {
74+ depth : 1 ,
75+ itemStyle : {
76+ color : '#b3cde3'
77+ } ,
78+ lineStyle : {
79+ color : 'source' ,
80+ opacity : 0.6
81+ }
82+ } ,
83+ {
84+ depth : 2 ,
85+ itemStyle : {
86+ color : '#ccebc5'
87+ } ,
88+ lineStyle : {
89+ color : 'source' ,
90+ opacity : 0.6
91+ }
92+ } ,
93+ {
94+ depth : 3 ,
95+ itemStyle : {
96+ color : '#decbe4'
97+ } ,
98+ lineStyle : {
99+ color : 'source' ,
100+ opacity : 0.6
101+ }
102+ }
103+ ] ,
104+ lineStyle : {
105+ color : 'source' ,
106+ curveness : 0.5
107+ }
108+ }
109+ ]
110+ } )
111+ ) ;
112+
113+ if ( option && typeof option === 'object' ) {
114+ chart . setOption ( option ) ;
115+ }
116+ window . onresize = function ( ) {
117+ //自适应大小
118+ chart . resize ( ) ;
119+ } ;
120+ }
0 commit comments