Skip to content

Commit 0d2b47f

Browse files
author
Xing
authored
Add 2 new demos, reoganize README, update Cytoscape wrapper default values and docstring (#47)
* Added new demos for using preset animations and reset button * Update usage-events to have ids for edges * Reorganize README + more images * Cytoscape.react.js: Added default values, updated docstring, added normalize feature * Added util function to display the default value by reading metadata * `npm run build:all` * Update CHANGELOG.md * Apply suggestions from code review Co-Authored-By: xhlulu <[email protected]> * Updated based on PR feedback * Fixed variable name
1 parent 2b053db commit 0d2b47f

16 files changed

+329
-77
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
* `demos/usage-dag-edges.py`: Show different types of edges in a DAG
1111
* `demos/usage-elements-extra.py`: Shows how to load external layouts, otherwise same app as `usage-elements.py`.
12+
* `demos/usage-preset-animation.py`: Example of animating nodes using the preset layout.
13+
* `demos/usage-reset-button.py`: Example of resetting the graph position using a button.
1214
* `dash_cytoscape.load_extra_layouts()`: A new function that can be called before initializing the Dash app (`app = dash.Dash(__name__)`) to load the JS bundle containing the external layouts.
1315
* `webpack.[dev|prod].extra.config.js`: Two new webpack configs for external layouts.
1416
* `src/lib/extra_index.js`: Loads external layouts before exporting the `Cytoscape` class. Needed to generate the new bundles.
1517
* Images of new external layouts.
1618
* `dash_cytoscape/dash_cytoscape_extra.[min|dev].js`: New bundles containing the extra layouts. Those bundles are double in size compared to the default bundles. Therefore, they are only loaded when the user uses `load_extra_layouts()` to limit bandwidth usage and maximize loading speed. Please view [fast3g-cytoscape](demos/images/fast3g-cytoscape.PNG) for an example of the impact on loading time.
19+
* `dash_cytoscape._display_default_values()`: A util function to display the default prop values by reading `metadata.json`. Useful for documentation.
1720

1821
### Changed
19-
* `src/lib/components/Cytoscape.react.js`: Updated description to include information about new external layouts.
22+
* `usage-events.py`: Added IDs for the edges in order to pass Percy tests.
23+
* `src/lib/components/Cytoscape.react.js`: Updated docstring to include information about new external layouts and warning about nodes that can't be modified by a callback. Added more default props for a better expected behavior.
2024
* `package.json`: Added new builds for the extra layouts, modified `npm build:all` to include new builds. Added external layouts as dependencies.
25+
* `README.md`: Moved images, added more images at the end, added useful links.
26+
2127

2228
## [0.0.5] - 2019-03-08
2329

README.md

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Dash Cytoscape [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/plotly/dash-cytoscape/blob/master/LICENSE) [![PyPi Version](https://img.shields.io/pypi/v/dash-cytoscape.svg)](https://pypi.org/project/dash-cytoscape/)
22

3-
A Component Library for Dash aimed at facilitating network visualization in Python, wrapped around [Cytoscape.js](http://js.cytoscape.org/).
3+
A Dash component library for creating interactive and customizable networks in Python, wrapped around [Cytoscape.js](http://js.cytoscape.org/).
44

5-
Interacting with the stylesheet:
65
![usage-stylesheet-demo](https://raw.githubusercontent.com/plotly/dash-cytoscape/master/demos/images/usage-stylesheet-demo.gif)
76

8-
Interacting with the elements:
9-
![usage-elements-demo](https://raw.githubusercontent.com/plotly/dash-cytoscape/master/demos/images/usage-elements-demo.gif)
7+
* 🌟 [Medium Article](https://medium.com/@plotlygraphs/introducing-dash-cytoscape-ce96cac824e4)
8+
* 📣 [Community Announcement](https://community.plot.ly/t/announcing-dash-cytoscape/19095)
9+
* 💻 [Github Repository](https://github.com/plotly/dash-cytoscape)
10+
* 📚 [User Guide](https://dash.plot.ly/cytoscape)
11+
* 🗺 [Component Reference](https://dash.plot.ly/cytoscape/reference)
12+
* 📺 [Webinar Recording](https://www.youtube.com/watch?v=snXcIsCMQgk)
1013

1114
## Getting Started
1215

@@ -52,16 +55,34 @@ if __name__ == '__main__':
5255
app.run_server(debug=True)
5356
```
5457

58+
![basic-usage](https://raw.githubusercontent.com/plotly/dash-cytoscape/master/demos/images/basic-usage.gif)
59+
60+
### External layouts
61+
62+
You can also add external layouts. Use the `cyto.load_extra_layouts()` function to get started:
63+
64+
```python
65+
import dash
66+
import dash_cytoscape as cyto
67+
import dash_html_components as html
68+
69+
cyto.load_extra_layouts()
70+
71+
app = dash.Dash(__name__)
72+
app.layout = html.Div([
73+
cyto.Cytoscape(...)
74+
])
75+
```
5576

5677
## Documentation
5778

58-
View the [Dash Cytoscape User Guide](https://dash.plot.ly/cytoscape/) to get started now. You can also use the [component reference](https://dash.plot.ly/cytoscape/reference/) to find how to use a certain feature.
79+
The [Dash Cytoscape User Guide](https://dash.plot.ly/cytoscape/) contains everything you need to know about the library. It contains useful examples, functioning code, and is fully interactive. You can also use the [component reference](https://dash.plot.ly/cytoscape/reference/) for a complete and concise specification of the API.
5980

6081
To learn more about the core Dash components and how to use callbacks, view the [Dash documentation](https://dash.plot.ly/).
6182

6283
For supplementary information about the underlying Javascript API, view the [Cytoscape.js documentation](http://js.cytoscape.org/).
6384

64-
### Development and Contributions
85+
## Contributing
6586

6687
Make sure that you have read and understood our [code of conduct](CODE_OF_CONDUCT.md), then head over to [CONTRIBUTING](CONTRIBUTING.md) to get started.
6788

@@ -79,3 +100,11 @@ Huge thanks to the Cytoscape Consortium and the Cytoscape.js team for their cont
79100

80101
The Pull Request and Issue Templates were inspired from the
81102
[scikit-learn project](https://github.com/scikit-learn/scikit-learn).
103+
104+
## Gallery
105+
106+
Interacting with the [elements](usage-elements.py):
107+
![usage-elements-demo](demos/images/usage-elements-demo.gif)
108+
109+
Using [external layouts](demos/usage-elements-extra.py):
110+
![usage-elements-extra](demos/images/usage-elements-extra.gif)

dash_cytoscape/Cytoscape.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ class attribute).
5454
- `breadthfirst`: Tree structure built using BFS, with optional `roots`
5555
- `cose`: Force-directed physics simulation
5656
57-
2. The following external layouts are also included:
57+
2. Some external layouts are also included. To use them, run
58+
`dash_cytoscape.load_extra_layouts()` before creating your Dash app. Be careful about
59+
using the extra layouts when not necessary, since they require supplementary bandwidth
60+
for loading, which impacts the startup time of the app.
5861
- `cose-bilkent`: https://github.com/cytoscape/cytoscape.js-cose-bilkent
5962
- `cola`: https://github.com/cytoscape/cytoscape.js-cola
6063
- `euler`: https://github.com/cytoscape/cytoscape.js-dagre
@@ -104,7 +107,7 @@ class attribute).
104107
- autounselectify (boolean; optional): Whether nodes should be unselectified (immutable selection state) by
105108
default (if true, overrides individual element state).
106109
- autoRefreshLayout (boolean; optional): Whether the layout should be refreshed when elements are added or removed.
107-
- tapNode (dict; optional): The complete node dictionary returned when you tap or click it.
110+
- tapNode (dict; optional): The complete node dictionary returned when you tap or click it. Read-only.
108111
109112
1. Node-specific items:
110113
- `edgesData` (dictionary)
@@ -133,8 +136,8 @@ class attribute).
133136
- `isChild` (boolean)
134137
- `isOrphan` (boolean)
135138
- `relativePosition` (dictionary)
136-
- tapNodeData (dict; optional): The data dictionary of a node returned when you tap or click it.
137-
- tapEdge (dict; optional): The complete edge dictionary returned when you tap or click it.
139+
- tapNodeData (dict; optional): The data dictionary of a node returned when you tap or click it. Read-only.
140+
- tapEdge (dict; optional): The complete edge dictionary returned when you tap or click it. Read-only.
138141
139142
1. Edge-specific items:
140143
- `isLoop` (boolean)
@@ -155,13 +158,13 @@ class attribute).
155158
- `selectable` (boolean)
156159
- `selected` (boolean)
157160
- `style` (dictionary)
158-
- tapEdgeData (dict; optional): The data dictionary of an edge returned when you tap or click it.
159-
- mouseoverNodeData (dict; optional): The data dictionary of a node returned when you hover over it.
160-
- mouseoverEdgeData (dict; optional): The data dictionary of an edge returned when you hover over it.
161+
- tapEdgeData (dict; optional): The data dictionary of an edge returned when you tap or click it. Read-only.
162+
- mouseoverNodeData (dict; optional): The data dictionary of a node returned when you hover over it. Read-only.
163+
- mouseoverEdgeData (dict; optional): The data dictionary of an edge returned when you hover over it. Read-only.
161164
- selectedNodeData (list; optional): The list of data dictionaries of all selected nodes (e.g. using
162-
Shift+Click to select multiple nodes, or Shift+Drag to use box selection).
165+
Shift+Click to select multiple nodes, or Shift+Drag to use box selection). Read-only.
163166
- selectedEdgeData (list; optional): The list of data dictionaries of all selected edges (e.g. using
164-
Shift+Click to select multiple nodes, or Shift+Drag to use box selection)."""
167+
Shift+Click to select multiple nodes, or Shift+Drag to use box selection). Read-only."""
165168
@_explicitize_args
166169
def __init__(self, id=Component.UNDEFINED, className=Component.UNDEFINED, style=Component.UNDEFINED, elements=Component.UNDEFINED, stylesheet=Component.UNDEFINED, layout=Component.UNDEFINED, pan=Component.UNDEFINED, zoom=Component.UNDEFINED, panningEnabled=Component.UNDEFINED, userPanningEnabled=Component.UNDEFINED, minZoom=Component.UNDEFINED, maxZoom=Component.UNDEFINED, zoomingEnabled=Component.UNDEFINED, userZoomingEnabled=Component.UNDEFINED, boxSelectionEnabled=Component.UNDEFINED, autoungrabify=Component.UNDEFINED, autolock=Component.UNDEFINED, autounselectify=Component.UNDEFINED, autoRefreshLayout=Component.UNDEFINED, tapNode=Component.UNDEFINED, tapNodeData=Component.UNDEFINED, tapEdge=Component.UNDEFINED, tapEdgeData=Component.UNDEFINED, mouseoverNodeData=Component.UNDEFINED, mouseoverEdgeData=Component.UNDEFINED, selectedNodeData=Component.UNDEFINED, selectedEdgeData=Component.UNDEFINED, **kwargs):
167170
self._prop_names = ['id', 'className', 'style', 'elements', 'stylesheet', 'layout', 'pan', 'zoom', 'panningEnabled', 'userPanningEnabled', 'minZoom', 'maxZoom', 'zoomingEnabled', 'userZoomingEnabled', 'boxSelectionEnabled', 'autoungrabify', 'autolock', 'autounselectify', 'autoRefreshLayout', 'tapNode', 'tapNodeData', 'tapEdge', 'tapEdgeData', 'mouseoverNodeData', 'mouseoverEdgeData', 'selectedNodeData', 'selectedEdgeData']

dash_cytoscape/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,32 @@ def load_extra_layouts():
9090
'namespace': package_name
9191
}
9292
]
93+
94+
95+
def _display_default_values():
96+
out_string = ""
97+
98+
metadata_path = _os.path.join(
99+
_os.path.dirname(_os.path.realpath(__file__)),
100+
'metadata.json'
101+
)
102+
103+
with open(metadata_path, 'r') as file:
104+
data = json.loads(file.read())
105+
106+
for component in data:
107+
component_name = component.replace('src/lib/components/', '').replace('.react.js', '')
108+
metadata = data[component]
109+
props = metadata['props']
110+
111+
out_string += "## {} Default Values\n\n".format(component_name)
112+
113+
for prop_name in props:
114+
prop = props[prop_name]
115+
116+
if 'defaultValue' in prop:
117+
default = prop['defaultValue']['value']
118+
119+
out_string += "* *{}*: {}\n".format(prop_name, default)
120+
121+
return out_string

dash_cytoscape/dash_cytoscape.dev.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_cytoscape/dash_cytoscape.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_cytoscape/dash_cytoscape_extra.dev.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_cytoscape/dash_cytoscape_extra.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)