|
| 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 | + |
| 23 | + |
| 24 | +## Files |
| 25 | + |
| 26 | +CyLeaflet functionality is implemented 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 | + |
| 35 | + |
| 36 | + |
| 37 | +The following callbacks are used by CyLeaflet: |
| 38 | + |
| 39 | +- **Synchronize Leaflet view with Cytoscape view** |
| 40 | + - Input: Cytoscape `extent` property |
| 41 | + - Outputs: Leaflet `viewport` property, Leaflet `invalidateSize` property |
| 42 | + |
| 43 | + 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. |
| 44 | + |
| 45 | +- **Update Cytoscape graph elements** |
| 46 | + - Input: dcc.Store `data` property |
| 47 | + - Output: Cytoscape `elements` property |
| 48 | + |
| 49 | + 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