table3 0.5.0__tar.gz → 0.6.0__tar.gz

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 (31) hide show
  1. {table3-0.5.0 → table3-0.6.0}/CHANGELOG.md +31 -0
  2. {table3-0.5.0/src/table3.egg-info → table3-0.6.0}/PKG-INFO +1 -1
  3. {table3-0.5.0 → table3-0.6.0}/docs/design.md +27 -9
  4. {table3-0.5.0 → table3-0.6.0}/docs/explorer.md +9 -1
  5. table3-0.6.0/src/table3/__version__.py +1 -0
  6. {table3-0.5.0 → table3-0.6.0}/src/table3/_explorer_js.py +137 -53
  7. {table3-0.5.0 → table3-0.6.0}/src/table3/_html.py +27 -23
  8. table3-0.6.0/src/table3/_pager.py +225 -0
  9. {table3-0.5.0 → table3-0.6.0/src/table3.egg-info}/PKG-INFO +1 -1
  10. {table3-0.5.0 → table3-0.6.0}/tests/test_explorer_browser.py +94 -7
  11. table3-0.6.0/tests/test_pager_browser.py +193 -0
  12. {table3-0.5.0 → table3-0.6.0}/tests/test_table3.py +11 -4
  13. table3-0.5.0/src/table3/__version__.py +0 -1
  14. table3-0.5.0/src/table3/_pager.py +0 -130
  15. table3-0.5.0/tests/test_pager_browser.py +0 -88
  16. {table3-0.5.0 → table3-0.6.0}/LICENSE +0 -0
  17. {table3-0.5.0 → table3-0.6.0}/MANIFEST.in +0 -0
  18. {table3-0.5.0 → table3-0.6.0}/README.md +0 -0
  19. {table3-0.5.0 → table3-0.6.0}/pyproject.toml +0 -0
  20. {table3-0.5.0 → table3-0.6.0}/setup.cfg +0 -0
  21. {table3-0.5.0 → table3-0.6.0}/src/table3/__init__.py +0 -0
  22. {table3-0.5.0 → table3-0.6.0}/src/table3/_explore.py +0 -0
  23. {table3-0.5.0 → table3-0.6.0}/src/table3/_format.py +0 -0
  24. {table3-0.5.0 → table3-0.6.0}/src/table3/_solveit.py +0 -0
  25. {table3-0.5.0 → table3-0.6.0}/src/table3/py.typed +0 -0
  26. {table3-0.5.0 → table3-0.6.0}/src/table3.egg-info/SOURCES.txt +0 -0
  27. {table3-0.5.0 → table3-0.6.0}/src/table3.egg-info/dependency_links.txt +0 -0
  28. {table3-0.5.0 → table3-0.6.0}/src/table3.egg-info/requires.txt +0 -0
  29. {table3-0.5.0 → table3-0.6.0}/src/table3.egg-info/top_level.txt +0 -0
  30. {table3-0.5.0 → table3-0.6.0}/tests/test_explore.py +0 -0
  31. {table3-0.5.0 → table3-0.6.0}/tests/test_solveit.py +0 -0
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0 — 2026-11-03
4
+
5
+ ### Changed
6
+
7
+ - The explorer's filters stay hidden until the new Filter button beside
8
+ Search is pressed, as in RStudio's viewer. Each column then shows a
9
+ compact `All`; clicking it opens that column's filter (from and to for
10
+ numbers and dates, contains for text, a pick-list for few values), and
11
+ once applied it reads as a label such as `10–50 ×`, where × clears it.
12
+ Turning Filter off clears every filter.
13
+ - The paged table lines text up on the left and numbers, dates and times
14
+ on the right, names and types with them, as `view()` does; before,
15
+ every column was on the right.
16
+ - The paged table's controls move to RStudio's places: ◂ and ▸ for the
17
+ columns before and after sit at the header's edges, the row and column
18
+ counts at the bottom left, and Previous / pages / Next at the bottom
19
+ right. When *n* cut the rows the counts say so plainly: "Rows 1–10 of
20
+ 1,000 previewed (52,341 total)", instead of "1–10 of 1,000 rows (first
21
+ 1,000 of 52,341)".
22
+
23
+ ## 0.5.1 — 2026-11-03
24
+
25
+ ### Fixed
26
+
27
+ - A paged table's Next button stays where it is from the first page to the
28
+ last, so it can be clicked over and over: the page links fill a fixed
29
+ number of fixed-width slots, each column keeps the width measured over
30
+ all rows, and blank rows pad a short last page. A control that can't act
31
+ is dimmed rather than disabled, so it keeps keyboard focus (pressing Enter
32
+ on Next walks every page).
33
+
3
34
  ## 0.5.0 — 2026-11-03
