deckkit 0.1.0__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.
Files changed (144) hide show
  1. deckkit/__init__.py +12 -0
  2. deckkit/_bundled_fonts.py +54 -0
  3. deckkit/_diagnostics.py +48 -0
  4. deckkit/_font_assets/SOURCES.txt +9 -0
  5. deckkit/_font_assets/SourceCodePro-Bold.ttf +0 -0
  6. deckkit/_font_assets/SourceCodePro-BoldIt.ttf +0 -0
  7. deckkit/_font_assets/SourceCodePro-It.ttf +0 -0
  8. deckkit/_font_assets/SourceCodePro-LICENSE.txt +93 -0
  9. deckkit/_font_assets/SourceCodePro-Regular.ttf +0 -0
  10. deckkit/_font_assets/SourceSans3-Bold.ttf +0 -0
  11. deckkit/_font_assets/SourceSans3-BoldIt.ttf +0 -0
  12. deckkit/_font_assets/SourceSans3-It.ttf +0 -0
  13. deckkit/_font_assets/SourceSans3-LICENSE.txt +93 -0
  14. deckkit/_font_assets/SourceSans3-Regular.ttf +0 -0
  15. deckkit/_variable_evaluation.py +82 -0
  16. deckkit/animation.py +211 -0
  17. deckkit/annotations.py +161 -0
  18. deckkit/backends/__init__.py +1 -0
  19. deckkit/backends/_font_embedding.py +41 -0
  20. deckkit/backends/_pptx_fonts.py +230 -0
  21. deckkit/backends/_pptx_shadows.py +241 -0
  22. deckkit/backends/_pptx_tables.py +251 -0
  23. deckkit/backends/pptx.py +1225 -0
  24. deckkit/backends/pptx_animation.py +175 -0
  25. deckkit/backends/svg.py +527 -0
  26. deckkit/canvas/__init__.py +40 -0
  27. deckkit/canvas/_geometry.py +49 -0
  28. deckkit/canvas/clipping.py +336 -0
  29. deckkit/canvas/context.py +34 -0
  30. deckkit/canvas/elements.py +306 -0
  31. deckkit/canvas/path.py +250 -0
  32. deckkit/canvas/scene.py +74 -0
  33. deckkit/canvas/style.py +31 -0
  34. deckkit/charts/__init__.py +59 -0
  35. deckkit/charts/axes.py +249 -0
  36. deckkit/charts/chart.py +244 -0
  37. deckkit/charts/content.py +132 -0
  38. deckkit/charts/context.py +45 -0
  39. deckkit/charts/interval.py +166 -0
  40. deckkit/charts/legends.py +82 -0
  41. deckkit/charts/marks.py +410 -0
  42. deckkit/charts/scales.py +205 -0
  43. deckkit/citations.py +200 -0
  44. deckkit/compiler.py +410 -0
  45. deckkit/context.py +72 -0
  46. deckkit/deck.py +168 -0
  47. deckkit/drawables/__init__.py +42 -0
  48. deckkit/drawables/bounds.py +17 -0
  49. deckkit/drawables/connector.py +22 -0
  50. deckkit/drawables/drawable.py +38 -0
  51. deckkit/drawables/ellipse.py +21 -0
  52. deckkit/drawables/group.py +10 -0
  53. deckkit/drawables/image.py +14 -0
  54. deckkit/drawables/line.py +18 -0
  55. deckkit/drawables/path.py +78 -0
  56. deckkit/drawables/rectangle.py +24 -0
  57. deckkit/drawables/rich_text.py +176 -0
  58. deckkit/drawables/table.py +42 -0
  59. deckkit/drawables/text.py +29 -0
  60. deckkit/effects.py +84 -0
  61. deckkit/expanded_views.py +561 -0
  62. deckkit/fonts.py +329 -0
  63. deckkit/geometry.py +48 -0
  64. deckkit/identity.py +72 -0
  65. deckkit/layout.py +398 -0
  66. deckkit/layouts/__init__.py +20 -0
  67. deckkit/layouts/_content.py +27 -0
  68. deckkit/layouts/annotations.py +217 -0
  69. deckkit/layouts/containers.py +202 -0
  70. deckkit/layouts/grid.py +299 -0
  71. deckkit/layouts/modifiers.py +200 -0
  72. deckkit/layouts/primitives.py +213 -0
  73. deckkit/layouts/table.py +139 -0
  74. deckkit/measurement.py +420 -0
  75. deckkit/paint.py +73 -0
  76. deckkit/py.typed +0 -0
  77. deckkit/reconcile.py +119 -0
  78. deckkit/semantic.py +47 -0
  79. deckkit/theme.py +364 -0
  80. deckkit/themes/__init__.py +91 -0
  81. deckkit/themes/clarity.py +98 -0
  82. deckkit/tokens.py +226 -0
  83. deckkit/units.py +73 -0
  84. deckkit/variables.py +212 -0
  85. deckkit/view_expansion.py +185 -0
  86. deckkit/views/__init__.py +100 -0
  87. deckkit/views/_code_source.py +42 -0
  88. deckkit/views/_drawing.py +52 -0
  89. deckkit/views/canvas.py +27 -0
  90. deckkit/views/code.py +481 -0
  91. deckkit/views/code_evolution.py +284 -0
  92. deckkit/views/composite_view.py +19 -0
  93. deckkit/views/divider.py +38 -0
  94. deckkit/views/ellipse.py +38 -0
  95. deckkit/views/grid.py +156 -0
  96. deckkit/views/hstack.py +43 -0
  97. deckkit/views/image.py +43 -0
  98. deckkit/views/layout_view.py +30 -0
  99. deckkit/views/line.py +31 -0
  100. deckkit/views/modifier_views.py +281 -0
  101. deckkit/views/path.py +36 -0
  102. deckkit/views/primitive_view.py +16 -0
  103. deckkit/views/pygments_highlighter.py +67 -0
  104. deckkit/views/rectangle.py +61 -0
  105. deckkit/views/section_number.py +21 -0
  106. deckkit/views/semantic/__init__.py +51 -0
  107. deckkit/views/semantic/before_after.py +109 -0
  108. deckkit/views/semantic/bullet_graph.py +216 -0
  109. deckkit/views/semantic/card.py +129 -0
  110. deckkit/views/semantic/code_block.py +41 -0
  111. deckkit/views/semantic/diff.py +642 -0
  112. deckkit/views/semantic/estimate_interval.py +137 -0
  113. deckkit/views/semantic/figure.py +55 -0
  114. deckkit/views/semantic/item_list.py +171 -0
  115. deckkit/views/semantic/metric.py +74 -0
  116. deckkit/views/semantic/pill.py +69 -0
  117. deckkit/views/semantic/pipeline.py +94 -0
  118. deckkit/views/semantic/pipeline_stage.py +59 -0
  119. deckkit/views/semantic/semantic_view.py +76 -0
  120. deckkit/views/semantic/sparkline.py +164 -0
  121. deckkit/views/semantic/table.py +439 -0
  122. deckkit/views/semantic/terminal.py +361 -0
  123. deckkit/views/semantic/timeline.py +158 -0
  124. deckkit/views/slide.py +37 -0
  125. deckkit/views/slide_number.py +20 -0
  126. deckkit/views/slides/__init__.py +16 -0
  127. deckkit/views/slides/section_slide.py +89 -0
  128. deckkit/views/slides/slide_margins.py +32 -0
  129. deckkit/views/slides/slide_with_margins.py +22 -0
  130. deckkit/views/slides/title_and_content.py +49 -0
  131. deckkit/views/slides/title_and_content_slide.py +55 -0
  132. deckkit/views/spacer.py +45 -0
  133. deckkit/views/stack.py +36 -0
  134. deckkit/views/text.py +142 -0
  135. deckkit/views/view.py +229 -0
  136. deckkit/views/vstack.py +31 -0
  137. deckkit/views/zstack.py +27 -0
  138. deckkit-0.1.0.dist-info/METADATA +123 -0
  139. deckkit-0.1.0.dist-info/RECORD +144 -0
  140. deckkit-0.1.0.dist-info/WHEEL +5 -0
  141. deckkit-0.1.0.dist-info/licenses/LICENSE +21 -0
  142. deckkit-0.1.0.dist-info/licenses/src/deckkit/_font_assets/SourceCodePro-LICENSE.txt +93 -0
  143. deckkit-0.1.0.dist-info/licenses/src/deckkit/_font_assets/SourceSans3-LICENSE.txt +93 -0
  144. deckkit-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,45 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Hashable
