Coverage for /builds/svesch/cikit/src/cikit/timeline/preview.py: 100%
12 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-10-09 14:17 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-10-09 14:17 +0000
1# SPDX-License-Identifier: GPL-3.0-or-later
2"""Generate deterministic preview charts for timeline presets.
4The preview helpers render one four-series chart for every available timeline
5preset. They are shared by the standalone timeline command and the cikit
6Sphinx documentation build so both always present the same chart examples.
8Author:
9 Sven Schlender
10Date:
11 2026-09-13
12"""
14from pathlib import Path
16from .timeline_chart import TimelineChart
17from .presets import TimelinePreset
20def build_preview_timeline() -> dict:
21 """Create deterministic four-series data for visual chart previews.
23 The values intentionally overlap and cross so line, filled line, grouped
24 bar, and stacked bar presets expose their characteristic rendering during
25 a quick visual inspection.
27 Returns:
28 Timeline dictionary accepted by ``TimelineChart``.
29 """
30 return {
31 "refs": [f"{index:02d}" for index in range(1, 17)],
32 "series": {
33 "Series A": [42, 45, 43, 47, 49, 48, 52, 51, 54, 57, 55, 59, 61, 60, 64, 66],
34 "Series B": [58, 56, 57, 54, 52, 53, 49, 50, 47, 45, 46, 43, 41, 42, 39, 37],
35 "Series C": [35, 38, 40, 39, 43, 46, 44, 48, 51, 49, 53, 56, 54, 58, 61, 59],
36 "Series D": [67, 64, 62, 65, 61, 59, 60, 56, 54, 55, 51, 49, 50, 46, 44, 45],
37 },
38 }
41def render_preview_chart(output_dir: Path, preset: TimelinePreset) -> Path:
42 """Render one four-series preview chart.
44 Args:
45 output_dir: Directory receiving the generated SVG file.
46 preset: Timeline preset to render.
48 Returns:
49 Path to the generated SVG file.
50 """
51 title = f"Timeline test - {preset.value} - 4 series"
52 chart = TimelineChart(build_preview_timeline(), title, preset)
53 output_file = output_dir / f"timeline_{preset.value}_4.svg"
55 return chart.render(output_file)
58def render_preview_charts(output_dir: Path) -> dict:
59 """Render one preview chart for every available preset.
61 Presets are resolved dynamically from ``TimelinePreset`` so newly added
62 chart types automatically become part of the preview set and generated
63 documentation without requiring another hard-coded list.
65 Args:
66 output_dir: Directory receiving the generated SVG files.
68 Returns:
69 Mapping from timeline preset to generated SVG path.
70 """
71 return {preset: render_preview_chart(output_dir, preset) for preset in TimelinePreset}