@@ -27,9 +27,15 @@ function init_graph(params) {
27
27
28
28
var myChart = init_graph ( ) ;
29
29
30
- function draw_graph ( myChart ) {
30
+ function draw_graph ( myChart , modal = false ) {
31
+ console . log ( modal ) ;
32
+ var _option = $ . extend ( true , { } , option ) ;
33
+ if ( ! modal ) {
34
+ _option . series [ 0 ] . data = graph_nodes ( ) ;
35
+ _option . series [ 0 ] . links = graph_links ( ) ;
36
+ }
31
37
// draw the graph
32
- myChart . setOption ( option ) ;
38
+ myChart . setOption ( _option ) ;
33
39
34
40
// add click event for nodes
35
41
myChart . on ( 'click' , function ( params ) {
@@ -44,6 +50,21 @@ function draw_graph(myChart) {
44
50
45
51
var option ;
46
52
53
+ function graph_links ( ) {
54
+ id = option . series [ 0 ] . data . find ( it => it . value === window . location . pathname ) . id ;
55
+ return option . series [ 0 ] . links . filter ( it => it . source === id || it . target === id ) ;
56
+ }
57
+
58
+ function graph_nodes ( ) {
59
+ id = option . series [ 0 ] . data . find ( it => it . value === window . location . pathname ) . id ;
60
+ links = option . series [ 0 ] . links . filter ( it => it . source === id || it . target === id ) ;
61
+ ids = [ ] ;
62
+ links . forEach ( function ( link ) {
63
+ ids . push ( link . source , link . target ) ;
64
+ } ) ;
65
+ return option . series [ 0 ] . data . filter ( it => [ ...new Set ( ids ) ] . includes ( it . id ) ) ;
66
+ }
67
+
47
68
$ . getJSON ( document . currentScript . src + '/../graph.json' , function ( graph ) {
48
69
myChart . hideLoading ( ) ;
49
70
@@ -138,5 +159,5 @@ $('#graph_button').on('click', function (params) {
138
159
}
139
160
} ) ;
140
161
myChart = init_graph ( ) ;
141
- draw_graph ( myChart ) ;
162
+ draw_graph ( myChart , true ) ;
142
163
} ) ;
0 commit comments