-
Notifications
You must be signed in to change notification settings - Fork 1
/
echarts.py
73 lines (64 loc) · 1.89 KB
/
echarts.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
# %%
from pyecharts import options as opts
from pyecharts.charts import Graph
import pandas as pd
import re
from config import *
# %%
categories = [
opts.GraphCategory(name="reference", symbol='circle'),
opts.GraphCategory(name="paper", symbol='rect'),
]
# %%
df = pd.read_csv(base_all_csv_path)
def get_name(row:pd.Series):
if pd.isna(row.citekey):
name = row.title
else:
name = row.citekey
print(name)
return str(name)
# %%
nodes, links = [], []
papers = set(
map(lambda x: re.sub(r"\(\d+\)$", '', x),
";".join(df.cite_by.tolist()).split(';')))
for paper in papers:
cite_df = df[df.cite_by.str.contains(paper)]
print(paper)
nodes.append(
opts.GraphNode(name=str(paper),
category='paper',
symbol_size=(len(cite_df))))
for i, row in df.iterrows():
if pd.isna(row.citekey):
continue
name = get_name(row)
if row.citekey not in papers:
nodes.append(
opts.GraphNode(name=name,
category='reference',
value=row.title,
symbol_size=row.cite_count * 10))
for paper in row.cite_by.split(';'):
paper = re.sub(r"\(\d+\)$", '', paper)
links.append(opts.GraphLink(source=str(paper), target=name))
# %%
c = (
Graph(init_opts=opts.InitOpts(
# width="700px", height="500px",
bg_color="#ffffff")).add(
"",
nodes,
links,
categories,
repulsion=1000,
edge_label=opts.LabelOpts(is_show=False,
position="middle",
formatter="{c}"),
# is_selected=True,
is_draggable=True).set_global_opts(title_opts=opts.TitleOpts(
title="References")))
# c.render_notebook()
c.render('index.html')
# %%