@malloy-publisher/sdk 0.9.14 → 0.9.16
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.
- package/dist/RenderedResult-5hOs5XnV.cjs.js +171 -0
- package/dist/RenderedResult-DxmHGZNQ.es.js +671 -0
- package/dist/{ServerProvider-BV7IoDMR.es.js → ServerProvider-D7neZcTk.es.js} +283 -265
- package/dist/ServerProvider-e2369oom.cjs.js +1 -0
- package/dist/builder/index.cjs.js +80 -79
- package/dist/builder/index.es.js +7732 -6717
- package/dist/builder-entry.d.ts +1 -1
- package/dist/client/api.d.ts +31 -7
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +51 -1
- package/dist/components/Dashboard/DashboardTile.d.ts +7 -2
- package/dist/components/Dashboard/DashboardView.d.ts +9 -2
- package/dist/components/Dashboard/index.d.ts +1 -1
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
- package/dist/components/Dashboard/useStuck.d.ts +18 -12
- package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
- package/dist/components/RenderedResult/ResultContainer.d.ts +18 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +7 -1
- package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
- package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
- package/dist/components/RenderedResult/resultSizing.d.ts +47 -6
- package/dist/components/Report/Report.d.ts +7 -1
- package/dist/components/Report/ReportPage.d.ts +7 -0
- package/dist/components/Report/layoutRules.d.ts +45 -0
- package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
- package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
- package/dist/components/ReportBuilder/BuilderGrid.d.ts +15 -4
- package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
- package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
- package/dist/components/ReportBuilder/EditorSurface.d.ts +10 -1
- package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
- package/dist/components/ReportBuilder/TileFrame.d.ts +54 -10
- package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
- package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
- package/dist/components/ReportBuilder/catalog.d.ts +23 -0
- package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
- package/dist/components/ReportBuilder/controls.d.ts +2 -2
- package/dist/components/ReportBuilder/document.d.ts +53 -5
- package/dist/components/ReportBuilder/imports.d.ts +7 -0
- package/dist/components/ReportBuilder/placement.d.ts +121 -0
- package/dist/components/ReportBuilder/preview.d.ts +59 -10
- package/dist/components/ReportBuilder/sortable.d.ts +12 -1
- package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
- package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
- package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
- package/dist/components/ReportBuilder/useTileReorder.d.ts +30 -3
- package/dist/index.cjs.js +7 -7
- package/dist/index.es.js +3349 -3307
- package/dist/text/index.es.js +1 -1
- package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
- package/dist/theme/classes.d.ts +1 -1
- package/dist/theme/resolveTheme.d.ts +15 -0
- package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-CaYP_OYG.es.js} +6353 -6047
- package/dist/useCompiledDocument-zYEfLogf.cjs.js +142 -0
- package/dist/utils/blankQuoted.d.ts +15 -0
- package/package.json +1 -1
- package/src/builder-entry.ts +1 -0
- package/src/components/Dashboard/DashboardGrid.tsx +129 -10
- package/src/components/Dashboard/DashboardTile.tsx +15 -1
- package/src/components/Dashboard/DashboardView.tsx +64 -10
- package/src/components/Dashboard/TileCard.tsx +6 -0
- package/src/components/Dashboard/index.ts +1 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
- package/src/components/Dashboard/tileHeight.spec.ts +72 -0
- package/src/components/Dashboard/useStuck.ts +76 -28
- package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
- package/src/components/Package/NewDocumentDialog.tsx +10 -11
- package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
- package/src/components/RenderedResult/RenderedResult.tsx +39 -6
- package/src/components/RenderedResult/ResultContainer.tsx +99 -10
- package/src/components/RenderedResult/ResultPanel.tsx +25 -1
- package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
- package/src/components/RenderedResult/chartPresentation.ts +166 -0
- package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
- package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
- package/src/components/RenderedResult/resultSizing.ts +71 -11
- package/src/components/Report/Report.spec.tsx +19 -0
- package/src/components/Report/Report.tsx +8 -1
- package/src/components/Report/ReportPage.tsx +13 -1
- package/src/components/Report/layoutRules.spec.ts +43 -3
- package/src/components/Report/layoutRules.ts +70 -0
- package/src/components/Report/tileOverflow.spec.tsx +162 -0
- package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
- package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
- package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
- package/src/components/ReportBuilder/BuilderBar.tsx +5 -1
- package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -1
- package/src/components/ReportBuilder/BuilderGrid.tsx +142 -35
- package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
- package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
- package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
- package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
- package/src/components/ReportBuilder/EditorSurface.tsx +101 -20
- package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
- package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
- package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
- package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
- package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +242 -2
- package/src/components/ReportBuilder/ReportBuilder.tsx +161 -27
- package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
- package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
- package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
- package/src/components/ReportBuilder/ReportEditor.tsx +13 -0
- package/src/components/ReportBuilder/TileFrame.tsx +366 -170
- package/src/components/ReportBuilder/TileMenu.tsx +259 -20
- package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
- package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
- package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
- package/src/components/ReportBuilder/builderControls.ts +34 -0
- package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
- package/src/components/ReportBuilder/catalog.ts +90 -37
- package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
- package/src/components/ReportBuilder/chartLine.ts +80 -2
- package/src/components/ReportBuilder/controls.ts +4 -3
- package/src/components/ReportBuilder/document.ts +65 -7
- package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
- package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
- package/src/components/ReportBuilder/imports.ts +1 -1
- package/src/components/ReportBuilder/invariants.spec.ts +18 -10
- package/src/components/ReportBuilder/layout.ts +3 -0
- package/src/components/ReportBuilder/placement.spec.ts +401 -0
- package/src/components/ReportBuilder/placement.ts +416 -0
- package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
- package/src/components/ReportBuilder/preview.spec.ts +151 -11
- package/src/components/ReportBuilder/preview.ts +203 -40
- package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
- package/src/components/ReportBuilder/readDocument.spec.ts +53 -19
- package/src/components/ReportBuilder/readDocument.ts +197 -29
- package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
- package/src/components/ReportBuilder/sortable.tsx +30 -2
- package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
- package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
- package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
- package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -58
- package/src/components/ReportBuilder/spliceDocument.ts +139 -91
- package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
- package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
- package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
- package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
- package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
- package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
- package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
- package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
- package/src/components/ReportBuilder/useTileEditing.ts +16 -3
- package/src/components/ReportBuilder/useTileReorder.ts +143 -6
- package/src/components/given/FilterButton.spec.tsx +27 -11
- package/src/components/given/FilterButton.tsx +19 -6
- package/src/theme/classes.ts +1 -1
- package/src/theme/resolveTheme.spec.ts +72 -1
- package/src/theme/resolveTheme.ts +43 -0
- package/src/utils/blankQuoted.spec.ts +50 -0
- package/src/utils/blankQuoted.ts +32 -0
- package/src/utils/malloyText.ts +2 -1
- package/dist/RenderedResult-DnBtf-cI.es.js +0 -593
- package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
- package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
- package/dist/components/ReportBuilder/useTileResize.d.ts +0 -32
- package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
- package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
- package/src/components/ReportBuilder/useTileResize.ts +0 -133
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import type { DashboardTile, QueryTile } from "./document";
|
|
6
|
+
import {
|
|
7
|
+
cellAt,
|
|
8
|
+
dropAt,
|
|
9
|
+
flowTiles,
|
|
10
|
+
hasGaps,
|
|
11
|
+
holdChartRows,
|
|
12
|
+
minRowsOf,
|
|
13
|
+
pack,
|
|
14
|
+
placeAtEnd,
|
|
15
|
+
inReadingOrder,
|
|
16
|
+
placeWhereDrawn,
|
|
17
|
+
settle,
|
|
18
|
+
stepPlaced,
|
|
19
|
+
trackWidth,
|
|
20
|
+
} from "./placement";
|
|
21
|
+
|
|
22
|
+
const tile = (name: string, layout: Partial<QueryTile> = {}): QueryTile => ({
|
|
23
|
+
name,
|
|
24
|
+
source: "a",
|
|
25
|
+
declaration: { kind: "inline" },
|
|
26
|
+
...layout,
|
|
27
|
+
});
|
|
28
|
+
const where = (tiles: DashboardTile[]) =>
|
|
29
|
+
tiles.map(({ name, row, col, colspan, rowspan }) => ({
|
|
30
|
+
name,
|
|
31
|
+
row,
|
|
32
|
+
col,
|
|
33
|
+
colspan,
|
|
34
|
+
rowspan,
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
describe("settle", () => {
|
|
38
|
+
it("pushes a tile the moved one now covers straight down", () => {
|
|
39
|
+
const tiles = [
|
|
40
|
+
tile("a", { row: 1, col: 1, colspan: 6, rowspan: 4 }),
|
|
41
|
+
tile("b", { row: 1, col: 4, colspan: 6, rowspan: 3 }),
|
|
42
|
+
];
|
|
43
|
+
expect(where(settle(tiles, 12, 1))).toEqual([
|
|
44
|
+
{ name: "a", row: 4, col: 1, colspan: 6, rowspan: 4 },
|
|
45
|
+
{ name: "b", row: 1, col: 4, colspan: 6, rowspan: 3 },
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("pushes in a chain, top to bottom", () => {
|
|
50
|
+
const tiles = [
|
|
51
|
+
tile("a", { row: 1, col: 1, colspan: 12, rowspan: 2 }),
|
|
52
|
+
tile("b", { row: 3, col: 1, colspan: 12, rowspan: 2 }),
|
|
53
|
+
tile("big", { row: 1, col: 1, colspan: 12, rowspan: 3 }),
|
|
54
|
+
];
|
|
55
|
+
expect(where(settle(tiles, 12, 2)).map((t) => [t.name, t.row])).toEqual([
|
|
56
|
+
["a", 4],
|
|
57
|
+
["b", 6],
|
|
58
|
+
["big", 1],
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("leaves empty cells empty: nothing is pulled up", () => {
|
|
63
|
+
const tiles = [
|
|
64
|
+
tile("a", { row: 1, col: 1, colspan: 6, rowspan: 2 }),
|
|
65
|
+
tile("b", { row: 9, col: 1, colspan: 6, rowspan: 2 }),
|
|
66
|
+
];
|
|
67
|
+
expect(settle(tiles, 12, 0)[1].row).toBe(9);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("pulls a tile hanging off the right edge back onto the grid", () => {
|
|
71
|
+
expect(
|
|
72
|
+
settle([tile("a", { row: 1, col: 10, colspan: 6 })], 12, 0)[0].col,
|
|
73
|
+
).toBe(7);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("counts a tile with no rowspan at its kind's default rows", () => {
|
|
77
|
+
const tiles = [
|
|
78
|
+
tile("a", { row: 1, col: 1, colspan: 6 }),
|
|
79
|
+
tile("b", { row: 5, col: 1, colspan: 6, rowspan: 2 }),
|
|
80
|
+
];
|
|
81
|
+
// a is 5 rows by default, so b at row 5 is covered and goes to row 6.
|
|
82
|
+
expect(settle(tiles, 12, 0)[1].row).toBe(6);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("leaves a tile that is not placed for the grid to place", () => {
|
|
86
|
+
const tiles = [tile("a", { row: 1, col: 1 }), tile("free")];
|
|
87
|
+
expect(settle(tiles, 12, 0)[1]).toEqual(tile("free"));
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("cellAt", () => {
|
|
92
|
+
const track = trackWidth(1200 - 0, 12);
|
|
93
|
+
it("snaps a corner to the nearest row and column", () => {
|
|
94
|
+
expect(cellAt(0, 0, 6, 12, track)).toEqual({ row: 1, col: 1 });
|
|
95
|
+
expect(cellAt(3 * (track + 16) + 10, 2 * 96 - 20, 6, 12, track)).toEqual({
|
|
96
|
+
row: 3,
|
|
97
|
+
col: 4,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("keeps a tile on the grid at its edges", () => {
|
|
102
|
+
expect(cellAt(-500, -500, 6, 12, track)).toEqual({ row: 1, col: 1 });
|
|
103
|
+
expect(cellAt(5000, 0, 6, 12, track)).toEqual({ row: 1, col: 7 });
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("placeWhereDrawn", () => {
|
|
108
|
+
it("reads each tile's row, column, width and height off where it is drawn", () => {
|
|
109
|
+
const track = trackWidth(1200, 12);
|
|
110
|
+
const step = track + 16;
|
|
111
|
+
const tiles = [
|
|
112
|
+
tile("kpis", { colspan: 12, break: true }),
|
|
113
|
+
tile("trend"),
|
|
114
|
+
tile("map", { colspan: 6 }),
|
|
115
|
+
];
|
|
116
|
+
const boxes = [
|
|
117
|
+
{ top: 0, left: 0, width: 1200, height: 272 },
|
|
118
|
+
{ top: 288, left: 0, width: 6 * step - 16, height: 492 },
|
|
119
|
+
{ top: 288, left: 6 * step, width: 6 * step - 16, height: 492 },
|
|
120
|
+
];
|
|
121
|
+
expect(where(placeWhereDrawn(tiles, boxes, 12, track))).toEqual([
|
|
122
|
+
{ name: "kpis", row: 1, col: 1, colspan: 12, rowspan: 3 },
|
|
123
|
+
{ name: "trend", row: 4, col: 1, colspan: 6, rowspan: 5 },
|
|
124
|
+
{ name: "map", row: 4, col: 7, colspan: 6, rowspan: 5 },
|
|
125
|
+
]);
|
|
126
|
+
// A row break means nothing once tiles are placed.
|
|
127
|
+
expect(placeWhereDrawn(tiles, boxes, 12, track)[0].break).toBeUndefined();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("inReadingOrder", () => {
|
|
132
|
+
it("orders placed tiles top to bottom, then left to right, unplaced last", () => {
|
|
133
|
+
const tiles = [
|
|
134
|
+
tile("free"),
|
|
135
|
+
tile("c", { row: 3, col: 1 }),
|
|
136
|
+
tile("b", { row: 1, col: 7 }),
|
|
137
|
+
tile("a", { row: 1, col: 1 }),
|
|
138
|
+
];
|
|
139
|
+
expect(inReadingOrder(tiles).map((t) => t.name)).toEqual([
|
|
140
|
+
"a",
|
|
141
|
+
"b",
|
|
142
|
+
"c",
|
|
143
|
+
"free",
|
|
144
|
+
]);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("dropAt", () => {
|
|
149
|
+
const tiles = () => [
|
|
150
|
+
tile("map", { row: 1, col: 7, colspan: 6, rowspan: 6 }),
|
|
151
|
+
tile("bar", { row: 1, col: 1, colspan: 6, rowspan: 3 }),
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
it("lands under a tile whose lower part it was dropped on", () => {
|
|
155
|
+
// Dropped at row 4, col 7: on the map's lower half, which starts at row 1.
|
|
156
|
+
expect(where(dropAt(tiles(), 1, { row: 4, col: 7 }, 12))).toEqual([
|
|
157
|
+
{ name: "map", row: 1, col: 7, colspan: 6, rowspan: 6 },
|
|
158
|
+
{ name: "bar", row: 7, col: 7, colspan: 6, rowspan: 3 },
|
|
159
|
+
]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("pushes a tile down when dropped at or above its top", () => {
|
|
163
|
+
expect(
|
|
164
|
+
where(dropAt(tiles(), 1, { row: 1, col: 7 }, 12)).map((t) => [
|
|
165
|
+
t.name,
|
|
166
|
+
t.row,
|
|
167
|
+
]),
|
|
168
|
+
).toEqual([
|
|
169
|
+
["map", 4],
|
|
170
|
+
["bar", 1],
|
|
171
|
+
]);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("placeAtEnd", () => {
|
|
176
|
+
it("puts a new tile under everything on a placed report, at the left", () => {
|
|
177
|
+
const tiles = [
|
|
178
|
+
tile("a", { row: 1, col: 1, colspan: 6, rowspan: 3 }),
|
|
179
|
+
tile("b", { row: 2, col: 7, colspan: 6, rowspan: 6 }),
|
|
180
|
+
tile("new", { colspan: 6 }),
|
|
181
|
+
];
|
|
182
|
+
expect(placeAtEnd(tiles, 2, 12)[2]).toMatchObject({ row: 8, col: 1 });
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("leaves a report that flows alone", () => {
|
|
186
|
+
const tiles = [tile("a", { colspan: 6 }), tile("new")];
|
|
187
|
+
expect(placeAtEnd(tiles, 1, 12)[1]).toEqual(tile("new"));
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe("dropAt, far below", () => {
|
|
192
|
+
it("lands no lower than right under the lowest other tile", () => {
|
|
193
|
+
const tiles = [
|
|
194
|
+
tile("a", { row: 1, col: 1, colspan: 6, rowspan: 3 }),
|
|
195
|
+
tile("b", { row: 1, col: 7, colspan: 6, rowspan: 3 }),
|
|
196
|
+
];
|
|
197
|
+
expect(dropAt(tiles, 1, { row: 40, col: 7 }, 12)[1].row).toBe(4);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe("pack", () => {
|
|
202
|
+
it("slides every tile up into the gaps above it, never sideways", () => {
|
|
203
|
+
const tiles = [
|
|
204
|
+
tile("a", { row: 1, col: 1, colspan: 6, rowspan: 3 }),
|
|
205
|
+
tile("b", { row: 7, col: 1, colspan: 6, rowspan: 2 }),
|
|
206
|
+
tile("c", { row: 5, col: 7, colspan: 6, rowspan: 4 }),
|
|
207
|
+
];
|
|
208
|
+
expect(hasGaps(tiles, 12)).toBe(true);
|
|
209
|
+
expect(where(pack(tiles, 12))).toEqual([
|
|
210
|
+
{ name: "a", row: 1, col: 1, colspan: 6, rowspan: 3 },
|
|
211
|
+
{ name: "b", row: 4, col: 1, colspan: 6, rowspan: 2 },
|
|
212
|
+
{ name: "c", row: 1, col: 7, colspan: 6, rowspan: 4 },
|
|
213
|
+
]);
|
|
214
|
+
expect(hasGaps(pack(tiles, 12), 12)).toBe(false);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("stops a tile under the lowest tile it would pass through", () => {
|
|
218
|
+
const tiles = [
|
|
219
|
+
tile("wide", { row: 1, col: 1, colspan: 12, rowspan: 2 }),
|
|
220
|
+
tile("low", { row: 9, col: 4, colspan: 4, rowspan: 2 }),
|
|
221
|
+
];
|
|
222
|
+
expect(pack(tiles, 12)[1].row).toBe(3);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe("flowTiles", () => {
|
|
227
|
+
it("takes every place off and keeps sizes, in reading order", () => {
|
|
228
|
+
const tiles = [
|
|
229
|
+
tile("b", { row: 4, col: 1, colspan: 6, rowspan: 3 }),
|
|
230
|
+
tile("a", { row: 1, col: 7, colspan: 6, rowspan: 2 }),
|
|
231
|
+
];
|
|
232
|
+
expect(where(flowTiles(tiles))).toEqual([
|
|
233
|
+
{ name: "a", row: undefined, col: undefined, colspan: 6, rowspan: 2 },
|
|
234
|
+
{ name: "b", row: undefined, col: undefined, colspan: 6, rowspan: 3 },
|
|
235
|
+
]);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe("placeWhereDrawn keeps rows where they are drawn", () => {
|
|
240
|
+
it("takes each edge to its nearest row line, so stacked tiles still touch and nothing is pushed", () => {
|
|
241
|
+
const track = trackWidth(1200, 12);
|
|
242
|
+
const half = 6 * (track + 16) - 16;
|
|
243
|
+
// Four rows of two auto tiles, each 300px tall with a 16px gap: drawn
|
|
244
|
+
// tops at 0, 316, 632, 948.
|
|
245
|
+
const tiles = Array.from({ length: 8 }, (_, i) =>
|
|
246
|
+
tile(`t${i}`, { colspan: 6 }),
|
|
247
|
+
);
|
|
248
|
+
const boxes = tiles.map((_, i) => ({
|
|
249
|
+
top: Math.floor(i / 2) * 316,
|
|
250
|
+
left: i % 2 === 0 ? 0 : half + 16,
|
|
251
|
+
width: half,
|
|
252
|
+
height: 300,
|
|
253
|
+
}));
|
|
254
|
+
const placed = placeWhereDrawn(tiles, boxes, 12, track);
|
|
255
|
+
// Every row's top stays within half a row (48px) of where it was drawn.
|
|
256
|
+
for (const [i, each] of placed.entries())
|
|
257
|
+
expect(
|
|
258
|
+
Math.abs((each.row! - 1) * 96 - boxes[i].top),
|
|
259
|
+
).toBeLessThanOrEqual(48);
|
|
260
|
+
// And each row starts right where the one above ends: no row was pushed.
|
|
261
|
+
for (let r = 2; r < 8; r += 2)
|
|
262
|
+
expect(placed[r].row).toBe(
|
|
263
|
+
placed[r - 2].row! + placed[r - 2].rowspan!,
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe("minRowsOf", () => {
|
|
269
|
+
const drawn = (html: string) => {
|
|
270
|
+
const frame = document.createElement("div");
|
|
271
|
+
frame.innerHTML = html;
|
|
272
|
+
return frame;
|
|
273
|
+
};
|
|
274
|
+
it("gives a chart three rows, value cards and a table two, and prose one", () => {
|
|
275
|
+
expect(minRowsOf(tile("chart"), drawn('<svg class="plot"></svg>'))).toBe(
|
|
276
|
+
3,
|
|
277
|
+
);
|
|
278
|
+
expect(
|
|
279
|
+
minRowsOf(tile("kpis"), drawn('<div class="malloy-big-value"></div>')),
|
|
280
|
+
).toBe(2);
|
|
281
|
+
expect(
|
|
282
|
+
minRowsOf(tile("rows"), drawn('<div class="malloy-table"></div>')),
|
|
283
|
+
).toBe(2);
|
|
284
|
+
expect(
|
|
285
|
+
minRowsOf({ kind: "text", name: "note", markdown: "" }, null),
|
|
286
|
+
).toBe(1);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("takes a query tile for a chart until it has drawn", () => {
|
|
290
|
+
expect(minRowsOf(tile("t"))).toBe(3);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("gives a dashboard with a chart beside its cards a chart's rows", () => {
|
|
294
|
+
expect(
|
|
295
|
+
minRowsOf(
|
|
296
|
+
tile("mixed"),
|
|
297
|
+
drawn(
|
|
298
|
+
'<div class="malloy-dashboard"><div class="malloy-big-value"></div><div class="malloy-chart"></div></div>',
|
|
299
|
+
),
|
|
300
|
+
),
|
|
301
|
+
).toBe(3);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("lets a chart inside a card or a table's cell size with its host", () => {
|
|
305
|
+
expect(
|
|
306
|
+
minRowsOf(
|
|
307
|
+
tile("spark"),
|
|
308
|
+
drawn(
|
|
309
|
+
'<div class="malloy-big-value"><div class="malloy-chart"></div></div>',
|
|
310
|
+
),
|
|
311
|
+
),
|
|
312
|
+
).toBe(2);
|
|
313
|
+
expect(
|
|
314
|
+
minRowsOf(
|
|
315
|
+
tile("cells"),
|
|
316
|
+
drawn(
|
|
317
|
+
'<div class="malloy-table"><div class="malloy-chart"></div></div>',
|
|
318
|
+
),
|
|
319
|
+
),
|
|
320
|
+
).toBe(2);
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
describe("holdChartRows", () => {
|
|
325
|
+
it("raises a tile switched to a plotted chart to a chart's rows", () => {
|
|
326
|
+
expect(
|
|
327
|
+
holdChartRows(tile("t", { rowspan: 2, chart: "line_chart" })).rowspan,
|
|
328
|
+
).toBe(3);
|
|
329
|
+
});
|
|
330
|
+
it("leaves value cards, a table, and a tile on auto height alone", () => {
|
|
331
|
+
expect(
|
|
332
|
+
holdChartRows(tile("t", { rowspan: 2, chart: "big_value" })).rowspan,
|
|
333
|
+
).toBe(2);
|
|
334
|
+
expect(
|
|
335
|
+
holdChartRows(tile("t", { rowspan: 2, chart: "none" })).rowspan,
|
|
336
|
+
).toBe(2);
|
|
337
|
+
expect(
|
|
338
|
+
holdChartRows(tile("t", { chart: "bar_chart" })).rowspan,
|
|
339
|
+
).toBeUndefined();
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
describe("stepPlaced", () => {
|
|
344
|
+
const at = (tiles: DashboardTile[], name: string) => {
|
|
345
|
+
const t = tiles.find((each) => each.name === name)!;
|
|
346
|
+
return [t.row, t.col];
|
|
347
|
+
};
|
|
348
|
+
const stacked = () => [
|
|
349
|
+
tile("a", { row: 1, col: 1, colspan: 6, rowspan: 4 }),
|
|
350
|
+
tile("b", { row: 5, col: 1, colspan: 6, rowspan: 3 }),
|
|
351
|
+
];
|
|
352
|
+
|
|
353
|
+
it("swaps a tile down past the one under it", () => {
|
|
354
|
+
const next = stepPlaced(stacked(), 0, 1, 0, 12);
|
|
355
|
+
expect(at(next, "b")).toEqual([1, 1]);
|
|
356
|
+
expect(at(next, "a")).toEqual([4, 1]);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("swaps a tile up past the one over it, the mirror of down", () => {
|
|
360
|
+
const next = stepPlaced(stacked(), 1, -1, 0, 12);
|
|
361
|
+
expect(at(next, "b")).toEqual([1, 1]);
|
|
362
|
+
expect(at(next, "a")).toEqual([4, 1]);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it("swaps tiles side by side", () => {
|
|
366
|
+
const tiles = [
|
|
367
|
+
tile("a", { row: 1, col: 1, colspan: 4, rowspan: 3 }),
|
|
368
|
+
tile("b", { row: 1, col: 5, colspan: 8, rowspan: 3 }),
|
|
369
|
+
];
|
|
370
|
+
const right = stepPlaced(tiles, 0, 0, 1, 12);
|
|
371
|
+
expect(at(right, "b")).toEqual([1, 1]);
|
|
372
|
+
expect(at(right, "a")).toEqual([1, 9]);
|
|
373
|
+
const left = stepPlaced(tiles, 1, 0, -1, 12);
|
|
374
|
+
expect(at(left, "b")).toEqual([1, 1]);
|
|
375
|
+
expect(at(left, "a")).toEqual([1, 9]);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("steps one cell into empty space", () => {
|
|
379
|
+
const next = stepPlaced(stacked(), 0, 0, 1, 12);
|
|
380
|
+
expect(at(next, "a")).toEqual([1, 2]);
|
|
381
|
+
expect(at(next, "b")).toEqual([5, 1]);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("pushes down what it lands on when two tiles are in the way", () => {
|
|
385
|
+
const tiles = [
|
|
386
|
+
tile("a", { row: 1, col: 1, colspan: 12, rowspan: 3 }),
|
|
387
|
+
tile("b", { row: 4, col: 1, colspan: 6, rowspan: 3 }),
|
|
388
|
+
tile("c", { row: 4, col: 7, colspan: 6, rowspan: 3 }),
|
|
389
|
+
];
|
|
390
|
+
const next = stepPlaced(tiles, 0, 1, 0, 12);
|
|
391
|
+
expect(at(next, "a")).toEqual([2, 1]);
|
|
392
|
+
expect(at(next, "b")).toEqual([5, 1]);
|
|
393
|
+
expect(at(next, "c")).toEqual([5, 7]);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("leaves the tiles as they were at the grid's edge", () => {
|
|
397
|
+
const tiles = stacked();
|
|
398
|
+
const next = stepPlaced(tiles, 0, -1, 0, 12);
|
|
399
|
+
expect(next.every((each, i) => each === tiles[i])).toBe(true);
|
|
400
|
+
});
|
|
401
|
+
});
|