-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
Expose CyLeaflet subcomponent IDs + Add additional documentation of CyLeaflet design #211
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# CyLeaflet: Cytoscape graph component with map layer | ||
|
||
CyLeaflet is a Dash component included with Dash Cytoscape which adds geospatial mapping layer to Cytoscape. Node latitude and longitude are specified in the node data, and then rendered by CyLeaflet in the correct position on the map. See the [CyLeaflet documentation](https://dash.plotly.com/cytoscape/cyleaflet) for full usage information. | ||
|
||
This document describes the architecture of the CyLeaflet component. | ||
|
||
|
||
## Component structure | ||
|
||
CyLeaflet uses the Dash [All-in-One Component](https://dash.plotly.com/all-in-one-components) pattern to combine Dash Cytoscape and Dash Leaflet with minimal overhead. | ||
|
||
This means that CyLeaflet appears at first glance to be a first-class Dash component, but is actually multiple Dash components in a trenchcoat. | ||
|
||
Under the hood, an instance of CyLeaflet consists of: | ||
|
||
1. A Dash Cytoscape instance | ||
2. A Dash Leaflet instance | ||
3. A dcc.Store instance used for holding element data (explained in more detail below) | ||
4. Some surrounding html.Divs which apply the necessary styling to align the Cytoscape canvas exactly on top of the Leaflet canvas. | ||
5. Several clientside callbacks to link the individual components together | ||
|
||
![fig1](img/cyleaflet-layers.png) | ||
|
||
## Files | ||
|
||
CyLeaflet functionality is implemented in the following files: | ||
|
||
1. `dash_cytoscape/CyLeaflet.py`: CyLeaflet class definition, instantiation of underlying Cytoscape and Leaflet components, layout and styling to align the two canvases, and registration of clientside callbacks | ||
2. `src/lib/cyleaflet_clientside.js`: Clientside callback function implementations | ||
|
||
|
||
## Callbacks | ||
|
||
![fig2](img/cyleaflet-callbacks.png) | ||
|
||
|
||
The following callbacks are used by CyLeaflet: | ||
|
||
- **Synchronize Leaflet view with Cytoscape view** | ||
- Input: Cytoscape `extent` property | ||
- Outputs: Leaflet `viewport` property, Leaflet `invalidateSize` property | ||
|
||
Purpose: Ensures that the nodes remain in the same places on the map whenever the view is zoomed or dragged. Whenever the Cytoscape view changes, this callback updates the Leaflet view to match. An additional output, the Leaflet `invalidateSize` property, ensures the map gets refreshed properly. | ||
|
||
- **Update Cytoscape graph elements** | ||
- Input: dcc.Store `data` property | ||
- Output: Cytoscape `elements` property | ||
|
||
Purpose: Provides a way for the Dash developer to update the graph elements displayed in Cytoscape. This callback transforms the `lat` and `lon` coordinates specified in the node data into a corresponding (x, y) canvas position that will align with the map. Updating the Cytoscape nodes directly does not work, because this skips the transformation step, and the nodes will not appear in the correct map positions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make it easier than
cyleaflet_instance.ids["leaf"]
? I guess this way you get autocompletion?Regardless, in order to use this you needed to pull
cyleaflet_instance
out of the layout... which might not always be possible, I wonder if it would also be worth making acyto.CyLeaflet.get_leaflet_id(cyleaflet_id)
etc that would construct the PMC ID for you - and then you could even callcyto.CyLeaflet.get_leaflet_id(ALL)
or(MATCH)
if you wanted to construct your own PMC?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah exactly, this way you get autocomplete and it looks cleaner than accessing a dictionary.
I see your point -- I'm open to switching this to exposing static functions instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it needs to be one or the other - this pattern is very nice when it works, but we can add the functions as well to cover the cases when it doesn't work.