1
1
import React , { useCallback , useEffect , useRef } from 'react' ;
2
2
3
- import { Core , use } from 'cytoscape' ;
3
+ import { Core , use } from 'cytoscape' ;
4
4
import produce from 'immer' ;
5
- import fcose from 'cytoscape-fcose ' ;
5
+ import cola from 'cytoscape-cola ' ;
6
6
import CytoscapeComponent from 'react-cytoscapejs' ;
7
7
8
- use ( fcose ) ;
8
+ use ( cola ) ;
9
9
10
10
import { useCytoscapeConfig } from 'ortho-client/hooks/cytoscapeData' ;
11
11
import {
12
12
useEdgeMouseMovementEventHandlers ,
13
13
useNodeClickEventHandler ,
14
14
useNodeMouseMovementEventHandlers ,
15
15
useUpdateHighlightedEdge ,
16
- useUpdateHighlightedNodes
16
+ useUpdateHighlightedNodes ,
17
17
} from 'ortho-client/hooks/cytoscapeEventHandlers' ;
18
18
19
19
import {
20
20
EdgeType ,
21
21
NodeDisplayType ,
22
- ProteinType
22
+ ProteinType ,
23
23
} from 'ortho-client/utils/clusterGraph' ;
24
24
import {
25
25
addCytoscapeClass ,
26
- removeCytoscapeClass
26
+ removeCytoscapeClass ,
27
27
} from 'ortho-client/utils/cytoscapeClasses' ;
28
28
import { GroupLayout } from 'ortho-client/utils/groupLayout' ;
29
29
import { TaxonUiMetadata } from 'ortho-client/utils/taxons' ;
@@ -55,88 +55,106 @@ export function ClusterGraphCanvas({
55
55
highlightedLegendNodeIds,
56
56
highlightedSequenceNodeId,
57
57
highlightedBlastEdgeId,
58
- onClickNode
58
+ onClickNode,
59
59
} : Props ) {
60
60
const cyRef = useRef < Core > ( ) ;
61
- const [ cytoscapeConfig , setCytoscapeConfig ] = useCytoscapeConfig (
61
+ const [ cytoscapeConfig , setCytoscapeConfig ] = useCytoscapeConfig (
62
62
layout ,
63
63
corePeripheralMap ,
64
64
taxonUiMetadata ,
65
65
selectedNodeDisplayType
66
66
) ;
67
67
68
- const updateHighlightedNodes = useUpdateHighlightedNodes ( cytoscapeConfig , setCytoscapeConfig ) ;
69
- const updateHighlightedEdge = useUpdateHighlightedEdge ( cyRef . current , cytoscapeConfig , setCytoscapeConfig ) ;
68
+ const updateHighlightedNodes = useUpdateHighlightedNodes (
69
+ cytoscapeConfig ,
70
+ setCytoscapeConfig
71
+ ) ;
72
+ const updateHighlightedEdge = useUpdateHighlightedEdge (
73
+ cyRef . current ,
74
+ cytoscapeConfig ,
75
+ setCytoscapeConfig
76
+ ) ;
70
77
71
78
const onMouseLeaveCanvas = useCallback ( ( ) => {
72
79
updateHighlightedNodes ( [ ] ) ;
73
80
updateHighlightedEdge ( undefined ) ;
74
- } , [ updateHighlightedNodes , updateHighlightedEdge ] ) ;
81
+ } , [ updateHighlightedNodes , updateHighlightedEdge ] ) ;
75
82
76
83
useEffect ( ( ) => {
77
- const newConfig = produce ( cytoscapeConfig , draftConfig => {
78
- draftConfig . elements . forEach ( element => {
84
+ const newConfig = produce ( cytoscapeConfig , ( draftConfig ) => {
85
+ draftConfig . elements . forEach ( ( element ) => {
79
86
if ( element . group === 'nodes' ) {
80
87
element . classes = selectedNodeDisplayType ;
81
88
}
82
89
} ) ;
83
90
} ) ;
84
91
85
92
setCytoscapeConfig ( newConfig ) ;
86
- } , [ selectedNodeDisplayType ] ) ;
93
+ } , [ selectedNodeDisplayType ] ) ;
87
94
88
95
useEffect ( ( ) => {
89
- const newConfig = produce ( cytoscapeConfig , draftConfig => {
96
+ const newConfig = produce ( cytoscapeConfig , ( draftConfig ) => {
90
97
const maxEValue = parseFloat ( `1e${ eValueExp } ` ) ;
91
98
92
- draftConfig . elements . forEach ( element => {
99
+ draftConfig . elements . forEach ( ( element ) => {
93
100
if ( element . group === 'edges' ) {
94
101
if (
95
102
! selectedEdgeTypes [ element . data . type as EdgeType ] ||
96
103
element . data . eValue > maxEValue
97
104
) {
98
- element . classes = addCytoscapeClass ( element . classes , 'filtered-out' ) ;
105
+ element . classes = addCytoscapeClass (
106
+ element . classes ,
107
+ 'filtered-out'
108
+ ) ;
99
109
} else {
100
- element . classes = removeCytoscapeClass ( element . classes , 'filtered-out' ) ;
110
+ element . classes = removeCytoscapeClass (
111
+ element . classes ,
112
+ 'filtered-out'
113
+ ) ;
101
114
}
102
115
}
103
116
} ) ;
104
117
} ) ;
105
118
106
119
setCytoscapeConfig ( newConfig ) ;
107
- } , [ eValueExp , selectedEdgeTypes ] ) ;
120
+ } , [ eValueExp , selectedEdgeTypes ] ) ;
108
121
109
122
useEffect ( ( ) => {
110
123
updateHighlightedNodes ( highlightedLegendNodeIds ) ;
111
- } , [ highlightedLegendNodeIds ] ) ;
124
+ } , [ highlightedLegendNodeIds ] ) ;
112
125
113
126
useEffect ( ( ) => {
114
- const newHighlightedNodeIds = highlightedSequenceNodeId == null
115
- ? [ ]
116
- : [ highlightedSequenceNodeId ] ;
127
+ const newHighlightedNodeIds =
128
+ highlightedSequenceNodeId == null ? [ ] : [ highlightedSequenceNodeId ] ;
117
129
118
130
updateHighlightedNodes ( newHighlightedNodeIds ) ;
119
- } , [ highlightedSequenceNodeId ] ) ;
131
+ } , [ highlightedSequenceNodeId ] ) ;
120
132
121
133
useEffect ( ( ) => {
122
134
updateHighlightedEdge ( highlightedBlastEdgeId ) ;
123
- } , [ highlightedBlastEdgeId ] ) ;
135
+ } , [ highlightedBlastEdgeId ] ) ;
124
136
125
137
useEffect ( ( ) => {
126
- const newConfig = produce ( cytoscapeConfig , draftConfig => {
127
- draftConfig . elements . forEach ( element => {
138
+ const newConfig = produce ( cytoscapeConfig , ( draftConfig ) => {
139
+ draftConfig . elements . forEach ( ( element ) => {
128
140
if ( element . group === 'edges' && element . data . type != null ) {
129
141
if ( element . data . type === highlightedEdgeType ) {
130
- element . classes = addCytoscapeClass ( element . classes , 'type-highlighted' ) ;
142
+ element . classes = addCytoscapeClass (
143
+ element . classes ,
144
+ 'type-highlighted'
145
+ ) ;
131
146
} else {
132
- element . classes = removeCytoscapeClass ( element . classes , 'type-highlighted' ) ;
147
+ element . classes = removeCytoscapeClass (
148
+ element . classes ,
149
+ 'type-highlighted'
150
+ ) ;
133
151
}
134
152
}
135
153
} ) ;
136
154
} ) ;
137
155
138
156
setCytoscapeConfig ( newConfig ) ;
139
- } , [ highlightedEdgeType ] ) ;
157
+ } , [ highlightedEdgeType ] ) ;
140
158
141
159
useNodeClickEventHandler ( cyRef , onClickNode ) ;
142
160
@@ -151,7 +169,7 @@ export function ClusterGraphCanvas({
151
169
>
152
170
< CytoscapeComponent
153
171
className = "ClusterGraphCanvas"
154
- cy = { cy => {
172
+ cy = { ( cy ) => {
155
173
cyRef . current = cy ;
156
174
} }
157
175
{ ...cytoscapeConfig }
0 commit comments