예제 #1
0
def find_graph_visualization(self, graph_id):
    graph = Graph.objects.get(pk=graph_id)
    nodes = graph.nodes.all().select_subclasses()
    edges = graph.edges.all().select_subclasses()

    # Visualization
    graph_options = Visualization.generate_graph_options()

    graph_structure = dict()
    nodes_data = list()
    for node in nodes:
        data = node.to_json(use_dict=True)
        vis = Visualization.generate_node_options(node)
        nodes_data.append(dict(**data, **vis))
    edges_data = list()
    for edge in edges:
        data = edge.to_json(use_dict=True)
        vis = Visualization.generate_edge_options(edge)
        edges_data.append(dict(**data, **vis))
    graph_structure['nodes'] = nodes_data
    graph_structure['edges'] = edges_data

    graph_legend = Visualization.generate_legend()

    graph.visualization.options = graph_options
    graph.visualization.structure = graph_structure
    graph.visualization.legend = graph_legend
    graph.visualization.save()

    return
def generate_node_options(node, analysis):
    node_options = default_visualization.generate_node_options(node)

    # Override for Frequency
    if analysis:
        frequencies = analysis.data.get('frequencies', {})
        if node.identifier in frequencies:
            freq_value = frequencies[node.identifier]
            node_options['value'] = freq_value
            node_options[
                'title'] += f'<p>Frequency: <strong>{str(freq_value)}%</strong></p>'
        else:
            node_options['value'] = 0

    return node_options
예제 #3
0
def generate_node_options(node, analysis):
    node_options = default_visualization.generate_node_options(node)
    node_options['level'] = 0
    root_nodes = [analysis.get('root_node', None)]
    downstream_nodes_and_levels = analysis.get('downstream_nodes_and_levels', {})

    if node.tags:
        if 'Outcome' in node.tags:
            node_options['color']['background'] = MapColours.NODE_BACKGROUND_OUTCOME.value
        if 'Intervention' in node.tags:
            node_options['color']['background'] = MapColours.NODE_BACKGROUND_INTERVENTION.value 
    if node.identifier in downstream_nodes_and_levels:
        node_options['level'] = downstream_nodes_and_levels[node.identifier]
    if node.identifier in root_nodes:
        node_options['color']['background'] = MapColours.NODE_BACKGROUND_INTERVENTION.value

    return node_options     
예제 #4
0
def generate_node_options(node, analysis):
    node_options = default_visualization.generate_node_options(node)
    heatmap_colours = HeatmapColours.__values__

    value = analysis.get(node.identifier, 0)
    node_options[
        'title'] += f'<p>Value: <strong>{str(value*100)}%</strong></p>'
    node_options['value'] = value

    colour_index = round(value * (len(heatmap_colours) - 1))
    matched_colour = heatmap_colours[colour_index]
    if matched_colour:
        node_options['color']['border'] = matched_colour
        node_options['color']['background'] = matched_colour

    node_options['font']['background'] = MapColours.NODE_FONT_BACKGROUND.value

    return node_options