@timeplus/vistral 0.1.1
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/LICENSE +201 -0
- package/README.md +530 -0
- package/dist/index.d.ts +999 -0
- package/dist/index.esm.js +4774 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +4850 -0
- package/dist/index.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,4774 @@
|
|
|
1
|
+
import require$$0, { useRef, useState, useEffect, useCallback, useMemo, forwardRef, useImperativeHandle } from 'react';
|
|
2
|
+
import { Chart } from '@antv/g2';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = {exports: {}};
|
|
5
|
+
|
|
6
|
+
var reactJsxRuntime_production_min = {};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @license React
|
|
10
|
+
* react-jsx-runtime.production.min.js
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the MIT license found in the
|
|
15
|
+
* LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
var hasRequiredReactJsxRuntime_production_min;
|
|
19
|
+
|
|
20
|
+
function requireReactJsxRuntime_production_min () {
|
|
21
|
+
if (hasRequiredReactJsxRuntime_production_min) return reactJsxRuntime_production_min;
|
|
22
|
+
hasRequiredReactJsxRuntime_production_min = 1;
|
|
23
|
+
var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};
|
|
24
|
+
function q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=""+g);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return {$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}reactJsxRuntime_production_min.Fragment=l;reactJsxRuntime_production_min.jsx=q;reactJsxRuntime_production_min.jsxs=q;
|
|
25
|
+
return reactJsxRuntime_production_min;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var reactJsxRuntime_development = {};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @license React
|
|
32
|
+
* react-jsx-runtime.development.js
|
|
33
|
+
*
|
|
34
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
35
|
+
*
|
|
36
|
+
* This source code is licensed under the MIT license found in the
|
|
37
|
+
* LICENSE file in the root directory of this source tree.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
var hasRequiredReactJsxRuntime_development;
|
|
41
|
+
|
|
42
|
+
function requireReactJsxRuntime_development () {
|
|
43
|
+
if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
|
|
44
|
+
hasRequiredReactJsxRuntime_development = 1;
|
|
45
|
+
|
|
46
|
+
if (process.env.NODE_ENV !== "production") {
|
|
47
|
+
(function() {
|
|
48
|
+
|
|
49
|
+
var React = require$$0;
|
|
50
|
+
|
|
51
|
+
// ATTENTION
|
|
52
|
+
// When adding new symbols to this file,
|
|
53
|
+
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
|
|
54
|
+
// The Symbol used to tag the ReactElement-like types.
|
|
55
|
+
var REACT_ELEMENT_TYPE = Symbol.for('react.element');
|
|
56
|
+
var REACT_PORTAL_TYPE = Symbol.for('react.portal');
|
|
57
|
+
var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
|
|
58
|
+
var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
|
|
59
|
+
var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
|
|
60
|
+
var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
|
|
61
|
+
var REACT_CONTEXT_TYPE = Symbol.for('react.context');
|
|
62
|
+
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
|
|
63
|
+
var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
|
|
64
|
+
var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
|
|
65
|
+
var REACT_MEMO_TYPE = Symbol.for('react.memo');
|
|
66
|
+
var REACT_LAZY_TYPE = Symbol.for('react.lazy');
|
|
67
|
+
var REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
|
|
68
|
+
var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
|
|
69
|
+
var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
|
70
|
+
function getIteratorFn(maybeIterable) {
|
|
71
|
+
if (maybeIterable === null || typeof maybeIterable !== 'object') {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
|
|
76
|
+
|
|
77
|
+
if (typeof maybeIterator === 'function') {
|
|
78
|
+
return maybeIterator;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
85
|
+
|
|
86
|
+
function error(format) {
|
|
87
|
+
{
|
|
88
|
+
{
|
|
89
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
90
|
+
args[_key2 - 1] = arguments[_key2];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
printWarning('error', format, args);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function printWarning(level, format, args) {
|
|
99
|
+
// When changing this logic, you might want to also
|
|
100
|
+
// update consoleWithStackDev.www.js as well.
|
|
101
|
+
{
|
|
102
|
+
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
103
|
+
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
104
|
+
|
|
105
|
+
if (stack !== '') {
|
|
106
|
+
format += '%s';
|
|
107
|
+
args = args.concat([stack]);
|
|
108
|
+
} // eslint-disable-next-line react-internal/safe-string-coercion
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
var argsWithFormat = args.map(function (item) {
|
|
112
|
+
return String(item);
|
|
113
|
+
}); // Careful: RN currently depends on this prefix
|
|
114
|
+
|
|
115
|
+
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
|
116
|
+
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
117
|
+
// eslint-disable-next-line react-internal/no-production-logging
|
|
118
|
+
|
|
119
|
+
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// -----------------------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
var enableScopeAPI = false; // Experimental Create Event Handle API.
|
|
126
|
+
var enableCacheElement = false;
|
|
127
|
+
var enableTransitionTracing = false; // No known bugs, but needs performance testing
|
|
128
|
+
|
|
129
|
+
var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in Fiber
|
|
130
|
+
// stuff. Intended to enable React core members to more easily debug scheduling
|
|
131
|
+
// issues in DEV builds.
|
|
132
|
+
|
|
133
|
+
var enableDebugTracing = false; // Track which Fiber(s) schedule render work.
|
|
134
|
+
|
|
135
|
+
var REACT_MODULE_REFERENCE;
|
|
136
|
+
|
|
137
|
+
{
|
|
138
|
+
REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function isValidElementType(type) {
|
|
142
|
+
if (typeof type === 'string' || typeof type === 'function') {
|
|
143
|
+
return true;
|
|
144
|
+
} // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || enableDebugTracing || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || enableLegacyHidden || type === REACT_OFFSCREEN_TYPE || enableScopeAPI || enableCacheElement || enableTransitionTracing ) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (typeof type === 'object' && type !== null) {
|
|
152
|
+
if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object
|
|
153
|
+
// types supported by any Flight configuration anywhere since
|
|
154
|
+
// we don't know which Flight build this will end up being used
|
|
155
|
+
// with.
|
|
156
|
+
type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function getWrappedName(outerType, innerType, wrapperName) {
|
|
165
|
+
var displayName = outerType.displayName;
|
|
166
|
+
|
|
167
|
+
if (displayName) {
|
|
168
|
+
return displayName;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
var functionName = innerType.displayName || innerType.name || '';
|
|
172
|
+
return functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName;
|
|
173
|
+
} // Keep in sync with react-reconciler/getComponentNameFromFiber
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
function getContextName(type) {
|
|
177
|
+
return type.displayName || 'Context';
|
|
178
|
+
} // Note that the reconciler package should generally prefer to use getComponentNameFromFiber() instead.
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
function getComponentNameFromType(type) {
|
|
182
|
+
if (type == null) {
|
|
183
|
+
// Host root, text node or just invalid type.
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
{
|
|
188
|
+
if (typeof type.tag === 'number') {
|
|
189
|
+
error('Received an unexpected object in getComponentNameFromType(). ' + 'This is likely a bug in React. Please file an issue.');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (typeof type === 'function') {
|
|
194
|
+
return type.displayName || type.name || null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (typeof type === 'string') {
|
|
198
|
+
return type;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
switch (type) {
|
|
202
|
+
case REACT_FRAGMENT_TYPE:
|
|
203
|
+
return 'Fragment';
|
|
204
|
+
|
|
205
|
+
case REACT_PORTAL_TYPE:
|
|
206
|
+
return 'Portal';
|
|
207
|
+
|
|
208
|
+
case REACT_PROFILER_TYPE:
|
|
209
|
+
return 'Profiler';
|
|
210
|
+
|
|
211
|
+
case REACT_STRICT_MODE_TYPE:
|
|
212
|
+
return 'StrictMode';
|
|
213
|
+
|
|
214
|
+
case REACT_SUSPENSE_TYPE:
|
|
215
|
+
return 'Suspense';
|
|
216
|
+
|
|
217
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
218
|
+
return 'SuspenseList';
|
|
219
|
+
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (typeof type === 'object') {
|
|
223
|
+
switch (type.$$typeof) {
|
|
224
|
+
case REACT_CONTEXT_TYPE:
|
|
225
|
+
var context = type;
|
|
226
|
+
return getContextName(context) + '.Consumer';
|
|
227
|
+
|
|
228
|
+
case REACT_PROVIDER_TYPE:
|
|
229
|
+
var provider = type;
|
|
230
|
+
return getContextName(provider._context) + '.Provider';
|
|
231
|
+
|
|
232
|
+
case REACT_FORWARD_REF_TYPE:
|
|
233
|
+
return getWrappedName(type, type.render, 'ForwardRef');
|
|
234
|
+
|
|
235
|
+
case REACT_MEMO_TYPE:
|
|
236
|
+
var outerName = type.displayName || null;
|
|
237
|
+
|
|
238
|
+
if (outerName !== null) {
|
|
239
|
+
return outerName;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return getComponentNameFromType(type.type) || 'Memo';
|
|
243
|
+
|
|
244
|
+
case REACT_LAZY_TYPE:
|
|
245
|
+
{
|
|
246
|
+
var lazyComponent = type;
|
|
247
|
+
var payload = lazyComponent._payload;
|
|
248
|
+
var init = lazyComponent._init;
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
return getComponentNameFromType(init(payload));
|
|
252
|
+
} catch (x) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// eslint-disable-next-line no-fallthrough
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
var assign = Object.assign;
|
|
265
|
+
|
|
266
|
+
// Helpers to patch console.logs to avoid logging during side-effect free
|
|
267
|
+
// replaying on render function. This currently only patches the object
|
|
268
|
+
// lazily which won't cover if the log function was extracted eagerly.
|
|
269
|
+
// We could also eagerly patch the method.
|
|
270
|
+
var disabledDepth = 0;
|
|
271
|
+
var prevLog;
|
|
272
|
+
var prevInfo;
|
|
273
|
+
var prevWarn;
|
|
274
|
+
var prevError;
|
|
275
|
+
var prevGroup;
|
|
276
|
+
var prevGroupCollapsed;
|
|
277
|
+
var prevGroupEnd;
|
|
278
|
+
|
|
279
|
+
function disabledLog() {}
|
|
280
|
+
|
|
281
|
+
disabledLog.__reactDisabledLog = true;
|
|
282
|
+
function disableLogs() {
|
|
283
|
+
{
|
|
284
|
+
if (disabledDepth === 0) {
|
|
285
|
+
/* eslint-disable react-internal/no-production-logging */
|
|
286
|
+
prevLog = console.log;
|
|
287
|
+
prevInfo = console.info;
|
|
288
|
+
prevWarn = console.warn;
|
|
289
|
+
prevError = console.error;
|
|
290
|
+
prevGroup = console.group;
|
|
291
|
+
prevGroupCollapsed = console.groupCollapsed;
|
|
292
|
+
prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
|
|
293
|
+
|
|
294
|
+
var props = {
|
|
295
|
+
configurable: true,
|
|
296
|
+
enumerable: true,
|
|
297
|
+
value: disabledLog,
|
|
298
|
+
writable: true
|
|
299
|
+
}; // $FlowFixMe Flow thinks console is immutable.
|
|
300
|
+
|
|
301
|
+
Object.defineProperties(console, {
|
|
302
|
+
info: props,
|
|
303
|
+
log: props,
|
|
304
|
+
warn: props,
|
|
305
|
+
error: props,
|
|
306
|
+
group: props,
|
|
307
|
+
groupCollapsed: props,
|
|
308
|
+
groupEnd: props
|
|
309
|
+
});
|
|
310
|
+
/* eslint-enable react-internal/no-production-logging */
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
disabledDepth++;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function reenableLogs() {
|
|
317
|
+
{
|
|
318
|
+
disabledDepth--;
|
|
319
|
+
|
|
320
|
+
if (disabledDepth === 0) {
|
|
321
|
+
/* eslint-disable react-internal/no-production-logging */
|
|
322
|
+
var props = {
|
|
323
|
+
configurable: true,
|
|
324
|
+
enumerable: true,
|
|
325
|
+
writable: true
|
|
326
|
+
}; // $FlowFixMe Flow thinks console is immutable.
|
|
327
|
+
|
|
328
|
+
Object.defineProperties(console, {
|
|
329
|
+
log: assign({}, props, {
|
|
330
|
+
value: prevLog
|
|
331
|
+
}),
|
|
332
|
+
info: assign({}, props, {
|
|
333
|
+
value: prevInfo
|
|
334
|
+
}),
|
|
335
|
+
warn: assign({}, props, {
|
|
336
|
+
value: prevWarn
|
|
337
|
+
}),
|
|
338
|
+
error: assign({}, props, {
|
|
339
|
+
value: prevError
|
|
340
|
+
}),
|
|
341
|
+
group: assign({}, props, {
|
|
342
|
+
value: prevGroup
|
|
343
|
+
}),
|
|
344
|
+
groupCollapsed: assign({}, props, {
|
|
345
|
+
value: prevGroupCollapsed
|
|
346
|
+
}),
|
|
347
|
+
groupEnd: assign({}, props, {
|
|
348
|
+
value: prevGroupEnd
|
|
349
|
+
})
|
|
350
|
+
});
|
|
351
|
+
/* eslint-enable react-internal/no-production-logging */
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (disabledDepth < 0) {
|
|
355
|
+
error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.');
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
|
|
361
|
+
var prefix;
|
|
362
|
+
function describeBuiltInComponentFrame(name, source, ownerFn) {
|
|
363
|
+
{
|
|
364
|
+
if (prefix === undefined) {
|
|
365
|
+
// Extract the VM specific prefix used by each line.
|
|
366
|
+
try {
|
|
367
|
+
throw Error();
|
|
368
|
+
} catch (x) {
|
|
369
|
+
var match = x.stack.trim().match(/\n( *(at )?)/);
|
|
370
|
+
prefix = match && match[1] || '';
|
|
371
|
+
}
|
|
372
|
+
} // We use the prefix to ensure our stacks line up with native stack frames.
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
return '\n' + prefix + name;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
var reentry = false;
|
|
379
|
+
var componentFrameCache;
|
|
380
|
+
|
|
381
|
+
{
|
|
382
|
+
var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
|
|
383
|
+
componentFrameCache = new PossiblyWeakMap();
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function describeNativeComponentFrame(fn, construct) {
|
|
387
|
+
// If something asked for a stack inside a fake render, it should get ignored.
|
|
388
|
+
if ( !fn || reentry) {
|
|
389
|
+
return '';
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
{
|
|
393
|
+
var frame = componentFrameCache.get(fn);
|
|
394
|
+
|
|
395
|
+
if (frame !== undefined) {
|
|
396
|
+
return frame;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
var control;
|
|
401
|
+
reentry = true;
|
|
402
|
+
var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined.
|
|
403
|
+
|
|
404
|
+
Error.prepareStackTrace = undefined;
|
|
405
|
+
var previousDispatcher;
|
|
406
|
+
|
|
407
|
+
{
|
|
408
|
+
previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function
|
|
409
|
+
// for warnings.
|
|
410
|
+
|
|
411
|
+
ReactCurrentDispatcher.current = null;
|
|
412
|
+
disableLogs();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
try {
|
|
416
|
+
// This should throw.
|
|
417
|
+
if (construct) {
|
|
418
|
+
// Something should be setting the props in the constructor.
|
|
419
|
+
var Fake = function () {
|
|
420
|
+
throw Error();
|
|
421
|
+
}; // $FlowFixMe
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
Object.defineProperty(Fake.prototype, 'props', {
|
|
425
|
+
set: function () {
|
|
426
|
+
// We use a throwing setter instead of frozen or non-writable props
|
|
427
|
+
// because that won't throw in a non-strict mode function.
|
|
428
|
+
throw Error();
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
if (typeof Reflect === 'object' && Reflect.construct) {
|
|
433
|
+
// We construct a different control for this case to include any extra
|
|
434
|
+
// frames added by the construct call.
|
|
435
|
+
try {
|
|
436
|
+
Reflect.construct(Fake, []);
|
|
437
|
+
} catch (x) {
|
|
438
|
+
control = x;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
Reflect.construct(fn, [], Fake);
|
|
442
|
+
} else {
|
|
443
|
+
try {
|
|
444
|
+
Fake.call();
|
|
445
|
+
} catch (x) {
|
|
446
|
+
control = x;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
fn.call(Fake.prototype);
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
try {
|
|
453
|
+
throw Error();
|
|
454
|
+
} catch (x) {
|
|
455
|
+
control = x;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
fn();
|
|
459
|
+
}
|
|
460
|
+
} catch (sample) {
|
|
461
|
+
// This is inlined manually because closure doesn't do it for us.
|
|
462
|
+
if (sample && control && typeof sample.stack === 'string') {
|
|
463
|
+
// This extracts the first frame from the sample that isn't also in the control.
|
|
464
|
+
// Skipping one frame that we assume is the frame that calls the two.
|
|
465
|
+
var sampleLines = sample.stack.split('\n');
|
|
466
|
+
var controlLines = control.stack.split('\n');
|
|
467
|
+
var s = sampleLines.length - 1;
|
|
468
|
+
var c = controlLines.length - 1;
|
|
469
|
+
|
|
470
|
+
while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
|
|
471
|
+
// We expect at least one stack frame to be shared.
|
|
472
|
+
// Typically this will be the root most one. However, stack frames may be
|
|
473
|
+
// cut off due to maximum stack limits. In this case, one maybe cut off
|
|
474
|
+
// earlier than the other. We assume that the sample is longer or the same
|
|
475
|
+
// and there for cut off earlier. So we should find the root most frame in
|
|
476
|
+
// the sample somewhere in the control.
|
|
477
|
+
c--;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
for (; s >= 1 && c >= 0; s--, c--) {
|
|
481
|
+
// Next we find the first one that isn't the same which should be the
|
|
482
|
+
// frame that called our sample function and the control.
|
|
483
|
+
if (sampleLines[s] !== controlLines[c]) {
|
|
484
|
+
// In V8, the first line is describing the message but other VMs don't.
|
|
485
|
+
// If we're about to return the first line, and the control is also on the same
|
|
486
|
+
// line, that's a pretty good indicator that our sample threw at same line as
|
|
487
|
+
// the control. I.e. before we entered the sample frame. So we ignore this result.
|
|
488
|
+
// This can happen if you passed a class to function component, or non-function.
|
|
489
|
+
if (s !== 1 || c !== 1) {
|
|
490
|
+
do {
|
|
491
|
+
s--;
|
|
492
|
+
c--; // We may still have similar intermediate frames from the construct call.
|
|
493
|
+
// The next one that isn't the same should be our match though.
|
|
494
|
+
|
|
495
|
+
if (c < 0 || sampleLines[s] !== controlLines[c]) {
|
|
496
|
+
// V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
|
|
497
|
+
var _frame = '\n' + sampleLines[s].replace(' at new ', ' at '); // If our component frame is labeled "<anonymous>"
|
|
498
|
+
// but we have a user-provided "displayName"
|
|
499
|
+
// splice it in to make the stack more readable.
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
if (fn.displayName && _frame.includes('<anonymous>')) {
|
|
503
|
+
_frame = _frame.replace('<anonymous>', fn.displayName);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
{
|
|
507
|
+
if (typeof fn === 'function') {
|
|
508
|
+
componentFrameCache.set(fn, _frame);
|
|
509
|
+
}
|
|
510
|
+
} // Return the line we found.
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
return _frame;
|
|
514
|
+
}
|
|
515
|
+
} while (s >= 1 && c >= 0);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
} finally {
|
|
523
|
+
reentry = false;
|
|
524
|
+
|
|
525
|
+
{
|
|
526
|
+
ReactCurrentDispatcher.current = previousDispatcher;
|
|
527
|
+
reenableLogs();
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
Error.prepareStackTrace = previousPrepareStackTrace;
|
|
531
|
+
} // Fallback to just using the name if we couldn't make it throw.
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
var name = fn ? fn.displayName || fn.name : '';
|
|
535
|
+
var syntheticFrame = name ? describeBuiltInComponentFrame(name) : '';
|
|
536
|
+
|
|
537
|
+
{
|
|
538
|
+
if (typeof fn === 'function') {
|
|
539
|
+
componentFrameCache.set(fn, syntheticFrame);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return syntheticFrame;
|
|
544
|
+
}
|
|
545
|
+
function describeFunctionComponentFrame(fn, source, ownerFn) {
|
|
546
|
+
{
|
|
547
|
+
return describeNativeComponentFrame(fn, false);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function shouldConstruct(Component) {
|
|
552
|
+
var prototype = Component.prototype;
|
|
553
|
+
return !!(prototype && prototype.isReactComponent);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) {
|
|
557
|
+
|
|
558
|
+
if (type == null) {
|
|
559
|
+
return '';
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (typeof type === 'function') {
|
|
563
|
+
{
|
|
564
|
+
return describeNativeComponentFrame(type, shouldConstruct(type));
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (typeof type === 'string') {
|
|
569
|
+
return describeBuiltInComponentFrame(type);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
switch (type) {
|
|
573
|
+
case REACT_SUSPENSE_TYPE:
|
|
574
|
+
return describeBuiltInComponentFrame('Suspense');
|
|
575
|
+
|
|
576
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
577
|
+
return describeBuiltInComponentFrame('SuspenseList');
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (typeof type === 'object') {
|
|
581
|
+
switch (type.$$typeof) {
|
|
582
|
+
case REACT_FORWARD_REF_TYPE:
|
|
583
|
+
return describeFunctionComponentFrame(type.render);
|
|
584
|
+
|
|
585
|
+
case REACT_MEMO_TYPE:
|
|
586
|
+
// Memo may contain any component type so we recursively resolve it.
|
|
587
|
+
return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn);
|
|
588
|
+
|
|
589
|
+
case REACT_LAZY_TYPE:
|
|
590
|
+
{
|
|
591
|
+
var lazyComponent = type;
|
|
592
|
+
var payload = lazyComponent._payload;
|
|
593
|
+
var init = lazyComponent._init;
|
|
594
|
+
|
|
595
|
+
try {
|
|
596
|
+
// Lazy may contain any component type so we recursively resolve it.
|
|
597
|
+
return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn);
|
|
598
|
+
} catch (x) {}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
return '';
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
607
|
+
|
|
608
|
+
var loggedTypeFailures = {};
|
|
609
|
+
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
610
|
+
|
|
611
|
+
function setCurrentlyValidatingElement(element) {
|
|
612
|
+
{
|
|
613
|
+
if (element) {
|
|
614
|
+
var owner = element._owner;
|
|
615
|
+
var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
|
|
616
|
+
ReactDebugCurrentFrame.setExtraStackFrame(stack);
|
|
617
|
+
} else {
|
|
618
|
+
ReactDebugCurrentFrame.setExtraStackFrame(null);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function checkPropTypes(typeSpecs, values, location, componentName, element) {
|
|
624
|
+
{
|
|
625
|
+
// $FlowFixMe This is okay but Flow doesn't know it.
|
|
626
|
+
var has = Function.call.bind(hasOwnProperty);
|
|
627
|
+
|
|
628
|
+
for (var typeSpecName in typeSpecs) {
|
|
629
|
+
if (has(typeSpecs, typeSpecName)) {
|
|
630
|
+
var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
|
|
631
|
+
// fail the render phase where it didn't fail before. So we log it.
|
|
632
|
+
// After these have been cleaned up, we'll let them throw.
|
|
633
|
+
|
|
634
|
+
try {
|
|
635
|
+
// This is intentionally an invariant that gets caught. It's the same
|
|
636
|
+
// behavior as without this statement except with a better message.
|
|
637
|
+
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
|
638
|
+
// eslint-disable-next-line react-internal/prod-error-codes
|
|
639
|
+
var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.');
|
|
640
|
+
err.name = 'Invariant Violation';
|
|
641
|
+
throw err;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED');
|
|
645
|
+
} catch (ex) {
|
|
646
|
+
error$1 = ex;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
if (error$1 && !(error$1 instanceof Error)) {
|
|
650
|
+
setCurrentlyValidatingElement(element);
|
|
651
|
+
|
|
652
|
+
error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error$1);
|
|
653
|
+
|
|
654
|
+
setCurrentlyValidatingElement(null);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
|
|
658
|
+
// Only monitor this failure once because there tends to be a lot of the
|
|
659
|
+
// same error.
|
|
660
|
+
loggedTypeFailures[error$1.message] = true;
|
|
661
|
+
setCurrentlyValidatingElement(element);
|
|
662
|
+
|
|
663
|
+
error('Failed %s type: %s', location, error$1.message);
|
|
664
|
+
|
|
665
|
+
setCurrentlyValidatingElement(null);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
|
|
673
|
+
|
|
674
|
+
function isArray(a) {
|
|
675
|
+
return isArrayImpl(a);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/*
|
|
679
|
+
* The `'' + value` pattern (used in in perf-sensitive code) throws for Symbol
|
|
680
|
+
* and Temporal.* types. See https://github.com/facebook/react/pull/22064.
|
|
681
|
+
*
|
|
682
|
+
* The functions in this module will throw an easier-to-understand,
|
|
683
|
+
* easier-to-debug exception with a clear errors message message explaining the
|
|
684
|
+
* problem. (Instead of a confusing exception thrown inside the implementation
|
|
685
|
+
* of the `value` object).
|
|
686
|
+
*/
|
|
687
|
+
// $FlowFixMe only called in DEV, so void return is not possible.
|
|
688
|
+
function typeName(value) {
|
|
689
|
+
{
|
|
690
|
+
// toStringTag is needed for namespaced types like Temporal.Instant
|
|
691
|
+
var hasToStringTag = typeof Symbol === 'function' && Symbol.toStringTag;
|
|
692
|
+
var type = hasToStringTag && value[Symbol.toStringTag] || value.constructor.name || 'Object';
|
|
693
|
+
return type;
|
|
694
|
+
}
|
|
695
|
+
} // $FlowFixMe only called in DEV, so void return is not possible.
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
function willCoercionThrow(value) {
|
|
699
|
+
{
|
|
700
|
+
try {
|
|
701
|
+
testStringCoercion(value);
|
|
702
|
+
return false;
|
|
703
|
+
} catch (e) {
|
|
704
|
+
return true;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function testStringCoercion(value) {
|
|
710
|
+
// If you ended up here by following an exception call stack, here's what's
|
|
711
|
+
// happened: you supplied an object or symbol value to React (as a prop, key,
|
|
712
|
+
// DOM attribute, CSS property, string ref, etc.) and when React tried to
|
|
713
|
+
// coerce it to a string using `'' + value`, an exception was thrown.
|
|
714
|
+
//
|
|
715
|
+
// The most common types that will cause this exception are `Symbol` instances
|
|
716
|
+
// and Temporal objects like `Temporal.Instant`. But any object that has a
|
|
717
|
+
// `valueOf` or `[Symbol.toPrimitive]` method that throws will also cause this
|
|
718
|
+
// exception. (Library authors do this to prevent users from using built-in
|
|
719
|
+
// numeric operators like `+` or comparison operators like `>=` because custom
|
|
720
|
+
// methods are needed to perform accurate arithmetic or comparison.)
|
|
721
|
+
//
|
|
722
|
+
// To fix the problem, coerce this object or symbol value to a string before
|
|
723
|
+
// passing it to React. The most reliable way is usually `String(value)`.
|
|
724
|
+
//
|
|
725
|
+
// To find which value is throwing, check the browser or debugger console.
|
|
726
|
+
// Before this exception was thrown, there should be `console.error` output
|
|
727
|
+
// that shows the type (Symbol, Temporal.PlainDate, etc.) that caused the
|
|
728
|
+
// problem and how that type was used: key, atrribute, input value prop, etc.
|
|
729
|
+
// In most cases, this console output also shows the component and its
|
|
730
|
+
// ancestor components where the exception happened.
|
|
731
|
+
//
|
|
732
|
+
// eslint-disable-next-line react-internal/safe-string-coercion
|
|
733
|
+
return '' + value;
|
|
734
|
+
}
|
|
735
|
+
function checkKeyStringCoercion(value) {
|
|
736
|
+
{
|
|
737
|
+
if (willCoercionThrow(value)) {
|
|
738
|
+
error('The provided key is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', typeName(value));
|
|
739
|
+
|
|
740
|
+
return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
|
|
746
|
+
var RESERVED_PROPS = {
|
|
747
|
+
key: true,
|
|
748
|
+
ref: true,
|
|
749
|
+
__self: true,
|
|
750
|
+
__source: true
|
|
751
|
+
};
|
|
752
|
+
var specialPropKeyWarningShown;
|
|
753
|
+
var specialPropRefWarningShown;
|
|
754
|
+
var didWarnAboutStringRefs;
|
|
755
|
+
|
|
756
|
+
{
|
|
757
|
+
didWarnAboutStringRefs = {};
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function hasValidRef(config) {
|
|
761
|
+
{
|
|
762
|
+
if (hasOwnProperty.call(config, 'ref')) {
|
|
763
|
+
var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
|
|
764
|
+
|
|
765
|
+
if (getter && getter.isReactWarning) {
|
|
766
|
+
return false;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
return config.ref !== undefined;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
function hasValidKey(config) {
|
|
775
|
+
{
|
|
776
|
+
if (hasOwnProperty.call(config, 'key')) {
|
|
777
|
+
var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
|
|
778
|
+
|
|
779
|
+
if (getter && getter.isReactWarning) {
|
|
780
|
+
return false;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
return config.key !== undefined;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
function warnIfStringRefCannotBeAutoConverted(config, self) {
|
|
789
|
+
{
|
|
790
|
+
if (typeof config.ref === 'string' && ReactCurrentOwner.current && self && ReactCurrentOwner.current.stateNode !== self) {
|
|
791
|
+
var componentName = getComponentNameFromType(ReactCurrentOwner.current.type);
|
|
792
|
+
|
|
793
|
+
if (!didWarnAboutStringRefs[componentName]) {
|
|
794
|
+
error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref', getComponentNameFromType(ReactCurrentOwner.current.type), config.ref);
|
|
795
|
+
|
|
796
|
+
didWarnAboutStringRefs[componentName] = true;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
function defineKeyPropWarningGetter(props, displayName) {
|
|
803
|
+
{
|
|
804
|
+
var warnAboutAccessingKey = function () {
|
|
805
|
+
if (!specialPropKeyWarningShown) {
|
|
806
|
+
specialPropKeyWarningShown = true;
|
|
807
|
+
|
|
808
|
+
error('%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
warnAboutAccessingKey.isReactWarning = true;
|
|
813
|
+
Object.defineProperty(props, 'key', {
|
|
814
|
+
get: warnAboutAccessingKey,
|
|
815
|
+
configurable: true
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
function defineRefPropWarningGetter(props, displayName) {
|
|
821
|
+
{
|
|
822
|
+
var warnAboutAccessingRef = function () {
|
|
823
|
+
if (!specialPropRefWarningShown) {
|
|
824
|
+
specialPropRefWarningShown = true;
|
|
825
|
+
|
|
826
|
+
error('%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
warnAboutAccessingRef.isReactWarning = true;
|
|
831
|
+
Object.defineProperty(props, 'ref', {
|
|
832
|
+
get: warnAboutAccessingRef,
|
|
833
|
+
configurable: true
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Factory method to create a new React element. This no longer adheres to
|
|
839
|
+
* the class pattern, so do not use new to call it. Also, instanceof check
|
|
840
|
+
* will not work. Instead test $$typeof field against Symbol.for('react.element') to check
|
|
841
|
+
* if something is a React Element.
|
|
842
|
+
*
|
|
843
|
+
* @param {*} type
|
|
844
|
+
* @param {*} props
|
|
845
|
+
* @param {*} key
|
|
846
|
+
* @param {string|object} ref
|
|
847
|
+
* @param {*} owner
|
|
848
|
+
* @param {*} self A *temporary* helper to detect places where `this` is
|
|
849
|
+
* different from the `owner` when React.createElement is called, so that we
|
|
850
|
+
* can warn. We want to get rid of owner and replace string `ref`s with arrow
|
|
851
|
+
* functions, and as long as `this` and owner are the same, there will be no
|
|
852
|
+
* change in behavior.
|
|
853
|
+
* @param {*} source An annotation object (added by a transpiler or otherwise)
|
|
854
|
+
* indicating filename, line number, and/or other information.
|
|
855
|
+
* @internal
|
|
856
|
+
*/
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
var ReactElement = function (type, key, ref, self, source, owner, props) {
|
|
860
|
+
var element = {
|
|
861
|
+
// This tag allows us to uniquely identify this as a React Element
|
|
862
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
863
|
+
// Built-in properties that belong on the element
|
|
864
|
+
type: type,
|
|
865
|
+
key: key,
|
|
866
|
+
ref: ref,
|
|
867
|
+
props: props,
|
|
868
|
+
// Record the component responsible for creating this element.
|
|
869
|
+
_owner: owner
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
{
|
|
873
|
+
// The validation flag is currently mutative. We put it on
|
|
874
|
+
// an external backing store so that we can freeze the whole object.
|
|
875
|
+
// This can be replaced with a WeakMap once they are implemented in
|
|
876
|
+
// commonly used development environments.
|
|
877
|
+
element._store = {}; // To make comparing ReactElements easier for testing purposes, we make
|
|
878
|
+
// the validation flag non-enumerable (where possible, which should
|
|
879
|
+
// include every environment we run tests in), so the test framework
|
|
880
|
+
// ignores it.
|
|
881
|
+
|
|
882
|
+
Object.defineProperty(element._store, 'validated', {
|
|
883
|
+
configurable: false,
|
|
884
|
+
enumerable: false,
|
|
885
|
+
writable: true,
|
|
886
|
+
value: false
|
|
887
|
+
}); // self and source are DEV only properties.
|
|
888
|
+
|
|
889
|
+
Object.defineProperty(element, '_self', {
|
|
890
|
+
configurable: false,
|
|
891
|
+
enumerable: false,
|
|
892
|
+
writable: false,
|
|
893
|
+
value: self
|
|
894
|
+
}); // Two elements created in two different places should be considered
|
|
895
|
+
// equal for testing purposes and therefore we hide it from enumeration.
|
|
896
|
+
|
|
897
|
+
Object.defineProperty(element, '_source', {
|
|
898
|
+
configurable: false,
|
|
899
|
+
enumerable: false,
|
|
900
|
+
writable: false,
|
|
901
|
+
value: source
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
if (Object.freeze) {
|
|
905
|
+
Object.freeze(element.props);
|
|
906
|
+
Object.freeze(element);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
return element;
|
|
911
|
+
};
|
|
912
|
+
/**
|
|
913
|
+
* https://github.com/reactjs/rfcs/pull/107
|
|
914
|
+
* @param {*} type
|
|
915
|
+
* @param {object} props
|
|
916
|
+
* @param {string} key
|
|
917
|
+
*/
|
|
918
|
+
|
|
919
|
+
function jsxDEV(type, config, maybeKey, source, self) {
|
|
920
|
+
{
|
|
921
|
+
var propName; // Reserved names are extracted
|
|
922
|
+
|
|
923
|
+
var props = {};
|
|
924
|
+
var key = null;
|
|
925
|
+
var ref = null; // Currently, key can be spread in as a prop. This causes a potential
|
|
926
|
+
// issue if key is also explicitly declared (ie. <div {...props} key="Hi" />
|
|
927
|
+
// or <div key="Hi" {...props} /> ). We want to deprecate key spread,
|
|
928
|
+
// but as an intermediary step, we will use jsxDEV for everything except
|
|
929
|
+
// <div {...props} key="Hi" />, because we aren't currently able to tell if
|
|
930
|
+
// key is explicitly declared to be undefined or not.
|
|
931
|
+
|
|
932
|
+
if (maybeKey !== undefined) {
|
|
933
|
+
{
|
|
934
|
+
checkKeyStringCoercion(maybeKey);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
key = '' + maybeKey;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
if (hasValidKey(config)) {
|
|
941
|
+
{
|
|
942
|
+
checkKeyStringCoercion(config.key);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
key = '' + config.key;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
if (hasValidRef(config)) {
|
|
949
|
+
ref = config.ref;
|
|
950
|
+
warnIfStringRefCannotBeAutoConverted(config, self);
|
|
951
|
+
} // Remaining properties are added to a new props object
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
for (propName in config) {
|
|
955
|
+
if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
956
|
+
props[propName] = config[propName];
|
|
957
|
+
}
|
|
958
|
+
} // Resolve default props
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
if (type && type.defaultProps) {
|
|
962
|
+
var defaultProps = type.defaultProps;
|
|
963
|
+
|
|
964
|
+
for (propName in defaultProps) {
|
|
965
|
+
if (props[propName] === undefined) {
|
|
966
|
+
props[propName] = defaultProps[propName];
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
if (key || ref) {
|
|
972
|
+
var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
|
|
973
|
+
|
|
974
|
+
if (key) {
|
|
975
|
+
defineKeyPropWarningGetter(props, displayName);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
if (ref) {
|
|
979
|
+
defineRefPropWarningGetter(props, displayName);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
|
|
988
|
+
var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
989
|
+
|
|
990
|
+
function setCurrentlyValidatingElement$1(element) {
|
|
991
|
+
{
|
|
992
|
+
if (element) {
|
|
993
|
+
var owner = element._owner;
|
|
994
|
+
var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
|
|
995
|
+
ReactDebugCurrentFrame$1.setExtraStackFrame(stack);
|
|
996
|
+
} else {
|
|
997
|
+
ReactDebugCurrentFrame$1.setExtraStackFrame(null);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
var propTypesMisspellWarningShown;
|
|
1003
|
+
|
|
1004
|
+
{
|
|
1005
|
+
propTypesMisspellWarningShown = false;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Verifies the object is a ReactElement.
|
|
1009
|
+
* See https://reactjs.org/docs/react-api.html#isvalidelement
|
|
1010
|
+
* @param {?object} object
|
|
1011
|
+
* @return {boolean} True if `object` is a ReactElement.
|
|
1012
|
+
* @final
|
|
1013
|
+
*/
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
function isValidElement(object) {
|
|
1017
|
+
{
|
|
1018
|
+
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
function getDeclarationErrorAddendum() {
|
|
1023
|
+
{
|
|
1024
|
+
if (ReactCurrentOwner$1.current) {
|
|
1025
|
+
var name = getComponentNameFromType(ReactCurrentOwner$1.current.type);
|
|
1026
|
+
|
|
1027
|
+
if (name) {
|
|
1028
|
+
return '\n\nCheck the render method of `' + name + '`.';
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
return '';
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
function getSourceInfoErrorAddendum(source) {
|
|
1037
|
+
{
|
|
1038
|
+
if (source !== undefined) {
|
|
1039
|
+
var fileName = source.fileName.replace(/^.*[\\\/]/, '');
|
|
1040
|
+
var lineNumber = source.lineNumber;
|
|
1041
|
+
return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
return '';
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Warn if there's no key explicitly set on dynamic arrays of children or
|
|
1049
|
+
* object keys are not valid. This allows us to keep track of children between
|
|
1050
|
+
* updates.
|
|
1051
|
+
*/
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
var ownerHasKeyUseWarning = {};
|
|
1055
|
+
|
|
1056
|
+
function getCurrentComponentErrorInfo(parentType) {
|
|
1057
|
+
{
|
|
1058
|
+
var info = getDeclarationErrorAddendum();
|
|
1059
|
+
|
|
1060
|
+
if (!info) {
|
|
1061
|
+
var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
|
|
1062
|
+
|
|
1063
|
+
if (parentName) {
|
|
1064
|
+
info = "\n\nCheck the top-level render call using <" + parentName + ">.";
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
return info;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Warn if the element doesn't have an explicit key assigned to it.
|
|
1073
|
+
* This element is in an array. The array could grow and shrink or be
|
|
1074
|
+
* reordered. All children that haven't already been validated are required to
|
|
1075
|
+
* have a "key" property assigned to it. Error statuses are cached so a warning
|
|
1076
|
+
* will only be shown once.
|
|
1077
|
+
*
|
|
1078
|
+
* @internal
|
|
1079
|
+
* @param {ReactElement} element Element that requires a key.
|
|
1080
|
+
* @param {*} parentType element's parent's type.
|
|
1081
|
+
*/
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
function validateExplicitKey(element, parentType) {
|
|
1085
|
+
{
|
|
1086
|
+
if (!element._store || element._store.validated || element.key != null) {
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
element._store.validated = true;
|
|
1091
|
+
var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
|
|
1092
|
+
|
|
1093
|
+
if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
ownerHasKeyUseWarning[currentComponentErrorInfo] = true; // Usually the current owner is the offender, but if it accepts children as a
|
|
1098
|
+
// property, it may be the creator of the child that's responsible for
|
|
1099
|
+
// assigning it a key.
|
|
1100
|
+
|
|
1101
|
+
var childOwner = '';
|
|
1102
|
+
|
|
1103
|
+
if (element && element._owner && element._owner !== ReactCurrentOwner$1.current) {
|
|
1104
|
+
// Give the component that originally created this child.
|
|
1105
|
+
childOwner = " It was passed a child from " + getComponentNameFromType(element._owner.type) + ".";
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
setCurrentlyValidatingElement$1(element);
|
|
1109
|
+
|
|
1110
|
+
error('Each child in a list should have a unique "key" prop.' + '%s%s See https://reactjs.org/link/warning-keys for more information.', currentComponentErrorInfo, childOwner);
|
|
1111
|
+
|
|
1112
|
+
setCurrentlyValidatingElement$1(null);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Ensure that every element either is passed in a static location, in an
|
|
1117
|
+
* array with an explicit keys property defined, or in an object literal
|
|
1118
|
+
* with valid key property.
|
|
1119
|
+
*
|
|
1120
|
+
* @internal
|
|
1121
|
+
* @param {ReactNode} node Statically passed child of any type.
|
|
1122
|
+
* @param {*} parentType node's parent's type.
|
|
1123
|
+
*/
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
function validateChildKeys(node, parentType) {
|
|
1127
|
+
{
|
|
1128
|
+
if (typeof node !== 'object') {
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
if (isArray(node)) {
|
|
1133
|
+
for (var i = 0; i < node.length; i++) {
|
|
1134
|
+
var child = node[i];
|
|
1135
|
+
|
|
1136
|
+
if (isValidElement(child)) {
|
|
1137
|
+
validateExplicitKey(child, parentType);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
} else if (isValidElement(node)) {
|
|
1141
|
+
// This element was passed in a valid location.
|
|
1142
|
+
if (node._store) {
|
|
1143
|
+
node._store.validated = true;
|
|
1144
|
+
}
|
|
1145
|
+
} else if (node) {
|
|
1146
|
+
var iteratorFn = getIteratorFn(node);
|
|
1147
|
+
|
|
1148
|
+
if (typeof iteratorFn === 'function') {
|
|
1149
|
+
// Entry iterators used to provide implicit keys,
|
|
1150
|
+
// but now we print a separate warning for them later.
|
|
1151
|
+
if (iteratorFn !== node.entries) {
|
|
1152
|
+
var iterator = iteratorFn.call(node);
|
|
1153
|
+
var step;
|
|
1154
|
+
|
|
1155
|
+
while (!(step = iterator.next()).done) {
|
|
1156
|
+
if (isValidElement(step.value)) {
|
|
1157
|
+
validateExplicitKey(step.value, parentType);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Given an element, validate that its props follow the propTypes definition,
|
|
1167
|
+
* provided by the type.
|
|
1168
|
+
*
|
|
1169
|
+
* @param {ReactElement} element
|
|
1170
|
+
*/
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
function validatePropTypes(element) {
|
|
1174
|
+
{
|
|
1175
|
+
var type = element.type;
|
|
1176
|
+
|
|
1177
|
+
if (type === null || type === undefined || typeof type === 'string') {
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
var propTypes;
|
|
1182
|
+
|
|
1183
|
+
if (typeof type === 'function') {
|
|
1184
|
+
propTypes = type.propTypes;
|
|
1185
|
+
} else if (typeof type === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE || // Note: Memo only checks outer props here.
|
|
1186
|
+
// Inner props are checked in the reconciler.
|
|
1187
|
+
type.$$typeof === REACT_MEMO_TYPE)) {
|
|
1188
|
+
propTypes = type.propTypes;
|
|
1189
|
+
} else {
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
if (propTypes) {
|
|
1194
|
+
// Intentionally inside to avoid triggering lazy initializers:
|
|
1195
|
+
var name = getComponentNameFromType(type);
|
|
1196
|
+
checkPropTypes(propTypes, element.props, 'prop', name, element);
|
|
1197
|
+
} else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
|
|
1198
|
+
propTypesMisspellWarningShown = true; // Intentionally inside to avoid triggering lazy initializers:
|
|
1199
|
+
|
|
1200
|
+
var _name = getComponentNameFromType(type);
|
|
1201
|
+
|
|
1202
|
+
error('Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', _name || 'Unknown');
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
if (typeof type.getDefaultProps === 'function' && !type.getDefaultProps.isReactClassApproved) {
|
|
1206
|
+
error('getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.');
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Given a fragment, validate that it can only be provided with fragment props
|
|
1212
|
+
* @param {ReactElement} fragment
|
|
1213
|
+
*/
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
function validateFragmentProps(fragment) {
|
|
1217
|
+
{
|
|
1218
|
+
var keys = Object.keys(fragment.props);
|
|
1219
|
+
|
|
1220
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1221
|
+
var key = keys[i];
|
|
1222
|
+
|
|
1223
|
+
if (key !== 'children' && key !== 'key') {
|
|
1224
|
+
setCurrentlyValidatingElement$1(fragment);
|
|
1225
|
+
|
|
1226
|
+
error('Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key);
|
|
1227
|
+
|
|
1228
|
+
setCurrentlyValidatingElement$1(null);
|
|
1229
|
+
break;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
if (fragment.ref !== null) {
|
|
1234
|
+
setCurrentlyValidatingElement$1(fragment);
|
|
1235
|
+
|
|
1236
|
+
error('Invalid attribute `ref` supplied to `React.Fragment`.');
|
|
1237
|
+
|
|
1238
|
+
setCurrentlyValidatingElement$1(null);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
var didWarnAboutKeySpread = {};
|
|
1244
|
+
function jsxWithValidation(type, props, key, isStaticChildren, source, self) {
|
|
1245
|
+
{
|
|
1246
|
+
var validType = isValidElementType(type); // We warn in this case but don't throw. We expect the element creation to
|
|
1247
|
+
// succeed and there will likely be errors in render.
|
|
1248
|
+
|
|
1249
|
+
if (!validType) {
|
|
1250
|
+
var info = '';
|
|
1251
|
+
|
|
1252
|
+
if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
|
|
1253
|
+
info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and named imports.";
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
var sourceInfo = getSourceInfoErrorAddendum(source);
|
|
1257
|
+
|
|
1258
|
+
if (sourceInfo) {
|
|
1259
|
+
info += sourceInfo;
|
|
1260
|
+
} else {
|
|
1261
|
+
info += getDeclarationErrorAddendum();
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
var typeString;
|
|
1265
|
+
|
|
1266
|
+
if (type === null) {
|
|
1267
|
+
typeString = 'null';
|
|
1268
|
+
} else if (isArray(type)) {
|
|
1269
|
+
typeString = 'array';
|
|
1270
|
+
} else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
|
|
1271
|
+
typeString = "<" + (getComponentNameFromType(type.type) || 'Unknown') + " />";
|
|
1272
|
+
info = ' Did you accidentally export a JSX literal instead of a component?';
|
|
1273
|
+
} else {
|
|
1274
|
+
typeString = typeof type;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
error('React.jsx: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
var element = jsxDEV(type, props, key, source, self); // The result can be nullish if a mock or a custom function is used.
|
|
1281
|
+
// TODO: Drop this when these are no longer allowed as the type argument.
|
|
1282
|
+
|
|
1283
|
+
if (element == null) {
|
|
1284
|
+
return element;
|
|
1285
|
+
} // Skip key warning if the type isn't valid since our key validation logic
|
|
1286
|
+
// doesn't expect a non-string/function type and can throw confusing errors.
|
|
1287
|
+
// We don't want exception behavior to differ between dev and prod.
|
|
1288
|
+
// (Rendering will throw with a helpful message and as soon as the type is
|
|
1289
|
+
// fixed, the key warnings will appear.)
|
|
1290
|
+
|
|
1291
|
+
|
|
1292
|
+
if (validType) {
|
|
1293
|
+
var children = props.children;
|
|
1294
|
+
|
|
1295
|
+
if (children !== undefined) {
|
|
1296
|
+
if (isStaticChildren) {
|
|
1297
|
+
if (isArray(children)) {
|
|
1298
|
+
for (var i = 0; i < children.length; i++) {
|
|
1299
|
+
validateChildKeys(children[i], type);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
if (Object.freeze) {
|
|
1303
|
+
Object.freeze(children);
|
|
1304
|
+
}
|
|
1305
|
+
} else {
|
|
1306
|
+
error('React.jsx: Static children should always be an array. ' + 'You are likely explicitly calling React.jsxs or React.jsxDEV. ' + 'Use the Babel transform instead.');
|
|
1307
|
+
}
|
|
1308
|
+
} else {
|
|
1309
|
+
validateChildKeys(children, type);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
{
|
|
1315
|
+
if (hasOwnProperty.call(props, 'key')) {
|
|
1316
|
+
var componentName = getComponentNameFromType(type);
|
|
1317
|
+
var keys = Object.keys(props).filter(function (k) {
|
|
1318
|
+
return k !== 'key';
|
|
1319
|
+
});
|
|
1320
|
+
var beforeExample = keys.length > 0 ? '{key: someKey, ' + keys.join(': ..., ') + ': ...}' : '{key: someKey}';
|
|
1321
|
+
|
|
1322
|
+
if (!didWarnAboutKeySpread[componentName + beforeExample]) {
|
|
1323
|
+
var afterExample = keys.length > 0 ? '{' + keys.join(': ..., ') + ': ...}' : '{}';
|
|
1324
|
+
|
|
1325
|
+
error('A props object containing a "key" prop is being spread into JSX:\n' + ' let props = %s;\n' + ' <%s {...props} />\n' + 'React keys must be passed directly to JSX without using spread:\n' + ' let props = %s;\n' + ' <%s key={someKey} {...props} />', beforeExample, componentName, afterExample, componentName);
|
|
1326
|
+
|
|
1327
|
+
didWarnAboutKeySpread[componentName + beforeExample] = true;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
if (type === REACT_FRAGMENT_TYPE) {
|
|
1333
|
+
validateFragmentProps(element);
|
|
1334
|
+
} else {
|
|
1335
|
+
validatePropTypes(element);
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
return element;
|
|
1339
|
+
}
|
|
1340
|
+
} // These two functions exist to still get child warnings in dev
|
|
1341
|
+
// even with the prod transform. This means that jsxDEV is purely
|
|
1342
|
+
// opt-in behavior for better messages but that we won't stop
|
|
1343
|
+
// giving you warnings if you use production apis.
|
|
1344
|
+
|
|
1345
|
+
function jsxWithValidationStatic(type, props, key) {
|
|
1346
|
+
{
|
|
1347
|
+
return jsxWithValidation(type, props, key, true);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
function jsxWithValidationDynamic(type, props, key) {
|
|
1351
|
+
{
|
|
1352
|
+
return jsxWithValidation(type, props, key, false);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
var jsx = jsxWithValidationDynamic ; // we may want to special case jsxs internally to take advantage of static children.
|
|
1357
|
+
// for now we can ship identical prod functions
|
|
1358
|
+
|
|
1359
|
+
var jsxs = jsxWithValidationStatic ;
|
|
1360
|
+
|
|
1361
|
+
reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
|
|
1362
|
+
reactJsxRuntime_development.jsx = jsx;
|
|
1363
|
+
reactJsxRuntime_development.jsxs = jsxs;
|
|
1364
|
+
})();
|
|
1365
|
+
}
|
|
1366
|
+
return reactJsxRuntime_development;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
if (process.env.NODE_ENV === 'production') {
|
|
1370
|
+
jsxRuntime.exports = requireReactJsxRuntime_production_min();
|
|
1371
|
+
} else {
|
|
1372
|
+
jsxRuntime.exports = requireReactJsxRuntime_development();
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
var jsxRuntimeExports = jsxRuntime.exports;
|
|
1376
|
+
|
|
1377
|
+
/**
|
|
1378
|
+
* Color palettes for stream visualization
|
|
1379
|
+
*/
|
|
1380
|
+
// Single color palettes (monochromatic)
|
|
1381
|
+
const singleColorPalettes = [
|
|
1382
|
+
{
|
|
1383
|
+
label: 'red',
|
|
1384
|
+
keyColor: 5,
|
|
1385
|
+
keyColorValue: '#FF3B65',
|
|
1386
|
+
values: [
|
|
1387
|
+
'#FFD2D9',
|
|
1388
|
+
'#FFB0BF',
|
|
1389
|
+
'#FF90A2',
|
|
1390
|
+
'#FF6780',
|
|
1391
|
+
'#FF3B65',
|
|
1392
|
+
'#D12D50',
|
|
1393
|
+
'#A31E3B',
|
|
1394
|
+
'#751025',
|
|
1395
|
+
'#470110',
|
|
1396
|
+
'#35010E',
|
|
1397
|
+
],
|
|
1398
|
+
},
|
|
1399
|
+
{
|
|
1400
|
+
label: 'pink',
|
|
1401
|
+
keyColor: 5,
|
|
1402
|
+
keyColorValue: '#D53C97',
|
|
1403
|
+
values: [
|
|
1404
|
+
'#F5D2E3',
|
|
1405
|
+
'#EDB0CF',
|
|
1406
|
+
'#E590BD',
|
|
1407
|
+
'#D967A4',
|
|
1408
|
+
'#D53C97',
|
|
1409
|
+
'#B52D7F',
|
|
1410
|
+
'#961F68',
|
|
1411
|
+
'#761050',
|
|
1412
|
+
'#560238',
|
|
1413
|
+
'#330124',
|
|
1414
|
+
],
|
|
1415
|
+
},
|
|
1416
|
+
{
|
|
1417
|
+
label: 'purple',
|
|
1418
|
+
keyColor: 5,
|
|
1419
|
+
keyColorValue: '#AC1BB5',
|
|
1420
|
+
values: [
|
|
1421
|
+
'#EACAEA',
|
|
1422
|
+
'#DAA6DA',
|
|
1423
|
+
'#CB81CC',
|
|
1424
|
+
'#B553BA',
|
|
1425
|
+
'#AC1BB5',
|
|
1426
|
+
'#911698',
|
|
1427
|
+
'#75127C',
|
|
1428
|
+
'#5A0E5F',
|
|
1429
|
+
'#3E0942',
|
|
1430
|
+
'#250528',
|
|
1431
|
+
],
|
|
1432
|
+
},
|
|
1433
|
+
{
|
|
1434
|
+
label: 'blue',
|
|
1435
|
+
keyColor: 5,
|
|
1436
|
+
keyColorValue: '#664CFC',
|
|
1437
|
+
values: [
|
|
1438
|
+
'#D9D3FC',
|
|
1439
|
+
'#BEB4F9',
|
|
1440
|
+
'#A395F8',
|
|
1441
|
+
'#806DF4',
|
|
1442
|
+
'#664CFC',
|
|
1443
|
+
'#523DCE',
|
|
1444
|
+
'#3F2F9F',
|
|
1445
|
+
'#2B2171',
|
|
1446
|
+
'#171242',
|
|
1447
|
+
'#0E0E35',
|
|
1448
|
+
],
|
|
1449
|
+
},
|
|
1450
|
+
{
|
|
1451
|
+
label: 'green',
|
|
1452
|
+
keyColor: 5,
|
|
1453
|
+
keyColorValue: '#52FFDB',
|
|
1454
|
+
values: [
|
|
1455
|
+
'#D5FFF6',
|
|
1456
|
+
'#B8FFF0',
|
|
1457
|
+
'#99FEE9',
|
|
1458
|
+
'#73FEE0',
|
|
1459
|
+
'#52FFDB',
|
|
1460
|
+
'#43D2B4',
|
|
1461
|
+
'#34A68D',
|
|
1462
|
+
'#23AD8F',
|
|
1463
|
+
'#1F8D77',
|
|
1464
|
+
'#113027',
|
|
1465
|
+
],
|
|
1466
|
+
},
|
|
1467
|
+
{
|
|
1468
|
+
label: 'orange',
|
|
1469
|
+
keyColor: 2,
|
|
1470
|
+
keyColorValue: '#F97316',
|
|
1471
|
+
values: ['#FDBA74', '#FB923C', '#F97316'],
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
label: 'yellow',
|
|
1475
|
+
keyColor: 2,
|
|
1476
|
+
keyColorValue: '#EAB308',
|
|
1477
|
+
values: ['#FDE047', '#FACC15', '#EAB308'],
|
|
1478
|
+
},
|
|
1479
|
+
{
|
|
1480
|
+
label: 'cyan',
|
|
1481
|
+
keyColor: 2,
|
|
1482
|
+
keyColorValue: '#06B6D4',
|
|
1483
|
+
values: ['#67E8F9', '#22D3EE', '#06B6D4'],
|
|
1484
|
+
},
|
|
1485
|
+
{
|
|
1486
|
+
label: 'gray',
|
|
1487
|
+
keyColor: 2,
|
|
1488
|
+
keyColorValue: '#71717A',
|
|
1489
|
+
values: ['#A1A1AA', '#71717A', '#52525B'],
|
|
1490
|
+
},
|
|
1491
|
+
];
|
|
1492
|
+
// Multi-color palettes for categorical data
|
|
1493
|
+
const multiColorPalettes = [
|
|
1494
|
+
{
|
|
1495
|
+
label: 'Dawn',
|
|
1496
|
+
keyColor: 0,
|
|
1497
|
+
keyColorValue: '#EC4899',
|
|
1498
|
+
values: [
|
|
1499
|
+
'#EC4899', // pink-400
|
|
1500
|
+
'#FACC15', // yellow-400
|
|
1501
|
+
'#DA4B36',
|
|
1502
|
+
'#9A1563',
|
|
1503
|
+
'#F87171', // red-400
|
|
1504
|
+
'#EF4444', // red-500
|
|
1505
|
+
'#A855F7', // purple-500
|
|
1506
|
+
'#DB2777', // pink-500
|
|
1507
|
+
'#F7775A',
|
|
1508
|
+
'#8B5CF6', // purple-500
|
|
1509
|
+
],
|
|
1510
|
+
},
|
|
1511
|
+
{
|
|
1512
|
+
label: 'Morning',
|
|
1513
|
+
keyColor: 0,
|
|
1514
|
+
keyColorValue: '#3B82F6',
|
|
1515
|
+
values: [
|
|
1516
|
+
'#3B82F6', // blue-500
|
|
1517
|
+
'#FB923C', // orange-400
|
|
1518
|
+
'#F87171', // red-400
|
|
1519
|
+
'#22D3EE', // cyan-400
|
|
1520
|
+
'#C084FC', // purple-400
|
|
1521
|
+
'#FACC15', // yellow-400
|
|
1522
|
+
'#F472B6', // pink-400
|
|
1523
|
+
'#4ADE80', // green-400
|
|
1524
|
+
'#EC4899', // pink-500
|
|
1525
|
+
'#4E5ADF',
|
|
1526
|
+
],
|
|
1527
|
+
},
|
|
1528
|
+
{
|
|
1529
|
+
label: 'Midnight',
|
|
1530
|
+
keyColor: 0,
|
|
1531
|
+
keyColorValue: '#4E5ADF',
|
|
1532
|
+
values: [
|
|
1533
|
+
'#4E5ADF',
|
|
1534
|
+
'#A855F7', // purple-500
|
|
1535
|
+
'#3B82F6', // blue-500
|
|
1536
|
+
'#084B8A',
|
|
1537
|
+
'#22C55E', // green-500
|
|
1538
|
+
'#C084FC', // purple-400
|
|
1539
|
+
'#244E47',
|
|
1540
|
+
'#0891B2', // cyan-600
|
|
1541
|
+
'#6626A3',
|
|
1542
|
+
'#2563EB', // blue-600
|
|
1543
|
+
],
|
|
1544
|
+
},
|
|
1545
|
+
{
|
|
1546
|
+
label: 'Ocean',
|
|
1547
|
+
keyColor: 0,
|
|
1548
|
+
keyColorValue: '#0EA5E9',
|
|
1549
|
+
values: [
|
|
1550
|
+
'#0EA5E9', // sky-500
|
|
1551
|
+
'#06B6D4', // cyan-500
|
|
1552
|
+
'#14B8A6', // teal-500
|
|
1553
|
+
'#22C55E', // green-500
|
|
1554
|
+
'#3B82F6', // blue-500
|
|
1555
|
+
'#6366F1', // indigo-500
|
|
1556
|
+
'#8B5CF6', // violet-500
|
|
1557
|
+
'#0284C7', // sky-600
|
|
1558
|
+
'#0891B2', // cyan-600
|
|
1559
|
+
'#0D9488', // teal-600
|
|
1560
|
+
],
|
|
1561
|
+
},
|
|
1562
|
+
{
|
|
1563
|
+
label: 'Sunset',
|
|
1564
|
+
keyColor: 0,
|
|
1565
|
+
keyColorValue: '#F97316',
|
|
1566
|
+
values: [
|
|
1567
|
+
'#F97316', // orange-500
|
|
1568
|
+
'#EF4444', // red-500
|
|
1569
|
+
'#EC4899', // pink-500
|
|
1570
|
+
'#F59E0B', // amber-500
|
|
1571
|
+
'#FACC15', // yellow-500
|
|
1572
|
+
'#FB923C', // orange-400
|
|
1573
|
+
'#F87171', // red-400
|
|
1574
|
+
'#F472B6', // pink-400
|
|
1575
|
+
'#FBBF24', // amber-400
|
|
1576
|
+
'#FDE047', // yellow-400
|
|
1577
|
+
],
|
|
1578
|
+
},
|
|
1579
|
+
];
|
|
1580
|
+
// All palettes combined
|
|
1581
|
+
const allPalettes = [...multiColorPalettes, ...singleColorPalettes];
|
|
1582
|
+
// Default palette
|
|
1583
|
+
const DEFAULT_PALETTE = multiColorPalettes[0];
|
|
1584
|
+
/**
|
|
1585
|
+
* Find a color palette by its values array
|
|
1586
|
+
*/
|
|
1587
|
+
function findPaletteByValues(values, defaultPalette = DEFAULT_PALETTE) {
|
|
1588
|
+
return (allPalettes.find((palette) => palette.values.join(',') === values.join(',')) || defaultPalette);
|
|
1589
|
+
}
|
|
1590
|
+
/**
|
|
1591
|
+
* Find a color palette by label
|
|
1592
|
+
*/
|
|
1593
|
+
function findPaletteByLabel(label, defaultPalette = DEFAULT_PALETTE) {
|
|
1594
|
+
return allPalettes.find((palette) => palette.label === label) || defaultPalette;
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Get the key color from a palette with optional opacity
|
|
1598
|
+
*/
|
|
1599
|
+
function getPaletteKeyColor(label, opacity = 1) {
|
|
1600
|
+
const palette = findPaletteByLabel(label);
|
|
1601
|
+
if (!palette)
|
|
1602
|
+
return '';
|
|
1603
|
+
if (opacity === 1)
|
|
1604
|
+
return palette.keyColorValue;
|
|
1605
|
+
const hex = palette.keyColorValue;
|
|
1606
|
+
const alpha = Math.floor(opacity * 255)
|
|
1607
|
+
.toString(16)
|
|
1608
|
+
.padStart(2, '0');
|
|
1609
|
+
return `${hex}${alpha}`;
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Generate colors for a given number of series from a palette
|
|
1613
|
+
*/
|
|
1614
|
+
function getSeriesColors(palette, count) {
|
|
1615
|
+
const colors = [];
|
|
1616
|
+
for (let i = 0; i < count; i++) {
|
|
1617
|
+
colors.push(palette.values[i % palette.values.length]);
|
|
1618
|
+
}
|
|
1619
|
+
return colors;
|
|
1620
|
+
}
|
|
1621
|
+
const darkTheme = {
|
|
1622
|
+
backgroundColor: 'transparent',
|
|
1623
|
+
textColor: '#E5E5E5',
|
|
1624
|
+
gridColor: '#374151',
|
|
1625
|
+
axisColor: '#6B7280',
|
|
1626
|
+
tooltipBackground: '#1F2937',
|
|
1627
|
+
tooltipTextColor: '#E5E5E5',
|
|
1628
|
+
fontFamily: 'Inter, system-ui, sans-serif',
|
|
1629
|
+
};
|
|
1630
|
+
const lightTheme = {
|
|
1631
|
+
backgroundColor: 'transparent',
|
|
1632
|
+
textColor: '#1F2937',
|
|
1633
|
+
gridColor: '#E5E7EB',
|
|
1634
|
+
axisColor: '#9CA3AF',
|
|
1635
|
+
tooltipBackground: '#FFFFFF',
|
|
1636
|
+
tooltipTextColor: '#1F2937',
|
|
1637
|
+
fontFamily: 'Inter, system-ui, sans-serif',
|
|
1638
|
+
};
|
|
1639
|
+
function getTheme(name) {
|
|
1640
|
+
return name === 'dark' ? darkTheme : lightTheme;
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
/**
|
|
1644
|
+
* VistralSpec — declarative grammar types for streaming visualizations.
|
|
1645
|
+
*
|
|
1646
|
+
* These types define a renderer-agnostic specification that can be compiled
|
|
1647
|
+
* down to AntV G2 options (or other backends in the future).
|
|
1648
|
+
*/
|
|
1649
|
+
// ---------------------------------------------------------------------------
|
|
1650
|
+
// Streaming
|
|
1651
|
+
// ---------------------------------------------------------------------------
|
|
1652
|
+
/** Default maximum number of data items kept in memory for streaming charts. */
|
|
1653
|
+
const DEFAULT_MAX_ITEMS = 1000;
|
|
1654
|
+
|
|
1655
|
+
/**
|
|
1656
|
+
* Utility functions for stream visualization
|
|
1657
|
+
*/
|
|
1658
|
+
// Type detection constants
|
|
1659
|
+
const NUMBER_TYPES = [
|
|
1660
|
+
'int8', 'int16', 'int32', 'int64', 'int128', 'int256',
|
|
1661
|
+
'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256',
|
|
1662
|
+
'float32', 'float64', 'float', 'double',
|
|
1663
|
+
'decimal', 'decimal32', 'decimal64', 'decimal128', 'decimal256',
|
|
1664
|
+
'number'
|
|
1665
|
+
];
|
|
1666
|
+
const DATETIME_TYPES = ['datetime', 'datetime64', 'date', 'date32', 'timestamp'];
|
|
1667
|
+
const STRING_TYPES = ['string', 'fixedstring', 'text', 'varchar', 'char'];
|
|
1668
|
+
/**
|
|
1669
|
+
* Check if a column type is numeric
|
|
1670
|
+
*/
|
|
1671
|
+
function isNumericColumn(type) {
|
|
1672
|
+
const upperType = type.toUpperCase();
|
|
1673
|
+
return NUMBER_TYPES.some((t) => upperType.startsWith(t.toUpperCase()));
|
|
1674
|
+
}
|
|
1675
|
+
/**
|
|
1676
|
+
* Check if a column type is datetime
|
|
1677
|
+
*/
|
|
1678
|
+
function isDateTimeColumn(type) {
|
|
1679
|
+
const upperType = type.toUpperCase();
|
|
1680
|
+
return DATETIME_TYPES.some((t) => upperType.startsWith(t.toUpperCase()));
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Check if a column type is string
|
|
1684
|
+
*/
|
|
1685
|
+
function isStringColumn(type) {
|
|
1686
|
+
const upperType = type.toUpperCase();
|
|
1687
|
+
return STRING_TYPES.some((t) => upperType.startsWith(t.toUpperCase()));
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Check if a column type is boolean
|
|
1691
|
+
*/
|
|
1692
|
+
function isBooleanColumn(type) {
|
|
1693
|
+
const upperType = type.toUpperCase();
|
|
1694
|
+
return upperType === 'BOOL' || upperType === 'BOOLEAN';
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* Determine automatic time format mask based on domain range
|
|
1698
|
+
*/
|
|
1699
|
+
function getTimeMask(domainMin, domainMax) {
|
|
1700
|
+
const date1 = new Date(domainMin);
|
|
1701
|
+
const date2 = new Date(domainMax);
|
|
1702
|
+
const y1 = date1.getFullYear();
|
|
1703
|
+
const m1 = date1.getMonth();
|
|
1704
|
+
const d1 = date1.getDate();
|
|
1705
|
+
const h1 = date1.getHours();
|
|
1706
|
+
const min1 = date1.getMinutes();
|
|
1707
|
+
const s1 = date1.getSeconds();
|
|
1708
|
+
const y2 = date2.getFullYear();
|
|
1709
|
+
const m2 = date2.getMonth();
|
|
1710
|
+
const d2 = date2.getDate();
|
|
1711
|
+
const h2 = date2.getHours();
|
|
1712
|
+
const min2 = date2.getMinutes();
|
|
1713
|
+
const s2 = date2.getSeconds();
|
|
1714
|
+
if (y1 !== y2)
|
|
1715
|
+
return 'YY/MM/DD';
|
|
1716
|
+
if (m1 !== m2)
|
|
1717
|
+
return 'MM/DD';
|
|
1718
|
+
if (d1 !== d2) {
|
|
1719
|
+
return Math.abs(d1 - d2) > 1 ? 'MM/DD' : 'MM/DD HH:mm:ss';
|
|
1720
|
+
}
|
|
1721
|
+
if (h1 !== h2 || min1 !== min2 || s1 !== s2)
|
|
1722
|
+
return 'HH:mm:ss';
|
|
1723
|
+
return 'HH:mm:ss';
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Clamp a number between min and max values
|
|
1727
|
+
*/
|
|
1728
|
+
function clamp(value, min, max) {
|
|
1729
|
+
return Math.min(Math.max(value, min), max);
|
|
1730
|
+
}
|
|
1731
|
+
/**
|
|
1732
|
+
* Truncate a string with ellipsis if too long
|
|
1733
|
+
*/
|
|
1734
|
+
function truncateWithEllipsis(str, maxLength) {
|
|
1735
|
+
if (!str || str.length <= maxLength)
|
|
1736
|
+
return str;
|
|
1737
|
+
return `${str.slice(0, maxLength)}...`;
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Format a number with locale formatting
|
|
1741
|
+
*/
|
|
1742
|
+
function formatNumber(num, digits = 2) {
|
|
1743
|
+
if (isNaN(num))
|
|
1744
|
+
return '-';
|
|
1745
|
+
return num.toLocaleString('en-US', { maximumFractionDigits: digits });
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1748
|
+
* Format a large number with abbreviation (k, m, b, t)
|
|
1749
|
+
*/
|
|
1750
|
+
function abbreviateNumber(num, decPlaces = 2) {
|
|
1751
|
+
if (isNaN(num))
|
|
1752
|
+
return '-';
|
|
1753
|
+
const abbrev = ['', 'k', 'm', 'b', 't'];
|
|
1754
|
+
let tier = 0;
|
|
1755
|
+
let scaledNum = num;
|
|
1756
|
+
while (Math.abs(scaledNum) >= 1000 && tier < abbrev.length - 1) {
|
|
1757
|
+
scaledNum /= 1000;
|
|
1758
|
+
tier++;
|
|
1759
|
+
}
|
|
1760
|
+
return `${scaledNum.toFixed(tier > 0 ? decPlaces : 0)}${abbrev[tier]}`;
|
|
1761
|
+
}
|
|
1762
|
+
/**
|
|
1763
|
+
* Format duration from milliseconds to human readable
|
|
1764
|
+
*/
|
|
1765
|
+
function formatDuration(ms) {
|
|
1766
|
+
if (ms < 1000)
|
|
1767
|
+
return `${Math.round(ms)}ms`;
|
|
1768
|
+
if (ms < 60000)
|
|
1769
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
1770
|
+
if (ms < 3600000)
|
|
1771
|
+
return `${(ms / 60000).toFixed(1)}m`;
|
|
1772
|
+
return `${(ms / 3600000).toFixed(1)}h`;
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* Format bytes to human readable size
|
|
1776
|
+
*/
|
|
1777
|
+
function formatBytes(bytes, decimals = 2) {
|
|
1778
|
+
if (bytes === 0)
|
|
1779
|
+
return '0 B';
|
|
1780
|
+
if (isNaN(bytes))
|
|
1781
|
+
return '-';
|
|
1782
|
+
const k = 1024;
|
|
1783
|
+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
1784
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
1785
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${sizes[i]}`;
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Debounce function execution
|
|
1789
|
+
*/
|
|
1790
|
+
function debounce(func, wait) {
|
|
1791
|
+
let timeout = null;
|
|
1792
|
+
return function (...args) {
|
|
1793
|
+
if (timeout)
|
|
1794
|
+
clearTimeout(timeout);
|
|
1795
|
+
timeout = setTimeout(() => func(...args), wait);
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* Get value from a data row by column index or name
|
|
1800
|
+
*/
|
|
1801
|
+
function getRowValue(row, column) {
|
|
1802
|
+
if (Array.isArray(row)) {
|
|
1803
|
+
return typeof column === 'number' ? row[column] : row[parseInt(column, 10)];
|
|
1804
|
+
}
|
|
1805
|
+
return row[column];
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Convert a row to array format if it's an object
|
|
1809
|
+
*/
|
|
1810
|
+
function rowToArray(row, columns) {
|
|
1811
|
+
if (Array.isArray(row))
|
|
1812
|
+
return row;
|
|
1813
|
+
return columns.map((col) => row[col.name]);
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Find column index by name
|
|
1817
|
+
*/
|
|
1818
|
+
function findColumnIndex(columns, name) {
|
|
1819
|
+
return columns.findIndex((col) => col.name === name);
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Get filtered columns by type
|
|
1823
|
+
*/
|
|
1824
|
+
function getColumnsByType(columns, filter) {
|
|
1825
|
+
switch (filter) {
|
|
1826
|
+
case 'numeric':
|
|
1827
|
+
return columns.filter((col) => isNumericColumn(col.type));
|
|
1828
|
+
case 'datetime':
|
|
1829
|
+
return columns.filter((col) => isDateTimeColumn(col.type));
|
|
1830
|
+
case 'string':
|
|
1831
|
+
return columns.filter((col) => isStringColumn(col.type));
|
|
1832
|
+
case 'boolean':
|
|
1833
|
+
return columns.filter((col) => isBooleanColumn(col.type));
|
|
1834
|
+
default:
|
|
1835
|
+
return columns;
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
/**
|
|
1839
|
+
* Calculate statistics for a numeric column
|
|
1840
|
+
*/
|
|
1841
|
+
function calculateColumnStats(data, columnIndex) {
|
|
1842
|
+
let min = Infinity;
|
|
1843
|
+
let max = -Infinity;
|
|
1844
|
+
let sum = 0;
|
|
1845
|
+
let count = 0;
|
|
1846
|
+
for (const row of data) {
|
|
1847
|
+
const value = Array.isArray(row) ? row[columnIndex] : Object.values(row)[columnIndex];
|
|
1848
|
+
if (typeof value === 'number' && !isNaN(value)) {
|
|
1849
|
+
min = Math.min(min, value);
|
|
1850
|
+
max = Math.max(max, value);
|
|
1851
|
+
sum += value;
|
|
1852
|
+
count++;
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
return {
|
|
1856
|
+
min: min === Infinity ? 0 : min,
|
|
1857
|
+
max: max === -Infinity ? 0 : max,
|
|
1858
|
+
sum,
|
|
1859
|
+
count,
|
|
1860
|
+
avg: count > 0 ? sum / count : 0,
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
/**
|
|
1864
|
+
* Get unique values for a column (for categorical data)
|
|
1865
|
+
*/
|
|
1866
|
+
function getUniqueValues(data, columnIndex) {
|
|
1867
|
+
const values = new Set();
|
|
1868
|
+
for (const row of data) {
|
|
1869
|
+
const value = Array.isArray(row) ? row[columnIndex] : Object.values(row)[columnIndex];
|
|
1870
|
+
if (value !== null && value !== undefined) {
|
|
1871
|
+
values.add(String(value));
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
return Array.from(values);
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* Parse datetime value to timestamp
|
|
1878
|
+
*/
|
|
1879
|
+
function parseDateTime(value) {
|
|
1880
|
+
if (typeof value === 'number')
|
|
1881
|
+
return value;
|
|
1882
|
+
if (value instanceof Date)
|
|
1883
|
+
return value.getTime();
|
|
1884
|
+
if (typeof value === 'string') {
|
|
1885
|
+
const parsed = Date.parse(value);
|
|
1886
|
+
return isNaN(parsed) ? 0 : parsed;
|
|
1887
|
+
}
|
|
1888
|
+
return 0;
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Process data source into internal format for charts
|
|
1892
|
+
*/
|
|
1893
|
+
function processDataSource(source, xKey, yKey, zKey) {
|
|
1894
|
+
const { columns, data } = source;
|
|
1895
|
+
const xIndex = findColumnIndex(columns, xKey);
|
|
1896
|
+
const yIndex = findColumnIndex(columns, yKey);
|
|
1897
|
+
const zIndex = zKey ? findColumnIndex(columns, zKey) : -1;
|
|
1898
|
+
const isXTime = xIndex >= 0 && isDateTimeColumn(columns[xIndex].type);
|
|
1899
|
+
// Calculate statistics
|
|
1900
|
+
let xMin = Infinity;
|
|
1901
|
+
let xMax = -Infinity;
|
|
1902
|
+
let yMin = Infinity;
|
|
1903
|
+
let yMax = -Infinity;
|
|
1904
|
+
const zValues = [];
|
|
1905
|
+
for (const row of data) {
|
|
1906
|
+
const arr = rowToArray(row, columns);
|
|
1907
|
+
// X stats
|
|
1908
|
+
if (xIndex >= 0) {
|
|
1909
|
+
const xVal = isXTime ? parseDateTime(arr[xIndex]) : Number(arr[xIndex]);
|
|
1910
|
+
if (!isNaN(xVal)) {
|
|
1911
|
+
xMin = Math.min(xMin, xVal);
|
|
1912
|
+
xMax = Math.max(xMax, xVal);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
// Y stats
|
|
1916
|
+
if (yIndex >= 0) {
|
|
1917
|
+
const yVal = Number(arr[yIndex]);
|
|
1918
|
+
if (!isNaN(yVal)) {
|
|
1919
|
+
yMin = Math.min(yMin, yVal);
|
|
1920
|
+
yMax = Math.max(yMax, yVal);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
// Z categories
|
|
1924
|
+
if (zIndex >= 0) {
|
|
1925
|
+
const zVal = String(arr[zIndex] ?? '');
|
|
1926
|
+
if (zVal && !zValues.includes(zVal)) {
|
|
1927
|
+
zValues.push(zVal);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
// Transform function for x-axis
|
|
1932
|
+
const xTransform = isXTime ? (v) => parseDateTime(v) : (v) => v;
|
|
1933
|
+
return {
|
|
1934
|
+
data: data.map((row) => rowToArray(row, columns)),
|
|
1935
|
+
header: columns,
|
|
1936
|
+
x: {
|
|
1937
|
+
index: xIndex,
|
|
1938
|
+
isTime: isXTime,
|
|
1939
|
+
min: xMin === Infinity ? 0 : xMin,
|
|
1940
|
+
max: xMax === -Infinity ? 0 : xMax,
|
|
1941
|
+
offset: 0,
|
|
1942
|
+
},
|
|
1943
|
+
y: {
|
|
1944
|
+
index: yIndex,
|
|
1945
|
+
min: yMin === Infinity ? 0 : yMin,
|
|
1946
|
+
max: yMax === -Infinity ? 0 : yMax,
|
|
1947
|
+
},
|
|
1948
|
+
z: {
|
|
1949
|
+
index: zIndex,
|
|
1950
|
+
values: zValues,
|
|
1951
|
+
},
|
|
1952
|
+
xTransform,
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
/**
|
|
1956
|
+
* Merge deep objects (like lodash merge)
|
|
1957
|
+
*/
|
|
1958
|
+
function mergeDeep(target, ...sources) {
|
|
1959
|
+
if (!sources.length)
|
|
1960
|
+
return target;
|
|
1961
|
+
const source = sources.shift();
|
|
1962
|
+
if (!source)
|
|
1963
|
+
return target;
|
|
1964
|
+
for (const key in source) {
|
|
1965
|
+
const sourceValue = source[key];
|
|
1966
|
+
const targetValue = target[key];
|
|
1967
|
+
if (isObject(sourceValue) && isObject(targetValue)) {
|
|
1968
|
+
target[key] = mergeDeep({ ...targetValue }, sourceValue);
|
|
1969
|
+
}
|
|
1970
|
+
else if (sourceValue !== undefined) {
|
|
1971
|
+
target[key] = sourceValue;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
return mergeDeep(target, ...sources);
|
|
1975
|
+
}
|
|
1976
|
+
function isObject(item) {
|
|
1977
|
+
return item !== null && typeof item === 'object' && !Array.isArray(item);
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* Generate unique ID
|
|
1981
|
+
*/
|
|
1982
|
+
function generateId(prefix = 'stream-viz') {
|
|
1983
|
+
return `${prefix}-${Math.random().toString(36).substr(2, 9)}`;
|
|
1984
|
+
}
|
|
1985
|
+
// ============================================================
|
|
1986
|
+
// Temporal Binding Utilities
|
|
1987
|
+
// ============================================================
|
|
1988
|
+
/**
|
|
1989
|
+
* Filter data by latest timestamp (frame-bound mode)
|
|
1990
|
+
* Keeps only rows with the maximum timestamp value
|
|
1991
|
+
*/
|
|
1992
|
+
function filterByLatestTimestamp(data, timeIndex) {
|
|
1993
|
+
if (data.length === 0 || timeIndex < 0)
|
|
1994
|
+
return data;
|
|
1995
|
+
// Find the maximum timestamp
|
|
1996
|
+
let maxTimestamp = -Infinity;
|
|
1997
|
+
for (const row of data) {
|
|
1998
|
+
const ts = parseDateTime(row[timeIndex]);
|
|
1999
|
+
if (ts > maxTimestamp) {
|
|
2000
|
+
maxTimestamp = ts;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
// Filter to only rows with the max timestamp
|
|
2004
|
+
return data.filter((row) => parseDateTime(row[timeIndex]) === maxTimestamp);
|
|
2005
|
+
}
|
|
2006
|
+
/**
|
|
2007
|
+
* Filter data by unique key (key-bound mode)
|
|
2008
|
+
* Keeps only the latest row for each unique key value
|
|
2009
|
+
*/
|
|
2010
|
+
/**
|
|
2011
|
+
* Filter data by unique key (key-bound mode)
|
|
2012
|
+
* Keeps only the latest row for each unique key value
|
|
2013
|
+
*/
|
|
2014
|
+
function filterByKey(data, keyIndex) {
|
|
2015
|
+
const indices = Array.isArray(keyIndex) ? keyIndex : [keyIndex];
|
|
2016
|
+
if (data.length === 0 || indices.some(idx => idx < 0))
|
|
2017
|
+
return data;
|
|
2018
|
+
// Use a map to keep the latest value for each key
|
|
2019
|
+
const groups = new Map();
|
|
2020
|
+
for (const row of data) {
|
|
2021
|
+
// specific composite key generation
|
|
2022
|
+
const key = indices.map(idx => String(row[idx] ?? '')).join('::');
|
|
2023
|
+
groups.set(key, row);
|
|
2024
|
+
}
|
|
2025
|
+
return Array.from(groups.values());
|
|
2026
|
+
}
|
|
2027
|
+
/**
|
|
2028
|
+
* Apply temporal filtering based on configuration
|
|
2029
|
+
*/
|
|
2030
|
+
function applyTemporalFilter(data, columns, temporal) {
|
|
2031
|
+
// Handle single or multiple fields
|
|
2032
|
+
const fields = Array.isArray(temporal.field) ? temporal.field : [temporal.field];
|
|
2033
|
+
const fieldIndices = fields.map(f => findColumnIndex(columns, f));
|
|
2034
|
+
// If any field is not found, return original data
|
|
2035
|
+
if (fieldIndices.some(idx => idx < 0))
|
|
2036
|
+
return data;
|
|
2037
|
+
const primaryIndex = fieldIndices[0]; // Used for frame/axis checking usually, but frame mode handles single index
|
|
2038
|
+
switch (temporal.mode) {
|
|
2039
|
+
case 'frame':
|
|
2040
|
+
// Frame mode currently assumes single time field
|
|
2041
|
+
return filterByLatestTimestamp(data, primaryIndex);
|
|
2042
|
+
case 'key':
|
|
2043
|
+
// Key mode supports multiple fields
|
|
2044
|
+
return filterByKey(data, Array.isArray(temporal.field) ? fieldIndices : primaryIndex);
|
|
2045
|
+
case 'axis':
|
|
2046
|
+
// Axis mode filtering is handled by the chart component itself
|
|
2047
|
+
// (e.g., through domain clamping in TimeSeriesChart)
|
|
2048
|
+
return data;
|
|
2049
|
+
default:
|
|
2050
|
+
return data;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
/**
|
|
2055
|
+
* React hooks for stream visualization
|
|
2056
|
+
*/
|
|
2057
|
+
/**
|
|
2058
|
+
* Hook to manage AntV G2 chart instance
|
|
2059
|
+
*/
|
|
2060
|
+
function useChart(options) {
|
|
2061
|
+
const chartRef = useRef(null);
|
|
2062
|
+
const [chart, setChart] = useState(null);
|
|
2063
|
+
const [isMouseOver, setIsMouseOver] = useState(false);
|
|
2064
|
+
const [activeColor, setActiveColor] = useState(-1);
|
|
2065
|
+
useEffect(() => {
|
|
2066
|
+
if (!chartRef.current)
|
|
2067
|
+
return;
|
|
2068
|
+
const chartInstance = new Chart({
|
|
2069
|
+
container: chartRef.current,
|
|
2070
|
+
autoFit: true,
|
|
2071
|
+
height: options?.height,
|
|
2072
|
+
padding: options?.padding,
|
|
2073
|
+
marginBottom: 0,
|
|
2074
|
+
});
|
|
2075
|
+
// Set up mouse tracking
|
|
2076
|
+
const container = chartInstance.getContainer();
|
|
2077
|
+
const handleMouseOver = () => setIsMouseOver(true);
|
|
2078
|
+
const handleMouseLeave = () => setIsMouseOver(false);
|
|
2079
|
+
container.addEventListener('mouseover', handleMouseOver);
|
|
2080
|
+
container.addEventListener('mouseleave', handleMouseLeave);
|
|
2081
|
+
// Initialize with empty data
|
|
2082
|
+
chartInstance.data([]);
|
|
2083
|
+
setChart(chartInstance);
|
|
2084
|
+
return () => {
|
|
2085
|
+
container.removeEventListener('mouseover', handleMouseOver);
|
|
2086
|
+
container.removeEventListener('mouseleave', handleMouseLeave);
|
|
2087
|
+
chartInstance.destroy();
|
|
2088
|
+
setChart(null);
|
|
2089
|
+
};
|
|
2090
|
+
}, [options?.height, options?.padding]);
|
|
2091
|
+
return {
|
|
2092
|
+
chart,
|
|
2093
|
+
chartRef,
|
|
2094
|
+
isMouseOver,
|
|
2095
|
+
activeColor,
|
|
2096
|
+
setActiveColor,
|
|
2097
|
+
};
|
|
2098
|
+
}
|
|
2099
|
+
/**
|
|
2100
|
+
* Hook to process streaming data source
|
|
2101
|
+
*/
|
|
2102
|
+
function useDataSource(source, xKey, yKey, zKey) {
|
|
2103
|
+
const [processedData, setProcessedData] = useState(null);
|
|
2104
|
+
useEffect(() => {
|
|
2105
|
+
if (!source || !yKey) {
|
|
2106
|
+
setProcessedData(null);
|
|
2107
|
+
return;
|
|
2108
|
+
}
|
|
2109
|
+
const processed = processDataSource(source, xKey, yKey, zKey);
|
|
2110
|
+
setProcessedData(processed);
|
|
2111
|
+
}, [source, xKey, yKey, zKey]);
|
|
2112
|
+
return processedData;
|
|
2113
|
+
}
|
|
2114
|
+
/**
|
|
2115
|
+
* Hook to track streaming data updates
|
|
2116
|
+
*/
|
|
2117
|
+
function useStreamingData(initialData, maxItems = DEFAULT_MAX_ITEMS) {
|
|
2118
|
+
const [data, setData] = useState(initialData);
|
|
2119
|
+
const append = useCallback((items) => {
|
|
2120
|
+
setData((prev) => {
|
|
2121
|
+
const newItems = Array.isArray(items) ? items : [items];
|
|
2122
|
+
const combined = [...prev, ...newItems];
|
|
2123
|
+
// Keep only the last maxItems
|
|
2124
|
+
return combined.slice(-maxItems);
|
|
2125
|
+
});
|
|
2126
|
+
}, [maxItems]);
|
|
2127
|
+
const replace = useCallback((items) => {
|
|
2128
|
+
setData(items.slice(-maxItems));
|
|
2129
|
+
}, [maxItems]);
|
|
2130
|
+
const clear = useCallback(() => {
|
|
2131
|
+
setData([]);
|
|
2132
|
+
}, []);
|
|
2133
|
+
return { data, append, replace, clear };
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* Hook to handle resize detection
|
|
2137
|
+
*/
|
|
2138
|
+
function useResizeObserver(callback) {
|
|
2139
|
+
const ref = useRef(null);
|
|
2140
|
+
useEffect(() => {
|
|
2141
|
+
if (!ref.current)
|
|
2142
|
+
return;
|
|
2143
|
+
let timeout = null;
|
|
2144
|
+
const debouncedCallback = (entry) => {
|
|
2145
|
+
if (timeout)
|
|
2146
|
+
clearTimeout(timeout);
|
|
2147
|
+
timeout = setTimeout(() => callback(entry), 200);
|
|
2148
|
+
};
|
|
2149
|
+
const observer = new ResizeObserver((entries) => {
|
|
2150
|
+
entries.forEach((entry) => debouncedCallback(entry));
|
|
2151
|
+
});
|
|
2152
|
+
observer.observe(ref.current);
|
|
2153
|
+
return () => {
|
|
2154
|
+
if (timeout)
|
|
2155
|
+
clearTimeout(timeout);
|
|
2156
|
+
observer.disconnect();
|
|
2157
|
+
};
|
|
2158
|
+
}, [callback]);
|
|
2159
|
+
return ref;
|
|
2160
|
+
}
|
|
2161
|
+
/**
|
|
2162
|
+
* Hook to manage chart theme
|
|
2163
|
+
*/
|
|
2164
|
+
function useChartTheme(theme = 'dark') {
|
|
2165
|
+
const [currentTheme, setCurrentTheme] = useState(theme);
|
|
2166
|
+
const toggleTheme = useCallback(() => {
|
|
2167
|
+
setCurrentTheme((prev) => (prev === 'dark' ? 'light' : 'dark'));
|
|
2168
|
+
}, []);
|
|
2169
|
+
return {
|
|
2170
|
+
theme: currentTheme,
|
|
2171
|
+
setTheme: setCurrentTheme,
|
|
2172
|
+
toggleTheme,
|
|
2173
|
+
isDark: currentTheme === 'dark',
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
/**
|
|
2177
|
+
* Hook to track last update time
|
|
2178
|
+
*/
|
|
2179
|
+
function useLastUpdated(data) {
|
|
2180
|
+
const [lastUpdated, setLastUpdated] = useState(null);
|
|
2181
|
+
useEffect(() => {
|
|
2182
|
+
if (data.length > 0) {
|
|
2183
|
+
setLastUpdated(new Date());
|
|
2184
|
+
}
|
|
2185
|
+
}, [data]);
|
|
2186
|
+
return lastUpdated;
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Hook for sparkline data management
|
|
2190
|
+
*/
|
|
2191
|
+
function useSparklineData(value, limit = 20) {
|
|
2192
|
+
const [data, setData] = useState([]);
|
|
2193
|
+
useEffect(() => {
|
|
2194
|
+
if (value === null || isNaN(value))
|
|
2195
|
+
return;
|
|
2196
|
+
setData((prev) => {
|
|
2197
|
+
const next = [...prev, { value }];
|
|
2198
|
+
return next.slice(-limit);
|
|
2199
|
+
});
|
|
2200
|
+
}, [value, limit]);
|
|
2201
|
+
const trend = data.length >= 2
|
|
2202
|
+
? data[data.length - 1].value > data[data.length - 2].value
|
|
2203
|
+
? 'up'
|
|
2204
|
+
: data[data.length - 1].value < data[data.length - 2].value
|
|
2205
|
+
? 'down'
|
|
2206
|
+
: 'stable'
|
|
2207
|
+
: 'stable';
|
|
2208
|
+
return { data, trend };
|
|
2209
|
+
}
|
|
2210
|
+
/**
|
|
2211
|
+
* Hook to manage chart animation state
|
|
2212
|
+
*/
|
|
2213
|
+
function useChartAnimation(enabled = true) {
|
|
2214
|
+
const [isAnimating, setIsAnimating] = useState(false);
|
|
2215
|
+
const startAnimation = useCallback(() => {
|
|
2216
|
+
if (enabled)
|
|
2217
|
+
setIsAnimating(true);
|
|
2218
|
+
}, [enabled]);
|
|
2219
|
+
const stopAnimation = useCallback(() => {
|
|
2220
|
+
setIsAnimating(false);
|
|
2221
|
+
}, []);
|
|
2222
|
+
return {
|
|
2223
|
+
isAnimating,
|
|
2224
|
+
startAnimation,
|
|
2225
|
+
stopAnimation,
|
|
2226
|
+
animationEnabled: enabled,
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* Hook to debounce a value
|
|
2231
|
+
*/
|
|
2232
|
+
function useDebouncedValue(value, delay = 300) {
|
|
2233
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
2234
|
+
useEffect(() => {
|
|
2235
|
+
const timer = setTimeout(() => {
|
|
2236
|
+
setDebouncedValue(value);
|
|
2237
|
+
}, delay);
|
|
2238
|
+
return () => {
|
|
2239
|
+
clearTimeout(timer);
|
|
2240
|
+
};
|
|
2241
|
+
}, [value, delay]);
|
|
2242
|
+
return debouncedValue;
|
|
2243
|
+
}
|
|
2244
|
+
/**
|
|
2245
|
+
* Hook to track previous value
|
|
2246
|
+
*/
|
|
2247
|
+
function usePrevious(value) {
|
|
2248
|
+
const ref = useRef();
|
|
2249
|
+
useEffect(() => {
|
|
2250
|
+
ref.current = value;
|
|
2251
|
+
}, [value]);
|
|
2252
|
+
return ref.current;
|
|
2253
|
+
}
|
|
2254
|
+
/**
|
|
2255
|
+
* Hook to determine default chart configuration based on data schema
|
|
2256
|
+
*/
|
|
2257
|
+
function useAutoConfig(columns) {
|
|
2258
|
+
return useCallback(() => {
|
|
2259
|
+
const dateCol = columns.find((c) => ['datetime', 'datetime64', 'date', 'timestamp'].some((t) => c.type.toLowerCase().includes(t)));
|
|
2260
|
+
const numericCols = columns.filter((c) => ['int', 'float', 'double', 'decimal', 'number'].some((t) => c.type.toLowerCase().includes(t)));
|
|
2261
|
+
const stringCols = columns.filter((c) => ['string', 'varchar', 'text', 'char'].some((t) => c.type.toLowerCase().includes(t)));
|
|
2262
|
+
return {
|
|
2263
|
+
suggestedXAxis: dateCol?.name || stringCols[0]?.name || columns[0]?.name,
|
|
2264
|
+
suggestedYAxis: numericCols[0]?.name || columns[1]?.name,
|
|
2265
|
+
suggestedColor: stringCols[0]?.name,
|
|
2266
|
+
hasTimeSeries: !!dateCol && numericCols.length > 0,
|
|
2267
|
+
hasCategorical: stringCols.length > 0 && numericCols.length > 0,
|
|
2268
|
+
};
|
|
2269
|
+
}, [columns]);
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
/**
|
|
2273
|
+
* Find color palette by name
|
|
2274
|
+
*/
|
|
2275
|
+
function findColorByName(name) {
|
|
2276
|
+
return singleColorPalettes.find((c) => c.label === name);
|
|
2277
|
+
}
|
|
2278
|
+
/**
|
|
2279
|
+
* Get default configuration for single value chart
|
|
2280
|
+
*/
|
|
2281
|
+
function getSingleValueDefaults(columns) {
|
|
2282
|
+
const numericCol = columns.find(({ type }) => ['int', 'float', 'double', 'decimal', 'number'].some((t) => type.toLowerCase().includes(t)));
|
|
2283
|
+
if (!numericCol)
|
|
2284
|
+
return null;
|
|
2285
|
+
return {
|
|
2286
|
+
chartType: 'singleValue',
|
|
2287
|
+
yAxis: numericCol.name,
|
|
2288
|
+
fontSize: 64,
|
|
2289
|
+
color: 'blue',
|
|
2290
|
+
fractionDigits: 2,
|
|
2291
|
+
sparkline: false,
|
|
2292
|
+
sparklineColor: 'purple',
|
|
2293
|
+
delta: false,
|
|
2294
|
+
increaseColor: 'green',
|
|
2295
|
+
decreaseColor: 'red',
|
|
2296
|
+
unit: { position: 'left', value: '' },
|
|
2297
|
+
};
|
|
2298
|
+
}
|
|
2299
|
+
/**
|
|
2300
|
+
* Animated number display component
|
|
2301
|
+
*/
|
|
2302
|
+
const AnimatedNumber = ({ value, decimals, duration = 500 }) => {
|
|
2303
|
+
const [displayValue, setDisplayValue] = useState(value);
|
|
2304
|
+
const previousValue = useRef(value);
|
|
2305
|
+
useEffect(() => {
|
|
2306
|
+
if (isNaN(value))
|
|
2307
|
+
return;
|
|
2308
|
+
const startValue = previousValue.current;
|
|
2309
|
+
const startTime = Date.now();
|
|
2310
|
+
const animate = () => {
|
|
2311
|
+
const elapsed = Date.now() - startTime;
|
|
2312
|
+
const progress = Math.min(elapsed / duration, 1);
|
|
2313
|
+
// Easing function (ease-out)
|
|
2314
|
+
const easeOut = 1 - Math.pow(1 - progress, 3);
|
|
2315
|
+
const current = startValue + (value - startValue) * easeOut;
|
|
2316
|
+
setDisplayValue(current);
|
|
2317
|
+
if (progress < 1) {
|
|
2318
|
+
requestAnimationFrame(animate);
|
|
2319
|
+
}
|
|
2320
|
+
else {
|
|
2321
|
+
previousValue.current = value;
|
|
2322
|
+
}
|
|
2323
|
+
};
|
|
2324
|
+
requestAnimationFrame(animate);
|
|
2325
|
+
}, [value, duration]);
|
|
2326
|
+
return (jsxRuntimeExports.jsx("span", { children: isNaN(displayValue) ? '-' : displayValue.toLocaleString('en-US', {
|
|
2327
|
+
minimumFractionDigits: decimals,
|
|
2328
|
+
maximumFractionDigits: decimals,
|
|
2329
|
+
}) }));
|
|
2330
|
+
};
|
|
2331
|
+
/**
|
|
2332
|
+
* Mini Sparkline Component
|
|
2333
|
+
*/
|
|
2334
|
+
const MiniSparkline = ({ data, color, width = 200, height = 60 }) => {
|
|
2335
|
+
const { chart, chartRef } = useChart({ height });
|
|
2336
|
+
useEffect(() => {
|
|
2337
|
+
if (!chart || data.length === 0)
|
|
2338
|
+
return;
|
|
2339
|
+
chart.clear();
|
|
2340
|
+
const indexedData = data.map((d, i) => ({ index: i, value: d.value }));
|
|
2341
|
+
chart
|
|
2342
|
+
.line()
|
|
2343
|
+
.data(indexedData)
|
|
2344
|
+
.animate(false)
|
|
2345
|
+
.encode('x', 'index')
|
|
2346
|
+
.encode('y', 'value')
|
|
2347
|
+
.style('stroke', color)
|
|
2348
|
+
.style('lineWidth', 2)
|
|
2349
|
+
.style('shape', 'smooth')
|
|
2350
|
+
.scale({
|
|
2351
|
+
x: { type: 'linear', range: [0, 1] },
|
|
2352
|
+
y: { type: 'linear', nice: true },
|
|
2353
|
+
})
|
|
2354
|
+
.axis(false)
|
|
2355
|
+
.tooltip(false);
|
|
2356
|
+
chart.render();
|
|
2357
|
+
}, [chart, data, color]);
|
|
2358
|
+
return (jsxRuntimeExports.jsx("div", { ref: chartRef, style: { width: `${width}px`, height: `${height}px` } }));
|
|
2359
|
+
};
|
|
2360
|
+
/**
|
|
2361
|
+
* Single Value Chart Component
|
|
2362
|
+
*/
|
|
2363
|
+
const SingleValueChart = ({ config: configRaw, data: dataSource, theme = 'dark', className, style, }) => {
|
|
2364
|
+
// Merge with defaults
|
|
2365
|
+
const defaults = getSingleValueDefaults(dataSource.columns);
|
|
2366
|
+
const config = useMemo(() => ({
|
|
2367
|
+
...defaults,
|
|
2368
|
+
...configRaw,
|
|
2369
|
+
}), [configRaw, defaults]);
|
|
2370
|
+
// Get colors
|
|
2371
|
+
const mainColor = findColorByName(config.color || 'blue')?.keyColorValue || '#3B82F6';
|
|
2372
|
+
const sparklineColor = findColorByName(config.sparklineColor || 'purple')?.keyColorValue || '#8B5CF6';
|
|
2373
|
+
const increaseColor = findColorByName(config.increaseColor || 'green')?.keyColorValue || '#22C55E';
|
|
2374
|
+
const decreaseColor = findColorByName(config.decreaseColor || 'red')?.keyColorValue || '#EF4444';
|
|
2375
|
+
// Process data source
|
|
2376
|
+
const source = useDataSource(dataSource, '', config.yAxis, '');
|
|
2377
|
+
// Get current value
|
|
2378
|
+
const currentValue = useMemo(() => {
|
|
2379
|
+
if (!source || source.y.index < 0 || source.data.length === 0)
|
|
2380
|
+
return NaN;
|
|
2381
|
+
const lastRow = source.data[source.data.length - 1];
|
|
2382
|
+
return Number(lastRow[source.y.index]);
|
|
2383
|
+
}, [source]);
|
|
2384
|
+
// Track sparkline data and previous value for delta
|
|
2385
|
+
const { data: sparklineData } = useSparklineData(currentValue, 20);
|
|
2386
|
+
const [previousValue, setPreviousValue] = useState(NaN);
|
|
2387
|
+
useEffect(() => {
|
|
2388
|
+
if (!isNaN(currentValue)) {
|
|
2389
|
+
const timer = setTimeout(() => {
|
|
2390
|
+
setPreviousValue(currentValue);
|
|
2391
|
+
}, 100);
|
|
2392
|
+
return () => clearTimeout(timer);
|
|
2393
|
+
}
|
|
2394
|
+
}, [currentValue]);
|
|
2395
|
+
// Calculate delta and keep last non-zero value
|
|
2396
|
+
const [displayedDelta, setDisplayedDelta] = useState(0);
|
|
2397
|
+
useEffect(() => {
|
|
2398
|
+
if (isNaN(currentValue) || isNaN(previousValue))
|
|
2399
|
+
return;
|
|
2400
|
+
const newDelta = currentValue - previousValue;
|
|
2401
|
+
// Only update displayed delta if it's non-zero
|
|
2402
|
+
if (newDelta !== 0) {
|
|
2403
|
+
setDisplayedDelta(newDelta);
|
|
2404
|
+
}
|
|
2405
|
+
}, [currentValue, previousValue]);
|
|
2406
|
+
// Decimal places
|
|
2407
|
+
const decimals = clamp(config.fractionDigits || 0, 0, 10);
|
|
2408
|
+
const fontSize = config.fontSize || 64;
|
|
2409
|
+
// Loading state
|
|
2410
|
+
if (isNaN(currentValue)) {
|
|
2411
|
+
return (jsxRuntimeExports.jsxs("div", { className: className, style: {
|
|
2412
|
+
width: '100%',
|
|
2413
|
+
height: '100%',
|
|
2414
|
+
display: 'flex',
|
|
2415
|
+
alignItems: 'center',
|
|
2416
|
+
justifyContent: 'center',
|
|
2417
|
+
color: theme === 'dark' ? '#9CA3AF' : '#6B7280',
|
|
2418
|
+
...style,
|
|
2419
|
+
}, "data-testid": "single-value-chart", children: [jsxRuntimeExports.jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { animation: 'spin 1s linear infinite' }, children: [jsxRuntimeExports.jsx("circle", { cx: "12", cy: "12", r: "10", strokeOpacity: "0.25" }), jsxRuntimeExports.jsx("path", { d: "M12 2a10 10 0 0 1 10 10", strokeLinecap: "round" })] }), jsxRuntimeExports.jsx("style", { children: `@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }` })] }));
|
|
2420
|
+
}
|
|
2421
|
+
// Unit rendering
|
|
2422
|
+
const renderUnit = (position) => {
|
|
2423
|
+
const unit = config.unit;
|
|
2424
|
+
if (!unit?.value || unit.position !== position)
|
|
2425
|
+
return null;
|
|
2426
|
+
return (jsxRuntimeExports.jsx("span", { style: {
|
|
2427
|
+
fontSize: position === 'left' ? fontSize : fontSize / 2,
|
|
2428
|
+
fontWeight: 'bold',
|
|
2429
|
+
fontFamily: 'Menlo, Monaco, monospace',
|
|
2430
|
+
color: mainColor,
|
|
2431
|
+
paddingRight: position === 'left' ? '4px' : 0,
|
|
2432
|
+
paddingLeft: position === 'right' ? '4px' : 0,
|
|
2433
|
+
}, children: unit.value }));
|
|
2434
|
+
};
|
|
2435
|
+
return (jsxRuntimeExports.jsxs("div", { className: className, style: {
|
|
2436
|
+
width: '100%',
|
|
2437
|
+
height: '100%',
|
|
2438
|
+
display: 'flex',
|
|
2439
|
+
flexDirection: 'column',
|
|
2440
|
+
alignItems: 'center',
|
|
2441
|
+
justifyContent: 'center',
|
|
2442
|
+
padding: '16px',
|
|
2443
|
+
...style,
|
|
2444
|
+
}, "data-testid": "single-value-chart", children: [jsxRuntimeExports.jsxs("div", { style: { display: 'flex', alignItems: 'baseline' }, children: [renderUnit('left'), jsxRuntimeExports.jsx("span", { style: {
|
|
2445
|
+
fontSize: `${fontSize}px`,
|
|
2446
|
+
fontWeight: 'bold',
|
|
2447
|
+
fontFamily: 'Menlo, Monaco, monospace',
|
|
2448
|
+
color: mainColor,
|
|
2449
|
+
}, children: jsxRuntimeExports.jsx(AnimatedNumber, { value: currentValue, decimals: decimals }) }), renderUnit('right')] }), config.delta && (jsxRuntimeExports.jsxs("div", { style: {
|
|
2450
|
+
fontSize: `${Math.ceil(fontSize / 3)}px`,
|
|
2451
|
+
fontWeight: 'bold',
|
|
2452
|
+
fontFamily: 'Menlo, Monaco, monospace',
|
|
2453
|
+
display: 'flex',
|
|
2454
|
+
alignItems: 'center',
|
|
2455
|
+
justifyContent: 'center',
|
|
2456
|
+
gap: '4px',
|
|
2457
|
+
color: displayedDelta > 0 ? increaseColor : displayedDelta < 0 ? decreaseColor : theme === 'dark' ? '#6B7280' : '#9CA3AF',
|
|
2458
|
+
marginTop: '8px',
|
|
2459
|
+
minHeight: `${Math.ceil(fontSize / 3) + 4}px`,
|
|
2460
|
+
}, children: [jsxRuntimeExports.jsx("span", { style: {
|
|
2461
|
+
width: 0,
|
|
2462
|
+
height: 0,
|
|
2463
|
+
borderStyle: 'solid',
|
|
2464
|
+
borderWidth: displayedDelta >= 0 ? '0 4px 8px 4px' : '8px 4px 0 4px',
|
|
2465
|
+
borderColor: displayedDelta >= 0
|
|
2466
|
+
? `transparent transparent ${displayedDelta > 0 ? increaseColor : (theme === 'dark' ? '#6B7280' : '#9CA3AF')} transparent`
|
|
2467
|
+
: `${decreaseColor} transparent transparent transparent`,
|
|
2468
|
+
} }), jsxRuntimeExports.jsxs("span", { children: [displayedDelta >= 0 ? '+' : '', displayedDelta.toLocaleString('en-US', {
|
|
2469
|
+
minimumFractionDigits: decimals,
|
|
2470
|
+
maximumFractionDigits: decimals,
|
|
2471
|
+
})] })] })), config.sparkline && sparklineData.length > 1 && (jsxRuntimeExports.jsx("div", { style: { marginTop: '16px', width: '80%', maxWidth: '300px' }, children: jsxRuntimeExports.jsx(MiniSparkline, { data: sparklineData, color: sparklineColor, height: 60 }) }))] }));
|
|
2472
|
+
};
|
|
2473
|
+
|
|
2474
|
+
/**
|
|
2475
|
+
* Get default table configuration
|
|
2476
|
+
*/
|
|
2477
|
+
function getTableDefaults(columns) {
|
|
2478
|
+
const tableStyles = {};
|
|
2479
|
+
columns.forEach((col) => {
|
|
2480
|
+
tableStyles[col.name] = {
|
|
2481
|
+
name: col.name,
|
|
2482
|
+
show: true,
|
|
2483
|
+
width: 150,
|
|
2484
|
+
miniChart: 'none',
|
|
2485
|
+
color: { type: 'none' },
|
|
2486
|
+
};
|
|
2487
|
+
});
|
|
2488
|
+
return {
|
|
2489
|
+
chartType: 'table',
|
|
2490
|
+
tableStyles,
|
|
2491
|
+
tableWrap: false,
|
|
2492
|
+
};
|
|
2493
|
+
}
|
|
2494
|
+
/**
|
|
2495
|
+
* Mini Sparkline for table cells
|
|
2496
|
+
*/
|
|
2497
|
+
const CellSparkline = ({ data, width = 80, height = 30, }) => {
|
|
2498
|
+
const { chart, chartRef } = useChart({ height });
|
|
2499
|
+
useEffect(() => {
|
|
2500
|
+
if (!chart || data.length === 0)
|
|
2501
|
+
return;
|
|
2502
|
+
chart.clear();
|
|
2503
|
+
const indexedData = data.map((d, i) => ({ index: i, value: d }));
|
|
2504
|
+
chart
|
|
2505
|
+
.line()
|
|
2506
|
+
.data(indexedData)
|
|
2507
|
+
.animate(false)
|
|
2508
|
+
.encode('x', 'index')
|
|
2509
|
+
.encode('y', 'value')
|
|
2510
|
+
.style('stroke', '#8B5CF6')
|
|
2511
|
+
.style('lineWidth', 1)
|
|
2512
|
+
.style('shape', 'smooth')
|
|
2513
|
+
.scale({
|
|
2514
|
+
x: { type: 'linear', range: [0, 1] },
|
|
2515
|
+
y: { type: 'linear', nice: true },
|
|
2516
|
+
})
|
|
2517
|
+
.axis(false)
|
|
2518
|
+
.tooltip(false);
|
|
2519
|
+
chart.render();
|
|
2520
|
+
}, [chart, data]);
|
|
2521
|
+
return jsxRuntimeExports.jsx("div", { ref: chartRef, style: { width, height } });
|
|
2522
|
+
};
|
|
2523
|
+
/**
|
|
2524
|
+
* Get cell background color based on conditions
|
|
2525
|
+
*/
|
|
2526
|
+
function getCellBackgroundColor(value, colorConfig) {
|
|
2527
|
+
if (!colorConfig || colorConfig.type === 'none')
|
|
2528
|
+
return undefined;
|
|
2529
|
+
if (colorConfig.type === 'condition' && colorConfig.conditions) {
|
|
2530
|
+
const numValue = Number(value);
|
|
2531
|
+
if (isNaN(numValue))
|
|
2532
|
+
return undefined;
|
|
2533
|
+
for (const condition of colorConfig.conditions) {
|
|
2534
|
+
let matches = false;
|
|
2535
|
+
switch (condition.operator) {
|
|
2536
|
+
case 'gt':
|
|
2537
|
+
matches = numValue > condition.value;
|
|
2538
|
+
break;
|
|
2539
|
+
case 'lt':
|
|
2540
|
+
matches = numValue < condition.value;
|
|
2541
|
+
break;
|
|
2542
|
+
case 'eq':
|
|
2543
|
+
matches = numValue === condition.value;
|
|
2544
|
+
break;
|
|
2545
|
+
case 'gte':
|
|
2546
|
+
matches = numValue >= condition.value;
|
|
2547
|
+
break;
|
|
2548
|
+
case 'lte':
|
|
2549
|
+
matches = numValue <= condition.value;
|
|
2550
|
+
break;
|
|
2551
|
+
}
|
|
2552
|
+
if (matches)
|
|
2553
|
+
return condition.color;
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
return undefined;
|
|
2557
|
+
}
|
|
2558
|
+
/**
|
|
2559
|
+
* Table Cell Component
|
|
2560
|
+
*/
|
|
2561
|
+
const TableCell = ({ value, isNumeric, miniChart, sparklineData = [], color, wrap, theme }) => {
|
|
2562
|
+
const bgColor = getCellBackgroundColor(value, color);
|
|
2563
|
+
const displayValue = isNumeric ? formatNumber(Number(value)) : String(value ?? '');
|
|
2564
|
+
return (jsxRuntimeExports.jsx("td", { style: {
|
|
2565
|
+
padding: '8px 12px',
|
|
2566
|
+
borderBottom: `1px solid ${theme === 'dark' ? '#374151' : '#E5E7EB'}`,
|
|
2567
|
+
textAlign: isNumeric ? 'right' : 'left',
|
|
2568
|
+
backgroundColor: bgColor,
|
|
2569
|
+
whiteSpace: wrap ? 'normal' : 'nowrap',
|
|
2570
|
+
overflow: 'hidden',
|
|
2571
|
+
textOverflow: 'ellipsis',
|
|
2572
|
+
maxWidth: '200px',
|
|
2573
|
+
}, title: String(value ?? ''), children: jsxRuntimeExports.jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '8px' }, children: [miniChart === 'sparkline' && sparklineData.length > 0 && (jsxRuntimeExports.jsx(CellSparkline, { data: sparklineData })), jsxRuntimeExports.jsx("span", { children: displayValue })] }) }));
|
|
2574
|
+
};
|
|
2575
|
+
/**
|
|
2576
|
+
* Table Header Cell Component
|
|
2577
|
+
*/
|
|
2578
|
+
const TableHeaderCell = ({ column, displayName, width, onResize, theme }) => {
|
|
2579
|
+
const resizeRef = useRef(null);
|
|
2580
|
+
const [isResizing, setIsResizing] = useState(false);
|
|
2581
|
+
const handleMouseDown = useCallback((e) => {
|
|
2582
|
+
e.preventDefault();
|
|
2583
|
+
setIsResizing(true);
|
|
2584
|
+
const startX = e.clientX;
|
|
2585
|
+
const startWidth = width;
|
|
2586
|
+
const handleMouseMove = (moveEvent) => {
|
|
2587
|
+
const diff = moveEvent.clientX - startX;
|
|
2588
|
+
const newWidth = Math.max(50, startWidth + diff);
|
|
2589
|
+
onResize(newWidth);
|
|
2590
|
+
};
|
|
2591
|
+
const handleMouseUp = () => {
|
|
2592
|
+
setIsResizing(false);
|
|
2593
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
2594
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
2595
|
+
};
|
|
2596
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
2597
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
2598
|
+
}, [width, onResize]);
|
|
2599
|
+
return (jsxRuntimeExports.jsxs("th", { style: {
|
|
2600
|
+
position: 'relative',
|
|
2601
|
+
padding: '12px',
|
|
2602
|
+
borderBottom: `2px solid ${theme === 'dark' ? '#374151' : '#E5E7EB'}`,
|
|
2603
|
+
backgroundColor: theme === 'dark' ? '#1F2937' : '#F3F4F6',
|
|
2604
|
+
textAlign: 'left',
|
|
2605
|
+
fontWeight: 600,
|
|
2606
|
+
width: `${width}px`,
|
|
2607
|
+
minWidth: `${width}px`,
|
|
2608
|
+
userSelect: 'none',
|
|
2609
|
+
}, children: [jsxRuntimeExports.jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '8px' }, children: [jsxRuntimeExports.jsx("span", { style: {
|
|
2610
|
+
fontSize: '10px',
|
|
2611
|
+
padding: '2px 4px',
|
|
2612
|
+
borderRadius: '4px',
|
|
2613
|
+
backgroundColor: theme === 'dark' ? '#374151' : '#E5E7EB',
|
|
2614
|
+
color: theme === 'dark' ? '#9CA3AF' : '#6B7280',
|
|
2615
|
+
}, children: column.type }), jsxRuntimeExports.jsx("span", { children: displayName || column.name })] }), jsxRuntimeExports.jsx("div", { ref: resizeRef, onMouseDown: handleMouseDown, style: {
|
|
2616
|
+
position: 'absolute',
|
|
2617
|
+
right: 0,
|
|
2618
|
+
top: 0,
|
|
2619
|
+
bottom: 0,
|
|
2620
|
+
width: '8px',
|
|
2621
|
+
cursor: 'col-resize',
|
|
2622
|
+
backgroundColor: isResizing ? (theme === 'dark' ? '#3B82F6' : '#2563EB') : 'transparent',
|
|
2623
|
+
transition: 'background-color 0.2s',
|
|
2624
|
+
}, onMouseEnter: (e) => {
|
|
2625
|
+
if (!isResizing) {
|
|
2626
|
+
e.currentTarget.style.backgroundColor = theme === 'dark' ? '#4B5563' : '#D1D5DB';
|
|
2627
|
+
}
|
|
2628
|
+
}, onMouseLeave: (e) => {
|
|
2629
|
+
if (!isResizing) {
|
|
2630
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
2631
|
+
}
|
|
2632
|
+
} })] }));
|
|
2633
|
+
};
|
|
2634
|
+
/**
|
|
2635
|
+
* Streaming Data Table Component
|
|
2636
|
+
*/
|
|
2637
|
+
const DataTable = ({ config: configRaw, data: dataSource, theme = 'dark', className, style, onConfigChange, maxRows = DEFAULT_MAX_ITEMS, }) => {
|
|
2638
|
+
// Merge with defaults
|
|
2639
|
+
const defaults = getTableDefaults(dataSource.columns);
|
|
2640
|
+
const config = useMemo(() => ({
|
|
2641
|
+
...defaults,
|
|
2642
|
+
...configRaw,
|
|
2643
|
+
}), [configRaw, defaults]);
|
|
2644
|
+
// Column widths state
|
|
2645
|
+
const [columnWidths, setColumnWidths] = useState(() => {
|
|
2646
|
+
const widths = {};
|
|
2647
|
+
dataSource.columns.forEach((col) => {
|
|
2648
|
+
widths[col.name] = config.tableStyles?.[col.name]?.width || 150;
|
|
2649
|
+
});
|
|
2650
|
+
return widths;
|
|
2651
|
+
});
|
|
2652
|
+
// Track sparkline data per row/column using ref to avoid infinite loops
|
|
2653
|
+
const sparklineHistoryRef = useRef({});
|
|
2654
|
+
// Version counter to trigger re-renders when sparkline data changes
|
|
2655
|
+
const [, setSparklineVersion] = useState(0);
|
|
2656
|
+
// Process data for display
|
|
2657
|
+
const displayData = useMemo(() => {
|
|
2658
|
+
const { columns, data } = dataSource;
|
|
2659
|
+
const { temporal } = config;
|
|
2660
|
+
let processedData = data.map((row) => rowToArray(row, columns));
|
|
2661
|
+
// Apply temporal filtering if configured
|
|
2662
|
+
if (temporal) {
|
|
2663
|
+
processedData = applyTemporalFilter(processedData, columns, temporal);
|
|
2664
|
+
}
|
|
2665
|
+
// Limit rows
|
|
2666
|
+
return processedData.slice(-maxRows);
|
|
2667
|
+
}, [dataSource, config, maxRows]);
|
|
2668
|
+
// Update sparkline history - use ref to avoid infinite loop
|
|
2669
|
+
const prevDataLengthRef = useRef(0);
|
|
2670
|
+
useEffect(() => {
|
|
2671
|
+
if (!config.tableStyles)
|
|
2672
|
+
return;
|
|
2673
|
+
const sparklineCols = Object.entries(config.tableStyles)
|
|
2674
|
+
.filter(([_, style]) => style?.miniChart === 'sparkline')
|
|
2675
|
+
.map(([name]) => name);
|
|
2676
|
+
// Only update if we have sparkline columns and data changed
|
|
2677
|
+
if (sparklineCols.length === 0)
|
|
2678
|
+
return;
|
|
2679
|
+
if (displayData.length === prevDataLengthRef.current && displayData.length > 0)
|
|
2680
|
+
return;
|
|
2681
|
+
prevDataLengthRef.current = displayData.length;
|
|
2682
|
+
let hasChanges = false;
|
|
2683
|
+
displayData.forEach((row, rowIndex) => {
|
|
2684
|
+
sparklineCols.forEach((colName) => {
|
|
2685
|
+
const colIndex = dataSource.columns.findIndex((c) => c.name === colName);
|
|
2686
|
+
if (colIndex >= 0) {
|
|
2687
|
+
const key = `${rowIndex}-${colName}`;
|
|
2688
|
+
const value = Number(row[colIndex]);
|
|
2689
|
+
if (!isNaN(value)) {
|
|
2690
|
+
const existing = sparklineHistoryRef.current[key] || [];
|
|
2691
|
+
const lastValue = existing[existing.length - 1];
|
|
2692
|
+
if (lastValue !== value || existing.length === 0) {
|
|
2693
|
+
sparklineHistoryRef.current[key] = [...existing, value].slice(-20);
|
|
2694
|
+
hasChanges = true;
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
});
|
|
2699
|
+
});
|
|
2700
|
+
// Only trigger re-render if there were actual changes
|
|
2701
|
+
if (hasChanges) {
|
|
2702
|
+
setSparklineVersion((v) => v + 1);
|
|
2703
|
+
}
|
|
2704
|
+
}, [displayData, config.tableStyles, dataSource.columns]);
|
|
2705
|
+
// Handle column resize
|
|
2706
|
+
const handleColumnResize = useCallback((columnName, width) => {
|
|
2707
|
+
setColumnWidths((prev) => ({ ...prev, [columnName]: width }));
|
|
2708
|
+
if (onConfigChange) {
|
|
2709
|
+
const newConfig = {
|
|
2710
|
+
...config,
|
|
2711
|
+
tableStyles: {
|
|
2712
|
+
...config.tableStyles,
|
|
2713
|
+
[columnName]: {
|
|
2714
|
+
...config.tableStyles?.[columnName],
|
|
2715
|
+
width,
|
|
2716
|
+
},
|
|
2717
|
+
},
|
|
2718
|
+
};
|
|
2719
|
+
onConfigChange(newConfig);
|
|
2720
|
+
}
|
|
2721
|
+
}, [config, onConfigChange]);
|
|
2722
|
+
// Visible columns
|
|
2723
|
+
const visibleColumns = useMemo(() => dataSource.columns.filter((col) => {
|
|
2724
|
+
const style = config.tableStyles?.[col.name];
|
|
2725
|
+
return style?.show !== false;
|
|
2726
|
+
}), [dataSource.columns, config.tableStyles]);
|
|
2727
|
+
return (jsxRuntimeExports.jsxs("div", { className: className, style: {
|
|
2728
|
+
width: '100%',
|
|
2729
|
+
height: '100%',
|
|
2730
|
+
overflow: 'auto',
|
|
2731
|
+
backgroundColor: theme === 'dark' ? '#111827' : '#FFFFFF',
|
|
2732
|
+
color: theme === 'dark' ? '#F3F4F6' : '#1F2937',
|
|
2733
|
+
...style,
|
|
2734
|
+
}, "data-testid": "data-table", children: [jsxRuntimeExports.jsxs("table", { style: {
|
|
2735
|
+
width: '100%',
|
|
2736
|
+
borderCollapse: 'collapse',
|
|
2737
|
+
fontSize: '14px',
|
|
2738
|
+
}, children: [jsxRuntimeExports.jsx("thead", { style: { position: 'sticky', top: 0, zIndex: 10 }, children: jsxRuntimeExports.jsxs("tr", { children: [jsxRuntimeExports.jsx("th", { style: {
|
|
2739
|
+
padding: '12px 8px',
|
|
2740
|
+
borderBottom: `2px solid ${theme === 'dark' ? '#374151' : '#E5E7EB'}`,
|
|
2741
|
+
backgroundColor: theme === 'dark' ? '#1F2937' : '#F3F4F6',
|
|
2742
|
+
textAlign: 'center',
|
|
2743
|
+
fontWeight: 600,
|
|
2744
|
+
width: '40px',
|
|
2745
|
+
minWidth: '40px',
|
|
2746
|
+
color: theme === 'dark' ? '#9CA3AF' : '#6B7280',
|
|
2747
|
+
}, children: "No." }), visibleColumns.map((col) => (jsxRuntimeExports.jsx(TableHeaderCell, { column: col, displayName: config.tableStyles?.[col.name]?.name, width: columnWidths[col.name] || 150, onResize: (width) => handleColumnResize(col.name, width), theme: theme }, col.name)))] }) }), jsxRuntimeExports.jsx("tbody", { children: displayData.map((row, rowIndex) => (jsxRuntimeExports.jsxs("tr", { style: {
|
|
2748
|
+
backgroundColor: rowIndex % 2 === 0
|
|
2749
|
+
? 'transparent'
|
|
2750
|
+
: theme === 'dark'
|
|
2751
|
+
? 'rgba(55, 65, 81, 0.3)'
|
|
2752
|
+
: 'rgba(243, 244, 246, 0.5)',
|
|
2753
|
+
}, children: [jsxRuntimeExports.jsx("td", { style: {
|
|
2754
|
+
padding: '8px',
|
|
2755
|
+
borderBottom: `1px solid ${theme === 'dark' ? '#374151' : '#E5E7EB'}`,
|
|
2756
|
+
textAlign: 'center',
|
|
2757
|
+
color: theme === 'dark' ? '#6B7280' : '#9CA3AF',
|
|
2758
|
+
fontWeight: 500,
|
|
2759
|
+
}, children: rowIndex + 1 }), visibleColumns.map((col) => {
|
|
2760
|
+
const colIndex = dataSource.columns.findIndex((c) => c.name === col.name);
|
|
2761
|
+
const value = row[colIndex];
|
|
2762
|
+
const colStyle = config.tableStyles?.[col.name];
|
|
2763
|
+
const sparklineKey = `${rowIndex}-${col.name}`;
|
|
2764
|
+
return (jsxRuntimeExports.jsx(TableCell, { value: value, isNumeric: isNumericColumn(col.type), miniChart: colStyle?.miniChart, sparklineData: sparklineHistoryRef.current[sparklineKey], color: colStyle?.color, wrap: config.tableWrap, theme: theme }, col.name));
|
|
2765
|
+
})] }, rowIndex))) })] }), displayData.length === 0 && (jsxRuntimeExports.jsx("div", { style: {
|
|
2766
|
+
padding: '48px',
|
|
2767
|
+
textAlign: 'center',
|
|
2768
|
+
color: theme === 'dark' ? '#6B7280' : '#9CA3AF',
|
|
2769
|
+
}, children: "No data available" }))] }));
|
|
2770
|
+
};
|
|
2771
|
+
|
|
2772
|
+
// Tile providers
|
|
2773
|
+
const TILE_PROVIDERS = {
|
|
2774
|
+
'openstreetmap': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
2775
|
+
'cartodb-dark': 'https://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
|
|
2776
|
+
'cartodb-light': 'https://basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
|
|
2777
|
+
};
|
|
2778
|
+
// Tile cache to avoid re-fetching
|
|
2779
|
+
const tileCache = new Map();
|
|
2780
|
+
/**
|
|
2781
|
+
* Load a map tile image
|
|
2782
|
+
*/
|
|
2783
|
+
function loadTile(url) {
|
|
2784
|
+
if (tileCache.has(url)) {
|
|
2785
|
+
return Promise.resolve(tileCache.get(url));
|
|
2786
|
+
}
|
|
2787
|
+
return new Promise((resolve, reject) => {
|
|
2788
|
+
const img = new Image();
|
|
2789
|
+
img.crossOrigin = 'anonymous';
|
|
2790
|
+
img.onload = () => {
|
|
2791
|
+
tileCache.set(url, img);
|
|
2792
|
+
resolve(img);
|
|
2793
|
+
};
|
|
2794
|
+
img.onerror = reject;
|
|
2795
|
+
img.src = url;
|
|
2796
|
+
});
|
|
2797
|
+
}
|
|
2798
|
+
/**
|
|
2799
|
+
* Get tile URL for a given tile coordinate
|
|
2800
|
+
*/
|
|
2801
|
+
function getTileUrl(provider, x, y, z) {
|
|
2802
|
+
const template = TILE_PROVIDERS[provider] || TILE_PROVIDERS['cartodb-dark'];
|
|
2803
|
+
return template
|
|
2804
|
+
.replace('{x}', String(x))
|
|
2805
|
+
.replace('{y}', String(y))
|
|
2806
|
+
.replace('{z}', String(z))
|
|
2807
|
+
.replace('{s}', ['a', 'b', 'c'][Math.floor(Math.random() * 3)]);
|
|
2808
|
+
}
|
|
2809
|
+
/**
|
|
2810
|
+
* Get default configuration for geo chart
|
|
2811
|
+
*/
|
|
2812
|
+
function getGeoChartDefaults(columns) {
|
|
2813
|
+
// Look for lat/lng columns
|
|
2814
|
+
const latNames = ['lat', 'latitude', 'y'];
|
|
2815
|
+
const lngNames = ['lng', 'lon', 'longitude', 'x'];
|
|
2816
|
+
const latCol = columns.find(({ name }) => latNames.some((n) => name.toLowerCase().includes(n)));
|
|
2817
|
+
const lngCol = columns.find(({ name }) => lngNames.some((n) => name.toLowerCase().includes(n)));
|
|
2818
|
+
if (!latCol || !lngCol)
|
|
2819
|
+
return null;
|
|
2820
|
+
return {
|
|
2821
|
+
chartType: 'geo',
|
|
2822
|
+
latitude: latCol.name,
|
|
2823
|
+
longitude: lngCol.name,
|
|
2824
|
+
zoom: 2,
|
|
2825
|
+
tileProvider: 'cartodb-dark',
|
|
2826
|
+
showZoomControl: true,
|
|
2827
|
+
pointOpacity: 0.8,
|
|
2828
|
+
pointColor: '#3B82F6',
|
|
2829
|
+
};
|
|
2830
|
+
}
|
|
2831
|
+
/**
|
|
2832
|
+
* Convert lat/lng to tile coordinates
|
|
2833
|
+
*/
|
|
2834
|
+
function latLngToTile(lat, lng, zoom) {
|
|
2835
|
+
const n = Math.pow(2, zoom);
|
|
2836
|
+
const x = ((lng + 180) / 360) * n;
|
|
2837
|
+
const latRad = (lat * Math.PI) / 180;
|
|
2838
|
+
const y = ((1 - Math.log(Math.tan(latRad) + 1 / Math.cos(latRad)) / Math.PI) / 2) * n;
|
|
2839
|
+
return { x, y };
|
|
2840
|
+
}
|
|
2841
|
+
/**
|
|
2842
|
+
* Convert tile coordinates to pixel position
|
|
2843
|
+
*/
|
|
2844
|
+
function tileToPixel(tileX, tileY, centerTileX, centerTileY, width, height, tileSize = 256) {
|
|
2845
|
+
const pixelX = (tileX - centerTileX) * tileSize + width / 2;
|
|
2846
|
+
const pixelY = (tileY - centerTileY) * tileSize + height / 2;
|
|
2847
|
+
return { x: pixelX, y: pixelY };
|
|
2848
|
+
}
|
|
2849
|
+
/**
|
|
2850
|
+
* Convert lat/lng to pixel position
|
|
2851
|
+
*/
|
|
2852
|
+
function latLngToPixel(lat, lng, center, zoom, width, height) {
|
|
2853
|
+
const tile = latLngToTile(lat, lng, zoom);
|
|
2854
|
+
const centerTile = latLngToTile(center[0], center[1], zoom);
|
|
2855
|
+
return tileToPixel(tile.x, tile.y, centerTile.x, centerTile.y, width, height);
|
|
2856
|
+
}
|
|
2857
|
+
/**
|
|
2858
|
+
* Get color for a category value
|
|
2859
|
+
*/
|
|
2860
|
+
function getCategoryColor(value, categories, colors) {
|
|
2861
|
+
const index = categories.indexOf(value);
|
|
2862
|
+
return colors[index % colors.length];
|
|
2863
|
+
}
|
|
2864
|
+
/**
|
|
2865
|
+
* GeoChart Component
|
|
2866
|
+
*/
|
|
2867
|
+
const GeoChart = ({ config: configRaw, data: dataSource, theme = 'dark', className, style, maxItems, }) => {
|
|
2868
|
+
const canvasRef = useRef(null);
|
|
2869
|
+
const containerRef = useRef(null);
|
|
2870
|
+
const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
|
|
2871
|
+
const [zoom, setZoom] = useState(configRaw.zoom || 2);
|
|
2872
|
+
const [center, setCenter] = useState(configRaw.center || [0, 0]);
|
|
2873
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
2874
|
+
const dragStart = useRef(null);
|
|
2875
|
+
// Merge with defaults
|
|
2876
|
+
const defaults = getGeoChartDefaults(dataSource.columns);
|
|
2877
|
+
const config = useMemo(() => ({
|
|
2878
|
+
...defaults,
|
|
2879
|
+
...configRaw,
|
|
2880
|
+
}), [configRaw, defaults]);
|
|
2881
|
+
// Get column indices
|
|
2882
|
+
const latIndex = findColumnIndex(dataSource.columns, config.latitude);
|
|
2883
|
+
const lngIndex = findColumnIndex(dataSource.columns, config.longitude);
|
|
2884
|
+
const colorIndex = config.color ? findColumnIndex(dataSource.columns, config.color) : -1;
|
|
2885
|
+
const sizeIndex = config.size?.key ? findColumnIndex(dataSource.columns, config.size.key) : -1;
|
|
2886
|
+
// Process data points
|
|
2887
|
+
const points = useMemo(() => {
|
|
2888
|
+
if (latIndex < 0 || lngIndex < 0)
|
|
2889
|
+
return [];
|
|
2890
|
+
const { columns, data } = dataSource;
|
|
2891
|
+
const { temporal } = config;
|
|
2892
|
+
// Convert data to array format and apply temporal filtering
|
|
2893
|
+
let processedData = data.map((row) => rowToArray(row, columns));
|
|
2894
|
+
// Apply temporal filtering if configured
|
|
2895
|
+
if (temporal) {
|
|
2896
|
+
processedData = applyTemporalFilter(processedData, columns, temporal);
|
|
2897
|
+
}
|
|
2898
|
+
// Limit data to maxItems
|
|
2899
|
+
const effectiveMaxItems = maxItems ?? config.maxItems ?? DEFAULT_MAX_ITEMS;
|
|
2900
|
+
processedData = processedData.slice(-effectiveMaxItems);
|
|
2901
|
+
const result = [];
|
|
2902
|
+
// Get unique color values for categorical coloring
|
|
2903
|
+
const colorValues = [];
|
|
2904
|
+
if (colorIndex >= 0) {
|
|
2905
|
+
processedData.forEach((arr) => {
|
|
2906
|
+
const val = String(arr[colorIndex] ?? '');
|
|
2907
|
+
if (!colorValues.includes(val)) {
|
|
2908
|
+
colorValues.push(val);
|
|
2909
|
+
}
|
|
2910
|
+
});
|
|
2911
|
+
}
|
|
2912
|
+
// Get color palette
|
|
2913
|
+
const palette = multiColorPalettes[0]?.values || ['#3B82F6'];
|
|
2914
|
+
// Calculate size range if needed
|
|
2915
|
+
let sizeMin = Infinity;
|
|
2916
|
+
let sizeMax = -Infinity;
|
|
2917
|
+
if (sizeIndex >= 0) {
|
|
2918
|
+
processedData.forEach((arr) => {
|
|
2919
|
+
const val = Number(arr[sizeIndex]);
|
|
2920
|
+
if (!isNaN(val)) {
|
|
2921
|
+
sizeMin = Math.min(sizeMin, val);
|
|
2922
|
+
sizeMax = Math.max(sizeMax, val);
|
|
2923
|
+
}
|
|
2924
|
+
});
|
|
2925
|
+
}
|
|
2926
|
+
processedData.forEach((arr) => {
|
|
2927
|
+
const lat = Number(arr[latIndex]);
|
|
2928
|
+
const lng = Number(arr[lngIndex]);
|
|
2929
|
+
if (isNaN(lat) || isNaN(lng))
|
|
2930
|
+
return;
|
|
2931
|
+
let color = config.pointColor || '#3B82F6';
|
|
2932
|
+
if (colorIndex >= 0) {
|
|
2933
|
+
const colorVal = String(arr[colorIndex] ?? '');
|
|
2934
|
+
color = getCategoryColor(colorVal, colorValues, palette);
|
|
2935
|
+
}
|
|
2936
|
+
let size = 6;
|
|
2937
|
+
if (sizeIndex >= 0) {
|
|
2938
|
+
const sizeVal = Number(arr[sizeIndex]);
|
|
2939
|
+
if (!isNaN(sizeVal) && sizeMax > sizeMin) {
|
|
2940
|
+
const normalized = (sizeVal - sizeMin) / (sizeMax - sizeMin);
|
|
2941
|
+
const minSize = config.size?.min || 4;
|
|
2942
|
+
const maxSize = config.size?.max || 20;
|
|
2943
|
+
size = minSize + normalized * (maxSize - minSize);
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
result.push({ lat, lng, color, size, row: arr });
|
|
2947
|
+
});
|
|
2948
|
+
return result;
|
|
2949
|
+
}, [dataSource, latIndex, lngIndex, colorIndex, sizeIndex, config]);
|
|
2950
|
+
// Set initial center from first point if not specified
|
|
2951
|
+
useEffect(() => {
|
|
2952
|
+
if (!configRaw.center && points.length > 0 && center[0] === 0 && center[1] === 0) {
|
|
2953
|
+
setCenter([points[0].lat, points[0].lng]);
|
|
2954
|
+
}
|
|
2955
|
+
}, [points, configRaw.center, center]);
|
|
2956
|
+
// Handle resize
|
|
2957
|
+
useEffect(() => {
|
|
2958
|
+
const container = containerRef.current;
|
|
2959
|
+
if (!container)
|
|
2960
|
+
return;
|
|
2961
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
2962
|
+
const entry = entries[0];
|
|
2963
|
+
if (entry) {
|
|
2964
|
+
setDimensions({
|
|
2965
|
+
width: entry.contentRect.width,
|
|
2966
|
+
height: entry.contentRect.height,
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
});
|
|
2970
|
+
resizeObserver.observe(container);
|
|
2971
|
+
return () => resizeObserver.disconnect();
|
|
2972
|
+
}, []);
|
|
2973
|
+
// Draw the map and points
|
|
2974
|
+
useEffect(() => {
|
|
2975
|
+
const canvas = canvasRef.current;
|
|
2976
|
+
if (!canvas || dimensions.width === 0 || dimensions.height === 0)
|
|
2977
|
+
return;
|
|
2978
|
+
const ctx = canvas.getContext('2d');
|
|
2979
|
+
if (!ctx)
|
|
2980
|
+
return;
|
|
2981
|
+
const { width, height } = dimensions;
|
|
2982
|
+
canvas.width = width;
|
|
2983
|
+
canvas.height = height;
|
|
2984
|
+
// Clear canvas with background color
|
|
2985
|
+
ctx.fillStyle = theme === 'dark' ? '#1a1a2e' : '#F3F4F6';
|
|
2986
|
+
ctx.fillRect(0, 0, width, height);
|
|
2987
|
+
const tileSize = 256;
|
|
2988
|
+
const zoomInt = Math.floor(zoom);
|
|
2989
|
+
const scale = Math.pow(2, zoom - zoomInt);
|
|
2990
|
+
// Calculate center tile
|
|
2991
|
+
const centerTile = latLngToTile(center[0], center[1], zoomInt);
|
|
2992
|
+
// Calculate how many tiles we need to cover the viewport
|
|
2993
|
+
const tilesX = Math.ceil(width / (tileSize * scale)) + 2;
|
|
2994
|
+
const tilesY = Math.ceil(height / (tileSize * scale)) + 2;
|
|
2995
|
+
// Calculate the top-left tile
|
|
2996
|
+
const startTileX = Math.floor(centerTile.x - tilesX / 2);
|
|
2997
|
+
const startTileY = Math.floor(centerTile.y - tilesY / 2);
|
|
2998
|
+
// Get tile provider
|
|
2999
|
+
const provider = config.tileProvider || (theme === 'dark' ? 'cartodb-dark' : 'cartodb-light');
|
|
3000
|
+
// Load and draw tiles
|
|
3001
|
+
const tilePromises = [];
|
|
3002
|
+
const maxTile = Math.pow(2, zoomInt);
|
|
3003
|
+
for (let dx = 0; dx < tilesX; dx++) {
|
|
3004
|
+
for (let dy = 0; dy < tilesY; dy++) {
|
|
3005
|
+
let tileX = startTileX + dx;
|
|
3006
|
+
let tileY = startTileY + dy;
|
|
3007
|
+
// Wrap X coordinate
|
|
3008
|
+
while (tileX < 0)
|
|
3009
|
+
tileX += maxTile;
|
|
3010
|
+
while (tileX >= maxTile)
|
|
3011
|
+
tileX -= maxTile;
|
|
3012
|
+
// Skip invalid Y tiles
|
|
3013
|
+
if (tileY < 0 || tileY >= maxTile)
|
|
3014
|
+
continue;
|
|
3015
|
+
const url = getTileUrl(provider, tileX, tileY, zoomInt);
|
|
3016
|
+
// Calculate pixel position for this tile
|
|
3017
|
+
const pixelX = (startTileX + dx - centerTile.x) * tileSize * scale + width / 2;
|
|
3018
|
+
const pixelY = (startTileY + dy - centerTile.y) * tileSize * scale + height / 2;
|
|
3019
|
+
const promise = loadTile(url)
|
|
3020
|
+
.then((img) => {
|
|
3021
|
+
ctx.drawImage(img, pixelX, pixelY, tileSize * scale, tileSize * scale);
|
|
3022
|
+
})
|
|
3023
|
+
.catch(() => {
|
|
3024
|
+
// Draw placeholder for failed tiles
|
|
3025
|
+
ctx.fillStyle = theme === 'dark' ? '#2d2d44' : '#E5E7EB';
|
|
3026
|
+
ctx.fillRect(pixelX, pixelY, tileSize * scale, tileSize * scale);
|
|
3027
|
+
});
|
|
3028
|
+
tilePromises.push(promise);
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
// After all tiles are loaded, draw points on top
|
|
3032
|
+
Promise.all(tilePromises).then(() => {
|
|
3033
|
+
// Draw points
|
|
3034
|
+
const opacity = config.pointOpacity || 0.8;
|
|
3035
|
+
points.forEach((point) => {
|
|
3036
|
+
const pos = latLngToPixel(point.lat, point.lng, center, zoom, width, height);
|
|
3037
|
+
// Skip points outside viewport
|
|
3038
|
+
if (pos.x < -50 || pos.x > width + 50 || pos.y < -50 || pos.y > height + 50) {
|
|
3039
|
+
return;
|
|
3040
|
+
}
|
|
3041
|
+
const pointSize = point.size ?? 6;
|
|
3042
|
+
const pointColor = point.color ?? '#3B82F6';
|
|
3043
|
+
ctx.beginPath();
|
|
3044
|
+
ctx.arc(pos.x, pos.y, pointSize, 0, Math.PI * 2);
|
|
3045
|
+
// Parse color and add opacity
|
|
3046
|
+
const hexColor = pointColor.startsWith('#') ? pointColor : '#3B82F6';
|
|
3047
|
+
const r = parseInt(hexColor.slice(1, 3), 16);
|
|
3048
|
+
const g = parseInt(hexColor.slice(3, 5), 16);
|
|
3049
|
+
const b = parseInt(hexColor.slice(5, 7), 16);
|
|
3050
|
+
ctx.fillStyle = `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
3051
|
+
ctx.fill();
|
|
3052
|
+
// Draw border
|
|
3053
|
+
ctx.strokeStyle = theme === 'dark' ? 'rgba(255,255,255,0.5)' : 'rgba(0,0,0,0.3)';
|
|
3054
|
+
ctx.lineWidth = 1.5;
|
|
3055
|
+
ctx.stroke();
|
|
3056
|
+
});
|
|
3057
|
+
});
|
|
3058
|
+
}, [dimensions, points, center, zoom, theme, config.pointOpacity, config.tileProvider]);
|
|
3059
|
+
// Mouse event handlers for panning
|
|
3060
|
+
const handleMouseDown = useCallback((e) => {
|
|
3061
|
+
setIsDragging(true);
|
|
3062
|
+
dragStart.current = { x: e.clientX, y: e.clientY, center: [...center] };
|
|
3063
|
+
}, [center]);
|
|
3064
|
+
const handleMouseMove = useCallback((e) => {
|
|
3065
|
+
if (!isDragging || !dragStart.current)
|
|
3066
|
+
return;
|
|
3067
|
+
const dx = e.clientX - dragStart.current.x;
|
|
3068
|
+
const dy = e.clientY - dragStart.current.y;
|
|
3069
|
+
// Convert pixel delta to lat/lng delta
|
|
3070
|
+
const scale = Math.pow(2, zoom) * 256;
|
|
3071
|
+
const lngDelta = (-dx / scale) * 360;
|
|
3072
|
+
const latDelta = (dy / scale) * 180;
|
|
3073
|
+
setCenter([
|
|
3074
|
+
Math.max(-85, Math.min(85, dragStart.current.center[0] + latDelta)),
|
|
3075
|
+
dragStart.current.center[1] + lngDelta,
|
|
3076
|
+
]);
|
|
3077
|
+
}, [isDragging, zoom]);
|
|
3078
|
+
const handleMouseUp = useCallback(() => {
|
|
3079
|
+
setIsDragging(false);
|
|
3080
|
+
dragStart.current = null;
|
|
3081
|
+
}, []);
|
|
3082
|
+
const handleWheel = useCallback((e) => {
|
|
3083
|
+
e.preventDefault();
|
|
3084
|
+
const delta = e.deltaY > 0 ? -0.5 : 0.5;
|
|
3085
|
+
setZoom((z) => Math.max(1, Math.min(18, z + delta)));
|
|
3086
|
+
}, []);
|
|
3087
|
+
// Zoom controls
|
|
3088
|
+
const handleZoomIn = useCallback(() => {
|
|
3089
|
+
setZoom((z) => Math.min(18, z + 1));
|
|
3090
|
+
}, []);
|
|
3091
|
+
const handleZoomOut = useCallback(() => {
|
|
3092
|
+
setZoom((z) => Math.max(1, z - 1));
|
|
3093
|
+
}, []);
|
|
3094
|
+
const buttonStyle = {
|
|
3095
|
+
width: '32px',
|
|
3096
|
+
height: '32px',
|
|
3097
|
+
display: 'flex',
|
|
3098
|
+
alignItems: 'center',
|
|
3099
|
+
justifyContent: 'center',
|
|
3100
|
+
backgroundColor: theme === 'dark' ? '#374151' : '#FFFFFF',
|
|
3101
|
+
color: theme === 'dark' ? '#F3F4F6' : '#1F2937',
|
|
3102
|
+
border: `1px solid ${theme === 'dark' ? '#4B5563' : '#E5E7EB'}`,
|
|
3103
|
+
borderRadius: '4px',
|
|
3104
|
+
cursor: 'pointer',
|
|
3105
|
+
fontSize: '18px',
|
|
3106
|
+
fontWeight: 'bold',
|
|
3107
|
+
};
|
|
3108
|
+
return (jsxRuntimeExports.jsxs("div", { ref: containerRef, className: className, style: {
|
|
3109
|
+
width: '100%',
|
|
3110
|
+
height: '100%',
|
|
3111
|
+
position: 'relative',
|
|
3112
|
+
overflow: 'hidden',
|
|
3113
|
+
backgroundColor: theme === 'dark' ? '#1F2937' : '#F3F4F6',
|
|
3114
|
+
...style,
|
|
3115
|
+
}, "data-testid": "geo-chart", children: [jsxRuntimeExports.jsx("canvas", { ref: canvasRef, style: {
|
|
3116
|
+
width: '100%',
|
|
3117
|
+
height: '100%',
|
|
3118
|
+
cursor: isDragging ? 'grabbing' : 'grab',
|
|
3119
|
+
}, onMouseDown: handleMouseDown, onMouseMove: handleMouseMove, onMouseUp: handleMouseUp, onMouseLeave: handleMouseUp, onWheel: handleWheel }), config.showZoomControl !== false && (jsxRuntimeExports.jsxs("div", { style: {
|
|
3120
|
+
position: 'absolute',
|
|
3121
|
+
top: '10px',
|
|
3122
|
+
right: '10px',
|
|
3123
|
+
display: 'flex',
|
|
3124
|
+
flexDirection: 'column',
|
|
3125
|
+
gap: '4px',
|
|
3126
|
+
}, children: [jsxRuntimeExports.jsx("button", { style: buttonStyle, onClick: handleZoomIn, children: "+" }), jsxRuntimeExports.jsx("button", { style: buttonStyle, onClick: handleZoomOut, children: "\u2212" })] })), config.showCenterDisplay && (jsxRuntimeExports.jsxs("div", { style: {
|
|
3127
|
+
position: 'absolute',
|
|
3128
|
+
bottom: '10px',
|
|
3129
|
+
left: '10px',
|
|
3130
|
+
padding: '4px 8px',
|
|
3131
|
+
backgroundColor: theme === 'dark' ? 'rgba(55, 65, 81, 0.9)' : 'rgba(255, 255, 255, 0.9)',
|
|
3132
|
+
color: theme === 'dark' ? '#F3F4F6' : '#1F2937',
|
|
3133
|
+
borderRadius: '4px',
|
|
3134
|
+
fontSize: '12px',
|
|
3135
|
+
fontFamily: 'monospace',
|
|
3136
|
+
}, children: [center[0].toFixed(4), ", ", center[1].toFixed(4), " | Zoom: ", zoom.toFixed(1)] })), jsxRuntimeExports.jsxs("div", { style: {
|
|
3137
|
+
position: 'absolute',
|
|
3138
|
+
bottom: '10px',
|
|
3139
|
+
right: '10px',
|
|
3140
|
+
padding: '4px 8px',
|
|
3141
|
+
backgroundColor: theme === 'dark' ? 'rgba(55, 65, 81, 0.9)' : 'rgba(255, 255, 255, 0.9)',
|
|
3142
|
+
color: theme === 'dark' ? '#9CA3AF' : '#6B7280',
|
|
3143
|
+
borderRadius: '4px',
|
|
3144
|
+
fontSize: '12px',
|
|
3145
|
+
}, children: [points.length, " points"] }), points.length === 0 && (jsxRuntimeExports.jsxs("div", { style: {
|
|
3146
|
+
position: 'absolute',
|
|
3147
|
+
top: '50%',
|
|
3148
|
+
left: '50%',
|
|
3149
|
+
transform: 'translate(-50%, -50%)',
|
|
3150
|
+
display: 'flex',
|
|
3151
|
+
flexDirection: 'column',
|
|
3152
|
+
alignItems: 'center',
|
|
3153
|
+
gap: '8px',
|
|
3154
|
+
color: theme === 'dark' ? '#9CA3AF' : '#6B7280',
|
|
3155
|
+
}, children: [jsxRuntimeExports.jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { animation: 'spin 1s linear infinite' }, children: [jsxRuntimeExports.jsx("circle", { cx: "12", cy: "12", r: "10", strokeOpacity: "0.25" }), jsxRuntimeExports.jsx("path", { d: "M12 2a10 10 0 0 1 10 10", strokeLinecap: "round" })] }), jsxRuntimeExports.jsx("span", { children: "Waiting for data..." }), jsxRuntimeExports.jsx("style", { children: `@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }` })] }))] }));
|
|
3156
|
+
};
|
|
3157
|
+
|
|
3158
|
+
/**
|
|
3159
|
+
* Core chart utilities and base functionality
|
|
3160
|
+
*/
|
|
3161
|
+
// Chart axis configuration constants
|
|
3162
|
+
const AXIS_HEIGHT_WITH_TITLE = 70;
|
|
3163
|
+
const AXIS_HEIGHT_WITHOUT_TITLE = 40;
|
|
3164
|
+
const MAX_LEGEND_ITEMS = 30;
|
|
3165
|
+
/**
|
|
3166
|
+
* Horizontal axis label transformation configuration
|
|
3167
|
+
*/
|
|
3168
|
+
const horizontalAxisLabelConfig = {
|
|
3169
|
+
labelAutoHide: {
|
|
3170
|
+
type: 'hide',
|
|
3171
|
+
keepHeader: true,
|
|
3172
|
+
keepTail: true,
|
|
3173
|
+
},
|
|
3174
|
+
labelAutoRotate: false,
|
|
3175
|
+
labelAutoEllipsis: {
|
|
3176
|
+
type: 'ellipsis',
|
|
3177
|
+
minLength: 100,
|
|
3178
|
+
maxLength: 150,
|
|
3179
|
+
},
|
|
3180
|
+
};
|
|
3181
|
+
/**
|
|
3182
|
+
* Vertical axis label transformation configuration
|
|
3183
|
+
*/
|
|
3184
|
+
const verticalAxisLabelConfig = {
|
|
3185
|
+
transform: [
|
|
3186
|
+
{
|
|
3187
|
+
margin: [1, 1, 1, 1],
|
|
3188
|
+
type: 'hide',
|
|
3189
|
+
},
|
|
3190
|
+
],
|
|
3191
|
+
};
|
|
3192
|
+
/**
|
|
3193
|
+
* Apply color encoding to a chart mark
|
|
3194
|
+
*/
|
|
3195
|
+
function applyColorEncoding(node, config) {
|
|
3196
|
+
const { values, keyColor } = config.colors;
|
|
3197
|
+
const domain = config.domain ?? [];
|
|
3198
|
+
// Generate colors for each domain value
|
|
3199
|
+
const colorRange = domain.map((_, index) => {
|
|
3200
|
+
const color = values[index % values.length];
|
|
3201
|
+
// Apply transparency if there's an active selection and this isn't it
|
|
3202
|
+
if (config.activeIndex !== undefined && config.activeIndex >= 0) {
|
|
3203
|
+
return index === config.activeIndex ? color : `${color}30`;
|
|
3204
|
+
}
|
|
3205
|
+
return color;
|
|
3206
|
+
});
|
|
3207
|
+
if (config.zIndex >= 0) {
|
|
3208
|
+
return node.encode('color', `${config.zIndex}`).scale('color', {
|
|
3209
|
+
type: 'ordinal',
|
|
3210
|
+
domain,
|
|
3211
|
+
range: colorRange,
|
|
3212
|
+
});
|
|
3213
|
+
}
|
|
3214
|
+
// Single color mode based on mark type
|
|
3215
|
+
switch (node.type) {
|
|
3216
|
+
case 'area':
|
|
3217
|
+
return node.style('stroke', values[keyColor]).style('fill', values[keyColor]);
|
|
3218
|
+
case 'line':
|
|
3219
|
+
return node.style('stroke', values[keyColor]);
|
|
3220
|
+
case 'interval':
|
|
3221
|
+
return node.style('fill', values[keyColor]);
|
|
3222
|
+
case 'point':
|
|
3223
|
+
return node.style('stroke', values[keyColor]);
|
|
3224
|
+
default:
|
|
3225
|
+
return node;
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
/**
|
|
3229
|
+
* Apply legend configuration to a chart mark
|
|
3230
|
+
*/
|
|
3231
|
+
function applyLegend(node, enabled, onItemClick, values, theme = 'dark') {
|
|
3232
|
+
if (!enabled || !values || values.length > MAX_LEGEND_ITEMS) {
|
|
3233
|
+
return node.legend(false);
|
|
3234
|
+
}
|
|
3235
|
+
const themeColors = getChartThemeColors(theme);
|
|
3236
|
+
return node.legend('color', {
|
|
3237
|
+
position: 'bottom',
|
|
3238
|
+
layout: {
|
|
3239
|
+
justifyContent: 'flex-start',
|
|
3240
|
+
alignItems: 'center',
|
|
3241
|
+
},
|
|
3242
|
+
itemLabelFill: themeColors.text,
|
|
3243
|
+
itemValueFill: themeColors.text,
|
|
3244
|
+
titleFill: themeColors.text,
|
|
3245
|
+
// Additional label styling for G2 5.x
|
|
3246
|
+
label: {
|
|
3247
|
+
fill: themeColors.text,
|
|
3248
|
+
fontSize: 12,
|
|
3249
|
+
},
|
|
3250
|
+
itemLabel: {
|
|
3251
|
+
style: {
|
|
3252
|
+
fill: themeColors.text,
|
|
3253
|
+
fontSize: 12,
|
|
3254
|
+
},
|
|
3255
|
+
},
|
|
3256
|
+
itemName: {
|
|
3257
|
+
style: {
|
|
3258
|
+
fill: themeColors.text,
|
|
3259
|
+
},
|
|
3260
|
+
},
|
|
3261
|
+
click: onItemClick
|
|
3262
|
+
? (e) => {
|
|
3263
|
+
const index = e?.__data__?.index;
|
|
3264
|
+
if (index !== undefined) {
|
|
3265
|
+
onItemClick(index);
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
: undefined,
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
/**
|
|
3272
|
+
* Apply data label configuration to a chart mark
|
|
3273
|
+
*/
|
|
3274
|
+
function applyDataLabel(node, config) {
|
|
3275
|
+
if (!config.enabled)
|
|
3276
|
+
return node;
|
|
3277
|
+
const { unit, yIndex, fractionDigits = 0, showAll = false, textAlign = 'center', textBaseline = 'alphabetic' } = config;
|
|
3278
|
+
return node.label({
|
|
3279
|
+
textAlign,
|
|
3280
|
+
textBaseline,
|
|
3281
|
+
text: (d) => {
|
|
3282
|
+
const v = Number.parseFloat(String(d?.[yIndex] ?? 0)).toFixed(fractionDigits);
|
|
3283
|
+
if (unit?.position === 'right') {
|
|
3284
|
+
return `${v}${unit.value}`;
|
|
3285
|
+
}
|
|
3286
|
+
return `${unit?.value ?? ''}${v}`;
|
|
3287
|
+
},
|
|
3288
|
+
transform: [{ type: 'overlapHide' }],
|
|
3289
|
+
...(showAll ? {} : { selector: 'last' }),
|
|
3290
|
+
});
|
|
3291
|
+
}
|
|
3292
|
+
/**
|
|
3293
|
+
* Truncate label with ellipsis
|
|
3294
|
+
*/
|
|
3295
|
+
function truncateLabel(value, maxChar) {
|
|
3296
|
+
if (maxChar === null || !value)
|
|
3297
|
+
return value;
|
|
3298
|
+
const result = value.slice(0, maxChar);
|
|
3299
|
+
return result === value ? result : `${result}...`;
|
|
3300
|
+
}
|
|
3301
|
+
/**
|
|
3302
|
+
* Render chart with standard interactions
|
|
3303
|
+
*/
|
|
3304
|
+
async function renderChart(chart, theme = 'dark') {
|
|
3305
|
+
const themeColors = getChartThemeColors(theme);
|
|
3306
|
+
chart.interaction('tooltip', {
|
|
3307
|
+
mount: document.body,
|
|
3308
|
+
css: {
|
|
3309
|
+
'.g2-tooltip': {
|
|
3310
|
+
'z-index': '10000',
|
|
3311
|
+
'background-color': 'rgba(0, 0, 0, 0.8)',
|
|
3312
|
+
color: '#fff',
|
|
3313
|
+
'border-radius': '4px',
|
|
3314
|
+
padding: '8px 12px',
|
|
3315
|
+
'font-size': '12px',
|
|
3316
|
+
},
|
|
3317
|
+
},
|
|
3318
|
+
});
|
|
3319
|
+
chart.interaction('legendFilter', false);
|
|
3320
|
+
await chart.render();
|
|
3321
|
+
// Apply CSS-based legend text styling after render
|
|
3322
|
+
// This ensures legend text is visible regardless of G2's default styling
|
|
3323
|
+
const container = chart.getContainer();
|
|
3324
|
+
if (container) {
|
|
3325
|
+
// Query for legend text elements using various possible selectors
|
|
3326
|
+
const legendSelectors = [
|
|
3327
|
+
'g[class*="bindClick"] text',
|
|
3328
|
+
'g[class*="bindChange"] text',
|
|
3329
|
+
'g[class*="legend"] text',
|
|
3330
|
+
'g[class*="Legend"] text',
|
|
3331
|
+
// G2 5.x legend item selectors
|
|
3332
|
+
'[class*="category"] text',
|
|
3333
|
+
'[class*="item-label"] text',
|
|
3334
|
+
'[class*="itemLabel"] text',
|
|
3335
|
+
];
|
|
3336
|
+
legendSelectors.forEach((selector) => {
|
|
3337
|
+
try {
|
|
3338
|
+
const elements = container.querySelectorAll(selector);
|
|
3339
|
+
elements.forEach((el) => {
|
|
3340
|
+
if (el instanceof SVGElement) {
|
|
3341
|
+
el.setAttribute('fill', themeColors.text);
|
|
3342
|
+
}
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3345
|
+
catch {
|
|
3346
|
+
// Ignore invalid selectors
|
|
3347
|
+
}
|
|
3348
|
+
});
|
|
3349
|
+
// Also inject a style element for broader coverage
|
|
3350
|
+
const styleId = 'vistral-legend-style';
|
|
3351
|
+
let styleEl = container.querySelector(`#${styleId}`);
|
|
3352
|
+
if (!styleEl) {
|
|
3353
|
+
styleEl = document.createElement('style');
|
|
3354
|
+
styleEl.id = styleId;
|
|
3355
|
+
container.appendChild(styleEl);
|
|
3356
|
+
}
|
|
3357
|
+
styleEl.textContent = `
|
|
3358
|
+
g[bindClick] text,
|
|
3359
|
+
g[bindChange] text,
|
|
3360
|
+
[class*="legend"] text,
|
|
3361
|
+
[class*="Legend"] text {
|
|
3362
|
+
fill: ${themeColors.text} !important;
|
|
3363
|
+
}
|
|
3364
|
+
`;
|
|
3365
|
+
}
|
|
3366
|
+
}
|
|
3367
|
+
/**
|
|
3368
|
+
* Configure tooltip for a chart mark
|
|
3369
|
+
*/
|
|
3370
|
+
function applyTooltip(node, enabled, config) {
|
|
3371
|
+
if (!enabled) {
|
|
3372
|
+
return node.tooltip(false);
|
|
3373
|
+
}
|
|
3374
|
+
const { xIndex, yIndex, zIndex = -1, zValues = [], colors, fractionDigits = 0, yLabel = '' } = config;
|
|
3375
|
+
return node.tooltip({
|
|
3376
|
+
title: (d) => String(d[xIndex] ?? ''),
|
|
3377
|
+
items: [
|
|
3378
|
+
(d) => {
|
|
3379
|
+
const colorValueIndex = zValues.indexOf(String(d[zIndex] ?? ''));
|
|
3380
|
+
const color = colors.values[colorValueIndex % colors.values.length] ?? colors.values[0];
|
|
3381
|
+
return {
|
|
3382
|
+
name: zIndex >= 0 ? String(d[zIndex]) : yLabel,
|
|
3383
|
+
value: Number.parseFloat(String(d[yIndex] ?? 0)).toFixed(fractionDigits),
|
|
3384
|
+
color,
|
|
3385
|
+
};
|
|
3386
|
+
},
|
|
3387
|
+
],
|
|
3388
|
+
});
|
|
3389
|
+
}
|
|
3390
|
+
/**
|
|
3391
|
+
* Create default chart configuration based on data source
|
|
3392
|
+
*/
|
|
3393
|
+
function createDefaultConfig(source, chartType) {
|
|
3394
|
+
const { header, x, y, z } = source;
|
|
3395
|
+
const baseConfig = {
|
|
3396
|
+
chartType,
|
|
3397
|
+
xAxis: x.index >= 0 ? header[x.index].name : '',
|
|
3398
|
+
yAxis: y.index >= 0 ? header[y.index].name : '',
|
|
3399
|
+
color: z.index >= 0 ? header[z.index].name : '',
|
|
3400
|
+
colors: DEFAULT_PALETTE.values,
|
|
3401
|
+
};
|
|
3402
|
+
switch (chartType) {
|
|
3403
|
+
case 'line':
|
|
3404
|
+
case 'area':
|
|
3405
|
+
return {
|
|
3406
|
+
...baseConfig,
|
|
3407
|
+
xTitle: '',
|
|
3408
|
+
yTitle: '',
|
|
3409
|
+
legend: z.values.length > 0,
|
|
3410
|
+
dataLabel: false,
|
|
3411
|
+
gridlines: false,
|
|
3412
|
+
points: false,
|
|
3413
|
+
lineStyle: 'curve',
|
|
3414
|
+
fractionDigits: 2,
|
|
3415
|
+
xRange: 'Infinity',
|
|
3416
|
+
yRange: { min: null, max: null },
|
|
3417
|
+
};
|
|
3418
|
+
case 'bar':
|
|
3419
|
+
case 'column':
|
|
3420
|
+
return {
|
|
3421
|
+
...baseConfig,
|
|
3422
|
+
xTitle: '',
|
|
3423
|
+
yTitle: '',
|
|
3424
|
+
legend: z.values.length > 0,
|
|
3425
|
+
dataLabel: false,
|
|
3426
|
+
gridlines: false,
|
|
3427
|
+
fractionDigits: 2,
|
|
3428
|
+
groupType: 'stack',
|
|
3429
|
+
};
|
|
3430
|
+
case 'singleValue':
|
|
3431
|
+
return {
|
|
3432
|
+
chartType,
|
|
3433
|
+
yAxis: y.index >= 0 ? header[y.index].name : '',
|
|
3434
|
+
fontSize: 64,
|
|
3435
|
+
color: 'blue',
|
|
3436
|
+
fractionDigits: 2,
|
|
3437
|
+
sparkline: false,
|
|
3438
|
+
delta: false,
|
|
3439
|
+
};
|
|
3440
|
+
default:
|
|
3441
|
+
return baseConfig;
|
|
3442
|
+
}
|
|
3443
|
+
}
|
|
3444
|
+
/**
|
|
3445
|
+
* Get theme colors for charts
|
|
3446
|
+
*/
|
|
3447
|
+
function getChartThemeColors(theme) {
|
|
3448
|
+
return theme === 'dark'
|
|
3449
|
+
? {
|
|
3450
|
+
text: '#E5E5E5', // Matches darkTheme.textColor
|
|
3451
|
+
textSecondary: '#9CA3AF',
|
|
3452
|
+
line: '#6B7280', // Matches darkTheme.axisColor (was #374151 which is very dark)
|
|
3453
|
+
gridline: '#374151', // Matches darkTheme.gridColor
|
|
3454
|
+
background: 'transparent',
|
|
3455
|
+
}
|
|
3456
|
+
: {
|
|
3457
|
+
text: '#000000',
|
|
3458
|
+
textSecondary: '#374151',
|
|
3459
|
+
line: '#4B5563',
|
|
3460
|
+
gridline: '#9CA3AF',
|
|
3461
|
+
background: 'transparent',
|
|
3462
|
+
};
|
|
3463
|
+
}
|
|
3464
|
+
/**
|
|
3465
|
+
* Apply chart theme
|
|
3466
|
+
*/
|
|
3467
|
+
function applyChartTheme(chart, theme = 'dark') {
|
|
3468
|
+
const colors = getChartThemeColors(theme);
|
|
3469
|
+
const themeConfig = {
|
|
3470
|
+
view: { viewFill: colors.background },
|
|
3471
|
+
// Data labels on points/bars
|
|
3472
|
+
label: {
|
|
3473
|
+
fill: colors.text,
|
|
3474
|
+
fontSize: 11,
|
|
3475
|
+
},
|
|
3476
|
+
// Axis configuration
|
|
3477
|
+
axis: {
|
|
3478
|
+
x: {
|
|
3479
|
+
line: { stroke: colors.line },
|
|
3480
|
+
tick: { stroke: colors.line },
|
|
3481
|
+
label: { fill: colors.text, fontSize: 11 },
|
|
3482
|
+
title: { fill: colors.text, fontSize: 12, fontWeight: 500 },
|
|
3483
|
+
grid: { stroke: colors.gridline },
|
|
3484
|
+
},
|
|
3485
|
+
y: {
|
|
3486
|
+
line: { stroke: colors.line },
|
|
3487
|
+
tick: { stroke: colors.line },
|
|
3488
|
+
label: { fill: colors.text, fontSize: 11 },
|
|
3489
|
+
title: { fill: colors.text, fontSize: 12, fontWeight: 500 },
|
|
3490
|
+
grid: { stroke: colors.gridline },
|
|
3491
|
+
},
|
|
3492
|
+
},
|
|
3493
|
+
// Legend configuration
|
|
3494
|
+
legend: {
|
|
3495
|
+
label: { fill: colors.text, fontSize: 12 },
|
|
3496
|
+
title: { fill: colors.text, fontSize: 12 },
|
|
3497
|
+
marker: { size: 8 },
|
|
3498
|
+
itemLabel: { fill: colors.text, fontSize: 12 },
|
|
3499
|
+
itemName: { fill: colors.text, fontSize: 12 },
|
|
3500
|
+
itemValue: { fill: colors.textSecondary, fontSize: 12 },
|
|
3501
|
+
},
|
|
3502
|
+
// Legend category specific
|
|
3503
|
+
legendCategory: {
|
|
3504
|
+
itemLabel: { fill: colors.text },
|
|
3505
|
+
itemName: { fill: colors.text },
|
|
3506
|
+
},
|
|
3507
|
+
// Title configuration
|
|
3508
|
+
title: {
|
|
3509
|
+
fill: colors.text,
|
|
3510
|
+
fontSize: 14,
|
|
3511
|
+
fontWeight: 600,
|
|
3512
|
+
},
|
|
3513
|
+
};
|
|
3514
|
+
chart.theme(themeConfig);
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3518
|
+
/**
|
|
3519
|
+
* Spec Engine — converts VistralSpec + data into renderable configuration.
|
|
3520
|
+
*
|
|
3521
|
+
* This module is the heart of the declarative pipeline. It takes a
|
|
3522
|
+
* VistralSpec and the current data snapshot and produces transforms,
|
|
3523
|
+
* scales, and other derived configuration that downstream renderers
|
|
3524
|
+
* (e.g. AntV G2) can consume.
|
|
3525
|
+
*/
|
|
3526
|
+
// ---------------------------------------------------------------------------
|
|
3527
|
+
// Helpers
|
|
3528
|
+
// ---------------------------------------------------------------------------
|
|
3529
|
+
/**
|
|
3530
|
+
* Returns the maximum parsed timestamp across all rows for the given field.
|
|
3531
|
+
* If data is empty, returns `Date.now()` as a sensible fallback.
|
|
3532
|
+
*/
|
|
3533
|
+
function getMaxTimestamp(data, field) {
|
|
3534
|
+
if (data.length === 0)
|
|
3535
|
+
return Date.now();
|
|
3536
|
+
let max = -Infinity;
|
|
3537
|
+
for (const row of data) {
|
|
3538
|
+
const ts = parseDateTime(row[field]);
|
|
3539
|
+
if (ts > max) {
|
|
3540
|
+
max = ts;
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
return max === -Infinity ? Date.now() : max;
|
|
3544
|
+
}
|
|
3545
|
+
// ---------------------------------------------------------------------------
|
|
3546
|
+
// G2 Spec Translation
|
|
3547
|
+
// ---------------------------------------------------------------------------
|
|
3548
|
+
/**
|
|
3549
|
+
* Translate a CoordinateSpec to G2 format.
|
|
3550
|
+
* Renames `transforms` to `transform`.
|
|
3551
|
+
*/
|
|
3552
|
+
function translateCoordinate(coord) {
|
|
3553
|
+
const { transforms, ...rest } = coord;
|
|
3554
|
+
const result = { ...rest };
|
|
3555
|
+
if (transforms) {
|
|
3556
|
+
result.transform = transforms;
|
|
3557
|
+
}
|
|
3558
|
+
return result;
|
|
3559
|
+
}
|
|
3560
|
+
/**
|
|
3561
|
+
* Translate an AxisChannelSpec to G2 axis channel format.
|
|
3562
|
+
*/
|
|
3563
|
+
function translateAxisChannel(axis, colors) {
|
|
3564
|
+
const result = {};
|
|
3565
|
+
if (axis.title !== undefined) {
|
|
3566
|
+
result.title = axis.title;
|
|
3567
|
+
result.titleFill = colors.text;
|
|
3568
|
+
result.titleFillOpacity = 1;
|
|
3569
|
+
}
|
|
3570
|
+
if (axis.grid !== undefined) {
|
|
3571
|
+
result.grid = axis.grid;
|
|
3572
|
+
result.gridStroke = colors.gridline;
|
|
3573
|
+
result.gridStrokeOpacity = 1;
|
|
3574
|
+
}
|
|
3575
|
+
if (axis.line !== undefined) {
|
|
3576
|
+
result.line = axis.line;
|
|
3577
|
+
result.lineStroke = colors.line;
|
|
3578
|
+
result.lineStrokeOpacity = 1;
|
|
3579
|
+
}
|
|
3580
|
+
// Force tick visibility and color
|
|
3581
|
+
result.tick = true;
|
|
3582
|
+
result.tickStroke = colors.line;
|
|
3583
|
+
result.tickStrokeOpacity = 1;
|
|
3584
|
+
// Force label color
|
|
3585
|
+
result.labelFill = colors.text;
|
|
3586
|
+
result.labelFillOpacity = 1;
|
|
3587
|
+
if (axis.labels) {
|
|
3588
|
+
if (axis.labels.format !== undefined) {
|
|
3589
|
+
result.labelFormatter = axis.labels.format;
|
|
3590
|
+
}
|
|
3591
|
+
if (axis.labels.rotate !== undefined) {
|
|
3592
|
+
result.labelTransform = [{ type: 'rotate', angle: axis.labels.rotate }];
|
|
3593
|
+
}
|
|
3594
|
+
}
|
|
3595
|
+
return result;
|
|
3596
|
+
}
|
|
3597
|
+
/**
|
|
3598
|
+
* Translate AxesSpec to G2 axis format.
|
|
3599
|
+
*/
|
|
3600
|
+
function translateAxes(axes, theme = 'dark') {
|
|
3601
|
+
const result = {};
|
|
3602
|
+
const colors = getChartThemeColors(theme);
|
|
3603
|
+
for (const channel of ['x', 'y']) {
|
|
3604
|
+
const value = axes[channel];
|
|
3605
|
+
if (value === undefined)
|
|
3606
|
+
continue;
|
|
3607
|
+
if (value === false) {
|
|
3608
|
+
result[channel] = false;
|
|
3609
|
+
}
|
|
3610
|
+
else {
|
|
3611
|
+
result[channel] = translateAxisChannel(value, colors);
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
return result;
|
|
3615
|
+
}
|
|
3616
|
+
/**
|
|
3617
|
+
* Translate a LabelSpec to G2 label format.
|
|
3618
|
+
* Converts `overlapHide` to `transform: [{ type: 'overlapHide' }]`.
|
|
3619
|
+
*/
|
|
3620
|
+
function translateLabel(label) {
|
|
3621
|
+
const { overlapHide, ...rest } = label;
|
|
3622
|
+
const result = { ...rest };
|
|
3623
|
+
if (overlapHide) {
|
|
3624
|
+
result.transform = [{ type: 'overlapHide' }];
|
|
3625
|
+
}
|
|
3626
|
+
return result;
|
|
3627
|
+
}
|
|
3628
|
+
/**
|
|
3629
|
+
* Translate an AnnotationSpec to a G2 child entry.
|
|
3630
|
+
*/
|
|
3631
|
+
function translateAnnotation(annotation) {
|
|
3632
|
+
const child = {
|
|
3633
|
+
type: annotation.type,
|
|
3634
|
+
};
|
|
3635
|
+
if (annotation.encode) {
|
|
3636
|
+
child.encode = annotation.encode;
|
|
3637
|
+
}
|
|
3638
|
+
if (annotation.style) {
|
|
3639
|
+
child.style = annotation.style;
|
|
3640
|
+
}
|
|
3641
|
+
if (annotation.value !== undefined) {
|
|
3642
|
+
child.data = [annotation.value];
|
|
3643
|
+
}
|
|
3644
|
+
if (annotation.label !== undefined) {
|
|
3645
|
+
child.labels = [{ text: annotation.label }];
|
|
3646
|
+
}
|
|
3647
|
+
return child;
|
|
3648
|
+
}
|
|
3649
|
+
/**
|
|
3650
|
+
* Translate a single MarkSpec to a G2 child entry.
|
|
3651
|
+
*/
|
|
3652
|
+
function translateMark(mark, spec) {
|
|
3653
|
+
const child = {
|
|
3654
|
+
type: mark.type,
|
|
3655
|
+
};
|
|
3656
|
+
// Encode
|
|
3657
|
+
if (mark.encode) {
|
|
3658
|
+
child.encode = { ...mark.encode };
|
|
3659
|
+
}
|
|
3660
|
+
// Scale: merge top-level scales with per-mark scales (per-mark wins)
|
|
3661
|
+
const topScales = spec.scales ?? {};
|
|
3662
|
+
const markScales = mark.scales ?? {};
|
|
3663
|
+
const mergedScales = { ...topScales, ...markScales };
|
|
3664
|
+
// --- Interval Mark Safety ---
|
|
3665
|
+
// If the mark is 'interval' (bar/column), G2 strictly requires a 'band' scale
|
|
3666
|
+
// for the categorical axis to calculate bandwidth. 'ordinal' (point) scales cause crashes.
|
|
3667
|
+
if (mark.type === 'interval') {
|
|
3668
|
+
// Detect which axis is likely categorical (band).
|
|
3669
|
+
// Usually X for column chart, Y for bar chart.
|
|
3670
|
+
// Heuristic: check if the scale type is explicitly 'ordinal'.
|
|
3671
|
+
for (const channel in mergedScales) {
|
|
3672
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
3673
|
+
if (mergedScales.hasOwnProperty(channel)) {
|
|
3674
|
+
const sc = mergedScales[channel];
|
|
3675
|
+
if (sc?.type === 'ordinal') {
|
|
3676
|
+
// Coerce to 'band'
|
|
3677
|
+
mergedScales[channel] = { ...sc, type: 'band' };
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
if (Object.keys(mergedScales).length > 0) {
|
|
3683
|
+
child.scale = mergedScales;
|
|
3684
|
+
}
|
|
3685
|
+
// Transforms: prepend top-level transforms before mark transforms
|
|
3686
|
+
const topTransforms = spec.transforms ?? [];
|
|
3687
|
+
const markTransforms = mark.transforms ?? [];
|
|
3688
|
+
const allTransforms = [...topTransforms, ...markTransforms];
|
|
3689
|
+
if (allTransforms.length > 0) {
|
|
3690
|
+
child.transform = allTransforms;
|
|
3691
|
+
}
|
|
3692
|
+
// Style
|
|
3693
|
+
if (mark.style) {
|
|
3694
|
+
child.style = mark.style;
|
|
3695
|
+
}
|
|
3696
|
+
// Labels
|
|
3697
|
+
if (mark.labels) {
|
|
3698
|
+
child.labels = mark.labels.map(translateLabel);
|
|
3699
|
+
}
|
|
3700
|
+
// Tooltip
|
|
3701
|
+
if (mark.tooltip !== undefined) {
|
|
3702
|
+
child.tooltip = mark.tooltip === false ? false : mark.tooltip;
|
|
3703
|
+
}
|
|
3704
|
+
// Animate: per-mark overrides top-level
|
|
3705
|
+
const animate = mark.animate ?? spec.animate;
|
|
3706
|
+
if (animate !== undefined) {
|
|
3707
|
+
child.animate = animate;
|
|
3708
|
+
}
|
|
3709
|
+
return child;
|
|
3710
|
+
}
|
|
3711
|
+
// ---------------------------------------------------------------------------
|
|
3712
|
+
// Public API
|
|
3713
|
+
// ---------------------------------------------------------------------------
|
|
3714
|
+
/**
|
|
3715
|
+
* Translate a VistralSpec into a G2-compatible options object.
|
|
3716
|
+
*
|
|
3717
|
+
* This is a **pure function** — no G2 imports, no DOM access, no side effects.
|
|
3718
|
+
* It produces a plain object that can be handed to `chart.options(result)`.
|
|
3719
|
+
*/
|
|
3720
|
+
function translateToG2Spec(spec) {
|
|
3721
|
+
const g2 = {
|
|
3722
|
+
type: 'view',
|
|
3723
|
+
};
|
|
3724
|
+
// Pre-analysis for Horizontal Bar Chart (Interval with X=Continuous, Y=Discrete)
|
|
3725
|
+
let shouldSwapAxes = false;
|
|
3726
|
+
if (!spec.coordinate) {
|
|
3727
|
+
const topScales = spec.scales ?? {};
|
|
3728
|
+
for (const mark of spec.marks) {
|
|
3729
|
+
if (mark.type === 'interval') {
|
|
3730
|
+
const markScales = mark.scales ?? {};
|
|
3731
|
+
const mergedScales = { ...topScales, ...markScales };
|
|
3732
|
+
const xScaleType = mergedScales.x?.type || 'linear';
|
|
3733
|
+
const yScaleType = mergedScales.y?.type || 'linear';
|
|
3734
|
+
const isXContinuous = ['linear', 'time', 'log', 'pow', 'sqrt'].includes(xScaleType);
|
|
3735
|
+
// check 'ordinal' too because we coerce it later, but here we detect intent
|
|
3736
|
+
const isYDiscrete = ['band', 'ordinal', 'point'].includes(yScaleType);
|
|
3737
|
+
if (isXContinuous && isYDiscrete) {
|
|
3738
|
+
shouldSwapAxes = true;
|
|
3739
|
+
break;
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
// Coordinate
|
|
3745
|
+
if (spec.coordinate) {
|
|
3746
|
+
g2.coordinate = translateCoordinate(spec.coordinate);
|
|
3747
|
+
}
|
|
3748
|
+
else if (shouldSwapAxes) {
|
|
3749
|
+
g2.coordinate = { transform: [{ type: 'transpose' }] };
|
|
3750
|
+
}
|
|
3751
|
+
// Axes
|
|
3752
|
+
if (spec.axes) {
|
|
3753
|
+
// If swapping axes, we must swap the axis configuration too
|
|
3754
|
+
const effectiveAxes = shouldSwapAxes
|
|
3755
|
+
? { ...spec.axes, x: spec.axes.y, y: spec.axes.x }
|
|
3756
|
+
: spec.axes;
|
|
3757
|
+
g2.axis = translateAxes(effectiveAxes, spec.theme);
|
|
3758
|
+
}
|
|
3759
|
+
// Legend
|
|
3760
|
+
if (spec.legend !== undefined) {
|
|
3761
|
+
if (spec.legend === false) {
|
|
3762
|
+
g2.legend = false;
|
|
3763
|
+
}
|
|
3764
|
+
else {
|
|
3765
|
+
const colors = getChartThemeColors(spec.theme ?? 'dark');
|
|
3766
|
+
g2.legend = {
|
|
3767
|
+
color: {
|
|
3768
|
+
position: spec.legend.position,
|
|
3769
|
+
// Explicitly inject colors to override G2 defaults/dimming
|
|
3770
|
+
itemLabelFill: colors.text,
|
|
3771
|
+
itemLabelFillOpacity: 1,
|
|
3772
|
+
itemNameFill: colors.text,
|
|
3773
|
+
itemNameFillOpacity: 1,
|
|
3774
|
+
titleFill: colors.text,
|
|
3775
|
+
titleFillOpacity: 1,
|
|
3776
|
+
// G2 5.0+ specific style overrides
|
|
3777
|
+
itemLabel: {
|
|
3778
|
+
fill: colors.text,
|
|
3779
|
+
fillOpacity: 1,
|
|
3780
|
+
fontSize: 12,
|
|
3781
|
+
},
|
|
3782
|
+
itemName: {
|
|
3783
|
+
fill: colors.text,
|
|
3784
|
+
fillOpacity: 1,
|
|
3785
|
+
fontSize: 12,
|
|
3786
|
+
},
|
|
3787
|
+
},
|
|
3788
|
+
};
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
// Interactions: array → object map
|
|
3792
|
+
if (spec.interactions) {
|
|
3793
|
+
const interaction = {};
|
|
3794
|
+
for (const { type, ...options } of spec.interactions) {
|
|
3795
|
+
interaction[type] = options;
|
|
3796
|
+
}
|
|
3797
|
+
g2.interaction = interaction;
|
|
3798
|
+
}
|
|
3799
|
+
// Children: marks + annotations
|
|
3800
|
+
const children = spec.marks.map((mark) => {
|
|
3801
|
+
// If we are swapping axes, we need to swap the mark's encoding and scales
|
|
3802
|
+
// BEFORE passing to translateMark (or inside it).
|
|
3803
|
+
// Let's create a "swapped" mark definition to pass down.
|
|
3804
|
+
if (shouldSwapAxes && mark.type === 'interval') {
|
|
3805
|
+
const swappedMark = { ...mark };
|
|
3806
|
+
// Swap Encodes
|
|
3807
|
+
if (mark.encode) {
|
|
3808
|
+
swappedMark.encode = { ...mark.encode };
|
|
3809
|
+
const oldX = swappedMark.encode.x;
|
|
3810
|
+
const oldY = swappedMark.encode.y;
|
|
3811
|
+
if (oldX)
|
|
3812
|
+
swappedMark.encode.y = oldX;
|
|
3813
|
+
else
|
|
3814
|
+
delete swappedMark.encode.y;
|
|
3815
|
+
if (oldY)
|
|
3816
|
+
swappedMark.encode.x = oldY;
|
|
3817
|
+
else
|
|
3818
|
+
delete swappedMark.encode.x;
|
|
3819
|
+
}
|
|
3820
|
+
// Swap Scales
|
|
3821
|
+
if (mark.scales) {
|
|
3822
|
+
swappedMark.scales = { ...mark.scales };
|
|
3823
|
+
const oldX = swappedMark.scales.x;
|
|
3824
|
+
const oldY = swappedMark.scales.y;
|
|
3825
|
+
if (oldX)
|
|
3826
|
+
swappedMark.scales.y = oldX;
|
|
3827
|
+
else
|
|
3828
|
+
delete swappedMark.scales.y;
|
|
3829
|
+
if (oldY)
|
|
3830
|
+
swappedMark.scales.x = oldY;
|
|
3831
|
+
else
|
|
3832
|
+
delete swappedMark.scales.x;
|
|
3833
|
+
}
|
|
3834
|
+
// Note: top-level scales also need swapping but `translateMark` retrieves them from `spec.scales`.
|
|
3835
|
+
// We need `translateMark` to use SWAPPED top-level scales.
|
|
3836
|
+
// So we pass a "virtual spec" to translateMark.
|
|
3837
|
+
const swappedSpec = { ...spec };
|
|
3838
|
+
if (spec.scales) {
|
|
3839
|
+
swappedSpec.scales = { ...spec.scales };
|
|
3840
|
+
const oldX = swappedSpec.scales.x;
|
|
3841
|
+
const oldY = swappedSpec.scales.y;
|
|
3842
|
+
if (oldX)
|
|
3843
|
+
swappedSpec.scales.y = oldX;
|
|
3844
|
+
else
|
|
3845
|
+
delete swappedSpec.scales.y;
|
|
3846
|
+
if (oldY)
|
|
3847
|
+
swappedSpec.scales.x = oldY;
|
|
3848
|
+
else
|
|
3849
|
+
delete swappedSpec.scales.x;
|
|
3850
|
+
}
|
|
3851
|
+
return translateMark(swappedMark, swappedSpec);
|
|
3852
|
+
}
|
|
3853
|
+
return translateMark(mark, spec);
|
|
3854
|
+
});
|
|
3855
|
+
if (spec.annotations) {
|
|
3856
|
+
for (const annotation of spec.annotations) {
|
|
3857
|
+
children.push(translateAnnotation(annotation));
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3860
|
+
g2.children = children;
|
|
3861
|
+
return g2;
|
|
3862
|
+
}
|
|
3863
|
+
// ---------------------------------------------------------------------------
|
|
3864
|
+
// Theme
|
|
3865
|
+
// ---------------------------------------------------------------------------
|
|
3866
|
+
/**
|
|
3867
|
+
* Build a G2 theme configuration object from a Vistral theme name.
|
|
3868
|
+
* Defaults to 'dark' when the theme argument is undefined.
|
|
3869
|
+
*/
|
|
3870
|
+
function applySpecTheme(theme) {
|
|
3871
|
+
const colors = getChartThemeColors(theme ?? 'dark');
|
|
3872
|
+
return {
|
|
3873
|
+
view: { viewFill: colors.background },
|
|
3874
|
+
label: { fill: colors.text, fontSize: 11, fillOpacity: 1 },
|
|
3875
|
+
axis: {
|
|
3876
|
+
x: {
|
|
3877
|
+
line: { stroke: colors.line, strokeOpacity: 1 },
|
|
3878
|
+
tick: { stroke: colors.line, strokeOpacity: 1 },
|
|
3879
|
+
label: { fill: colors.text, fontSize: 11, fillOpacity: 1 },
|
|
3880
|
+
title: { fill: colors.text, fontSize: 12, fontWeight: 500, fillOpacity: 1 },
|
|
3881
|
+
grid: { stroke: colors.gridline },
|
|
3882
|
+
},
|
|
3883
|
+
y: {
|
|
3884
|
+
line: { stroke: colors.line, strokeOpacity: 1 },
|
|
3885
|
+
tick: { stroke: colors.line, strokeOpacity: 1 },
|
|
3886
|
+
label: { fill: colors.text, fontSize: 11, fillOpacity: 1 },
|
|
3887
|
+
title: { fill: colors.text, fontSize: 12, fontWeight: 500, fillOpacity: 1 },
|
|
3888
|
+
grid: { stroke: colors.gridline },
|
|
3889
|
+
},
|
|
3890
|
+
},
|
|
3891
|
+
legend: {
|
|
3892
|
+
label: { fill: colors.text, fontSize: 12, fillOpacity: 1 },
|
|
3893
|
+
title: { fill: colors.text, fontSize: 12, fillOpacity: 1 },
|
|
3894
|
+
itemLabel: { fill: colors.text, fontSize: 12, fillOpacity: 1 },
|
|
3895
|
+
itemName: { fill: colors.text, fontSize: 12, fillOpacity: 1 },
|
|
3896
|
+
itemValue: { fill: colors.textSecondary, fontSize: 12, fillOpacity: 1 },
|
|
3897
|
+
},
|
|
3898
|
+
legendCategory: {
|
|
3899
|
+
itemLabel: { fill: colors.text, fillOpacity: 1 },
|
|
3900
|
+
itemName: { fill: colors.text, fillOpacity: 1 },
|
|
3901
|
+
},
|
|
3902
|
+
};
|
|
3903
|
+
}
|
|
3904
|
+
// ---------------------------------------------------------------------------
|
|
3905
|
+
// Temporal data filtering (in JavaScript)
|
|
3906
|
+
// ---------------------------------------------------------------------------
|
|
3907
|
+
/**
|
|
3908
|
+
* Apply temporal filtering and sorting to data **in JavaScript** rather than
|
|
3909
|
+
* relying on G2 data transforms. This is the preferred approach for the
|
|
3910
|
+
* declarative `chart.options()` API because G2 mark-level `transform` is
|
|
3911
|
+
* intended for visual transforms (stackY, dodgeX, …) — not data filtering.
|
|
3912
|
+
*
|
|
3913
|
+
* Returns a new array; the input is never mutated.
|
|
3914
|
+
*/
|
|
3915
|
+
function filterDataByTemporal(spec, data) {
|
|
3916
|
+
const { temporal } = spec;
|
|
3917
|
+
if (!temporal || data.length === 0)
|
|
3918
|
+
return data;
|
|
3919
|
+
const { mode, field } = temporal;
|
|
3920
|
+
let result = data;
|
|
3921
|
+
switch (mode) {
|
|
3922
|
+
case 'axis': {
|
|
3923
|
+
const { range } = temporal;
|
|
3924
|
+
// Time-window filter
|
|
3925
|
+
if (typeof range === 'number' && range !== Infinity) {
|
|
3926
|
+
const timeField = Array.isArray(field) ? field[0] : field;
|
|
3927
|
+
const maxTs = getMaxTimestamp(data, timeField);
|
|
3928
|
+
const windowMs = range * 60000;
|
|
3929
|
+
const minTs = maxTs - windowMs;
|
|
3930
|
+
result = result.filter((d) => {
|
|
3931
|
+
const ts = parseDateTime(d[timeField]);
|
|
3932
|
+
return ts >= minTs && ts <= maxTs;
|
|
3933
|
+
});
|
|
3934
|
+
}
|
|
3935
|
+
// Sort by temporal field
|
|
3936
|
+
const sortField = Array.isArray(field) ? field[0] : field;
|
|
3937
|
+
result = [...result].sort((a, b) => parseDateTime(a[sortField]) - parseDateTime(b[sortField]));
|
|
3938
|
+
break;
|
|
3939
|
+
}
|
|
3940
|
+
case 'frame': {
|
|
3941
|
+
const timeField = Array.isArray(field) ? field[0] : field;
|
|
3942
|
+
const maxTs = getMaxTimestamp(data, timeField);
|
|
3943
|
+
result = result.filter((d) => parseDateTime(d[timeField]) === maxTs);
|
|
3944
|
+
break;
|
|
3945
|
+
}
|
|
3946
|
+
case 'key': {
|
|
3947
|
+
// In 'key' mode, the `field` property represents the categorical Key (e.g. 'server').
|
|
3948
|
+
const keyFields = Array.isArray(temporal.field) ? temporal.field : [temporal.field];
|
|
3949
|
+
let timeField = 'timestamp'; // default guess
|
|
3950
|
+
// We need to find the timestamp field to determine "latest".
|
|
3951
|
+
// Heuristic: check for common names or first date-like field.
|
|
3952
|
+
if (data.length > 0) {
|
|
3953
|
+
const row = data[0];
|
|
3954
|
+
if (Object.prototype.hasOwnProperty.call(row, 'timestamp'))
|
|
3955
|
+
timeField = 'timestamp';
|
|
3956
|
+
else if (Object.prototype.hasOwnProperty.call(row, 'time'))
|
|
3957
|
+
timeField = 'time';
|
|
3958
|
+
else if (Object.prototype.hasOwnProperty.call(row, 'date'))
|
|
3959
|
+
timeField = 'date';
|
|
3960
|
+
else {
|
|
3961
|
+
// Scan for a value that looks like a timestamp
|
|
3962
|
+
for (const k in row) {
|
|
3963
|
+
if (keyFields.includes(k))
|
|
3964
|
+
continue;
|
|
3965
|
+
if (parseDateTime(row[k]) > 0) {
|
|
3966
|
+
timeField = k;
|
|
3967
|
+
break;
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3972
|
+
const latestByKey = new Map();
|
|
3973
|
+
for (const row of data) {
|
|
3974
|
+
const key = keyFields.map(f => String(row[f] ?? '')).join('::');
|
|
3975
|
+
const ts = parseDateTime(row[timeField]);
|
|
3976
|
+
const prev = latestByKey.get(key);
|
|
3977
|
+
if (prev === undefined || ts > prev) {
|
|
3978
|
+
latestByKey.set(key, ts);
|
|
3979
|
+
}
|
|
3980
|
+
}
|
|
3981
|
+
result = result.filter((d) => {
|
|
3982
|
+
const key = keyFields.map(f => String(d[f] ?? '')).join('::');
|
|
3983
|
+
const ts = parseDateTime(d[timeField]);
|
|
3984
|
+
return latestByKey.get(key) === ts;
|
|
3985
|
+
});
|
|
3986
|
+
break;
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
return result;
|
|
3990
|
+
}
|
|
3991
|
+
// ---------------------------------------------------------------------------
|
|
3992
|
+
// Pipeline helpers
|
|
3993
|
+
// ---------------------------------------------------------------------------
|
|
3994
|
+
/**
|
|
3995
|
+
* Collect the set of data-field names that are encoded to a channel whose
|
|
3996
|
+
* scale `type` is `'time'`. G2 needs Date objects (or epoch numbers) for
|
|
3997
|
+
* time scales — raw ISO strings are not parsed automatically.
|
|
3998
|
+
*/
|
|
3999
|
+
function collectTimeFields(spec) {
|
|
4000
|
+
const timeFields = new Set();
|
|
4001
|
+
const topScales = spec.scales ?? {};
|
|
4002
|
+
for (const mark of spec.marks) {
|
|
4003
|
+
const markScales = mark.scales ?? {};
|
|
4004
|
+
const merged = { ...topScales, ...markScales };
|
|
4005
|
+
for (const [channel, scaleConfig] of Object.entries(merged)) {
|
|
4006
|
+
if (scaleConfig?.type === 'time') {
|
|
4007
|
+
const fieldName = mark.encode?.[channel];
|
|
4008
|
+
if (typeof fieldName === 'string') {
|
|
4009
|
+
timeFields.add(fieldName);
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
// The temporal field is usually a date...
|
|
4015
|
+
// BUT if it is encoded to a 'band' scale (e.g. in a Bar Chart),
|
|
4016
|
+
// we must NOT convert it to a Date object, otherwise G2 will override the band scale with a time scale.
|
|
4017
|
+
if (spec.temporal?.field) {
|
|
4018
|
+
// In 'key' mode, the fields is the KEY, not the time.
|
|
4019
|
+
if (spec.temporal.mode === 'key') {
|
|
4020
|
+
return timeFields;
|
|
4021
|
+
}
|
|
4022
|
+
const fields = Array.isArray(spec.temporal.field) ? spec.temporal.field : [spec.temporal.field];
|
|
4023
|
+
let isBand = false;
|
|
4024
|
+
for (const mark of spec.marks) {
|
|
4025
|
+
const markScales = mark.scales ?? {};
|
|
4026
|
+
const merged = { ...topScales, ...markScales };
|
|
4027
|
+
for (const [channel, encodedField] of Object.entries(mark.encode ?? {})) {
|
|
4028
|
+
if (fields.includes(encodedField)) {
|
|
4029
|
+
const type = merged[channel]?.type;
|
|
4030
|
+
if (type === 'band') {
|
|
4031
|
+
isBand = true;
|
|
4032
|
+
}
|
|
4033
|
+
}
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
if (!isBand) {
|
|
4037
|
+
fields.forEach(f => timeFields.add(f));
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
return timeFields;
|
|
4041
|
+
}
|
|
4042
|
+
/**
|
|
4043
|
+
* If any area or line mark uses a `color` encoding (multi-series), return the
|
|
4044
|
+
* field name so the pipeline can apply a stable secondary sort. This prevents
|
|
4045
|
+
* the visual stacking order from flipping when series values cross each other.
|
|
4046
|
+
*/
|
|
4047
|
+
function getSeriesFieldForStableSort(spec) {
|
|
4048
|
+
for (const mark of spec.marks) {
|
|
4049
|
+
if ((mark.type === 'area' || mark.type === 'line') && mark.encode?.color) {
|
|
4050
|
+
const colorField = mark.encode.color;
|
|
4051
|
+
if (typeof colorField === 'string')
|
|
4052
|
+
return colorField;
|
|
4053
|
+
}
|
|
4054
|
+
}
|
|
4055
|
+
return null;
|
|
4056
|
+
}
|
|
4057
|
+
/**
|
|
4058
|
+
* Find the time/x field from the spec — either from temporal config or from
|
|
4059
|
+
* the first mark's x encoding that uses a time scale.
|
|
4060
|
+
*/
|
|
4061
|
+
function getTimeFieldFromSpec(spec) {
|
|
4062
|
+
// 1. From temporal config
|
|
4063
|
+
if (spec.temporal?.field) {
|
|
4064
|
+
const f = spec.temporal.field;
|
|
4065
|
+
return Array.isArray(f) ? f[0] : f;
|
|
4066
|
+
}
|
|
4067
|
+
// 2. From marks' x encoding with time scale
|
|
4068
|
+
const topScales = spec.scales ?? {};
|
|
4069
|
+
for (const mark of spec.marks) {
|
|
4070
|
+
const markScales = mark.scales ?? {};
|
|
4071
|
+
const merged = { ...topScales, ...markScales };
|
|
4072
|
+
if (merged.x?.type === 'time' && typeof mark.encode?.x === 'string') {
|
|
4073
|
+
return mark.encode.x;
|
|
4074
|
+
}
|
|
4075
|
+
}
|
|
4076
|
+
return null;
|
|
4077
|
+
}
|
|
4078
|
+
// ---------------------------------------------------------------------------
|
|
4079
|
+
// Pipeline
|
|
4080
|
+
// ---------------------------------------------------------------------------
|
|
4081
|
+
/**
|
|
4082
|
+
* Main pipeline — combines temporal data filtering, G2 spec translation, and
|
|
4083
|
+
* theme application into a single G2-ready options object.
|
|
4084
|
+
*
|
|
4085
|
+
* 1. `filterDataByTemporal(spec, data)` — filter/sort data in JavaScript
|
|
4086
|
+
* 2. `translateToG2Spec(spec)` — produce G2 options (no visual transforms)
|
|
4087
|
+
* 3. `applySpecTheme(spec.theme)` — attach theme configuration
|
|
4088
|
+
* 4. Attach filtered data + sliding time domain to each child mark
|
|
4089
|
+
*
|
|
4090
|
+
* The returned object is ready for `chart.options(result)`.
|
|
4091
|
+
*/
|
|
4092
|
+
function buildG2Options(spec, data) {
|
|
4093
|
+
// Filter/sort data in JS — do NOT inject temporal transforms into G2
|
|
4094
|
+
let filteredData = filterDataByTemporal(spec, data);
|
|
4095
|
+
// --- Stable sort by color/series field for area/line marks -----------------
|
|
4096
|
+
// For stacked or overlapping area/line charts with a color encoding, the
|
|
4097
|
+
// data rows within each time group must be in a consistent order. Without
|
|
4098
|
+
// this, the visual stacking order flips when series values cross each other.
|
|
4099
|
+
const seriesField = getSeriesFieldForStableSort(spec);
|
|
4100
|
+
if (seriesField && filteredData.length > 0) {
|
|
4101
|
+
// Find the time/x field for the primary sort key
|
|
4102
|
+
const timeField = getTimeFieldFromSpec(spec);
|
|
4103
|
+
if (timeField) {
|
|
4104
|
+
// Combined sort: primary by time, secondary by series (stable)
|
|
4105
|
+
filteredData = [...filteredData].sort((a, b) => {
|
|
4106
|
+
const ta = parseDateTime(a[timeField]);
|
|
4107
|
+
const tb = parseDateTime(b[timeField]);
|
|
4108
|
+
if (ta !== tb)
|
|
4109
|
+
return ta - tb;
|
|
4110
|
+
// Same time — sort by series name for consistent stack order
|
|
4111
|
+
const sa = String(a[seriesField] ?? '');
|
|
4112
|
+
const sb = String(b[seriesField] ?? '');
|
|
4113
|
+
return sa < sb ? -1 : sa > sb ? 1 : 0;
|
|
4114
|
+
});
|
|
4115
|
+
}
|
|
4116
|
+
else {
|
|
4117
|
+
// No time field — just sort by series for consistent order
|
|
4118
|
+
filteredData = [...filteredData].sort((a, b) => {
|
|
4119
|
+
const sa = String(a[seriesField] ?? '');
|
|
4120
|
+
const sb = String(b[seriesField] ?? '');
|
|
4121
|
+
return sa < sb ? -1 : sa > sb ? 1 : 0;
|
|
4122
|
+
});
|
|
4123
|
+
}
|
|
4124
|
+
}
|
|
4125
|
+
// --- Convert time-scale fields to Date objects ----------------------------
|
|
4126
|
+
// G2's time scale cannot parse ISO 8601 strings directly; it needs Date
|
|
4127
|
+
// objects (or epoch numbers). Collect every data field that is encoded to a
|
|
4128
|
+
// channel whose scale `type` is `'time'` and convert those field values.
|
|
4129
|
+
const timeFields = collectTimeFields(spec);
|
|
4130
|
+
if (timeFields.size > 0 && filteredData.length > 0) {
|
|
4131
|
+
filteredData = filteredData.map((row) => {
|
|
4132
|
+
const newRow = { ...row };
|
|
4133
|
+
for (const f of timeFields) {
|
|
4134
|
+
if (newRow[f] !== undefined) {
|
|
4135
|
+
newRow[f] = new Date(parseDateTime(newRow[f]));
|
|
4136
|
+
}
|
|
4137
|
+
}
|
|
4138
|
+
return newRow;
|
|
4139
|
+
});
|
|
4140
|
+
}
|
|
4141
|
+
// Translate spec to G2 (only visual transforms like stackY/dodgeX reach G2)
|
|
4142
|
+
const g2Spec = translateToG2Spec(spec);
|
|
4143
|
+
g2Spec.theme = applySpecTheme(spec.theme);
|
|
4144
|
+
// Attach filtered data at the view level. Child marks inherit from the
|
|
4145
|
+
// view; annotations that already carry their own `data` (set by
|
|
4146
|
+
// translateAnnotation) keep it — G2 lets child-level data override.
|
|
4147
|
+
g2Spec.data = filteredData;
|
|
4148
|
+
// --- Axis-mode temporal: set sliding time domain on appropriate scale ---
|
|
4149
|
+
// This makes the axis scroll forward as new data arrives.
|
|
4150
|
+
if (spec.temporal?.mode === 'axis' && filteredData.length > 0) {
|
|
4151
|
+
const field = spec.temporal.field;
|
|
4152
|
+
const timeField = Array.isArray(field) ? field[0] : field;
|
|
4153
|
+
const maxTs = getMaxTimestamp(filteredData, timeField);
|
|
4154
|
+
const range = spec.temporal.range;
|
|
4155
|
+
let minTs;
|
|
4156
|
+
if (typeof range === 'number' && range !== Infinity) {
|
|
4157
|
+
minTs = maxTs - range * 60000;
|
|
4158
|
+
}
|
|
4159
|
+
else {
|
|
4160
|
+
// No finite range — span the full data extent
|
|
4161
|
+
minTs = maxTs;
|
|
4162
|
+
for (const row of filteredData) {
|
|
4163
|
+
const ts = parseDateTime(row[timeField]);
|
|
4164
|
+
if (ts < minTs)
|
|
4165
|
+
minTs = ts;
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
// Auto-detect a suitable time format mask
|
|
4169
|
+
// Check both axes for mask config, though usually it's on the temporal axis
|
|
4170
|
+
const xMask = spec.scales?.x?.mask;
|
|
4171
|
+
const yMask = spec.scales?.y?.mask;
|
|
4172
|
+
const mask = (xMask || yMask) ?? getTimeMask(minTs, maxTs);
|
|
4173
|
+
if (g2Spec.children) {
|
|
4174
|
+
for (const child of g2Spec.children) {
|
|
4175
|
+
if (!child.scale)
|
|
4176
|
+
child.scale = {};
|
|
4177
|
+
// Interval marks (bars) usually require a 'band' scale for width calculation.
|
|
4178
|
+
// Forcing 'time' scale can cause internal G2 crashes (getBandWidth error).
|
|
4179
|
+
// Since data is already filtered by time, we can skip enforcing time scale here.
|
|
4180
|
+
if (child.type === 'interval') {
|
|
4181
|
+
continue;
|
|
4182
|
+
}
|
|
4183
|
+
// Find which channel is using the temporal field
|
|
4184
|
+
let targetChannel = null;
|
|
4185
|
+
// Check local encode first
|
|
4186
|
+
if (child.encode) {
|
|
4187
|
+
if (child.encode.x === timeField)
|
|
4188
|
+
targetChannel = 'x';
|
|
4189
|
+
else if (child.encode.y === timeField)
|
|
4190
|
+
targetChannel = 'y';
|
|
4191
|
+
}
|
|
4192
|
+
// If not found in local mark, could rely on defaults but Vistral requires explicit encode usually.
|
|
4193
|
+
// If we found a target channel, update its scale.
|
|
4194
|
+
if (targetChannel) {
|
|
4195
|
+
// Don't override an explicit 'band' scale with 'time'
|
|
4196
|
+
const existingType = child.scale[targetChannel]?.type || spec.scales?.[targetChannel]?.type;
|
|
4197
|
+
if (existingType === 'band') {
|
|
4198
|
+
continue;
|
|
4199
|
+
}
|
|
4200
|
+
child.scale[targetChannel] = {
|
|
4201
|
+
...(child.scale[targetChannel] ?? {}),
|
|
4202
|
+
type: 'time',
|
|
4203
|
+
domainMin: new Date(minTs),
|
|
4204
|
+
domainMax: new Date(maxTs),
|
|
4205
|
+
mask,
|
|
4206
|
+
};
|
|
4207
|
+
}
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4211
|
+
return g2Spec;
|
|
4212
|
+
}
|
|
4213
|
+
|
|
4214
|
+
// ---------------------------------------------------------------------------
|
|
4215
|
+
// Helpers
|
|
4216
|
+
// ---------------------------------------------------------------------------
|
|
4217
|
+
/**
|
|
4218
|
+
* Normalise a `StreamDataSource` into an array of `Record<string, unknown>`.
|
|
4219
|
+
*
|
|
4220
|
+
* Rows that are already objects are kept as-is. Array rows are mapped using
|
|
4221
|
+
* the column definitions so that `row[i]` becomes `{ [columns[i].name]: v }`.
|
|
4222
|
+
*/
|
|
4223
|
+
function normaliseData(source) {
|
|
4224
|
+
if (!source || !source.data || source.data.length === 0)
|
|
4225
|
+
return [];
|
|
4226
|
+
const { columns, data } = source;
|
|
4227
|
+
return data.map((row) => {
|
|
4228
|
+
if (Array.isArray(row)) {
|
|
4229
|
+
return arrayRowToObject(row, columns);
|
|
4230
|
+
}
|
|
4231
|
+
return row;
|
|
4232
|
+
});
|
|
4233
|
+
}
|
|
4234
|
+
/**
|
|
4235
|
+
* Convert a single array-style row to an object using column definitions.
|
|
4236
|
+
*/
|
|
4237
|
+
function arrayRowToObject(row, columns) {
|
|
4238
|
+
const obj = {};
|
|
4239
|
+
for (let i = 0; i < columns.length; i++) {
|
|
4240
|
+
obj[columns[i].name] = row[i];
|
|
4241
|
+
}
|
|
4242
|
+
return obj;
|
|
4243
|
+
}
|
|
4244
|
+
/**
|
|
4245
|
+
* Normalise raw rows (which may be arrays or objects) into objects.
|
|
4246
|
+
* When array rows are encountered without column info we fall back to
|
|
4247
|
+
* positional keys ("col_0", "col_1", ...).
|
|
4248
|
+
*/
|
|
4249
|
+
function normaliseRows(rows, columns) {
|
|
4250
|
+
return rows.map((row) => {
|
|
4251
|
+
if (Array.isArray(row)) {
|
|
4252
|
+
if (columns && columns.length > 0) {
|
|
4253
|
+
return arrayRowToObject(row, columns);
|
|
4254
|
+
}
|
|
4255
|
+
// Fallback: positional keys
|
|
4256
|
+
const obj = {};
|
|
4257
|
+
for (let i = 0; i < row.length; i++) {
|
|
4258
|
+
obj[`col_${i}`] = row[i];
|
|
4259
|
+
}
|
|
4260
|
+
return obj;
|
|
4261
|
+
}
|
|
4262
|
+
return row;
|
|
4263
|
+
});
|
|
4264
|
+
}
|
|
4265
|
+
// ---------------------------------------------------------------------------
|
|
4266
|
+
// Component
|
|
4267
|
+
// ---------------------------------------------------------------------------
|
|
4268
|
+
/**
|
|
4269
|
+
* `VistralChart` renders a VistralSpec declaratively. It manages the G2
|
|
4270
|
+
* chart lifecycle and exposes an imperative `ChartHandle` via ref for
|
|
4271
|
+
* streaming updates.
|
|
4272
|
+
*/
|
|
4273
|
+
const VistralChart = forwardRef(function VistralChart(props, ref) {
|
|
4274
|
+
const { spec, source, width, height, className, style, onReady } = props;
|
|
4275
|
+
// DOM container
|
|
4276
|
+
const containerRef = useRef(null);
|
|
4277
|
+
// G2 chart instance
|
|
4278
|
+
const chartRef = useRef(null);
|
|
4279
|
+
// Internal data buffer
|
|
4280
|
+
const dataRef = useRef([]);
|
|
4281
|
+
// Column definitions (kept from source for array-row normalisation)
|
|
4282
|
+
const columnsRef = useRef([]);
|
|
4283
|
+
// Throttle timer
|
|
4284
|
+
const throttleTimerRef = useRef(null);
|
|
4285
|
+
const pendingRenderRef = useRef(false);
|
|
4286
|
+
// Track whether onReady has been called
|
|
4287
|
+
const [readyFired, setReadyFired] = useState(false);
|
|
4288
|
+
// ----- Render helper -----
|
|
4289
|
+
const renderChart = useCallback(() => {
|
|
4290
|
+
const chart = chartRef.current;
|
|
4291
|
+
if (!chart)
|
|
4292
|
+
return;
|
|
4293
|
+
const data = dataRef.current;
|
|
4294
|
+
// Skip rendering when there is no data — avoids putting G2 into a
|
|
4295
|
+
// broken empty state that prevents subsequent renders from showing.
|
|
4296
|
+
if (data.length === 0)
|
|
4297
|
+
return;
|
|
4298
|
+
const g2Options = buildG2Options(spec, data);
|
|
4299
|
+
// Apply explicit dimensions if provided
|
|
4300
|
+
if (width !== undefined)
|
|
4301
|
+
g2Options.width = width;
|
|
4302
|
+
if (height !== undefined)
|
|
4303
|
+
g2Options.height = height;
|
|
4304
|
+
chart.options(g2Options);
|
|
4305
|
+
chart.render();
|
|
4306
|
+
}, [spec, width, height]);
|
|
4307
|
+
/**
|
|
4308
|
+
* Schedule a render, respecting the optional throttle interval.
|
|
4309
|
+
*/
|
|
4310
|
+
const scheduleRender = useCallback(() => {
|
|
4311
|
+
const throttle = spec.streaming?.throttle ?? 0;
|
|
4312
|
+
if (throttle <= 0) {
|
|
4313
|
+
renderChart();
|
|
4314
|
+
return;
|
|
4315
|
+
}
|
|
4316
|
+
// If a timer is already running, mark as pending
|
|
4317
|
+
if (throttleTimerRef.current !== null) {
|
|
4318
|
+
pendingRenderRef.current = true;
|
|
4319
|
+
return;
|
|
4320
|
+
}
|
|
4321
|
+
renderChart();
|
|
4322
|
+
throttleTimerRef.current = setTimeout(() => {
|
|
4323
|
+
throttleTimerRef.current = null;
|
|
4324
|
+
if (pendingRenderRef.current) {
|
|
4325
|
+
pendingRenderRef.current = false;
|
|
4326
|
+
renderChart();
|
|
4327
|
+
}
|
|
4328
|
+
}, throttle);
|
|
4329
|
+
}, [renderChart, spec.streaming?.throttle]);
|
|
4330
|
+
// ----- Imperative handle -----
|
|
4331
|
+
const maxItems = spec.streaming?.maxItems ?? DEFAULT_MAX_ITEMS;
|
|
4332
|
+
const handleRef = useRef({
|
|
4333
|
+
append: () => { },
|
|
4334
|
+
replace: () => { },
|
|
4335
|
+
clear: () => { },
|
|
4336
|
+
g2: null,
|
|
4337
|
+
});
|
|
4338
|
+
// Keep handle methods up-to-date
|
|
4339
|
+
handleRef.current.append = (rows) => {
|
|
4340
|
+
const normalised = normaliseRows(rows, columnsRef.current);
|
|
4341
|
+
const buffer = dataRef.current;
|
|
4342
|
+
buffer.push(...normalised);
|
|
4343
|
+
// Trim to maxItems
|
|
4344
|
+
if (buffer.length > maxItems) {
|
|
4345
|
+
dataRef.current = buffer.slice(buffer.length - maxItems);
|
|
4346
|
+
}
|
|
4347
|
+
scheduleRender();
|
|
4348
|
+
};
|
|
4349
|
+
handleRef.current.replace = (rows) => {
|
|
4350
|
+
const normalised = normaliseRows(rows, columnsRef.current);
|
|
4351
|
+
dataRef.current = normalised.slice(-maxItems);
|
|
4352
|
+
scheduleRender();
|
|
4353
|
+
};
|
|
4354
|
+
handleRef.current.clear = () => {
|
|
4355
|
+
dataRef.current = [];
|
|
4356
|
+
scheduleRender();
|
|
4357
|
+
};
|
|
4358
|
+
handleRef.current.g2 = chartRef.current;
|
|
4359
|
+
useImperativeHandle(ref, () => handleRef.current, []);
|
|
4360
|
+
// ----- Chart lifecycle: create / destroy -----
|
|
4361
|
+
useEffect(() => {
|
|
4362
|
+
if (!containerRef.current)
|
|
4363
|
+
return;
|
|
4364
|
+
const chart = new Chart({
|
|
4365
|
+
container: containerRef.current,
|
|
4366
|
+
autoFit: true,
|
|
4367
|
+
});
|
|
4368
|
+
chartRef.current = chart;
|
|
4369
|
+
handleRef.current.g2 = chart;
|
|
4370
|
+
// Fire onReady after the chart instance is created. This happens
|
|
4371
|
+
// synchronously inside the effect so the handle is available by the
|
|
4372
|
+
// time any sibling effects or the caller's own effects run.
|
|
4373
|
+
if (!readyFired && onReady) {
|
|
4374
|
+
onReady(handleRef.current);
|
|
4375
|
+
setReadyFired(true);
|
|
4376
|
+
}
|
|
4377
|
+
return () => {
|
|
4378
|
+
// Cleanup throttle timer
|
|
4379
|
+
if (throttleTimerRef.current !== null) {
|
|
4380
|
+
clearTimeout(throttleTimerRef.current);
|
|
4381
|
+
throttleTimerRef.current = null;
|
|
4382
|
+
}
|
|
4383
|
+
chart.destroy();
|
|
4384
|
+
chartRef.current = null;
|
|
4385
|
+
handleRef.current.g2 = null;
|
|
4386
|
+
};
|
|
4387
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4388
|
+
}, []);
|
|
4389
|
+
// ----- React to source / spec changes -----
|
|
4390
|
+
useEffect(() => {
|
|
4391
|
+
if (source) {
|
|
4392
|
+
columnsRef.current = source.columns;
|
|
4393
|
+
dataRef.current = normaliseData(source);
|
|
4394
|
+
}
|
|
4395
|
+
scheduleRender();
|
|
4396
|
+
}, [source, scheduleRender]);
|
|
4397
|
+
// ----- Render -----
|
|
4398
|
+
const containerStyle = {
|
|
4399
|
+
width: width !== undefined ? width : '100%',
|
|
4400
|
+
height: height !== undefined ? height : '100%',
|
|
4401
|
+
...style,
|
|
4402
|
+
};
|
|
4403
|
+
return (jsxRuntimeExports.jsx("div", { ref: containerRef, className: className, style: containerStyle }));
|
|
4404
|
+
});
|
|
4405
|
+
|
|
4406
|
+
/**
|
|
4407
|
+
* Config Compilers — bridge between legacy chart configs and VistralSpec.
|
|
4408
|
+
*
|
|
4409
|
+
* These functions convert the existing high-level chart configuration
|
|
4410
|
+
* objects (TimeSeriesConfig, BarColumnConfig) into the declarative
|
|
4411
|
+
* VistralSpec grammar.
|
|
4412
|
+
*/
|
|
4413
|
+
// ---------------------------------------------------------------------------
|
|
4414
|
+
// Helpers
|
|
4415
|
+
// ---------------------------------------------------------------------------
|
|
4416
|
+
/**
|
|
4417
|
+
* Map the legacy TemporalConfig to a TemporalSpec.
|
|
4418
|
+
* Falls back to the given `defaultField` when the config's field is empty.
|
|
4419
|
+
*/
|
|
4420
|
+
function mapTemporal(temporal, defaultField) {
|
|
4421
|
+
if (!temporal)
|
|
4422
|
+
return undefined;
|
|
4423
|
+
return {
|
|
4424
|
+
mode: temporal.mode,
|
|
4425
|
+
field: temporal.field || defaultField,
|
|
4426
|
+
range: temporal.range,
|
|
4427
|
+
};
|
|
4428
|
+
}
|
|
4429
|
+
// ---------------------------------------------------------------------------
|
|
4430
|
+
// compileTimeSeriesConfig
|
|
4431
|
+
// ---------------------------------------------------------------------------
|
|
4432
|
+
/**
|
|
4433
|
+
* Compile a `TimeSeriesConfig` into a `VistralSpec`.
|
|
4434
|
+
*
|
|
4435
|
+
* Mapping summary:
|
|
4436
|
+
* - `chartType` -> mark type ('line' | 'area')
|
|
4437
|
+
* - `xAxis` / `yAxis` / `color` -> encode channels
|
|
4438
|
+
* - `lineStyle: 'curve'` -> style.shape: 'smooth', else 'line'
|
|
4439
|
+
* - Always adds style.connect: true
|
|
4440
|
+
* - `points: true` -> adds second point mark (tooltip: false)
|
|
4441
|
+
* - `dataLabel: true` -> adds label; if showAll is false, selector: 'last'
|
|
4442
|
+
* - area + color -> transforms: [{ type: 'stackY' }]
|
|
4443
|
+
* - scales.x: time scale with optional mask from xFormat
|
|
4444
|
+
* - scales.y: linear, nice, optional domain from yRange
|
|
4445
|
+
* - temporal -> maps to TemporalSpec
|
|
4446
|
+
* - streaming: { maxItems: config.maxItems ?? DEFAULT_MAX_ITEMS }
|
|
4447
|
+
* - axes, legend, theme, animate configured per defaults
|
|
4448
|
+
*/
|
|
4449
|
+
function compileTimeSeriesConfig(config, theme = 'dark') {
|
|
4450
|
+
const { chartType, xAxis, yAxis, color } = config;
|
|
4451
|
+
// -- Primary mark ----------------------------------------------------------
|
|
4452
|
+
const mark = {
|
|
4453
|
+
type: chartType, // 'line' | 'area'
|
|
4454
|
+
encode: {
|
|
4455
|
+
x: xAxis,
|
|
4456
|
+
y: yAxis,
|
|
4457
|
+
...(color ? { color } : {}),
|
|
4458
|
+
},
|
|
4459
|
+
style: {
|
|
4460
|
+
connect: true,
|
|
4461
|
+
...(config.chartType === 'line'
|
|
4462
|
+
? { shape: config.lineStyle === 'curve' ? 'smooth' : 'line' }
|
|
4463
|
+
: {}),
|
|
4464
|
+
...(config.chartType === 'area' && config.lineStyle === 'curve'
|
|
4465
|
+
? { shape: 'smooth' }
|
|
4466
|
+
: {}),
|
|
4467
|
+
},
|
|
4468
|
+
};
|
|
4469
|
+
// Labels
|
|
4470
|
+
if (config.dataLabel) {
|
|
4471
|
+
const label = {
|
|
4472
|
+
text: yAxis,
|
|
4473
|
+
overlapHide: true,
|
|
4474
|
+
};
|
|
4475
|
+
if (config.showAll === false) {
|
|
4476
|
+
label.selector = 'last';
|
|
4477
|
+
}
|
|
4478
|
+
mark.labels = [label];
|
|
4479
|
+
}
|
|
4480
|
+
// -- Marks array -----------------------------------------------------------
|
|
4481
|
+
const marks = [mark];
|
|
4482
|
+
if (config.points) {
|
|
4483
|
+
marks.push({
|
|
4484
|
+
type: 'point',
|
|
4485
|
+
encode: {
|
|
4486
|
+
x: xAxis,
|
|
4487
|
+
y: yAxis,
|
|
4488
|
+
...(color ? { color } : {}),
|
|
4489
|
+
},
|
|
4490
|
+
tooltip: false,
|
|
4491
|
+
});
|
|
4492
|
+
}
|
|
4493
|
+
// -- Transforms ------------------------------------------------------------
|
|
4494
|
+
const transforms = [];
|
|
4495
|
+
if (chartType === 'area' && color) {
|
|
4496
|
+
transforms.push({ type: 'stackY' });
|
|
4497
|
+
}
|
|
4498
|
+
// -- Scales ----------------------------------------------------------------
|
|
4499
|
+
const xScale = { type: 'time' };
|
|
4500
|
+
if (config.xFormat) {
|
|
4501
|
+
xScale.mask = config.xFormat;
|
|
4502
|
+
}
|
|
4503
|
+
const yScale = { type: 'linear', nice: true };
|
|
4504
|
+
if (config.yRange &&
|
|
4505
|
+
config.yRange.min != null &&
|
|
4506
|
+
config.yRange.max != null) {
|
|
4507
|
+
yScale.domain = [config.yRange.min, config.yRange.max];
|
|
4508
|
+
}
|
|
4509
|
+
// -- Temporal --------------------------------------------------------------
|
|
4510
|
+
// Default to axis-bound sliding window for time series charts
|
|
4511
|
+
const temporal = mapTemporal(config.temporal, xAxis)
|
|
4512
|
+
?? { mode: 'axis', field: xAxis, range: 2 };
|
|
4513
|
+
// -- Axes ------------------------------------------------------------------
|
|
4514
|
+
const gridY = config.gridlines ?? true;
|
|
4515
|
+
// -- Legend ----------------------------------------------------------------
|
|
4516
|
+
const legend = config.legend === false
|
|
4517
|
+
? false
|
|
4518
|
+
: { position: 'bottom', interactive: true };
|
|
4519
|
+
// -- Assemble spec ---------------------------------------------------------
|
|
4520
|
+
const spec = {
|
|
4521
|
+
marks,
|
|
4522
|
+
scales: {
|
|
4523
|
+
x: xScale,
|
|
4524
|
+
y: yScale,
|
|
4525
|
+
},
|
|
4526
|
+
...(transforms.length > 0 ? { transforms } : {}),
|
|
4527
|
+
...(temporal ? { temporal } : {}),
|
|
4528
|
+
streaming: { maxItems: config.maxItems ?? DEFAULT_MAX_ITEMS },
|
|
4529
|
+
axes: {
|
|
4530
|
+
x: { title: config.xTitle || false, grid: false },
|
|
4531
|
+
y: { title: config.yTitle || false, grid: gridY },
|
|
4532
|
+
},
|
|
4533
|
+
legend,
|
|
4534
|
+
theme: theme,
|
|
4535
|
+
animate: false,
|
|
4536
|
+
};
|
|
4537
|
+
return spec;
|
|
4538
|
+
}
|
|
4539
|
+
// ---------------------------------------------------------------------------
|
|
4540
|
+
// compileBarColumnConfig
|
|
4541
|
+
// ---------------------------------------------------------------------------
|
|
4542
|
+
/**
|
|
4543
|
+
* Compile a `BarColumnConfig` into a `VistralSpec`.
|
|
4544
|
+
*
|
|
4545
|
+
* Mapping summary:
|
|
4546
|
+
* - mark type is always 'interval'
|
|
4547
|
+
* - `chartType 'bar'` -> coordinate: { transforms: [{ type: 'transpose' }] }
|
|
4548
|
+
* - `color` set -> transforms: stackY (if groupType==='stack') or dodgeX
|
|
4549
|
+
* - `dataLabel: true` -> label with text: yAxis, overlapHide: true
|
|
4550
|
+
* - scales: x with padding 0.5, y linear with nice
|
|
4551
|
+
* - Same streaming/axes/legend/theme/animate defaults as time series
|
|
4552
|
+
*/
|
|
4553
|
+
function compileBarColumnConfig(config, theme = 'dark') {
|
|
4554
|
+
const { xAxis, yAxis, color, chartType } = config;
|
|
4555
|
+
const isBar = chartType === 'bar';
|
|
4556
|
+
// Standard Mapping:
|
|
4557
|
+
// xAxis -> Independent Variable (Category) -> x channel (Band scale)
|
|
4558
|
+
// yAxis -> Dependent Variable (Value) -> y channel (Linear scale)
|
|
4559
|
+
//
|
|
4560
|
+
// For Bar Charts, we apply 'transpose' to flip the visual axes.
|
|
4561
|
+
// -- Primary mark ----------------------------------------------------------
|
|
4562
|
+
const mark = {
|
|
4563
|
+
type: 'interval',
|
|
4564
|
+
encode: {
|
|
4565
|
+
x: xAxis,
|
|
4566
|
+
y: yAxis,
|
|
4567
|
+
...(color ? { color } : {}),
|
|
4568
|
+
},
|
|
4569
|
+
};
|
|
4570
|
+
// Labels: Always display the VALUE (yAxis)
|
|
4571
|
+
if (config.dataLabel) {
|
|
4572
|
+
mark.labels = [
|
|
4573
|
+
{
|
|
4574
|
+
text: yAxis,
|
|
4575
|
+
overlapHide: true,
|
|
4576
|
+
},
|
|
4577
|
+
];
|
|
4578
|
+
}
|
|
4579
|
+
// -- Transforms ------------------------------------------------------------
|
|
4580
|
+
const transforms = [];
|
|
4581
|
+
if (color) {
|
|
4582
|
+
transforms.push({
|
|
4583
|
+
type: config.groupType === 'stack' ? 'stackY' : 'dodgeX',
|
|
4584
|
+
});
|
|
4585
|
+
}
|
|
4586
|
+
// -- Coordinate ------------------------------------------------------------
|
|
4587
|
+
const coordinate = isBar
|
|
4588
|
+
? { transforms: [{ type: 'transpose' }] }
|
|
4589
|
+
: undefined;
|
|
4590
|
+
// -- Scales ----------------------------------------------------------------
|
|
4591
|
+
// G2 Interval Mark expects 'x' to be the discrete (band) axis.
|
|
4592
|
+
// We use Transpose for Bar Charts to flip it to the vertical axis.
|
|
4593
|
+
const scales = {
|
|
4594
|
+
x: { type: 'band', padding: 0.5 },
|
|
4595
|
+
y: { type: 'linear', nice: true },
|
|
4596
|
+
};
|
|
4597
|
+
// -- Temporal --------------------------------------------------------------
|
|
4598
|
+
// Default temporal field is the Category field (xAxis)
|
|
4599
|
+
const temporal = mapTemporal(config.temporal, xAxis);
|
|
4600
|
+
// -- Axes ------------------------------------------------------------------
|
|
4601
|
+
const gridY = config.gridlines ?? true;
|
|
4602
|
+
// -- Legend ----------------------------------------------------------------
|
|
4603
|
+
const legend = config.legend === false
|
|
4604
|
+
? false
|
|
4605
|
+
: { position: 'bottom', interactive: true };
|
|
4606
|
+
// -- Assemble spec ---------------------------------------------------------
|
|
4607
|
+
const spec = {
|
|
4608
|
+
marks: [mark],
|
|
4609
|
+
scales,
|
|
4610
|
+
...(transforms.length > 0 ? { transforms } : {}),
|
|
4611
|
+
...(coordinate ? { coordinate } : {}),
|
|
4612
|
+
...(temporal ? { temporal } : {}),
|
|
4613
|
+
streaming: { maxItems: config.maxItems ?? DEFAULT_MAX_ITEMS },
|
|
4614
|
+
axes: {
|
|
4615
|
+
x: { title: config.xTitle || false, grid: false },
|
|
4616
|
+
y: { title: config.yTitle || false, grid: gridY },
|
|
4617
|
+
},
|
|
4618
|
+
legend,
|
|
4619
|
+
theme: theme,
|
|
4620
|
+
animate: false,
|
|
4621
|
+
};
|
|
4622
|
+
return spec;
|
|
4623
|
+
}
|
|
4624
|
+
|
|
4625
|
+
/**
|
|
4626
|
+
* Check if configuration is for a time series chart
|
|
4627
|
+
*/
|
|
4628
|
+
function isTimeSeriesConfig(config) {
|
|
4629
|
+
return config.chartType === 'line' || config.chartType === 'area';
|
|
4630
|
+
}
|
|
4631
|
+
/**
|
|
4632
|
+
* Check if configuration is for a bar/column chart
|
|
4633
|
+
*/
|
|
4634
|
+
function isBarColumnConfig(config) {
|
|
4635
|
+
return config.chartType === 'bar' || config.chartType === 'column';
|
|
4636
|
+
}
|
|
4637
|
+
/**
|
|
4638
|
+
* Check if configuration is for a single value chart
|
|
4639
|
+
*/
|
|
4640
|
+
function isSingleValueConfig(config) {
|
|
4641
|
+
return config.chartType === 'singleValue';
|
|
4642
|
+
}
|
|
4643
|
+
/**
|
|
4644
|
+
* Check if configuration is for a table
|
|
4645
|
+
*/
|
|
4646
|
+
function isTableConfig(config) {
|
|
4647
|
+
return config.chartType === 'table';
|
|
4648
|
+
}
|
|
4649
|
+
/**
|
|
4650
|
+
* Check if configuration is for a geo chart
|
|
4651
|
+
*/
|
|
4652
|
+
function isGeoConfig(config) {
|
|
4653
|
+
return config.chartType === 'geo';
|
|
4654
|
+
}
|
|
4655
|
+
/**
|
|
4656
|
+
* Error Boundary for chart rendering errors
|
|
4657
|
+
*/
|
|
4658
|
+
class ChartErrorBoundary extends require$$0.Component {
|
|
4659
|
+
constructor(props) {
|
|
4660
|
+
super(props);
|
|
4661
|
+
this.state = { hasError: false, error: null };
|
|
4662
|
+
}
|
|
4663
|
+
static getDerivedStateFromError(error) {
|
|
4664
|
+
return { hasError: true, error };
|
|
4665
|
+
}
|
|
4666
|
+
render() {
|
|
4667
|
+
if (this.state.hasError) {
|
|
4668
|
+
const { theme } = this.props;
|
|
4669
|
+
return (jsxRuntimeExports.jsxs("div", { style: {
|
|
4670
|
+
width: '100%',
|
|
4671
|
+
height: '100%',
|
|
4672
|
+
display: 'flex',
|
|
4673
|
+
flexDirection: 'column',
|
|
4674
|
+
alignItems: 'center',
|
|
4675
|
+
justifyContent: 'center',
|
|
4676
|
+
padding: '24px',
|
|
4677
|
+
textAlign: 'center',
|
|
4678
|
+
color: theme === 'dark' ? '#F87171' : '#DC2626',
|
|
4679
|
+
backgroundColor: theme === 'dark' ? 'rgba(127, 29, 29, 0.1)' : 'rgba(254, 226, 226, 0.5)',
|
|
4680
|
+
borderRadius: '8px',
|
|
4681
|
+
}, children: [jsxRuntimeExports.jsxs("svg", { width: "48", height: "48", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [jsxRuntimeExports.jsx("circle", { cx: "12", cy: "12", r: "10" }), jsxRuntimeExports.jsx("line", { x1: "12", y1: "8", x2: "12", y2: "12" }), jsxRuntimeExports.jsx("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })] }), jsxRuntimeExports.jsx("p", { style: { marginTop: '16px', fontWeight: 500 }, children: "Chart rendering error" }), jsxRuntimeExports.jsx("p", { style: {
|
|
4682
|
+
marginTop: '8px',
|
|
4683
|
+
fontSize: '12px',
|
|
4684
|
+
color: theme === 'dark' ? '#FCA5A5' : '#F87171',
|
|
4685
|
+
}, children: this.state.error?.message || 'Unknown error' })] }));
|
|
4686
|
+
}
|
|
4687
|
+
return this.props.children;
|
|
4688
|
+
}
|
|
4689
|
+
}
|
|
4690
|
+
/**
|
|
4691
|
+
* Placeholder for unsupported chart types
|
|
4692
|
+
*/
|
|
4693
|
+
const UnsupportedChart = ({ chartType, theme, }) => (jsxRuntimeExports.jsxs("div", { style: {
|
|
4694
|
+
width: '100%',
|
|
4695
|
+
height: '100%',
|
|
4696
|
+
display: 'flex',
|
|
4697
|
+
flexDirection: 'column',
|
|
4698
|
+
alignItems: 'center',
|
|
4699
|
+
justifyContent: 'center',
|
|
4700
|
+
padding: '24px',
|
|
4701
|
+
textAlign: 'center',
|
|
4702
|
+
color: theme === 'dark' ? '#FCD34D' : '#D97706',
|
|
4703
|
+
backgroundColor: theme === 'dark' ? 'rgba(120, 53, 15, 0.1)' : 'rgba(254, 243, 199, 0.5)',
|
|
4704
|
+
borderRadius: '8px',
|
|
4705
|
+
}, children: [jsxRuntimeExports.jsxs("svg", { width: "48", height: "48", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [jsxRuntimeExports.jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2", ry: "2" }), jsxRuntimeExports.jsx("line", { x1: "9", y1: "9", x2: "15", y2: "15" }), jsxRuntimeExports.jsx("line", { x1: "15", y1: "9", x2: "9", y2: "15" })] }), jsxRuntimeExports.jsxs("p", { style: { marginTop: '16px', fontWeight: 500 }, children: ["Unsupported chart type: \"", chartType, "\""] }), jsxRuntimeExports.jsx("p", { style: {
|
|
4706
|
+
marginTop: '8px',
|
|
4707
|
+
fontSize: '12px',
|
|
4708
|
+
color: theme === 'dark' ? '#FDE68A' : '#F59E0B',
|
|
4709
|
+
}, children: "Supported types: line, area, bar, column, singleValue, table, geo" })] }));
|
|
4710
|
+
/**
|
|
4711
|
+
* StreamChart Component
|
|
4712
|
+
*
|
|
4713
|
+
* Universal chart component for streaming data visualization.
|
|
4714
|
+
* Automatically renders the appropriate chart based on the config.chartType property.
|
|
4715
|
+
*
|
|
4716
|
+
* @example
|
|
4717
|
+
* ```tsx
|
|
4718
|
+
* <StreamChart
|
|
4719
|
+
* config={{
|
|
4720
|
+
* chartType: 'line',
|
|
4721
|
+
* xAxis: 'timestamp',
|
|
4722
|
+
* yAxis: 'value',
|
|
4723
|
+
* legend: true,
|
|
4724
|
+
* }}
|
|
4725
|
+
* data={{
|
|
4726
|
+
* columns: [
|
|
4727
|
+
* { name: 'timestamp', type: 'datetime64' },
|
|
4728
|
+
* { name: 'value', type: 'float64' },
|
|
4729
|
+
* ],
|
|
4730
|
+
* data: [...],
|
|
4731
|
+
* }}
|
|
4732
|
+
* theme="dark"
|
|
4733
|
+
* />
|
|
4734
|
+
* ```
|
|
4735
|
+
*/
|
|
4736
|
+
const StreamChart = ({ config, data, theme = 'dark', showTable = false, className, style, onConfigChange, }) => {
|
|
4737
|
+
// If showTable is true, always render as table
|
|
4738
|
+
if (showTable) {
|
|
4739
|
+
const tableConfig = {
|
|
4740
|
+
chartType: 'table',
|
|
4741
|
+
tableStyles: {},
|
|
4742
|
+
tableWrap: false,
|
|
4743
|
+
};
|
|
4744
|
+
return (jsxRuntimeExports.jsx(ChartErrorBoundary, { theme: theme, children: jsxRuntimeExports.jsx(DataTable, { config: tableConfig, data: data, theme: theme, className: className, style: style, onConfigChange: onConfigChange, maxRows: config.maxItems }) }));
|
|
4745
|
+
}
|
|
4746
|
+
// Render appropriate chart based on config type
|
|
4747
|
+
const chartComponent = useMemo(() => {
|
|
4748
|
+
// Phase 2: Use Grammar Abstraction for Time Series
|
|
4749
|
+
if (isTimeSeriesConfig(config)) {
|
|
4750
|
+
const spec = compileTimeSeriesConfig(config, theme);
|
|
4751
|
+
return (jsxRuntimeExports.jsx(VistralChart, { spec: spec, source: data, className: className, style: style }));
|
|
4752
|
+
}
|
|
4753
|
+
// Phase 2: Use Grammar Abstraction for Bar/Column
|
|
4754
|
+
if (isBarColumnConfig(config)) {
|
|
4755
|
+
const spec = compileBarColumnConfig(config, theme);
|
|
4756
|
+
return (jsxRuntimeExports.jsx(VistralChart, { spec: spec, source: data, className: className, style: style }));
|
|
4757
|
+
}
|
|
4758
|
+
if (isSingleValueConfig(config)) {
|
|
4759
|
+
return (jsxRuntimeExports.jsx(SingleValueChart, { config: config, data: data, theme: theme, className: className, style: style }));
|
|
4760
|
+
}
|
|
4761
|
+
if (isTableConfig(config)) {
|
|
4762
|
+
return (jsxRuntimeExports.jsx(DataTable, { config: config, data: data, theme: theme, className: className, style: style, onConfigChange: onConfigChange, maxRows: config.maxItems }));
|
|
4763
|
+
}
|
|
4764
|
+
if (isGeoConfig(config)) {
|
|
4765
|
+
return (jsxRuntimeExports.jsx(GeoChart, { config: config, data: data, theme: theme, className: className, style: style, maxItems: config.maxItems }));
|
|
4766
|
+
}
|
|
4767
|
+
// Unsupported chart type
|
|
4768
|
+
return jsxRuntimeExports.jsx(UnsupportedChart, { chartType: config.chartType, theme: theme });
|
|
4769
|
+
}, [config, data, theme, className, style, onConfigChange]);
|
|
4770
|
+
return jsxRuntimeExports.jsx(ChartErrorBoundary, { theme: theme, children: chartComponent });
|
|
4771
|
+
};
|
|
4772
|
+
|
|
4773
|
+
export { AXIS_HEIGHT_WITHOUT_TITLE, AXIS_HEIGHT_WITH_TITLE, DEFAULT_MAX_ITEMS, DEFAULT_PALETTE, DataTable, GeoChart, MAX_LEGEND_ITEMS, SingleValueChart, StreamChart, VistralChart, abbreviateNumber, allPalettes, applyChartTheme, applyColorEncoding, applyDataLabel, applyLegend, applyTemporalFilter, applyTooltip, calculateColumnStats, clamp, compileBarColumnConfig, compileTimeSeriesConfig, createDefaultConfig, darkTheme, debounce, StreamChart as default, filterByKey, filterByLatestTimestamp, findColumnIndex, findPaletteByLabel, findPaletteByValues, formatBytes, formatDuration, formatNumber, generateId, getChartThemeColors, getColumnsByType, getGeoChartDefaults, getPaletteKeyColor, getRowValue, getSeriesColors, getSingleValueDefaults, getTableDefaults, getTheme, getTimeMask, getUniqueValues, horizontalAxisLabelConfig, isBooleanColumn, isDateTimeColumn, isNumericColumn, isStringColumn, lightTheme, mergeDeep, multiColorPalettes, parseDateTime, processDataSource, renderChart, rowToArray, singleColorPalettes, truncateLabel, truncateWithEllipsis, useAutoConfig, useChart, useChartAnimation, useChartTheme, useDataSource, useDebouncedValue, useLastUpdated, usePrevious, useResizeObserver, useSparklineData, useStreamingData, verticalAxisLabelConfig };
|
|
4774
|
+
//# sourceMappingURL=index.esm.js.map
|