@malloydata/render 0.0.56-dev230710212813 → 0.0.56-dev230711015353
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/html/container.d.ts +2 -2
- package/dist/html/container.js +2 -2
- package/dist/html/html_view.js +6 -6
- package/dist/html/table.js +42 -18
- package/dist/renderer.d.ts +3 -2
- package/dist/renderer.js +2 -1
- package/package.json +2 -2
package/dist/html/container.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Explore } from '@malloydata/malloy';
|
|
1
|
+
import { Explore, Tags } from '@malloydata/malloy';
|
|
2
2
|
import { StyleDefaults } from '../data_styles';
|
|
3
3
|
import { ChildRenderers, RenderTree } from '../renderer';
|
|
4
4
|
import { RendererOptions } from '../renderer_types';
|
|
@@ -6,5 +6,5 @@ export declare abstract class ContainerRenderer extends RenderTree {
|
|
|
6
6
|
childRenderers: ChildRenderers;
|
|
7
7
|
protected abstract childrenStyleDefaults: StyleDefaults;
|
|
8
8
|
get defaultStylesForChildren(): StyleDefaults;
|
|
9
|
-
static make<Type extends ContainerRenderer>(c: new (document: Document, options: RendererOptions) => Type, document: Document, exploreField: Explore, options: RendererOptions): Type;
|
|
9
|
+
static make<Type extends ContainerRenderer>(c: new (document: Document, options: RendererOptions, tags?: Tags) => Type, document: Document, exploreField: Explore, options: RendererOptions, tags?: Tags): Type;
|
|
10
10
|
}
|
package/dist/html/container.js
CHANGED
|
@@ -35,8 +35,8 @@ class ContainerRenderer extends renderer_1.RenderTree {
|
|
|
35
35
|
// We can't use a normal constructor here because we need
|
|
36
36
|
// we need to be fully constructed before we construct
|
|
37
37
|
// our children.
|
|
38
|
-
static make(c, document, exploreField, options) {
|
|
39
|
-
const n = new c(document, options);
|
|
38
|
+
static make(c, document, exploreField, options, tags) {
|
|
39
|
+
const n = new c(document, options, tags);
|
|
40
40
|
return n;
|
|
41
41
|
}
|
|
42
42
|
}
|
package/dist/html/html_view.js
CHANGED
|
@@ -150,24 +150,24 @@ function makeRenderer(field, document, options, styleDefaults, queryTimezone, ta
|
|
|
150
150
|
return renderer;
|
|
151
151
|
}
|
|
152
152
|
if ((renderDef === null || renderDef === void 0 ? void 0 : renderDef.renderer) === 'dashboard') {
|
|
153
|
-
return makeContainerRenderer(dashboard_1.HTMLDashboardRenderer, document, isContainer(field), options);
|
|
153
|
+
return makeContainerRenderer(dashboard_1.HTMLDashboardRenderer, document, isContainer(field), options, tags);
|
|
154
154
|
}
|
|
155
155
|
else if ((renderDef === null || renderDef === void 0 ? void 0 : renderDef.renderer) === 'list') {
|
|
156
|
-
return makeContainerRenderer(list_1.HTMLListRenderer, document, isContainer(field), options);
|
|
156
|
+
return makeContainerRenderer(list_1.HTMLListRenderer, document, isContainer(field), options, tags);
|
|
157
157
|
}
|
|
158
158
|
else if ((renderDef === null || renderDef === void 0 ? void 0 : renderDef.renderer) === 'list_detail') {
|
|
159
|
-
return makeContainerRenderer(list_detail_1.HTMLListDetailRenderer, document, isContainer(field), options);
|
|
159
|
+
return makeContainerRenderer(list_detail_1.HTMLListDetailRenderer, document, isContainer(field), options, tags);
|
|
160
160
|
}
|
|
161
161
|
else if ((renderDef === null || renderDef === void 0 ? void 0 : renderDef.renderer) === 'table' ||
|
|
162
162
|
!field.hasParentExplore() ||
|
|
163
163
|
field.isExploreField()) {
|
|
164
|
-
return makeContainerRenderer(table_1.HTMLTableRenderer, document, isContainer(field), options);
|
|
164
|
+
return makeContainerRenderer(table_1.HTMLTableRenderer, document, isContainer(field), options, tags);
|
|
165
165
|
}
|
|
166
166
|
throw new Error(`Could not find a proper renderer for field ${field.name}`);
|
|
167
167
|
}
|
|
168
168
|
exports.makeRenderer = makeRenderer;
|
|
169
|
-
function makeContainerRenderer(cType, document, explore, options) {
|
|
170
|
-
const c = container_1.ContainerRenderer.make(cType, document, explore, options);
|
|
169
|
+
function makeContainerRenderer(cType, document, explore, options, tags) {
|
|
170
|
+
const c = container_1.ContainerRenderer.make(cType, document, explore, options, tags);
|
|
171
171
|
const result = {};
|
|
172
172
|
explore.intrinsicFields.forEach((field) => {
|
|
173
173
|
result[field.name] = makeRenderer(field, document, options, c.defaultStylesForChildren, explore.queryTimezone, field.getTags());
|
package/dist/html/table.js
CHANGED
|
@@ -39,10 +39,19 @@ class HTMLTableRenderer extends container_1.ContainerRenderer {
|
|
|
39
39
|
if (!table.isArray() && !table.isRecord()) {
|
|
40
40
|
throw new Error('Invalid type for Table Renderer');
|
|
41
41
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const shouldTranspose = this.tags
|
|
43
|
+
? this.tags.getMalloyTags().properties['transpose'] === true
|
|
44
|
+
: false;
|
|
45
|
+
if (shouldTranspose && table.field.intrinsicFields.length > 20) {
|
|
46
|
+
throw new Error('Transpose limit of 20 columns exceeded.');
|
|
47
|
+
}
|
|
48
|
+
let rowIndex = 0;
|
|
49
|
+
let columnIndex = 0;
|
|
50
|
+
const cells = [];
|
|
51
|
+
cells[rowIndex] = [];
|
|
52
|
+
for (const field of table.field.intrinsicFields) {
|
|
44
53
|
if ((0, tags_utils_1.isFieldHidden)(field)) {
|
|
45
|
-
|
|
54
|
+
continue;
|
|
46
55
|
}
|
|
47
56
|
let name = (0, utils_1.formatTitle)(this.options, field, this.options.dataStyles[field.name], field.parentExplore.queryTimezone);
|
|
48
57
|
const childRenderer = this.childRenderers[name];
|
|
@@ -52,13 +61,14 @@ class HTMLTableRenderer extends container_1.ContainerRenderer {
|
|
|
52
61
|
padding: 8px;
|
|
53
62
|
color: var(--malloy-title-color, #505050);
|
|
54
63
|
border-bottom: 1px solid var(--malloy-border-color, #eaeaea);
|
|
55
|
-
text-align: ${isNumeric ? '
|
|
64
|
+
text-align: ${!isNumeric || shouldTranspose ? 'left' : 'right'};
|
|
56
65
|
`;
|
|
57
66
|
name = name.replace(/_/g, '_​');
|
|
58
67
|
headerCell.innerHTML = name;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
cells[rowIndex][columnIndex] = headerCell;
|
|
69
|
+
columnIndex++;
|
|
70
|
+
}
|
|
71
|
+
if (!shouldTranspose && this.options.isDrillingEnabled) {
|
|
62
72
|
const drillHeader = this.document.createElement('th');
|
|
63
73
|
drillHeader.style.cssText = `
|
|
64
74
|
padding: 8px;
|
|
@@ -66,11 +76,13 @@ class HTMLTableRenderer extends container_1.ContainerRenderer {
|
|
|
66
76
|
border-bottom: 1px solid var(--malloy-border-color, #eaeaea);
|
|
67
77
|
width: 25px;
|
|
68
78
|
`;
|
|
69
|
-
|
|
79
|
+
cells[rowIndex][columnIndex] = drillHeader;
|
|
80
|
+
columnIndex++;
|
|
70
81
|
}
|
|
71
|
-
|
|
82
|
+
rowIndex++;
|
|
72
83
|
for (const row of table) {
|
|
73
|
-
|
|
84
|
+
cells[rowIndex] = [];
|
|
85
|
+
columnIndex = 0;
|
|
74
86
|
for (const field of table.field.intrinsicFields) {
|
|
75
87
|
if ((0, tags_utils_1.isFieldHidden)(field)) {
|
|
76
88
|
continue;
|
|
@@ -87,9 +99,11 @@ class HTMLTableRenderer extends container_1.ContainerRenderer {
|
|
|
87
99
|
${isNumeric ? 'text-align: right;' : ''}
|
|
88
100
|
`;
|
|
89
101
|
cellElement.appendChild(rendered);
|
|
90
|
-
|
|
102
|
+
cells[rowIndex][columnIndex] = cellElement;
|
|
103
|
+
columnIndex++;
|
|
91
104
|
}
|
|
92
|
-
|
|
105
|
+
// TODO(figutierrez): Deal with drill when transpose is on.
|
|
106
|
+
if (!shouldTranspose && this.options.isDrillingEnabled) {
|
|
93
107
|
const drillCell = this.document.createElement('td');
|
|
94
108
|
const drillIcon = (0, utils_1.createDrillIcon)(this.document);
|
|
95
109
|
drillCell.appendChild(drillIcon);
|
|
@@ -106,11 +120,25 @@ class HTMLTableRenderer extends container_1.ContainerRenderer {
|
|
|
106
120
|
this.options.onDrill(drillQuery, drillIcon, drillFilters);
|
|
107
121
|
}
|
|
108
122
|
};
|
|
109
|
-
|
|
123
|
+
cells[rowIndex][columnIndex] = drillCell;
|
|
124
|
+
columnIndex++;
|
|
110
125
|
}
|
|
111
|
-
|
|
126
|
+
rowIndex++;
|
|
112
127
|
}
|
|
113
128
|
const tableElement = this.document.createElement('table');
|
|
129
|
+
let tableSection = this.document.createElement('thead');
|
|
130
|
+
for (let row = 0; row < (shouldTranspose ? columnIndex : rowIndex); row++) {
|
|
131
|
+
if (row === 1) {
|
|
132
|
+
tableElement.appendChild(tableSection);
|
|
133
|
+
tableSection = this.document.createElement('tbody');
|
|
134
|
+
}
|
|
135
|
+
const currentRow = this.document.createElement('tr');
|
|
136
|
+
for (let column = 0; column < (shouldTranspose ? rowIndex : columnIndex); column++) {
|
|
137
|
+
currentRow.appendChild(shouldTranspose ? cells[column][row] : cells[row][column]);
|
|
138
|
+
}
|
|
139
|
+
tableSection.appendChild(currentRow);
|
|
140
|
+
}
|
|
141
|
+
tableElement.appendChild(tableSection);
|
|
114
142
|
tableElement.style.cssText = `
|
|
115
143
|
border: 1px solid var(--malloy-border-color, #eaeaea);
|
|
116
144
|
vertical-align: top;
|
|
@@ -118,10 +146,6 @@ class HTMLTableRenderer extends container_1.ContainerRenderer {
|
|
|
118
146
|
border-collapse: collapse;
|
|
119
147
|
width: 100%;
|
|
120
148
|
`;
|
|
121
|
-
const tableHead = this.document.createElement('thead');
|
|
122
|
-
tableHead.appendChild(header);
|
|
123
|
-
tableElement.appendChild(tableHead);
|
|
124
|
-
tableElement.appendChild(tableBody);
|
|
125
149
|
return tableElement;
|
|
126
150
|
}
|
|
127
151
|
}
|
package/dist/renderer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataColumn } from '@malloydata/malloy';
|
|
1
|
+
import { DataColumn, Tags } from '@malloydata/malloy';
|
|
2
2
|
import { RendererOptions } from './renderer_types';
|
|
3
3
|
export declare type ChildRenderers = {
|
|
4
4
|
[fieldName: string]: Renderer;
|
|
@@ -9,7 +9,8 @@ export interface Renderer {
|
|
|
9
9
|
export declare abstract class RenderTree implements Renderer {
|
|
10
10
|
protected readonly document: Document;
|
|
11
11
|
protected readonly options: RendererOptions;
|
|
12
|
-
|
|
12
|
+
protected readonly tags?: Tags | undefined;
|
|
13
|
+
constructor(document: Document, options: RendererOptions, tags?: Tags | undefined);
|
|
13
14
|
protected abstract get childRenderers(): ChildRenderers;
|
|
14
15
|
abstract render(value: DataColumn): Promise<HTMLElement>;
|
|
15
16
|
}
|
package/dist/renderer.js
CHANGED
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.RenderTree = void 0;
|
|
26
26
|
class RenderTree {
|
|
27
|
-
constructor(document, options) {
|
|
27
|
+
constructor(document, options, tags) {
|
|
28
28
|
this.document = document;
|
|
29
29
|
this.options = options;
|
|
30
|
+
this.tags = tags;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
exports.RenderTree = RenderTree;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.56-
|
|
3
|
+
"version": "0.0.56-dev230711015353",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"prepublishOnly": "npm run build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@malloydata/malloy": "^0.0.56-
|
|
21
|
+
"@malloydata/malloy": "^0.0.56-dev230711015353",
|
|
22
22
|
"@types/luxon": "^2.4.0",
|
|
23
23
|
"lodash": "^4.17.20",
|
|
24
24
|
"luxon": "^2.4.0",
|