1
- import { Button , Typography , Divider } from '@mui/material'
1
+ import { Button , FormControlLabel , Switch , FormGroup } from '@mui/material'
2
2
import React from 'react'
3
3
import { ControllerContext , FullGraphContext } from './Contexts'
4
4
import { Node , Edge , NetworkStats , Graph } from './types'
@@ -27,7 +27,6 @@ export function selectCluster(
27
27
nodes : new_nodes ,
28
28
edges : new_edges
29
29
}
30
- ClusterCache . set ( activeCluster , result )
31
30
return result
32
31
}
33
32
@@ -60,24 +59,22 @@ export function clusterGraph({networkStatistics, nodes, edges}: Graph): {nodes:
60
59
nodes : Array . from ( new_nodes ) . map ( make_node ) ,
61
60
edges : Array . from ( new_edges ) . map ( make_edge )
62
61
}
63
- ClusterCache . set ( null , result )
64
62
return result
65
63
}
66
64
67
65
export function GraphClusterButton ( { itemId} : { itemId : any } ) {
68
66
const { fullGraph} = React . useContext ( FullGraphContext )
69
67
const { controller, activeCluster} = React . useContext ( ControllerContext )
70
- const showing_clusters = activeCluster === null
68
+ const showing_clusters = activeCluster === null || activeCluster === false
71
69
72
- if ( showing_clusters && ! itemId ) return null
70
+ if ( ( showing_clusters && ! itemId ) || activeCluster === false ) return null
73
71
74
72
return (
75
73
< div >
76
74
< Button
77
75
onClick = { ( ) => {
78
76
const zoomIn = showing_clusters && itemId
79
77
const { nodes, edges} = zoomIn ? selectCluster ( fullGraph , itemId ) : clusterGraph ( fullGraph )
80
-
81
78
controller . update ( ( draft : any ) => {
82
79
draft . nodes = nodes
83
80
draft . edges = edges
@@ -91,3 +88,34 @@ export function GraphClusterButton({itemId}: {itemId: any}) {
91
88
</ div >
92
89
)
93
90
}
91
+
92
+ export function ClusterToggleSwitch ( { itemId} : { itemId : any } ) {
93
+ const { fullGraph} = React . useContext ( FullGraphContext )
94
+ const { controller, activeCluster} = React . useContext ( ControllerContext )
95
+ const showing_clusters = activeCluster === null || activeCluster === false
96
+
97
+ if ( ! showing_clusters ) return null
98
+ return (
99
+ < div >
100
+ < FormGroup >
101
+ < FormControlLabel
102
+ control = {
103
+ < Switch
104
+ defaultChecked
105
+ onChange = { ( event : React . ChangeEvent < HTMLInputElement > ) => {
106
+ const showClusters = event . target . checked
107
+ const { nodes, edges} = showClusters ? clusterGraph ( fullGraph ) : fullGraph
108
+ controller . update ( ( draft : any ) => {
109
+ draft . nodes = nodes
110
+ draft . edges = edges
111
+ draft . activeCluster = showClusters ? null : false
112
+ } )
113
+ } }
114
+ />
115
+ }
116
+ label = "Show clusters?"
117
+ />
118
+ </ FormGroup >
119
+ </ div >
120
+ )
121
+ }
0 commit comments