Coverage for app / documents / visuals / theme.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-10-31 11:23 +0000

1"""Colours, sizes and fonts every visual is drawn with. 

2 

3``PALETTE`` is fe-core's (``RichMarkdown.tsx`` ``PALETTE`` and 

4``_GRAPH_PALETTE``, pinned by ``tests/documents/visuals/test_pins.py``), so a 

5chart keeps its colours from the chat to the PDF. The PDF's own colours live 

6here too and ``pdf.py`` reads them. Fonts come from the PDF's registered set 

7(``pdf._fonts``): a visual never registers its own. 

8""" 

9 

10from __future__ import annotations 

11 

12from dataclasses import dataclass 

13 

14from reportlab.lib import colors 

15 

16PALETTE: tuple[str, ...] = ( 

17 "#6366f1", 

18 "#10b981", 

19 "#f59e0b", 

20 "#ef4444", 

21 "#8b5cf6", 

22 "#06b6d4", 

23 "#f97316", 

24 "#ec4899", 

25) 

26 

27INK = colors.HexColor("#111827") 

28MUTED = colors.HexColor("#6b7280") 

29RULE = colors.HexColor("#e5e7eb") 

30PANEL = colors.HexColor("#f5f3ff") 

31ACCENT = colors.HexColor("#6d28d9") 

32#: Axis labels and node labels, as fe-core draws them. 

33LABEL = colors.HexColor("#4b5563") 

34FAINT = colors.HexColor("#9ca3af") 

35EDGE = colors.HexColor("#94a3b8") 

36WHITE = colors.white 

37 

38#: A CSS pixel in points: fe-core's sizes are pixels. 

39PX = 0.75 

40#: Text sizes, in points. 

41TICK_SIZE = 7.5 

42LABEL_SIZE = 8.0 

43LEGEND_SIZE = 7.5 

44 

45 

46def palette(i: int) -> colors.Color: 

47 return colors.HexColor(PALETTE[i % len(PALETTE)]) 

48 

49 

50@dataclass(frozen=True) 

51class Theme: 

52 """The PDF's fonts, as a visual draws its text.""" 

53 

54 regular: str 

55 bold: str 

56 mono: str