Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,39 @@ jobs:
name: Run pylint
command: |
. venv/bin/activate
pylint usage.py tests
pylint usage.py usage-advanced.py usage-elements.py usage-events.py usage-stylesheet.py
pylint demos tests
when: always

- run:
name: Run flake8
command: |
. venv/bin/activate
flake8 usage.py tests
flake8 --max-line-length=100 usage.py usage-advanced.py usage-elements.py usage-events.py usage-stylesheet.py
flake8 --max-line-length=100 demos tests
when: always

- run:
name: Integration Tests - Usage
name: Integration Tests - Usage Apps Rendering
command: |
. venv/bin/activate
python -m unittest tests.test_usage
when: always

- run:
name: Integration Tests - Interactions
command: |
. venv/bin/activate
python -m unittest tests.test_interactions
when: always

- run:
name: Integration Tests - Callbacks
command: |
. venv/bin/activate
python -m unittest tests.test_callbacks
when: always

- run:
name: Capture Percy Snapshots
command: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
.idea/**/gradle.xml
.idea/**/libraries
tests/screenshots/*.png
tests/screenshots/**/*.png

# misc
.DS_Store
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## Added
* `tests.test_usage`: Tests for rendering usage files.
* `tests.test_callbacks`: Tests for updating `Cytoscape` with callbacks.
* `tests.test_interactions`: Tests for interacting with `Cytoscape`, and evaluating its event callbacks.
* `tests.test_percy_snapshot`: Creates a Percy build using screenshots from other tests.

## Changed
* `config.yml`: Added steps to run the new tests. Added coverage for Python 3.7. Included `demos` and all usage examples in `pylint` and `flake8`. Increased line limit to 100.
* `demos/usage-*`: Formatted all demo apps in order to respect pylint and flake8.
* `usage-*`: Formatted all demo apps in order to respect pylint and flake8.
* `package.json`: Removed `"prepublish": "npm run validate-init"` due to conflict with CircleCI build. This script will be deprecated in favor of the upcoming Dash Component CLI.
* `tests/IntegrationTests.py`: Moved the `percy_snapshot` method to `test_percy_snapshot` in order to avoid duplicate (failing) builds on Percy. Decrease the number of processes to 1.

## Removed
* `tests.test_render`: Removed unused test

## Added
* Two new demos: `usage-grid-social-network.py` and `usage-concentric-social-network.py`
* Add Issue and PR templates for Github (located in `.github`)
Expand Down
2 changes: 0 additions & 2 deletions demos/dash_reusable_components.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from textwrap import dedent

import dash_core_components as dcc
import dash_html_components as html

Expand Down
13 changes: 11 additions & 2 deletions demos/editor/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=W0612,R1705
import json
from colour import Color

Expand Down Expand Up @@ -41,10 +42,19 @@ def validate_color(color, default='#999999'):
try:
# Converting 'deep sky blue' to 'deepskyblue'
color = color.replace(" ", "")

if color.startswith('rgb'):
values = color.replace('rgb(', '').replace(')', '').split(',')

if len(values) == 3 and all(0 <= int(v) <= 255 for v in values):
return color

return default

Color(color)
# if everything goes fine then return True
return color
except: # The color code was not found
except: # noqa
return default


Expand Down Expand Up @@ -225,7 +235,6 @@ def disable_side_endpoint_width(value):
def disable_side_endpoint_height(value):
return value != 'other'


# ############################## CYTOSCAPE ################################
@app.callback(Output('cytoscape', 'elements'),
[Input('dropdown-select-element-list', 'value')])
Expand Down
54 changes: 24 additions & 30 deletions demos/editor/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@
id='dropdown-edge-curve-style',
value='haystack',
clearable=False,
searchable=False,
options=drc.DropdownOptionsList(
'haystack',
'bezier',
Expand Down Expand Up @@ -610,8 +609,7 @@
placeholder='Input value in % or px...',
value='0px'
)
]) for side in
['source', 'target']],
]) for side in ['source', 'target']],

