@xplortech/apollo-data 0.0.4 → 0.0.5

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 (43) hide show
  1. package/dist/apollo-data/apollo-data.esm.js +1 -1
  2. package/dist/apollo-data/p-2nuV5Vny.js +1 -0
  3. package/dist/apollo-data/p-4ac3c97c.entry.js +1 -0
  4. package/dist/apollo-data/p-BWkrM8dc.js +11 -0
  5. package/dist/apollo-data/p-b7471c12.entry.js +1 -0
  6. package/dist/apollo-data/p-e518baac.entry.js +1 -0
  7. package/dist/cjs/apollo-data-bar-chart.cjs.entry.js +314 -0
  8. package/dist/cjs/{apollo-data-bar-chart_2.cjs.entry.js → apollo-data-base-CxVQ-WVP.js} +1 -715
  9. package/dist/cjs/apollo-data-donut-chart.cjs.entry.js +408 -0
  10. package/dist/cjs/apollo-data-line-chart_2.cjs.entry.js +534 -0
  11. package/dist/cjs/apollo-data.cjs.js +1 -1
  12. package/dist/cjs/constants-B3weDEpc.js +5 -0
  13. package/dist/cjs/loader.cjs.js +1 -1
  14. package/dist/collection/collection-manifest.json +3 -1
  15. package/dist/collection/components/apollo-data-line/apollo-data-line.js +346 -0
  16. package/dist/collection/components/apollo-data-scatter/apollo-data-scatter.js +329 -0
  17. package/dist/collection/examples/apollo-data-line.examples.js +91 -0
  18. package/dist/collection/examples/apollo-data-scatter.examples.js +94 -0
  19. package/dist/collection/examples/index.js +1 -0
  20. package/dist/components/apollo-data-bar-chart.js +1 -1
  21. package/dist/components/apollo-data-line-chart.d.ts +11 -0
  22. package/dist/components/apollo-data-line-chart.js +1 -0
  23. package/dist/components/apollo-data-scatter-chart.d.ts +11 -0
  24. package/dist/components/apollo-data-scatter-chart.js +1 -0
  25. package/dist/components/p-2nuV5Vny.js +1 -0
  26. package/dist/esm/apollo-data-bar-chart.entry.js +312 -0
  27. package/dist/esm/{apollo-data-bar-chart_2.entry.js → apollo-data-base-BWkrM8dc.js} +1 -714
  28. package/dist/esm/apollo-data-donut-chart.entry.js +406 -0
  29. package/dist/esm/apollo-data-line-chart_2.entry.js +531 -0
  30. package/dist/esm/apollo-data.js +1 -1
  31. package/dist/esm/constants-2nuV5Vny.js +3 -0
  32. package/dist/esm/loader.js +1 -1
  33. package/dist/types/components/apollo-data-line/apollo-data-line.d.ts +244 -0
  34. package/dist/types/components/apollo-data-scatter/apollo-data-scatter.d.ts +329 -0
  35. package/dist/types/components.d.ts +86 -0
  36. package/dist/types/examples/apollo-data-line.examples.d.ts +12 -0
  37. package/dist/types/examples/apollo-data-scatter.examples.d.ts +11 -0
  38. package/dist/types/examples/index.d.ts +1 -0
  39. package/package.json +1 -1
  40. package/src/examples/apollo-data-line.examples.ts +103 -0
  41. package/src/examples/apollo-data-scatter.examples.ts +109 -0
  42. package/src/examples/index.ts +2 -1
  43. package/dist/apollo-data/p-e6584598.entry.js +0 -11