4
35
 
5
36
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: table3
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Paged, theme-aware tables in notebook output: shared by tidy3, tidy3a and stats3
5
5
  Author: Rigoberto Leyva Salmeron
6
6
  License-Expression: MIT
@@ -38,13 +38,24 @@ used it yet, so it is gone rather than deprecated.
38
38
  `pl.Config(float_precision=)`, unless `digits=` asks for significant
39
39
  digits (§2.1); values longer than 40 characters cut with
40
40
  "…", the full value on hover.
41
- - Ten rows a page (`page_size=`), Previous / page numbers / Next, and as many
42
- columns as fit the cell with `◂ columns` / `columns ▸` for the rest. Column
43
- groups are measured once over all *n* rows, so they don't shift between
44
- pages, and they are regrouped when the cell's width changes.
45
- - The footer counts rows and columns ("21–30 of 344 rows | 10–12 of 12
46
- columns") and says when *n* cut the rows ("1–10 of 100 rows (first 100 of
47
- 52,341)").
41
+ - Text, booleans and the rest line up on the left, numbers, dates and times
42
+ on the right, with their names and types; `view()` lines them up the
43
+ same way.
44
+ - Ten rows a page (`page_size=`), and as many columns as fit the cell, with
45
+ ◂ and ▸ at the header's left and right edges for the columns before and
46
+ after. Column groups are measured once over all *n* rows, so they don't
47
+ shift between pages, and they are regrouped when the cell's width
48
+ changes.
49
+ - Under the table, as in RStudio's paged table: the counts on the left,
50
+ "Rows 21–30 of 344 | Columns 10–12 of 12", and Previous / page numbers /
51
+ Next on the right. When *n* cut the rows the counts say what was
52
+ previewed of how many: "Rows 1–10 of 100 previewed (52,341 total)", or
53
+ "(total not counted)".
54
+ - Nothing moves from page to page: each column is pinned at its measured
55
+ width, a short last page is padded with blank rows, the pager is
56
+ anchored at the right, past seven pages its links fill seven
57
+ fixed-width slots (`1 … 4 5 6 … 21`, or five pages and `…` near an end),
58
+ and the column arrows keep their place, dimmed at either end.
48
59
 
49
60
  ### 2.1 Float digits
50
61
 
@@ -109,11 +120,18 @@ prints its frames as this table by returning `table3.html(self, n=…)` from
109
120
 
110
121
  | Package | Change | Dependency |
111
122
  |---|---|---|
112
- | tidy3 | `TidyFrame._repr_html_` returns `table3.html(self, n=preview_max, page_size=preview_rows, digits=preview_digits)` from `options()`; `TidyFrame.__table3__` from `_preview_parts` (respects `preview_count`), caption `TidyFrame (preview groups=[…])`. No verb: every frame in a cell prints this way | `table3>=0.3,<0.4` |
123
+ | tidy3 | `TidyFrame._repr_html_` returns `table3.html(self, n=preview_max, page_size=preview_rows, digits=preview_digits)` from `options()`; `TidyFrame.__table3__` from `_preview_parts` (respects `preview_count`), caption `TidyFrame (preview groups=[…])`. No verb: every frame in a cell prints this way | `table3>=0.5.1,<1` |
113
124
  | stats3 | Result tables are polars, so `table3.show(table)` works as is; its own result objects may return `table3.html` from `_repr_html_` | optional at first |
114
- | tidy3a | `TidyArray.__table3__` through `as_table` | extra `tidy3a[view]` (tidy3a has no polars) |
125
+ | tidy3a | `TidyArray.__table3__` through `as_table` | extra `tidy3a[table3]`, `table3>=0.5.1,<1` (tidy3a has no polars) |
115
126
  | plot3, tidy3syntax | none | none |
116
127
 
128
+ Callers cap table3 below 1.0, not below its next minor version, so a new
129
+ table3 reaches them without a release of their own. table3 keeps `html()`,
130
+ `show()`, `view()`, their keywords and the `__table3__` hook working
131
+ through its 0.x releases; anything it removes is deprecated first, and a
132
+ break that can't be is 1.0. A caller raises its floor when it needs a
133
+ table3 fix, so upgrading the caller pulls the fix in.
134
+
117
135
  None of them exports `show` or `view` bare, so `from … import *` in any order
118
136
  leaves the names alone.
119
137
 
@@ -81,11 +81,19 @@ only bare `view` in the family; tidy3a and stats3 document `table3.view(x)`.
81
81
 
82
82
  - **Header**, pinned: name, type (`i64`, `str`), and a sort arrow; clicking
83
83
  cycles ascending, descending, off. One sort column at a time, as R.
84
- - **Filter row** under the header, one control per column by type:
84
+ - **Filters**, as RStudio shows them: hidden until the **Filter** button
85
+ beside the search box is pressed, then a compact `All` under each
86
+ column. Clicking it opens that column's editor in its place:
85
87
  - numbers and dates: two boxes, from and to, either blank;
86
88
  - strings: contains, case-insensitive;
87
89
  - strings with at most 50 distinct values, booleans and categoricals: a
88
90
  pick-list of their values, with `null` as one choice.
91
+ Enter, Escape or a click elsewhere closes the editor, and a column with a
92
+ filter then reads it in words, `10–50 ×`, `≥ 2008 ×`, `Gentoo ×` or
93
+ `"item 2" ×`, where × clears it. Turning Filter off clears every filter,
94
+ so no row is ever filtered out of sight. The editor is the chip's height,
95
+ so opening it moves nothing. (0.5.1 and before showed every column's
96
+ boxes at once: two inputs under each number column, mostly unused.)
89
97
  - **Search box** above: rows where any cell's text contains it.
90
98
  - **Row numbers** on the left: the row's place in *data*, kept through sorts
91
99
  and filters, as R shows them.
@@ -0,0 +1 @@
1
+ __version__ = "0.6.0"
@@ -43,7 +43,7 @@ EXPLORER_JS = r"""
43
43
 
44
44
  // Column widths in characters, from the widest text up to the cut.
45
45
  var widths = cols.map(function (col, c) {
46
- // Numbers and dates need room for their two filter boxes, from and to.
46
+ // Numbers and dates need room for their filter's from and to boxes.
47
47
  var w = Math.max(col.name.length + 2, col.type.length, NUMERIC[col.kind] ? 12 : 6);
48
48
  for (var r = 0; r < rows.length && w < CUT; r++) w = Math.max(w, text[r][c].length);
49
49
  return Math.min(w, CUT);
@@ -68,10 +68,17 @@ EXPLORER_JS = r"""
68
68
  var INPUT = "font:inherit;color:inherit;background:transparent;border:1px solid " + GREY +
69
69
  ";border-radius:4px;padding:1px 6px;box-sizing:border-box";
70
70
  search.style.cssText = INPUT + ";width:16em";
71
+ // Filters stay out of sight until asked for, as in RStudio's viewer.
72
+ var filterBtn = document.createElement("button");
73
+ filterBtn.type = "button"; filterBtn.textContent = "Filter";
74
+ filterBtn.dataset.filterToggle = "";
75
+ filterBtn.setAttribute("aria-pressed", "false");
76
+ filterBtn.title = "Filter by column";
77
+ filterBtn.style.cssText = INPUT + ";cursor:pointer";
71
78
  var status = document.createElement("span");
72
79
  status.dataset.status = "";
73
80
  status.style.cssText = "opacity:.65";
74
- bar.appendChild(search); bar.appendChild(status);
81
+ bar.appendChild(search); bar.appendChild(filterBtn); bar.appendChild(status);
75
82
  root.appendChild(bar);
76
83
 
77
84
  var box = document.createElement("div");
@@ -90,17 +97,24 @@ EXPLORER_JS = r"""
90
97
  var sortCol = -1, sortDir = 0, filters = cols.map(function () { return null; });
91
98
  var order = [], query = "";
92
99
 
93
- // Header: names with sort arrows, types, filters.
100
+ // Header: names with sort arrows, types, and, under the Filter button, a
101
+ // filter per column.
94
102
  var nameRow = document.createElement("tr"), typeRow = document.createElement("tr"),
95
103
  filterRow = document.createElement("tr");
104
+ var RULE = "1px solid " + GREY, typeCells = [];
105
+ var CHIP = "font:inherit;color:inherit;background:transparent;border:1px solid " + GREY +
106
+ ";border-radius:9px;padding:0 6px;line-height:16px;cursor:pointer;white-space:pre;" +
107
+ "overflow:hidden;text-overflow:ellipsis;min-width:0;max-width:100%";
96
108
  function corner(tr, html) {
97
109
  var td = document.createElement("td");
98
110
  td.style.cssText = NUM_STYLE + ";z-index:3";
99
111
  td.innerHTML = html;
100
112
  tr.appendChild(td);
113
+ return td;
101
114
  }
102
- corner(nameRow, ""); corner(typeRow, ""); corner(filterRow, "");
103
- var arrows = [];
115
+ corner(nameRow, ""); typeCells.push(corner(typeRow, ""));
116
+ corner(filterRow, "").style.borderBottom = RULE;
117
+ var arrows = [], controls = [];
104
118
  cols.forEach(function (col, c) {
105
119
  var td = document.createElement("td");
106
120
  td.style.cssText = cellStyle(c) + ";cursor:pointer;user-select:none";
@@ -124,69 +138,139 @@ EXPLORER_JS = r"""
124
138
  ttd.style.cssText = cellStyle(c) + ";opacity:.55";
125
139
  ttd.textContent = col.type;
126
140
  typeRow.appendChild(ttd);
141
+ typeCells.push(ttd);
127
142
 
128
143
  var ftd = document.createElement("td");
129
- ftd.style.cssText = cellStyle(c) + ";height:auto;padding:2px 4px 4px 4px;border-bottom:1px solid " + GREY;
130
- ftd.appendChild(filterControl(col, c));
144
+ ftd.style.cssText = cellStyle(c) + ";height:auto;padding:2px 4px 4px 4px;" +
145
+ "overflow:visible;border-bottom:" + RULE;
146
+ var control = filterControl(col, c);
147
+ ftd.appendChild(control.el);
148
+ controls.push(control);
131
149
  filterRow.appendChild(ftd);
132
150
  });
