@xplortech/apollo-data 0.0.3-draft.64d0fa1

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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +112 -0
  3. package/dist/apollo-data/apollo-data.esm.js +1 -0
  4. package/dist/apollo-data/index.esm.js +1 -0
  5. package/dist/apollo-data/p-Bb2nY-Tf.js +2 -0
  6. package/dist/apollo-data/p-DQuL1Twl.js +1 -0
  7. package/dist/apollo-data/p-e6584598.entry.js +11 -0
  8. package/dist/cjs/apollo-data-bar-chart_2.cjs.entry.js +68368 -0
  9. package/dist/cjs/apollo-data.cjs.js +25 -0
  10. package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
  11. package/dist/cjs/index-Cl7HgRm0.js +1198 -0
  12. package/dist/cjs/index.cjs.js +7 -0
  13. package/dist/cjs/loader.cjs.js +13 -0
  14. package/dist/collection/apollo-data-base.js +38 -0
  15. package/dist/collection/collection-manifest.json +13 -0
  16. package/dist/collection/components/apollo-data-bar/apollo-data-bar.js +367 -0
  17. package/dist/collection/components/apollo-data-donut/apollo-data-donut.js +479 -0
  18. package/dist/collection/examples/apollo-data-bar.examples.js +160 -0
  19. package/dist/collection/examples/apollo-data-donut.examples.js +100 -0
  20. package/dist/collection/examples/index.js +2 -0
  21. package/dist/collection/index.js +10 -0
  22. package/dist/collection/utils/code-generator.js +240 -0
  23. package/dist/collection/utils/constants.js +2 -0
  24. package/dist/collection/utils/utils.js +3 -0
  25. package/dist/components/apollo-data-bar-chart.d.ts +11 -0
  26. package/dist/components/apollo-data-bar-chart.js +1 -0
  27. package/dist/components/apollo-data-donut-chart.d.ts +11 -0
  28. package/dist/components/apollo-data-donut-chart.js +1 -0
  29. package/dist/components/index.d.ts +35 -0
  30. package/dist/components/index.js +1 -0
  31. package/dist/components/p-7XF5Cax8.js +11 -0
  32. package/dist/components/p-Dws5s-Xe.js +1 -0
  33. package/dist/esm/apollo-data-bar-chart_2.entry.js +68365 -0
  34. package/dist/esm/apollo-data.js +21 -0
  35. package/dist/esm/app-globals-DQuL1Twl.js +3 -0
  36. package/dist/esm/index-Bb2nY-Tf.js +1190 -0
  37. package/dist/esm/index.js +5 -0
  38. package/dist/esm/loader.js +11 -0
  39. package/dist/index.cjs.js +1 -0
  40. package/dist/index.js +1 -0
  41. package/dist/types/apollo-data-base.d.ts +7 -0
  42. package/dist/types/components/apollo-data-bar/apollo-data-bar.d.ts +298 -0
  43. package/dist/types/components/apollo-data-donut/apollo-data-donut.d.ts +533 -0
  44. package/dist/types/components.d.ts +102 -0
  45. package/dist/types/examples/apollo-data-bar.examples.d.ts +12 -0
  46. package/dist/types/examples/apollo-data-donut.examples.d.ts +11 -0
  47. package/dist/types/examples/index.d.ts +2 -0
  48. package/dist/types/index.d.ts +11 -0
  49. package/dist/types/stencil-public-runtime.d.ts +1839 -0
  50. package/dist/types/utils/code-generator.d.ts +12 -0
  51. package/dist/types/utils/constants.d.ts +2 -0
  52. package/dist/types/utils/utils.d.ts +1 -0
  53. package/loader/cdn.js +1 -0
  54. package/loader/index.cjs.js +1 -0
  55. package/loader/index.d.ts +24 -0
  56. package/loader/index.es2017.js +1 -0
  57. package/loader/index.js +2 -0
  58. package/package.json +92 -0
  59. package/src/examples/apollo-data-bar.examples.ts +172 -0
  60. package/src/examples/apollo-data-donut.examples.ts +118 -0
  61. package/src/examples/index.ts +2 -0
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ function format(first, middle, last) {
4
+ return (first || '') + (middle ? ` ${middle}` : '') + (last ? ` ${last}` : '');
5
+ }
6
+
7
+ exports.format = format;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index-Cl7HgRm0.js');
4
+ var appGlobals = require('./app-globals-V2Kpy_OQ.js');
5
+
6
+ const defineCustomElements = async (win, options) => {
7
+ if (typeof window === 'undefined') return undefined;
8
+ await appGlobals.globalScripts();
9
+ return index.bootstrapLazy([["apollo-data-bar-chart_2.cjs",[[513,"apollo-data-bar-chart",{"adData":[1,"ad-data"],"adSpec":[1,"ad-spec"]}],[513,"apollo-data-donut-chart",{"adData":[1,"ad-data"],"adSpec":[1,"ad-spec"]}]]]], options);
10
+ };
11
+
12
+ exports.setNonce = index.setNonce;
13
+ exports.defineCustomElements = defineCustomElements;
@@ -0,0 +1,38 @@
1
+ // @ts-ignore
2
+ import embed from "vega-embed";
3
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
4
+ export class ApolloBase {
5
+ // @ts-ignore
6
+ getViewData(data, spec) {
7
+ throw new Error('getViewData is not implemented');
8
+ }
9
+ async renderChart() {
10
+ // Wait for shadow DOM to be ready
11
+ await new Promise(resolve => setTimeout(resolve, 0));
12
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
13
+ const container = this.el?.shadowRoot?.querySelector('#container');
14
+ if (!container) {
15
+ return;
16
+ }
17
+ let data;
18
+ let spec;
19
+ try {
20
+ data = typeof this.adData === 'string' ? JSON.parse(this.adData || '[]') : this.adData;
21
+ spec = typeof this.adSpec === 'string' ? JSON.parse(this.adSpec) : this.adSpec;
22
+ }
23
+ catch (err) {
24
+ console.error('Error parsing data/spec', err);
25
+ return;
26
+ }
27
+ const view = await this.getViewData(data, spec);
28
+ container.innerHTML = '';
29
+ await embed(container, view, {
30
+ actions: false,
31
+ ast: true,
32
+ tooltip: {
33
+ position: 'top',
34
+ anchor: 'mark',
35
+ },
36
+ });
37
+ }
38
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "entries": [
3
+ "components/apollo-data-bar/apollo-data-bar.js",
4
+ "components/apollo-data-donut/apollo-data-donut.js"
5
+ ],
6
+ "compiler": {
7
+ "name": "@stencil/core",
8
+ "version": "4.41.3",
9
+ "typescriptVersion": "5.8.3"
10
+ },
11
+ "collections": [],
12
+ "bundles": []
13
+ }
@@ -0,0 +1,367 @@
1
+ import { h, Host } from "@stencil/core";
2
+ import { ApolloBase } from "../../apollo-data-base";
3
+ import { CHART_COLORS } from "../../utils/constants";
4
+ const FONT_FAMILY = "apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif";
5
+ export class ApolloDataBarChart extends ApolloBase {
6
+ constructor() {
7
+ super();
8
+ }
9
+ el = null;
10
+ adData = [];
11
+ adSpec = null;
12
+ static tooltipStylesInjected = false;
13
+ componentDidLoad() {
14
+ this.injectTooltipStyles();
15
+ }
16
+ async componentDidRender() {
17
+ await this.renderChart();
18
+ }
19
+ injectTooltipStyles() {
20
+ if (ApolloDataBarChart.tooltipStylesInjected) {
21
+ return;
22
+ }
23
+ const styleId = 'apollo-data-bar-tooltip-styles';
24
+ if (document.getElementById(styleId)) {
25
+ ApolloDataBarChart.tooltipStylesInjected = true;
26
+ return;
27
+ }
28
+ const style = document.createElement('style');
29
+ style.id = styleId;
30
+ style.textContent = `
31
+ #vg-tooltip-element {
32
+ background-color: #ffffff;
33
+ border: 1px solid #e1e2e8;
34
+ border-radius: 0.25rem;
35
+ box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.05);
36
+ font-family: apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif;
37
+ font-weight: 500;
38
+ padding: 0.25rem 0.75rem;
39
+ pointer-events: none;
40
+ text-align: center;
41
+ transform: translateY(20%);
42
+ white-space: pre;
43
+ z-index: 999999999;
44
+ }
45
+
46
+ #vg-tooltip-element table tr td.key {
47
+ color: #6a6d7d;
48
+ text-align: center;
49
+ }
50
+
51
+ #vg-tooltip-element table tr td.value {
52
+ text-align: center;
53
+ }
54
+
55
+ #vg-tooltip-element.dark-theme {
56
+ background-color: #292632;
57
+ border: 1px solid #6a6d7d;
58
+ box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.5);
59
+ color: #ffffff;
60
+ }
61
+
62
+ #vg-tooltip-element::after {
63
+ border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
64
+ border-style: solid;
65
+ border-width: 9px;
66
+ bottom: -17px;
67
+ content: '';
68
+ left: 50%;
69
+ position: absolute;
70
+ transform: translateX(-50%);
71
+ }
72
+ `;
73
+ document.head.appendChild(style);
74
+ ApolloDataBarChart.tooltipStylesInjected = true;
75
+ }
76
+ // @ts-ignore
77
+ async getViewData(data, spec) {
78
+ if (!spec) {
79
+ throw new Error('adSpec is required for apollo-data-bar-chart');
80
+ }
81
+ const { tooltipPrefix = '', currencySymbol = '' } = spec;
82
+ if (!data || data.length === 0) {
83
+ throw new Error('Data is required for apollo-data-bar-chart');
84
+ }
85
+ const uniqueCategories = Array.from(new Set(data.map(item => item.category)));
86
+ const formatNumber = tooltipPrefix ? '.2f' : '.0f';
87
+ const currencyPrefix = tooltipPrefix ? currencySymbol : '';
88
+ return {
89
+ $schema: 'https://vega.github.io/schema/vega/v5.json',
90
+ config: {
91
+ text: {
92
+ fill: '#6a6d7d',
93
+ font: FONT_FAMILY,
94
+ labelFontSize: 12,
95
+ labelFontWeight: 400,
96
+ },
97
+ axis: {
98
+ labelColor: '#6a6d7d',
99
+ titleColor: '#6a6d7d',
100
+ labelFont: FONT_FAMILY,
101
+ titleFont: FONT_FAMILY,
102
+ titleFontWeight: 400,
103
+ },
104
+ legend: {
105
+ labelColor: '#6a6d7d',
106
+ titleColor: '#6a6d7d',
107
+ labelFont: FONT_FAMILY,
108
+ titleFont: FONT_FAMILY,
109
+ labelFontSize: 12,
110
+ labelLimit: 95,
111
+ },
112
+ title: {
113
+ color: '#6a6d7d',
114
+ font: FONT_FAMILY,
115
+ labelFontSize: 12,
116
+ labelFontWeight: 400,
117
+ },
118
+ },
119
+ height: 250,
120
+ autosize: { type: 'fit-x', contains: 'padding', resize: true },
121
+ signals: [
122
+ {
123
+ name: 'containerW',
124
+ update: 'max(containerSize()[0], 400)',
125
+ },
126
+ {
127
+ name: 'legendColumns',
128
+ update: 'ceil(containerW / 140)',
129
+ },
130
+ {
131
+ name: 'hoveredPeriod',
132
+ value: null,
133
+ on: [
134
+ { events: 'rect:mouseover', update: 'datum.period' },
135
+ { events: 'rect:mouseout', update: 'null' },
136
+ ],
137
+ },
138
+ ],
139
+ width: { signal: 'containerW' },
140
+ data: [
141
+ {
142
+ name: 'raw',
143
+ values: data,
144
+ },
145
+ {
146
+ name: 'periodTotals',
147
+ source: 'raw',
148
+ transform: [
149
+ {
150
+ type: 'aggregate',
151
+ groupby: ['periodId'],
152
+ fields: ['value'],
153
+ ops: ['sum'],
154
+ as: ['total'],
155
+ },
156
+ ],
157
+ },
158
+ {
159
+ name: 'table',
160
+ source: 'raw',
161
+ transform: [
162
+ {
163
+ type: 'lookup',
164
+ from: 'periodTotals',
165
+ key: 'periodId',
166
+ fields: ['periodId'],
167
+ values: ['total'],
168
+ as: ['total'],
169
+ },
170
+ {
171
+ type: 'stack',
172
+ groupby: ['periodId'],
173
+ sort: { field: 'category' },
174
+ field: 'value',
175
+ },
176
+ {
177
+ type: 'formula',
178
+ as: 'periodId',
179
+ expr: 'datum.periodId',
180
+ },
181
+ {
182
+ type: 'formula',
183
+ as: 'labelOnly',
184
+ expr: 'datum.label',
185
+ },
186
+ ],
187
+ },
188
+ {
189
+ name: 'periodLabels',
190
+ source: 'raw',
191
+ transform: [
192
+ {
193
+ type: 'aggregate',
194
+ groupby: ['periodId', 'label'],
195
+ },
196
+ ],
197
+ },
198
+ ],
199
+ scales: [
200
+ {
201
+ name: 'x',
202
+ type: 'band',
203
+ domain: { data: 'table', field: 'periodId' },
204
+ range: 'width',
205
+ paddingInner: 0.35,
206
+ paddingOuter: 0.02,
207
+ },
208
+ {
209
+ name: 'xLabels',
210
+ type: 'ordinal',
211
+ domain: { data: 'periodLabels', field: 'periodId' },
212
+ range: { data: 'periodLabels', field: 'label' },
213
+ },
214
+ {
215
+ name: 'y',
216
+ type: 'linear',
217
+ domain: { data: 'table', field: 'y1' },
218
+ nice: true,
219
+ zero: true,
220
+ range: 'height',
221
+ },
222
+ {
223
+ name: 'color',
224
+ type: 'ordinal',
225
+ domain: uniqueCategories,
226
+ range: spec?.colorSet ?? CHART_COLORS,
227
+ },
228
+ ],
229
+ axes: [
230
+ {
231
+ orient: 'bottom',
232
+ scale: 'x',
233
+ title: spec?.xAxisTitle,
234
+ labelPadding: 12,
235
+ titlePadding: 12,
236
+ labelAngle: -90,
237
+ labelAlign: 'right',
238
+ labelBaseline: 'middle',
239
+ tickSize: 3,
240
+ labelFontSize: 12,
241
+ titleFontSize: 14,
242
+ ticks: false,
243
+ domain: false,
244
+ encode: {
245
+ labels: {
246
+ update: {
247
+ text: { signal: "scale('xLabels', datum.value)" },
248
+ },
249
+ },
250
+ },
251
+ },
252
+ {
253
+ orient: 'left',
254
+ scale: 'y',
255
+ title: spec?.yAxisTitle || '',
256
+ format: ',.0f',
257
+ grid: true,
258
+ tickCount: 6,
259
+ labelFontSize: 12,
260
+ titleFontSize: 14,
261
+ ticks: false,
262
+ domain: false,
263
+ tickBand: 'extent',
264
+ labelPadding: 10,
265
+ },
266
+ ],
267
+ legends: [
268
+ {
269
+ fill: 'color',
270
+ orient: 'bottom',
271
+ direction: 'horizontal',
272
+ columns: { signal: 'legendColumns' },
273
+ title: null,
274
+ symbolType: 'square',
275
+ rowPadding: 8,
276
+ symbolOffset: -35,
277
+ symbolSize: 100,
278
+ labelOffset: 8,
279
+ labelLimit: 95,
280
+ },
281
+ ],
282
+ marks: [
283
+ {
284
+ type: 'rect',
285
+ from: { data: 'table' },
286
+ encode: {
287
+ enter: {
288
+ x: { scale: 'x', field: 'periodId' },
289
+ width: { scale: 'x', band: 1 },
290
+ y: { scale: 'y', field: 'y1' },
291
+ y2: { scale: 'y', field: 'y0' },
292
+ fill: { scale: 'color', field: 'category' },
293
+ tooltip: {
294
+ signal: `datum.category + ': ${currencyPrefix}' + format(datum.value, ',${formatNumber}') + '\\nTotal: ${currencyPrefix}' + format(datum.total, ',${formatNumber}')`,
295
+ },
296
+ },
297
+ update: {
298
+ opacity: [{ test: 'hoveredPeriod && datum.period !== hoveredPeriod', value: 0.2 }, { value: 1 }],
299
+ },
300
+ },
301
+ },
302
+ ],
303
+ };
304
+ }
305
+ render() {
306
+ return (h(Host, { key: '86ed2e74e5abd57e684a93bc9cf6a014b3ed081c' }, h("div", { key: '96e5f7dd2dfa6a104ca709d1399308a86041c2f3', id: "container", style: { width: '100%', height: '100%' } })));
307
+ }
308
+ static get is() { return "apollo-data-bar-chart"; }
309
+ static get encapsulation() { return "shadow"; }
310
+ static get properties() {
311
+ return {
312
+ "adData": {
313
+ "type": "string",
314
+ "mutable": false,
315
+ "complexType": {
316
+ "original": "string | BarDataItem[]",
317
+ "resolved": "BarDataItem[] | string",
318
+ "references": {
319
+ "BarDataItem": {
320
+ "location": "local",
321
+ "path": "/home/runner/work/apollo/apollo/packages/apollo-data/src/components/apollo-data-bar/apollo-data-bar.tsx",
322
+ "id": "src/components/apollo-data-bar/apollo-data-bar.tsx::BarDataItem"
323
+ }
324
+ }
325
+ },
326
+ "required": false,
327
+ "optional": false,
328
+ "docs": {
329
+ "tags": [],
330
+ "text": ""
331
+ },
332
+ "getter": false,
333
+ "setter": false,
334
+ "reflect": false,
335
+ "attribute": "ad-data",
336
+ "defaultValue": "[]"
337
+ },
338
+ "adSpec": {
339
+ "type": "string",
340
+ "mutable": false,
341
+ "complexType": {
342
+ "original": "string | BarSpec",
343
+ "resolved": "BarSpec | string",
344
+ "references": {
345
+ "BarSpec": {
346
+ "location": "local",
347
+ "path": "/home/runner/work/apollo/apollo/packages/apollo-data/src/components/apollo-data-bar/apollo-data-bar.tsx",
348
+ "id": "src/components/apollo-data-bar/apollo-data-bar.tsx::BarSpec"
349
+ }
350
+ }
351
+ },
352
+ "required": false,
353
+ "optional": false,
354
+ "docs": {
355
+ "tags": [],
356
+ "text": ""
357
+ },
358
+ "getter": false,
359
+ "setter": false,
360
+ "reflect": false,
361
+ "attribute": "ad-spec",
362
+ "defaultValue": "null"
363
+ }
364
+ };
365
+ }
366
+ static get elementRef() { return "el"; }
367
+ }