drc.NamedInput(
name='Source Distance from node',
Expand All @@ -637,8 +635,7 @@
drc.NamedRadioItems(
name='Use Labels',
id='radio-use-labels',
options=drc.DropdownOptionsList('yes',
'no'),
options=drc.DropdownOptionsList('yes', 'no'),
value='no'
),

Expand Down Expand Up @@ -682,8 +679,7 @@
options=[{
'label': element.capitalize(),
'value': f'div-label-{element}'
} for element in
LABEL_ELEMENT_TYPES],
} for element in LABEL_ELEMENT_TYPES],
clearable=False,
value='div-label-node'
),
Expand Down Expand Up @@ -760,8 +756,7 @@
searchable=False,
value='none'
)
]) for element in
LABEL_ELEMENT_TYPES],
]) for element in LABEL_ELEMENT_TYPES],
]),
drc.NamedCard(title='Text Wrapping', size=4, children=[
drc.NamedDropdown(
Expand All @@ -770,8 +765,7 @@
options=[{
'label': element.capitalize(),
'value': f'div-text-wrapping-{element}'
} for element in
LABEL_ELEMENT_TYPES],
} for element in LABEL_ELEMENT_TYPES],
clearable=False,
value='div-text-wrapping-node'
),
Expand All @@ -796,8 +790,7 @@
type='number',
placeholder='Enter the maximum width in px...'
)
]) for element in
LABEL_ELEMENT_TYPES],
]) for element in LABEL_ELEMENT_TYPES],
]),
drc.NamedCard(title='Label Alignment', size=4, children=[
drc.NamedRadioItems(
Expand Down Expand Up @@ -848,23 +841,24 @@
value='div-text-margins-node'
),

*[html.Div(id=f'div-text-margins-{element}',
children=[
drc.NamedInput(
name=f"{element.capitalize()} Margin X (px)",
id=f'input-{element}-text-margin-x',
type='number',
placeholder='Enter a value in px...'
),

drc.NamedInput(
name=f"{element.capitalize()} Margin Y(px)",
id=f'input-{element}-text-margin-y',
type='number',
placeholder='Enter a value in px...'
)
]) for element in
LABEL_ELEMENT_TYPES_ALL],
*[html.Div(
id=f'div-text-margins-{element}',
children=[
drc.NamedInput(
name=f"{element.capitalize()} Margin X (px)",
id=f'input-{element}-text-margin-x',
type='number',
placeholder='Enter a value in px...'
),

drc.NamedInput(
name=f"{element.capitalize()} Margin Y(px)",
id=f'input-{element}-text-margin-y',
type='number',
placeholder='Enter a value in px...'
)
]
) for element in LABEL_ELEMENT_TYPES_ALL],
])
]
)
Expand Down
2 changes: 1 addition & 1 deletion demos/usage-animated-bfs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Original Demo: http://js.cytoscape.org/demos/animated-bfs/
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/animated-bfs
Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/animated-bfs

Note: Animation Not Implemented yet, please refer to code.
"""
Expand Down
1 change: 0 additions & 1 deletion demos/usage-breadthfirst-layout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/images-breadthfirst-layout/
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/images-breadthfirst-layout

Note: Click Animation is not implemented.
"""
Expand Down
1 change: 0 additions & 1 deletion demos/usage-circle-layout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/circle-layout/
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/circle-layout
"""
import json

Expand Down
1 change: 0 additions & 1 deletion demos/usage-compound-nodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/compound-nodes/
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/compound-nodes

Note: The Dash version is also uncentered. Otherwise it works.
"""
Expand Down
1 change: 0 additions & 1 deletion demos/usage-concentric-layout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/concentric-layout/
Original Code: https://github.com/cytoscape/cytoscape.js/blob/master/documentation/demos/concentric-layout/code.js

