@malloydata/render 0.0.1

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.
Files changed (66) hide show
  1. package/README.md +7 -0
  2. package/dist/data_styles.d.ts +181 -0
  3. package/dist/data_styles.js +15 -0
  4. package/dist/drill.d.ts +10 -0
  5. package/dist/drill.js +103 -0
  6. package/dist/html/bar_chart.d.ts +7 -0
  7. package/dist/html/bar_chart.js +48 -0
  8. package/dist/html/boolean.d.ts +5 -0
  9. package/dist/html/boolean.js +26 -0
  10. package/dist/html/bytes.d.ts +5 -0
  11. package/dist/html/bytes.js +26 -0
  12. package/dist/html/cartesian_chart.d.ts +7 -0
  13. package/dist/html/cartesian_chart.js +88 -0
  14. package/dist/html/chart.d.ts +21 -0
  15. package/dist/html/chart.js +105 -0
  16. package/dist/html/container.d.ts +21 -0
  17. package/dist/html/container.js +43 -0
  18. package/dist/html/currency.d.ts +5 -0
  19. package/dist/html/currency.js +32 -0
  20. package/dist/html/dashboard.d.ts +7 -0
  21. package/dist/html/dashboard.js +224 -0
  22. package/dist/html/date.d.ts +7 -0
  23. package/dist/html/date.js +38 -0
  24. package/dist/html/html_view.d.ts +23 -0
  25. package/dist/html/html_view.js +217 -0
  26. package/dist/html/image.d.ts +7 -0
  27. package/dist/html/image.js +34 -0
  28. package/dist/html/index.d.ts +1 -0
  29. package/dist/html/index.js +18 -0
  30. package/dist/html/json.d.ts +7 -0
  31. package/dist/html/json.js +31 -0
  32. package/dist/html/line_chart.d.ts +7 -0
  33. package/dist/html/line_chart.js +51 -0
  34. package/dist/html/link.d.ts +7 -0
  35. package/dist/html/link.js +35 -0
  36. package/dist/html/list.d.ts +9 -0
  37. package/dist/html/list.js +63 -0
  38. package/dist/html/list_detail.d.ts +5 -0
  39. package/dist/html/list_detail.js +23 -0
  40. package/dist/html/number.d.ts +6 -0
  41. package/dist/html/number.js +30 -0
  42. package/dist/html/percent.d.ts +5 -0
  43. package/dist/html/percent.js +26 -0
  44. package/dist/html/point_map.d.ts +8 -0
  45. package/dist/html/point_map.js +147 -0
  46. package/dist/html/scatter_chart.d.ts +7 -0
  47. package/dist/html/scatter_chart.js +51 -0
  48. package/dist/html/segment_map.d.ts +8 -0
  49. package/dist/html/segment_map.js +128 -0
  50. package/dist/html/shape_map.d.ts +10 -0
  51. package/dist/html/shape_map.js +171 -0
  52. package/dist/html/state_codes.d.ts +3 -0
  53. package/dist/html/state_codes.js +127 -0
  54. package/dist/html/table.d.ts +7 -0
  55. package/dist/html/table.js +111 -0
  56. package/dist/html/text.d.ts +8 -0
  57. package/dist/html/text.js +35 -0
  58. package/dist/html/utils.d.ts +18 -0
  59. package/dist/html/utils.js +175 -0
  60. package/dist/html/vega_spec.d.ts +18 -0
  61. package/dist/html/vega_spec.js +499 -0
  62. package/dist/index.d.ts +2 -0
  63. package/dist/index.js +19 -0
  64. package/dist/renderer.d.ts +21 -0
  65. package/dist/renderer.js +23 -0
  66. package/package.json +17 -0
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * version 2 as published by the Free Software Foundation.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createDrillIcon = exports.createNullElement = exports.createErrorElement = exports.yieldTask = exports.timeToString = exports.getColorScale = void 0;
16
+ const malloy_1 = require("@malloydata/malloy");
17
+ function getColorScale(type, isRectMark, hasOverlappingText = false) {
18
+ if (type === undefined) {
19
+ return undefined;
20
+ }
21
+ switch (type) {
22
+ case "ordinal":
23
+ return { range: ["#C2D5EE", "#1A73E8"] };
24
+ case "temporal":
25
+ case "quantitative":
26
+ return isRectMark
27
+ ? hasOverlappingText
28
+ ? { range: ["#6BA4EE", "#EEA361"] }
29
+ : { range: ["#1A73E8", "#E8710A"] }
30
+ : { range: ["#C2D5EE", "#1A73E8"] };
31
+ case "nominal":
32
+ return hasOverlappingText
33
+ ? {
34
+ range: [
35
+ "#6BA4EE",
36
+ "#66CEDC",
37
+ "#EC72B8",
38
+ "#EEA361",
39
+ "#F9C85B",
40
+ "#AACD85",
41
+ "#B87CED",
42
+ "#ACB0B3",
43
+ ],
44
+ }
45
+ : {
46
+ range: [
47
+ "#1A73E8",
48
+ "#12B5CB",
49
+ "#E52592",
50
+ "#E8710A",
51
+ "#F9AB00",
52
+ "#7CB342",
53
+ "#9334E6",
54
+ "#80868B",
55
+ ],
56
+ };
57
+ }
58
+ }
59
+ exports.getColorScale = getColorScale;
60
+ function numberFixedDigits(value, digits) {
61
+ return value.toString().padStart(digits, "0");
62
+ }
63
+ function timeToString(time, timeframe) {
64
+ switch (timeframe) {
65
+ case malloy_1.TimestampTimeframe.Year:
66
+ case malloy_1.DateTimeframe.Year: {
67
+ const year = numberFixedDigits(time.getUTCFullYear(), 4);
68
+ return `${year}`;
69
+ }
70
+ case malloy_1.TimestampTimeframe.Quarter:
71
+ case malloy_1.DateTimeframe.Quarter: {
72
+ const year = numberFixedDigits(time.getUTCFullYear(), 4);
73
+ const quarter = Math.floor(time.getUTCMonth() / 3) + 1;
74
+ return `${year}-Q${quarter}`;
75
+ }
76
+ case malloy_1.TimestampTimeframe.Month:
77
+ case malloy_1.DateTimeframe.Month: {
78
+ const year = numberFixedDigits(time.getUTCFullYear(), 2);
79
+ const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
80
+ return `${year}-${month}`;
81
+ }
82
+ case malloy_1.TimestampTimeframe.Week:
83
+ case malloy_1.DateTimeframe.Week: {
84
+ const year = numberFixedDigits(time.getUTCFullYear(), 2);
85
+ const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
86
+ const day = numberFixedDigits(time.getUTCDate(), 2);
87
+ return `WK${year}-${month}-${day}`;
88
+ }
89
+ case malloy_1.DateTimeframe.Day:
90
+ case malloy_1.TimestampTimeframe.Day: {
91
+ const year = numberFixedDigits(time.getUTCFullYear(), 2);
92
+ const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
93
+ const day = numberFixedDigits(time.getUTCDate(), 2);
94
+ return `${year}-${month}-${day}`;
95
+ }
96
+ case malloy_1.TimestampTimeframe.Hour: {
97
+ const year = numberFixedDigits(time.getUTCFullYear(), 2);
98
+ const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
99
+ const day = numberFixedDigits(time.getUTCDate(), 2);
100
+ const hour = numberFixedDigits(time.getUTCHours(), 2);
101
+ return `${year}-${month}-${day} ${hour}:00 for 1 hour`;
102
+ }
103
+ case malloy_1.TimestampTimeframe.Minute: {
104
+ const year = numberFixedDigits(time.getUTCFullYear(), 2);
105
+ const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
106
+ const day = numberFixedDigits(time.getUTCDate(), 2);
107
+ const hour = numberFixedDigits(time.getUTCHours(), 2);
108
+ const minute = numberFixedDigits(time.getUTCMinutes(), 2);
109
+ return `${year}-${month}-${day} ${hour}:${minute}`;
110
+ }
111
+ case malloy_1.TimestampTimeframe.Second: {
112
+ const year = numberFixedDigits(time.getUTCFullYear(), 2);
113
+ const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
114
+ const day = numberFixedDigits(time.getUTCDate(), 2);
115
+ const hour = numberFixedDigits(time.getUTCHours(), 2);
116
+ const minute = numberFixedDigits(time.getUTCMinutes(), 2);
117
+ const second = numberFixedDigits(time.getUTCSeconds(), 2);
118
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
119
+ }
120
+ default:
121
+ throw new Error("Unknown timeframe.");
122
+ }
123
+ }
124
+ exports.timeToString = timeToString;
125
+ /**
126
+ * Use this function to break up expensive computation over multiple tasks.
127
+ *
128
+ * @returns A promise, which when awaited, puts subsequent code in a separate task.
129
+ *
130
+ * This is useful for cases when expensive code needs to run "concurrently" with a
131
+ * rendering / UI task. Sprinkling in `yieldTask`s into a long task allows other
132
+ * tasks to run periodically.
133
+ */
134
+ async function yieldTask() {
135
+ return new Promise((resolve) => {
136
+ setTimeout(resolve, 0);
137
+ });
138
+ }
139
+ exports.yieldTask = yieldTask;
140
+ function createErrorElement(document, error) {
141
+ const element = document.createElement("span");
142
+ element.classList.add("error");
143
+ element.appendChild(document.createTextNode(typeof error === "string" ? error : error.message));
144
+ return element;
145
+ }
146
+ exports.createErrorElement = createErrorElement;
147
+ function createNullElement(document) {
148
+ const element = document.createElement("span");
149
+ element.appendChild(document.createTextNode("∅"));
150
+ element.classList.add("value-null");
151
+ return element;
152
+ }
153
+ exports.createNullElement = createNullElement;
154
+ function createDrillIcon(document) {
155
+ const drill = document.createElement("div");
156
+ drill.style.borderRadius = "20px";
157
+ drill.style.backgroundColor = "var(--malloy-border-color, #efefef)";
158
+ drill.style.width = "27px";
159
+ drill.style.height = "14px";
160
+ drill.style.display = "flex";
161
+ drill.style.justifyContent = "center";
162
+ drill.style.alignItems = "center";
163
+ drill.style.gap = "2px";
164
+ for (let i = 0; i < 3; i++) {
165
+ const dot = document.createElement("div");
166
+ dot.style.backgroundColor = "var(--malloy-title-color, rgb(181 181 181))";
167
+ dot.style.borderRadius = "5px";
168
+ dot.style.width = "4px";
169
+ dot.style.height = "4px";
170
+ drill.appendChild(dot);
171
+ }
172
+ return drill;
173
+ }
174
+ exports.createDrillIcon = createDrillIcon;
175
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,18 @@
1
+ import * as lite from "vega-lite";
2
+ import { DataColumn, Explore, Field } from "@malloydata/malloy";
3
+ import { HTMLChartRenderer } from "./chart";
4
+ import { StyleDefaults } from "../data_styles";
5
+ declare type DataContainer = Array<unknown> | Record<string, unknown>;
6
+ export declare const DEFAULT_SPEC: Partial<lite.TopLevelSpec>;
7
+ export declare const vegaSpecs: Record<string, lite.TopLevelSpec>;
8
+ export declare function isDataContainer(a: unknown): a is DataContainer;
9
+ export declare class HTMLVegaSpecRenderer extends HTMLChartRenderer {
10
+ spec: lite.TopLevelSpec;
11
+ constructor(document: Document, styleDefaults: StyleDefaults, spec: lite.TopLevelSpec);
12
+ getDataValue(data: DataColumn): Date | string | number | null;
13
+ getDataType(field: Field): "ordinal" | "quantitative" | "nominal";
14
+ translateField(explore: Explore, fieldString: string): string;
15
+ translateFields(node: DataContainer, explore: Explore): void;
16
+ getVegaLiteSpec(data: DataColumn): lite.TopLevelSpec;
17
+ }
18
+ export {};
@@ -0,0 +1,499 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * version 2 as published by the Free Software Foundation.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.HTMLVegaSpecRenderer = exports.isDataContainer = exports.vegaSpecs = exports.DEFAULT_SPEC = void 0;
16
+ const chart_1 = require("./chart");
17
+ const lodash_1 = require("lodash");
18
+ const utils_1 = require("./utils");
19
+ exports.DEFAULT_SPEC = {
20
+ $schema: "https://vega.github.io/schema/vega-lite/v5.json",
21
+ config: {
22
+ params: [
23
+ {
24
+ name: "defaultFont",
25
+ value: "var(--malloy-font-family, 'Roboto')",
26
+ },
27
+ { name: "titleColor", value: "var(--malloy-title-color, #505050)" },
28
+ { name: "labelColor", value: "var(--malloy-label-color, #505050)" },
29
+ ],
30
+ background: undefined,
31
+ color: { expr: "titleColor" },
32
+ header: {
33
+ labelFont: { expr: "defaultFont" },
34
+ titleFont: { expr: "defaultFont" },
35
+ titleFontWeight: 500,
36
+ },
37
+ text: {
38
+ font: { expr: "defaultFont" },
39
+ color: { expr: "labelColor" },
40
+ },
41
+ mark: {
42
+ font: { expr: "defaultFont" },
43
+ color: { expr: "labelColor" },
44
+ },
45
+ title: {
46
+ font: { expr: "defaultFont" },
47
+ subtitleFont: { expr: "defaultFont" },
48
+ fontWeight: 500,
49
+ },
50
+ axis: {
51
+ labelColor: { expr: "labelColor" },
52
+ labelFont: { expr: "defaultFont" },
53
+ titleFont: { expr: "defaultFont" },
54
+ titleFontWeight: 500,
55
+ titleColor: { expr: "titleColor" },
56
+ titleFontSize: 12,
57
+ },
58
+ legend: {
59
+ titleFontWeight: 500,
60
+ titleColor: { expr: "titleColor" },
61
+ titleFontSize: 12,
62
+ labelColor: { expr: "labelColor" },
63
+ labelFont: { expr: "defaultFont" },
64
+ titleFont: { expr: "defaultFont" },
65
+ },
66
+ },
67
+ };
68
+ const sizeSmall = {
69
+ height: 80,
70
+ width: 150,
71
+ };
72
+ const sizeSmallWidth = {
73
+ width: 150,
74
+ };
75
+ const sizeSmallHeightStep = {
76
+ height: { step: 13 },
77
+ };
78
+ const sizeSmallStep = { ...sizeSmallWidth, ...sizeSmallHeightStep };
79
+ const sizeMediumStep = { ...sizeSmallWidth };
80
+ const sizeMedium = {
81
+ height: 150,
82
+ width: 200,
83
+ };
84
+ const sizeLarge = {
85
+ // height: 350,
86
+ // width: 500,
87
+ };
88
+ // bar with text in the bars.
89
+ const bar_SM = {
90
+ ...exports.DEFAULT_SPEC,
91
+ encoding: {
92
+ y: { field: "#{1}", type: "nominal", axis: null, sort: null },
93
+ },
94
+ layer: [
95
+ {
96
+ mark: { type: "bar", color: "#aec7e8" },
97
+ encoding: {
98
+ x: {
99
+ field: "#{2}",
100
+ type: "quantitative",
101
+ sort: null,
102
+ },
103
+ color: { value: "#4285F4" },
104
+ },
105
+ },
106
+ {
107
+ mark: { type: "text", align: "left", x: 5 },
108
+ encoding: {
109
+ text: { field: "#{1}" },
110
+ },
111
+ },
112
+ ],
113
+ };
114
+ const bar_SM_large = {
115
+ ...exports.DEFAULT_SPEC,
116
+ mark: "bar",
117
+ data: [],
118
+ encoding: {
119
+ x: { field: "#{1}", type: "nominal", sort: null },
120
+ y: { field: "#{2}", type: "quantitative", sort: null },
121
+ color: { value: "#4285F4" },
122
+ },
123
+ };
124
+ const bar_SMM_large = {
125
+ ...bar_SM_large,
126
+ encoding: {
127
+ ...bar_SM_large.encoding,
128
+ color: {
129
+ field: "#{3}",
130
+ type: "quantitative",
131
+ scale: (0, utils_1.getColorScale)("quantitative", true, true),
132
+ },
133
+ },
134
+ };
135
+ const bar_SMS_large = {
136
+ ...bar_SM_large,
137
+ encoding: {
138
+ ...bar_SM_large.encoding,
139
+ color: {
140
+ field: "#{3}",
141
+ scale: (0, utils_1.getColorScale)("nominal", true, true),
142
+ },
143
+ },
144
+ };
145
+ const bar_SMS = {
146
+ ...bar_SM,
147
+ layer: [
148
+ {
149
+ ...bar_SM.layer[0],
150
+ encoding: {
151
+ ...bar_SM.layer[0].encoding,
152
+ color: {
153
+ field: "#{3}",
154
+ scale: (0, utils_1.getColorScale)("nominal", true, true),
155
+ },
156
+ },
157
+ },
158
+ bar_SM.layer[1],
159
+ ],
160
+ };
161
+ const bar_SMM = {
162
+ ...bar_SM,
163
+ layer: [
164
+ {
165
+ ...bar_SM.layer[0],
166
+ encoding: {
167
+ ...bar_SM.layer[0].encoding,
168
+ color: {
169
+ field: "#{3}",
170
+ type: "quantitative",
171
+ scale: (0, utils_1.getColorScale)("quantitative", true, true),
172
+ },
173
+ },
174
+ },
175
+ bar_SM.layer[1],
176
+ ],
177
+ };
178
+ // simple column chart
179
+ const bar_NM = {
180
+ ...exports.DEFAULT_SPEC,
181
+ mark: "bar",
182
+ data: [],
183
+ encoding: {
184
+ x: { field: "#{1}", type: "nominal", sort: null },
185
+ y: { field: "#{2}", type: "quantitative", sort: null },
186
+ color: { value: "#4285F4" },
187
+ },
188
+ };
189
+ const bar_NMS = {
190
+ ...bar_NM,
191
+ encoding: {
192
+ ...bar_NM.encoding,
193
+ color: {
194
+ field: "#{3}",
195
+ type: "nominal",
196
+ scale: (0, utils_1.getColorScale)("nominal", true),
197
+ },
198
+ },
199
+ };
200
+ const bar_NMM = {
201
+ ...bar_NM,
202
+ encoding: {
203
+ ...bar_NM.encoding,
204
+ color: {
205
+ field: "#{3}",
206
+ type: "quantitative",
207
+ scale: (0, utils_1.getColorScale)("quantitative", true),
208
+ },
209
+ },
210
+ };
211
+ exports.vegaSpecs = {
212
+ bar_SM,
213
+ bar_SM_small: { ...bar_SM, ...sizeSmallStep },
214
+ bar_SM_medium: { ...bar_SM, ...sizeMediumStep },
215
+ bar_SM_large,
216
+ bar_SMS,
217
+ bar_SMS_small: { ...bar_SMS, ...sizeSmallStep },
218
+ bar_SMS_medium: { ...bar_SMS, ...sizeMediumStep },
219
+ bar_SMS_large,
220
+ bar_SMM,
221
+ bar_SMM_small: { ...bar_SMM, ...sizeSmallStep },
222
+ bar_SMM_medium: { ...bar_SMM, ...sizeMediumStep },
223
+ bar_SMM_large,
224
+ bar_NM,
225
+ bar_NM_small: { ...bar_NM, ...sizeSmall },
226
+ bar_NM_medium: { ...bar_NM, ...sizeMedium },
227
+ bar_NM_large: { ...bar_NM },
228
+ bar_NMS,
229
+ bar_NMS_small: { ...bar_NMS, ...sizeSmall },
230
+ bar_NMS_medium: { ...bar_NMS, ...sizeMedium },
231
+ bar_NMS_large: { ...bar_NMS, ...sizeLarge },
232
+ bar_NMM,
233
+ bar_NMM_small: { ...bar_NMM, ...sizeSmall },
234
+ bar_NMM_medium: { ...bar_NMM, ...sizeMedium },
235
+ bar_NMM_large: { ...bar_NMM, ...sizeLarge },
236
+ bar_SSMMM: {
237
+ ...exports.DEFAULT_SPEC,
238
+ repeat: ["#{3}", "#{4}", "#{5}"],
239
+ spec: {
240
+ description: "A simple bar chart with embedded data.",
241
+ encoding: {
242
+ y: { field: "#{1}", type: "nominal", axis: null, sort: null },
243
+ },
244
+ layer: [
245
+ {
246
+ mark: {
247
+ type: "bar",
248
+ },
249
+ encoding: {
250
+ x: {
251
+ field: { repeat: "repeat" },
252
+ type: "quantitative",
253
+ sort: null,
254
+ },
255
+ color: {
256
+ field: "#{2}",
257
+ scale: (0, utils_1.getColorScale)("nominal", true, true),
258
+ },
259
+ },
260
+ },
261
+ {
262
+ mark: { type: "text", align: "left", x: 5 },
263
+ encoding: {
264
+ text: { field: "#{1}" },
265
+ detail: { aggregate: "count" },
266
+ },
267
+ },
268
+ ],
269
+ },
270
+ },
271
+ bubble_NNM: {
272
+ ...exports.DEFAULT_SPEC,
273
+ data: [],
274
+ mark: "circle",
275
+ width: 400,
276
+ encoding: {
277
+ y: {
278
+ field: "#{1}",
279
+ type: "ordinal",
280
+ sort: null,
281
+ },
282
+ x: {
283
+ field: "#{2}",
284
+ type: "ordinal",
285
+ sort: null,
286
+ },
287
+ size: {
288
+ field: "#{3}",
289
+ type: "quantitative",
290
+ },
291
+ color: { value: "#4285F4" },
292
+ },
293
+ },
294
+ heat_NNM: {
295
+ ...exports.DEFAULT_SPEC,
296
+ data: [],
297
+ mark: "bar",
298
+ width: 400,
299
+ encoding: {
300
+ y: {
301
+ field: "#{1}",
302
+ type: "ordinal",
303
+ sort: null,
304
+ },
305
+ x: {
306
+ field: "#{2}",
307
+ type: "ordinal",
308
+ sort: null,
309
+ },
310
+ color: {
311
+ field: "#{3}",
312
+ type: "quantitative",
313
+ scale: (0, utils_1.getColorScale)("quantitative", false),
314
+ },
315
+ },
316
+ },
317
+ heat_SNM: {
318
+ ...exports.DEFAULT_SPEC,
319
+ data: [],
320
+ mark: "bar",
321
+ width: 400,
322
+ encoding: {
323
+ y: {
324
+ field: "#{1}",
325
+ type: "nominal",
326
+ sort: null,
327
+ },
328
+ x: {
329
+ field: "#{2}",
330
+ type: "ordinal",
331
+ sort: null,
332
+ },
333
+ color: {
334
+ field: "#{3}",
335
+ type: "quantitative",
336
+ scale: (0, utils_1.getColorScale)("quantitative", false),
337
+ },
338
+ },
339
+ },
340
+ stacked_line_STM: {
341
+ ...exports.DEFAULT_SPEC,
342
+ height: 50,
343
+ data: [],
344
+ mark: "area",
345
+ encoding: {
346
+ x: {
347
+ field: "#{2}",
348
+ type: "temporal",
349
+ axis: { grid: false },
350
+ sort: null,
351
+ },
352
+ y: {
353
+ field: "#{3}",
354
+ type: "quantitative",
355
+ axis: { grid: false },
356
+ title: null,
357
+ sort: null,
358
+ },
359
+ color: {
360
+ field: "#{1}",
361
+ type: "nominal",
362
+ legend: null,
363
+ scale: (0, utils_1.getColorScale)("nominal", false),
364
+ },
365
+ row: {
366
+ field: "#{1}",
367
+ type: "nominal",
368
+ },
369
+ },
370
+ },
371
+ grid_line_SSTM: {
372
+ ...exports.DEFAULT_SPEC,
373
+ height: 50,
374
+ data: [],
375
+ mark: "area",
376
+ encoding: {
377
+ x: {
378
+ field: "#{3}",
379
+ type: "temporal",
380
+ axis: { grid: false },
381
+ sort: null,
382
+ },
383
+ y: {
384
+ field: "#{4}",
385
+ type: "quantitative",
386
+ axis: { grid: false },
387
+ title: null,
388
+ sort: null,
389
+ },
390
+ color: {
391
+ field: "#{1}",
392
+ type: "nominal",
393
+ legend: null,
394
+ scale: (0, utils_1.getColorScale)("nominal", false),
395
+ },
396
+ row: {
397
+ field: "#{1}",
398
+ type: "nominal",
399
+ },
400
+ column: {
401
+ field: "#{2}",
402
+ type: "nominal",
403
+ },
404
+ },
405
+ },
406
+ };
407
+ function isDataContainer(a) {
408
+ return Array.isArray(a) || (a !== null && typeof a === "object");
409
+ }
410
+ exports.isDataContainer = isDataContainer;
411
+ class HTMLVegaSpecRenderer extends chart_1.HTMLChartRenderer {
412
+ constructor(document, styleDefaults, spec) {
413
+ super(document, styleDefaults);
414
+ this.spec = spec;
415
+ }
416
+ getDataValue(data) {
417
+ if (data.isNull()) {
418
+ return null;
419
+ }
420
+ else if (data.isTimestamp() ||
421
+ data.isDate() ||
422
+ data.isNumber() ||
423
+ data.isString()) {
424
+ return data.value;
425
+ }
426
+ else {
427
+ throw new Error("Invalid field type for vega chart.");
428
+ }
429
+ }
430
+ getDataType(field) {
431
+ if (field.isAtomicField()) {
432
+ if (field.isDate() || field.isTimestamp() || field.isString()) {
433
+ return "nominal";
434
+ }
435
+ else if (field.isNumber()) {
436
+ return "quantitative";
437
+ }
438
+ }
439
+ throw new Error("Invalid field type for vega chart.");
440
+ }
441
+ translateField(explore, fieldString) {
442
+ const m = fieldString.match(/#\{(?<fieldnum>\d+)\}/);
443
+ if (m && m.groups) {
444
+ return explore.intrinsicFields[parseInt(m.groups["fieldnum"]) - 1].name;
445
+ }
446
+ return fieldString;
447
+ }
448
+ translateFields(node, explore) {
449
+ if (Array.isArray(node)) {
450
+ for (const e of node) {
451
+ if (isDataContainer(e)) {
452
+ this.translateFields(e, explore);
453
+ }
454
+ }
455
+ }
456
+ else if (node && typeof node === "object") {
457
+ for (const [key, value] of Object.entries(node)) {
458
+ if (key === "field" && typeof value === "string") {
459
+ node[key] = this.translateField(explore, value);
460
+ }
461
+ else if (key === "repeat" && Array.isArray(value)) {
462
+ for (const k of value.keys()) {
463
+ const fieldName = value[k];
464
+ if (typeof fieldName === "string") {
465
+ value[k] = this.translateField(explore, fieldName);
466
+ }
467
+ }
468
+ }
469
+ else {
470
+ if (isDataContainer(value)) {
471
+ this.translateFields(value, explore);
472
+ }
473
+ }
474
+ }
475
+ }
476
+ }
477
+ // formatData(data: QueryDataRow, metadata: StructDef): VegaData {
478
+ // const ret: VegaData = [];
479
+ // for (const row of QueryDataRow) {
480
+ // forEach){
481
+ // }
482
+ // }
483
+ // return ret;
484
+ // }
485
+ getVegaLiteSpec(data) {
486
+ if (data.isNull() || !data.isArray()) {
487
+ throw new Error("Expected struct value not to be null.");
488
+ }
489
+ const newSpec = (0, lodash_1.cloneDeep)(this.spec);
490
+ this.translateFields(newSpec, data.field);
491
+ const rdata = {
492
+ values: this.mapData(data),
493
+ };
494
+ newSpec.data = rdata;
495
+ return newSpec;
496
+ }
497
+ }
498
+ exports.HTMLVegaSpecRenderer = HTMLVegaSpecRenderer;
499
+ //# sourceMappingURL=vega_spec.js.map
@@ -0,0 +1,2 @@
1
+ export { HTMLView, JSONView } from "./html/html_view";
2
+ export type { DataStyles } from "./data_styles";