Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
wrap svg in images
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromedockes committed Jan 11, 2024
1 parent f0a05a1 commit f43c433
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/skrubview/_data/templates/column-summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ <h3 class="skrubview-margin-r-t">
</div>

{% for plot_name in column.plot_names %}
<div>
{{ column[plot_name] | safe }}
</div>
<img class="pure-img" src="{{ column[plot_name] | svg_to_img_src | safe }}" alt={{ plot_name }} />
{% endfor %}

</div>
Expand Down
1 change: 1 addition & 0 deletions src/skrubview/_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def _get_jinja_env():
)
env.filters["format_number"] = _utils.format_number
env.filters["format_percent"] = _utils.format_percent
env.filters["svg_to_img_src"] = _utils.svg_to_img_src
return env


Expand Down
5 changes: 5 additions & 0 deletions src/skrubview/_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import re
from pathlib import Path

Expand Down Expand Up @@ -114,3 +115,7 @@ def format_percent(proportion):
if 0.0 < proportion < 0.001:
return "< 0.1%"
return f"{proportion:0.1%}"

def svg_to_img_src(svg):
encoded_svg = base64.b64encode(svg.encode("UTF-8")).decode("UTF-8")
return f"data:image/svg+xml;base64,{encoded_svg}"

0 comments on commit f43c433

Please sign in to comment.