Ken-INOUE commited on
Commit
88d6d47
·
1 Parent(s): 93ebee4

Refactor figures_to_html to use PlotlyJS embedding for rendering figures, improving display and reducing SVG usage.

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -549,22 +549,18 @@ def make_trend_figs_by_tag(
549
  return out
550
 
551
  def figures_to_html(figs_by_tag: Dict[str, go.Figure]) -> str:
552
- """
553
- 各 Figure を SVG に変換してインラインで並べる(<script>不要で確実に表示)。
554
- """
555
- if not figs_by_tag:
556
- return "<p>図がありません。</p>"
557
  parts = []
 
558
  for tag, fig in figs_by_tag.items():
559
- # 必要なら width/height/scale を調整可
560
- svg_bytes = pio.to_image(fig, format="svg", engine="kaleido")
561
- svg = svg_bytes.decode("utf-8")
562
  parts.append(
563
  f'<div style="margin:16px 0;border:1px solid #e5e7eb;border-radius:8px;padding:8px">'
564
  f'<div style="font-weight:600;margin:4px 0 8px 0;">{tag}</div>'
565
- f'{svg}'
566
  f'</div>'
567
  )
 
568
  return "\n".join(parts)
569
 
570
  # ======================================
 
549
  return out
550
 
551
  def figures_to_html(figs_by_tag: Dict[str, go.Figure]) -> str:
552
+ """PlotlyJS埋め込み方式(ブラウザ側で描画)"""
 
 
 
 
553
  parts = []
554
+ first = True
555
  for tag, fig in figs_by_tag.items():
556
+ html = pio.to_html(fig, include_plotlyjs='cdn' if first else False, full_html=False)
 
 
557
  parts.append(
558
  f'<div style="margin:16px 0;border:1px solid #e5e7eb;border-radius:8px;padding:8px">'
559
  f'<div style="font-weight:600;margin:4px 0 8px 0;">{tag}</div>'
560
+ f'{html}'
561
  f'</div>'
562
  )
563
+ first = False
564
  return "\n".join(parts)
565
 
566
  # ======================================