diff --git a/src/lib/vis/visualizations/vis0D/Vis0D.tsx b/src/lib/vis/visualizations/vis0D/Vis0D.tsx index b564bf47e8eea210a309a63d59f718f659e0bcbe..f2020895a7a4fd1dcba37f50f10476d5f890a57e 100644 --- a/src/lib/vis/visualizations/vis0D/Vis0D.tsx +++ b/src/lib/vis/visualizations/vis0D/Vis0D.tsx @@ -148,26 +148,45 @@ const Vis0DSettings = ({ settings, graphMetadata, updateSettings }: Visualizatio const [attributeOptions, setAttributeOptions] = useState<string[]>([]); const [statsOptions, setStatsOptions] = useState<string[]>([]); useEffect(() => { - if (settings.selectedEntity === '' && graphMetadata && graphMetadata.nodes && graphMetadata.nodes.labels.length > 0) { - const firstEntity = graphMetadata.nodes.labels[0]; + if (graphMetadata && graphMetadata.nodes && graphMetadata.nodes.labels.length > 0) { + if (settings.selectedEntity === '') { + const firstEntity = graphMetadata.nodes.labels[0]; - const attributesFirstEntity = Object.keys(graphMetadata.nodes.types[firstEntity].attributes); - setAttributeOptions(attributesFirstEntity); - const selectedAttribute = attributesFirstEntity[0]; + const attributesFirstEntity = Object.keys(graphMetadata.nodes.types[firstEntity].attributes); + setAttributeOptions(attributesFirstEntity); + const selectedAttribute = attributesFirstEntity[0]; - const attributeSelectedStatistics = graphMetadata.nodes.types[firstEntity].attributes[selectedAttribute].statistics; + const attributeSelectedStatistics = graphMetadata.nodes.types[firstEntity].attributes[selectedAttribute].statistics; - const notNaNStats = Object.keys(attributeSelectedStatistics).filter(key => { - const value = attributeSelectedStatistics[key as keyof typeof attributeSelectedStatistics]; - return typeof value === 'number' && !isNaN(value); - }); + const notNaNStats = Object.keys(attributeSelectedStatistics).filter(key => { + const value = attributeSelectedStatistics[key as keyof typeof attributeSelectedStatistics]; + return typeof value === 'number' && !isNaN(value); + }); - setStatsOptions(notNaNStats as string[]); - updateSettings({ - selectedEntity: firstEntity, - selectedAttribute: selectedAttribute, - selectedStat: notNaNStats[0], - }); + setStatsOptions(notNaNStats as string[]); + updateSettings({ + selectedEntity: firstEntity, + selectedAttribute: selectedAttribute, + selectedStat: notNaNStats[0], + }); + } + + if (settings.selectedEntity != null && attributeOptions.length == 0) { + const attributesFirstEntity = Object.keys(graphMetadata.nodes.types[settings.selectedEntity].attributes); + setAttributeOptions(attributesFirstEntity); + } + + if (settings.selectedEntity != null && settings.selectedAttribute && statsOptions.length == 0) { + const attributeSelectedStatistics = + graphMetadata.nodes.types[settings.selectedEntity].attributes[settings.selectedAttribute].statistics; + + const notNaNStats = Object.keys(attributeSelectedStatistics).filter(key => { + const value = attributeSelectedStatistics[key as keyof typeof attributeSelectedStatistics]; + return typeof value === 'number' && !isNaN(value); + }); + + setStatsOptions(notNaNStats as string[]); + } } }, [graphMetadata]);