@@ -0,0 +1,406 @@
1
+ import { r as registerInstance, g as getElement, h, H as Host } from './index-Bb2nY-Tf.js';
2
+ import { A as ApolloBase } from './apollo-data-base-BWkrM8dc.js';
3
+
4
+ const ApolloDataDonutChart = class extends ApolloBase {
5
+ constructor(hostRef) {
6
+ super();
7
+ registerInstance(this, hostRef);
8
+ }
9
+ get el() { return getElement(this); }
10
+ /**
11
+ * Array of data items to display in the donut chart. Each item represents a segment with category and value.
12
+ * @property {string} category - Category name for the data segment
13
+ * @property {number} value - Numeric value for the donut chart segment
14
+ */
15
+ adData = [];
16
+ /**
17
+ * Optional specification object for customizing the chart appearance
18
+ * @property {string[]} [colorSet] - Array of color hex codes for chart segments
19
+ * @property {string} [preffix] - A string added at the start of another string, like $ or a currency symbol.
20
+ * @property {string} [suffix] - A string added at the end of another string, like %, kg or a currency symbol.
21
+ * @property {string} [centerText] - A label string rendered at the center of the view.
22
+ */
23
+ adSpec = {};
24
+ categories;
25
+ dataValues;
26
+ totalRevenue;
27
+ chartColors;
28
+ defaultChartColors = ['#4d1ab2', '#f99170', '#e550c8', '#ffd563', '#8857fa', '#52ebba', '#bf1d78', '#31cff8'];
29
+ defaultCenterText = 'Total Revenue';
30
+ async componentDidRender() {
31
+ await this.renderChart();
32
+ }
33
+ // @ts-ignore
34
+ async getViewData(data, spec) {
35
+ const dataValues = data;
36
+ this.chartColors = spec?.colorSet ? spec.colorSet : this.defaultChartColors;
37
+ this.categories = dataValues.map(item => item.category);
38
+ this.dataValues = dataValues.map((item, index) => ({
39
+ ...item,
40
+ order: index + 1,
41
+ }));
42
+ this.totalRevenue = Math.round(dataValues.reduce((prev, curr) => prev + curr.value, 0) * 100) / 100;
43
+ return {
44
+ $schema: 'https://vega.github.io/schema/vega/v5.json',
45
+ description: "Donut chart with correctly placed percentage labels and exploded 'Other' slices on hover",
46
+ height: 250,
47
+ signals: [
48
+ {
49
+ name: 'containerW',
50
+ update: 'min(containerSize()[0], 400)',
51
+ },
52
+ { name: 'centerX', update: 'containerW / 2' },
53
+ { name: 'centerY', update: '250 / 2' },
54
+ { name: 'radius', update: 'min(containerW, 250) / 2 - 20' },
55
+ {
56
+ name: 'categoryDisplay',
57
+ value: null,
58
+ on: [
59
+ {
60
+ events: { type: 'mouseover', markname: 'mainArc' },
61
+ update: 'datum.category',
62
+ },
63
+ {
64
+ events: {
65
+ type: 'mouseover',
66
+ markname: 'mainArcLabel',
67
+ },
68
+ update: 'datum.category',
69
+ },
70
+ {
71
+ events: { type: 'mouseout', markname: 'mainArc' },
72
+ update: 'null',
73
+ },
74
+ {
75
+ events: {
76
+ type: 'mouseout',
77
+ markname: 'mainArcLabel',
78
+ },
79
+ update: 'null',
80
+ },
81
+ {
82
+ events: { type: 'mouseover', markname: 'innerArc' },
83
+ update: 'null',
84
+ },
85
+ {
86
+ events: { type: 'mouseover', markname: 'outerArc' },
87
+ update: 'null',
88
+ },
89
+ {
90
+ events: { type: 'mouseover', markname: 'otherArc' },
91
+ update: 'datum.category',
92
+ },
93
+ {
94
+ events: { type: 'mouseout', markname: 'otherArc' },
95
+ update: 'null',
96
+ },
97
+ ],
98
+ },
99
+ {
100
+ name: 'displayText',
101
+ update: `categoryDisplay && length(categoryDisplay) > 18 ? (lastindexof(categoryDisplay, ' ') > 0 ? slice(categoryDisplay, 0, lastindexof(categoryDisplay, ' ')) + '\\n' + slice(categoryDisplay, lastindexof(categoryDisplay, ' ') + 1) : categoryDisplay) : categoryDisplay || '${spec?.centerText ? spec.centerText : this.defaultCenterText}'`,
102
+ },
103
+ {
104
+ name: 'hoveredCategory',
105
+ value: null,
106
+ on: [
107
+ {
108
+ events: { type: 'mouseover', markname: 'mainArc' },
109
+ update: 'datum.category',
110
+ },
111
+ {
112
+ events: {
113
+ type: 'mouseover',
114
+ markname: 'mainArcLabel',
115
+ },
116
+ update: 'datum.category',
117
+ },
118
+ {
119
+ events: { type: 'mouseover', markname: 'outerArc' },
120
+ update: 'null',
121
+ },
122
+ {
123
+ events: { type: 'mouseover', markname: 'innerArc' },
124
+ update: 'null',
125
+ },
126
+ {
127
+ events: { type: 'mouseout', markname: 'innerArc' },
128
+ update: 'null',
129
+ },
130
+ ],
131
+ },
132
+ {
133
+ name: 'hoveredValue',
134
+ value: null,
135
+ on: [
136
+ {
137
+ events: { type: 'mouseover', markname: 'mainArc' },
138
+ update: 'datum.value',
139
+ },
140
+ {
141
+ events: {
142
+ type: 'mouseover',
143
+ markname: 'mainArcLabel',
144
+ },
145
+ update: 'datum.value',
146
+ },
147
+ {
148
+ events: { type: 'mouseout', markname: 'mainArc' },
149
+ update: 'null',
150
+ },
151
+ {
152
+ events: { type: 'mouseover', markname: 'otherArc' },
153
+ update: 'datum.value',
154
+ },
155
+ {
156
+ events: { type: 'mouseout', markname: 'otherArc' },
157
+ update: 'null',
158
+ },
159
+ ],
160
+ },
161
+ ],
162
+ width: { signal: 'containerW' },
163
+ data: [
164
+ {
165
+ name: 'table',
166
+ values: this.dataValues,
167
+ transform: [
168
+ {
169
+ type: 'joinaggregate',
170
+ fields: ['value'],
171
+ ops: ['sum'],
172
+ as: ['total'],
173
+ },
174
+ {
175
+ type: 'formula',
176
+ as: 'percent',
177
+ expr: 'datum.value / datum.total',
178
+ },
179
+ {
180
+ type: 'collect',
181
+ sort: { field: 'order', order: 'descending' },
182
+ },
183
+ {
184
+ type: 'pie',
185
+ field: 'value',
186
+ as: ['startAngle', 'endAngle'],
187
+ },
188
+ {
189
+ type: 'formula',
190
+ as: 'midAngle',
191
+ expr: '((datum.startAngle + datum.endAngle) + 9.418) / 2',
192
+ },
193
+ {
194
+ type: 'formula',
195
+ as: 'labelX',
196
+ expr: 'centerX + (radius * 1.2 * cos(datum.midAngle))',
197
+ },
198
+ {
199
+ type: 'formula',
200
+ as: 'labelY',
201
+ expr: 'centerY + (radius * 1.2 * sin(datum.midAngle))',
202
+ },
203
+ {
204
+ type: 'formula',
205
+ as: 'percentLabel',
206
+ expr: `format(datum.value / ${this.totalRevenue} * 100, '.1f') + '%'`,
207
+ },
208
+ ],
209
+ },
210
+ {
211
+ name: 'defaultCenterText',
212
+ values: [
213
+ {
214
+ category: spec?.centerText ? spec.centerText : this.defaultCenterText,
215
+ value: this.totalRevenue,
216
+ order: 4,
217
+ },
218
+ ],
219
+ transform: [
220
+ { type: 'filter', expr: 'hoveredCategory === null' },
221
+ {
222
+ type: 'formula',
223
+ as: 'textDisplay',
224
+ expr: `'${spec?.prefix ?? '$'}' + format(floor(datum.value), ',') + '${spec?.suffix ?? ''}' `,
225
+ },
226
+ ],
227
+ },
228
+ ],
229
+ scales: [
230
+ {
231
+ name: 'mainColor',
232
+ type: 'ordinal',
233
+ domain: this.categories,
234
+ range: this.chartColors,
235
+ },
236
+ ],
237
+ legends: [
238
+ {
239
+ fill: 'mainColor',
240
+ orient: 'bottom',
241
+ direction: 'horizontal',
242
+ columns: 2,
243
+ title: '',
244
+ padding: 10,
245
+ symbolType: 'square',
246
+ symbolSize: 100,
247
+ labelFontSize: 12,
248
+ labelColor: '#6A6D7D',
249
+ rowPadding: 8,
250
+ },
251
+ ],
252
+ marks: [
253
+ {
254
+ type: 'rule',
255
+ name: 'labelLines',
256
+ from: { data: 'table' },
257
+ encode: {
258
+ enter: {
259
+ stroke: { value: 'black' }, // line color
260
+ strokeWidth: { value: 1 },
261
+ x: {
262
+ signal: 'centerX + (radius * 0.9) * cos(datum.midAngle)',
263
+ },
264
+ y: {
265
+ signal: 'centerY + (radius * 0.9) * sin(datum.midAngle)',
266
+ },
267
+ x2: {
268
+ signal: 'datum.labelX - 12 * cos(datum.midAngle)', // <-- added offset
269
+ },
270
+ y2: {
271
+ signal: 'datum.labelY - 12 * sin(datum.midAngle)', // <-- added offset
272
+ },
273
+ },
274
+ update: {
275
+ opacity: { value: 1 },
276
+ },
277
+ },
278
+ zindex: 5,
279
+ },
280
+ {
281
+ type: 'arc',
282
+ name: 'mainArc',
283
+ from: { data: 'table' },
284
+ encode: {
285
+ enter: {
286
+ fill: { scale: 'mainColor', field: 'category' },
287
+ x: { signal: 'centerX' },
288
+ y: { signal: 'centerY' },
289
+ startAngle: { field: 'startAngle' },
290
+ endAngle: { field: 'endAngle' },
291
+ innerRadius: { signal: 'radius * 0.5' },
292
+ outerRadius: { signal: 'radius * 0.9' },
293
+ padAngle: { value: 0.03 },
294
+ cornerRadius: { value: 1 },
295
+ },
296
+ },
297
+ interactive: true,
298
+ },
299
+ {
300
+ type: 'arc',
301
+ name: 'innerArc',
302
+ from: { data: 'table' },
303
+ encode: {
304
+ enter: {
305
+ fill: { value: 'transparent' },
306
+ x: { signal: 'centerX' },
307
+ y: { signal: 'centerY' },
308
+ startAngle: { field: 'startAngle' },
309
+ endAngle: { field: 'endAngle' },
310
+ innerRadius: { signal: 'radius * 0.4' },
311
+ outerRadius: { signal: 'radius * 0.5' },
312
+ padAngle: { value: 0.03 },
313
+ cornerRadius: { value: 1 },
314
+ },
315
+ },
316
+ zindex: 1,
317
+ },
318
+ {
319
+ type: 'arc',
320
+ name: 'outerArc',
321
+ from: { data: 'table' },
322
+ encode: {
323
+ enter: {
324
+ fill: { value: 'transparent' },
325
+ x: { signal: 'centerX' },
326
+ y: { signal: 'centerY' },
327
+ startAngle: { field: 'startAngle' },
328
+ endAngle: { field: 'endAngle' },
329
+ innerRadius: { signal: 'radius * 0.91' },
330
+ outerRadius: { signal: 'radius * 1.30' },
331
+ },
332
+ },
333
+ zindex: 1,
334
+ },
335
+ {
336
+ type: 'text',
337
+ name: 'mainArcLabel',
338
+ from: { data: 'table' },
339
+ encode: {
340
+ enter: {
341
+ text: { field: 'percentLabel' },
342
+ align: { value: 'center' },
343
+ baseline: { value: 'middle' },
344
+ fill: { value: '#302D3B' },
345
+ fontSize: { value: 10 },
346
+ x: { field: 'labelX' },
347
+ y: { field: 'labelY' },
348
+ font: {
349
+ value: "apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif",
350
+ },
351
+ fontWeight: 600,
352
+ },
353
+ },
354
+ },
355
+ {
356
+ type: 'text',
357
+ encode: {
358
+ enter: {
359
+ text: { value: '$850,000' },
360
+ x: { signal: 'centerX' },
361
+ y: { signal: 'centerY' },
362
+ align: { value: 'center' },
363
+ baseline: { value: 'middle' },
364
+ fontSize: { value: 16 },
365
+ fontWeight: { value: 'bold' },
366
+ fill: { value: '#302D3B' },
367
+ font: {
368
+ value: "apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif",
369
+ },
370
+ },
371
+ update: {
372
+ text: {
373
+ signal: `hoveredValue ? '${spec?.prefix ?? '$'}' + format(floor(hoveredValue), ',') + '${spec?.suffix ?? ''}' : '${spec?.prefix ?? '$'}' + format(floor(${this.totalRevenue ?? 1}), ',') + '${spec?.suffix ?? ''}'`,
374
+ },
375
+ },
376
+ },
377
+ },
378
+ {
379
+ type: 'text',
380
+ encode: {
381
+ enter: {
382
+ x: { signal: 'centerX' },
383
+ y: { signal: 'centerY + 15' },
384
+ align: { value: 'center' },
385
+ baseline: { value: 'middle' },
386
+ fontSize: { value: 10 },
387
+ fill: { value: '#6A6D7D' },
388
+ font: {
389
+ value: "apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif",
390
+ },
391
+ fontWeight: 400,
392
+ limit: { value: 100 },
393
+ lineBreak: { value: '\\n' },
394
+ },
395
+ update: { text: { signal: 'displayText' } },
396
+ },
397
+ },
398
+ ],
399
+ };
400
+ }
401
+ render() {
402
+ return (h(Host, { key: 'fb26a6b02b83b0ce64a8301149b66f5d09a4a7b4' }, h("div", { key: 'fc08cdc3c0c0fda7f7c13149532eb61f511aa035', id: "container", style: { width: '100%', height: '100%' } })));
403
+ }
404
+ };
405
+
406
+ export { ApolloDataDonutChart as apollo_data_donut_chart };