Skip to content

Commit

Permalink
Fix: Fixed the Layout error in "Vulnerability Report PDF" (Top 10 Hos…
Browse files Browse the repository at this point in the history
…ts graph).

Recalculated the extra space in the h_bar_chart (Top 10 Hosts graph) for the legend.
  • Loading branch information
jhelmold authored Jun 30, 2023
2 parents e188962 + 3b09430 commit 7006278
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions pheme/templatetags/charts/h_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import itertools
from typing import Dict
from PIL import ImageFont
from django.utils.safestring import SafeText
from pheme.templatetags.charts import (
register,
Expand Down Expand Up @@ -96,6 +97,7 @@ def h_bar_chart(
orientation_marker=6,
limit=10,
font_family="Dejavu Sans",
font_file_name="DejaVuSans.ttf",
font_size=10,
) -> SafeText:
"""
Expand Down Expand Up @@ -132,10 +134,25 @@ def h_bar_chart(
title_color = _severity_class_colors
if not data.values():
return SafeText("")
# multiply by 1.25 for kerning
max_hostname_len = (
max(max(len(k) for k in data.keys()), len(x_title)) * font_size * 1.25
)
try:
font = ImageFont.truetype(font_file_name, font_size)
# add 87.5 + 10 for legend
max_hostname_len = (
max(
max(font.getlength(k) for k in data.keys()),
font.getlength(x_title),
)
+ 87.5
+ 10
)
except OSError:
# multiply by 1.25 for kerning and add 87.5 for legend
max_hostname_len = (
max(max(len(k) for k in data.keys()), len(x_title))
* font_size
* 1.25
+ 87.5
)
max_width = svg_width - max_hostname_len - 100 # key and total placeholder
# highest sum of counts
max_sum = max([sum(list(counts.values())) for counts in data.values()])
Expand Down

0 comments on commit 7006278

Please sign in to comment.