@@ -27,6 +27,13 @@ export const CytoViz = (props) => {
27
27
const { cytoscapeStylesheet, defaultSettings, elements, extraLayouts, labels, loading, getNodeDetails, bubblesets } =
28
28
props ;
29
29
30
+ let getNodeDetailsCallback = getNodeDetails ;
31
+ if ( ! getNodeDetailsCallback ) {
32
+ // eslint-disable-next-line react/display-name
33
+ getNodeDetailsCallback = ( node ) => < NodeData data = { node . data ( ) } labels = { labels . nodeData } /> ;
34
+ getNodeDetailsCallback . displayName = 'NodeData' ;
35
+ }
36
+
30
37
// Layout
31
38
const [ isDrawerOpen , setIsDrawerOpen ] = React . useState ( false ) ;
32
39
const [ currentDrawerTab , setCurrentDrawerTab ] = React . useState ( 0 ) ;
@@ -76,7 +83,7 @@ export const CytoViz = (props) => {
76
83
// Init node selection behavior
77
84
cytoscapeRef . on ( 'select' , 'node' , function ( e ) {
78
85
const selectedNode = e . target ;
79
- setCurrentNodeDetails ( getNodeDetails ( selectedNode ) ) ;
86
+ setCurrentNodeDetails ( getNodeDetailsCallback ( selectedNode ) ) ;
80
87
} ) ;
81
88
cytoscapeRef . on ( 'unselect' , 'node' , function ( e ) {
82
89
setCurrentNodeDetails ( null ) ;
@@ -86,7 +93,7 @@ export const CytoViz = (props) => {
86
93
const selectedNode = e . target ;
87
94
setCurrentDrawerTab ( 0 ) ;
88
95
setIsDrawerOpen ( true ) ;
89
- setCurrentNodeDetails ( getNodeDetails ( selectedNode ) ) ;
96
+ setCurrentNodeDetails ( getNodeDetailsCallback ( selectedNode ) ) ;
90
97
} ) ;
91
98
92
99
// Init bubblesets
@@ -287,16 +294,38 @@ CytoViz.propTypes = {
287
294
spacingFactor: 'string',
288
295
zoomLimits: 'string',
289
296
}
297
+ nodeData: {
298
+ dictKey: 'string',
299
+ dictValue: 'string',
300
+ }
290
301
}
291
302
* </pre>
292
303
*/
293
304
labels : PropTypes . object ,
294
305
/**
295
- * Array of cytoscape elements to display
306
+ * Boolean defining whether or not the data are loading.
307
+ While loading is true, a spinner is displayed instead of the cytoscape component.
296
308
*/
297
309
loading : PropTypes . bool ,
298
310
} ;
299
311
312
+ const DEFAULT_LABELS = {
313
+ elementDetails : 'Details' ,
314
+ loading : 'Loading...' ,
315
+ noSelectedNode : 'Select a node to view its data' ,
316
+ settings : {
317
+ compactMode : 'Compact layout' ,
318
+ layout : 'Layout' ,
319
+ title : 'Settings' ,
320
+ spacingFactor : 'Spacing factor' ,
321
+ zoomLimits : 'Min & max zoom' ,
322
+ } ,
323
+ nodeData : {
324
+ dictKey : 'Key' ,
325
+ dictValue : 'Value' ,
326
+ } ,
327
+ } ;
328
+
300
329
CytoViz . defaultProps = {
301
330
cytoscapeStylesheet : [ ] ,
302
331
defaultSettings : {
@@ -307,19 +336,7 @@ CytoViz.defaultProps = {
307
336
spacingFactor : 1 ,
308
337
} ,
309
338
extraLayouts : { } ,
310
- getNodeDetails : ( node ) => < NodeData data = { node . data ( ) } /> ,
311
339
groups : { } ,
312
- labels : {
313
- elementDetails : 'Details' ,
314
- loading : 'Loading...' ,
315
- noSelectedNode : 'Select a node to view its data' ,
316
- settings : {
317
- compactMode : 'Compact layout' ,
318
- layout : 'Layout' ,
319
- title : 'Settings' ,
320
- spacingFactor : 'Spacing factor' ,
321
- zoomLimits : 'Min & max zoom' ,
322
- } ,
323
- } ,
340
+ labels : DEFAULT_LABELS ,
324
341
loading : false ,
325
342
} ;
0 commit comments