Innovenergy_trunk/python/gui/cytoscape.py

235 lines
6.5 KiB
Python

from PIL import Image
# Documentation is lax here; the code pretty much documents itself:
def buildNodes(devices):
return [
{
'data': {'id':device.name, 'label': device.name, },
'position': {'x': device.position[0]*170, 'y': device.position[1]*170},
'locked': True,
'classes': 'device ' + device.name + " ",
'style': {
#'color': '#fff',
'color': '#000000', ##646363
'font-family': "sans-serif",
'font-color': '#000000'
},
}
for device in devices if not device.position == [0,0]]
def buildEdges(connections):
return [
{'data': {'source': connection[0], 'target': connection[1], 'label':[]},
'classes':'Edge',
'style':{
#'color': '#fff',
'color': '#646363',
'font-family': "sans-serif",
'font-color': '#000000',
'width': '0px',
}} for connection in connections]
# legacy todo DELETE ME
# This file contains the nodes, edges and stylesheet for the Cytoscape graph
# nodes = [
# {
# 'data': {'id':short, 'label': label, },
# 'position': {'x': long, 'y': lat},
# 'locked': True,
# 'classes': 'device ' + image,
# 'style': {
# 'font-family': 'FontAwesome',
#
# },
# }
#
# for short, label, long, lat, image in (
# ('Grid', 'Grid', -120, 200, 'grid'),
# ('PvOnAcIn', 'AC PV',45, 65, 'pv'),
# ('pv_two', 'AC PV', 210, 65, 'pv'),
# ('ac_in', 'AC In Bus', 45, 200, 'ac'),
# ('ac_last_one', 'AC Lasten', 45, 335, 'last'),
# ('ac_last_two', 'Kritische Lasten', 210, 335, 'last'),
# ('ac_out', 'AC Out Bus', 210, 200, 'ac'),
# ('Inverter', 'Inverter', 375, 200, 'inverter'),
# ('dc_last', 'DC Lasten', 540, 335, 'last'),
# ('PvOnDc', 'DC PV', 540, 65, 'pv'),
# ('dc_bus', 'DC Bus', 540, 200, 'dc'),
# ('DcDc', 'DC/DC', 705, 200, 'dc'),
# ('battery', 'Batterie', 870, 200, 'battery')
# )
# ]
#
# # Todo grab from topology
# edges = [
# {'data': {'source': source, 'target': target, 'label':[]},
# 'classes':'edge dot-floating',
# 'style':{
# 'label': 'data(label)',
# 'width': '0px',
# }}
# for source, target in (
# ('PvOnAcIn','ac_in'),
# ('Grid', 'ac_in'),
# ('ac_in', 'Grid'),
# ('ac_in', 'ac_last_one'),
# ('ac_in','ac_out'),
# ('ac_out','ac_in'),
# ('pv_two','ac_out'),
# ('ac_out','Inverter'),
# ('Inverter','ac_out'),
# ('ac_out','ac_last_two'),
# ('Inverter','dc_bus'),
# ('dc_bus','Inverter'),
# ('dc_bus','dc_last'),
# ('PvOnDc','dc_bus'),
# ('dc_bus','DcDc'),
# ('DcDc','dc_bus'),
# ('DcDc','battery'),
# ('battery','DcDc')
# )
# ]
style = [
{
'selector': '.device',
'style':{
'shape': 'rectangle',
'height': '70px',
'width': '95px',
"text-valign": "bottom",
"text-halign": "center",
'font-family': 'FontAwesome',
'content': 'data(label)',
}
},
{
'selector': '.consumer',
'style': {
'background-color': '#ea9f97',
'shape': 'rectangle',
'content': 'data(label)',
}
},
{
'selector': '.producer', #'#2ecc71'
'style': {
'background-color': '#00cc96',
'shape': 'rectangle',
'content': 'data(label)',
}
},
{
'selector': '.Grid',
'style': {
'background-color': '#f4b350',
'background-image': Image.open("assets/plug-solid.png"),
}
},
{
'selector': '.Inverter', ##518fd3
'style': {
'background-color': '#636efa',
'background-image': Image.open("assets/bolt-solid.png"),
}
},
{
'selector': '.AcIn',
'style': {
'background-color': '#adadad',
'background-image': Image.open("assets/bolt-solid.png"),
}
},
{
'selector': '.AcOut',
'style': {
'background-color': '#adadad',
'background-image': Image.open("assets/bolt-solid.png"),
}
},
{
'selector': '.PvOnAcIn', ##f4b350
'style': {
'background-color': '#00cc96',
'background-image': Image.open("assets/solar-panel-solid.png"),
}
},
{
'selector': '.PvOnAcOut',
'style': {
'background-color': '#00cc96',
'background-image': Image.open("assets/solar-panel-solid.png"),
}
},
{
'selector': '.PvOnDc',
'style': {
'background-color': '#00cc96',
'background-image': Image.open("assets/solar-panel-solid.png"),
}
},
{
'selector': '.Load',
'style': {
'background-color': '#f7a99c',
'background-image': Image.open("assets/industry-solid.png"),
}
},
{
'selector': '.CriticalLoad',
'style': {
'background-color': '#f7a99c',
'background-image': Image.open("assets/industry-solid.png"),
}
},
{
'selector': '.DcLoad',
'style': {
'background-color': '#f7a99c',
'background-image': Image.open("assets/industry-solid.png"),
}
},
{
'selector': '.Dc',
'style': {
'background-color': '#adadad',
'background-image': Image.open("assets/bolt-solid.png"),
}
},
{
'selector': '.DcDc',
'style': {
'background-color': '#adadad',
'background-image': Image.open("assets/bolt-solid.png"),
}
},
{
'selector': '.Dc48',
'style': {
'background-color': '#adadad',
'background-image': Image.open("assets/bolt-solid.png"),
}
},
{
'selector': '.Battery',
'style': {
'background-color': '#636efa',
'background-image': Image.open("assets/car-battery-solid.png"),
}
},
{
'selector': '.Edge',
'style': {
'label': 'data(label)',
'line-color': '#f9e1b1',
'curve-style': 'straight',
'opacity': '0.9',
'target-arrow-color': '#F59100',
'target-arrow-shape': 'vee',
'height': '0px',
}
},
]