@@ -27,6 +27,13 @@ export const CytoViz = (props) => {
2727 const { cytoscapeStylesheet, defaultSettings, elements, extraLayouts, labels, loading, getNodeDetails, bubblesets } =
2828 props ;
2929
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+
3037 // Layout
3138 const [ isDrawerOpen , setIsDrawerOpen ] = React . useState ( false ) ;
3239 const [ currentDrawerTab , setCurrentDrawerTab ] = React . useState ( 0 ) ;
@@ -76,7 +83,7 @@ export const CytoViz = (props) => {
7683 // Init node selection behavior
7784 cytoscapeRef . on ( 'select' , 'node' , function ( e ) {
7885 const selectedNode = e . target ;
79- setCurrentNodeDetails ( getNodeDetails ( selectedNode ) ) ;
86+ setCurrentNodeDetails ( getNodeDetailsCallback ( selectedNode ) ) ;
8087 } ) ;
8188 cytoscapeRef . on ( 'unselect' , 'node' , function ( e ) {
8289 setCurrentNodeDetails ( null ) ;
@@ -86,7 +93,7 @@ export const CytoViz = (props) => {
8693 const selectedNode = e . target ;
8794 setCurrentDrawerTab ( 0 ) ;
8895 setIsDrawerOpen ( true ) ;
89- setCurrentNodeDetails ( getNodeDetails ( selectedNode ) ) ;
96+ setCurrentNodeDetails ( getNodeDetailsCallback ( selectedNode ) ) ;
9097 } ) ;
9198
9299 // Init bubblesets
@@ -287,16 +294,38 @@ CytoViz.propTypes = {
287294 spacingFactor: 'string',
288295 zoomLimits: 'string',
289296 }
297+ nodeData: {
298+ dictKey: 'string',
299+ dictValue: 'string',
300+ }
290301 }
291302 * </pre>
292303 */
293304 labels : PropTypes . object ,
294305 /**
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.
296308 */
297309 loading : PropTypes . bool ,
298310} ;
299311
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+
300329CytoViz . defaultProps = {
301330 cytoscapeStylesheet : [ ] ,
302331 defaultSettings : {
@@ -307,19 +336,7 @@ CytoViz.defaultProps = {
307336 spacingFactor : 1 ,
308337 } ,
309338 extraLayouts : { } ,
310- getNodeDetails : ( node ) => < NodeData data = { node . data ( ) } /> ,
311339 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 ,
324341 loading : false ,
325342} ;
0 commit comments