M: Inverse treeView

This commit is contained in:
Ivan 2024-09-26 22:40:00 +03:00
parent aeaa92df3f
commit f3c11747d8

View File

@ -27,7 +27,7 @@ function DlgShowAST({ hideWindow, syntaxTree, expression }: DlgShowASTProps) {
const nodes: GraphNode[] = useMemo( const nodes: GraphNode[] = useMemo(
() => () =>
syntaxTree.map(node => ({ syntaxTree.map(node => ({
id: String(node.uid), id: String(syntaxTree.length - node.uid), // invert order of IDs to force correct ordering in graph layout
label: labelSyntaxTree(node), label: labelSyntaxTree(node),
fill: colorBgSyntaxTree(node, colors) fill: colorBgSyntaxTree(node, colors)
})), })),
@ -40,15 +40,15 @@ function DlgShowAST({ hideWindow, syntaxTree, expression }: DlgShowASTProps) {
if (node.parent !== node.uid) { if (node.parent !== node.uid) {
result.push({ result.push({
id: String(node.uid), id: String(node.uid),
source: String(node.parent), source: String(syntaxTree.length - node.parent),
target: String(node.uid) target: String(syntaxTree.length - node.uid)
}); });
} }
}); });
return result; return result;
}, [syntaxTree]); }, [syntaxTree]);
const handleHoverIn = useCallback((node: GraphNode) => setHoverID(Number(node.id)), []); const handleHoverIn = useCallback((node: GraphNode) => setHoverID(syntaxTree.length - Number(node.id)), [syntaxTree]);
const handleHoverOut = useCallback(() => setHoverID(undefined), []); const handleHoverOut = useCallback(() => setHoverID(undefined), []);