quantumgui 1.0.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.
- quantumgui/__init__.py +9 -0
- quantumgui/__main__.py +6 -0
- quantumgui/cli.py +341 -0
- quantumgui/core/__init__.py +39 -0
- quantumgui/core/animation.py +221 -0
- quantumgui/core/audit.py +323 -0
- quantumgui/core/context.py +54 -0
- quantumgui/core/data_source.py +426 -0
- quantumgui/core/draw.py +428 -0
- quantumgui/core/enterprise.py +402 -0
- quantumgui/core/enterprise_app.py +419 -0
- quantumgui/core/events.py +34 -0
- quantumgui/core/geometry.py +108 -0
- quantumgui/core/native_dialogs.py +276 -0
- quantumgui/core/pdf_report.py +390 -0
- quantumgui/core/rules.py +284 -0
- quantumgui/core/state.py +42 -0
- quantumgui/core/task_runner.py +181 -0
- quantumgui/core/widget.py +498 -0
- quantumgui/core/window.py +920 -0
- quantumgui/core/xlsx_export.py +145 -0
- quantumgui/py.typed +0 -0
- quantumgui/theme/__init__.py +32 -0
- quantumgui/theme/hct.py +191 -0
- quantumgui/theme/theme.py +93 -0
- quantumgui/theme/tokens.py +423 -0
- quantumgui/ui.py +2142 -0
- quantumgui/widgets/__init__.py +168 -0
- quantumgui/widgets/advanced.py +499 -0
- quantumgui/widgets/button.py +224 -0
- quantumgui/widgets/charts.py +625 -0
- quantumgui/widgets/charts_bi.py +528 -0
- quantumgui/widgets/charts_extra.py +430 -0
- quantumgui/widgets/charts_pro.py +568 -0
- quantumgui/widgets/checkbox.py +199 -0
- quantumgui/widgets/chip.py +219 -0
- quantumgui/widgets/containers.py +321 -0
- quantumgui/widgets/data_controls.py +487 -0
- quantumgui/widgets/data_grid.py +956 -0
- quantumgui/widgets/data_table.py +551 -0
- quantumgui/widgets/date_picker.py +407 -0
- quantumgui/widgets/display_media.py +372 -0
- quantumgui/widgets/display_pro.py +407 -0
- quantumgui/widgets/drawer.py +252 -0
- quantumgui/widgets/enterprise_controls.py +934 -0
- quantumgui/widgets/fab.py +261 -0
- quantumgui/widgets/forms_pro.py +703 -0
- quantumgui/widgets/forms_pro_media.py +587 -0
- quantumgui/widgets/inputs.py +870 -0
- quantumgui/widgets/layout_pro.py +162 -0
- quantumgui/widgets/list_view.py +307 -0
- quantumgui/widgets/masked_input.py +131 -0
- quantumgui/widgets/master_detail.py +155 -0
- quantumgui/widgets/navigation.py +382 -0
- quantumgui/widgets/overlays.py +355 -0
- quantumgui/widgets/productivity.py +500 -0
- quantumgui/widgets/productivity_boards.py +544 -0
- quantumgui/widgets/radio.py +209 -0
- quantumgui/widgets/scroll_view.py +129 -0
- quantumgui/widgets/select.py +373 -0
- quantumgui/widgets/sheets.py +249 -0
- quantumgui/widgets/slider.py +209 -0
- quantumgui/widgets/switch.py +196 -0
- quantumgui/widgets/tabs.py +175 -0
- quantumgui/widgets/text.py +101 -0
- quantumgui/widgets/text_field.py +490 -0
- quantumgui/widgets/time_picker.py +499 -0
- quantumgui-1.0.0.dist-info/METADATA +137 -0
- quantumgui-1.0.0.dist-info/RECORD +73 -0
- quantumgui-1.0.0.dist-info/WHEEL +5 -0
- quantumgui-1.0.0.dist-info/entry_points.txt +2 -0
- quantumgui-1.0.0.dist-info/licenses/LICENSE +32 -0
- quantumgui-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
"""Material Design 3 Specialized GPU Charts: HorizontalBarChart, FunnelChart, CandlestickChart, GanttChart."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Sequence
|
|
6
|
+
|
|
7
|
+
import skia
|
|
8
|
+
|
|
9
|
+
from ..core.draw import draw_text_centered_y, font_for_style, make_rrect, measure_text
|
|
10
|
+
from ..core.events import MouseEvent
|
|
11
|
+
from ..core.geometry import Constraints, Rect, Size
|
|
12
|
+
from ..core.widget import Widget
|
|
13
|
+
from ..theme import Color, Theme
|
|
14
|
+
from .charts import ChartColorRole, _draw_chart_tooltip, _format_num, _resolve_accent
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class HorizontalBarChart(Widget):
|
|
18
|
+
"""Material Design 3 GPU HorizontalBarChart ideal for rankings and long labels."""
|
|
19
|
+
|
|
20
|
+
interactive = True
|
|
21
|
+
cursor = "pointer"
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
labels: Sequence[str],
|
|
26
|
+
values: Sequence[float],
|
|
27
|
+
*,
|
|
28
|
+
title: str | None = None,
|
|
29
|
+
color: ChartColorRole | Color = "primary",
|
|
30
|
+
show_values: bool = True,
|
|
31
|
+
chart_height: float = 220.0,
|
|
32
|
+
) -> None:
|
|
33
|
+
super().__init__()
|
|
34
|
+
self.labels = [str(x) for x in labels]
|
|
35
|
+
self.values = [float(v) for v in values]
|
|
36
|
+
self.title = title
|
|
37
|
+
self.color: ChartColorRole | Color = color
|
|
38
|
+
self.show_values = show_values
|
|
39
|
+
self.chart_height = float(chart_height)
|
|
40
|
+
self._hover_idx: int = -1
|
|
41
|
+
self._bar_rects: list[Rect] = []
|
|
42
|
+
self._fill_width = True
|
|
43
|
+
|
|
44
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
45
|
+
w = constraints.max_width if constraints.max_width != float("inf") else 420.0
|
|
46
|
+
return Size(w, self.chart_height)
|
|
47
|
+
|
|
48
|
+
def on_mouse_move(self, event: MouseEvent) -> None:
|
|
49
|
+
found = -1
|
|
50
|
+
for i, br in enumerate(self._bar_rects):
|
|
51
|
+
if self.rect.x <= event.x <= self.rect.right and br.y - 4.0 <= event.y <= br.bottom + 4.0:
|
|
52
|
+
found = i
|
|
53
|
+
break
|
|
54
|
+
if found != self._hover_idx:
|
|
55
|
+
self._hover_idx = found
|
|
56
|
+
self.invalidate()
|
|
57
|
+
|
|
58
|
+
def on_mouse_leave(self) -> None:
|
|
59
|
+
super().on_mouse_leave()
|
|
60
|
+
self._hover_idx = -1
|
|
61
|
+
|
|
62
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
63
|
+
c = theme.colors
|
|
64
|
+
r = self.rect
|
|
65
|
+
accent = _resolve_accent(theme, self.color)
|
|
66
|
+
top_pad = 36.0 if self.title else 12.0
|
|
67
|
+
if self.title:
|
|
68
|
+
tf = font_for_style(theme.font_family, theme.typography.title_medium)
|
|
69
|
+
draw_text_centered_y(canvas, self.title, r.x + 4.0, r.y + 14.0, tf, c.on_surface)
|
|
70
|
+
|
|
71
|
+
if not self.values:
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
lf = font_for_style(theme.font_family, theme.typography.label_medium)
|
|
75
|
+
max_lbl_w = min(130.0, max((measure_text(lf, lb) for lb in self.labels), default=50.0) + 14.0)
|
|
76
|
+
plot = Rect(r.x + max_lbl_w, r.y + top_pad, max(40.0, r.width - max_lbl_w - 48.0), max(20.0, r.height - top_pad - 12.0))
|
|
77
|
+
|
|
78
|
+
hi = max(1.0, max(self.values) * 1.08)
|
|
79
|
+
n = len(self.values)
|
|
80
|
+
slot_h = plot.height / n
|
|
81
|
+
bar_h = max(10.0, min(26.0, slot_h * 0.6))
|
|
82
|
+
self._bar_rects = []
|
|
83
|
+
|
|
84
|
+
for i, val in enumerate(self.values):
|
|
85
|
+
bw = max(2.0, (max(0.0, val) / hi) * plot.width)
|
|
86
|
+
by = plot.y + i * slot_h + (slot_h - bar_h) * 0.5
|
|
87
|
+
br = Rect(plot.x, by, bw, bar_h)
|
|
88
|
+
self._bar_rects.append(br)
|
|
89
|
+
|
|
90
|
+
if i < len(self.labels):
|
|
91
|
+
lb = self.labels[i]
|
|
92
|
+
draw_text_centered_y(canvas, lb, plot.x - measure_text(lf, lb) - 10.0, br.center_y, lf, c.on_surface_variant)
|
|
93
|
+
|
|
94
|
+
is_hov = i == self._hover_idx
|
|
95
|
+
fill = accent if (self._hover_idx == -1 or is_hov) else accent.with_alpha(0.42)
|
|
96
|
+
rr = skia.RRect()
|
|
97
|
+
rad = min(7.0, bar_h * 0.5, bw)
|
|
98
|
+
rr.setRectRadii(
|
|
99
|
+
skia.Rect.MakeXYWH(br.x, br.y, br.width, br.height),
|
|
100
|
+
[(0.0, 0.0), (rad, rad), (rad, rad), (0.0, 0.0)],
|
|
101
|
+
)
|
|
102
|
+
canvas.drawRRect(rr, skia.Paint(AntiAlias=True, Color=fill.to_skia()))
|
|
103
|
+
|
|
104
|
+
if self.show_values:
|
|
105
|
+
draw_text_centered_y(canvas, _format_num(val), br.right + 8.0, br.center_y, lf, c.on_surface)
|
|
106
|
+
|
|
107
|
+
if 0 <= self._hover_idx < len(self._bar_rects):
|
|
108
|
+
br = self._bar_rects[self._hover_idx]
|
|
109
|
+
lb = self.labels[self._hover_idx] if self._hover_idx < len(self.labels) else f"#{self._hover_idx + 1}"
|
|
110
|
+
_draw_chart_tooltip(canvas, theme, br.right, br.y, f"{lb}: {_format_num(self.values[self._hover_idx])}", r)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class FunnelChart(Widget):
|
|
114
|
+
"""Material Design 3 GPU Conversion FunnelChart with stage percentages and hover tooltip."""
|
|
115
|
+
|
|
116
|
+
interactive = True
|
|
117
|
+
cursor = "pointer"
|
|
118
|
+
|
|
119
|
+
def __init__(
|
|
120
|
+
self,
|
|
121
|
+
stages: Sequence[tuple[str, float]],
|
|
122
|
+
*,
|
|
123
|
+
title: str | None = None,
|
|
124
|
+
color: ChartColorRole | Color = "primary",
|
|
125
|
+
chart_height: float = 230.0,
|
|
126
|
+
) -> None:
|
|
127
|
+
super().__init__()
|
|
128
|
+
self.stages: list[tuple[str, float]] = [(str(k), max(0.0, float(v))) for k, v in stages]
|
|
129
|
+
self.title = title
|
|
130
|
+
self.color: ChartColorRole | Color = color
|
|
131
|
+
self.chart_height = float(chart_height)
|
|
132
|
+
self._hover_idx: int = -1
|
|
133
|
+
self._stage_rects: list[Rect] = []
|
|
134
|
+
self._fill_width = True
|
|
135
|
+
|
|
136
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
137
|
+
w = constraints.max_width if constraints.max_width != float("inf") else 400.0
|
|
138
|
+
return Size(w, self.chart_height)
|
|
139
|
+
|
|
140
|
+
def on_mouse_move(self, event: MouseEvent) -> None:
|
|
141
|
+
found = -1
|
|
142
|
+
for i, sr in enumerate(self._stage_rects):
|
|
143
|
+
if sr.contains(event.x, event.y):
|
|
144
|
+
found = i
|
|
145
|
+
break
|
|
146
|
+
if found != self._hover_idx:
|
|
147
|
+
self._hover_idx = found
|
|
148
|
+
self.invalidate()
|
|
149
|
+
|
|
150
|
+
def on_mouse_leave(self) -> None:
|
|
151
|
+
super().on_mouse_leave()
|
|
152
|
+
self._hover_idx = -1
|
|
153
|
+
|
|
154
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
155
|
+
c = theme.colors
|
|
156
|
+
r = self.rect
|
|
157
|
+
accent = _resolve_accent(theme, self.color)
|
|
158
|
+
top_pad = 36.0 if self.title else 12.0
|
|
159
|
+
if self.title:
|
|
160
|
+
tf = font_for_style(theme.font_family, theme.typography.title_medium)
|
|
161
|
+
draw_text_centered_y(canvas, self.title, r.x + 4.0, r.y + 14.0, tf, c.on_surface)
|
|
162
|
+
|
|
163
|
+
if not self.stages:
|
|
164
|
+
return
|
|
165
|
+
|
|
166
|
+
top_val = max(1e-3, self.stages[0][1])
|
|
167
|
+
n = len(self.stages)
|
|
168
|
+
gap = 6.0
|
|
169
|
+
avail_h = max(40.0, r.height - top_pad - 12.0)
|
|
170
|
+
row_h = max(20.0, (avail_h - gap * (n - 1)) / n)
|
|
171
|
+
max_w = max(80.0, r.width - 24.0)
|
|
172
|
+
lf = font_for_style(theme.font_family, theme.typography.label_medium)
|
|
173
|
+
self._stage_rects = []
|
|
174
|
+
|
|
175
|
+
for i, (label, val) in enumerate(self.stages):
|
|
176
|
+
frac = max(0.18, min(1.0, val / top_val))
|
|
177
|
+
sw = max_w * frac
|
|
178
|
+
sx = r.center_x - sw * 0.5
|
|
179
|
+
sy = r.y + top_pad + i * (row_h + gap)
|
|
180
|
+
sr = Rect(sx, sy, sw, row_h)
|
|
181
|
+
self._stage_rects.append(sr)
|
|
182
|
+
|
|
183
|
+
blend_t = (i / max(1, n - 1)) * 0.55
|
|
184
|
+
col = accent.blend(c.tertiary, blend_t)
|
|
185
|
+
if self._hover_idx != -1 and self._hover_idx != i:
|
|
186
|
+
col = col.with_alpha(0.45)
|
|
187
|
+
|
|
188
|
+
canvas.drawRRect(make_rrect(sr, 8.0), skia.Paint(AntiAlias=True, Color=col.to_skia()))
|
|
189
|
+
pct = (val / top_val) * 100.0
|
|
190
|
+
txt = f"{label} · {_format_num(val)} ({pct:.0f}%)"
|
|
191
|
+
tw = measure_text(lf, txt)
|
|
192
|
+
if tw + 12.0 <= sw:
|
|
193
|
+
draw_text_centered_y(canvas, txt, sr.center_x - tw * 0.5, sr.center_y, lf, c.on_primary)
|
|
194
|
+
else:
|
|
195
|
+
draw_text_centered_y(canvas, txt, sr.right + 8.0, sr.center_y, lf, c.on_surface)
|
|
196
|
+
|
|
197
|
+
if 0 <= self._hover_idx < len(self._stage_rects):
|
|
198
|
+
sr = self._stage_rects[self._hover_idx]
|
|
199
|
+
lb, val = self.stages[self._hover_idx]
|
|
200
|
+
pct = (val / top_val) * 100.0
|
|
201
|
+
_draw_chart_tooltip(canvas, theme, sr.center_x, sr.y, f"{lb}: {_format_num(val)} ({pct:.1f}%)", r)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class CandlestickChart(Widget):
|
|
205
|
+
"""Material Design 3 GPU Financial CandlestickChart (`(label, open, high, low, close)`)."""
|
|
206
|
+
|
|
207
|
+
interactive = True
|
|
208
|
+
cursor = "pointer"
|
|
209
|
+
|
|
210
|
+
def __init__(
|
|
211
|
+
self,
|
|
212
|
+
candles: Sequence[tuple[str, float, float, float, float]],
|
|
213
|
+
*,
|
|
214
|
+
title: str | None = None,
|
|
215
|
+
chart_height: float = 240.0,
|
|
216
|
+
) -> None:
|
|
217
|
+
super().__init__()
|
|
218
|
+
self.candles: list[tuple[str, float, float, float, float]] = [
|
|
219
|
+
(str(c[0]), float(c[1]), float(c[2]), float(c[3]), float(c[4]))
|
|
220
|
+
for c in candles
|
|
221
|
+
]
|
|
222
|
+
self.title = title
|
|
223
|
+
self.chart_height = float(chart_height)
|
|
224
|
+
self._hover_idx: int = -1
|
|
225
|
+
self._xs: list[float] = []
|
|
226
|
+
self._fill_width = True
|
|
227
|
+
|
|
228
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
229
|
+
w = constraints.max_width if constraints.max_width != float("inf") else 460.0
|
|
230
|
+
return Size(w, self.chart_height)
|
|
231
|
+
|
|
232
|
+
def on_mouse_move(self, event: MouseEvent) -> None:
|
|
233
|
+
if not self._xs:
|
|
234
|
+
return
|
|
235
|
+
best = min(range(len(self._xs)), key=lambda i: abs(event.x - self._xs[i]))
|
|
236
|
+
if best != self._hover_idx:
|
|
237
|
+
self._hover_idx = best
|
|
238
|
+
self.invalidate()
|
|
239
|
+
|
|
240
|
+
def on_mouse_leave(self) -> None:
|
|
241
|
+
super().on_mouse_leave()
|
|
242
|
+
self._hover_idx = -1
|
|
243
|
+
|
|
244
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
245
|
+
c = theme.colors
|
|
246
|
+
r = self.rect
|
|
247
|
+
top_pad = 36.0 if self.title else 14.0
|
|
248
|
+
plot = Rect(r.x + 48.0, r.y + top_pad, max(20.0, r.width - 64.0), max(20.0, r.height - top_pad - 28.0))
|
|
249
|
+
|
|
250
|
+
if self.title:
|
|
251
|
+
tf = font_for_style(theme.font_family, theme.typography.title_medium)
|
|
252
|
+
draw_text_centered_y(canvas, self.title, r.x + 4.0, r.y + 14.0, tf, c.on_surface)
|
|
253
|
+
|
|
254
|
+
if not self.candles:
|
|
255
|
+
return
|
|
256
|
+
|
|
257
|
+
lo = min(x[3] for x in self.candles)
|
|
258
|
+
hi = max(x[2] for x in self.candles)
|
|
259
|
+
pad = max(1.0, (hi - lo) * 0.08)
|
|
260
|
+
lo -= pad
|
|
261
|
+
hi += pad
|
|
262
|
+
span = max(1e-3, hi - lo)
|
|
263
|
+
|
|
264
|
+
lf = font_for_style(theme.font_family, theme.typography.label_small)
|
|
265
|
+
grid_p = skia.Paint(AntiAlias=True, Color=c.outline_variant.with_alpha(0.55).to_skia(), StrokeWidth=1.0)
|
|
266
|
+
for step in range(5):
|
|
267
|
+
frac = step / 4.0
|
|
268
|
+
gy = plot.bottom - frac * plot.height
|
|
269
|
+
canvas.drawLine(plot.x, gy, plot.right, gy, grid_p)
|
|
270
|
+
vt = _format_num(lo + frac * span)
|
|
271
|
+
draw_text_centered_y(canvas, vt, plot.x - measure_text(lf, vt) - 8.0, gy, lf, c.on_surface_variant)
|
|
272
|
+
|
|
273
|
+
n = len(self.candles)
|
|
274
|
+
slot_w = plot.width / n
|
|
275
|
+
body_w = max(6.0, min(22.0, slot_w * 0.56))
|
|
276
|
+
bull_c = Color.from_hex("#1E8E3E") if theme.mode == "light" else Color.from_hex("#81C995")
|
|
277
|
+
bear_c = c.error
|
|
278
|
+
self._xs = []
|
|
279
|
+
|
|
280
|
+
def y_for(p: float) -> float:
|
|
281
|
+
return plot.bottom - ((p - lo) / span) * plot.height
|
|
282
|
+
|
|
283
|
+
for i, (lbl, o, h, l, cl) in enumerate(self.candles):
|
|
284
|
+
cx = plot.x + (i + 0.5) * slot_w
|
|
285
|
+
self._xs.append(cx)
|
|
286
|
+
col = bull_c if cl >= o else bear_c
|
|
287
|
+
if self._hover_idx != -1 and self._hover_idx != i:
|
|
288
|
+
col = col.with_alpha(0.45)
|
|
289
|
+
|
|
290
|
+
# High-Low wick
|
|
291
|
+
canvas.drawLine(cx, y_for(h), cx, y_for(l), skia.Paint(AntiAlias=True, Color=col.to_skia(), StrokeWidth=1.6))
|
|
292
|
+
|
|
293
|
+
# Open-Close body
|
|
294
|
+
y1, y2 = y_for(max(o, cl)), y_for(min(o, cl))
|
|
295
|
+
bh = max(2.0, y2 - y1)
|
|
296
|
+
canvas.drawRRect(
|
|
297
|
+
make_rrect(Rect(cx - body_w * 0.5, y1, body_w, bh), 2.5),
|
|
298
|
+
skia.Paint(AntiAlias=True, Color=col.to_skia()),
|
|
299
|
+
)
|
|
300
|
+
draw_text_centered_y(canvas, lbl, cx - measure_text(lf, lbl) * 0.5, plot.bottom + 15.0, lf, c.on_surface_variant)
|
|
301
|
+
|
|
302
|
+
if 0 <= self._hover_idx < len(self.candles):
|
|
303
|
+
lbl, o, h, l, cl = self.candles[self._hover_idx]
|
|
304
|
+
cx = self._xs[self._hover_idx]
|
|
305
|
+
canvas.drawLine(cx, plot.y, cx, plot.bottom, skia.Paint(AntiAlias=True, Color=c.outline.with_alpha(0.4).to_skia(), StrokeWidth=1.0))
|
|
306
|
+
_draw_chart_tooltip(
|
|
307
|
+
canvas,
|
|
308
|
+
theme,
|
|
309
|
+
cx,
|
|
310
|
+
y_for(h),
|
|
311
|
+
f"{lbl} · O:{_format_num(o)} H:{_format_num(h)} L:{_format_num(l)} C:{_format_num(cl)}",
|
|
312
|
+
r,
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
class GanttChart(Widget):
|
|
317
|
+
"""Material Design 3 GPU Project Timeline GanttChart (`(name, start, end[, progress])`)."""
|
|
318
|
+
|
|
319
|
+
interactive = True
|
|
320
|
+
cursor = "pointer"
|
|
321
|
+
|
|
322
|
+
def __init__(
|
|
323
|
+
self,
|
|
324
|
+
tasks: Sequence[tuple],
|
|
325
|
+
*,
|
|
326
|
+
title: str | None = None,
|
|
327
|
+
unit: str = "Día",
|
|
328
|
+
chart_height: float = 230.0,
|
|
329
|
+
) -> None:
|
|
330
|
+
super().__init__()
|
|
331
|
+
self.tasks: list[tuple[str, float, float, float]] = []
|
|
332
|
+
for t in tasks:
|
|
333
|
+
name = str(t[0])
|
|
334
|
+
st = float(t[1])
|
|
335
|
+
en = max(st + 0.1, float(t[2]))
|
|
336
|
+
prog = max(0.0, min(1.0, float(t[3]))) if len(t) >= 4 else 1.0
|
|
337
|
+
self.tasks.append((name, st, en, prog))
|
|
338
|
+
self.title = title
|
|
339
|
+
self.unit = unit
|
|
340
|
+
self.chart_height = float(chart_height)
|
|
341
|
+
self._hover_idx: int = -1
|
|
342
|
+
self._bar_rects: list[Rect] = []
|
|
343
|
+
self._fill_width = True
|
|
344
|
+
|
|
345
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
346
|
+
w = constraints.max_width if constraints.max_width != float("inf") else 460.0
|
|
347
|
+
return Size(w, self.chart_height)
|
|
348
|
+
|
|
349
|
+
def on_mouse_move(self, event: MouseEvent) -> None:
|
|
350
|
+
found = -1
|
|
351
|
+
for i, br in enumerate(self._bar_rects):
|
|
352
|
+
if br.contains(event.x, event.y):
|
|
353
|
+
found = i
|
|
354
|
+
break
|
|
355
|
+
if found != self._hover_idx:
|
|
356
|
+
self._hover_idx = found
|
|
357
|
+
self.invalidate()
|
|
358
|
+
|
|
359
|
+
def on_mouse_leave(self) -> None:
|
|
360
|
+
super().on_mouse_leave()
|
|
361
|
+
self._hover_idx = -1
|
|
362
|
+
|
|
363
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
364
|
+
c = theme.colors
|
|
365
|
+
r = self.rect
|
|
366
|
+
top_pad = 36.0 if self.title else 14.0
|
|
367
|
+
if self.title:
|
|
368
|
+
tf = font_for_style(theme.font_family, theme.typography.title_medium)
|
|
369
|
+
draw_text_centered_y(canvas, self.title, r.x + 4.0, r.y + 14.0, tf, c.on_surface)
|
|
370
|
+
|
|
371
|
+
if not self.tasks:
|
|
372
|
+
return
|
|
373
|
+
|
|
374
|
+
lf = font_for_style(theme.font_family, theme.typography.label_medium)
|
|
375
|
+
sf = font_for_style(theme.font_family, theme.typography.label_small)
|
|
376
|
+
lbl_w = min(140.0, max(measure_text(lf, t[0]) for t in self.tasks) + 16.0)
|
|
377
|
+
plot = Rect(r.x + lbl_w, r.y + top_pad, max(40.0, r.width - lbl_w - 16.0), max(20.0, r.height - top_pad - 26.0))
|
|
378
|
+
|
|
379
|
+
t_min = min(t[1] for t in self.tasks)
|
|
380
|
+
t_max = max(t[2] for t in self.tasks)
|
|
381
|
+
span = max(1.0, t_max - t_min)
|
|
382
|
+
|
|
383
|
+
grid_p = skia.Paint(AntiAlias=True, Color=c.outline_variant.with_alpha(0.5).to_skia(), StrokeWidth=1.0)
|
|
384
|
+
for step in range(5):
|
|
385
|
+
frac = step / 4.0
|
|
386
|
+
gx = plot.x + frac * plot.width
|
|
387
|
+
canvas.drawLine(gx, plot.y, gx, plot.bottom, grid_p)
|
|
388
|
+
tl = f"{self.unit} {_format_num(t_min + frac * span)}"
|
|
389
|
+
draw_text_centered_y(canvas, tl, gx - measure_text(sf, tl) * 0.5, plot.bottom + 14.0, sf, c.on_surface_variant)
|
|
390
|
+
|
|
391
|
+
n = len(self.tasks)
|
|
392
|
+
slot_h = plot.height / n
|
|
393
|
+
bar_h = max(14.0, min(24.0, slot_h * 0.6))
|
|
394
|
+
self._bar_rects = []
|
|
395
|
+
|
|
396
|
+
for i, (name, st, en, prog) in enumerate(self.tasks):
|
|
397
|
+
bx = plot.x + ((st - t_min) / span) * plot.width
|
|
398
|
+
bw = max(12.0, ((en - st) / span) * plot.width)
|
|
399
|
+
by = plot.y + i * slot_h + (slot_h - bar_h) * 0.5
|
|
400
|
+
br = Rect(bx, by, bw, bar_h)
|
|
401
|
+
self._bar_rects.append(br)
|
|
402
|
+
|
|
403
|
+
draw_text_centered_y(canvas, name, plot.x - measure_text(lf, name) - 10.0, br.center_y, lf, c.on_surface)
|
|
404
|
+
|
|
405
|
+
is_hov = i == self._hover_idx
|
|
406
|
+
track_c = c.secondary_container if (self._hover_idx == -1 or is_hov) else c.secondary_container.with_alpha(0.5)
|
|
407
|
+
fill_c = c.primary if (self._hover_idx == -1 or is_hov) else c.primary.with_alpha(0.5)
|
|
408
|
+
|
|
409
|
+
rad = bar_h * 0.5
|
|
410
|
+
canvas.drawRRect(make_rrect(br, rad), skia.Paint(AntiAlias=True, Color=track_c.to_skia()))
|
|
411
|
+
if prog > 0.0:
|
|
412
|
+
canvas.save()
|
|
413
|
+
canvas.clipRRect(make_rrect(br, rad), doAntiAlias=True)
|
|
414
|
+
canvas.drawRect(
|
|
415
|
+
skia.Rect.MakeXYWH(br.x, br.y, br.width * prog, br.height),
|
|
416
|
+
skia.Paint(AntiAlias=True, Color=fill_c.to_skia()),
|
|
417
|
+
)
|
|
418
|
+
canvas.restore()
|
|
419
|
+
|
|
420
|
+
if 0 <= self._hover_idx < len(self._bar_rects):
|
|
421
|
+
br = self._bar_rects[self._hover_idx]
|
|
422
|
+
name, st, en, prog = self.tasks[self._hover_idx]
|
|
423
|
+
_draw_chart_tooltip(
|
|
424
|
+
canvas,
|
|
425
|
+
theme,
|
|
426
|
+
br.center_x,
|
|
427
|
+
br.y,
|
|
428
|
+
f"{name} · {self.unit} {_format_num(st)}→{_format_num(en)} ({int(round(prog * 100))}%)",
|
|
429
|
+
r,
|
|
430
|
+
)
|