Created
December 13, 2020 18:17
-
-
Save joseberlines/9bd904a54844ce9d9a9ebcaf6c8d5a7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ipycytoscape | |
import json | |
import ipywidgets | |
# I paste here allthe data in order to allow you to copy and paste it without loading data from files. | |
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" }} | |
] | |
}''' | |
train_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_obj = ipycytoscape.CytoscapeWidget() | |
ipycytoscape_obj.graph.add_graph_from_json(railnetJSON) | |
ipycytoscape_obj.set_style(train_style) | |
ipycytoscape_obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment