@malloydata/render 0.0.43-dev230616164521 → 0.0.43-dev230620232755
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/date.d.ts +2 -3
- package/dist/html/date.js +3 -3
- package/dist/html/html_view.d.ts +1 -1
- package/dist/html/html_view.js +4 -4
- package/dist/html/table.js +8 -2
- package/dist/html/utils.d.ts +1 -1
- package/dist/html/utils.js +29 -27
- package/package.json +4 -2
package/dist/html/date.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { DataColumn } from '@malloydata/malloy';
|
|
2
2
|
import { Renderer } from '../renderer';
|
|
3
|
-
import { RendererOptions } from '../renderer_types';
|
|
4
3
|
export declare class HTMLDateRenderer implements Renderer {
|
|
5
4
|
private readonly document;
|
|
6
|
-
private readonly
|
|
7
|
-
constructor(document: Document,
|
|
5
|
+
private readonly queryTimezone;
|
|
6
|
+
constructor(document: Document, queryTimezone: string | undefined);
|
|
8
7
|
render(data: DataColumn): Promise<HTMLElement>;
|
|
9
8
|
}
|
package/dist/html/date.js
CHANGED
|
@@ -26,9 +26,9 @@ exports.HTMLDateRenderer = void 0;
|
|
|
26
26
|
const malloy_1 = require("@malloydata/malloy");
|
|
27
27
|
const utils_1 = require("./utils");
|
|
28
28
|
class HTMLDateRenderer {
|
|
29
|
-
constructor(document,
|
|
29
|
+
constructor(document, queryTimezone) {
|
|
30
30
|
this.document = document;
|
|
31
|
-
this.
|
|
31
|
+
this.queryTimezone = queryTimezone;
|
|
32
32
|
}
|
|
33
33
|
async render(data) {
|
|
34
34
|
if (data.isNull()) {
|
|
@@ -39,7 +39,7 @@ class HTMLDateRenderer {
|
|
|
39
39
|
}
|
|
40
40
|
const timeframe = data.field.timeframe ||
|
|
41
41
|
(data.isTimestamp() ? malloy_1.TimestampTimeframe.Second : malloy_1.DateTimeframe.Day);
|
|
42
|
-
const timestring = (0, utils_1.timeToString)(data.value, timeframe);
|
|
42
|
+
const timestring = (0, utils_1.timeToString)(data.value, timeframe, this.queryTimezone);
|
|
43
43
|
const element = this.document.createElement('span');
|
|
44
44
|
element.appendChild(this.document.createTextNode(timestring));
|
|
45
45
|
return element;
|
package/dist/html/html_view.d.ts
CHANGED
|
@@ -12,4 +12,4 @@ export declare class JSONView {
|
|
|
12
12
|
constructor(document: Document);
|
|
13
13
|
render(table: DataArray): Promise<HTMLElement>;
|
|
14
14
|
}
|
|
15
|
-
export declare function makeRenderer(field: Explore | Field, document: Document, options: RendererOptions, styleDefaults: StyleDefaults): Renderer;
|
|
15
|
+
export declare function makeRenderer(field: Explore | Field, document: Document, options: RendererOptions, styleDefaults: StyleDefaults, queryTimezone: string | undefined): Renderer;
|
package/dist/html/html_view.js
CHANGED
|
@@ -59,7 +59,7 @@ class HTMLView {
|
|
|
59
59
|
async render(table, options) {
|
|
60
60
|
const renderer = makeRenderer(table.field, this.document, options, {
|
|
61
61
|
size: 'large',
|
|
62
|
-
});
|
|
62
|
+
}, table.field.structDef.queryTimezone);
|
|
63
63
|
try {
|
|
64
64
|
// TODO Implement row streaming capability for some renderers: some renderers should be usable
|
|
65
65
|
// as a builder with `begin(field: StructDef)`, `row(field: StructDef, row: QueryDataRow)`,
|
|
@@ -159,7 +159,7 @@ function isContainer(field) {
|
|
|
159
159
|
throw new Error(`${field.name} does not contain fields and cannot be rendered this way`);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
function makeRenderer(field, document, options, styleDefaults) {
|
|
162
|
+
function makeRenderer(field, document, options, styleDefaults, queryTimezone) {
|
|
163
163
|
const renderDef = getRendererOptions(field, options.dataStyles) || {};
|
|
164
164
|
options.dataStyles[field.name] = renderDef;
|
|
165
165
|
if (renderDef.renderer === 'shape_map') {
|
|
@@ -230,7 +230,7 @@ function makeRenderer(field, document, options, styleDefaults) {
|
|
|
230
230
|
field.isAtomicField() &&
|
|
231
231
|
(field.type === malloy_1.AtomicFieldType.Date ||
|
|
232
232
|
field.type === malloy_1.AtomicFieldType.Timestamp))) {
|
|
233
|
-
return new date_1.HTMLDateRenderer(document,
|
|
233
|
+
return new date_1.HTMLDateRenderer(document, queryTimezone);
|
|
234
234
|
}
|
|
235
235
|
else if (renderDef.renderer === 'currency') {
|
|
236
236
|
return new currency_1.HTMLCurrencyRenderer(document);
|
|
@@ -280,7 +280,7 @@ function makeContainerRenderer(cType, document, explore, options) {
|
|
|
280
280
|
const c = container_1.ContainerRenderer.make(cType, document, explore, options);
|
|
281
281
|
const result = {};
|
|
282
282
|
explore.intrinsicFields.forEach((field) => {
|
|
283
|
-
result[field.name] = makeRenderer(field, document, options, c.defaultStylesForChildren);
|
|
283
|
+
result[field.name] = makeRenderer(field, document, options, c.defaultStylesForChildren, explore.queryTimezone);
|
|
284
284
|
});
|
|
285
285
|
c.childRenderers = result;
|
|
286
286
|
return c;
|
package/dist/html/table.js
CHANGED
|
@@ -27,6 +27,7 @@ const drill_1 = require("../drill");
|
|
|
27
27
|
const container_1 = require("./container");
|
|
28
28
|
const number_1 = require("./number");
|
|
29
29
|
const utils_1 = require("./utils");
|
|
30
|
+
const date_1 = require("./date");
|
|
30
31
|
class HTMLTableRenderer extends container_1.ContainerRenderer {
|
|
31
32
|
constructor() {
|
|
32
33
|
super(...arguments);
|
|
@@ -40,9 +41,10 @@ class HTMLTableRenderer extends container_1.ContainerRenderer {
|
|
|
40
41
|
}
|
|
41
42
|
const header = this.document.createElement('tr');
|
|
42
43
|
table.field.intrinsicFields.forEach(field => {
|
|
43
|
-
|
|
44
|
+
let name = (0, utils_1.formatTitle)(this.options, field.name, this.options.dataStyles[field.name]);
|
|
44
45
|
const childRenderer = this.childRenderers[name];
|
|
45
46
|
const isNumeric = childRenderer instanceof number_1.HTMLNumberRenderer;
|
|
47
|
+
const isDateTime = childRenderer instanceof date_1.HTMLDateRenderer;
|
|
46
48
|
const headerCell = this.document.createElement('th');
|
|
47
49
|
headerCell.style.cssText = `
|
|
48
50
|
padding: 8px;
|
|
@@ -50,7 +52,11 @@ class HTMLTableRenderer extends container_1.ContainerRenderer {
|
|
|
50
52
|
border-bottom: 1px solid var(--malloy-border-color, #eaeaea);
|
|
51
53
|
text-align: ${isNumeric ? 'right' : 'left'};
|
|
52
54
|
`;
|
|
53
|
-
|
|
55
|
+
name = name.replace(/_/g, '_​');
|
|
56
|
+
if (isDateTime && field.parentExplore.structDef.queryTimezone) {
|
|
57
|
+
name = `${name} (${field.parentExplore.structDef.queryTimezone})`;
|
|
58
|
+
}
|
|
59
|
+
headerCell.innerHTML = name;
|
|
54
60
|
header.appendChild(headerCell);
|
|
55
61
|
});
|
|
56
62
|
if (this.options.isDrillingEnabled) {
|
package/dist/html/utils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { RendererOptions } from '../renderer_types';
|
|
|
4
4
|
export declare function getColorScale(type: 'temporal' | 'ordinal' | 'quantitative' | 'nominal' | undefined, isRectMark: boolean, hasOverlappingText?: boolean): {
|
|
5
5
|
range: string[];
|
|
6
6
|
} | undefined;
|
|
7
|
-
export declare function timeToString(time: Date, timeframe: DateTimeframe | TimestampTimeframe): string;
|
|
7
|
+
export declare function timeToString(time: Date, timeframe: DateTimeframe | TimestampTimeframe, timezone?: string): string;
|
|
8
8
|
export declare function yieldTask(): Promise<void>;
|
|
9
9
|
export declare function createErrorElement(document: Document, error: string | Error): HTMLElement;
|
|
10
10
|
export declare function createNullElement(document: Document): HTMLElement;
|
package/dist/html/utils.js
CHANGED
|
@@ -28,6 +28,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
28
28
|
exports.formatTitle = exports.createDrillIcon = exports.createNullElement = exports.createErrorElement = exports.yieldTask = exports.timeToString = exports.getColorScale = void 0;
|
|
29
29
|
const malloy_1 = require("@malloydata/malloy");
|
|
30
30
|
const startCase_1 = __importDefault(require("lodash/startCase"));
|
|
31
|
+
const luxon_1 = require("luxon");
|
|
31
32
|
function getColorScale(type, isRectMark, hasOverlappingText = false) {
|
|
32
33
|
if (type === undefined) {
|
|
33
34
|
return undefined;
|
|
@@ -74,61 +75,62 @@ exports.getColorScale = getColorScale;
|
|
|
74
75
|
function numberFixedDigits(value, digits) {
|
|
75
76
|
return value.toString().padStart(digits, '0');
|
|
76
77
|
}
|
|
77
|
-
function timeToString(time, timeframe) {
|
|
78
|
+
function timeToString(time, timeframe, timezone) {
|
|
79
|
+
const dateTime = luxon_1.DateTime.fromJSDate(time, { zone: timezone });
|
|
78
80
|
switch (timeframe) {
|
|
79
81
|
case malloy_1.TimestampTimeframe.Year:
|
|
80
82
|
case malloy_1.DateTimeframe.Year: {
|
|
81
|
-
const year = numberFixedDigits(
|
|
83
|
+
const year = numberFixedDigits(dateTime.year, 4);
|
|
82
84
|
return `${year}`;
|
|
83
85
|
}
|
|
84
86
|
case malloy_1.TimestampTimeframe.Quarter:
|
|
85
87
|
case malloy_1.DateTimeframe.Quarter: {
|
|
86
|
-
const year = numberFixedDigits(
|
|
87
|
-
const quarter = Math.floor(
|
|
88
|
+
const year = numberFixedDigits(dateTime.year, 4);
|
|
89
|
+
const quarter = Math.floor(dateTime.month / 3) + 1;
|
|
88
90
|
return `${year}-Q${quarter}`;
|
|
89
91
|
}
|
|
90
92
|
case malloy_1.TimestampTimeframe.Month:
|
|
91
93
|
case malloy_1.DateTimeframe.Month: {
|
|
92
|
-
const year = numberFixedDigits(
|
|
93
|
-
const month = numberFixedDigits(
|
|
94
|
+
const year = numberFixedDigits(dateTime.year, 2);
|
|
95
|
+
const month = numberFixedDigits(dateTime.month, 2);
|
|
94
96
|
return `${year}-${month}`;
|
|
95
97
|
}
|
|
96
98
|
case malloy_1.TimestampTimeframe.Week:
|
|
97
99
|
case malloy_1.DateTimeframe.Week: {
|
|
98
|
-
const year = numberFixedDigits(
|
|
99
|
-
const month = numberFixedDigits(
|
|
100
|
-
const day = numberFixedDigits(
|
|
100
|
+
const year = numberFixedDigits(dateTime.year, 2);
|
|
101
|
+
const month = numberFixedDigits(dateTime.month, 2);
|
|
102
|
+
const day = numberFixedDigits(dateTime.day, 2);
|
|
101
103
|
return `WK${year}-${month}-${day}`;
|
|
102
104
|
}
|
|
103
105
|
case malloy_1.DateTimeframe.Day:
|
|
104
106
|
case malloy_1.TimestampTimeframe.Day: {
|
|
105
|
-
const year = numberFixedDigits(
|
|
106
|
-
const month = numberFixedDigits(
|
|
107
|
-
const day = numberFixedDigits(
|
|
107
|
+
const year = numberFixedDigits(dateTime.year, 2);
|
|
108
|
+
const month = numberFixedDigits(dateTime.month, 2);
|
|
109
|
+
const day = numberFixedDigits(dateTime.day, 2);
|
|
108
110
|
return `${year}-${month}-${day}`;
|
|
109
111
|
}
|
|
110
112
|
case malloy_1.TimestampTimeframe.Hour: {
|
|
111
|
-
const year = numberFixedDigits(
|
|
112
|
-
const month = numberFixedDigits(
|
|
113
|
-
const day = numberFixedDigits(
|
|
114
|
-
const hour = numberFixedDigits(
|
|
113
|
+
const year = numberFixedDigits(dateTime.year, 2);
|
|
114
|
+
const month = numberFixedDigits(dateTime.month, 2);
|
|
115
|
+
const day = numberFixedDigits(dateTime.day, 2);
|
|
116
|
+
const hour = numberFixedDigits(dateTime.hour, 2);
|
|
115
117
|
return `${year}-${month}-${day} ${hour}:00 for 1 hour`;
|
|
116
118
|
}
|
|
117
119
|
case malloy_1.TimestampTimeframe.Minute: {
|
|
118
|
-
const year = numberFixedDigits(
|
|
119
|
-
const month = numberFixedDigits(
|
|
120
|
-
const day = numberFixedDigits(
|
|
121
|
-
const hour = numberFixedDigits(
|
|
122
|
-
const minute = numberFixedDigits(
|
|
120
|
+
const year = numberFixedDigits(dateTime.year, 2);
|
|
121
|
+
const month = numberFixedDigits(dateTime.month, 2);
|
|
122
|
+
const day = numberFixedDigits(dateTime.day, 2);
|
|
123
|
+
const hour = numberFixedDigits(dateTime.hour, 2);
|
|
124
|
+
const minute = numberFixedDigits(dateTime.minute, 2);
|
|
123
125
|
return `${year}-${month}-${day} ${hour}:${minute}`;
|
|
124
126
|
}
|
|
125
127
|
case malloy_1.TimestampTimeframe.Second: {
|
|
126
|
-
const year = numberFixedDigits(
|
|
127
|
-
const month = numberFixedDigits(
|
|
128
|
-
const day = numberFixedDigits(
|
|
129
|
-
const hour = numberFixedDigits(
|
|
130
|
-
const minute = numberFixedDigits(
|
|
131
|
-
const second = numberFixedDigits(
|
|
128
|
+
const year = numberFixedDigits(dateTime.year, 2);
|
|
129
|
+
const month = numberFixedDigits(dateTime.month, 2);
|
|
130
|
+
const day = numberFixedDigits(dateTime.day, 2);
|
|
131
|
+
const hour = numberFixedDigits(dateTime.hour, 2);
|
|
132
|
+
const minute = numberFixedDigits(dateTime.minute, 2);
|
|
133
|
+
const second = numberFixedDigits(dateTime.second, 2);
|
|
132
134
|
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
|
133
135
|
}
|
|
134
136
|
default:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.43-
|
|
3
|
+
"version": "0.0.43-dev230620232755",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,8 +18,10 @@
|
|
|
18
18
|
"prepublishOnly": "npm run build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@malloydata/malloy": "^0.0.43-
|
|
21
|
+
"@malloydata/malloy": "^0.0.43-dev230620232755",
|
|
22
|
+
"@types/luxon": "^2.4.0",
|
|
22
23
|
"lodash": "^4.17.20",
|
|
24
|
+
"luxon": "^2.4.0",
|
|
23
25
|
"us-atlas": "^3.0.0",
|
|
24
26
|
"vega": "^5.21.0",
|
|
25
27
|
"vega-lite": "^5.2.0"
|