Changeset - 5edc670d4252
[Not reviewed]
default
0 1 0
Branko Majic (branko) - 12 years ago 2013-11-09 13:49:13
branko@majic.rs
CONNT-17: Order the entities of a project by primary key in order to have consistent assignment of node colours as in case of tabular listing.
1 file changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
conntrackt/utils.py
Show inline comments
 
@@ -146,39 +146,39 @@ def generate_project_diagram(project):
 
    entities = project.entity_set.all()
 

	
 
    # Set-up dictinary that will contains clusters of entities belonging to same
 
    # location.
 
    clusters = {}
 

	
 
    # Dictinoary for storing mapping between nodes and colours.
 
    node_colors = {}
 

	
 
    # Get distinct colours, one for each node/entity.
 
    colors = get_distinct_colors(entities.count())
 

	
 
    # Created nodes based on entities, and put them into correct cluster.
 
    for entity in entities:
 
    # Create nodes based on entities, and put them into correct cluster.
 
    for entity in entities.order_by("pk"):
 

	
 
        # Try to get the existing cluster based on location name.
 
        location = entity.location
 
        cluster_name = location.name.replace(" ", "_").lower()
 
        cluster = clusters.get(cluster_name, None)
 

	
 
        # Set-up a new cluster for location encountered for the first time.
 
        if cluster is None:
 
            cluster = pydot.Cluster(graph_name=cluster_name, label=location.name)
 
            clusters[cluster_name] = cluster
 

	
 
        # Fetch a colour that will be associated with the node/entity.
 
        node_color = colors.pop()
 
        node_color = colors.pop(0)
 
        node_colors[entity.id] = node_color.hex
 

	
 
        # Determine whether the node label should be black or white based on brightness of node colour.
 
        node_color_brightness = 1 - (node_color.rgb["r"] * 0.299 + node_color.rgb["g"] * 0.587 + node_color.rgb["b"] * 0.114)
 

	
 
        if node_color_brightness < 0.5:
 
            font_color = "black"
 
        else:
 
            font_color = "white"
 

	
 
        # Finally create the node, and add it to location cluster.
 
        node = pydot.Node(entity.name, style="filled", color=node_color.hex, fontcolor=font_color)
0 comments (0 inline, 0 general)