From ef78663eb8bdb3682e939f83e2bb728d418b8da8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= <jbb@kaidan.im>
Date: Fri, 22 Jul 2022 00:03:19 +0200
Subject: [PATCH] Show diagram as svg

---
 src/app.py                    | 10 ++++------
 src/templates/publishers.html |  4 +++-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/app.py b/src/app.py
index d313ebc..c0f6820 100644
--- a/src/app.py
+++ b/src/app.py
@@ -3,7 +3,7 @@ from flask import Flask, request, send_from_directory
 from flask import render_template
 import psycopg2
 from matplotlib import pyplot as plt
-from io import BytesIO
+from io import StringIO
 import base64
 
 database = conn = psycopg2.connect(
@@ -31,13 +31,11 @@ def publishers():
 
     rows = cursor.fetchall()
     lists = list(zip(*rows))
-    buffer = BytesIO()
+    buffer = StringIO()
     fig = plt.figure(figsize = (15, 15))
     plt.pie(lists[0], labels = lists[1])
-    fig.savefig(buffer, format="png")
-    data = str(base64.b64encode(buffer.getvalue()), "utf-8")
-    image = f"data:image/png;base64,{data}"
-    return render_template("publishers.html", title="Publishers", image = image)
+    fig.savefig(buffer, format="svg")
+    return render_template("publishers.html", title="Publishers", image = buffer.getvalue())
 
 
 @app.route("/")
diff --git a/src/templates/publishers.html b/src/templates/publishers.html
index ac447e6..f147ef9 100644
--- a/src/templates/publishers.html
+++ b/src/templates/publishers.html
@@ -3,5 +3,7 @@
 {% block content %}
 <h1>Publishers</h1>
 
-<img width="100%" src="{{ image }}">
+<img width="100%">
+{{ image | safe }}
+</img>
 {% endblock content %}
-- 
GitLab