Skip to content

Instantly share code, notes, and snippets.

@joseberlines
Last active November 22, 2020 19:12
Show Gist options
  • Save joseberlines/ff0bd19bffe0e5dfa98df1199ad3767f to your computer and use it in GitHub Desktop.
Save joseberlines/ff0bd19bffe0e5dfa98df1199ad3767f to your computer and use it in GitHub Desktop.
graph9
railnet= '''{
"nodes": [
{"data": { "id": "BER", "label":"HBf BER", "classes":"east"}},
{"data": { "id": "MUN", "label":"HBf MUN", "classes":"west"}},
{"data": { "id": "FRA", "label":"HBf FRA", "classes":"west"}},
{"data": { "id": "HAM", "label":"HBf HAM", "classes":"west"}},
{"data": { "id": "LEP", "label":"HBf LEP", "classes":"east"}}
],
"edges": [
{"data": { "id": "line1", "source": "BER", "target": "MUN","label":"200km/h"}},
{"data": { "id": "line2", "source": "MUN", "target": "FRA","label":"200km/h"}},
{"data": { "id": "line3", "source": "FRA", "target": "BER","label":"250km/h" }},
{"data": { "id": "line4", "source": "BER", "target": "HAM","label":"300km/h" }},
{"data": { "id": "line5", "source": "BER", "target": "LEP","label":"300km/h" }}
]
}'''
my_style = [
{'selector': 'node','style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)',}},
{'selector': 'node[classes="east"]','style': {
'background-color': 'yellow'}},
{'selector': 'node[classes="west"]','style': {
'background-color': 'blue'}},
{'selector': 'node[id = "BER"]','style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)',
'background-color': 'green'}},
{'selector': 'edge[id = "line1"]','style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)'}},
{'selector': 'edge[id = "line2"]','style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)'}},
{'selector': 'edge[id = "line3"]','style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)'}},
{'selector': 'edge[id = "line4"]','style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)'}},
{'selector': 'edge[id = "line5"]','style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)'}}
]
railnetJSON = json.loads(railnet)
ipycytoscape_obj9 = ipycytoscape.CytoscapeWidget()
ipycytoscape_obj9.graph.add_graph_from_json(railnetJSON, directed=True) # I am telling I dont want directions
ipycytoscape_obj9.set_style(my_style)
ipycytoscape_obj9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment