import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import io from PIL import Image, ImageDraw, ImageFont def create_placeholder_image(): """Cria uma imagem placeholder simples com texto""" # Cores profissionais bg_color = (248, 250, 252) # Slate-50 text_color = (100, 116, 139) # Slate-500 img = Image.new('RGB', (800, 600), color=bg_color) draw = ImageDraw.Draw(img) # Carregar fonte try: font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 48) except: font = ImageFont.load_default() # Texto centralizado text = "Waiting for plot..." bbox = draw.textbbox((0, 0), text, font=font) text_width = bbox[2] - bbox[0] text_height = bbox[3] - bbox[1] x = (800 - text_width) // 2 y = (600 - text_height) // 2 draw.text((x, y), text, fill=text_color, font=font) return img last_chart_image = None PLACEHOLDER_IMAGE = create_placeholder_image() def get_current_chart(): """Retorna o gráfico atual ou placeholder""" global last_chart_image return last_chart_image if last_chart_image is not None else PLACEHOLDER_IMAGE