Note: This example is broken because layout takes a function as input, i.e.
```
Expand Down
2 changes: 1 addition & 1 deletion demos/usage-concentric-social-network.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@


if __name__ == '__main__':
app.run_server(debug=True)
app.run_server(debug=True)
4 changes: 2 additions & 2 deletions demos/usage-cose-bilkent-layout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/cose-bilkent-layout-compound/
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/cose-bilkent-layout-compound

Note: This implementation DOES NOT work yet, since cose-bilkent hasn't been implemented yet

Expand All @@ -16,7 +15,8 @@
server = app.server

app.scripts.append_script({
'external_url': 'https://cdn.rawgit.com/cytoscape/cytoscape.js-cose-bilkent/d810281d/cytoscape-cose-bilkent.js'
'external_url': ('https://cdn.rawgit.com/cytoscape/cytoscape.js-cose-bilkent/d810281d/'
'cytoscape-cose-bilkent.js')
})

app.scripts.config.serve_locally = True
Expand Down
1 change: 0 additions & 1 deletion demos/usage-cose-layout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/cose-layout/
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/cose-layout

Note: This implementation looks different from the original implementation,
although the input paramters are exactly the same.
Expand Down
1 change: 0 additions & 1 deletion demos/usage-edge-types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/edge-types/
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/edge-types

Note: This example is broken because layout takes a function as input:
```
Expand Down
1 change: 0 additions & 1 deletion demos/usage-grid-layout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/grid-layout/
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/grid-layout
"""
import json

Expand Down
2 changes: 1 addition & 1 deletion demos/usage-grid-social-network.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@


if __name__ == '__main__':
app.run_server(debug=True)
app.run_server(debug=True)
1 change: 0 additions & 1 deletion demos/usage-initialisation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/initialisation/
Original Code: https://github.com/cytoscape/cytoscape.js/blob/master/documentation/demos/initialisation/code.js

Note: The click-and-drag functionality is broken in this Dash implementation
because the example requires a function referring to the "cy" property, i.e.
Expand Down
4 changes: 2 additions & 2 deletions demos/usage-labels.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/labels/
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/labels

Note: This example is broken because layout takes a function as input:
```
Expand Down Expand Up @@ -51,7 +50,8 @@

{'data': {'id': 'ar-src'}},
{'data': {'id': 'ar-tgt'}},
{'data': {'source': 'ar-src', 'target': 'ar-tgt', 'label': 'autorotate (move my nodes)'}, 'classes': 'autorotate'},
{'data': {'source': 'ar-src', 'target': 'ar-tgt', 'label': 'autorotate (move my nodes)'},
'classes': 'autorotate'},
{'data': {'label': 'background'}, 'classes': 'background'}
]

Expand Down
1 change: 0 additions & 1 deletion demos/usage-linkout-example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/linkout-example/
Original Code: https://github.com/cytoscape/cytoscape.js/blob/master/documentation/demos/linkout-example/

Note: Href Links do not work

Expand Down
1 change: 0 additions & 1 deletion demos/usage-multiple-instances.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/multiple-instances/
Original Code: https://github.com/cytoscape/cytoscape.js/blob/master/documentation/demos/multiple-instances
"""
import dash
import dash_html_components as html
Expand Down
7 changes: 3 additions & 4 deletions demos/usage-phylogeny.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pylint: disable=W0621
import math

import dash
import dash_html_components as html
from dash.dependencies import Input, Output

import dash_cytoscape as cyto
import dash_html_components as html

try:
from Bio import Phylo
Expand All @@ -16,13 +16,13 @@

def generate_elements(tree, xlen=30, ylen=30, grabbable=False):
def get_col_positions(tree, column_width=80):
"""Create a mapping of each clade to its column position."""
taxa = tree.get_terminals()

# Some constants for the drawing calculations
max_label_width = max(len(str(taxon)) for taxon in taxa)
drawing_width = column_width - max_label_width - 1

"""Create a mapping of each clade to its column position."""
depths = tree.depths()
# If there are no branch lengths, assume unit branch lengths
if not max(depths.values()):
Expand Down Expand Up @@ -164,7 +164,6 @@ def add_to_elements(clade, clade_id):
app = dash.Dash(__name__)
server = app.server


app.layout = html.Div([
cyto.Cytoscape(
id='cytoscape',
Expand Down
1 change: 0 additions & 1 deletion demos/usage-pie-style.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/pie-style/
Original Code: https://github.com/cytoscape/cytoscape.js/blob/master/documentation/demos/pie-style
"""
import dash
import dash_html_components as html
Expand Down
1 change: 0 additions & 1 deletion demos/usage-visual-style.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Original Demo: http://js.cytoscape.org/demos/visual-style/
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/visual-style
"""
import dash
import dash_html_components as html
Expand Down
Loading