feat(grid): right-align numeric result columns
This commit is contained in:
1 parent
66c768061a
commit
e2b35944ce
35 files changed
+1082
-109
No files matched your search
+29
-1
@@ -1,6 +1,7 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { test } from "vitest";
|
||||
import { fitCanvasText, resolveCanvasDataGridRowFill } from "../../apps/desktop/src/lib/dataGrid/canvasDataGridRenderer.ts";
|
||||
import { canvasDataGridActionReservedWidth, fitCanvasText, resolveCanvasCellTextLayout, resolveCanvasDataGridRowFill } from "../../apps/desktop/src/lib/dataGrid/canvasDataGridRenderer.ts";
|
||||
import { DATA_GRID_DARK_STRIPED_ROW_BG, DATA_GRID_LIGHT_STRIPED_ROW_BG, resolveDataGridPaintTheme } from "../../apps/desktop/src/lib/dataGrid/dataGridPaintTheme.ts";
|
||||
|
||||
function measureContext(charWidth = 1): CanvasRenderingContext2D {
|
||||
@@ -23,6 +24,33 @@ test("fitCanvasText truncates only when text exceeds the available cell width",
|
||||
assert.equal(fitCanvasText(ctx, "1234567890", 8), "12345...");
|
||||
});
|
||||
|
||||
test("fitCanvasText preserves the numeric suffix for right-aligned narrow cells", () => {
|
||||
const ctx = measureContext();
|
||||
|
||||
assert.equal(fitCanvasText(ctx, "1234567890", 8, "right"), "...67890");
|
||||
});
|
||||
|
||||
test("canvas text layout reserves hover actions only for right-aligned cells", () => {
|
||||
assert.deepEqual(resolveCanvasCellTextLayout({ drawX: 100, colWidth: 80, dpr: 1, isRightAlign: true, reservedWidth: 28 }), {
|
||||
textAnchorX: 140,
|
||||
maxWidth: 28,
|
||||
});
|
||||
assert.deepEqual(resolveCanvasCellTextLayout({ drawX: 100, colWidth: 80, dpr: 1, isRightAlign: false, reservedWidth: 28 }), {
|
||||
textAnchorX: 112,
|
||||
maxWidth: 56,
|
||||
});
|
||||
assert.equal(canvasDataGridActionReservedWidth(false), 28);
|
||||
assert.equal(canvasDataGridActionReservedWidth(true), 50);
|
||||
});
|
||||
|
||||
test("DataGrid forwards hover action reservation only for right-aligned canvas cells", () => {
|
||||
const source = readFileSync("apps/desktop/src/components/grid/DataGrid.vue", "utf8");
|
||||
|
||||
assert.match(source, /columnAligns\.value\[cell\.visibleColIdx\] !== "right"/);
|
||||
assert.match(source, /reservedWidth: canvasDataGridActionReservedWidth\(cell\.canQuickDownload\)/);
|
||||
assert.match(source, /rightAlignedActionCell: canvasRightAlignedActionCell\.value/);
|
||||
});
|
||||
|
||||
test("canvas row fill keeps frozen and scrolling regions on the same selection surface", () => {
|
||||
const theme = { cellActive: "active-blue", cellSelected: "selected-blue" };
|
||||
|
||||
|
||||
Reference in new issue
Block a user