fix generate report pie chart to fix overlapping labels when all boards are working

This commit is contained in:
UpstreamData
2022-06-08 10:59:52 -06:00
parent 3a60a3584a
commit 10949225c0

View File

@@ -2,6 +2,7 @@ import datetime
import ipaddress import ipaddress
from base64 import b64decode from base64 import b64decode
from io import BytesIO from io import BytesIO
from copy import copy
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.figure import Figure from matplotlib.figure import Figure
@@ -178,15 +179,26 @@ def create_boards_pie_chart(data):
num_bad_boards = [0, 0, 0, 0] num_bad_boards = [0, 0, 0, 0]
for item in data.keys(): for item in data.keys():
num_bad_boards[len(data[item])] += 1 num_bad_boards[len(data[item])] += 1
idxs = []
graph_labels = copy(labels)
graph_num_bad_board = copy(num_bad_boards)
for idx in range(len(num_bad_boards)):
if num_bad_boards[idx] == 0:
idxs.append(idx)
idxs.sort(reverse=True)
for idx in idxs:
graph_labels.pop(idx)
graph_num_bad_board.pop(idx)
cmap = plt.get_cmap("Blues") cmap = plt.get_cmap("Blues")
cs = cmap(np.linspace(0.2, 0.8, num=len(num_bad_boards))) cs = cmap(np.linspace(0.2, 0.8, num=len(graph_num_bad_board)))
# fig, ax = plt.subplots() -> causes window resizing... # fig, ax = plt.subplots() -> causes window resizing...
fig = Figure() fig = Figure()
ax = fig.add_subplot() ax = fig.add_subplot()
ax.pie( ax.pie(
num_bad_boards, graph_num_bad_board,
labels=labels, labels=graph_labels,
autopct="%1.2f%%", autopct="%1.2f%%",
shadow=True, shadow=True,
startangle=180, startangle=180,