tesorotools-python 0.1.4__py3-none-any.whl → 0.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -624,7 +624,7 @@ def compact_legend_font_pt() -> float:
624
624
  )
625
625
 
626
626
 
627
- def compact_legend_kwargs() -> dict[str, Any]:
627
+ def compact_legend_kwargs(ax: Axes | None = None) -> dict[str, Any]:
628
628
  """Legend styling for compact charts, from the ``compact`` config.
629
629
 
630
630
  Returns ``fontsize`` / ``handlelength`` / ``handletextpad`` /
@@ -633,9 +633,17 @@ def compact_legend_kwargs() -> dict[str, Any]:
633
633
  the metrics used to *draw* the legend in :func:`legend_above` -- the
634
634
  invariant that prevents an over-counted ``ncol``. The smaller font
635
635
  and shorter handles let several wide labels share one legend row.
636
+
637
+ With *ax*, the legend is never larger than its tick labels: a chart
638
+ drawn with a small ``font_pt`` (the 7 pt of the notes) keeps the
639
+ legend at that size instead of ``legend_font_pt``.
636
640
  """
641
+ fontsize = compact_legend_font_pt()
642
+ ticks = (ax.get_yticklabels() or ax.get_xticklabels()) if ax else []
643
+ if ticks:
644
+ fontsize = min(fontsize, float(ticks[0].get_fontsize()))
637
645
  return {
638
- "fontsize": compact_legend_font_pt(),
646
+ "fontsize": fontsize,
639
647
  "handlelength": float(COMPACT_CONFIG.get("legend_handlelength", 1.2)),
640
648
  "handletextpad": float(COMPACT_CONFIG.get("legend_handletextpad", 0.4)),
641
649
  "columnspacing": float(COMPACT_CONFIG.get("legend_columnspacing", 0.8)),
@@ -1251,7 +1259,7 @@ def place_legend(
1251
1259
  side = resolve_legend_position(position, compact=compact)
1252
1260
  fig_w_px: float = fig.get_size_inches()[0] * fig.dpi
1253
1261
  if compact:
1254
- legend_kw = compact_legend_kwargs()
1262
+ legend_kw = compact_legend_kwargs(ax)
1255
1263
  if ncol is None:
1256
1264
  ncol = auto_ncol(
1257
1265
  ax, labels, available_width_px=fig_w_px, **legend_kw
@@ -499,7 +499,7 @@ class BoxPlot(FigureLifecycle):
499
499
  self.legend.position, compact=self.compact
500
500
  )
501
501
  if self.compact:
502
- kw = compact_legend_kwargs()
502
+ kw = compact_legend_kwargs(ax)
503
503
  ncol = self.legend.ncol or auto_ncol(
504
504
  ax, labels, available_width_px=fig_w_px, **kw
505
505
  )
@@ -15,26 +15,51 @@ from tesorotools.note.builder import (
15
15
  Chart,
16
16
  Note,
17
17
  Table,
18
- chart_size,
19
18
  format_number,
19
+ normalize_unit,
20
20
  spanish_date,
21
21
  )
22
- from tesorotools.note.lint import Issue, check
23
- from tesorotools.note.markdown import NoteSource, build, parse, read
22
+ from tesorotools.note.charts import (
23
+ NOTE_COLORS,
24
+ axis_decimals,
25
+ axis_format,
26
+ chart_size,
27
+ note_palette,
28
+ )
29
+ from tesorotools.note.cli import skill_text
30
+ from tesorotools.note.issues import Issue, NoteError
31
+ from tesorotools.note.lint import check
32
+ from tesorotools.note.markdown import (
33
+ ChartRenderer,
34
+ NoteSource,
35
+ assemble,
36
+ build,
37
+ parse,
38
+ read,
39
+ )
24
40
  from tesorotools.note.template import open_template
25
41
 
26
42
  __all__ = [
43
+ "NOTE_COLORS",
27
44
  "Chart",
45
+ "ChartRenderer",
28
46
  "Issue",
29
47
  "Note",
48
+ "NoteError",
30
49
  "NoteSource",
31
50
  "Table",
51
+ "assemble",
52
+ "axis_decimals",
53
+ "axis_format",
32
54
  "build",
33
55
  "chart_size",
34
56
  "check",
35
57
  "format_number",
58
+ "normalize_unit",
59
+ "note_palette",
36
60
  "open_template",
37
61
  "parse",
38
62
  "read",
63
+ "skill_text",
39
64
  "spanish_date",
40
65
  ]