Skip to content

Instantly share code, notes, and snippets.

View joseberlines's full-sized avatar
💭
Python

joseberlines joseberlines

💭
Python
  • European Patent Office
  • Berlin
View GitHub Profile
train_style.append({'selector': 'node[classes="EU"]',
'style': {'background-color': 'orange'}})
train_style.append({'selector': 'edge[classes="EU"]',
'style': {'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)'}})
ipycytoscape_obj3 = ipycytoscape.CytoscapeWidget()
ipycytoscape_obj3.graph.add_graph_from_json(railnetJSON)
ipycytoscape_obj3.graph.add_node(station_NUR)
ipycytoscape_obj3.graph.add_edges([new_edge1,new_edge2])
EU_stations = ['PAR','MIL','BAR','LYO']
new_EU_stations = []
for station in EU_stations:
new_station = ipycytoscape.Node()
new_station.data['id'] = station
new_station.data['label'] = f"CS {station}" # CS = Central Station
new_station.data['classes'] = "EU"
new_EU_stations.append(new_station)
connections = [('BER','PAR'),('PAR','LYO'),('LYO','BAR'),('LYO','MIL')]
ipycytoscape_obj2.graph.nodes
for node in ipycytoscape_obj2.graph.nodes:
if node.data['id'] == 'NUR':
node.data['label'] = 'Hbf NUR'
ipycytoscape_obj2
train_style.append({'selector': 'edge[id = "line6"]',
'style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)'}})
train_style.append({'selector': 'edge[id = "line7"]',
'style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)'}})
# rail connection NUR-LEP
new_edge1 = ipycytoscape.Edge()
new_edge1.data['id'] = "line6"
new_edge1.data['source'] = "NUR"
new_edge1.data['target'] = "LEP"
new_edge1.data['label'] = "150km/h"
# rail connection NUR-FRA
new_edge2 = ipycytoscape.Edge()
new_edge2.data['id'] = "line7"
station_NUR = ipycytoscape.Node()
station_NUR.data['id'] = "NUR"
station_NUR.data['label'] = "HBf NUR in construction"
station_NUR.data['classes'] = "west"
ipycytoscape_obj.graph.add_node(station_NUR)
ipycytoscape_obj
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"}},
train_style.append({'selector': 'node[classes="EU"]',
'style': {'background-color': 'orange'}})
train_style.append({'selector': 'edge[classes="EU"]',
'style': {'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)'}})
ipycytoscape_obj3 = ipycytoscape.CytoscapeWidget()
ipycytoscape_obj3.graph.add_graph_from_json(railnetJSON)
ipycytoscape_obj3.graph.add_node(station_NUR)
ipycytoscape_obj3.graph.add_edges([new_edge1,new_edge2])
EU_stations = ['PAR','MIL','BAR','LYO']
new_EU_stations = []
for station in EU_stations:
new_station = ipycytoscape.Node()
new_station.data['id'] = station
new_station.data['label'] = f"CS {station}" # CS = Central Station
new_station.data['classes'] = "EU"
new_EU_stations.append(new_station)
connections = [('BER','PAR'),('PAR','LYO'),('LYO','BAR'),('LYO','MIL')]
ipycytoscape_obj2.graph.nodes
for node in ipycytoscape_obj2.graph.nodes:
if node.data['id'] == 'NUR':
node.data['label'] = 'Hbf NUR'
ipycytoscape_obj2