Daniel0315 commited on
Commit
61f402d
Β·
verified Β·
1 Parent(s): aedd2d3

Upload app.py

Browse files
Files changed (1) hide show
  1. 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 = 750) -> go.Figure:
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
- # edges + edge labels
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(x=mx, y=my, text=f"<i>{lbl}</i>",
197
- showarrow=False, font=dict(size=9, color="#64748b"),
198
- bgcolor="rgba(255,255,255,0.7)"))
 
 
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", hovertext=f"<b>{label}</b><br>Type: {ntype}",
 
 
212
  name=label, showlegend=False,
213
- marker=dict(size=22, color=color,
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=0, r=0, t=10, b=0),
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),