Skip to content

Commit 2b053db

Browse files
author
Xing
authored
Adding option to load external layouts (#46)
* 🚫 Update Gitignore * 📦 Add external layouts to package.json Also update yarn.lock * 🆕 Create extra_index.js to load external layouts Update Cytoscape.react.js description as well * Add new webpack configs + update build scripts * 🚧 `npm run build:all` * 🆕 Add `load_extra_layouts()` to dash_cytoscape This function lets the user load the extra layouts by changing the global _js_dist * 🆕 Create demos for new features * 📷 Images for external layouts * Update requirements.txt * Update CHANGELOG.md * Flake 8 on new demos * Add docstring to load_extra_layouts()
1 parent 5ef1c66 commit 2b053db

21 files changed

+6699
-47
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,5 @@ temp.py# Sublime-github package stores a github token in this file
301301
# https://packagecontrol.io/packages/sublime-github
302302
GitHub.sublime-settings
303303
temp.py
304+
test.py
305+
tests/selenium_scripting.py

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Added
10+
* `demos/usage-dag-edges.py`: Show different types of edges in a DAG
11+
* `demos/usage-elements-extra.py`: Shows how to load external layouts, otherwise same app as `usage-elements.py`.
12+
* `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.
13+
* `webpack.[dev|prod].extra.config.js`: Two new webpack configs for external layouts.
14+
* `src/lib/extra_index.js`: Loads external layouts before exporting the `Cytoscape` class. Needed to generate the new bundles.
15+
* Images of new external layouts.
16+
* `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.
17+
18+
### Changed
19+
* `src/lib/components/Cytoscape.react.js`: Updated description to include information about new external layouts.
20+
* `package.json`: Added new builds for the extra layouts, modified `npm build:all` to include new builds. Added external layouts as dependencies.
21+
922
## [0.0.5] - 2019-03-08
1023

1124
### Added

dash_cytoscape/Cytoscape.py

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,26 @@ class attribute).
5454
- `breadthfirst`: Tree structure built using BFS, with optional `roots`
5555
- `cose`: Force-directed physics simulation
5656
57-
2. The keys accepted by `layout` vary depending on the algorithm, but some
57+
2. The following external layouts are also included:
58+
- `cose-bilkent`: https://github.com/cytoscape/cytoscape.js-cose-bilkent
59+
- `cola`: https://github.com/cytoscape/cytoscape.js-cola
60+
- `euler`: https://github.com/cytoscape/cytoscape.js-dagre
61+
- `spread`: https://github.com/cytoscape/cytoscape.js-spread
62+
- `dagre`: https://github.com/cytoscape/cytoscape.js-dagre
63+
- `klay`: https://github.com/cytoscape/cytoscape.js-klay
64+
65+
3. The keys accepted by `layout` vary depending on the algorithm, but some
5866
keys are accepted by all layouts:
5967
- `fit` (boolean): Whether to render the nodes in order to fit the canvas.
6068
- `padding` (number): Padding around the sides of the canvas, if fit is enabled.
6169
- `animate` (boolean): Whether to animate change in position when the layout changes.
6270
- `animationDuration` (number): Duration of animation in milliseconds, if enabled.
6371
- `boundingBox` (dictionary): How to constrain the layout in a specific area. Keys accepted are either `x1, y1, x2, y2` or `x1, y1, w, h`, all of which receive a pixel value.
6472
65-
3. The complete list of layouts and their accepted options are available
66-
on the [Cytoscape.js docs](http://js.cytoscape.org/#layouts).
73+
4. The complete list of layouts and their accepted options are available
74+
on the [Cytoscape.js docs](http://js.cytoscape.org/#layouts). For the
75+
external layouts, the options are listed in the "API" section of the
76+
README.
6777
Note that certain keys are not supported in Dash since the value is a
6878
JavaScript function or a callback. Please visit [this issue](https://github.com/plotly/dash-cytoscape/issues/25)
6979
for more information.
@@ -151,16 +161,13 @@ class attribute).
151161
- selectedNodeData (list; optional): The list of data dictionaries of all selected nodes (e.g. using
152162
Shift+Click to select multiple nodes, or Shift+Drag to use box selection).
153163
- selectedEdgeData (list; optional): The list of data dictionaries of all selected edges (e.g. using
154-
Shift+Click to select multiple nodes, or Shift+Drag to use box selection).
155-
156-
Available events: """
164+
Shift+Click to select multiple nodes, or Shift+Drag to use box selection)."""
157165
@_explicitize_args
158166
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):
159167
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']
160168
self._type = 'Cytoscape'
161169
self._namespace = 'dash_cytoscape'
162170
self._valid_wildcard_attributes = []
163-
self.available_events = []
164171
self.available_properties = ['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']
165172
self.available_wildcard_properties = []
166173

@@ -174,26 +181,3 @@ def __init__(self, id=Component.UNDEFINED, className=Component.UNDEFINED, style=
174181
raise TypeError(
175182
'Required argument `' + k + '` was not specified.')
176183
super(Cytoscape, self).__init__(**args)
177-
178-
def __repr__(self):
179-
if(any(getattr(self, c, None) is not None
180-
for c in self._prop_names
181-
if c is not self._prop_names[0])
182-
or any(getattr(self, c, None) is not None
183-
for c in self.__dict__.keys()
184-
if any(c.startswith(wc_attr)
185-
for wc_attr in self._valid_wildcard_attributes))):
186-
props_string = ', '.join([c+'='+repr(getattr(self, c, None))
187-
for c in self._prop_names
188-
if getattr(self, c, None) is not None])
189-
wilds_string = ', '.join([c+'='+repr(getattr(self, c, None))
190-
for c in self.__dict__.keys()
191-
if any([c.startswith(wc_attr)
192-
for wc_attr in
193-
self._valid_wildcard_attributes])])
194-
return ('Cytoscape(' + props_string +
195-
(', ' + wilds_string if wilds_string != '' else '') + ')')
196-
else:
197-
return (
198-
'Cytoscape(' +
199-
repr(getattr(self, self._prop_names[0], None)) + ')')

dash_cytoscape/__init__.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ._imports_ import *
1111
from ._imports_ import __all__
1212

13+
1314
if not hasattr(_dash, 'development'):
1415
print('Dash was not successfully imported. '
1516
'Make sure you don\'t have a file '
@@ -45,3 +46,47 @@
4546
for _component in __all__:
4647
setattr(locals()[_component], '_js_dist', _js_dist)
4748
setattr(locals()[_component], '_css_dist', _css_dist)
49+
50+
51+
def load_extra_layouts():
52+
"""
53+
Load 3rd party layouts that are not included by default with Cytoscape. You can find the
54+
documentation about those layouts here:
55+
- `cose-bilkent`: https://github.com/cytoscape/cytoscape.js-cose-bilkent
56+
- `cola`: https://github.com/cytoscape/cytoscape.js-cola
57+
- `euler`: https://github.com/cytoscape/cytoscape.js-dagre
58+
- `spread`: https://github.com/cytoscape/cytoscape.js-spread
59+
- `dagre`: https://github.com/cytoscape/cytoscape.js-dagre
60+
- `klay`: https://github.com/cytoscape/cytoscape.js-klay
61+
62+
Example:
63+
64+
```
65+
import dash
66+
import dash_html_components as html
67+
import dash_cytoscape as cyto
68+
69+
cyto.load_extra_layouts()
70+
71+
app = dash.Dash(__name__)
72+
73+
app.layout = html.Div([
74+
cyto.Cytoscape(...),
75+
])
76+
```
77+
78+
Be careful about using the extra layouts when not necessary, since they require supplementary
79+
bandwidth for loading, which impacts the startup time of the app.
80+
"""
81+
global _js_dist
82+
83+
_js_dist = [
84+
{
85+
'relative_package_path': 'dash_cytoscape_extra.min.js',
86+
'dev_package_path': 'dash_cytoscape_extra.dev.js',
87+
'external_url': 'https://unpkg.com/dash-cytoscape@{}/{}/{}.min.js'.format(
88+
__version__, __name__, 'dash_cytoscape_extra'
89+
),
90+
'namespace': package_name
91+
}
92+
]

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: 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.dev.js

Lines changed: 5752 additions & 0 deletions
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: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)