Skip to content

Commit 105f5a4

Browse files
author
Xing Han Lu
committed
❄️ flake8 + pylint on usage apps
1 parent f7cc272 commit 105f5a4

24 files changed

+60
-72
lines changed

demos/dash_reusable_components.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from textwrap import dedent
2-
31
import dash_core_components as dcc
42
import dash_html_components as html
53

demos/editor/callbacks.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=W0612,R1705
12
import json
23
from colour import Color
34

@@ -28,7 +29,7 @@ def validate_positive(value):
2829
return min(0, value)
2930

3031

31-
def validate_color(color, default='#999999'):
32+
def validate_color(color: str, default='#999999'):
3233
'''
3334
Check if a color is valid, if so returns the color, else return a default color
3435
:param color: The color to validate
@@ -41,10 +42,19 @@ def validate_color(color, default='#999999'):
4142
try:
4243
# Converting 'deep sky blue' to 'deepskyblue'
4344
color = color.replace(" ", "")
45+
46+
if color.startswith('rgb'):
47+
values = color.replace('rgb(', '').replace(')', '').split(',')
48+
49+
if len(values) == 3 and all(0 <= int(v) <= 255 for v in values):
50+
return color
51+
52+
return default
53+
4454
Color(color)
4555
# if everything goes fine then return True
4656
return color
47-
except: # The color code was not found
57+
except: # noqa
4858
return default
4959

5060

@@ -225,7 +235,6 @@ def disable_side_endpoint_width(value):
225235
def disable_side_endpoint_height(value):
226236
return value != 'other'
227237

228-
229238
# ############################## CYTOSCAPE ################################
230239
@app.callback(Output('cytoscape', 'elements'),
231240
[Input('dropdown-select-element-list', 'value')])

demos/editor/layout.py

+24-30
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@
437437
id='dropdown-edge-curve-style',
438438
value='haystack',
439439
clearable=False,
440-
searchable=False,
441440
options=drc.DropdownOptionsList(
442441
'haystack',
443442
'bezier',
@@ -610,8 +609,7 @@
610609
placeholder='Input value in % or px...',
611610
value='0px'
612611
)
613-
]) for side in
614-
['source', 'target']],
612+
]) for side in ['source', 'target']],
615613

616614
drc.NamedInput(
617615
name='Source Distance from node',
@@ -637,8 +635,7 @@
637635
drc.NamedRadioItems(
638636
name='Use Labels',
639637
id='radio-use-labels',
640-
options=drc.DropdownOptionsList('yes',
641-
'no'),
638+
options=drc.DropdownOptionsList('yes', 'no'),
642639
value='no'
643640
),
644641

@@ -682,8 +679,7 @@
682679
options=[{
683680
'label': element.capitalize(),
684681
'value': f'div-label-{element}'
685-
} for element in
686-
LABEL_ELEMENT_TYPES],
682+
} for element in LABEL_ELEMENT_TYPES],
687683
clearable=False,
688684
value='div-label-node'
689685
),
@@ -760,8 +756,7 @@
760756
searchable=False,
761757
value='none'
762758
)
763-
]) for element in
764-
LABEL_ELEMENT_TYPES],
759+
]) for element in LABEL_ELEMENT_TYPES],
765760
]),
766761
drc.NamedCard(title='Text Wrapping', size=4, children=[
767762
drc.NamedDropdown(
@@ -770,8 +765,7 @@
770765
options=[{
771766
'label': element.capitalize(),
772767
'value': f'div-text-wrapping-{element}'
773-
} for element in
774-
LABEL_ELEMENT_TYPES],
768+
} for element in LABEL_ELEMENT_TYPES],
775769
clearable=False,
776770
value='div-text-wrapping-node'
777771
),
@@ -796,8 +790,7 @@
796790
type='number',
797791
placeholder='Enter the maximum width in px...'
798792
)
799-
]) for element in
800-
LABEL_ELEMENT_TYPES],
793+
]) for element in LABEL_ELEMENT_TYPES],
801794
]),
802795
drc.NamedCard(title='Label Alignment', size=4, children=[
803796
drc.NamedRadioItems(
@@ -848,23 +841,24 @@
848841
value='div-text-margins-node'
849842
),
850843

851-
*[html.Div(id=f'div-text-margins-{element}',
852-
children=[
853-
drc.NamedInput(
854-
name=f"{element.capitalize()} Margin X (px)",
855-
id=f'input-{element}-text-margin-x',
856-
type='number',
857-
placeholder='Enter a value in px...'
858-
),
859-
860-
drc.NamedInput(
861-
name=f"{element.capitalize()} Margin Y(px)",
862-
id=f'input-{element}-text-margin-y',
863-
type='number',
864-
placeholder='Enter a value in px...'
865-
)
866-
]) for element in
867-
LABEL_ELEMENT_TYPES_ALL],
844+
*[html.Div(
845+
id=f'div-text-margins-{element}',
846+
children=[
847+
drc.NamedInput(
848+
name=f"{element.capitalize()} Margin X (px)",
849+
id=f'input-{element}-text-margin-x',
850+
type='number',
851+
placeholder='Enter a value in px...'
852+
),
853+
854+
drc.NamedInput(
855+
name=f"{element.capitalize()} Margin Y(px)",
856+
id=f'input-{element}-text-margin-y',
857+
type='number',
858+
placeholder='Enter a value in px...'
859+
)
860+
]
861+
) for element in LABEL_ELEMENT_TYPES_ALL],
868862
])
869863
]
870864
)

demos/usage-animated-bfs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/animated-bfs/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/animated-bfs
3+
Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/animated-bfs
44
55
Note: Animation Not Implemented yet, please refer to code.
66
"""

demos/usage-breadthfirst-layout.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/images-breadthfirst-layout/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/images-breadthfirst-layout
43
54
Note: Click Animation is not implemented.
65
"""

demos/usage-circle-layout.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/circle-layout/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/circle-layout
43
"""
54
import json
65

demos/usage-compound-nodes.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/compound-nodes/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/compound-nodes
43
54
Note: The Dash version is also uncentered. Otherwise it works.
65
"""

demos/usage-concentric-layout.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/concentric-layout/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/blob/master/documentation/demos/concentric-layout/code.js
43
54
Note: This example is broken because layout takes a function as input, i.e.
65
```

demos/usage-concentric-social-network.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@
7070

7171

7272
if __name__ == '__main__':
73-
app.run_server(debug=True)
73+
app.run_server(debug=True)

demos/usage-cose-bilkent-layout.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/cose-bilkent-layout-compound/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/cose-bilkent-layout-compound
43
54
Note: This implementation DOES NOT work yet, since cose-bilkent hasn't been implemented yet
65
@@ -16,7 +15,8 @@
1615
server = app.server
1716

1817
app.scripts.append_script({
19-
'external_url': 'https://cdn.rawgit.com/cytoscape/cytoscape.js-cose-bilkent/d810281d/cytoscape-cose-bilkent.js'
18+
'external_url': ('https://cdn.rawgit.com/cytoscape/cytoscape.js-cose-bilkent/d810281d/'
19+
'cytoscape-cose-bilkent.js')
2020
})
2121

2222
app.scripts.config.serve_locally = True

demos/usage-cose-layout.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/cose-layout/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/cose-layout
43
54
Note: This implementation looks different from the original implementation,
65
although the input paramters are exactly the same.

demos/usage-edge-types.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/edge-types/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/edge-types
43
54
Note: This example is broken because layout takes a function as input:
65
```

demos/usage-grid-layout.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/grid-layout/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/grid-layout
43
"""
54
import json
65

demos/usage-grid-social-network.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@
7373

7474

7575
if __name__ == '__main__':
76-
app.run_server(debug=True)
76+
app.run_server(debug=True)

demos/usage-initialisation.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/initialisation/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/blob/master/documentation/demos/initialisation/code.js
43
54
Note: The click-and-drag functionality is broken in this Dash implementation
65
because the example requires a function referring to the "cy" property, i.e.

demos/usage-labels.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/labels/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/labels
43
54
Note: This example is broken because layout takes a function as input:
65
```
@@ -51,7 +50,8 @@
5150

5251
{'data': {'id': 'ar-src'}},
5352
{'data': {'id': 'ar-tgt'}},
54-
{'data': {'source': 'ar-src', 'target': 'ar-tgt', 'label': 'autorotate (move my nodes)'}, 'classes': 'autorotate'},
53+
{'data': {'source': 'ar-src', 'target': 'ar-tgt', 'label': 'autorotate (move my nodes)'},
54+
'classes': 'autorotate'},
5555
{'data': {'label': 'background'}, 'classes': 'background'}
5656
]
5757

demos/usage-linkout-example.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/linkout-example/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/blob/master/documentation/demos/linkout-example/
43
54
Note: Href Links do not work
65

demos/usage-multiple-instances.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/multiple-instances/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/blob/master/documentation/demos/multiple-instances
43
"""
54
import dash
65
import dash_html_components as html

demos/usage-phylogeny.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
# pylint: disable=W0621
12
import math
23

34
import dash
4-
import dash_html_components as html
55
from dash.dependencies import Input, Output
6-
76
import dash_cytoscape as cyto
7+
import dash_html_components as html
88

99
try:
1010
from Bio import Phylo
@@ -16,13 +16,13 @@
1616

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

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

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

167-
168167
app.layout = html.Div([
169168
cyto.Cytoscape(
170169
id='cytoscape',

demos/usage-pie-style.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/pie-style/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/blob/master/documentation/demos/pie-style
43
"""
54
import dash
65
import dash_html_components as html

demos/usage-visual-style.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/visual-style/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/visual-style
43
"""
54
import dash
65
import dash_html_components as html

usage-elements.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import json
22

33
import dash
4+
from dash.dependencies import Input, Output, State
45
import dash_core_components as dcc
56
import dash_html_components as html
6-
from dash.dependencies import Input, Output, State
77

88
import dash_cytoscape as cyto
99
from demos import dash_reusable_components as drc
@@ -15,10 +15,10 @@
1515
# ###################### DATA PREPROCESSING ######################
1616
# Load data
1717
with open('demos/data/sample_network.txt', 'r') as f:
18-
data = f.read().split('\n')
18+
network_data = f.read().split('\n')
1919

2020
# We select the first 750 edges and associated nodes for an easier visualization
21-
edges = data[:750]
21+
edges = network_data[:750]
2222
nodes = set()
2323

2424
following_node_di = {} # user id -> list of users they are following
@@ -263,8 +263,8 @@ def generate_elements(nodeData, elements, expansion_mode):
263263
elements.extend(followers_nodes)
264264

265265
if followers_edges:
266-
for edge in followers_edges:
267-
edge['classes'] = 'followerEdge'
266+
for follower_edge in followers_edges:
267+
follower_edge['classes'] = 'followerEdge'
268268
elements.extend(followers_edges)
269269

270270
elif expansion_mode == 'following':
@@ -279,8 +279,8 @@ def generate_elements(nodeData, elements, expansion_mode):
279279
elements.append(node)
280280

281281
if following_edges:
282-
for edge in following_edges:
283-
edge['classes'] = 'followingEdge'
282+
for follower_edge in following_edges:
283+
follower_edge['classes'] = 'followingEdge'
284284
elements.extend(following_edges)
285285

286286
return elements

usage-events.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import json
22

33
import dash
4+
from dash.dependencies import Input, Output
45
import dash_core_components as dcc
56
import dash_html_components as html
6-
from dash.dependencies import Input, Output
77

88
import dash_cytoscape as cyto
99

0 commit comments

Comments
 (0)