* Load network data to be displayed in vis-network graph. * * @return a promise which executes a load of network data.
()
| 260 | * @return a promise which executes a load of network data. |
| 261 | */ |
| 262 | private async load(): Promise<void> { |
| 263 | const currParams = networkUtils.buildParams(this.state); |
| 264 | if (!currParams.to || !currParams.from) { |
| 265 | this.network?.destroy?.(); |
| 266 | this.network = undefined; |
| 267 | this.setState({ ...networkUtils.buildState(), loadingDtypes: false, dtypes: this.state.dtypes }); |
| 268 | return; |
| 269 | } |
| 270 | this.setState({ loadingData: true }); |
| 271 | const response = await NetworkRepository.getData(this.props.dataId, currParams); |
| 272 | if (response?.error) { |
| 273 | this.setState({ error: <RemovableError {...response} />, loadingData: false }); |
| 274 | return; |
| 275 | } |
| 276 | const { nodes, edges } = response!; |
| 277 | if (this.state.weight) { |
| 278 | edges.forEach((edge) => (edge.title = `Weight: ${edge.value}`)); |
| 279 | } |
| 280 | nodes.forEach((node) => (node.title = node.label)); |
| 281 | const nodesDataset = new DataSet(nodes); |
| 282 | const edgesDataset = new DataSet(edges); |
| 283 | this.draw(nodesDataset, edgesDataset); |
| 284 | const networkNodes = (this.network as any)?.body.nodes; |
| 285 | let groupsMapping: GroupColor[] = []; |
| 286 | if (response?.groups && Object.keys(response.groups).length > 1) { |
| 287 | groupsMapping = Object.entries(response.groups).map(([nodeGroup, nodeId]) => [ |
| 288 | nodeGroup, |
| 289 | { ...networkNodes[nodeId]?.options?.color }, |
| 290 | ]); |
| 291 | } |
| 292 | this.setState({ |
| 293 | params: currParams, |
| 294 | loadingData: false, |
| 295 | allNodes: nodesDataset.get({ returnType: 'Object' }), |
| 296 | highlightActive: false, |
| 297 | groups: groupsMapping, |
| 298 | error: undefined, |
| 299 | }); |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Draw the vis-network graph. |