-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation mapping visual UI with code structure, modules and classes #93
Comments
As an update on this, I have been checking/playing around with some packages/utilities to generate diagrams:
As an example running the following command (setting the path to the
And running the following (setting the path to the napari directory) you can get a class diagram for the related class that contains the layer list (
However, seems like some relations are not shown unless I change the code to add attributes like the delegate. If I add a For the moment I will try to programmatically use If you have any other tools suggestions let me know! |
Did you have a look at mermaid? Probably a lot less powerful than the options you looked at, but has the advantage of being a lot more readable. |
Will take a look at it, thanks for the suggestion! |
Those look pretty cool @dalthviz but very much 🤯 |
Is quite interesting what you can generate with some tools although seems like the generation process needs some level of refinement to actually be useful most of the time :) I started checking @melissawm Also, seems like |
After playing around a little bit more I was able to generate the directory layout using the dependency graph generated by Layers listDependencies diagram (related modules)graph LR
napari._qt.containers._base_item_model(napari._qt.containers._base_item_model)
napari._qt.containers._layer_delegate(napari._qt.containers._layer_delegate)
napari._qt.containers._layer_delegate --> napari._qt.containers._base_item_model
napari._qt.containers._layer_delegate --> napari._qt.containers.qt_layer_model
napari._qt.containers._layer_delegate --> napari.components
napari._qt.containers._layer_delegate --> napari.components.layerlist
napari._qt.containers.qt_layer_list(napari._qt.containers.qt_layer_list)
napari._qt.containers.qt_layer_list --> napari._qt.containers._base_item_model
napari._qt.containers.qt_layer_list --> napari._qt.containers._layer_delegate
napari._qt.containers.qt_layer_list --> napari._qt.containers.qt_list_view
napari._qt.containers.qt_layer_list --> napari.components
napari._qt.containers.qt_layer_list --> napari.components.layerlist
napari._qt.containers.qt_layer_list --> napari.layers
napari._qt.containers.qt_layer_model(napari._qt.containers.qt_layer_model)
napari._qt.containers.qt_layer_model --> napari._qt.containers.qt_list_model
napari._qt.containers.qt_layer_model --> napari.layers
napari._qt.containers.qt_list_model(napari._qt.containers.qt_list_model)
napari._qt.containers.qt_list_model --> napari._qt.containers._base_item_model
napari._qt.containers.qt_list_view(napari._qt.containers.qt_list_view)
napari._qt.containers.qt_list_view --> napari._qt.containers.qt_list_model
napari.components(napari.components)
napari.components --> napari.components.layerlist
napari.components.layerlist(napari.components.layerlist)
napari.components.layerlist --> napari.layers
napari.layers(napari.layers)
Source code directory layout
The script I'm using to generate the page: To run the code above you need to have GraphViz installed/the Running the script should generate a I will check now what I can generate for the other sections and maybe explore adding some style to the mermaid diagram but if anyone has suggestions, comments or ideas about this let me know! |
This looks great! Would we be able to infer connection between the GUI and this graph in some way? It would be awesome to be able to answer "I want to edit the size of this button but where is the code for it?" |
That's an interesting idea! I'm not sure how something like that can be done but I will check 👍 Also, I was checking and seems like you can add links to an URL inside the mermaid diagram so for each node we could add a link to the module file on GitHub or a link to get further information but I guess that's a different idea from the GUI to code above 😅 (at least in terms of granularity) |
Playing around a little bit with the definition of an So, for example you could Here how the Branch with the Maybe a more polished way to do this could be worthy to explore? Like showing the output in a dockwidget and activating the functionality through a setting like with |
I think this can be useful as a debugging/info option |
Wow that looks super useful! |
Agreed this would be super useful developer/debugging tool. I think adding a setting section for developer settings might make sense, then I think we could add one for this (as well perfmon), so that it can be easily enabled either through the GUI or with an environment variable. |
So I went for the plugin approach and created a simple plugin with a widget that can show the output of the event and install/uninstall the event filter (I used the cookiecutter template to create it). I put the code in a repo just in case someone wants to check it.
|
An update regarding the docs generation part (generating a Layers listDependencies diagram (related
|
Another update regarding the plugin, after checking the code to debug events pointed out by @brisvag that is at https://github.com/napari/napari/blob/397ef2c4f978e60a0cb231887f46d9de2d76a002/napari/utils/events/debugging.py#L69 I tried adding that functionality to the plugin (adding a way to activate the events logging and show the output inside the plugin while adding support for linking the stacktrace entry to open corresponding file): If you want to give it a try you can check the code from the The implementation patches things to work so probably that needs to be improved but happy to hear any feedback about how something like that could be done properly :) |
This issue has been mentioned on Image.sc Forum. There might be relevant details there: |
Just in case, I released an initial version of the Also, the PR related with adding the UI sections in the documentation is at #114 I added there some functionality to zoom the diagrams and organized the nodes a little bit more following the given feedback: #114 (comment) Any other suggestion or comment is appreciated :) |
Quick update, the plugin is now available also on conda/conda-forge 🎉 : https://anaconda.org/conda-forge/napari-ui-tracer |
📚 New content request
After helping around fixing bugs, I was thinking that maybe having some sort of mapping from the visual elements/UI to its related source code (directory structure, modules and classes) could be a good way to document the Napari GUI. This could help with the task of onboarding contributors and also document the general way things are currently working in terms of the GUI.
I think it could be nice to create documentation per interface section (layers controls, layers list, viewer, menus, dialogs, etc) and show for each of them the corresponding subset of the Napari source code directory layout: only the most related directories/files as well as some sort of dependency diagram(s) to show how the modules and classes depend between each other in that subset of the Napari source code.
Checking, seems like some exploration to do mappings of the source code have been done in a more or less automatic manner as well as an exploration of tooling to create diagrams (napari/napari#1389). I would say that finding a way to at least semiautomatically create this documentation should be explored.
Also, talking about this with @melissawm a suggestion I got is asking core developers about the current code layout and the decisions behind the current code layout to document this, and seems like @psobolewskiPhD and @goanpeca did some notes about things that could be nice to document related to the Napari source code that could also apply to the idea here of creating some documentation for the visual UI/frontend (https://hackmd.io/2iq_CmjHR8mK0UL7e4bYaw#napari-codebase-related).
This effort could be related also with #49
Outline
The sections above come from what I have explored from the source code but probably there are more UI sections.
Creating an issue for this as discussed with @potating-potato
The text was updated successfully, but these errors were encountered: