forked from streamlit/demo-self-driving
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefs.py
78 lines (65 loc) · 2.24 KB
/
refs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#run from app.py
from pyvis.network import Network
import numpy as np
import os
import sys
import pandas as pd
def vizrender(ref, domain, physics, search, term):
# set the network options
ccx_net = Network(height='750px', width='750', bgcolor='white', font_color='blue', heading="")
#read inputfile
df = pd.read_csv("https://raw.githubusercontent.com/tyrin/info-topo-dash/master/data.csv")
#set outputfile
# filter by relationship and domain
if ref == 'all' and 'all' in domain:
dff = df
elif ref=='all':
dff = df.loc[df['Group'].isin(domain)]
elif domain=='all':
dff = df.loc[df['Ref'] == ref]
else:
dff = df.loc[(df['Group'].isin(domain)) & (df['Ref'] == ref)]
# keyword filtering
if term == 'no':
dfff = dff
elif search=='label':
dfff = dff.loc[(df['Label'].str.contains(term)) | (df['TargetLabel'].str.contains(term))]
else:
dfff = dff.loc[(df['Source'].str.contains(term)) | (df['Target'].str.contains(term))]
sources = dfff['Source']
targets = dfff['Target']
weights = dfff['Weight']
refs = dfff['Ref']
groups = dfff['Group']
colors = dfff['Color']
labels = dfff['Label']
tgtgroup = dfff['TargetGroup']
tgtcolors = dfff['TargetColor']
tgtlabels = dfff['TargetLabel']
edge_data = zip(sources, targets, weights, refs, groups, colors, labels, tgtgroup, tgtcolors, tgtlabels)
for e in edge_data:
src = e[0]
tgt = e[1]
w = e[2]
rt = e[3]
grp = e[4]
clr = e[5]
lbl = e[6]
tgtgrp = e[7]
tgtclr = e[8]
tgtlbl = e[9]
# node_id, label, named args
ccx_net.add_node(src, lbl, title=src, color=clr)
ccx_net.add_node(tgt, tgtlbl, title=tgt, color=tgtclr)
ccx_net.add_edge(src, tgt, value=w)
neighbor_map = ccx_net.get_adj_list()
# add neighbor data to node hover data
for node in ccx_net.nodes:
node['title'] += ' Neighbors:<br>' + '<br>'.join(neighbor_map[node['id']])
node['value'] = len(neighbor_map[node['id']])
if physics:
ccx_net.show_buttons(filter_=['physics'])
ccx_net.show("data.html")
else:
ccx_net.show("data.html")
#display(HTML(outputfile))