133
151
  thead.appendChild(nameRow); thead.appendChild(typeRow); thead.appendChild(filterRow);
134
152
 
153
+ function showFilters(on) {
154
+ filterBtn.setAttribute("aria-pressed", String(on));
155
+ filterBtn.style.borderColor = on ? "currentColor" : GREY;
156
+ filterRow.style.display = on ? "" : "none";
157
+ typeCells.forEach(function (td) { td.style.borderBottom = on ? "0" : RULE; });
158
+ }
159
+ showFilters(false);
160
+ // Hiding the filters clears them, so no row is ever filtered out of sight.
161
+ filterBtn.onclick = function () {
162
+ var on = filterBtn.getAttribute("aria-pressed") !== "true";
163
+ if (!on) controls.forEach(function (k) { k.clear(); });
164
+ showFilters(on);
165
+ if (!on) apply();
166
+ };
167
+
168
+ // One column's filter: a chip that reads "All", or the filter in words
169
+ // ("10–50", "Gentoo") with × to clear it. Clicking the chip swaps it for
170
+ // the column's editor until Enter, Escape or a click elsewhere.
135
171
  function filterControl(col, c) {
136
- var timer = null;
137
- function later(fn) { clearTimeout(timer); timer = setTimeout(fn, 150); }
172
+ var el = document.createElement("div");
173
+ // The chip sits where the column's values do: right for numbers and dates.
174
+ el.style.cssText = "display:flex;align-items:center;gap:2px;min-width:0;height:18px;" +
175
+ "justify-content:" + (NUMERIC[col.kind] ? "flex-end" : "flex-start");
176
+ var chip = document.createElement("button");
177
+ chip.type = "button"; chip.dataset.chip = col.name;
178
+ chip.style.cssText = CHIP + ";flex:0 1 auto";
179
+ var clearBtn = document.createElement("button");
180
+ clearBtn.type = "button"; clearBtn.dataset.clear = col.name; clearBtn.textContent = "×";
181
+ clearBtn.title = "Clear the filter on " + col.name;
182
+ clearBtn.style.cssText = CHIP + ";flex:none;padding:0 4px";
183
+ var editor = document.createElement("div");
184
+ editor.style.cssText = "display:none;gap:2px;width:100%;min-width:0";
185
+ el.appendChild(chip); el.appendChild(clearBtn); el.appendChild(editor);
186
+
187
+ // The editor's boxes are the chip's height, so opening one moves nothing.
188
+ var SLIM = "height:18px;padding:0 4px;line-height:16px";
189
+ var words = "", timer = null, inputs = [], commit;
190
+ function later() { clearTimeout(timer); timer = setTimeout(function () { commit(); apply(); }, 150); }
191
+ function input(placeholder, width) {
192
+ var inp = document.createElement("input");
193
+ inp.placeholder = placeholder;
194
+ inp.style.cssText = INPUT + ";width:" + width + ";min-width:0;" + SLIM;
195
+ inp.oninput = later;
196
+ editor.appendChild(inp); inputs.push(inp);
197
+ return inp;
198
+ }
199
+
138
200
  if (col.kind === "choice" || col.kind === "bool") {
139
201
  var sel = document.createElement("select");
140
- sel.style.cssText = INPUT + ";width:100%;" + SOLID;
202
+ sel.style.cssText = INPUT + ";width:100%;" + SLIM + ";" + SOLID;
141
203
  var values = col.kind === "bool" ? [true, false] : col.choices;
142
- var opts = [["", "All"]].concat(values.map(function (v, i) { return ["v" + i, String(v)]; }))
143
- .concat([["null", "null"]]);
144
- opts.forEach(function (o) {
145
- var op = document.createElement("option");
146
- op.value = o[0]; op.textContent = o[1];
147
- sel.appendChild(op);
148
- });
149
- sel.onchange = function () {
204
+ [["", "All"]].concat(values.map(function (v, i) { return ["v" + i, String(v)]; }))
205
+ .concat([["null", "null"]]).forEach(function (o) {
206
+ var op = document.createElement("option");
207
+ op.value = o[0]; op.textContent = o[1];
208
+ sel.appendChild(op);
209
+ });
210
+ editor.appendChild(sel); inputs.push(sel);
211
+ commit = function () {
150
212
  var v = sel.value;
151
213
  filters[c] = v === "" ? null : v === "null" ? { is: null } : { is: values[+v.slice(1)] };
152
- apply();
214
+ words = sel.options[sel.selectedIndex].textContent;
215
+ };
216
+ sel.onchange = function () { close(); chip.focus(); };
217
+ } else if (NUMERIC[col.kind]) {
218
+ var lo = input("from", "50%"), hi = input("to", "50%");
219
+ commit = function () {
220
+ var a = lo.value.trim(), b = hi.value.trim(), fa = a || null, fb = b || null;
221
+ if (col.kind === "number") {
222
+ fa = a === "" ? null : parseFloat(a); fb = b === "" ? null : parseFloat(b);
223
+ if (fa !== null && isNaN(fa)) { fa = null; a = ""; }
224
+ if (fb !== null && isNaN(fb)) { fb = null; b = ""; }
225
+ }
226
+ filters[c] = fa === null && fb === null ? null : { from: fa, to: fb };
227
+ words = a && b ? (a === b ? a : a + "–" + b) : a ? "≥ " + a : "≤ " + b;
228
+ };
229
+ } else {
230
+ var has = input("contains", "100%");
231
+ commit = function () {
232
+ var q = has.value.trim();
233
+ filters[c] = q ? { has: q.toLowerCase() } : null;
234
+ words = '"' + q + '"';
153
235
  };
154
- return sel;
155
236
  }
156
- if (NUMERIC[col.kind]) {
157
- var wrap = document.createElement("div");
158
- wrap.style.cssText = "display:flex;gap:2px";
159
- var lo = document.createElement("input"), hi = document.createElement("input");
160
- [lo, hi].forEach(function (inp, i) {
161
- inp.placeholder = i ? "to" : "from";
162
- inp.style.cssText = INPUT + ";width:50%;min-width:0";
163
- inp.oninput = function () {
164
- later(function () {
165
- var a = lo.value.trim(), b = hi.value.trim();
166
- if (col.kind === "number") {
167
- a = a === "" ? null : parseFloat(a); b = b === "" ? null : parseFloat(b);
168
- if (a !== null && isNaN(a)) a = null;
169
- if (b !== null && isNaN(b)) b = null;
170
- } else { a = a || null; b = b || null; }
171
- filters[c] = a === null && b === null ? null : { from: a, to: b };
172
- apply();
173
- });
174
- };
175
- wrap.appendChild(inp);
176
- });
177
- return wrap;
237
+
238
+ function show() {
239
+ var on = filters[c] !== null;
240
+ chip.textContent = on ? words : "All";
241
+ chip.title = on ? col.name + ": " + words + " (click to change)" : "Filter " + col.name;
242
+ chip.style.opacity = on ? "1" : ".55";
243
+ clearBtn.style.display = on ? "" : "none";
178
244
  }
179
- var inp = document.createElement("input");
180
- inp.placeholder = "contains";
181
- inp.style.cssText = INPUT + ";width:100%";
182
- inp.oninput = function () {
183
- later(function () {
184
- var q = inp.value.trim().toLowerCase();
185
- filters[c] = q ? { has: q } : null;
186
- apply();
187
- });
188
- };
189
- return inp;
245
+ function open() {
246
+ chip.style.display = clearBtn.style.display = "none";
247
+ editor.style.display = "flex";
248
+ inputs[0].focus();
249
+ }
250
+ function close() {
251
+ if (editor.style.display === "none") return;
252
+ clearTimeout(timer);
253
+ commit(); apply();
254
+ editor.style.display = "none"; chip.style.display = "";
255
+ show();
256
+ }
257
+ function clear() {
258
+ clearTimeout(timer);
259
+ inputs.forEach(function (inp) { inp.value = ""; });
260
+ commit();
261
+ editor.style.display = "none"; chip.style.display = "";
262
+ show();
263
+ }
264
+ chip.onclick = open;
265
+ clearBtn.onclick = function () { clear(); apply(); chip.focus(); };
266
+ editor.addEventListener("keydown", function (e) {
267
+ if (e.key === "Enter" || e.key === "Escape") { e.preventDefault(); close(); chip.focus(); }
268
+ });
269
+ editor.addEventListener("focusout", function (e) {
270
+ if (!editor.contains(e.relatedTarget)) close();
271
+ });
272
+ show();
273
+ return { el: el, clear: clear };
190
274
  }
191
275
 
192
276
  function passes(r) {
@@ -29,7 +29,7 @@ MONO = "12px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace"
29
29
  RULE = "border-bottom:1px solid rgba(127,127,127,.45)"
30
30
  # The font is set once on the table: a cell's style repeats on up to
31
31
  # n x columns cells, and the font list is half its length.
32
- CELL = "font:inherit;padding:3px 10px;text-align:right;white-space:pre;border:0"
32
+ CELL = "font:inherit;padding:3px 10px;white-space:pre;border:0"
33
33
  HEAD_BG = (
34
34
  "background-color:var(--vscode-editor-background,"
35
35
  "var(--jp-layout-color0,Canvas));"
@@ -51,12 +51,9 @@ def rows_label(shown: int, total: int | None) -> str:
51
51
  return f"showing first {shown:,} of {of} rows"
52
52
 
53
53
 
54
- def pages_label(shown: int, total: int | None) -> str:
55
- """What the pager counts rows of: "344 rows", or the first 100 of more."""
56
- if total is not None and total <= shown:
57
- return _plural(shown)
58
- of = "more" if total is None else f"{total:,}"
59
- return f"{_plural(shown)} (first {shown:,} of {of})"
54
+ def right_aligned(dtype: pl.DataType) -> bool:
55
+ """Numbers, dates and times line up on the right; text and the rest on the left."""
56
+ return dtype.is_numeric() or dtype.is_temporal()
60
57
 
61
58
 
62
59
  def table_html(
@@ -71,18 +68,20 @@ def table_html(
71
68
  ) -> str:
72
69
  """*df* is the first rows; *total* the whole row count, None if not counted."""
73
70
 
74
- def _tr(cells: list[str], style: str, row_style: str = "") -> str:
75
- tds = "".join(f"<td style='{style}'>{c}</td>" for c in cells)
71
+ align = [
72
+ f"{CELL};text-align:{'right' if right_aligned(t) else 'left'}" for t in df.dtypes
73
+ ]
74
+
75
+ def _tr(cells: list[str], extra: str = "", row_style: str = "") -> str:
76
+ tds = "".join(f"<td style='{a}{extra}'>{c}</td>" for a, c in zip(align, cells))
76
77
  return f"<tr style='{row_style}'>{tds}</tr>"
77
78
 
78
- head = _tr([f"<b>{escape(c)}</b>" for c in df.columns], f"{CELL};{RULE}")
79
- types = _tr(
80
- [escape(dtype_short(t)) for t in df.dtypes], f"{CELL};opacity:.55;{RULE}"
81
- )
79
+ head = _tr([f"<b>{escape(c)}</b>" for c in df.columns], f";{RULE}")
80
+ types = _tr([escape(dtype_short(t)) for t in df.dtypes], f";opacity:.55;{RULE}")
82
81
  rows = display_rows(df, digits)
83
82
  written = rows[:page_size] if pages else rows
84
83
  body = [
85
- _tr([cell(v) for v in row], CELL, ZEBRA if i % 2 else "")
84
+ _tr([cell(v) for v in row], "", ZEBRA if i % 2 else "")
86
85
  for i, row in enumerate(written)
87
86
  ]
88
87
 
@@ -99,14 +98,21 @@ def table_html(
99
98
  )
100
99
 
101
100
  root = "<div>"
102
- pager = script = data = ""
101
+ foot = f"<small data-foot style='{small}'>{rows_label(len(written), total)}</small>"
102
+ script = data = ""
103
103
  if pages:
104
104
  uid = f"table3-{uuid.uuid4().hex}"
105
- label = _html.escape(pages_label(df.height, total))
106
- root = f"<div id='{uid}' data-page-size='{page_size}' data-label='{label}'>"
107
- pager = (
108
- f"<div data-pager style='font:{MONO};margin:4px 0 0 0;display:none'>"
109
- "</div>"
105
+ counted = "" if total is None else str(total)
106
+ root = (
107
+ f"<div id='{uid}' data-page-size='{page_size}' data-total='{counted}'>"
108
+ )
109
+ # The row and column counts on the left, the pager on the right.
110
+ foot = (
111
+ "<div data-bar style='display:flex;flex-wrap:wrap;align-items:center;"
112
+ "gap:4px 12px;margin:2px 0 0 0'>"
113
+ + foot
114
+ + f"<div data-pager style='font:{MONO};margin-left:auto;display:none'>"
115
+ "</div></div>"
110
116
  )
111
117
  script = f"<script>{PAGER_JS.replace('__ID__', uid)}</script>"
112
118
  if len(written) < len(rows):
@@ -125,9 +131,7 @@ def table_html(
125
131
  + "</thead><tbody>"
126
132
  + "".join(body)
127
133
  + "</tbody></table></div>"
128
- f"<small data-foot style='{small}'>"
129
- f"{rows_label(len(written), total)}</small>"
130
- + pager
134
+ + foot
131
135
  + data
132
136
  + "</div>"
133
137
  + script