zjl9959 / algviz

Algorithm animation engine for Python in Jupyter.
https://zjl9959.github.io/algviz/
GNU General Public License v3.0
64 stars 6 forks source link

Multi-Child Tree Display Does Not Update #6

Closed lucasmurphyy closed 1 year ago

lucasmurphyy commented 1 year ago

Sample code from the tutorial recreates the bug:

tree_info = {
    0: [1, 2, 3],   # Node0 has child nodes: 1, 2, 3.
    1: [4, 5],      # Node1 has child nodes: 4, 5.
    2: [6]          # Node2 has child node: 6.
}
nodes_label = {
    0: 'root',      # Set the display name of node0 as 'root'.
    3: 'n3'         # Set the display name of node3 as 'n3'.
}
root2 = algviz.parseTree(tree_info, nodes_label)
tree = viz.createGraph(data=root2, name="Tree")
viz.display()
# Visit all the child nodes in root2 and mark them.
for child in root2.children():
    tree.markNode(algviz.color_red, child)
    viz.display(1.0)
tree_node3 = root2.childAt(2)           # Record node3.
tree_node3.add(algviz.TreeNode(8))      # Add a new node8 for node3.
viz.display()
tree_node3.add(algviz.TreeNode(7), 0)   # Add a new node7 for node3.
viz.display()
root2.removeAt(1)                       # Remove the subtree 'node2->node6' of the root node.
viz.display()

The first cell correctly displays the tree when ran. The second cell does not update. It appears that after one or two 'display()' calls the graph no longer visually updates (however when I checked, the tree object was still having new nodes added).

Test enviroment:

zjl9959 commented 1 year ago

@lucasmurphyy Thank you for providing detailed information about this bug! I reproduced the problem that you described. It seems that the tree node status change wasn't detected when the animation updating. I will try to fix it in the next release version.

lucasmurphyy commented 1 year ago

Thanks for the quick response! Yeah I’ve been looking for a library to demonstrate the building and searching of a trie data structure and this repo is absolutely leagues ahead of anything else I have found. Could I also leave another suggestion? It would be useful to have a way to rename node values. For my trie example I would like to have count values of each node update as the trie is being constructed, however it seems that the value you set when you add a node cannot be changed.

P.S. I tried some of the tutorial code for vectors and it seems the issue is also consistent (i.e. updates once then stops).

zjl9959 commented 1 year ago

@lucasmurphyy I'm glad to hear that this repo can help to solve your problems.

  1. About the animation doesn't update issue, I find the root cause is the compatibility issue with jupyter notebook. I can reproduce this bug with VSCode + Jupyter_extension_v2023.2.1200692131. But I can not reproduce this bug with Anaconda + JupyterNotebook_v6.5.2 + Chrome_111.0.5563.65. I will improve the compatibility in the next release version. But for a quick fix, you can roll back your jupyter notebook (before 2022.10.1) or try the Anaconda + JupytherNotebook environment.
  2. About the "rename node values" suggestion, algviz has already supported this feature. You can simply assign a new name to the node.val like this:
    node.val="a:3"
    viz.display()
    node.val="a:4"
    viz.display()

    And you can see the animation about the node value update like this: map_class_example

If you meet any other problems when using algviz, please feel free to pin me! 😊

zjl9959 commented 1 year ago

This is the related issue about the VSCode jupyter extension. https://github.com/microsoft/vscode-jupyter/issues/13105

zjl9959 commented 1 year ago

The latest vscode jupyter extension(v2023.3.1000892223 or later) has fixed the issue https://github.com/microsoft/vscode-jupyter/issues/13105. You can open this issue again if the problem still exists.

lucasmurphyy commented 1 year ago

Thanks for the help!