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