Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -9,10 +9,26 @@ DATA_FILE = "data/aclanthology2016-23_specter2_base.json"
|
|
9 |
THEMES = {"cluster": "fall", "year": "mint", "source": "phase"}
|
10 |
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def load_df(data_file: os.PathLike):
|
13 |
df = pd.read_json(data_file, orient="records")
|
14 |
df["x"] = df["point2d"].apply(lambda x: x[0])
|
15 |
df["y"] = df["point2d"].apply(lambda x: x[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
if "publication_type" in df.columns:
|
17 |
df["type"] = df["publication_type"]
|
18 |
df = df.drop(columns=["point2d", "publication_type"])
|
@@ -79,9 +95,12 @@ fig = px.scatter(
|
|
79 |
color=color,
|
80 |
width=1000,
|
81 |
height=800,
|
82 |
-
|
83 |
color_continuous_scale=THEMES[color],
|
84 |
)
|
|
|
|
|
|
|
85 |
fig.update_layout(
|
86 |
# margin=dict(l=10, r=10, t=10, b=10),
|
87 |
showlegend=False,
|
@@ -89,8 +108,14 @@ fig.update_layout(
|
|
89 |
family="Times New Roman",
|
90 |
size=30,
|
91 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
)
|
93 |
fig.update_xaxes(title="")
|
94 |
fig.update_yaxes(title="")
|
95 |
|
96 |
-
st.plotly_chart(fig, use_container_width=True)
|
|
|
9 |
THEMES = {"cluster": "fall", "year": "mint", "source": "phase"}
|
10 |
|
11 |
|
12 |
+
def to_string_authors(list_of_authors):
|
13 |
+
if len(list_of_authors) > 5:
|
14 |
+
return ", ".join(list_of_authors[:5]) + ", et al."
|
15 |
+
elif len(list_of_authors) > 2:
|
16 |
+
return ", ".join(list_of_authors[:-1]) + ", and " + list_of_authors[-1]
|
17 |
+
else:
|
18 |
+
return " and ".join(list_of_authors)
|
19 |
+
|
20 |
+
|
21 |
def load_df(data_file: os.PathLike):
|
22 |
df = pd.read_json(data_file, orient="records")
|
23 |
df["x"] = df["point2d"].apply(lambda x: x[0])
|
24 |
df["y"] = df["point2d"].apply(lambda x: x[1])
|
25 |
+
|
26 |
+
df["authors_trimmed"] = df.authors.apply(
|
27 |
+
lambda row: to_string_authors(
|
28 |
+
[(x[x.index(",") + 1 :].strip() + " " + x.split(",")[0].strip()) if "," in x else x for x in row]
|
29 |
+
)
|
30 |
+
)
|
31 |
+
|
32 |
if "publication_type" in df.columns:
|
33 |
df["type"] = df["publication_type"]
|
34 |
df = df.drop(columns=["point2d", "publication_type"])
|
|
|
95 |
color=color,
|
96 |
width=1000,
|
97 |
height=800,
|
98 |
+
custom_data=("title", "authors_trimmed", "year", "source", "type"),
|
99 |
color_continuous_scale=THEMES[color],
|
100 |
)
|
101 |
+
fig.update_traces(
|
102 |
+
hovertemplate="<b>%{customdata[0]}</b><br>%{customdata[1]}<br>%{customdata[2]}<br><i>%{customdata[3]}</i>"
|
103 |
+
)
|
104 |
fig.update_layout(
|
105 |
# margin=dict(l=10, r=10, t=10, b=10),
|
106 |
showlegend=False,
|
|
|
108 |
family="Times New Roman",
|
109 |
size=30,
|
110 |
),
|
111 |
+
hoverlabel=dict(
|
112 |
+
align="left",
|
113 |
+
font_size=14,
|
114 |
+
font_family="Rockwell",
|
115 |
+
namelength=-1,
|
116 |
+
),
|
117 |
)
|
118 |
fig.update_xaxes(title="")
|
119 |
fig.update_yaxes(title="")
|
120 |
|
121 |
+
st.plotly_chart(fig, use_container_width=True)
|