4
+ from dataclasses import dataclass
5
+ from typing import Literal, Union
6
+
7
+ from ..canvas import CanvasContext
8
+ from ..drawables import Bounds
9
+ from ..theme import ColorStyle
10
+ from ..units import Length, pt
11
+ from .scales import BandScale, LinearScale, OrdinalScale
12
+
13
+ ResolvedPositionScale = Union[LinearScale, BandScale[Hashable]]
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class ChartContext:
18
+ canvas: CanvasContext
19
+ plot_bounds: Bounds
20
+ x_scale: ResolvedPositionScale
21
+ y_scale: ResolvedPositionScale
22
+ color_scale: OrdinalScale[Hashable, ColorStyle] | None = None
23
+
24
+ def position(self, channel: Literal["x", "y"], value: float | Hashable) -> Length:
25
+ scale = self.x_scale if channel == "x" else self.y_scale
26
+ if isinstance(scale, LinearScale):
27
+ if not isinstance(value, (int, float)):
28
+ raise TypeError("Quantitative chart scales require numeric values")
29
+ return scale(float(value))
30
+ return scale(value)
31
+
32
+ def center(self, channel: Literal["x", "y"], value: float | Hashable) -> Length:
33
+ scale = self.x_scale if channel == "x" else self.y_scale
34
+ if isinstance(scale, BandScale):
35
+ return scale.center(value)
36
+ return self.position(channel, value)
37
+
38
+ def bandwidth(self, channel: Literal["x", "y"]) -> Length:
39
+ scale = self.x_scale if channel == "x" else self.y_scale
40
+ return scale.bandwidth if isinstance(scale, BandScale) else pt(0)
41
+
42
+ def color(self, value: Hashable) -> ColorStyle:
43
+ if self.color_scale is None:
44
+ raise ValueError("Chart has no resolved color scale")
45
+ return self.color_scale(value)
@@ -0,0 +1,166 @@
1
+ """A point estimate with lower and upper bounds on a chart."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Callable, Hashable, Iterable
6
+ from dataclasses import dataclass
7
+ from math import isfinite
8
+ from typing import Generic, Literal, TypeVar
9
+
10
+ from ..canvas import CanvasElement, Ellipse, Line, Stroke
11
+ from ..drawables import Bounds
12
+ from ..geometry import Point
13
+ from ..theme import AccentColor, ColorStyle, PrimaryColor
14
+ from ..units import Length, pt, require_length
15
+ from .content import ChartContent, ChartOverflow, DomainContribution, Value
16
+ from .context import ChartContext
17
+
18
+ Datum = TypeVar("Datum")
19
+ _Axis = Literal["x", "y"]
20
+ _DEFAULT_STROKE = Stroke(AccentColor, pt(1.5))
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class IntervalMark(ChartContent, Generic[Datum]):
25
+ """Show a point estimate and interval for each category."""
26
+
27
+ data: tuple[Datum, ...]
28
+ category: Value[Datum, Hashable]
29
+ estimate: Value[Datum, float]
30
+ lower_bound: Value[Datum, float]
31
+ upper_bound: Value[Datum, float]
32
+ orientation: Literal["horizontal", "vertical"]
33
+ stroke: Stroke
34
+ point_fill: ColorStyle
35
+ point_radius: Length
36
+ cap_length: Length
37
+ key: Callable[[Datum], str | int] | None
38
+ series: str
39
+
40
+ def __init__(
41
+ self,
42
+ data: Iterable[Datum],
43
+ *,
44
+ category: Value[Datum, Hashable],
45
+ estimate: Value[Datum, float],
46
+ lower: Value[Datum, float],
47
+ upper: Value[Datum, float],
48
+ orientation: Literal["horizontal", "vertical"] = "horizontal",
49
+ stroke: Stroke = _DEFAULT_STROKE,
50
+ point_fill: ColorStyle = PrimaryColor,
51
+ point_radius: Length = pt(2.5),
52
+ cap_length: Length = pt(6),
53
+ key: Callable[[Datum], str | int] | None = None,
54
+ series: str | None = None,
55
+ ) -> None:
56
+ if orientation not in ("horizontal", "vertical"):
57
+ raise ValueError("IntervalMark orientation must be horizontal or vertical")
58
+ if not all(callable(channel) for channel in (category, estimate, lower, upper)):
59
+ raise TypeError("IntervalMark channels must be callable")
60
+ if not isinstance(stroke, Stroke):
61
+ raise TypeError("IntervalMark.stroke must be a Stroke")
62
+ if key is not None and not callable(key):
63
+ raise TypeError("IntervalMark key must be callable")
64
+ for length in (point_radius, cap_length):
65
+ require_length(length)
66
+ if length < pt(0):
67
+ raise ValueError(
68
+ "IntervalMark point radius and cap length must be nonnegative"
69
+ )
70
+ object.__setattr__(self, "data", tuple(data))
71
+ object.__setattr__(self, "category", category)
72
+ object.__setattr__(self, "estimate", estimate)
73
+ object.__setattr__(self, "lower_bound", lower)
74
+ object.__setattr__(self, "upper_bound", upper)
75
+ object.__setattr__(self, "orientation", orientation)
76
+ object.__setattr__(self, "stroke", stroke)
77
+ object.__setattr__(self, "point_fill", point_fill)
78
+ object.__setattr__(self, "point_radius", point_radius)
79
+ object.__setattr__(self, "cap_length", cap_length)
80
+ object.__setattr__(self, "key", key)
81
+ object.__setattr__(self, "series", series or estimate.label)
82
+
83
+ def _interval(self, datum: Datum) -> tuple[float, float, float]:
84
+ estimate, lower, upper = (
85
+ self.estimate(datum),
86
+ self.lower_bound(datum),
87
+ self.upper_bound(datum),
88
+ )
89
+ if not all(isfinite(number) for number in (estimate, lower, upper)):
90
+ raise ValueError("IntervalMark values must be finite")
91
+ if lower > upper:
92
+ raise ValueError("IntervalMark lower bounds must not exceed upper bounds")
93
+ return estimate, lower, upper
94
+
95
+ def domain_contributions(self) -> tuple[DomainContribution, ...]:
96
+ magnitude, category = self._axes()
97
+ return (
98
+ DomainContribution.quantitative(
99
+ magnitude,
100
+ (number for item in self.data for number in self._interval(item)),
101
+ ),
102
+ DomainContribution.categorical(
103
+ category, (self.category(item) for item in self.data)
104
+ ),
105
+ )
106
+
107
+ def _axes(self) -> tuple[_Axis, _Axis]:
108
+ return ("x", "y") if self.orientation == "horizontal" else ("y", "x")
109
+
110
+ def overflow(self) -> ChartOverflow:
111
+ along = max(self.point_radius, self.stroke.width / 2)
112
+ across = max(self.point_radius, self.cap_length / 2 + self.stroke.width / 2)
113
+ if self.orientation == "horizontal":
114
+ return ChartOverflow(top=across, bottom=across, left=along, right=along)
115
+ return ChartOverflow(top=along, bottom=along, left=across, right=across)
116
+
117
+ def lower(self, context: ChartContext) -> Iterable[CanvasElement]:
118
+ plot, inset = context.plot_bounds, self.overflow()
119
+ if (
120
+ plot.width <= inset.left + inset.right
121
+ or plot.height <= inset.top + inset.bottom
122
+ ):
123
+ return
124
+ horizontal = self.orientation == "horizontal"
125
+ magnitude, category = self._axes()
126
+
127
+ def point(along: Length, across: Length) -> Point:
128
+ return Point(along, across) if horizontal else Point(across, along)
129
+
130
+ for datum in self.data:
131
+ offsets = self._interval(datum)
132
+ estimate, lower, upper = (
133
+ context.position(magnitude, value) for value in offsets
134
+ )
135
+ center = context.center(category, self.category(datum))
136
+ prefix = (
137
+ f"series:{self.series}/datum:{self.key(datum)}" if self.key else None
138
+ )
139
+ if lower != upper:
140
+ yield Line(
141
+ point(lower, center),
142
+ point(upper, center),
143
+ self.stroke,
144
+ key=f"{prefix}/interval" if prefix is not None else None,
145
+ )
146
+ if self.cap_length > pt(0):
147
+ caps = (
148
+ ((lower, "lower"), (upper, "upper"))
149
+ if lower != upper
150
+ else ((lower, "lower"),)
151
+ )
152
+ for edge, name in caps:
153
+ yield Line(
154
+ point(edge, center - self.cap_length / 2),
155
+ point(edge, center + self.cap_length / 2),
156
+ self.stroke,
157
+ key=f"{prefix}/{name}" if prefix is not None else None,
158
+ )
159
+ if self.point_radius > pt(0):
160
+ radius = self.point_radius
161
+ dot = point(estimate, center)
162
+ yield Ellipse(
163
+ Bounds(dot.x - radius, dot.y - radius, radius * 2, radius * 2),
164
+ fill=self.point_fill,
165
+ key=f"{prefix}/estimate" if prefix is not None else None,
166
+ )
@@ -0,0 +1,82 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Hashable
4
+ from dataclasses import dataclass
5
+
6
+ from ..canvas import CanvasContext, CanvasElement, CanvasText, Rect
7
+ from ..drawables import Bounds
8
+ from ..geometry import Point
9
+ from ..theme import ChartLegendTextStyle, ColorStyle
10
+ from ..units import Length, pt
11
+ from .scales import OrdinalScale
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class Legend:
16
+ title: str | None = None
17
+
18
+
19
+ DEFAULT_LEGEND = Legend()
20
+
21
+
22
+ def required_legend_width(
23
+ canvas: CanvasContext,
24
+ scale: OrdinalScale[Hashable, ColorStyle] | None,
25
+ legend: Legend | None,
26
+ inferred_title: str | None,
27
+ ) -> Length:
28
+ if scale is None or legend is None:
29
+ return pt(0)
30
+ labels = tuple(str(value) for value in scale.domain)
31
+ title = legend.title if legend.title is not None else inferred_title
32
+ text_width = max(
33
+ (
34
+ _measure(canvas, text).width
35
+ for text in (*labels, *((title,) if title else ()))
36
+ ),
37
+ default=pt(0),
38
+ )
39
+ return pt(12) + pt(8) + text_width + pt(16)
40
+
41
+
42
+ def lower_legend(
43
+ canvas: CanvasContext,
44
+ plot: Bounds,
45
+ scale: OrdinalScale[Hashable, ColorStyle] | None,
46
+ legend: Legend | None,
47
+ inferred_title: str | None,
48
+ ) -> tuple[CanvasElement, ...]:
49
+ if scale is None or legend is None:
50
+ return ()
51
+ result: list[CanvasElement] = []
52
+ x = plot.x + plot.width + pt(16)
53
+ y = plot.y
54
+ title = legend.title if legend.title is not None else inferred_title
55
+ if title:
56
+ result.append(CanvasText(title, Point(x, y), typography=ChartLegendTextStyle))
57
+ y += _measure(canvas, title).height + pt(8)
58
+ for category in scale.domain:
59
+ label = str(category)
60
+ row_height = max(pt(12), _measure(canvas, label).height)
61
+ result.append(
62
+ Rect(
63
+ Bounds(x, y + (row_height - pt(10)) / 2, pt(10), pt(10)),
64
+ fill=scale(category),
65
+ )
66
+ )
67
+ result.append(
68
+ CanvasText(
69
+ label,
70
+ Point(x + pt(18), y + row_height / 2),
71
+ typography=ChartLegendTextStyle,
72
+ vertical_alignment="center",
73
+ )
74
+ )
75
+ y += row_height + pt(6)
76
+ return tuple(result)
77
+
78
+
79
+ def _measure(canvas: CanvasContext, text: str) -> Bounds:
80
+ return CanvasText(
81
+ text, Point(pt(0), pt(0)), typography=ChartLegendTextStyle
82
+ ).measured_anchor_bounds(canvas)