@xplortech/apollo-data 0.0.5 → 0.0.7
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/README.md +15 -91
- package/dist/apollo-data/apollo-data.esm.js +1 -1
- package/dist/apollo-data/p-4d3f0792.entry.js +1 -0
- package/dist/apollo-data/p-C2k3WBpi.js +11 -0
- package/dist/apollo-data/p-D64asVrg.js +2 -0
- package/dist/apollo-data/{p-b7471c12.entry.js → p-e2c3a317.entry.js} +1 -1
- package/dist/cjs/apollo-data-bar-chart_5.cjs.entry.js +1193 -0
- package/dist/cjs/{apollo-data-base-CxVQ-WVP.js → apollo-data-base-COGMOEqL.js} +7 -11
- package/dist/cjs/apollo-data-donut-chart.cjs.entry.js +3 -3
- package/dist/cjs/apollo-data.cjs.js +3 -3
- package/dist/cjs/{index-Cl7HgRm0.js → index-Bd5risOy.js} +116 -63
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/collection/apollo-data-base.js +4 -8
- package/dist/collection/collection-manifest.json +5 -2
- package/dist/collection/components/apollo-data-bar/apollo-data-bar.js +10 -9
- package/dist/collection/components/apollo-data-bar/apollo-data-bar.stories.js +122 -0
- package/dist/collection/components/apollo-data-donut/apollo-data-donut.js +1 -1
- package/dist/collection/components/apollo-data-donut/apollo-data-donut.stories.js +132 -0
- package/dist/collection/components/apollo-data-heat-map/apollo-data-heat-map.js +208 -0
- package/dist/collection/components/apollo-data-heat-map/apollo-data-heat-map.stories.js +137 -0
- package/dist/collection/components/apollo-data-line/apollo-data-line.js +8 -6
- package/dist/collection/components/apollo-data-line/apollo-data-line.stories.js +122 -0
- package/dist/collection/components/apollo-data-scatter/apollo-data-scatter.js +1 -1
- package/dist/collection/components/apollo-data-scatter/apollo-data-scatter.stories.js +147 -0
- package/dist/collection/components/apollo-data-world-map/apollo-data-world-map.js +294 -0
- package/dist/collection/components/apollo-data-world-map/apollo-data-world-map.stories.js +126 -0
- package/dist/collection/examples/apollo-data-heat-map.examples.js +131 -0
- package/dist/collection/examples/apollo-data-world-map.examples.js +45 -0
- package/dist/collection/examples/index.js +2 -0
- package/dist/collection/utils/code-generator.js +1 -1
- package/dist/components/apollo-data-bar-chart.js +1 -1
- package/dist/components/apollo-data-donut-chart.js +1 -1
- package/dist/components/apollo-data-heat-map.d.ts +11 -0
- package/dist/components/apollo-data-heat-map.js +1 -0
- package/dist/components/apollo-data-line-chart.js +1 -1
- package/dist/components/apollo-data-scatter-chart.js +1 -1
- package/dist/components/apollo-data-world-map-chart.d.ts +11 -0
- package/dist/components/apollo-data-world-map-chart.js +1 -0
- package/dist/components/index.js +1 -1
- package/dist/components/p-CfbMSXKd.js +11 -0
- package/dist/components/p-gcjU8DVr.js +1 -0
- package/dist/esm/apollo-data-bar-chart_5.entry.js +1187 -0
- package/dist/esm/{apollo-data-base-BWkrM8dc.js → apollo-data-base-C2k3WBpi.js} +7 -11
- package/dist/esm/apollo-data-donut-chart.entry.js +3 -3
- package/dist/esm/apollo-data.js +4 -4
- package/dist/esm/{index-Bb2nY-Tf.js → index-D64asVrg.js} +116 -63
- package/dist/esm/loader.js +3 -3
- package/dist/types/apollo-data-base.d.ts +2 -2
- package/dist/types/components/apollo-data-bar/apollo-data-bar.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-donut/apollo-data-donut.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-heat-map/apollo-data-heat-map.d.ts +140 -0
- package/dist/types/components/apollo-data-heat-map/apollo-data-heat-map.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-line/apollo-data-line.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-scatter/apollo-data-scatter.d.ts +1 -3
- package/dist/types/components/apollo-data-scatter/apollo-data-scatter.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-world-map/apollo-data-world-map.d.ts +281 -0
- package/dist/types/components/apollo-data-world-map/apollo-data-world-map.stories.d.ts +5 -0
- package/dist/types/components.d.ts +128 -8
- package/dist/types/examples/apollo-data-heat-map.examples.d.ts +11 -0
- package/dist/types/examples/apollo-data-scatter.examples.d.ts +1 -1
- package/dist/types/examples/apollo-data-world-map.examples.d.ts +11 -0
- package/dist/types/examples/index.d.ts +2 -0
- package/dist/types/stencil-public-runtime.d.ts +23 -2
- package/dist/types/utils/code-generator.d.ts +1 -3
- package/package.json +8 -8
- package/src/examples/apollo-data-bar.examples.ts +157 -157
- package/src/examples/apollo-data-heat-map.examples.ts +147 -0
- package/src/examples/apollo-data-line.examples.ts +91 -91
- package/src/examples/apollo-data-scatter.examples.ts +1 -1
- package/src/examples/apollo-data-world-map.examples.ts +57 -0
- package/src/examples/index.ts +3 -1
- package/dist/apollo-data/p-2nuV5Vny.js +0 -1
- package/dist/apollo-data/p-4ac3c97c.entry.js +0 -1
- package/dist/apollo-data/p-BWkrM8dc.js +0 -11
- package/dist/apollo-data/p-Bb2nY-Tf.js +0 -2
- package/dist/apollo-data/p-e518baac.entry.js +0 -1
- package/dist/cjs/apollo-data-bar-chart.cjs.entry.js +0 -314
- package/dist/cjs/apollo-data-line-chart_2.cjs.entry.js +0 -534
- package/dist/cjs/constants-B3weDEpc.js +0 -5
- package/dist/components/p-7XF5Cax8.js +0 -11
- package/dist/components/p-Dws5s-Xe.js +0 -1
- package/dist/esm/apollo-data-bar-chart.entry.js +0 -312
- package/dist/esm/apollo-data-line-chart_2.entry.js +0 -531
- package/dist/esm/constants-2nuV5Vny.js +0 -3
|
@@ -0,0 +1,1187 @@
|
|
|
1
|
+
import { r as registerInstance, g as getElement, h, H as Host } from './index-D64asVrg.js';
|
|
2
|
+
import { A as ApolloBase } from './apollo-data-base-C2k3WBpi.js';
|
|
3
|
+
|
|
4
|
+
const CHART_COLORS = ['#4d1ab2', '#f99170', '#e550c8', '#ffd563', '#8857fa', '#52ebba', '#bf1d78', '#31cff8'];
|
|
5
|
+
|
|
6
|
+
const FONT_FAMILY$1 = "apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif";
|
|
7
|
+
const ApolloDataBarChart = class extends ApolloBase {
|
|
8
|
+
constructor(hostRef) {
|
|
9
|
+
super();
|
|
10
|
+
registerInstance(this, hostRef);
|
|
11
|
+
}
|
|
12
|
+
get el() { return getElement(this); }
|
|
13
|
+
adData = [];
|
|
14
|
+
adSpec = null;
|
|
15
|
+
static tooltipStylesInjected = false;
|
|
16
|
+
componentDidLoad() {
|
|
17
|
+
this.injectTooltipStyles();
|
|
18
|
+
}
|
|
19
|
+
async componentDidRender() {
|
|
20
|
+
await this.renderChart();
|
|
21
|
+
}
|
|
22
|
+
injectTooltipStyles() {
|
|
23
|
+
const chartClass = this.constructor;
|
|
24
|
+
if (chartClass.tooltipStylesInjected) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const styleId = 'apollo-data-bar-tooltip-styles';
|
|
28
|
+
if (document.getElementById(styleId)) {
|
|
29
|
+
chartClass.tooltipStylesInjected = true;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const style = document.createElement('style');
|
|
33
|
+
style.id = styleId;
|
|
34
|
+
style.textContent = `
|
|
35
|
+
#vg-tooltip-element {
|
|
36
|
+
background-color: #ffffff;
|
|
37
|
+
border: 1px solid #e1e2e8;
|
|
38
|
+
border-radius: 0.25rem;
|
|
39
|
+
box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.05);
|
|
40
|
+
font-family: apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif;
|
|
41
|
+
font-weight: 500;
|
|
42
|
+
padding: 0.25rem 0.75rem;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
text-align: center;
|
|
45
|
+
transform: translateY(20%);
|
|
46
|
+
white-space: pre;
|
|
47
|
+
z-index: 999999999;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#vg-tooltip-element table tr td.key {
|
|
51
|
+
color: #6a6d7d;
|
|
52
|
+
text-align: center;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#vg-tooltip-element table tr td.value {
|
|
56
|
+
text-align: center;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#vg-tooltip-element.dark-theme {
|
|
60
|
+
background-color: #292632;
|
|
61
|
+
border: 1px solid #6a6d7d;
|
|
62
|
+
box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.5);
|
|
63
|
+
color: #ffffff;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
#vg-tooltip-element::after {
|
|
67
|
+
border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
|
|
68
|
+
border-style: solid;
|
|
69
|
+
border-width: 9px;
|
|
70
|
+
bottom: -17px;
|
|
71
|
+
content: '';
|
|
72
|
+
left: 50%;
|
|
73
|
+
position: absolute;
|
|
74
|
+
transform: translateX(-50%);
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
document.head.appendChild(style);
|
|
78
|
+
chartClass.tooltipStylesInjected = true;
|
|
79
|
+
}
|
|
80
|
+
async getViewData(data, spec) {
|
|
81
|
+
const componentTag = this.el?.tagName?.toLowerCase() ?? 'apollo-data-bar-chart';
|
|
82
|
+
if (!spec) {
|
|
83
|
+
throw new Error(`adSpec is required for ${componentTag}`);
|
|
84
|
+
}
|
|
85
|
+
const { tooltipPrefix = '', currencySymbol = '' } = spec;
|
|
86
|
+
if (!data || data.length === 0) {
|
|
87
|
+
throw new Error(`Data is required for ${componentTag}`);
|
|
88
|
+
}
|
|
89
|
+
const uniqueCategories = Array.from(new Set(data.map(item => item.category)));
|
|
90
|
+
const formatNumber = tooltipPrefix ? '.2f' : '.0f';
|
|
91
|
+
const currencyPrefix = tooltipPrefix ? currencySymbol : '';
|
|
92
|
+
return {
|
|
93
|
+
$schema: 'https://vega.github.io/schema/vega/v5.json',
|
|
94
|
+
config: {
|
|
95
|
+
text: {
|
|
96
|
+
fill: '#6a6d7d',
|
|
97
|
+
font: FONT_FAMILY$1,
|
|
98
|
+
labelFontSize: 12,
|
|
99
|
+
labelFontWeight: 400,
|
|
100
|
+
},
|
|
101
|
+
axis: {
|
|
102
|
+
labelColor: '#6a6d7d',
|
|
103
|
+
titleColor: '#6a6d7d',
|
|
104
|
+
labelFont: FONT_FAMILY$1,
|
|
105
|
+
titleFont: FONT_FAMILY$1,
|
|
106
|
+
titleFontWeight: 400,
|
|
107
|
+
},
|
|
108
|
+
legend: {
|
|
109
|
+
labelColor: '#6a6d7d',
|
|
110
|
+
titleColor: '#6a6d7d',
|
|
111
|
+
labelFont: FONT_FAMILY$1,
|
|
112
|
+
titleFont: FONT_FAMILY$1,
|
|
113
|
+
labelFontSize: 12,
|
|
114
|
+
labelLimit: 95,
|
|
115
|
+
},
|
|
116
|
+
title: {
|
|
117
|
+
color: '#6a6d7d',
|
|
118
|
+
font: FONT_FAMILY$1,
|
|
119
|
+
labelFontSize: 12,
|
|
120
|
+
labelFontWeight: 400,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
height: 250,
|
|
124
|
+
autosize: { type: 'fit-x', contains: 'padding', resize: true },
|
|
125
|
+
signals: [
|
|
126
|
+
{
|
|
127
|
+
name: 'containerW',
|
|
128
|
+
update: 'max(containerSize()[0], 400)',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'legendColumns',
|
|
132
|
+
update: 'ceil(containerW / 140)',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'hoveredPeriod',
|
|
136
|
+
value: null,
|
|
137
|
+
on: [
|
|
138
|
+
{ events: 'rect:mouseover', update: 'datum.periodId' },
|
|
139
|
+
{ events: 'rect:mouseout', update: 'null' },
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
width: { signal: 'containerW' },
|
|
144
|
+
data: [
|
|
145
|
+
{
|
|
146
|
+
name: 'raw',
|
|
147
|
+
values: data,
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: 'periodTotals',
|
|
151
|
+
source: 'raw',
|
|
152
|
+
transform: [
|
|
153
|
+
{
|
|
154
|
+
type: 'aggregate',
|
|
155
|
+
groupby: ['periodId'],
|
|
156
|
+
fields: ['value'],
|
|
157
|
+
ops: ['sum'],
|
|
158
|
+
as: ['total'],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: 'table',
|
|
164
|
+
source: 'raw',
|
|
165
|
+
transform: [
|
|
166
|
+
{
|
|
167
|
+
type: 'lookup',
|
|
168
|
+
from: 'periodTotals',
|
|
169
|
+
key: 'periodId',
|
|
170
|
+
fields: ['periodId'],
|
|
171
|
+
values: ['total'],
|
|
172
|
+
as: ['total'],
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
type: 'stack',
|
|
176
|
+
groupby: ['periodId'],
|
|
177
|
+
sort: { field: 'category' },
|
|
178
|
+
field: 'value',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
type: 'formula',
|
|
182
|
+
as: 'periodId',
|
|
183
|
+
expr: 'datum.periodId',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
type: 'formula',
|
|
187
|
+
as: 'labelOnly',
|
|
188
|
+
expr: 'datum.label',
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: 'periodLabels',
|
|
194
|
+
source: 'raw',
|
|
195
|
+
transform: [
|
|
196
|
+
{
|
|
197
|
+
type: 'aggregate',
|
|
198
|
+
groupby: ['periodId', 'label'],
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
scales: [
|
|
204
|
+
{
|
|
205
|
+
name: 'x',
|
|
206
|
+
type: 'band',
|
|
207
|
+
domain: { data: 'table', field: 'periodId' },
|
|
208
|
+
range: 'width',
|
|
209
|
+
paddingInner: 0.35,
|
|
210
|
+
paddingOuter: 0.02,
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: 'xLabels',
|
|
214
|
+
type: 'ordinal',
|
|
215
|
+
domain: { data: 'periodLabels', field: 'periodId' },
|
|
216
|
+
range: { data: 'periodLabels', field: 'label' },
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: 'y',
|
|
220
|
+
type: 'linear',
|
|
221
|
+
domain: { data: 'table', field: 'y1' },
|
|
222
|
+
nice: true,
|
|
223
|
+
zero: true,
|
|
224
|
+
range: 'height',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: 'color',
|
|
228
|
+
type: 'ordinal',
|
|
229
|
+
domain: uniqueCategories,
|
|
230
|
+
range: spec?.colorSet ?? CHART_COLORS,
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
axes: [
|
|
234
|
+
{
|
|
235
|
+
orient: 'bottom',
|
|
236
|
+
scale: 'x',
|
|
237
|
+
title: spec?.xAxisTitle,
|
|
238
|
+
labelPadding: 12,
|
|
239
|
+
titlePadding: 12,
|
|
240
|
+
labelAngle: -90,
|
|
241
|
+
labelAlign: 'right',
|
|
242
|
+
labelBaseline: 'middle',
|
|
243
|
+
tickSize: 3,
|
|
244
|
+
labelFontSize: 12,
|
|
245
|
+
titleFontSize: 14,
|
|
246
|
+
ticks: false,
|
|
247
|
+
domain: false,
|
|
248
|
+
encode: {
|
|
249
|
+
labels: {
|
|
250
|
+
update: {
|
|
251
|
+
text: { signal: "scale('xLabels', datum.value)" },
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
orient: 'left',
|
|
258
|
+
scale: 'y',
|
|
259
|
+
title: spec?.yAxisTitle || '',
|
|
260
|
+
format: ',.0f',
|
|
261
|
+
grid: true,
|
|
262
|
+
tickCount: 6,
|
|
263
|
+
labelFontSize: 12,
|
|
264
|
+
titleFontSize: 14,
|
|
265
|
+
ticks: false,
|
|
266
|
+
domain: false,
|
|
267
|
+
tickBand: 'extent',
|
|
268
|
+
labelPadding: 10,
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
legends: [
|
|
272
|
+
{
|
|
273
|
+
fill: 'color',
|
|
274
|
+
orient: 'bottom',
|
|
275
|
+
direction: 'horizontal',
|
|
276
|
+
columns: { signal: 'legendColumns' },
|
|
277
|
+
title: null,
|
|
278
|
+
symbolType: 'square',
|
|
279
|
+
rowPadding: 8,
|
|
280
|
+
symbolOffset: -35,
|
|
281
|
+
symbolSize: 100,
|
|
282
|
+
labelOffset: 8,
|
|
283
|
+
labelLimit: 95,
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
marks: [
|
|
287
|
+
{
|
|
288
|
+
type: 'rect',
|
|
289
|
+
from: { data: 'table' },
|
|
290
|
+
encode: {
|
|
291
|
+
enter: {
|
|
292
|
+
x: { scale: 'x', field: 'periodId' },
|
|
293
|
+
width: { scale: 'x', band: 1 },
|
|
294
|
+
y: { scale: 'y', field: 'y1' },
|
|
295
|
+
y2: { scale: 'y', field: 'y0' },
|
|
296
|
+
fill: { scale: 'color', field: 'category' },
|
|
297
|
+
tooltip: {
|
|
298
|
+
signal: `datum.category + ': ${currencyPrefix}' + format(datum.value, ',${formatNumber}') + '\\nTotal: ${currencyPrefix}' + format(datum.total, ',${formatNumber}')`,
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
update: {
|
|
302
|
+
opacity: [{ test: 'hoveredPeriod && datum.periodId !== hoveredPeriod', value: 0.2 }, { value: 1 }],
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
render() {
|
|
310
|
+
return (h(Host, { key: 'fd34c44431e85e36cec86ff19c7142c2deb2e9ff' }, h("div", { key: 'f3e9c269e4817b0f06233860c67649f1e1d9ec16', id: "container", style: { width: '100%', height: '100%' } })));
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const ApolloDataHeatMap = class extends ApolloBase {
|
|
315
|
+
constructor(hostRef) {
|
|
316
|
+
super();
|
|
317
|
+
registerInstance(this, hostRef);
|
|
318
|
+
}
|
|
319
|
+
get el() { return getElement(this); }
|
|
320
|
+
/**
|
|
321
|
+
* Data for the heat map. Each item defines a cell by xLabel, yLabel, and value.
|
|
322
|
+
* @property {string} xLabel - Label for the X-axis (horizontal).
|
|
323
|
+
* @property {string} yLabel - Label for the Y-axis (vertical).
|
|
324
|
+
* @property {number} value - Numeric value encoded as color.
|
|
325
|
+
*/
|
|
326
|
+
adData = [];
|
|
327
|
+
/**
|
|
328
|
+
* Optional specification for axis titles, color range, and tooltip behavior.
|
|
329
|
+
* @property {string} [xAxisTitle] - Label for the X-axis.
|
|
330
|
+
* @property {string} [yAxisTitle] - Label for the Y-axis.
|
|
331
|
+
* @property {string[]} [colorRange] - Two or more colors for the value scale (Vega interpolates between them).
|
|
332
|
+
* @property {'auto' | 'none'} [tooltip] - Tooltip behavior.
|
|
333
|
+
*/
|
|
334
|
+
adSpec = {};
|
|
335
|
+
async componentDidRender() {
|
|
336
|
+
await this.renderChart();
|
|
337
|
+
}
|
|
338
|
+
DEFAULT_COLOR_RANGE = ['#e8f4f8', '#0066a1'];
|
|
339
|
+
// @ts-ignore
|
|
340
|
+
async getViewData(data, spec) {
|
|
341
|
+
const rawRange = spec?.colorRange;
|
|
342
|
+
const colorRange = Array.isArray(rawRange) && rawRange.length >= 2 ? rawRange : this.DEFAULT_COLOR_RANGE;
|
|
343
|
+
const tooltip = spec?.tooltip !== 'none';
|
|
344
|
+
const valid = data.filter(d => d != null && typeof d.xLabel === 'string' && typeof d.yLabel === 'string' && d.xLabel !== '' && d.yLabel !== '' && typeof d.value === 'number');
|
|
345
|
+
const xLabels = [...new Set(valid.map(d => d.xLabel))];
|
|
346
|
+
const yLabels = [...new Set(valid.map(d => d.yLabel))];
|
|
347
|
+
return {
|
|
348
|
+
$schema: 'https://vega.github.io/schema/vega/v6.json',
|
|
349
|
+
description: 'A heat map with xLabel and yLabel categories and value encoded as color.',
|
|
350
|
+
width: 450,
|
|
351
|
+
height: 350,
|
|
352
|
+
padding: { left: 5, top: 5, bottom: 5, right: 70 },
|
|
353
|
+
autosize: { type: 'fit', resize: true },
|
|
354
|
+
data: [
|
|
355
|
+
{
|
|
356
|
+
name: 'source',
|
|
357
|
+
values: valid,
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
scales: [
|
|
361
|
+
{
|
|
362
|
+
name: 'xscale',
|
|
363
|
+
type: 'band',
|
|
364
|
+
range: [0, { signal: 'width' }],
|
|
365
|
+
domain: xLabels,
|
|
366
|
+
padding: 0.05,
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
name: 'yscale',
|
|
370
|
+
type: 'band',
|
|
371
|
+
range: [{ signal: 'height' }, 0],
|
|
372
|
+
domain: yLabels,
|
|
373
|
+
padding: 0.05,
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
name: 'color',
|
|
377
|
+
type: 'sequential',
|
|
378
|
+
range: colorRange,
|
|
379
|
+
domain: { data: 'source', field: 'value' },
|
|
380
|
+
zero: true,
|
|
381
|
+
},
|
|
382
|
+
],
|
|
383
|
+
axes: [
|
|
384
|
+
{
|
|
385
|
+
orient: 'bottom',
|
|
386
|
+
scale: 'xscale',
|
|
387
|
+
title: spec?.xAxisTitle ?? 'X',
|
|
388
|
+
labelAngle: -90,
|
|
389
|
+
labelAlign: 'right',
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
orient: 'left',
|
|
393
|
+
scale: 'yscale',
|
|
394
|
+
title: spec?.yAxisTitle ?? 'Y',
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
legends: [
|
|
398
|
+
{
|
|
399
|
+
type: 'gradient',
|
|
400
|
+
fill: 'color',
|
|
401
|
+
orient: 'right',
|
|
402
|
+
direction: 'vertical',
|
|
403
|
+
title: 'Value',
|
|
404
|
+
titleLimit: 120,
|
|
405
|
+
tickCount: 5,
|
|
406
|
+
format: 's',
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
marks: [
|
|
410
|
+
{
|
|
411
|
+
type: 'rect',
|
|
412
|
+
from: { data: 'source' },
|
|
413
|
+
encode: {
|
|
414
|
+
...(tooltip && {
|
|
415
|
+
enter: {
|
|
416
|
+
tooltip: {
|
|
417
|
+
signal: "datum.xLabel + ' | ' + datum.yLabel + ' | ' + format(datum.value, ',.2f')",
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
}),
|
|
421
|
+
update: {
|
|
422
|
+
x: { scale: 'xscale', field: 'xLabel' },
|
|
423
|
+
y: { scale: 'yscale', field: 'yLabel' },
|
|
424
|
+
width: { scale: 'xscale', band: 1 },
|
|
425
|
+
height: { scale: 'yscale', band: 1 },
|
|
426
|
+
fill: { scale: 'color', field: 'value' },
|
|
427
|
+
},
|
|
428
|
+
hover: {
|
|
429
|
+
fill: { value: 'firebrick' },
|
|
430
|
+
opacity: { value: 0.8 },
|
|
431
|
+
},
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
],
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
render() {
|
|
438
|
+
return (h(Host, { key: 'd15b44f268f153498e61dc7829fe0d45f315a992' }, h("div", { key: '7783444f4675c885980f1cd571737d506e00fdbc', id: "container", style: { width: '100%', height: '100%' } })));
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
const FONT_FAMILY = "apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif";
|
|
443
|
+
function lineStyleToStrokeDash(lineStyle) {
|
|
444
|
+
switch (lineStyle) {
|
|
445
|
+
case 'dashed':
|
|
446
|
+
return [6, 4];
|
|
447
|
+
case 'dotted':
|
|
448
|
+
return [2, 2];
|
|
449
|
+
case 'solid':
|
|
450
|
+
default:
|
|
451
|
+
return [];
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const ApolloDataLineChart = class extends ApolloBase {
|
|
455
|
+
constructor(hostRef) {
|
|
456
|
+
super();
|
|
457
|
+
registerInstance(this, hostRef);
|
|
458
|
+
}
|
|
459
|
+
get el() { return getElement(this); }
|
|
460
|
+
adData = [];
|
|
461
|
+
adSpec = null;
|
|
462
|
+
static tooltipStylesInjected = false;
|
|
463
|
+
componentDidLoad() {
|
|
464
|
+
this.injectTooltipStyles();
|
|
465
|
+
}
|
|
466
|
+
async componentDidRender() {
|
|
467
|
+
await this.renderChart();
|
|
468
|
+
}
|
|
469
|
+
injectTooltipStyles() {
|
|
470
|
+
const chartClass = this.constructor;
|
|
471
|
+
if (chartClass.tooltipStylesInjected) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
const styleId = 'apollo-data-line-tooltip-styles';
|
|
475
|
+
if (document.getElementById(styleId)) {
|
|
476
|
+
chartClass.tooltipStylesInjected = true;
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
const style = document.createElement('style');
|
|
480
|
+
style.id = styleId;
|
|
481
|
+
style.textContent = `
|
|
482
|
+
#vg-tooltip-element {
|
|
483
|
+
background-color: #ffffff;
|
|
484
|
+
border: 1px solid #e1e2e8;
|
|
485
|
+
border-radius: 0.25rem;
|
|
486
|
+
box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.05);
|
|
487
|
+
font-family: apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif;
|
|
488
|
+
font-weight: 500;
|
|
489
|
+
padding: 0.25rem 0.75rem;
|
|
490
|
+
pointer-events: none;
|
|
491
|
+
text-align: center;
|
|
492
|
+
transform: translateY(20%);
|
|
493
|
+
white-space: pre;
|
|
494
|
+
z-index: 999999999;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
#vg-tooltip-element table tr td.key {
|
|
498
|
+
color: #6a6d7d;
|
|
499
|
+
text-align: center;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
#vg-tooltip-element table tr td.value {
|
|
503
|
+
text-align: center;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
#vg-tooltip-element.dark-theme {
|
|
507
|
+
background-color: #292632;
|
|
508
|
+
border: 1px solid #6a6d7d;
|
|
509
|
+
box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.5);
|
|
510
|
+
color: #ffffff;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
#vg-tooltip-element::after {
|
|
514
|
+
border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
|
|
515
|
+
border-style: solid;
|
|
516
|
+
border-width: 9px;
|
|
517
|
+
bottom: -17px;
|
|
518
|
+
content: '';
|
|
519
|
+
left: 50%;
|
|
520
|
+
position: absolute;
|
|
521
|
+
transform: translateX(-50%);
|
|
522
|
+
}
|
|
523
|
+
`;
|
|
524
|
+
document.head.appendChild(style);
|
|
525
|
+
chartClass.tooltipStylesInjected = true;
|
|
526
|
+
}
|
|
527
|
+
// @ts-ignore
|
|
528
|
+
async getViewData(data, spec) {
|
|
529
|
+
const componentTag = this.el?.tagName?.toLowerCase() ?? 'apollo-data-line-chart';
|
|
530
|
+
if (!spec) {
|
|
531
|
+
throw new Error(`adSpec is required for ${componentTag}`);
|
|
532
|
+
}
|
|
533
|
+
const { tooltipPrefix = '', currencySymbol = '' } = spec;
|
|
534
|
+
if (!data || data.length === 0) {
|
|
535
|
+
throw new Error(`Data is required for ${componentTag}`);
|
|
536
|
+
}
|
|
537
|
+
const uniqueCategories = Array.from(new Set(data.map(item => item.category)));
|
|
538
|
+
const uniqueXValues = [...new Set(data.map(item => item.xValue))].sort((a, b) => a - b);
|
|
539
|
+
const colorSet = spec?.colorSet ?? CHART_COLORS;
|
|
540
|
+
const xLabelData = uniqueXValues.map(x => {
|
|
541
|
+
const first = data.find(d => d.xValue === x);
|
|
542
|
+
return { xValue: x, displayLabel: first?.xLabel != null ? first.xLabel : String(x) };
|
|
543
|
+
});
|
|
544
|
+
const formatNumber = tooltipPrefix ? '.2f' : '.0f';
|
|
545
|
+
const currencyPrefix = tooltipPrefix ? currencySymbol : '';
|
|
546
|
+
const pointShape = spec.pointStyle ?? 'circle';
|
|
547
|
+
const strokeDash = lineStyleToStrokeDash(spec.lineStyle ?? 'solid');
|
|
548
|
+
const dataSpec = [
|
|
549
|
+
{ name: 'raw', values: data },
|
|
550
|
+
{ name: 'xLabelData', values: xLabelData },
|
|
551
|
+
];
|
|
552
|
+
uniqueCategories.forEach((cat, i) => {
|
|
553
|
+
dataSpec.push({
|
|
554
|
+
name: `series_${i}`,
|
|
555
|
+
source: 'raw',
|
|
556
|
+
transform: [
|
|
557
|
+
{ type: 'filter', expr: `datum.category === ${JSON.stringify(cat)}` },
|
|
558
|
+
{ type: 'collect', sort: { field: 'xValue' } },
|
|
559
|
+
],
|
|
560
|
+
});
|
|
561
|
+
});
|
|
562
|
+
const lineMarks = uniqueCategories.map((_, i) => ({
|
|
563
|
+
type: 'line',
|
|
564
|
+
from: { data: `series_${i}` },
|
|
565
|
+
encode: {
|
|
566
|
+
enter: {
|
|
567
|
+
x: { scale: 'x', field: 'xValue' },
|
|
568
|
+
y: { scale: 'y', field: 'yValue' },
|
|
569
|
+
stroke: { value: colorSet[i % colorSet.length] },
|
|
570
|
+
strokeWidth: { value: 2 },
|
|
571
|
+
interpolate: { value: 'monotone' },
|
|
572
|
+
...(strokeDash.length > 0 ? { strokeDash: { value: strokeDash } } : {}),
|
|
573
|
+
},
|
|
574
|
+
},
|
|
575
|
+
}));
|
|
576
|
+
return {
|
|
577
|
+
$schema: 'https://vega.github.io/schema/vega/v5.json',
|
|
578
|
+
config: {
|
|
579
|
+
text: {
|
|
580
|
+
fill: '#6a6d7d',
|
|
581
|
+
font: FONT_FAMILY,
|
|
582
|
+
labelFontSize: 12,
|
|
583
|
+
labelFontWeight: 400,
|
|
584
|
+
},
|
|
585
|
+
axis: {
|
|
586
|
+
labelColor: '#6a6d7d',
|
|
587
|
+
titleColor: '#6a6d7d',
|
|
588
|
+
labelFont: FONT_FAMILY,
|
|
589
|
+
titleFont: FONT_FAMILY,
|
|
590
|
+
titleFontWeight: 400,
|
|
591
|
+
},
|
|
592
|
+
legend: {
|
|
593
|
+
labelColor: '#6a6d7d',
|
|
594
|
+
titleColor: '#6a6d7d',
|
|
595
|
+
labelFont: FONT_FAMILY,
|
|
596
|
+
titleFont: FONT_FAMILY,
|
|
597
|
+
labelFontSize: 12,
|
|
598
|
+
labelLimit: 95,
|
|
599
|
+
},
|
|
600
|
+
title: {
|
|
601
|
+
color: '#6a6d7d',
|
|
602
|
+
font: FONT_FAMILY,
|
|
603
|
+
labelFontSize: 12,
|
|
604
|
+
labelFontWeight: 400,
|
|
605
|
+
},
|
|
606
|
+
},
|
|
607
|
+
height: 250,
|
|
608
|
+
autosize: { type: 'fit-x', contains: 'padding', resize: true },
|
|
609
|
+
signals: [
|
|
610
|
+
{
|
|
611
|
+
name: 'containerW',
|
|
612
|
+
update: 'max(containerSize()[0], 400)',
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
name: 'legendColumns',
|
|
616
|
+
update: 'ceil(containerW / 140)',
|
|
617
|
+
},
|
|
618
|
+
],
|
|
619
|
+
width: { signal: 'containerW' },
|
|
620
|
+
data: dataSpec,
|
|
621
|
+
scales: [
|
|
622
|
+
{
|
|
623
|
+
name: 'x',
|
|
624
|
+
type: 'point',
|
|
625
|
+
domain: uniqueXValues,
|
|
626
|
+
range: 'width',
|
|
627
|
+
padding: 0.5,
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
name: 'xLabels',
|
|
631
|
+
type: 'ordinal',
|
|
632
|
+
domain: { data: 'xLabelData', field: 'xValue' },
|
|
633
|
+
range: { data: 'xLabelData', field: 'displayLabel' },
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
name: 'y',
|
|
637
|
+
type: 'linear',
|
|
638
|
+
domain: { data: 'raw', field: 'yValue' },
|
|
639
|
+
nice: true,
|
|
640
|
+
zero: true,
|
|
641
|
+
range: 'height',
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
name: 'color',
|
|
645
|
+
type: 'ordinal',
|
|
646
|
+
domain: uniqueCategories,
|
|
647
|
+
range: spec?.colorSet ?? CHART_COLORS,
|
|
648
|
+
},
|
|
649
|
+
],
|
|
650
|
+
axes: [
|
|
651
|
+
{
|
|
652
|
+
orient: 'bottom',
|
|
653
|
+
scale: 'x',
|
|
654
|
+
title: spec?.xAxisTitle,
|
|
655
|
+
labelPadding: 12,
|
|
656
|
+
titlePadding: 12,
|
|
657
|
+
labelAngle: -90,
|
|
658
|
+
labelAlign: 'right',
|
|
659
|
+
labelBaseline: 'middle',
|
|
660
|
+
tickSize: 3,
|
|
661
|
+
labelFontSize: 12,
|
|
662
|
+
titleFontSize: 14,
|
|
663
|
+
ticks: false,
|
|
664
|
+
domain: false,
|
|
665
|
+
encode: {
|
|
666
|
+
labels: {
|
|
667
|
+
update: {
|
|
668
|
+
text: { signal: "scale('xLabels', datum.value)" },
|
|
669
|
+
},
|
|
670
|
+
},
|
|
671
|
+
},
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
orient: 'left',
|
|
675
|
+
scale: 'y',
|
|
676
|
+
title: spec?.yAxisTitle || '',
|
|
677
|
+
format: ',.0f',
|
|
678
|
+
grid: true,
|
|
679
|
+
tickCount: 6,
|
|
680
|
+
labelFontSize: 12,
|
|
681
|
+
titleFontSize: 14,
|
|
682
|
+
ticks: false,
|
|
683
|
+
domain: false,
|
|
684
|
+
tickBand: 'extent',
|
|
685
|
+
labelPadding: 10,
|
|
686
|
+
},
|
|
687
|
+
],
|
|
688
|
+
legends: [
|
|
689
|
+
{
|
|
690
|
+
stroke: 'color',
|
|
691
|
+
orient: 'bottom',
|
|
692
|
+
direction: 'horizontal',
|
|
693
|
+
columns: { signal: 'legendColumns' },
|
|
694
|
+
title: null,
|
|
695
|
+
symbolType: 'stroke',
|
|
696
|
+
symbolStrokeWidth: 3,
|
|
697
|
+
rowPadding: 8,
|
|
698
|
+
symbolOffset: -35,
|
|
699
|
+
symbolSize: 100,
|
|
700
|
+
labelOffset: 8,
|
|
701
|
+
labelLimit: 95,
|
|
702
|
+
},
|
|
703
|
+
],
|
|
704
|
+
marks: [
|
|
705
|
+
...lineMarks,
|
|
706
|
+
{
|
|
707
|
+
type: 'symbol',
|
|
708
|
+
from: { data: 'raw' },
|
|
709
|
+
encode: {
|
|
710
|
+
enter: {
|
|
711
|
+
x: { scale: 'x', field: 'xValue' },
|
|
712
|
+
y: { scale: 'y', field: 'yValue' },
|
|
713
|
+
fill: { scale: 'color', field: 'category' },
|
|
714
|
+
size: { value: 50 },
|
|
715
|
+
shape: { value: pointShape },
|
|
716
|
+
tooltip: {
|
|
717
|
+
signal: `(datum.xLabel != null ? datum.xLabel : format(datum.xValue, ',.0f')) + ' · ' + datum.category + ': ' + (datum.yLabel != null ? datum.yLabel : '${currencyPrefix}' + format(datum.yValue, ',${formatNumber}'))`,
|
|
718
|
+
},
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
},
|
|
722
|
+
],
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
render() {
|
|
726
|
+
return (h(Host, { key: 'fd64f4abb624b14a878808b23345910c9b23a72c' }, h("div", { key: 'aeda5086730862ca1368a0374caf2d918969839d', id: "container", style: { width: '100%', height: '100%' } })));
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
const ApolloDataScatterChart = class extends ApolloBase {
|
|
731
|
+
constructor(hostRef) {
|
|
732
|
+
super();
|
|
733
|
+
registerInstance(this, hostRef);
|
|
734
|
+
}
|
|
735
|
+
get el() { return getElement(this); }
|
|
736
|
+
/**
|
|
737
|
+
* Represents a single data point in the scatter chart.
|
|
738
|
+
* @property {string} category - Category or group name associated with the data point.
|
|
739
|
+
* This can be used for legend grouping or category-based styling.
|
|
740
|
+
* @property {number} xValue - Numeric value plotted along the X-axis.
|
|
741
|
+
* @property {number} yValue - Numeric value plotted along the Y-axis.
|
|
742
|
+
* @property {PointStyle} [pointStyle] - Optional style override for this specific data point.
|
|
743
|
+
* If provided, it takes precedence over default or category-level styles.
|
|
744
|
+
*/
|
|
745
|
+
adData = [];
|
|
746
|
+
/**
|
|
747
|
+
* Optional specification object for customizing the scatter chart configuration.
|
|
748
|
+
* @property {string} [yAxisTitle] - Label displayed for the Y-axis.
|
|
749
|
+
* @property {string} [xAxisTitle] - Label displayed for the X-axis.
|
|
750
|
+
* @property {PointStyle} [defaultPointStyle] - Default styling applied to all scatter points (e.g., size, color, shape, opacity).
|
|
751
|
+
* @property {PointStyle} [pointStyle] - Global point style override applied to all data points.
|
|
752
|
+
* @property {{ [categoryName: string]: PointStyle }} [categoryPointStyleMap] -
|
|
753
|
+
* A mapping object that allows custom point styles per category name.
|
|
754
|
+
* Each key represents a category, and its value defines the corresponding PointStyle.
|
|
755
|
+
* @property {'auto' | 'none'} [tooltip] - Controls tooltip behavior.
|
|
756
|
+
* 'auto' enables default tooltip rendering, while 'none' disables tooltips.
|
|
757
|
+
*/
|
|
758
|
+
adSpec = {};
|
|
759
|
+
async componentDidRender() {
|
|
760
|
+
await this.renderChart();
|
|
761
|
+
}
|
|
762
|
+
DEFAULT_POINT_STYLE = {
|
|
763
|
+
shape: 'circle',
|
|
764
|
+
opacity: 1,
|
|
765
|
+
color: 'blue',
|
|
766
|
+
size: 1,
|
|
767
|
+
};
|
|
768
|
+
// @ts-ignore
|
|
769
|
+
async getViewData(data, spec) {
|
|
770
|
+
const dataItemsToUse = data.map(dataItem => {
|
|
771
|
+
const pointStylesToUse = {};
|
|
772
|
+
Object.keys(this.DEFAULT_POINT_STYLE).forEach(key => {
|
|
773
|
+
const value = dataItem.pointStyle?.[key] ??
|
|
774
|
+
dataItem?.[key] ??
|
|
775
|
+
spec.categoryPointStyleMap?.[dataItem.category]?.[key] ??
|
|
776
|
+
spec.defaultPointStyle?.[key] ??
|
|
777
|
+
this.DEFAULT_POINT_STYLE[key];
|
|
778
|
+
pointStylesToUse[key] = value;
|
|
779
|
+
});
|
|
780
|
+
return {
|
|
781
|
+
category: dataItem.category,
|
|
782
|
+
xValue: dataItem.xValue,
|
|
783
|
+
yValue: dataItem.yValue,
|
|
784
|
+
color: pointStylesToUse.color,
|
|
785
|
+
shape: pointStylesToUse.shape,
|
|
786
|
+
opacity: pointStylesToUse.opacity,
|
|
787
|
+
};
|
|
788
|
+
});
|
|
789
|
+
const tooltipField = spec?.tooltip === 'auto' ? 'category' : 'none';
|
|
790
|
+
return {
|
|
791
|
+
$schema: 'https://vega.github.io/schema/vega/v6.json',
|
|
792
|
+
description: 'A scatter plot with null values visualized along the axes.',
|
|
793
|
+
width: 450,
|
|
794
|
+
height: 450,
|
|
795
|
+
padding: 5,
|
|
796
|
+
autosize: { type: 'fit', resize: true },
|
|
797
|
+
signals: [
|
|
798
|
+
{ name: 'nullSize', value: 8 },
|
|
799
|
+
{ name: 'nullGap', update: 'nullSize + 10' },
|
|
800
|
+
],
|
|
801
|
+
data: [
|
|
802
|
+
{
|
|
803
|
+
name: 'source',
|
|
804
|
+
values: dataItemsToUse,
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
name: 'valid',
|
|
808
|
+
source: 'source',
|
|
809
|
+
transform: [
|
|
810
|
+
{
|
|
811
|
+
type: 'filter',
|
|
812
|
+
expr: 'datum.xValue != null && datum.yValue != null',
|
|
813
|
+
},
|
|
814
|
+
],
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
name: 'nullXY',
|
|
818
|
+
source: 'source',
|
|
819
|
+
transform: [
|
|
820
|
+
{
|
|
821
|
+
type: 'filter',
|
|
822
|
+
expr: 'datum.xValue == null && datum.yValue == null',
|
|
823
|
+
},
|
|
824
|
+
{ type: 'aggregate' },
|
|
825
|
+
],
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
name: 'nullY',
|
|
829
|
+
source: 'source',
|
|
830
|
+
transform: [
|
|
831
|
+
{
|
|
832
|
+
type: 'filter',
|
|
833
|
+
expr: 'datum.xValue != null && datum.yValue == null',
|
|
834
|
+
},
|
|
835
|
+
],
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
name: 'nullX',
|
|
839
|
+
source: 'source',
|
|
840
|
+
transform: [
|
|
841
|
+
{
|
|
842
|
+
type: 'filter',
|
|
843
|
+
expr: 'datum.xValue == null && datum.yValue != null',
|
|
844
|
+
},
|
|
845
|
+
],
|
|
846
|
+
},
|
|
847
|
+
],
|
|
848
|
+
scales: [
|
|
849
|
+
{
|
|
850
|
+
name: 'xscale',
|
|
851
|
+
type: 'linear',
|
|
852
|
+
range: [{ signal: 'nullGap' }, { signal: 'width' }],
|
|
853
|
+
nice: true,
|
|
854
|
+
domain: { data: 'valid', field: 'xValue' },
|
|
855
|
+
},
|
|
856
|
+
{
|
|
857
|
+
name: 'yscale',
|
|
858
|
+
type: 'linear',
|
|
859
|
+
range: [{ signal: 'height - nullGap' }, 0],
|
|
860
|
+
nice: true,
|
|
861
|
+
domain: { data: 'valid', field: 'yValue' },
|
|
862
|
+
},
|
|
863
|
+
],
|
|
864
|
+
axes: [
|
|
865
|
+
{
|
|
866
|
+
orient: 'bottom',
|
|
867
|
+
scale: 'xscale',
|
|
868
|
+
offset: 5,
|
|
869
|
+
format: 's',
|
|
870
|
+
title: spec?.xAxisTitle || 'X Value',
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
orient: 'left',
|
|
874
|
+
scale: 'yscale',
|
|
875
|
+
offset: 5,
|
|
876
|
+
format: 's',
|
|
877
|
+
title: spec?.yAxisTitle || 'Y Value',
|
|
878
|
+
},
|
|
879
|
+
],
|
|
880
|
+
marks: [
|
|
881
|
+
{
|
|
882
|
+
type: 'symbol',
|
|
883
|
+
from: { data: 'valid' },
|
|
884
|
+
encode: {
|
|
885
|
+
enter: {
|
|
886
|
+
size: { value: 50 },
|
|
887
|
+
tooltip: { field: tooltipField },
|
|
888
|
+
},
|
|
889
|
+
update: {
|
|
890
|
+
x: { scale: 'xscale', field: 'xValue' },
|
|
891
|
+
y: { scale: 'yscale', field: 'yValue' },
|
|
892
|
+
fill: { field: 'color' },
|
|
893
|
+
fillOpacity: { field: 'opacity' },
|
|
894
|
+
shape: { field: 'shape' },
|
|
895
|
+
zindex: { value: 0 },
|
|
896
|
+
},
|
|
897
|
+
hover: {
|
|
898
|
+
fill: { value: 'firebrick' },
|
|
899
|
+
fillOpacity: { value: 1 },
|
|
900
|
+
zindex: { value: 1 },
|
|
901
|
+
},
|
|
902
|
+
},
|
|
903
|
+
},
|
|
904
|
+
{
|
|
905
|
+
type: 'symbol',
|
|
906
|
+
from: { data: 'nullY' },
|
|
907
|
+
encode: {
|
|
908
|
+
enter: {
|
|
909
|
+
size: { value: 50 },
|
|
910
|
+
tooltip: { field: tooltipField },
|
|
911
|
+
},
|
|
912
|
+
update: {
|
|
913
|
+
x: { scale: 'xscale', field: 'xValue' },
|
|
914
|
+
y: { signal: 'height - nullSize/2' },
|
|
915
|
+
fill: { value: '#aaa' },
|
|
916
|
+
fillOpacity: { value: 0.2 },
|
|
917
|
+
},
|
|
918
|
+
hover: {
|
|
919
|
+
fill: { value: 'firebrick' },
|
|
920
|
+
fillOpacity: { value: 1 },
|
|
921
|
+
},
|
|
922
|
+
},
|
|
923
|
+
},
|
|
924
|
+
{
|
|
925
|
+
type: 'symbol',
|
|
926
|
+
from: { data: 'nullX' },
|
|
927
|
+
encode: {
|
|
928
|
+
enter: {
|
|
929
|
+
size: { value: 50 },
|
|
930
|
+
tooltip: { field: 'name' },
|
|
931
|
+
},
|
|
932
|
+
update: {
|
|
933
|
+
x: { signal: 'nullSize/2' },
|
|
934
|
+
y: { scale: 'yscale', field: 'yValue' },
|
|
935
|
+
fill: { value: '#aaa' },
|
|
936
|
+
fillOpacity: { value: 0.2 },
|
|
937
|
+
zindex: { value: 0 },
|
|
938
|
+
},
|
|
939
|
+
hover: {
|
|
940
|
+
fill: { value: 'firebrick' },
|
|
941
|
+
fillOpacity: { value: 1 },
|
|
942
|
+
zindex: { value: 1 },
|
|
943
|
+
},
|
|
944
|
+
},
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
type: 'text',
|
|
948
|
+
interactive: false,
|
|
949
|
+
from: { data: 'nullXY' },
|
|
950
|
+
encode: {
|
|
951
|
+
update: {
|
|
952
|
+
x: { signal: 'nullSize', offset: -4 },
|
|
953
|
+
y: { signal: 'height', offset: 13 },
|
|
954
|
+
text: { signal: "datum.count + ' null'" },
|
|
955
|
+
align: { value: 'right' },
|
|
956
|
+
baseline: { value: 'top' },
|
|
957
|
+
fill: { value: '#999' },
|
|
958
|
+
fontSize: { value: 9 },
|
|
959
|
+
},
|
|
960
|
+
},
|
|
961
|
+
},
|
|
962
|
+
],
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
render() {
|
|
966
|
+
return (h(Host, { key: 'f6c1e8d9e9a6ba41dbbf8c2c5737895b96b0915d' }, h("div", { key: '2aeba82bc31c5995a3d5b532c339f5b45ae850f7', id: "container", style: { width: '100%', height: '100%' } })));
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
const ApolloDataWorldMapChart = class extends ApolloBase {
|
|
971
|
+
constructor(hostRef) {
|
|
972
|
+
super();
|
|
973
|
+
registerInstance(this, hostRef);
|
|
974
|
+
}
|
|
975
|
+
get el() { return getElement(this); }
|
|
976
|
+
/**
|
|
977
|
+
* Represents a single data point in the world map chart.
|
|
978
|
+
* @property {number} lon - Longitude coordinate used to position the point on the map.
|
|
979
|
+
* @property {number} lat - Latitude coordinate used to position the point on the map.
|
|
980
|
+
* @property {number} value - A numeric metric tied to the point.
|
|
981
|
+
* @property {string} label - Label displayed for the place or location represented by the point.
|
|
982
|
+
*/
|
|
983
|
+
adData = [];
|
|
984
|
+
/**
|
|
985
|
+
* @property {string} pinColor - Color of the pin representing the point.
|
|
986
|
+
* @property {'circle' | 'square' | 'triangle'} pinShape - Shape of the pin representing the point.
|
|
987
|
+
*/
|
|
988
|
+
adSpec = {};
|
|
989
|
+
async componentDidRender() {
|
|
990
|
+
await this.renderChart();
|
|
991
|
+
}
|
|
992
|
+
// @ts-ignore
|
|
993
|
+
// eslint-disable-next-line class-methods-use-this
|
|
994
|
+
async getViewData(data, spec) {
|
|
995
|
+
const pinColor = spec?.pinColor || '#d3544b';
|
|
996
|
+
const pinShape = spec?.pinShape || 'circle';
|
|
997
|
+
return {
|
|
998
|
+
$schema: 'https://vega.github.io/schema/vega/v6.json',
|
|
999
|
+
description: 'World map + tooltip + points.',
|
|
1000
|
+
width: 600,
|
|
1001
|
+
height: 400,
|
|
1002
|
+
autosize: 'none',
|
|
1003
|
+
background: '#cfe3f1',
|
|
1004
|
+
signals: [
|
|
1005
|
+
{
|
|
1006
|
+
name: 'scale',
|
|
1007
|
+
value: 85,
|
|
1008
|
+
on: [
|
|
1009
|
+
{
|
|
1010
|
+
events: { type: 'wheel', consume: true },
|
|
1011
|
+
update: 'clamp(scale * pow(1.002, -event.deltaY), 85, 2000)',
|
|
1012
|
+
},
|
|
1013
|
+
],
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
name: 'xc',
|
|
1017
|
+
value: 0,
|
|
1018
|
+
on: [{ events: 'mousedown', update: 'x()' }],
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
name: 'yc',
|
|
1022
|
+
value: 0,
|
|
1023
|
+
on: [{ events: 'mousedown', update: 'y()' }],
|
|
1024
|
+
},
|
|
1025
|
+
{
|
|
1026
|
+
name: 'xo',
|
|
1027
|
+
value: 300,
|
|
1028
|
+
on: [{ events: 'mousedown', update: 'tx' }],
|
|
1029
|
+
},
|
|
1030
|
+
{
|
|
1031
|
+
name: 'yo',
|
|
1032
|
+
value: 175,
|
|
1033
|
+
on: [{ events: 'mousedown', update: 'ty' }],
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
name: 'tx',
|
|
1037
|
+
value: 300,
|
|
1038
|
+
on: [
|
|
1039
|
+
{
|
|
1040
|
+
events: '[mousedown, window:mouseup] > window:mousemove',
|
|
1041
|
+
update: 'xo - (x() - xc)',
|
|
1042
|
+
},
|
|
1043
|
+
],
|
|
1044
|
+
},
|
|
1045
|
+
{
|
|
1046
|
+
name: 'ty',
|
|
1047
|
+
value: 270,
|
|
1048
|
+
on: [
|
|
1049
|
+
{
|
|
1050
|
+
events: '[mousedown, window:mouseup] > window:mousemove',
|
|
1051
|
+
update: 'clamp(yo + y() - yc, -scale * 0.5, scale * 2.5 + height)',
|
|
1052
|
+
},
|
|
1053
|
+
],
|
|
1054
|
+
},
|
|
1055
|
+
],
|
|
1056
|
+
projections: [
|
|
1057
|
+
{
|
|
1058
|
+
name: 'projection',
|
|
1059
|
+
type: 'mercator',
|
|
1060
|
+
scale: { signal: 'scale' },
|
|
1061
|
+
rotate: [{ signal: '-(tx - width / 2) * 180 / (scale * PI)' }, 0, 0],
|
|
1062
|
+
center: [0, 0],
|
|
1063
|
+
translate: [{ signal: 'width / 2' }, { signal: 'ty' }],
|
|
1064
|
+
},
|
|
1065
|
+
],
|
|
1066
|
+
data: [
|
|
1067
|
+
{
|
|
1068
|
+
name: 'names',
|
|
1069
|
+
url: 'https://raw.githubusercontent.com/KoGor/Map-Icons-Generator/master/data/world-110m-country-names.tsv',
|
|
1070
|
+
format: { type: 'tsv' },
|
|
1071
|
+
transform: [{ type: 'formula', as: 'id', expr: 'toNumber(datum.id)' }],
|
|
1072
|
+
},
|
|
1073
|
+
{
|
|
1074
|
+
name: 'metrics',
|
|
1075
|
+
values: data,
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
name: 'world',
|
|
1079
|
+
url: 'https://vega.github.io/editor/data/world-110m.json',
|
|
1080
|
+
format: { type: 'topojson', feature: 'countries' },
|
|
1081
|
+
transform: [
|
|
1082
|
+
{
|
|
1083
|
+
type: 'lookup',
|
|
1084
|
+
from: 'names',
|
|
1085
|
+
key: 'id',
|
|
1086
|
+
fields: ['id'],
|
|
1087
|
+
values: ['name'],
|
|
1088
|
+
as: ['name'],
|
|
1089
|
+
},
|
|
1090
|
+
{ type: 'filter', expr: "datum.name != 'Antarctica'" },
|
|
1091
|
+
],
|
|
1092
|
+
},
|
|
1093
|
+
{
|
|
1094
|
+
name: 'points',
|
|
1095
|
+
source: 'metrics',
|
|
1096
|
+
transform: [
|
|
1097
|
+
{ type: 'filter', expr: 'isValid(datum.lon) && isValid(datum.lat)' },
|
|
1098
|
+
{
|
|
1099
|
+
type: 'geopoint',
|
|
1100
|
+
projection: 'projection',
|
|
1101
|
+
fields: ['lon', 'lat'],
|
|
1102
|
+
as: ['x', 'y'],
|
|
1103
|
+
},
|
|
1104
|
+
],
|
|
1105
|
+
},
|
|
1106
|
+
{
|
|
1107
|
+
name: 'continentLabels',
|
|
1108
|
+
values: [
|
|
1109
|
+
{ name: 'North America', lon: -105, lat: 45 },
|
|
1110
|
+
{ name: 'South America', lon: -60, lat: -15 },
|
|
1111
|
+
{ name: 'Europe', lon: 15, lat: 52 },
|
|
1112
|
+
{ name: 'Africa', lon: 20, lat: 5 },
|
|
1113
|
+
{ name: 'Asia', lon: 90, lat: 35 },
|
|
1114
|
+
{ name: 'Oceania', lon: 135, lat: -25 },
|
|
1115
|
+
],
|
|
1116
|
+
transform: [
|
|
1117
|
+
{
|
|
1118
|
+
type: 'geopoint',
|
|
1119
|
+
projection: 'projection',
|
|
1120
|
+
fields: ['lon', 'lat'],
|
|
1121
|
+
as: ['x', 'y'],
|
|
1122
|
+
},
|
|
1123
|
+
],
|
|
1124
|
+
},
|
|
1125
|
+
],
|
|
1126
|
+
marks: [
|
|
1127
|
+
{
|
|
1128
|
+
type: 'shape',
|
|
1129
|
+
from: { data: 'world' },
|
|
1130
|
+
transform: [{ type: 'geoshape', projection: 'projection' }],
|
|
1131
|
+
encode: {
|
|
1132
|
+
update: {
|
|
1133
|
+
fill: { value: '#8fbf8f' },
|
|
1134
|
+
stroke: { value: '#6c8c8c' },
|
|
1135
|
+
strokeWidth: { value: 0.7 },
|
|
1136
|
+
tooltip: { signal: "{Country: datum.name ? datum.name : 'Unknown'}" },
|
|
1137
|
+
},
|
|
1138
|
+
hover: {
|
|
1139
|
+
stroke: { value: '#2b3a42' },
|
|
1140
|
+
strokeWidth: { value: 1.3 },
|
|
1141
|
+
},
|
|
1142
|
+
},
|
|
1143
|
+
},
|
|
1144
|
+
{
|
|
1145
|
+
type: 'symbol',
|
|
1146
|
+
from: { data: 'points' },
|
|
1147
|
+
encode: {
|
|
1148
|
+
update: {
|
|
1149
|
+
x: { field: 'x' },
|
|
1150
|
+
y: { field: 'y' },
|
|
1151
|
+
size: { value: 80 },
|
|
1152
|
+
fill: { value: pinColor },
|
|
1153
|
+
stroke: { value: 'white' },
|
|
1154
|
+
shape: { value: pinShape },
|
|
1155
|
+
strokeWidth: { value: 1 },
|
|
1156
|
+
tooltip: {
|
|
1157
|
+
signal: '{Label: datum.label, Value: datum.value, Latitude: datum.lat, Longitude: datum.lon}',
|
|
1158
|
+
},
|
|
1159
|
+
},
|
|
1160
|
+
},
|
|
1161
|
+
},
|
|
1162
|
+
{
|
|
1163
|
+
type: 'text',
|
|
1164
|
+
from: { data: 'continentLabels' },
|
|
1165
|
+
encode: {
|
|
1166
|
+
update: {
|
|
1167
|
+
x: { field: 'x' },
|
|
1168
|
+
y: { field: 'y' },
|
|
1169
|
+
text: { field: 'name' },
|
|
1170
|
+
align: { value: 'center' },
|
|
1171
|
+
baseline: { value: 'middle' },
|
|
1172
|
+
fontSize: { value: 12 },
|
|
1173
|
+
fontWeight: { value: '600' },
|
|
1174
|
+
fill: { value: '#2b3a42' },
|
|
1175
|
+
fillOpacity: { value: 0.5 },
|
|
1176
|
+
},
|
|
1177
|
+
},
|
|
1178
|
+
},
|
|
1179
|
+
],
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
render() {
|
|
1183
|
+
return (h(Host, { key: '8053ea3b9706cdd03a430157b3f63e93c1201d1f' }, h("div", { key: '514807ae8dd4868d3d74e86c4260b7b9967c0ac2', id: "container", style: { width: '100%', height: '100%' } })));
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1187
|
+
export { ApolloDataBarChart as apollo_data_bar_chart, ApolloDataHeatMap as apollo_data_heat_map, ApolloDataLineChart as apollo_data_line_chart, ApolloDataScatterChart as apollo_data_scatter_chart, ApolloDataWorldMapChart as apollo_data_world_map_chart };
|