@malloydata/render 0.0.135-dev240325191847 → 0.0.135-dev240326020414

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 (86) hide show
  1. package/dist/component/render-webcomponent.d.ts +6 -0
  2. package/dist/component/render.d.ts +7 -17
  3. package/dist/component/result-context.d.ts +2 -3
  4. package/dist/component/table/table-context.d.ts +9 -0
  5. package/dist/component/{table-layout.d.ts → table/table-layout.d.ts} +2 -2
  6. package/dist/component/table/table.d.ts +9 -0
  7. package/dist/html/html_view.d.ts +1 -1
  8. package/dist/module/index.mjs +145001 -0
  9. package/dist/module/index.umd.js +1643 -0
  10. package/dist/module/style.css +1 -0
  11. package/dist/stories/bars.stories.d.ts +1 -1
  12. package/dist/stories/tables.stories.d.ts +1 -1
  13. package/dist/stories/themes.stories.d.ts +1 -1
  14. package/dist/webcomponent/malloy-render.mjs +90572 -0
  15. package/dist/webcomponent/malloy-render.umd.js +1491 -0
  16. package/dist/webcomponent/style.css +1 -0
  17. package/package.json +21 -7
  18. package/vite.config.ts +25 -0
  19. package/vite.config.webcomponent.ts +25 -0
  20. package/dist/bundle/bundled_renderer.js +0 -139374
  21. package/dist/bundle/bundled_renderer.min.js +0 -2374
  22. package/dist/bundle/main.js +0 -29
  23. package/dist/bundle/renderer.js +0 -71
  24. package/dist/component/bar-chart.js +0 -130
  25. package/dist/component/chart-settings.js +0 -152
  26. package/dist/component/render-numeric-field.js +0 -104
  27. package/dist/component/render-result-metadata.js +0 -91
  28. package/dist/component/render.js +0 -155
  29. package/dist/component/result-context.js +0 -28
  30. package/dist/component/table-layout.js +0 -83
  31. package/dist/component/table.d.ts +0 -35
  32. package/dist/component/table.js +0 -375
  33. package/dist/component/util.js +0 -53
  34. package/dist/component/vega-chart.js +0 -105
  35. package/dist/component/vega-lite-base-spec.js +0 -61
  36. package/dist/component/vega-types.js +0 -34
  37. package/dist/data_styles.js +0 -50
  38. package/dist/drill.js +0 -124
  39. package/dist/html/area_sparkline.js +0 -118
  40. package/dist/html/bar_chart.js +0 -70
  41. package/dist/html/bar_sparkline.js +0 -119
  42. package/dist/html/boolean.js +0 -53
  43. package/dist/html/bytes.js +0 -47
  44. package/dist/html/cartesian_chart.js +0 -110
  45. package/dist/html/chart.js +0 -120
  46. package/dist/html/column_sparkline.js +0 -120
  47. package/dist/html/container.js +0 -44
  48. package/dist/html/currency.js +0 -75
  49. package/dist/html/dashboard.js +0 -242
  50. package/dist/html/data_volume.js +0 -94
  51. package/dist/html/date.js +0 -66
  52. package/dist/html/duration.js +0 -108
  53. package/dist/html/html_view.js +0 -187
  54. package/dist/html/image.js +0 -77
  55. package/dist/html/index.js +0 -28
  56. package/dist/html/json.js +0 -52
  57. package/dist/html/line_chart.js +0 -72
  58. package/dist/html/link.js +0 -57
  59. package/dist/html/list.js +0 -73
  60. package/dist/html/list_detail.js +0 -33
  61. package/dist/html/number.js +0 -73
  62. package/dist/html/percent.js +0 -50
  63. package/dist/html/point_map.js +0 -182
  64. package/dist/html/scatter_chart.js +0 -72
  65. package/dist/html/segment_map.js +0 -151
  66. package/dist/html/shape_map.js +0 -194
  67. package/dist/html/sparkline.js +0 -120
  68. package/dist/html/state_codes.js +0 -137
  69. package/dist/html/table.js +0 -475
  70. package/dist/html/text.js +0 -65
  71. package/dist/html/unsupported.js +0 -72
  72. package/dist/html/utils.js +0 -277
  73. package/dist/html/vega_spec.js +0 -544
  74. package/dist/index.js +0 -47
  75. package/dist/main_renderer_factory.js +0 -101
  76. package/dist/renderer.js +0 -34
  77. package/dist/renderer_factory.js +0 -57
  78. package/dist/renderer_types.js +0 -25
  79. package/dist/stories/bars.stories.js +0 -52
  80. package/dist/stories/basic.stories.js +0 -34
  81. package/dist/stories/image.stories.js +0 -34
  82. package/dist/stories/render-malloy-legacy.js +0 -27
  83. package/dist/stories/tables.stories.js +0 -65
  84. package/dist/stories/themes.stories.js +0 -47
  85. package/dist/stories/util.js +0 -25
  86. package/dist/tags_utils.js +0 -30
