@xyo-network/react-node-renderer 2.72.4 → 2.72.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -23,10 +23,10 @@
23
23
  "@xyo-network/module-events": "^2.94.40",
24
24
  "@xyo-network/module-model": "^2.94.40",
25
25
  "@xyo-network/node-model": "^2.94.40",
26
- "@xyo-network/react-archivist": "~2.72.4",
27
- "@xyo-network/react-module": "~2.72.4",
28
- "@xyo-network/react-node": "~2.72.4",
29
- "@xyo-network/react-shared": "~2.72.4",
26
+ "@xyo-network/react-archivist": "~2.72.5",
27
+ "@xyo-network/react-module": "~2.72.5",
28
+ "@xyo-network/react-node": "~2.72.5",
29
+ "@xyo-network/react-shared": "~2.72.5",
30
30
  "@xyo-network/sentinel-model": "^2.94.40",
31
31
  "@xyo-network/witness-model": "^2.94.40",
32
32
  "cytoscape": "^3.28.1",
@@ -55,8 +55,8 @@
55
55
  "@xyo-network/http-bridge": "^2.94.40",
56
56
  "@xyo-network/id-plugin": "^2.91.11",
57
57
  "@xyo-network/node-memory": "^2.94.40",
58
- "@xyo-network/react-storybook": "~2.72.4",
59
- "@xyo-network/react-wallet": "~2.72.4",
58
+ "@xyo-network/react-storybook": "~2.72.5",
59
+ "@xyo-network/react-wallet": "~2.72.5",
60
60
  "@xyo-network/sentinel": "^2.94.40",
61
61
  "typescript": "^5.4.5"
62
62
  },
@@ -111,6 +111,6 @@
111
111
  },
112
112
  "sideEffects": false,
113
113
  "types": "dist/browser/index.d.ts",
114
- "version": "2.72.4",
114
+ "version": "2.72.5",
115
115
  "type": "module"
116
116
  }
@@ -11,6 +11,7 @@ import { MemorySentinel, SentinelConfigSchema } from '@xyo-network/sentinel'
11
11
  import { useState } from 'react'
12
12
 
13
13
  import { ModuleGraphFlexBoxWithProvider } from './GraphFlexBox'
14
+ import { Button, ButtonGroup } from '@mui/material'
14
15
 
15
16
  const nodeUrl = 'http://localhost:8080/node'
16
17
 
@@ -75,7 +76,15 @@ const Template: StoryFn<typeof ModuleGraphFlexBoxWithProvider> = (props) => <Mod
75
76
 
76
77
  const TemplateWithProvidedModule: StoryFn<typeof ModuleGraphFlexBoxWithProvider> = (props) => {
77
78
  const [node] = useProvidedNode()
78
- return <ModuleGraphFlexBoxWithProvider rootModule={node} {...props} />
79
+ const [layout, setLayout] = useState<'dagre' | 'euler' | 'cose-bilkent' | 'cola'>('euler')
80
+ return <div>
81
+ <ButtonGroup>
82
+ <Button onClick={() => setLayout('dagre')}>Dagre</Button>
83
+ <Button onClick={() => setLayout('euler')}>Euler</Button>
84
+ <Button onClick={() => setLayout('cose-bilkent')}>CoseBilkent</Button>
85
+ <Button onClick={() => setLayout('cola')}>Cola</Button>
86
+ </ButtonGroup><ModuleGraphFlexBoxWithProvider rootModule={node} {...props} layout={layout} />
87
+ </div>
79
88
  }
80
89
 
81
90
  const defaultProps = {
@@ -92,16 +92,29 @@ const TemplateCustomAddress: StoryFn<typeof NodeRelationalGraphFlexBox> = (props
92
92
  const [node] = useNodeFromNode('ChildNode')
93
93
  const elements = useCytoscapeElements(node)
94
94
  const options = useCytoscapeOptions(elements)
95
+
95
96
  return <NodeRelationalGraphFlexBox options={options} {...props} />
96
97
  }
97
98
 
98
- const TemplateProvidedNodeRenderer: StoryFn<typeof ProvidedNodeRenderer> = (props) => <ProvidedNodeRenderer {...props} />
99
+ const TemplateProvidedNodeRenderer: StoryFn<typeof ProvidedNodeRenderer> = (props) => {
100
+ const [layout, setLayout] = useState<'dagre' | 'euler' | 'cose-bilkent' | 'cola'>('euler')
101
+ return <div>
102
+ <ButtonGroup>
103
+ <Button onClick={() => setLayout('dagre')}>Dagre</Button>
104
+ <Button onClick={() => setLayout('euler')}>Euler</Button>
105
+ <Button onClick={() => setLayout('cose-bilkent')}>CoseBilkent</Button>
106
+ <Button onClick={() => setLayout('cola')}>Cola</Button>
107
+ </ButtonGroup>
108
+ <ProvidedNodeRenderer {...props} layout={layout} />
109
+ </div>
110
+ }
99
111
 
100
112
  const TemplateAttachDetach: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
101
113
  const [node] = useNodeFromNode('ChildNode')
102
114
  const elements = useCytoscapeElements(node)
103
115
  const options = useCytoscapeOptions(elements)
104
116
  const [idWitness, setIdWitness] = useState<IdWitness>()
117
+ const [layout, setLayout] = useState<'dagre' | 'euler' | 'cose-bilkent' | 'cola'>('euler')
105
118
 
106
119
  useAsyncEffect(
107
120
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -134,8 +147,12 @@ const TemplateAttachDetach: StoryFn<typeof NodeRelationalGraphFlexBox> = (props)
134
147
  <ButtonGroup>
135
148
  <Button onClick={handleAddWitness}>Add Witness</Button>
136
149
  <Button onClick={handleRemoveWitness}>Remove Witness</Button>
150
+ <Button onClick={() => setLayout('dagre')}>Dagre</Button>
151
+ <Button onClick={() => setLayout('euler')}>Euler</Button>
152
+ <Button onClick={() => setLayout('cose-bilkent')}>CoseBilkent</Button>
153
+ <Button onClick={() => setLayout('cola')}>Cola</Button>
137
154
  </ButtonGroup>
138
- <NodeRelationalGraphFlexBox options={options} {...props} />
155
+ <NodeRelationalGraphFlexBox layout={layout} options={options} {...props} />
139
156
  </>
140
157
  )
141
158
  }
@@ -51,19 +51,24 @@ export const NodeRelationalGraphFlexBox = forwardRef<HTMLDivElement, NodeRelatio
51
51
  let newCy: Core | undefined
52
52
  const container = cytoscapeRef.current
53
53
  if (container) {
54
- loadLayout(layout)
55
54
  newCy = cytoscape({
56
55
  container,
57
56
  ...options,
58
57
  })
59
- applyLayout(newCy, layout ?? 'euler', layoutOptions)
60
58
  setCy(newCy)
61
59
  }
62
60
  return () => {
63
61
  newCy?.destroy()
64
62
  setCy(undefined)
65
63
  }
66
- }, [options, cytoscapeRef, layoutOptions, layout])
64
+ }, [options, cytoscapeRef, layoutOptions])
65
+
66
+ useEffect(() => {
67
+ if (cy) {
68
+ loadLayout(layout)
69
+ applyLayout(cy, layout ?? 'euler', layoutOptions)
70
+ }
71
+ }, [cy, layoutOptions, layout])
67
72
 
68
73
  useEffect(() => {
69
74
  setCyContext?.(cy ? new WeakRef(cy) : undefined)