@malloydata/render 0.0.135-dev240325191847 → 0.0.135-dev240326154530
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/component/render-webcomponent.d.ts +6 -0
- package/dist/component/render.d.ts +7 -17
- package/dist/component/result-context.d.ts +2 -3
- package/dist/component/table/table-context.d.ts +9 -0
- package/dist/component/{table-layout.d.ts → table/table-layout.d.ts} +2 -2
- package/dist/component/table/table.d.ts +9 -0
- package/dist/html/html_view.d.ts +1 -1
- package/dist/module/index.mjs +145243 -0
- package/dist/module/index.umd.js +1643 -0
- package/dist/module/style.css +1 -0
- package/dist/stories/bars.stories.d.ts +1 -1
- package/dist/stories/tables.stories.d.ts +1 -1
- package/dist/stories/themes.stories.d.ts +1 -1
- package/dist/webcomponent/malloy-render.mjs +90572 -0
- package/dist/webcomponent/malloy-render.umd.js +1491 -0
- package/dist/webcomponent/style.css +1 -0
- package/package.json +21 -7
- package/vite.config.ts +25 -0
- package/vite.config.webcomponent.ts +25 -0
- package/dist/bundle/bundled_renderer.js +0 -139374
- package/dist/bundle/bundled_renderer.min.js +0 -2374
- package/dist/bundle/main.js +0 -29
- package/dist/bundle/renderer.js +0 -71
- package/dist/component/bar-chart.js +0 -130
- package/dist/component/chart-settings.js +0 -152
- package/dist/component/render-numeric-field.js +0 -104
- package/dist/component/render-result-metadata.js +0 -91
- package/dist/component/render.js +0 -155
- package/dist/component/result-context.js +0 -28
- package/dist/component/table-layout.js +0 -83
- package/dist/component/table.d.ts +0 -35
- package/dist/component/table.js +0 -375
- package/dist/component/util.js +0 -53
- package/dist/component/vega-chart.js +0 -105
- package/dist/component/vega-lite-base-spec.js +0 -61
- package/dist/component/vega-types.js +0 -34
- package/dist/data_styles.js +0 -50
- package/dist/drill.js +0 -124
- package/dist/html/area_sparkline.js +0 -118
- package/dist/html/bar_chart.js +0 -70
- package/dist/html/bar_sparkline.js +0 -119
- package/dist/html/boolean.js +0 -53
- package/dist/html/bytes.js +0 -47
- package/dist/html/cartesian_chart.js +0 -110
- package/dist/html/chart.js +0 -120
- package/dist/html/column_sparkline.js +0 -120
- package/dist/html/container.js +0 -44
- package/dist/html/currency.js +0 -75
- package/dist/html/dashboard.js +0 -242
- package/dist/html/data_volume.js +0 -94
- package/dist/html/date.js +0 -66
- package/dist/html/duration.js +0 -108
- package/dist/html/html_view.js +0 -187
- package/dist/html/image.js +0 -77
- package/dist/html/index.js +0 -28
- package/dist/html/json.js +0 -52
- package/dist/html/line_chart.js +0 -72
- package/dist/html/link.js +0 -57
- package/dist/html/list.js +0 -73
- package/dist/html/list_detail.js +0 -33
- package/dist/html/number.js +0 -73
- package/dist/html/percent.js +0 -50
- package/dist/html/point_map.js +0 -182
- package/dist/html/scatter_chart.js +0 -72
- package/dist/html/segment_map.js +0 -151
- package/dist/html/shape_map.js +0 -194
- package/dist/html/sparkline.js +0 -120
- package/dist/html/state_codes.js +0 -137
- package/dist/html/table.js +0 -475
- package/dist/html/text.js +0 -65
- package/dist/html/unsupported.js +0 -72
- package/dist/html/utils.js +0 -277
- package/dist/html/vega_spec.js +0 -544
- package/dist/index.js +0 -47
- package/dist/main_renderer_factory.js +0 -101
- package/dist/renderer.js +0 -34
- package/dist/renderer_factory.js +0 -57
- package/dist/renderer_types.js +0 -25
- package/dist/stories/bars.stories.js +0 -52
- package/dist/stories/basic.stories.js +0 -34
- package/dist/stories/image.stories.js +0 -34
- package/dist/stories/render-malloy-legacy.js +0 -27
- package/dist/stories/tables.stories.js +0 -65
- package/dist/stories/themes.stories.js +0 -47
- package/dist/stories/util.js +0 -25
- package/dist/tags_utils.js +0 -30
package/dist/html/table.js
DELETED
|
@@ -1,475 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2023 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
* a copy of this software and associated documentation files
|
|
7
|
-
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
-
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
-
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
-
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
-
* subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be
|
|
14
|
-
* included in all copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.HTMLTableRenderer = void 0;
|
|
26
|
-
const drill_1 = require("../drill");
|
|
27
|
-
const container_1 = require("./container");
|
|
28
|
-
const number_1 = require("./number");
|
|
29
|
-
const utils_1 = require("./utils");
|
|
30
|
-
const tags_utils_1 = require("../tags_utils");
|
|
31
|
-
class PivotedField {
|
|
32
|
-
constructor(parentField, values, span) {
|
|
33
|
-
this.parentField = parentField;
|
|
34
|
-
this.values = values;
|
|
35
|
-
this.span = span;
|
|
36
|
-
this.key = JSON.stringify({
|
|
37
|
-
parentField: this.parentField.name,
|
|
38
|
-
values: this.values.map(v => (v.isScalar() ? v.key : '')),
|
|
39
|
-
});
|
|
40
|
-
this.fieldValueMap = new Map();
|
|
41
|
-
for (const value of this.values) {
|
|
42
|
-
this.fieldValueMap.set(value.field.name, value);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
class PivotedColumnField {
|
|
47
|
-
constructor(pivotedField, field, userDefinedPivotDimensions) {
|
|
48
|
-
this.pivotedField = pivotedField;
|
|
49
|
-
this.field = field;
|
|
50
|
-
this.userDefinedPivotDimensions = userDefinedPivotDimensions;
|
|
51
|
-
}
|
|
52
|
-
isPivotedColumnField() {
|
|
53
|
-
return this instanceof PivotedColumnField;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
class FlattenedColumnField {
|
|
57
|
-
constructor(flattenedField, field, name) {
|
|
58
|
-
this.flattenedField = flattenedField;
|
|
59
|
-
this.field = field;
|
|
60
|
-
this.name = name;
|
|
61
|
-
}
|
|
62
|
-
isFlattenedColumnField() {
|
|
63
|
-
return this instanceof FlattenedColumnField;
|
|
64
|
-
}
|
|
65
|
-
getChildRenderer(childRenderers) {
|
|
66
|
-
const baseRenderer = childRenderers[this.flattenedField.name];
|
|
67
|
-
if (baseRenderer instanceof HTMLTableRenderer) {
|
|
68
|
-
return baseRenderer.childRenderers[this.field.name];
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
throw Error('Could not render flattened table. `# flatten` only supports nests.');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
getValue(row) {
|
|
75
|
-
const parentRecord = row.cell(this.flattenedField);
|
|
76
|
-
if (parentRecord.isRecord())
|
|
77
|
-
return parentRecord.cell(this.field);
|
|
78
|
-
else
|
|
79
|
-
throw Error('Cannot find nested record within flattened field. `# flatten` only supports nests with no group_bys.');
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function shouldFlattenField(field) {
|
|
83
|
-
const { tag } = field.tagParse();
|
|
84
|
-
return field.isExploreField() && tag.has('flatten') && field.isRecord;
|
|
85
|
-
}
|
|
86
|
-
class HTMLTableRenderer extends container_1.ContainerRenderer {
|
|
87
|
-
constructor() {
|
|
88
|
-
super(...arguments);
|
|
89
|
-
this.childrenStyleDefaults = {
|
|
90
|
-
size: 'medium',
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
async render(table) {
|
|
94
|
-
var _a, _b, _c;
|
|
95
|
-
if (table.isNull()) {
|
|
96
|
-
return this.document.createElement('span');
|
|
97
|
-
}
|
|
98
|
-
if (!table.isArray() && !table.isRecord()) {
|
|
99
|
-
throw new Error('Invalid type for Table Renderer');
|
|
100
|
-
}
|
|
101
|
-
const shouldTranspose = this.tagged.has('transpose');
|
|
102
|
-
if (shouldTranspose && table.field.intrinsicFields.length > 20) {
|
|
103
|
-
throw new Error('Transpose limit of 20 columns exceeded.');
|
|
104
|
-
}
|
|
105
|
-
let rowIndex = 0;
|
|
106
|
-
let columnIndex = 0;
|
|
107
|
-
let cells = [];
|
|
108
|
-
cells[rowIndex] = [];
|
|
109
|
-
const columnFields = [];
|
|
110
|
-
let pivotDepth = 0;
|
|
111
|
-
for (const field of table.field.intrinsicFields) {
|
|
112
|
-
if ((0, tags_utils_1.isFieldHidden)(field)) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
const childRenderer = this.childRenderers[field.name];
|
|
116
|
-
const shouldPivot = childRenderer instanceof HTMLTableRenderer &&
|
|
117
|
-
childRenderer.tagged.has('pivot');
|
|
118
|
-
if (shouldPivot) {
|
|
119
|
-
const userDefinedDimensions = childRenderer.tagged.textArray('pivot', 'dimensions');
|
|
120
|
-
let dimensions = undefined;
|
|
121
|
-
let nonDimensions = [];
|
|
122
|
-
const pivotedFields = new Map();
|
|
123
|
-
for (const row of table) {
|
|
124
|
-
const dc = row.cell(field);
|
|
125
|
-
if (dc.isNull()) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (!dc.isArray() && !dc.isRecord()) {
|
|
129
|
-
throw new Error(`Can not pivot field ${field.name}.`);
|
|
130
|
-
}
|
|
131
|
-
if (!dimensions) {
|
|
132
|
-
const dimensionsResult = childRenderer.calculatePivotDimensions(dc, userDefinedDimensions);
|
|
133
|
-
dimensions = dimensionsResult.dimensions;
|
|
134
|
-
nonDimensions = dimensionsResult.nonDimensions;
|
|
135
|
-
}
|
|
136
|
-
for (const innerRow of dc) {
|
|
137
|
-
const pivotedField = new PivotedField(field, dimensions.map(d => innerRow.cell(d.field)), nonDimensions.length);
|
|
138
|
-
const pfKey = pivotedField.key;
|
|
139
|
-
if (!pivotedFields.get(pfKey)) {
|
|
140
|
-
pivotedFields.set(pfKey, pivotedField);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (!dimensions) {
|
|
145
|
-
throw new Error(`Could not pivot ${field.name}, no data found.`);
|
|
146
|
-
}
|
|
147
|
-
const sortedPivotedFields = Array.from(pivotedFields.values()).sort((a, b) => {
|
|
148
|
-
for (const d of dimensions) {
|
|
149
|
-
const aValue = a.fieldValueMap.get(d.field.name);
|
|
150
|
-
const bValue = b.fieldValueMap.get(d.field.name);
|
|
151
|
-
if ((aValue === null || aValue === void 0 ? void 0 : aValue.isScalar()) &&
|
|
152
|
-
(bValue === null || bValue === void 0 ? void 0 : bValue.isScalar()) &&
|
|
153
|
-
typeof aValue === typeof bValue) {
|
|
154
|
-
if (aValue.isNull()) {
|
|
155
|
-
if (bValue.isNull()) {
|
|
156
|
-
return 0;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
return 1;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else if (bValue.isNull()) {
|
|
163
|
-
return -1;
|
|
164
|
-
}
|
|
165
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
166
|
-
const compValue = aValue.compareTo(bValue);
|
|
167
|
-
if (compValue !== 0) {
|
|
168
|
-
return d.dir !== 'desc' ? compValue : -compValue;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return 0;
|
|
173
|
-
});
|
|
174
|
-
for (const pf of sortedPivotedFields) {
|
|
175
|
-
for (const nonDimension of nonDimensions) {
|
|
176
|
-
columnFields.push(new PivotedColumnField(pf, nonDimension.field, userDefinedDimensions));
|
|
177
|
-
cells[rowIndex][columnIndex] = childRenderer.createHeaderCell(nonDimension.field, shouldTranspose, {
|
|
178
|
-
name: (_a = nonDimension.flattenedField) === null || _a === void 0 ? void 0 : _a.name,
|
|
179
|
-
childRenderer: (_b = nonDimension.flattenedField) === null || _b === void 0 ? void 0 : _b.getChildRenderer(childRenderer.childRenderers),
|
|
180
|
-
});
|
|
181
|
-
columnIndex++;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
pivotDepth = Math.max(pivotDepth, dimensions.length);
|
|
185
|
-
}
|
|
186
|
-
else if (shouldFlattenField(field)) {
|
|
187
|
-
const parentField = field;
|
|
188
|
-
const flattenedFields = parentField.allFields.map(f => new FlattenedColumnField(parentField, f, `${parentField.name} ${f.name}`));
|
|
189
|
-
for (const flatField of flattenedFields) {
|
|
190
|
-
cells[rowIndex][columnIndex] = this.createHeaderCell(flatField.field, shouldTranspose, {
|
|
191
|
-
name: flatField.name,
|
|
192
|
-
childRenderer: flatField.getChildRenderer(this.childRenderers),
|
|
193
|
-
});
|
|
194
|
-
columnFields.push(flatField);
|
|
195
|
-
columnIndex++;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
cells[rowIndex][columnIndex] = this.createHeaderCell(field, shouldTranspose);
|
|
200
|
-
columnFields.push(field);
|
|
201
|
-
columnIndex++;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (pivotDepth > 0 && columnFields.length > 30) {
|
|
205
|
-
throw new Error('Pivot limit of 30 columns exceeded.');
|
|
206
|
-
}
|
|
207
|
-
if (!shouldTranspose && this.options.isDrillingEnabled) {
|
|
208
|
-
const drillHeader = this.document.createElement('th');
|
|
209
|
-
drillHeader.style.cssText = `
|
|
210
|
-
padding: 8px;
|
|
211
|
-
color: var(--malloy-title-color, #505050);
|
|
212
|
-
border-bottom: 1px solid var(--malloy-border-color, #eaeaea);
|
|
213
|
-
width: 25px;
|
|
214
|
-
`;
|
|
215
|
-
cells[rowIndex][columnIndex] = drillHeader;
|
|
216
|
-
columnIndex++;
|
|
217
|
-
}
|
|
218
|
-
rowIndex++;
|
|
219
|
-
const pivotHeaderCells = [];
|
|
220
|
-
for (let r = 0; r < pivotDepth; r++) {
|
|
221
|
-
const row = [];
|
|
222
|
-
let lastPivotedColumnHash = null;
|
|
223
|
-
for (const field of columnFields) {
|
|
224
|
-
if (field instanceof PivotedColumnField) {
|
|
225
|
-
const pfKey = field.pivotedField.key;
|
|
226
|
-
const valueIndex = field.pivotedField.values.length - pivotDepth + r;
|
|
227
|
-
if (valueIndex < 0) {
|
|
228
|
-
row.push(this.createEmptyHeaderCell());
|
|
229
|
-
}
|
|
230
|
-
else if (lastPivotedColumnHash !== pfKey) {
|
|
231
|
-
const headerCell = this.document.createElement('th');
|
|
232
|
-
if (!shouldTranspose) {
|
|
233
|
-
headerCell.colSpan = field.pivotedField.span;
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
headerCell.rowSpan = field.pivotedField.span;
|
|
237
|
-
}
|
|
238
|
-
headerCell.style.cssText = `
|
|
239
|
-
padding: 8px;
|
|
240
|
-
color: var(--malloy-title-color, #505050);
|
|
241
|
-
border-bottom: 1px solid var(--malloy-border-color, #eaeaeb);
|
|
242
|
-
text-align: left;
|
|
243
|
-
`;
|
|
244
|
-
const value = field.pivotedField.values[valueIndex];
|
|
245
|
-
headerCell.appendChild(this.document.createTextNode(`${value.field.name}: `));
|
|
246
|
-
headerCell.appendChild(await this.childRenderers[field.pivotedField.parentField.name].renderChild(value));
|
|
247
|
-
lastPivotedColumnHash = pfKey;
|
|
248
|
-
row.push(headerCell);
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
row.push(undefined);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
row.push(this.createEmptyHeaderCell());
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
pivotHeaderCells.push(row);
|
|
259
|
-
rowIndex++;
|
|
260
|
-
}
|
|
261
|
-
cells = [...pivotHeaderCells, ...cells];
|
|
262
|
-
for (const row of table) {
|
|
263
|
-
cells[rowIndex] = [];
|
|
264
|
-
columnIndex = 0;
|
|
265
|
-
let currentPivotedFieldKey = '';
|
|
266
|
-
let pivotedCells = new Map();
|
|
267
|
-
for (const field of columnFields) {
|
|
268
|
-
if (field instanceof PivotedColumnField) {
|
|
269
|
-
const childRenderer = this.childRenderers[field.pivotedField.parentField.name];
|
|
270
|
-
const childTableRecord = row.cell(field.pivotedField.parentField);
|
|
271
|
-
await (0, utils_1.yieldTask)();
|
|
272
|
-
if (field.pivotedField.key !== currentPivotedFieldKey) {
|
|
273
|
-
pivotedCells = await childRenderer.generatePivotedCells(childTableRecord, shouldTranspose, field.userDefinedPivotDimensions);
|
|
274
|
-
currentPivotedFieldKey = field.pivotedField.key;
|
|
275
|
-
}
|
|
276
|
-
const pfKey = field.pivotedField.key;
|
|
277
|
-
if (pivotedCells.has(pfKey) &&
|
|
278
|
-
((_c = pivotedCells.get(pfKey)) === null || _c === void 0 ? void 0 : _c.has(field.field.name))) {
|
|
279
|
-
cells[rowIndex][columnIndex] = pivotedCells
|
|
280
|
-
.get(pfKey)
|
|
281
|
-
.get(field.field.name);
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
cells[rowIndex][columnIndex] = childRenderer.generateNoValueCell(field.field, shouldTranspose);
|
|
285
|
-
}
|
|
286
|
-
columnIndex++;
|
|
287
|
-
// back
|
|
288
|
-
}
|
|
289
|
-
else if (field instanceof FlattenedColumnField) {
|
|
290
|
-
cells[rowIndex][columnIndex] = await this.createCellAndRender(field.getChildRenderer(this.childRenderers), field.getValue(row), shouldTranspose);
|
|
291
|
-
columnIndex++;
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
if ((0, tags_utils_1.isFieldHidden)(field)) {
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
const childRenderer = this.childRenderers[field.name];
|
|
298
|
-
cells[rowIndex][columnIndex] = await this.createCellAndRender(childRenderer, row.cell(field), shouldTranspose);
|
|
299
|
-
columnIndex++;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
// TODO(figutierrez): Deal with drill when transpose is on.
|
|
303
|
-
if (!shouldTranspose && this.options.isDrillingEnabled) {
|
|
304
|
-
const drillCell = this.document.createElement('td');
|
|
305
|
-
const drillIcon = (0, utils_1.createDrillIcon)(this.document);
|
|
306
|
-
drillCell.appendChild(drillIcon);
|
|
307
|
-
drillCell.style.cssText = `
|
|
308
|
-
padding: 2px;
|
|
309
|
-
vertical-align: top;
|
|
310
|
-
border-bottom: 1px solid var(--malloy-border-color, #eaeaea);
|
|
311
|
-
width: 25px;
|
|
312
|
-
cursor: pointer;
|
|
313
|
-
`;
|
|
314
|
-
drillCell.onclick = () => {
|
|
315
|
-
if (this.options.onDrill) {
|
|
316
|
-
const { drillQuery, drillFilters } = (0, drill_1.getDrillQuery)(row);
|
|
317
|
-
this.options.onDrill(drillQuery, drillIcon, drillFilters);
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
cells[rowIndex][columnIndex] = drillCell;
|
|
321
|
-
columnIndex++;
|
|
322
|
-
}
|
|
323
|
-
rowIndex++;
|
|
324
|
-
}
|
|
325
|
-
const tableElement = this.document.createElement('table');
|
|
326
|
-
let tableSection = this.document.createElement('thead');
|
|
327
|
-
for (let row = 0; row < (shouldTranspose ? columnIndex : rowIndex); row++) {
|
|
328
|
-
if (row === 1 + pivotDepth) {
|
|
329
|
-
tableElement.appendChild(tableSection);
|
|
330
|
-
tableSection = this.document.createElement('tbody');
|
|
331
|
-
}
|
|
332
|
-
const currentRow = this.document.createElement('tr');
|
|
333
|
-
for (let column = 0; column < (shouldTranspose ? rowIndex : columnIndex); column++) {
|
|
334
|
-
const cell = shouldTranspose ? cells[column][row] : cells[row][column];
|
|
335
|
-
if (cell) {
|
|
336
|
-
currentRow.appendChild(cell);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
tableSection.appendChild(currentRow);
|
|
340
|
-
}
|
|
341
|
-
tableElement.appendChild(tableSection);
|
|
342
|
-
tableElement.style.cssText = `
|
|
343
|
-
border: 1px solid var(--malloy-border-color, #eaeaea);
|
|
344
|
-
vertical-align: top;
|
|
345
|
-
border-bottom: 1px solid var(--malloy-border-color, #eaeaea);
|
|
346
|
-
border-collapse: collapse;
|
|
347
|
-
width: 100%;
|
|
348
|
-
`;
|
|
349
|
-
return tableElement;
|
|
350
|
-
}
|
|
351
|
-
calculatePivotDimensions(table, userSpecifiedDimensions) {
|
|
352
|
-
if (!table.isArray() && !table.isRecord()) {
|
|
353
|
-
throw new Error(`Could not pivot ${table.field.name}`);
|
|
354
|
-
}
|
|
355
|
-
let dimensions = undefined;
|
|
356
|
-
if (userSpecifiedDimensions) {
|
|
357
|
-
dimensions = table.field.allFieldsWithOrder.filter(f => userSpecifiedDimensions.indexOf(f.field.name) >= 0);
|
|
358
|
-
if (dimensions.length !== userSpecifiedDimensions.length) {
|
|
359
|
-
for (const dim of userSpecifiedDimensions) {
|
|
360
|
-
if (table.field.allFieldsWithOrder.filter(f => f.field.name === dim)
|
|
361
|
-
.length === 0) {
|
|
362
|
-
throw new Error(`Could not pivot ${table.field.name} since ${dim} is not a valid field.`);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
dimensions = table.field.dimensions;
|
|
369
|
-
}
|
|
370
|
-
const nonDimensions = [];
|
|
371
|
-
for (const f of table.field.allFieldsWithOrder) {
|
|
372
|
-
if (dimensions.indexOf(f) >= 0)
|
|
373
|
-
continue;
|
|
374
|
-
if (shouldFlattenField(f.field)) {
|
|
375
|
-
const nestedFields = f.field.allFieldsWithOrder.map(nf => ({
|
|
376
|
-
dir: nf.dir,
|
|
377
|
-
field: nf.field,
|
|
378
|
-
flattenedField: new FlattenedColumnField(f.field, nf.field, `${f.field.name} ${nf.field.name}`),
|
|
379
|
-
}));
|
|
380
|
-
nonDimensions.push(...nestedFields);
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
nonDimensions.push(f);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
if (nonDimensions.length === 0) {
|
|
387
|
-
throw new Error(`Can not pivot ${table.field.name} since all of its fields are dimensions.`);
|
|
388
|
-
}
|
|
389
|
-
return { dimensions, nonDimensions };
|
|
390
|
-
}
|
|
391
|
-
async generatePivotedCells(table, shouldTranspose, userSpecifiedDimensions) {
|
|
392
|
-
const result = new Map();
|
|
393
|
-
if (table.isNull()) {
|
|
394
|
-
return result;
|
|
395
|
-
}
|
|
396
|
-
if (!table.isArray() && !table.isRecord()) {
|
|
397
|
-
throw new Error(`Could not pivot ${table.field.name}`);
|
|
398
|
-
}
|
|
399
|
-
const { dimensions, nonDimensions } = this.calculatePivotDimensions(table, userSpecifiedDimensions);
|
|
400
|
-
for (const row of table) {
|
|
401
|
-
const pf = new PivotedField(table.field, dimensions.map(f => row.cell(f.field.name)), nonDimensions.length);
|
|
402
|
-
const renderedCells = new Map();
|
|
403
|
-
for (const nonDimension of nonDimensions) {
|
|
404
|
-
let childRenderer;
|
|
405
|
-
let value;
|
|
406
|
-
if (nonDimension.flattenedField) {
|
|
407
|
-
childRenderer = nonDimension.flattenedField.getChildRenderer(this.childRenderers);
|
|
408
|
-
value = nonDimension.flattenedField.getValue(row);
|
|
409
|
-
}
|
|
410
|
-
else {
|
|
411
|
-
childRenderer = this.childRenderers[nonDimension.field.name];
|
|
412
|
-
value = row.cell(nonDimension.field.name);
|
|
413
|
-
}
|
|
414
|
-
renderedCells.set(nonDimension.field.name, await this.createCellAndRender(childRenderer, value, shouldTranspose));
|
|
415
|
-
}
|
|
416
|
-
if (result.has(pf.key)) {
|
|
417
|
-
throw new Error(`Can not pivot ${table.field.name} dimensions lead to non unique pivots.`);
|
|
418
|
-
}
|
|
419
|
-
result.set(pf.key, renderedCells);
|
|
420
|
-
}
|
|
421
|
-
return result;
|
|
422
|
-
}
|
|
423
|
-
generateNoValueCell(field, shouldTranspose) {
|
|
424
|
-
const cell = this.createCell(this.childRenderers[field.name], shouldTranspose);
|
|
425
|
-
cell.textContent = '-';
|
|
426
|
-
return cell;
|
|
427
|
-
}
|
|
428
|
-
async createCellAndRender(childRenderer, value, shouldTranspose) {
|
|
429
|
-
const cell = this.createCell(childRenderer, shouldTranspose);
|
|
430
|
-
cell.appendChild(await childRenderer.render(value));
|
|
431
|
-
return cell;
|
|
432
|
-
}
|
|
433
|
-
createEmptyHeaderCell() {
|
|
434
|
-
const headerCell = this.document.createElement('th');
|
|
435
|
-
headerCell.style.cssText = `
|
|
436
|
-
padding: 8px;
|
|
437
|
-
color: var(--malloy-title-color, #505050);
|
|
438
|
-
border-bottom: 1px solid var(--malloy-border-color, #eaeaea);
|
|
439
|
-
`;
|
|
440
|
-
return headerCell;
|
|
441
|
-
}
|
|
442
|
-
createHeaderCell(field, shouldTranspose, override = {}) {
|
|
443
|
-
var _a, _b;
|
|
444
|
-
let name = (_a = override.name) !== null && _a !== void 0 ? _a : (0, utils_1.formatTitle)(this.options, field, this.options.dataStyles[field.name], field.parentExplore.queryTimezone);
|
|
445
|
-
const childRenderer = (_b = override.childRenderer) !== null && _b !== void 0 ? _b : this.childRenderers[field.name];
|
|
446
|
-
const isNumeric = childRenderer instanceof number_1.HTMLNumberRenderer;
|
|
447
|
-
const headerCell = this.document.createElement('th');
|
|
448
|
-
headerCell.style.cssText = `
|
|
449
|
-
padding: 8px;
|
|
450
|
-
color: var(--malloy-title-color, #505050);
|
|
451
|
-
border-bottom: 1px solid var(--malloy-border-color, #eaeaea);
|
|
452
|
-
text-align: ${isNumeric || shouldTranspose ? 'right' : 'left'};
|
|
453
|
-
`;
|
|
454
|
-
name = name.replace(/_/g, '_​');
|
|
455
|
-
headerCell.innerHTML = name;
|
|
456
|
-
return headerCell;
|
|
457
|
-
}
|
|
458
|
-
createCell(childRenderer, shouldTranspose) {
|
|
459
|
-
const isNumeric = childRenderer instanceof number_1.HTMLNumberRenderer;
|
|
460
|
-
(0, utils_1.yieldTask)();
|
|
461
|
-
const cellElement = this.document.createElement('td');
|
|
462
|
-
cellElement.style.cssText = `
|
|
463
|
-
padding: ${childRenderer instanceof HTMLTableRenderer ? '0' : '8px'};
|
|
464
|
-
vertical-align: top;
|
|
465
|
-
border-bottom: 1px solid var(--malloy-border-color, #eaeaea);
|
|
466
|
-
${isNumeric || shouldTranspose ? 'text-align: right;' : ''}
|
|
467
|
-
`;
|
|
468
|
-
return cellElement;
|
|
469
|
-
}
|
|
470
|
-
async renderChild(value) {
|
|
471
|
-
return this.childRenderers[value.field.name].render(value);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
exports.HTMLTableRenderer = HTMLTableRenderer;
|
|
475
|
-
//# sourceMappingURL=table.js.map
|
package/dist/html/text.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2023 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
* a copy of this software and associated documentation files
|
|
7
|
-
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
-
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
-
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
-
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
-
* subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be
|
|
14
|
-
* included in all copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.TextRendererFactory = exports.HTMLTextRenderer = void 0;
|
|
26
|
-
const utils_1 = require("./utils");
|
|
27
|
-
const renderer_factory_1 = require("../renderer_factory");
|
|
28
|
-
class HTMLTextRenderer {
|
|
29
|
-
constructor(document) {
|
|
30
|
-
this.document = document;
|
|
31
|
-
}
|
|
32
|
-
getText(data) {
|
|
33
|
-
return data.value === null ? null : `${data.value}`;
|
|
34
|
-
}
|
|
35
|
-
async render(data) {
|
|
36
|
-
let text = null;
|
|
37
|
-
try {
|
|
38
|
-
text = this.getText(data);
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
return (0, utils_1.createErrorElement)(this.document, e);
|
|
42
|
-
}
|
|
43
|
-
if (text === null) {
|
|
44
|
-
return (0, utils_1.createNullElement)(this.document);
|
|
45
|
-
}
|
|
46
|
-
const element = this.document.createElement('span');
|
|
47
|
-
element.appendChild(this.document.createTextNode(text));
|
|
48
|
-
return element;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.HTMLTextRenderer = HTMLTextRenderer;
|
|
52
|
-
class TextRendererFactory extends renderer_factory_1.RendererFactory {
|
|
53
|
-
activates(field) {
|
|
54
|
-
return field.hasParentExplore() && !field.isExploreField();
|
|
55
|
-
}
|
|
56
|
-
create(document, _styleDefaults, _rendererOptions, _field, _options) {
|
|
57
|
-
return new HTMLTextRenderer(document);
|
|
58
|
-
}
|
|
59
|
-
get rendererName() {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.TextRendererFactory = TextRendererFactory;
|
|
64
|
-
TextRendererFactory.instance = new TextRendererFactory();
|
|
65
|
-
//# sourceMappingURL=text.js.map
|
package/dist/html/unsupported.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2023 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
* a copy of this software and associated documentation files
|
|
7
|
-
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
-
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
-
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
-
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
-
* subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be
|
|
14
|
-
* included in all copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.UnsupportedRendererFactory = exports.HTMLUnsupportedRenderer = void 0;
|
|
26
|
-
const utils_1 = require("./utils");
|
|
27
|
-
const renderer_factory_1 = require("../renderer_factory");
|
|
28
|
-
class HTMLUnsupportedRenderer {
|
|
29
|
-
constructor(document) {
|
|
30
|
-
this.document = document;
|
|
31
|
-
}
|
|
32
|
-
getText(data) {
|
|
33
|
-
const value = data.value;
|
|
34
|
-
if (typeof value === 'string') {
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
else if (value === null) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
else if (typeof data.value === 'object') {
|
|
41
|
-
const record = data.value;
|
|
42
|
-
if ('value' in record && typeof record['value'] === 'string') {
|
|
43
|
-
return record['value'];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return JSON.stringify(data.value);
|
|
47
|
-
}
|
|
48
|
-
async render(data) {
|
|
49
|
-
const text = this.getText(data);
|
|
50
|
-
if (text === null) {
|
|
51
|
-
return (0, utils_1.createNullElement)(this.document);
|
|
52
|
-
}
|
|
53
|
-
const element = this.document.createElement('span');
|
|
54
|
-
element.appendChild(this.document.createTextNode(text));
|
|
55
|
-
return element;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.HTMLUnsupportedRenderer = HTMLUnsupportedRenderer;
|
|
59
|
-
class UnsupportedRendererFactory extends renderer_factory_1.RendererFactory {
|
|
60
|
-
activates(field) {
|
|
61
|
-
return (field.hasParentExplore() && field.isAtomicField() && field.isUnsupported());
|
|
62
|
-
}
|
|
63
|
-
create(document, _styleDefaults, _rendererOptions, _field, _options) {
|
|
64
|
-
return new HTMLUnsupportedRenderer(document);
|
|
65
|
-
}
|
|
66
|
-
get rendererName() {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.UnsupportedRendererFactory = UnsupportedRendererFactory;
|
|
71
|
-
UnsupportedRendererFactory.instance = new UnsupportedRendererFactory();
|
|
72
|
-
//# sourceMappingURL=unsupported.js.map
|