@@ -1,277 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.getDynamicValue = exports.getParentRecord = exports.formatTitle = exports.createDrillIcon = exports.createNullElement = exports.createErrorElement = exports.yieldTask = exports.normalizeToTimezone = exports.timeToString = exports.getColorScale = void 0;
29
- const malloy_1 = require("@malloydata/malloy");
30
- const startCase_1 = __importDefault(require("lodash/startCase"));
31
- const luxon_1 = require("luxon");
32
- function getColorScale(type, isRectMark, hasOverlappingText = false) {
33
- if (type === undefined) {
34
- return undefined;
35
- }
36
- switch (type) {
37
- case 'ordinal':
38
- return { range: ['#C2D5EE', '#1A73E8'] };
39
- case 'temporal':
40
- case 'quantitative':
41
- return isRectMark
42
- ? hasOverlappingText
43
- ? { range: ['#6BA4EE', '#EEA361'] }
44
- : { range: ['#1A73E8', '#E8710A'] }
45
- : { range: ['#C2D5EE', '#1A73E8'] };
46
- case 'nominal':
47
- return hasOverlappingText
48
- ? {
49
- range: [
50
- '#6BA4EE',
51
- '#66CEDC',
52
- '#EC72B8',
53
- '#EEA361',
54
- '#F9C85B',
55
- '#AACD85',
56
- '#B87CED',
57
- '#ACB0B3',
58
- ],
59
- }
60
- : {
61
- range: [
62
- '#1A73E8',
63
- '#12B5CB',
64
- '#E52592',
65
- '#E8710A',
66
- '#F9AB00',
67
- '#7CB342',
68
- '#9334E6',
69
- '#80868B',
70
- ],
71
- };
72
- }
73
- }
74
- exports.getColorScale = getColorScale;
75
- function numberFixedDigits(value, digits) {
76
- return value.toString().padStart(digits, '0');
77
- }
78
- function timeToString(time, timeframe, timezone) {
79
- timeframe || (timeframe = malloy_1.TimestampTimeframe.Second);
80
- let shouldNormalize = false;
81
- switch (timeframe) {
82
- case malloy_1.TimestampTimeframe.Hour:
83
- case malloy_1.TimestampTimeframe.Minute:
84
- case malloy_1.TimestampTimeframe.Second:
85
- shouldNormalize = true;
86
- break;
87
- }
88
- const dateTime = luxon_1.DateTime.fromJSDate(time, {
89
- zone: shouldNormalize && timezone ? timezone : 'UTC',
90
- });
91
- switch (timeframe) {
92
- case malloy_1.TimestampTimeframe.Year:
93
- case malloy_1.DateTimeframe.Year: {
94
- const year = numberFixedDigits(dateTime.year, 4);
95
- return `${year}`;
96
- }
97
- case malloy_1.TimestampTimeframe.Quarter:
98
- case malloy_1.DateTimeframe.Quarter: {
99
- const year = numberFixedDigits(dateTime.year, 4);
100
- const quarter = Math.floor(dateTime.month / 3) + 1;
101
- return `${year}-Q${quarter}`;
102
- }
103
- case malloy_1.TimestampTimeframe.Month:
104
- case malloy_1.DateTimeframe.Month: {
105
- const year = numberFixedDigits(dateTime.year, 2);
106
- const month = numberFixedDigits(dateTime.month, 2);
107
- return `${year}-${month}`;
108
- }
109
- case malloy_1.TimestampTimeframe.Week:
110
- case malloy_1.DateTimeframe.Week: {
111
- const year = numberFixedDigits(dateTime.year, 2);
112
- const month = numberFixedDigits(dateTime.month, 2);
113
- const day = numberFixedDigits(dateTime.day, 2);
114
- return `WK${year}-${month}-${day}`;
115
- }
116
- case malloy_1.DateTimeframe.Day:
117
- case malloy_1.TimestampTimeframe.Day: {
118
- const year = numberFixedDigits(dateTime.year, 2);
119
- const month = numberFixedDigits(dateTime.month, 2);
120
- const day = numberFixedDigits(dateTime.day, 2);
121
- return `${year}-${month}-${day}`;
122
- }
123
- case malloy_1.TimestampTimeframe.Hour: {
124
- const year = numberFixedDigits(dateTime.year, 2);
125
- const month = numberFixedDigits(dateTime.month, 2);
126
- const day = numberFixedDigits(dateTime.day, 2);
127
- const hour = numberFixedDigits(dateTime.hour, 2);
128
- return `${year}-${month}-${day} ${hour}:00 for 1 hour`;
129
- }
130
- case malloy_1.TimestampTimeframe.Minute: {
131
- const year = numberFixedDigits(dateTime.year, 2);
132
- const month = numberFixedDigits(dateTime.month, 2);
133
- const day = numberFixedDigits(dateTime.day, 2);
134
- const hour = numberFixedDigits(dateTime.hour, 2);
135
- const minute = numberFixedDigits(dateTime.minute, 2);
136
- return `${year}-${month}-${day} ${hour}:${minute}`;
137
- }
138
- case malloy_1.TimestampTimeframe.Second: {
139
- const year = numberFixedDigits(dateTime.year, 2);
140
- const month = numberFixedDigits(dateTime.month, 2);
141
- const day = numberFixedDigits(dateTime.day, 2);
142
- const hour = numberFixedDigits(dateTime.hour, 2);
143
- const minute = numberFixedDigits(dateTime.minute, 2);
144
- const second = numberFixedDigits(dateTime.second, 2);
145
- return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
146
- }
147
- default:
148
- throw new Error('Unknown timeframe.');
149
- }
150
- }
151
- exports.timeToString = timeToString;
152
- function normalizeToTimezone(date, timezone) {
153
- const dateTime = luxon_1.DateTime.fromJSDate(date, {
154
- zone: timezone !== null && timezone !== void 0 ? timezone : 'UTC',
155
- });
156
- return new Date(dateTime.year, dateTime.month - 1, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.millisecond);
157
- }
158
- exports.normalizeToTimezone = normalizeToTimezone;
159
- /**
160
- * Use this function to break up expensive computation over multiple tasks.
161
- *
162
- * @return A promise, which when awaited, puts subsequent code in a separate task.
163
- *
164
- * This is useful for cases when expensive code needs to run "concurrently" with a
165
- * rendering / UI task. Sprinkling in `yieldTask`s into a long task allows other
166
- * tasks to run periodically.
167
- */
168
- let LAST_YIELD_TIME = undefined;
169
- const YIELD_DEBOUNCE = 100; // milliseconds
170
- async function yieldTask() {
171
- const currentTime = Date.now();
172
- // We don't actually yield every time the function is called, because that can add a lot of
173
- // overhead in terms of new tasks. Instead, we debounce yielding to once every 100ms.
174
- if (LAST_YIELD_TIME && currentTime < LAST_YIELD_TIME + YIELD_DEBOUNCE) {
175
- return;
176
- }
177
- LAST_YIELD_TIME = currentTime;
178
- return new Promise(resolve => {
179
- setTimeout(resolve, 0);
180
- });
181
- }
182
- exports.yieldTask = yieldTask;
183
- function createErrorElement(document, error) {
184
- const element = document.createElement('span');
185
- element.classList.add('error');
186
- element.appendChild(document.createTextNode(typeof error === 'string' ? error : error.message));
187
- return element;
188
- }
189
- exports.createErrorElement = createErrorElement;
190
- function createNullElement(document) {
191
- const element = document.createElement('span');
192
- element.appendChild(document.createTextNode('∅'));
193
- element.classList.add('value-null');
194
- return element;
195
- }
196
- exports.createNullElement = createNullElement;
197
- function createDrillIcon(document) {
198
- const drill = document.createElement('div');
199
- drill.classList.add('drill-icon');
200
- drill.innerHTML = `
201
- <style>
202
- .drill-icon:hover .copy-circle {
203
- fill: #eef7f9;
204
- }
205
-
206
- .drill-icon:active .copy-circle {
207
- fill: #cfe9f0;
208
- }
209
-
210
- .drill-icon:hover .copy-icon,
211
- .drill-icon:active .copy-icon {
212
- fill: #53b2c8;
213
- }
214
- </style>
215
- <svg
216
- width="24"
217
- height="24"
218
- viewBox="0 0 24 24"
219
- fill="none"
220
- xmlns="http://www.w3.org/2000/svg"
221
- >
222
- <circle cx="12" cy="12" r="12" fill="none" class="copy-circle" />
223
- <svg
224
- x="6"
225
- y="6"
226
- width="12"
227
- height="14"
228
- viewBox="0 0 12 14"
229
- fill="none"
230
- xmlns="http://www.w3.org/2000/svg"
231
- >
232
- <path
233
- d="M4 10.6667C3.63333 10.6667 3.31944 10.5361 3.05833 10.275C2.79722 10.0139 2.66667 9.7 2.66667 9.33333V1.33333C2.66667 0.966667 2.79722 0.652778 3.05833 0.391667C3.31944 0.130556 3.63333 0 4 0H10C10.3667 0 10.6806 0.130556 10.9417 0.391667C11.2028 0.652778 11.3333 0.966667 11.3333 1.33333V9.33333C11.3333 9.7 11.2028 10.0139 10.9417 10.275C10.6806 10.5361 10.3667 10.6667 10 10.6667H4ZM4 9.33333H10V1.33333H4V9.33333ZM1.33333 13.3333C0.966667 13.3333 0.652778 13.2028 0.391667 12.9417C0.130556 12.6806 0 12.3667 0 12V2.66667H1.33333V12H8.66667V13.3333H1.33333Z"
234
- fill="#E7E7E7"
235
- class="copy-icon"
236
- />
237
- </svg>
238
- </svg>`;
239
- return drill;
240
- }
241
- exports.createDrillIcon = createDrillIcon;
242
- function formatTitle(options, field, renderDef, timezone) {
243
- var _a;
244
- const label = ((_a = renderDef === null || renderDef === void 0 ? void 0 : renderDef.data) === null || _a === void 0 ? void 0 : _a.label) || field.name;
245
- let title = options.titleCase ? (0, startCase_1.default)(label) : label;
246
- if (field.isAtomicField() &&
247
- (field.isDate() || field.isTimestamp()) &&
248
- timezone) {
249
- title = `${title} (${timezone})`;
250
- }
251
- return title;
252
- }
253
- exports.formatTitle = formatTitle;
254
- function getParentRecord(data, n = 0) {
255
- let record = data;
256
- while (n > 0 && record.parentRecord) {
257
- n -= 1;
258
- record = record.parentRecord;
259
- }
260
- return record;
261
- }
262
- exports.getParentRecord = getParentRecord;
263
- function getDynamicValue({ tag, data, }) {
264
- var _a, _b, _c;
265
- const match = (_b = (_a = tag
266
- .tag('field')) === null || _a === void 0 ? void 0 : _a.text()) === null || _b === void 0 ? void 0 : _b.match(/^(\^*)(.*)/);
267
- if (!match)
268
- return undefined;
269
- const [, parentScoping, fieldName] = match;
270
- const ancestorCt = parentScoping.length;
271
- const scope = getParentRecord(data, ancestorCt);
272
- if ('cell' in scope)
273
- return (_c = scope.cell(fieldName)) === null || _c === void 0 ? void 0 : _c.value;
274
- return undefined;
275
- }
276
- exports.getDynamicValue = getDynamicValue;
277
- //# sourceMappingURL=utils.js.map