Skip to content

Commit 231eaab

Browse files
committed
add additional developer documentation for CyLeaflet
1 parent be60394 commit 231eaab

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

CYLEAFLET.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# CyLeaflet: Cytoscape graph component with map layer
2+
3+
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.
4+
5+
This document describes the architecture of the CyLeaflet component.
6+
7+
8+
## Component structure
9+
10+
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.
11+
12+
This means that CyLeaflet appears at first glance to be a first-class Dash component, but is actually multiple Dash components in a trenchcoat.
13+
14+
Under the hood, an instance of CyLeaflet consists of:
15+
16+
1. A Dash Cytoscape instance
17+
2. A Dash Leaflet instance
18+
3. A dcc.Store instance used for holding element data (explained in more detail below)
19+
4. Some surrounding html.Divs which apply the necessary styling to align the Cytoscape canvas exactly on top of the Leaflet canvas.
20+
5. Several clientside callbacks to link the individual components together
21+
22+
![fig1](img/cyleaflet-layers.png)
23+
24+
## Files
25+
26+
CyLeaflet functionality is dimplemented in the following files:
27+
28+
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
29+
2. `src/lib/cyleaflet_clientside.js`: Clientside callback function implementations
30+
31+
32+
## Callbacks
33+
34+
The following callbacks are used by CyLeaflet:
35+
36+
- **Synchronize Leaflet view with Cytoscape view**
37+
- Input: Cytoscape extent property
38+
- Output: Leaflet viewport property
39+
40+
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.
41+
42+
- **Update Cytoscape graph elements**
43+
- Input: dcc.Store `data` property
44+
- Output: Cytoscape `elements` property
45+
46+
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.

0 commit comments

Comments
 (0)