Spaces:
Sleeping
Sleeping
Upload app.py
Browse files- src/app.py +50 -11
src/app.py
CHANGED
|
@@ -157,8 +157,23 @@ def plotly_network_fig(
|
|
| 157 |
return fig
|
| 158 |
|
| 159 |
|
| 160 |
-
def plotly_ontology_fig(height: int =
|
| 161 |
-
"""CitationHub μ¨ν¨λ‘μ§ κ΅¬μ‘° β Plotly SVG."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
node_defs = [
|
| 163 |
("seed", "Top5PctCitedPaper", "seed_paper"),
|
| 164 |
("event", "CitationEvent", "citation_event"),
|
|
@@ -186,40 +201,64 @@ def plotly_ontology_fig(height: int = 750) -> go.Figure:
|
|
| 186 |
|
| 187 |
pos = nx.spring_layout(G, seed=7, k=2.5, iterations=80)
|
| 188 |
|
| 189 |
-
#
|
| 190 |
ex, ey = [], []
|
| 191 |
ann = []
|
| 192 |
for s, t, lbl in edge_defs:
|
| 193 |
x0, y0 = pos[s]; x1, y1 = pos[t]
|
| 194 |
ex += [x0, x1, None]; ey += [y0, y1, None]
|
| 195 |
mx, my = (x0+x1)/2, (y0+y1)/2
|
| 196 |
-
ann.append(dict(
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
| 199 |
|
| 200 |
traces: list[go.BaseTraceType] = [
|
| 201 |
go.Scatter(x=ex, y=ey, mode="lines",
|
| 202 |
line=dict(width=1.2, color="#94a3b8"),
|
| 203 |
hoverinfo="none", showlegend=False)
|
| 204 |
]
|
|
|
|
|
|
|
| 205 |
for nid, label, ntype in node_defs:
|
| 206 |
x, y = pos[nid]
|
| 207 |
color = NODE_TYPE_COLORS.get(ntype, "#94a3b8")
|
|
|
|
|
|
|
|
|
|
| 208 |
traces.append(go.Scatter(
|
| 209 |
x=[x], y=[y], mode="markers+text",
|
| 210 |
-
text=[label], textposition="top center",
|
| 211 |
-
hoverinfo="text",
|
|
|
|
|
|
|
| 212 |
name=label, showlegend=False,
|
| 213 |
-
marker=dict(size=
|
| 214 |
line=dict(width=1.5, color="white")),
|
| 215 |
-
textfont=dict(size=11),
|
| 216 |
))
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
fig = go.Figure(data=traces)
|
| 219 |
fig.update_layout(
|
| 220 |
showlegend=False, hovermode="closest", height=height,
|
| 221 |
annotations=ann,
|
| 222 |
-
margin=dict(l=
|
| 223 |
paper_bgcolor="white", plot_bgcolor="#f8fafc",
|
| 224 |
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 225 |
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
|
|
|
| 157 |
return fig
|
| 158 |
|
| 159 |
|
| 160 |
+
def plotly_ontology_fig(height: int = 820) -> go.Figure:
|
| 161 |
+
"""CitationHub μ¨ν¨λ‘μ§ κ΅¬μ‘° β Plotly SVG. κ° λ
Έλμ μμ±κ° νμ."""
|
| 162 |
+
|
| 163 |
+
# κ° λ
Έλ νμ
μ μ£Όμ μμ± (λ
Έλ μλμ μκ² νμ)
|
| 164 |
+
NODE_PROPS = {
|
| 165 |
+
"seed_paper": "doi Β· title Β· journal\nauthor Β· affiliation\ncountry Β· field Β· citedby_count",
|
| 166 |
+
"citation_event": "event_id Β· citing_year\nprimary_intent Β· context\nis_influential",
|
| 167 |
+
"citing_paper": "doi Β· title\nyear Β· venue Β· oa_pdf",
|
| 168 |
+
"intent": "background Β· uses\nsimilarities Β· motivation\ndifferences Β· future_work Β· extends",
|
| 169 |
+
"journal": "journal_name",
|
| 170 |
+
"author": "author_name Β· author_id",
|
| 171 |
+
"affiliation": "affiliation_name",
|
| 172 |
+
"city": "city_name",
|
| 173 |
+
"country": "country_name",
|
| 174 |
+
"field": "field_name",
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
node_defs = [
|
| 178 |
("seed", "Top5PctCitedPaper", "seed_paper"),
|
| 179 |
("event", "CitationEvent", "citation_event"),
|
|
|
|
| 201 |
|
| 202 |
pos = nx.spring_layout(G, seed=7, k=2.5, iterations=80)
|
| 203 |
|
| 204 |
+
# ββ μ£μ§ λΌμΈ + μ£μ§ λ μ΄λΈ βββββββββββββββββββββββββββββββ
|
| 205 |
ex, ey = [], []
|
| 206 |
ann = []
|
| 207 |
for s, t, lbl in edge_defs:
|
| 208 |
x0, y0 = pos[s]; x1, y1 = pos[t]
|
| 209 |
ex += [x0, x1, None]; ey += [y0, y1, None]
|
| 210 |
mx, my = (x0+x1)/2, (y0+y1)/2
|
| 211 |
+
ann.append(dict(
|
| 212 |
+
x=mx, y=my, text=f"<i>{lbl}</i>",
|
| 213 |
+
showarrow=False, font=dict(size=9, color="#64748b"),
|
| 214 |
+
bgcolor="rgba(255,255,255,0.75)",
|
| 215 |
+
))
|
| 216 |
|
| 217 |
traces: list[go.BaseTraceType] = [
|
| 218 |
go.Scatter(x=ex, y=ey, mode="lines",
|
| 219 |
line=dict(width=1.2, color="#94a3b8"),
|
| 220 |
hoverinfo="none", showlegend=False)
|
| 221 |
]
|
| 222 |
+
|
| 223 |
+
# ββ λ
Έλ + μμ± annotation ββββββββββββββββββββββββββββββββ
|
| 224 |
for nid, label, ntype in node_defs:
|
| 225 |
x, y = pos[nid]
|
| 226 |
color = NODE_TYPE_COLORS.get(ntype, "#94a3b8")
|
| 227 |
+
props = NODE_PROPS.get(ntype, "")
|
| 228 |
+
|
| 229 |
+
# λ
Έλ λ§μ»€ + μλ¨ μ΄λ¦ λ μ΄λΈ
|
| 230 |
traces.append(go.Scatter(
|
| 231 |
x=[x], y=[y], mode="markers+text",
|
| 232 |
+
text=[f"<b>{label}</b>"], textposition="top center",
|
| 233 |
+
hoverinfo="text",
|
| 234 |
+
hovertext=(f"<b>{label}</b><br>Type: {ntype}<br>"
|
| 235 |
+
+ props.replace("\n", "<br>")),
|
| 236 |
name=label, showlegend=False,
|
| 237 |
+
marker=dict(size=24, color=color,
|
| 238 |
line=dict(width=1.5, color="white")),
|
| 239 |
+
textfont=dict(size=11, color="#1e293b"),
|
| 240 |
))
|
| 241 |
|
| 242 |
+
# μμ±κ°: λ
Έλ μλμ μμ κΈμ¨ annotation
|
| 243 |
+
if props:
|
| 244 |
+
prop_html = props.replace("\n", "<br>")
|
| 245 |
+
ann.append(dict(
|
| 246 |
+
x=x, y=y,
|
| 247 |
+
text=f"<span style='font-size:8px;color:#64748b'>{prop_html}</span>",
|
| 248 |
+
showarrow=False,
|
| 249 |
+
xanchor="center",
|
| 250 |
+
yanchor="top",
|
| 251 |
+
yshift=-22, # λ
Έλ λ§μ»€ μλλ‘ μ€νμ
|
| 252 |
+
font=dict(size=8, color="#64748b"),
|
| 253 |
+
bgcolor="rgba(248,250,252,0.85)",
|
| 254 |
+
borderpad=2,
|
| 255 |
+
))
|
| 256 |
+
|
| 257 |
fig = go.Figure(data=traces)
|
| 258 |
fig.update_layout(
|
| 259 |
showlegend=False, hovermode="closest", height=height,
|
| 260 |
annotations=ann,
|
| 261 |
+
margin=dict(l=10, r=10, t=20, b=10),
|
| 262 |
paper_bgcolor="white", plot_bgcolor="#f8fafc",
|
| 263 |
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 264 |
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|