@@ -15,7 +15,7 @@ import cytoscape from 'cytoscape';
15
15
import BubbleSets from 'cytoscape-bubblesets' ;
16
16
import dagre from 'cytoscape-dagre' ;
17
17
import useStyles from './style' ;
18
- import { NodeData , TabPanel } from './components' ;
18
+ import { ElementData , TabPanel } from './components' ;
19
19
20
20
cytoscape . use ( BubbleSets ) ;
21
21
cytoscape . use ( dagre ) ;
@@ -24,20 +24,28 @@ const DEFAULT_LAYOUTS = ['dagre'];
24
24
25
25
export const CytoViz = ( props ) => {
26
26
const classes = useStyles ( ) ;
27
- const { cytoscapeStylesheet, defaultSettings, elements, extraLayouts, labels, loading, getNodeDetails, bubblesets } =
28
- props ;
27
+ const {
28
+ cytoscapeStylesheet,
29
+ defaultSettings,
30
+ elements,
31
+ extraLayouts,
32
+ labels,
33
+ loading,
34
+ getElementDetails,
35
+ bubblesets,
36
+ } = props ;
29
37
30
- let getNodeDetailsCallback = getNodeDetails ;
31
- if ( ! getNodeDetailsCallback ) {
38
+ let getElementDetailsCallback = getElementDetails ;
39
+ if ( ! getElementDetailsCallback ) {
32
40
// eslint-disable-next-line react/display-name
33
- getNodeDetailsCallback = ( node ) => < NodeData data = { node . data ( ) } labels = { labels . nodeData } /> ;
34
- getNodeDetailsCallback . displayName = 'NodeData ' ;
41
+ getElementDetailsCallback = ( element ) => < ElementData data = { element . data ( ) } labels = { labels . elementData } /> ;
42
+ getElementDetailsCallback . displayName = 'ElementData ' ;
35
43
}
36
44
37
45
// Layout
38
46
const [ isDrawerOpen , setIsDrawerOpen ] = React . useState ( false ) ;
39
47
const [ currentDrawerTab , setCurrentDrawerTab ] = React . useState ( 0 ) ;
40
- const [ currentNodeDetails , setCurrentNodeDetails ] = React . useState ( null ) ;
48
+ const [ currentElementDetails , setCurrentElementDetails ] = React . useState ( null ) ;
41
49
const closeDrawer = ( ) => {
42
50
setIsDrawerOpen ( false ) ;
43
51
} ;
@@ -78,30 +86,29 @@ export const CytoViz = (props) => {
78
86
79
87
const initCytoscape = ( cytoscapeRef ) => {
80
88
cytoscapeRef . removeAllListeners ( ) ;
81
- // Prevent multiple selection
82
- cytoscapeRef . on ( 'select' , 'node, edge' , ( e ) => cytoscapeRef . elements ( ) . not ( e . target ) . unselect ( ) ) ;
83
- // Init node selection behavior
84
- cytoscapeRef . on ( 'select' , 'node' , function ( e ) {
85
- const selectedNode = e . target ;
86
- setCurrentNodeDetails ( getNodeDetailsCallback ( selectedNode ) ) ;
89
+ // Prevent multiple selection & init elements selection behavior
90
+ cytoscapeRef . on ( 'select' , 'node, edge' , function ( e ) {
91
+ cytoscapeRef . elements ( ) . not ( e . target ) . unselect ( ) ;
92
+ const selectedElement = e . target ;
93
+ setCurrentElementDetails ( getElementDetailsCallback ( selectedElement ) ) ;
87
94
} ) ;
88
- cytoscapeRef . on ( 'unselect' , 'node' , function ( e ) {
89
- setCurrentNodeDetails ( null ) ;
95
+ cytoscapeRef . on ( 'unselect' , 'node, edge ' , function ( e ) {
96
+ setCurrentElementDetails ( null ) ;
90
97
} ) ;
91
98
// Add handling of double click events
92
- cytoscapeRef . on ( 'dbltap' , 'node' , function ( e ) {
93
- const selectedNode = e . target ;
99
+ cytoscapeRef . on ( 'dbltap' , 'node, edge ' , function ( e ) {
100
+ const selectedElement = e . target ;
94
101
setCurrentDrawerTab ( 0 ) ;
95
102
setIsDrawerOpen ( true ) ;
96
- setCurrentNodeDetails ( getNodeDetailsCallback ( selectedNode ) ) ;
103
+ setCurrentElementDetails ( getElementDetailsCallback ( selectedElement ) ) ;
97
104
} ) ;
98
105
99
106
// Init bubblesets
100
107
const bb = cytoscapeRef . bubbleSets ( ) ;
101
108
for ( const groupName in bubblesets ) {
102
- const groupNodes = cytoscapeRef . nodes ( `.${ groupName } ` ) ;
109
+ const nodesGroup = cytoscapeRef . nodes ( `.${ groupName } ` ) ;
103
110
const groupColor = bubblesets [ groupName ] ;
104
- bb . addPath ( groupNodes , undefined , null , {
111
+ bb . addPath ( nodesGroup , undefined , null , {
105
112
virtualEdges : true ,
106
113
style : {
107
114
fill : groupColor ,
@@ -173,7 +180,7 @@ export const CytoViz = (props) => {
173
180
</ div >
174
181
< div className = { classes . drawerContent } >
175
182
< TabPanel value = { currentDrawerTab } index = { 0 } >
176
- { currentNodeDetails || labels . noSelectedNode }
183
+ { currentElementDetails || labels . noSelectedElement }
177
184
</ TabPanel >
178
185
< TabPanel value = { currentDrawerTab } index = { 1 } >
179
186
< div className = { classes . settingsContainer } >
@@ -272,9 +279,9 @@ CytoViz.propTypes = {
272
279
*/
273
280
extraLayouts : PropTypes . object ,
274
281
/**
275
- * Function to generate a string or component elements details from the data of the currently selected node.
282
+ * Function to generate a string or React component from the data of the currently selected element ( node or edge) .
276
283
*/
277
- getNodeDetails : PropTypes . func ,
284
+ getElementDetails : PropTypes . func ,
278
285
/**
279
286
* Map of bubblesets to display in cytoscape graph. Keys of this object are the group names (each group can be
280
287
represented by a compound node in cytoscape elements to get a better layout), and values are the color of the group.
@@ -286,15 +293,15 @@ CytoViz.propTypes = {
286
293
{
287
294
elementDetails: 'string',
288
295
loading: 'string',
289
- noSelectedNode : 'string',
296
+ noSelectedElement : 'string',
290
297
settings: {
291
298
compactMode: 'string',
292
299
layout: 'string',
293
300
title: 'string',
294
301
spacingFactor: 'string',
295
302
zoomLimits: 'string',
296
303
}
297
- nodeData : {
304
+ elementData : {
298
305
dictKey: 'string',
299
306
dictValue: 'string',
300
307
}
@@ -312,15 +319,15 @@ CytoViz.propTypes = {
312
319
const DEFAULT_LABELS = {
313
320
elementDetails : 'Details' ,
314
321
loading : 'Loading...' ,
315
- noSelectedNode : 'Select a node to view its data' ,
322
+ noSelectedElement : 'Select a node or edge to show its data' ,
316
323
settings : {
317
324
compactMode : 'Compact layout' ,
318
325
layout : 'Layout' ,
319
326
title : 'Settings' ,
320
327
spacingFactor : 'Spacing factor' ,
321
328
zoomLimits : 'Min & max zoom' ,
322
329
} ,
323
- nodeData : {
330
+ elementData : {
324
331
dictKey : 'Key' ,
325
332
dictValue : 'Value' ,
326
333
} ,
0 commit comments