✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.
feat: hide empty parent nodes (array/object)
AykutSarac02f4fe46e7fd
diff --git a/src/features/editor/views/GraphView/lib/jsonParser.ts b/src/features/editor/views/GraphView/lib/jsonParser.tsindex aaa6382b..124dca90 100644--- a/src/features/editor/views/GraphView/lib/jsonParser.ts+++ b/src/features/editor/views/GraphView/lib/jsonParser.ts@@ -73,11 +73,31 @@ export function parser(jsonStr: string): Graph {}}- states.graph.nodes = states.graph.nodes.map(node => ({+ // filter parent nodes that have no children+ // not the best way to do this, but it works+ const filteredNodes = states.graph.nodes.filter(node => {+ if (node.data.isParent && node.data.childrenCount === 0) {+ return false;+ }++ return true;+ });++ // add path to nodes+ states.graph.nodes = filteredNodes.map(node => ({...node,path: getNodePath(states.graph.nodes, states.graph.edges, node.id),}));+ // filter edges that have no from or to node (since we filtered empty parent nodes)+ states.graph.edges = states.graph.edges.filter(edge => {+ const fromNode = states.graph.nodes.find(node => node.id === edge.from);+ const toNode = states.graph.nodes.find(node => node.id === edge.to);++ if (!fromNode || !toNode) return false;+ return true;+ });+return states.graph;} catch (error) {console.error(error);