@apia/charts 2.0.9 → 2.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/charts/chartJsRenderer/ChartComponent.d.ts +22 -0
  2. package/dist/charts/chartJsRenderer/ChartComponent.d.ts.map +1 -0
  3. package/dist/charts/chartJsRenderer/ChartComponent.js +274 -0
  4. package/dist/charts/chartJsRenderer/ChartComponent.js.map +1 -0
  5. package/dist/charts/types.d.ts +173 -0
  6. package/dist/charts/types.d.ts.map +1 -0
  7. package/dist/index.d.ts +4 -334
  8. package/dist/index.js +2 -1455
  9. package/dist/index.js.map +1 -1
  10. package/dist/widgets/WidgetComponent.d.ts +10 -0
  11. package/dist/widgets/WidgetComponent.d.ts.map +1 -0
  12. package/dist/widgets/WidgetComponent.js +54 -0
  13. package/dist/widgets/WidgetComponent.js.map +1 -0
  14. package/dist/widgets/counter/Counter.js +117 -0
  15. package/dist/widgets/counter/Counter.js.map +1 -0
  16. package/dist/widgets/custom/useCustomWidget.js +64 -0
  17. package/dist/widgets/custom/useCustomWidget.js.map +1 -0
  18. package/dist/widgets/custom/util.js +9 -0
  19. package/dist/widgets/custom/util.js.map +1 -0
  20. package/dist/widgets/oxford/Oxford.js +248 -0
  21. package/dist/widgets/oxford/Oxford.js.map +1 -0
  22. package/dist/widgets/ring/Ring.js +133 -0
  23. package/dist/widgets/ring/Ring.js.map +1 -0
  24. package/dist/widgets/scale/Scale.js +150 -0
  25. package/dist/widgets/scale/Scale.js.map +1 -0
  26. package/dist/widgets/speedMeter/SpeedMeter.js +194 -0
  27. package/dist/widgets/speedMeter/SpeedMeter.js.map +1 -0
  28. package/dist/widgets/tLight/TLight.js +143 -0
  29. package/dist/widgets/tLight/TLight.js.map +1 -0
  30. package/dist/widgets/thermometer/Thermometer.js +151 -0
  31. package/dist/widgets/thermometer/Thermometer.js.map +1 -0
  32. package/dist/widgets/thermometer/util.js +38 -0
  33. package/dist/widgets/thermometer/util.js.map +1 -0
  34. package/dist/widgets/types.d.ts +108 -0
  35. package/dist/widgets/types.d.ts.map +1 -0
  36. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,1456 +1,3 @@
1
- import { jsx, jsxs } from '@apia/theme/jsx-runtime';
2
- import { noNaN, animate, addBoundary, getIndex, arrayOrArray, getValueByPath } from '@apia/util';
3
- import { Box, createElement, useThemeUI } from '@apia/theme';
4
- import React, { useState, useRef, useEffect, useCallback, useMemo } from 'react';
5
- import { useGauge } from 'use-gauge';
6
- import tinycolor from 'tinycolor2';
7
- import { uniqueId } from 'lodash-es';
8
- import { Chart, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend, BarController, BarElement, PieController, ArcElement, LineController } from 'chart.js';
9
- import { Chart as Chart$1 } from 'react-chartjs-2';
10
- import { createPlotlyRenderers, PivotTableUI, TableRenderers } from '@imc-trading/react-pivottable';
11
-
12
- const START_ANGLE$5 = 30;
13
- const END_ANGLE$5 = 330;
14
- const SpeedMeter = ({
15
- backgroundColor,
16
- colorRanges,
17
- currentValue,
18
- currentValueColor,
19
- currentValueFontSize,
20
- height,
21
- maxValue,
22
- minValue,
23
- pointerColor,
24
- scaleValuesSize,
25
- valueRanges,
26
- width
27
- }) => {
28
- const value = currentValue;
29
- const diameter = Math.min(height, width);
30
- const domainMax = noNaN(maxValue) ?? valueRanges[valueRanges.length - 1];
31
- const domainMin = noNaN(minValue) ?? valueRanges[0];
32
- const offset = 20;
33
- const gauge = useGauge({
34
- domain: [domainMin, domainMax],
35
- startAngle: START_ANGLE$5,
36
- endAngle: END_ANGLE$5,
37
- numTicks: valueRanges[valueRanges.length - 1] / 10 + 1,
38
- diameter
39
- });
40
- const needle = gauge.getNeedleProps({
41
- value: 0,
42
- baseRadius: 12,
43
- tipRadius: 2
44
- });
45
- function getColor(value2) {
46
- const index = valueRanges.findIndex(
47
- (range) => noNaN(value2) <= noNaN(range)
48
- );
49
- if (index === -1) {
50
- return colorRanges[0];
51
- }
52
- return colorRanges[index];
53
- }
54
- const angle = (END_ANGLE$5 - START_ANGLE$5) * value / (domainMax - domainMin);
55
- return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(
56
- "svg",
57
- {
58
- ...gauge.getSVGProps(),
59
- height: Math.max(width, height),
60
- width: Math.max(width, height),
61
- viewBox: `-${diameter / 2 + offset} -${diameter / 2 + offset} ${diameter + offset * 2} ${diameter + offset * 2}`,
62
- children: [
63
- /* @__PURE__ */ jsxs("g", { id: "arcs", children: [
64
- /* @__PURE__ */ jsx(
65
- "path",
66
- {
67
- ...gauge.getArcProps({
68
- offset: offset - 5,
69
- startAngle: 0,
70
- endAngle: 360
71
- }),
72
- stroke: "gray",
73
- fill: backgroundColor ?? "none",
74
- strokeLinecap: "round",
75
- strokeWidth: 5
76
- }
77
- ),
78
- valueRanges.map((innerValue, i) => {
79
- const valueToAngle = (value2) => {
80
- const angleRange = END_ANGLE$5 - START_ANGLE$5;
81
- const valueRange = domainMax - domainMin;
82
- const angle2 = START_ANGLE$5 + (value2 - domainMin) / valueRange * angleRange;
83
- return Math.round(angle2);
84
- };
85
- return /* @__PURE__ */ jsxs("g", { children: [
86
- /* @__PURE__ */ jsx(
87
- "path",
88
- {
89
- ...gauge.getArcProps({
90
- offset: -50,
91
- startAngle: i === 0 ? START_ANGLE$5 : valueToAngle(innerValue),
92
- endAngle: i === 0 ? valueToAngle(valueRanges[1]) : i === valueRanges.length - 1 ? END_ANGLE$5 : valueToAngle(valueRanges[i + 1])
93
- }),
94
- stroke: getColor(innerValue),
95
- opacity: "0.8",
96
- fill: "none",
97
- strokeLinecap: "round",
98
- strokeWidth: 2
99
- }
100
- ),
101
- /* @__PURE__ */ createElement(
102
- "path",
103
- {
104
- ...gauge.getArcProps({
105
- offset: -55,
106
- startAngle: i === 0 ? START_ANGLE$5 : valueToAngle(innerValue),
107
- endAngle: i === 0 ? valueToAngle(valueRanges[1]) : i === valueRanges.length - 1 ? END_ANGLE$5 : valueToAngle(valueRanges[i + 1])
108
- }),
109
- key: `${innerValue}_${i}`,
110
- stroke: getColor(innerValue),
111
- opacity: "0.8",
112
- fill: "none",
113
- strokeLinecap: "round",
114
- strokeWidth: 2
115
- }
116
- )
117
- ] }, `${innerValue}_${i}`);
118
- })
119
- ] }),
120
- /* @__PURE__ */ jsx("g", { id: "ticks", children: gauge.ticks.map((angle2) => {
121
- const angleToValue = (angle3) => {
122
- const angleRange = END_ANGLE$5 - START_ANGLE$5;
123
- const valueRange = domainMax - domainMin;
124
- const value2 = domainMin + (angle3 - START_ANGLE$5) / angleRange * valueRange;
125
- return Math.round(value2);
126
- };
127
- const asValue = angleToValue(angle2);
128
- const showText = asValue % 10 === 0;
129
- return /* @__PURE__ */ jsxs(React.Fragment, { children: [
130
- /* @__PURE__ */ jsx(
131
- "line",
132
- {
133
- stroke: "gray",
134
- strokeWidth: showText ? 4 : 2,
135
- ...gauge.getTickProps({ angle: angle2, length: showText ? 12 : 3 })
136
- }
137
- ),
138
- showText && /* @__PURE__ */ jsx(
139
- "text",
140
- {
141
- fill: "black",
142
- ...gauge.getLabelProps({ angle: angle2, offset: 20 }),
143
- style: { fontSize: `${scaleValuesSize ?? 30}px` },
144
- children: asValue
145
- }
146
- )
147
- ] }, `tick-group-${angle2}`);
148
- }) }),
149
- /* @__PURE__ */ jsxs("g", { id: "needle", children: [
150
- /* @__PURE__ */ jsx("circle", { fill: pointerColor, ...needle.base, r: 20 }),
151
- /* @__PURE__ */ jsx("circle", { fill: pointerColor, ...needle.base }),
152
- /* @__PURE__ */ jsx(
153
- "circle",
154
- {
155
- fill: pointerColor,
156
- opacity: "0.5",
157
- ...needle.tip,
158
- style: {
159
- transform: `rotate(${angle}deg)`,
160
- transition: "transform 500ms"
161
- }
162
- }
163
- ),
164
- /* @__PURE__ */ jsx(
165
- "polyline",
166
- {
167
- style: {
168
- transform: `rotate(${angle}deg)`,
169
- transition: "transform 500ms"
170
- },
171
- fill: pointerColor,
172
- opacity: "0.5",
173
- points: needle.points
174
- }
175
- ),
176
- /* @__PURE__ */ jsx("circle", { fill: "white", ...needle.base, r: 4 })
177
- ] }),
178
- /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
179
- "text",
180
- {
181
- textAnchor: "middle",
182
- y: diameter / 2,
183
- fill: currentValueColor,
184
- style: { fontSize: `${currentValueFontSize ?? 30}px` },
185
- children: value
186
- }
187
- ) })
188
- ]
189
- }
190
- ) });
191
- };
192
-
193
- const START_ANGLE$4 = 45;
194
- const END_ANGLE$4 = 315;
195
- const Oxford = ({
196
- backgroundColor,
197
- colorRanges,
198
- currentValue,
199
- currentValueColor,
200
- currentValueFontSize,
201
- height,
202
- maxValue,
203
- minValue,
204
- pointerColor,
205
- scaleValuesSize,
206
- valueRanges,
207
- width
208
- }) => {
209
- const value = currentValue;
210
- const diameter = Math.min(height, width);
211
- const domainMax = noNaN(maxValue) ?? valueRanges[valueRanges.length - 1];
212
- const domainMin = noNaN(minValue) ?? valueRanges[0];
213
- const offset = 20;
214
- const gauge = useGauge({
215
- domain: [domainMin, domainMax],
216
- startAngle: START_ANGLE$4,
217
- endAngle: END_ANGLE$4,
218
- numTicks: 10 + 1,
219
- diameter
220
- });
221
- const gauge2 = useGauge({
222
- domain: [valueRanges[0], valueRanges[valueRanges.length - 1]],
223
- startAngle: START_ANGLE$4,
224
- endAngle: END_ANGLE$4,
225
- numTicks: valueRanges[valueRanges.length - 1] - valueRanges[0] + 1,
226
- diameter
227
- });
228
- const needle = gauge.getNeedleProps({
229
- value: 0,
230
- baseRadius: 12,
231
- tipRadius: 2
232
- });
233
- const angle = (END_ANGLE$4 - START_ANGLE$4) * value / (domainMax - domainMin);
234
- function getColor(value2) {
235
- const index = valueRanges.findIndex(
236
- (range) => noNaN(value2) <= noNaN(range)
237
- );
238
- if (index === -1) {
239
- return colorRanges[0];
240
- }
241
- return colorRanges[index];
242
- }
243
- return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(
244
- "svg",
245
- {
246
- ...gauge.getSVGProps(),
247
- height: Math.max(width, height),
248
- width: Math.max(width, height),
249
- viewBox: `-${diameter / 2 + offset} -${diameter / 2 + offset} ${diameter + offset * 2} ${diameter + offset * 2}`,
250
- children: [
251
- /* @__PURE__ */ jsxs("g", { id: "arcs", children: [
252
- /* @__PURE__ */ jsx(
253
- "path",
254
- {
255
- ...gauge.getArcProps({
256
- offset: offset - 5,
257
- startAngle: 0,
258
- endAngle: 360
259
- }),
260
- stroke: "black",
261
- opacity: "1",
262
- fill: backgroundColor !== "" && backgroundColor !== void 0 ? tinycolor(backgroundColor).setAlpha(0.5).toPercentageRgbString() : "none",
263
- strokeLinecap: "round",
264
- strokeWidth: 5,
265
- vectorEffect: "non-scaling-stroke"
266
- }
267
- ),
268
- valueRanges.map((innerValue, i) => {
269
- if (!valueRanges[i + 1]) {
270
- return null;
271
- }
272
- const valueToAngle = (value2) => {
273
- const angleRange = END_ANGLE$4 - START_ANGLE$4;
274
- const valueRange = domainMax - domainMin;
275
- const angle2 = START_ANGLE$4 + (value2 - domainMin) / valueRange * angleRange;
276
- return Math.round(angle2);
277
- };
278
- return /* @__PURE__ */ jsxs("g", { children: [
279
- /* @__PURE__ */ jsx(
280
- "path",
281
- {
282
- ...gauge.getArcProps({
283
- offset: offset - 5,
284
- startAngle: i === 0 ? START_ANGLE$4 : valueToAngle(innerValue),
285
- endAngle: i === 0 ? valueToAngle(valueRanges[1]) : i === valueRanges.length - 1 ? END_ANGLE$4 : valueToAngle(valueRanges[i + 1])
286
- }),
287
- stroke: "black",
288
- opacity: "0.8",
289
- fill: "none",
290
- strokeLinecap: "square",
291
- strokeWidth: 5,
292
- vectorEffect: "non-scaling-stroke"
293
- }
294
- ),
295
- /* @__PURE__ */ jsx(
296
- "path",
297
- {
298
- ...gauge.getArcProps({
299
- offset: -20,
300
- startAngle: i === 0 ? START_ANGLE$4 : valueToAngle(innerValue),
301
- endAngle: i === 0 ? valueToAngle(valueRanges[1]) : i === valueRanges.length - 1 ? END_ANGLE$4 : valueToAngle(valueRanges[i + 1])
302
- }),
303
- stroke: getColor(innerValue),
304
- opacity: "0.1",
305
- fill: "none",
306
- strokeLinecap: "butt",
307
- strokeWidth: 75,
308
- vectorEffect: "non-scaling-stroke"
309
- }
310
- ),
311
- /* @__PURE__ */ createElement(
312
- "path",
313
- {
314
- ...gauge.getArcProps({
315
- offset: -55,
316
- startAngle: i === 0 ? START_ANGLE$4 : valueToAngle(innerValue),
317
- endAngle: i === 0 ? valueToAngle(valueRanges[1]) : i === valueRanges.length - 1 ? END_ANGLE$4 : valueToAngle(valueRanges[i + 1])
318
- }),
319
- key: `${innerValue}_${i}`,
320
- stroke: getColor(innerValue) || "#999",
321
- opacity: "0.8",
322
- fill: "none",
323
- strokeLinecap: "butt",
324
- strokeWidth: 10,
325
- vectorEffect: "non-scaling-stroke"
326
- }
327
- )
328
- ] }, `${innerValue}_${i}`);
329
- })
330
- ] }),
331
- /* @__PURE__ */ jsxs("g", { id: "ticks", children: [
332
- gauge.ticks.map((angle2, i) => {
333
- const angleToValue = (angle3) => {
334
- const angleRange = END_ANGLE$4 - START_ANGLE$4;
335
- const valueRange = domainMax - domainMin;
336
- const value2 = domainMin + (angle3 - START_ANGLE$4) / angleRange * valueRange;
337
- return Math.round(value2);
338
- };
339
- const asValue = angleToValue(angle2);
340
- const showText = asValue % 10 === 0;
341
- return /* @__PURE__ */ jsxs(React.Fragment, { children: [
342
- /* @__PURE__ */ jsx(
343
- "line",
344
- {
345
- stroke: "gray",
346
- strokeWidth: showText ? 4 : 2,
347
- ...gauge.getTickProps({ angle: angle2, length: showText ? 12 : 3 }),
348
- vectorEffect: "non-scaling-stroke"
349
- }
350
- ),
351
- showText && /* @__PURE__ */ jsx(
352
- "text",
353
- {
354
- fill: "black",
355
- ...gauge.getLabelProps({
356
- angle: angle2,
357
- offset: 20
358
- }),
359
- style: {
360
- fontSize: `${scaleValuesSize ?? 30}px`
361
- },
362
- children: asValue
363
- }
364
- )
365
- ] }, `tick-group-${angle2}_ ${i}`);
366
- }),
367
- gauge2.ticks.map((angle2, i) => {
368
- return /* @__PURE__ */ jsx(React.Fragment, { children: /* @__PURE__ */ jsx(
369
- "line",
370
- {
371
- stroke: "gray",
372
- strokeWidth: 2,
373
- ...gauge.getTickProps({
374
- angle: angle2,
375
- length: 3
376
- }),
377
- vectorEffect: "non-scaling-stroke"
378
- }
379
- ) }, `tick-group-${angle2}_ ${i}_2`);
380
- })
381
- ] }),
382
- /* @__PURE__ */ jsxs("g", { id: "needle", children: [
383
- /* @__PURE__ */ jsx("circle", { fill: pointerColor, ...needle.base, r: 20 }),
384
- /* @__PURE__ */ jsx("circle", { fill: pointerColor, ...needle.base }),
385
- /* @__PURE__ */ jsx(
386
- "circle",
387
- {
388
- fill: pointerColor,
389
- opacity: "0.5",
390
- ...needle.tip,
391
- style: {
392
- transform: `rotate(${angle}deg)`,
393
- transition: "transform 500ms"
394
- }
395
- }
396
- ),
397
- /* @__PURE__ */ jsx(
398
- "polyline",
399
- {
400
- style: {
401
- transform: `rotate(${angle}deg)`,
402
- transition: "transform 500ms"
403
- },
404
- fill: pointerColor,
405
- opacity: "0.5",
406
- points: needle.points
407
- }
408
- ),
409
- /* @__PURE__ */ jsx("circle", { fill: "white", ...needle.base, r: 4 })
410
- ] }),
411
- /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
412
- "text",
413
- {
414
- textAnchor: "middle",
415
- alignmentBaseline: "text-before-edge",
416
- y: diameter / 5,
417
- style: { fontSize: `${currentValueFontSize ?? 30}px` },
418
- fill: currentValueColor,
419
- children: value
420
- }
421
- ) })
422
- ]
423
- }
424
- ) });
425
- };
426
-
427
- const START_ANGLE$3 = 0;
428
- const END_ANGLE$3 = 360;
429
- const Counter = ({
430
- addBorder = false,
431
- colorRanges,
432
- currentValue,
433
- valueRanges,
434
- maxValue,
435
- minValue,
436
- currentValueFontSize
437
- }) => {
438
- const [value, setValue] = useState(noNaN(currentValue) ?? 0);
439
- const actualWidth = (currentValueFontSize ?? 80) * 3 * 0.8;
440
- const diameter = actualWidth;
441
- const domainMax = noNaN(maxValue) ?? valueRanges[valueRanges.length - 1];
442
- const domainMin = noNaN(minValue) ?? valueRanges[0];
443
- const gauge = useGauge({
444
- domain: [domainMin, domainMax],
445
- startAngle: START_ANGLE$3,
446
- endAngle: END_ANGLE$3,
447
- numTicks: 0,
448
- diameter
449
- });
450
- function getColor(value2) {
451
- const index = valueRanges.findIndex(
452
- (range) => noNaN(value2) <= noNaN(range)
453
- );
454
- if (index === -1) {
455
- return colorRanges[0];
456
- }
457
- return colorRanges[index - 1] ?? colorRanges[index];
458
- }
459
- const lastCurrentValue = useRef(0);
460
- useEffect(() => {
461
- const difference = noNaN(currentValue) - lastCurrentValue.current;
462
- return animate(
463
- 500,
464
- (progress) => {
465
- const step = addBoundary(
466
- difference * progress + lastCurrentValue.current,
467
- domainMin,
468
- domainMax
469
- );
470
- setValue(Math.round(step));
471
- },
472
- () => {
473
- lastCurrentValue.current = noNaN(currentValue);
474
- }
475
- );
476
- }, [noNaN(currentValue)]);
477
- return /* @__PURE__ */ jsxs(Box, { sx: { position: "relative" }, className: "widgetContainer__Counter", children: [
478
- /* @__PURE__ */ jsx(
479
- "svg",
480
- {
481
- ...gauge.getSVGProps(),
482
- height: actualWidth,
483
- width: actualWidth,
484
- viewBox: void 0,
485
- children: /* @__PURE__ */ jsx("g", { id: "arcs", children: addBorder && `${value}`.length < 4 && /* @__PURE__ */ jsx(
486
- "ellipse",
487
- {
488
- cx: actualWidth / 2,
489
- cy: actualWidth / 2,
490
- rx: actualWidth / 2 - 5,
491
- ry: actualWidth / 2 - 5,
492
- stroke: "gray",
493
- opacity: "0.2",
494
- fill: "none",
495
- strokeLinecap: "round",
496
- strokeWidth: 2
497
- }
498
- ) })
499
- }
500
- ),
501
- /* @__PURE__ */ jsx(
502
- "svg",
503
- {
504
- height: actualWidth,
505
- width: actualWidth,
506
- style: { position: "absolute", left: 0, top: 0 },
507
- children: /* @__PURE__ */ jsx(
508
- "text",
509
- {
510
- x: actualWidth / 2,
511
- y: actualWidth / 2 - 5,
512
- textAnchor: "middle",
513
- style: {
514
- fontSize: `${currentValueFontSize ?? 80}px`,
515
- transition: "fill 0.5s"
516
- },
517
- alignmentBaseline: "central",
518
- fill: getColor(value),
519
- children: value
520
- }
521
- )
522
- }
523
- )
524
- ] });
525
- };
526
-
527
- const START_ANGLE$2 = 0;
528
- const END_ANGLE$2 = 360;
529
- const TLight = ({
530
- addBorder = false,
531
- colorRanges,
532
- maxValue,
533
- minValue,
534
- currentValue,
535
- height,
536
- valueRanges,
537
- width,
538
- currentValueColor,
539
- currentValueFontSize
540
- }) => {
541
- const [value, setValue] = useState(noNaN(currentValue));
542
- const diameter = Math.min(height, width);
543
- const domainMax = noNaN(maxValue) ?? valueRanges[valueRanges.length - 1];
544
- const domainMin = noNaN(minValue) ?? valueRanges[0];
545
- const gauge = useGauge({
546
- domain: [domainMin, domainMax],
547
- startAngle: START_ANGLE$2,
548
- endAngle: END_ANGLE$2,
549
- numTicks: 0,
550
- diameter
551
- });
552
- function getColor(value2) {
553
- const index = valueRanges.findIndex((range) => value2 < range);
554
- if (index === -1) {
555
- return colorRanges[0];
556
- }
557
- return colorRanges[index - 1] ?? colorRanges[index];
558
- }
559
- const hasRendered = useRef(false);
560
- const onRenderSvg = useCallback(
561
- (el) => {
562
- if (!el || hasRendered.current)
563
- return;
564
- hasRendered.current = true;
565
- const svgElement = el;
566
- const pathElement = el.querySelector("#TLight_arcs");
567
- if (!(svgElement && pathElement)) {
568
- return;
569
- }
570
- const pathBox = pathElement.getBoundingClientRect();
571
- const svgBox = svgElement.getBoundingClientRect();
572
- const pathX = pathBox.x - svgBox.x;
573
- const pathY = pathBox.y - svgBox.y;
574
- const viewBox = `${pathX - diameter / 2} ${pathY - diameter / 2} ${diameter} ${diameter}`;
575
- svgElement.setAttribute("viewBox", viewBox);
576
- svgElement.style.visibility = "visible";
577
- },
578
- [diameter]
579
- );
580
- const lastCurrentValue = useRef(0);
581
- useEffect(() => {
582
- const difference = noNaN(currentValue) - lastCurrentValue.current;
583
- return animate(
584
- 500,
585
- (progress) => {
586
- const step = addBoundary(
587
- difference * progress + lastCurrentValue.current,
588
- domainMin,
589
- domainMax
590
- );
591
- setValue(Math.round(step));
592
- },
593
- () => {
594
- lastCurrentValue.current = noNaN(currentValue);
595
- }
596
- );
597
- }, [noNaN(currentValue)]);
598
- return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(
599
- "svg",
600
- {
601
- ...gauge.getSVGProps(),
602
- style: { visibility: "hidden" },
603
- height: Math.max(width, height),
604
- width: Math.max(width, height),
605
- id: "TLight_svg",
606
- ref: onRenderSvg,
607
- viewBox: `-${diameter / 2} -${diameter / 2} ${diameter} ${diameter}`,
608
- children: [
609
- /* @__PURE__ */ jsxs("g", { id: "TLight_arcs", children: [
610
- /* @__PURE__ */ jsx(
611
- "path",
612
- {
613
- ...gauge.getArcProps({
614
- startAngle: START_ANGLE$2,
615
- endAngle: END_ANGLE$2
616
- }),
617
- fill: getColor(value),
618
- id: "TLight_path",
619
- style: { transition: "fill 0.3s" }
620
- }
621
- ),
622
- addBorder && /* @__PURE__ */ jsx(
623
- "path",
624
- {
625
- ...gauge.getArcProps({
626
- offset: -2.5,
627
- startAngle: START_ANGLE$2,
628
- endAngle: END_ANGLE$2
629
- }),
630
- stroke: "black",
631
- fill: "transparent",
632
- strokeLinecap: "round",
633
- strokeWidth: 5,
634
- id: "TLight_path"
635
- }
636
- )
637
- ] }),
638
- /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
639
- "text",
640
- {
641
- textAnchor: "middle",
642
- style: { fontSize: `${currentValueFontSize ?? 100}pt` },
643
- alignmentBaseline: "central",
644
- fill: currentValueColor,
645
- children: value
646
- }
647
- ) })
648
- ]
649
- }
650
- ) });
651
- };
652
-
653
- const colorGetter = (valueRanges, colorRanges, innerValue) => {
654
- let color = "";
655
- valueRanges.forEach((value, index) => {
656
- if (value >= innerValue && valueRanges[index - 1] <= innerValue) {
657
- color = colorRanges[index - 1];
658
- }
659
- });
660
- return color;
661
- };
662
- function getColor(valueRanges, colorRanges, value) {
663
- const index = valueRanges.findIndex((range) => noNaN(value) <= noNaN(range));
664
- if (index === -1) {
665
- return colorRanges[0];
666
- }
667
- return colorRanges[index];
668
- }
669
- function getInnerColor(valueRanges, colorRanges, value) {
670
- const index = valueRanges.findIndex((range) => value < range);
671
- if (index === -1) {
672
- return colorRanges[0];
673
- }
674
- console.log({ colorRanges, index });
675
- return colorRanges[index - 1] ?? colorRanges[index];
676
- }
677
- const valueToTickPercent = (domainMax, baseValue, value) => {
678
- const range = domainMax - (baseValue ?? 0);
679
- const percentage = 100 - (value - (baseValue ?? 0)) / range * 100;
680
- return Math.round(percentage);
681
- };
682
-
683
- const valueToPercent = (domainMax, baseValue, value) => {
684
- const range = domainMax - (baseValue ?? 0);
685
- const percentage = 100 - (value - (baseValue ?? 0)) / range * 100;
686
- const test = percentage * 69 / 100;
687
- return Math.round(test);
688
- };
689
-
690
- const useCustomWidget = ({
691
- maxValue,
692
- minValue,
693
- currentValue,
694
- uId
695
- }) => {
696
- const baseValue = minValue;
697
- const domainMax = maxValue;
698
- const [yDifference, setYDifference] = useState(0);
699
- const svgRect = useRef({});
700
- const pathRect = useRef({});
701
- const onRenderRect = useCallback(
702
- (el) => {
703
- if (!el)
704
- return;
705
- const svgElement = el.closest("svg");
706
- const pathElement = svgElement?.querySelector(`#path_${uId}`);
707
- if (!svgElement)
708
- throw new Error("No svg");
709
- if (!pathElement)
710
- throw new Error("No path");
711
- const svgBox = svgElement.getBoundingClientRect();
712
- const pathBox = pathElement.getBoundingClientRect();
713
- const pathY2 = pathBox.y - svgBox.y;
714
- svgRect.current = svgBox;
715
- pathRect.current = pathBox;
716
- setYDifference(pathY2);
717
- },
718
- [uId]
719
- );
720
- const pathX = noNaN(pathRect.current.x - svgRect.current.x);
721
- const pathY = noNaN(pathRect.current.y - svgRect.current.y);
722
- const pathWidth = noNaN(pathRect.current.width);
723
- const pathHeight = noNaN(pathRect.current.height);
724
- const viewBox = `${pathX} ${pathY} ${pathWidth} ${pathHeight}`;
725
- const rectProps = {
726
- y: noNaN(
727
- valueToPercent(domainMax, baseValue, currentValue) * pathHeight / 100 + yDifference
728
- ),
729
- x: pathX,
730
- width: pathWidth,
731
- height: pathHeight,
732
- style: {
733
- visibility: "visible",
734
- transition: "y 0.5s, fill 0.5s"
735
- }
736
- };
737
- return {
738
- rectRef: onRenderRect,
739
- svgViewBox: viewBox,
740
- rectProps,
741
- pathX,
742
- pathY,
743
- pathRect,
744
- svgRect
745
- };
746
- };
747
-
748
- const Thermometer = ({
749
- colorRanges,
750
- maxValue,
751
- minValue,
752
- currentValue,
753
- height,
754
- valueRanges,
755
- width,
756
- currentValueFontSize
757
- }) => {
758
- const value = currentValue;
759
- const baseValue = noNaN(minValue) ?? valueRanges[0];
760
- const domainMax = noNaN(maxValue) ?? valueRanges[valueRanges.length - 1];
761
- const pathDValue = `m 179.6875,717.73633 c -0.45013,0 -0.8125,0.36237 -0.8125,0.8125 l 0,8.46289 a 2.3125,2.3125 0 0 0 -1.5,2.16211 2.3125,2.3125 0 0 0 2.3125,2.3125 2.3125,2.3125 0 0 0 2.3125,-2.3125 2.3125,2.3125 0 0 0 -1.5,-2.16211 l 0,-8.46289 c 0,-0.45013 -0.36237,-0.8125 -0.8125,-0.8125 z`;
762
- const uId = useMemo(() => uniqueId(), []);
763
- const { rectProps, rectRef, svgViewBox, pathX, pathY } = useCustomWidget({
764
- currentValue: value,
765
- maxValue: domainMax,
766
- minValue: baseValue,
767
- uId
768
- });
769
- const boxValues = {
770
- height: noNaN(Math.max(width, height) - Math.max(width, height) * 0.31),
771
- width: noNaN(Math.max(width, height)),
772
- x: pathX,
773
- y: pathY
774
- };
775
- const tickArray = valueRanges.map((val, i) => {
776
- return {
777
- height: boxValues.height * (valueToTickPercent(domainMax, baseValue, val) / 100),
778
- color: !valueRanges[i + 1] ? "black" : colorGetter(valueRanges, colorRanges, val),
779
- value: val
780
- };
781
- });
782
- return /* @__PURE__ */ jsxs(Box, { sx: { position: "relative" }, children: [
783
- /* @__PURE__ */ jsxs(
784
- "svg",
785
- {
786
- height: Math.max(width, height),
787
- width: Math.max(width, height),
788
- id: `svg_${uId}`,
789
- viewBox: svgViewBox,
790
- style: { position: "relative", top: "10px" },
791
- children: [
792
- /* @__PURE__ */ jsx("clipPath", { id: "clipPath", children: /* @__PURE__ */ jsx("path", { d: pathDValue }) }),
793
- /* @__PURE__ */ jsx("mask", { id: "myMask", children: /* @__PURE__ */ jsx("path", { d: pathDValue, id: "maskPath", fill: "white" }) }),
794
- /* @__PURE__ */ jsx("path", { d: pathDValue, id: `path_${uId}`, fill: "white" }),
795
- /* @__PURE__ */ jsx(
796
- "rect",
797
- {
798
- fill: getInnerColor(valueRanges, colorRanges, value),
799
- id: `rect_${uId}`,
800
- mask: "url(#myMask)",
801
- ref: rectRef,
802
- ...rectProps
803
- }
804
- ),
805
- /* @__PURE__ */ jsx(
806
- "path",
807
- {
808
- d: pathDValue,
809
- id: "path",
810
- fill: "none",
811
- stroke: "white",
812
- strokeWidth: 10,
813
- clipPath: "url(#clipPath)",
814
- vectorEffect: "non-scaling-stroke"
815
- }
816
- ),
817
- /* @__PURE__ */ jsx(
818
- "path",
819
- {
820
- clipPath: "url(#clipPath)",
821
- d: pathDValue,
822
- id: "path",
823
- fill: "none",
824
- stroke: "black",
825
- strokeWidth: 5,
826
- vectorEffect: "non-scaling-stroke"
827
- }
828
- )
829
- ]
830
- }
831
- ),
832
- /* @__PURE__ */ jsxs(
833
- "svg",
834
- {
835
- height: Math.max(width, height) + 10,
836
- width: Math.max(width, height),
837
- style: { position: "absolute", left: 0, top: 0 },
838
- children: [
839
- boxValues.x && /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
840
- "text",
841
- {
842
- x: Math.max(width, height) / 2,
843
- y: Math.max(width, height) - Math.max(width, height) / 6 + 10,
844
- style: {
845
- fontSize: `${noNaN(currentValueFontSize) ?? 50}px`
846
- },
847
- textAnchor: "middle",
848
- alignmentBaseline: "central",
849
- vectorEffect: "non-scaling-stroke",
850
- children: value
851
- }
852
- ) }),
853
- tickArray.map((tick, i) => {
854
- return /* @__PURE__ */ jsxs("g", { children: [
855
- /* @__PURE__ */ jsx(
856
- "rect",
857
- {
858
- x: i === 0 ? Math.max(width, height) / 2 + 30 : Math.max(width, height) / 2 + 20,
859
- y: tick.height + 10,
860
- width: "15px",
861
- height: "3px",
862
- vectorEffect: "non-scaling-stroke",
863
- fill: getColor(valueRanges, colorRanges, tick.value)
864
- }
865
- ),
866
- /* @__PURE__ */ jsx(
867
- "text",
868
- {
869
- x: i === 0 ? Math.max(width, height) - Math.max(width, height) / 3 + 10 : Math.max(width, height) - Math.max(width, height) / 3,
870
- y: tickArray[i + 1] ? tick.height + 16 : tick.height + 1.5,
871
- textAnchor: "middle",
872
- alignmentBaseline: tickArray[i + 1] ? "auto" : "text-before-edge",
873
- children: tick.value
874
- }
875
- )
876
- ] }, i);
877
- })
878
- ]
879
- }
880
- )
881
- ] });
882
- };
883
-
884
- const START_ANGLE$1 = 90;
885
- const END_ANGLE$1 = 270;
886
- const Scale = ({
887
- currentValue,
888
- currentValueFontSize,
889
- height,
890
- maxValue,
891
- minValue,
892
- pointerColor,
893
- scaleValuesSize,
894
- valueRanges,
895
- width
896
- }) => {
897
- const allTicks = false;
898
- const value = currentValue;
899
- const diameter = Math.min(height, width);
900
- const domainMax = noNaN(maxValue) ?? valueRanges[valueRanges.length - 1];
901
- const domainMin = noNaN(minValue) ?? valueRanges[0];
902
- const offset = 20;
903
- const gauge = useGauge({
904
- domain: [domainMin, domainMax],
905
- startAngle: START_ANGLE$1,
906
- endAngle: END_ANGLE$1,
907
- numTicks: 10 + 1,
908
- diameter
909
- });
910
- useGauge({
911
- domain: [valueRanges[0], valueRanges[valueRanges.length - 1]],
912
- startAngle: START_ANGLE$1,
913
- endAngle: END_ANGLE$1,
914
- numTicks: valueRanges[valueRanges.length - 1] - valueRanges[0] + 1,
915
- diameter
916
- });
917
- const needle = gauge.getNeedleProps({
918
- value: 0,
919
- baseRadius: 12,
920
- tipRadius: 2
921
- });
922
- const angle = (END_ANGLE$1 - START_ANGLE$1) * value / (domainMax - domainMin);
923
- return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(
924
- "svg",
925
- {
926
- ...gauge.getSVGProps(),
927
- height: Math.max(width, height),
928
- width: Math.max(width, height),
929
- viewBox: `-${diameter / 2 + offset} -${diameter / 2 + offset} ${diameter + offset * 2} ${diameter / 2 + offset * 2}`,
930
- children: [
931
- /* @__PURE__ */ jsx("g", { id: "arcs", children: /* @__PURE__ */ jsx(
932
- "path",
933
- {
934
- ...gauge.getArcProps({
935
- offset: offset - 5,
936
- startAngle: 90,
937
- endAngle: 270
938
- }),
939
- stroke: "gray",
940
- opacity: "0.2",
941
- fill: "none",
942
- strokeLinecap: "round",
943
- strokeWidth: 5
944
- }
945
- ) }),
946
- /* @__PURE__ */ jsxs("g", { id: "ticks", children: [
947
- gauge.ticks.map((angle2) => {
948
- const angleToValue = (angle3) => {
949
- const angleRange = END_ANGLE$1 - START_ANGLE$1;
950
- const valueRange = domainMax - domainMin;
951
- const value2 = domainMin + (angle3 - START_ANGLE$1) / angleRange * valueRange;
952
- return Math.round(value2);
953
- };
954
- const asValue = angleToValue(angle2);
955
- const showText = asValue % 10 === 0;
956
- return /* @__PURE__ */ jsxs(React.Fragment, { children: [
957
- /* @__PURE__ */ jsx(
958
- "line",
959
- {
960
- stroke: "gray",
961
- strokeWidth: showText ? 4 : 2,
962
- ...gauge.getTickProps({ angle: angle2, length: showText ? 12 : 3 })
963
- }
964
- ),
965
- showText && /* @__PURE__ */ jsx(
966
- "text",
967
- {
968
- fill: "black",
969
- ...gauge.getLabelProps({ angle: angle2, offset: 20 }),
970
- style: { fontSize: `${scaleValuesSize ?? 30}px` },
971
- children: asValue
972
- }
973
- )
974
- ] }, `tick-group-${angle2}`);
975
- }),
976
- allTicks
977
- ] }),
978
- /* @__PURE__ */ jsxs("g", { id: "needle", children: [
979
- /* @__PURE__ */ jsx("circle", { fill: pointerColor, ...needle.base, r: 20 }),
980
- /* @__PURE__ */ jsx("circle", { fill: pointerColor, ...needle.base }),
981
- /* @__PURE__ */ jsx(
982
- "circle",
983
- {
984
- fill: pointerColor,
985
- opacity: "0.5",
986
- ...needle.tip,
987
- style: {
988
- transform: `rotate(${angle}deg)`,
989
- transition: "transform 500ms"
990
- }
991
- }
992
- ),
993
- /* @__PURE__ */ jsx(
994
- "polyline",
995
- {
996
- style: {
997
- transform: `rotate(${angle}deg)`,
998
- transition: "transform 500ms"
999
- },
1000
- fill: pointerColor,
1001
- opacity: "0.5",
1002
- points: needle.points
1003
- }
1004
- ),
1005
- /* @__PURE__ */ jsx("circle", { fill: "white", ...needle.base, r: 4 })
1006
- ] }),
1007
- /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
1008
- "text",
1009
- {
1010
- textAnchor: "middle",
1011
- style: { fontSize: `${currentValueFontSize ?? 30}px` },
1012
- y: -diameter / 4 + 20,
1013
- children: value
1014
- }
1015
- ) })
1016
- ]
1017
- }
1018
- ) });
1019
- };
1020
-
1021
- const START_ANGLE = 0;
1022
- const END_ANGLE = 360;
1023
- const Ring = ({
1024
- colorRanges,
1025
- maxValue,
1026
- minValue,
1027
- currentValue,
1028
- height,
1029
- valueRanges,
1030
- ringEmptyColor,
1031
- ringWidth,
1032
- width,
1033
- currentValueColor,
1034
- currentValueFontSize
1035
- }) => {
1036
- const [value, setValue] = useState(currentValue);
1037
- const diameter = Math.min(height, width);
1038
- const offset = 20;
1039
- const domainMax = noNaN(maxValue) ?? valueRanges[valueRanges.length - 1];
1040
- const domainMin = noNaN(minValue) ?? valueRanges[0];
1041
- const gauge = useGauge({
1042
- domain: [domainMin, domainMax],
1043
- startAngle: START_ANGLE,
1044
- endAngle: END_ANGLE,
1045
- numTicks: 0,
1046
- diameter
1047
- });
1048
- const lastCurrentValue = useRef(0);
1049
- useEffect(() => {
1050
- const difference = currentValue - lastCurrentValue.current;
1051
- return animate(
1052
- 500,
1053
- (progress) => {
1054
- const step = addBoundary(
1055
- difference * progress + lastCurrentValue.current,
1056
- domainMin,
1057
- domainMax
1058
- );
1059
- setValue(Math.round(step));
1060
- },
1061
- () => {
1062
- lastCurrentValue.current = currentValue;
1063
- }
1064
- );
1065
- }, [currentValue]);
1066
- function getColor(value2) {
1067
- const index = valueRanges.findIndex((range) => value2 <= range);
1068
- if (index === -1) {
1069
- return colorRanges[0];
1070
- }
1071
- return colorRanges[index - 1] ?? colorRanges[index];
1072
- }
1073
- const valueToAngle = (value2) => {
1074
- const angleRange = 360;
1075
- const valueRange = domainMax - domainMin;
1076
- const angle = (value2 - domainMin) / valueRange * angleRange;
1077
- return Math.round(angle);
1078
- };
1079
- return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(
1080
- "svg",
1081
- {
1082
- ...gauge.getSVGProps(),
1083
- height: Math.max(width, height),
1084
- width: Math.max(width, height),
1085
- viewBox: `-${diameter / 2 + offset} -${diameter / 2 + offset} ${diameter + offset * 2} ${diameter + offset * 2}`,
1086
- children: [
1087
- /* @__PURE__ */ jsxs("g", { id: "arcs", children: [
1088
- /* @__PURE__ */ jsx(
1089
- "path",
1090
- {
1091
- ...gauge.getArcProps({
1092
- offset: offset - ((noNaN(ringWidth) ?? 0) < 0 ? (noNaN(ringWidth) ?? 0) * 100 : noNaN(ringWidth) ?? 0),
1093
- startAngle: START_ANGLE,
1094
- endAngle: END_ANGLE
1095
- }),
1096
- stroke: ringEmptyColor ?? "transparent",
1097
- fill: "none",
1098
- strokeLinecap: "round",
1099
- strokeWidth: (noNaN(ringWidth) ?? 0) < 0 ? (noNaN(ringWidth) ?? 0) * 100 : noNaN(ringWidth) ?? 0
1100
- }
1101
- ),
1102
- /* @__PURE__ */ jsx(
1103
- "path",
1104
- {
1105
- ...gauge.getArcProps({
1106
- offset: offset - ((noNaN(ringWidth) ?? 0) < 0 ? (noNaN(ringWidth) ?? 0) * 100 : noNaN(ringWidth) ?? 0),
1107
- startAngle: 180,
1108
- endAngle: valueToAngle(value) === 360 ? 179 + valueToAngle(value) : 180 + valueToAngle(value)
1109
- }),
1110
- stroke: getColor(value),
1111
- opacity: "0.8",
1112
- fill: "none",
1113
- strokeLinecap: "square",
1114
- strokeWidth: (noNaN(ringWidth) ?? 0) < 0 ? (noNaN(ringWidth) ?? 0) * 100 : noNaN(ringWidth) ?? 0,
1115
- style: {
1116
- transition: "stroke 0.5s"
1117
- }
1118
- }
1119
- )
1120
- ] }),
1121
- /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
1122
- "text",
1123
- {
1124
- textAnchor: "middle",
1125
- style: { fontSize: `${currentValueFontSize ?? 30}px` },
1126
- alignmentBaseline: "central",
1127
- color: currentValueColor,
1128
- children: value
1129
- }
1130
- ) })
1131
- ]
1132
- }
1133
- ) });
1134
- };
1135
-
1136
- const WidgetComponent = ({
1137
- data,
1138
- type
1139
- }) => {
1140
- const CurrentWidget = getIndex(
1141
- [SpeedMeter, Oxford, Counter, TLight, Thermometer, Scale, Ring],
1142
- [
1143
- type === "SpeedMeter",
1144
- type === "Oxford",
1145
- type === "Counter",
1146
- type === "TLight",
1147
- type === "Thermometer",
1148
- type === "Scale",
1149
- type === "Ring"
1150
- ],
1151
- 0
1152
- );
1153
- const wigetTypeData = data;
1154
- const widgetData = wigetTypeData;
1155
- let valueRanges = [];
1156
- let colorRanges = [];
1157
- if (data.zones && arrayOrArray(data.zones.Zone).length > 0) {
1158
- valueRanges = Array.from(
1159
- new Set(
1160
- arrayOrArray(data.zones.Zone).map((zone) => {
1161
- return [Number(zone.minimum), Number(zone.maximum)];
1162
- }).flat().sort((a, b) => a - b)
1163
- )
1164
- );
1165
- colorRanges = arrayOrArray(data.zones.Zone).map((zone) => {
1166
- return tinycolor(zone.color).setAlpha(1 - (255 - zone.transparency) / 255).toPercentageRgbString();
1167
- }).flat();
1168
- } else {
1169
- valueRanges = widgetData.valueRanges;
1170
- colorRanges = widgetData.colorRanges;
1171
- }
1172
- widgetData.colorRanges = colorRanges;
1173
- widgetData.valueRanges = valueRanges;
1174
- return /* @__PURE__ */ jsx(CurrentWidget, { ...widgetData });
1175
- };
1176
-
1177
- Chart.register(
1178
- CategoryScale,
1179
- LinearScale,
1180
- PointElement,
1181
- LineElement,
1182
- Title,
1183
- Tooltip,
1184
- Legend,
1185
- BarController,
1186
- BarElement,
1187
- PieController,
1188
- ArcElement,
1189
- LineController
1190
- );
1191
- const ChartComponent = (props = {
1192
- chartData: { datasets: [{ data: [{ x: 0, y: 0 }] }] },
1193
- type: "bar",
1194
- indexAxis: "x",
1195
- showLegend: true,
1196
- showValues: true,
1197
- showXAxisValues: true,
1198
- showYAxisValues: true,
1199
- showTable: true,
1200
- xAxisTitle: "",
1201
- yAxisTitle: "",
1202
- aspectRatio: 2.5
1203
- }) => {
1204
- const { theme } = useThemeUI();
1205
- if (!theme.layout)
1206
- console.error("The layout property is missing in the current theme");
1207
- const data = useMemo(() => {
1208
- const charts = theme.layout?.charts ?? {};
1209
- return {
1210
- datasets: (props.type === "waterfall" ? arrayOrArray(props.chartData.datasets).map((dataset) => {
1211
- let sum = 0;
1212
- const newData = dataset.data.map((dataValue) => {
1213
- if (typeof dataValue === "number") {
1214
- const currentValue = sum;
1215
- sum += dataValue;
1216
- return [currentValue, sum];
1217
- } else {
1218
- return dataValue;
1219
- }
1220
- });
1221
- return {
1222
- ...dataset,
1223
- data: newData
1224
- };
1225
- }) : props.chartData.datasets).map((dataset, datasetIndex) => {
1226
- const isSingle = arrayOrArray(props.chartData.datasets).every(
1227
- (dataset2) => arrayOrArray(dataset2.data).length === 1
1228
- ) || props.type === "pie";
1229
- return {
1230
- ...dataset,
1231
- backgroundColor: dataset.backgroundColor.map((color, i) => {
1232
- let schemaArray = [];
1233
- if (typeof color === "string") {
1234
- if (color in charts) {
1235
- const currentBackgroundStylescheme = {
1236
- schema: getValueByPath(
1237
- theme.colors,
1238
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
1239
- charts[color.toLowerCase()]?.schema
1240
- )
1241
- };
1242
- if (typeof currentBackgroundStylescheme.schema === "object" && currentBackgroundStylescheme.schema) {
1243
- if (isSingle) {
1244
- if (props.type === "pie") {
1245
- schemaArray = Object.values(
1246
- currentBackgroundStylescheme.schema
1247
- ).map((varColor) => {
1248
- return window.getComputedStyle(document.documentElement).getPropertyValue(varColor.slice(4, -1));
1249
- });
1250
- } else {
1251
- schemaArray = new Array(6).fill(
1252
- Object.values(currentBackgroundStylescheme.schema)[datasetIndex % 6]
1253
- ).map((varColor) => {
1254
- return window.getComputedStyle(document.documentElement).getPropertyValue(varColor.slice(4, -1));
1255
- });
1256
- }
1257
- } else {
1258
- schemaArray = new Array(6).fill(
1259
- Object.values(currentBackgroundStylescheme.schema).map(
1260
- (varColor) => {
1261
- return window.getComputedStyle(document.documentElement).getPropertyValue(varColor.slice(4, -1));
1262
- }
1263
- )[datasetIndex % 6]
1264
- );
1265
- }
1266
- }
1267
- } else {
1268
- schemaArray = [color, color, color, color, color, color];
1269
- }
1270
- } else {
1271
- return color[datasetIndex % color.length];
1272
- }
1273
- return schemaArray[i % 6];
1274
- }),
1275
- borderColor: dataset.borderColor.map(
1276
- (color, i) => {
1277
- let schemaBorderArray = [];
1278
- if (typeof color === "string") {
1279
- if (color in charts) {
1280
- const currentBorderStylescheme = {
1281
- schema: getValueByPath(
1282
- theme.colors,
1283
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
1284
- charts[color.toLowerCase()]?.schema
1285
- )
1286
- };
1287
- if (typeof currentBorderStylescheme.schema === "object" && currentBorderStylescheme.schema) {
1288
- schemaBorderArray = Object.values(
1289
- currentBorderStylescheme.schema
1290
- ).map((varColor) => {
1291
- return window.getComputedStyle(document.documentElement).getPropertyValue(varColor.slice(4, -1));
1292
- });
1293
- }
1294
- } else {
1295
- schemaBorderArray = [
1296
- color,
1297
- color,
1298
- color,
1299
- color,
1300
- color,
1301
- color
1302
- ];
1303
- }
1304
- } else {
1305
- return color[datasetIndex % color.length];
1306
- }
1307
- return schemaBorderArray[i % 6];
1308
- }
1309
- )
1310
- };
1311
- }),
1312
- labels: props.chartData.labels
1313
- };
1314
- }, [
1315
- props.chartData.datasets,
1316
- props.chartData.labels,
1317
- props.type,
1318
- theme.colors,
1319
- theme.layout
1320
- ]);
1321
- const options = useMemo(() => {
1322
- return {
1323
- plugins: {
1324
- legend: { position: "right", display: props.showLegend },
1325
- tooltip: {
1326
- callbacks: {
1327
- label(tooltipItem) {
1328
- const XLabel = tooltipItem.dataset.label ?? "";
1329
- let YValue = tooltipItem.formattedValue;
1330
- if (isNaN(parseFloat(YValue))) {
1331
- const arrayValue = tooltipItem.raw;
1332
- const realValue = arrayValue[1] - arrayValue[0];
1333
- YValue = `${realValue}`;
1334
- }
1335
- let finalString = "";
1336
- if (props.showLegend || props.type === "pie") {
1337
- finalString += XLabel;
1338
- if (props.showValues) {
1339
- finalString += ": " + YValue;
1340
- }
1341
- } else if (props.showValues) {
1342
- finalString += YValue;
1343
- }
1344
- return finalString;
1345
- },
1346
- title(tooltipItems) {
1347
- if (props.type !== "pie" && !props.showXAxisValues && props.indexAxis === "x" || props.type !== "pie" && !props.showYAxisValues && props.indexAxis === "y" || props.type === "pie" && !props.showLegend) {
1348
- return "";
1349
- }
1350
- return tooltipItems[0].label;
1351
- }
1352
- },
1353
- enabled: (props.indexAxis === "y" ? props.showYAxisValues : props.showXAxisValues) || props.showValues || props.showLegend
1354
- }
1355
- },
1356
- aspectRatio: props.aspectRatio,
1357
- indexAxis: props.indexAxis,
1358
- scales: {
1359
- x: {
1360
- display: props.type !== "pie",
1361
- title: {
1362
- display: props.showXAxisValues,
1363
- text: props.indexAxis === "y" ? props.yAxisTitle : props.xAxisTitle
1364
- },
1365
- ticks: {
1366
- display: !!props.showXAxisValues
1367
- },
1368
- grid: {
1369
- display: props.showTable
1370
- }
1371
- },
1372
- y: {
1373
- axis: props.indexAxis === "y" ? "x" : "y",
1374
- display: props.type !== "pie",
1375
- title: {
1376
- display: props.showYAxisValues,
1377
- text: props.indexAxis === "y" ? props.xAxisTitle : props.yAxisTitle
1378
- },
1379
- ticks: {
1380
- display: !!props.showYAxisValues
1381
- },
1382
- grid: {
1383
- display: props.showTable
1384
- }
1385
- }
1386
- }
1387
- };
1388
- }, [
1389
- props.aspectRatio,
1390
- props.indexAxis,
1391
- props.showLegend,
1392
- props.showTable,
1393
- props.showValues,
1394
- props.showXAxisValues,
1395
- props.showYAxisValues,
1396
- props.type,
1397
- props.xAxisTitle,
1398
- props.yAxisTitle
1399
- ]);
1400
- return /* @__PURE__ */ jsx(
1401
- Chart$1,
1402
- {
1403
- id: props.id ?? void 0,
1404
- className: props.chartId ?? "",
1405
- type: props.type === "waterfall" ? "bar" : props.type,
1406
- options,
1407
- data
1408
- }
1409
- );
1410
- };
1411
-
1412
- function R(props) {
1413
- const [Plot, setPlot] = useState(null);
1414
- const handleChange = useCallback((s) => {
1415
- setPivotState(() => {
1416
- return s;
1417
- });
1418
- }, []);
1419
- const [pivotState, setPivotState] = useState({
1420
- ...props,
1421
- onChange: handleChange
1422
- });
1423
- const imported = useRef(false);
1424
- useEffect(() => {
1425
- if (imported.current)
1426
- return;
1427
- imported.current = true;
1428
- import('react-plotly.js').then((Plot2) => {
1429
- setPlot(createPlotlyRenderers(Plot2.default.default));
1430
- });
1431
- }, []);
1432
- if (!Plot)
1433
- return null;
1434
- return /* @__PURE__ */ jsx(
1435
- PivotTableUI,
1436
- {
1437
- renderers: Object.assign({}, TableRenderers, Plot),
1438
- ...pivotState
1439
- }
1440
- );
1441
- }
1442
- const PivotTableComponent = (props) => {
1443
- return /* @__PURE__ */ jsx(
1444
- Box,
1445
- {
1446
- onClick: (ev) => ev.stopPropagation(),
1447
- onMouseDown: (ev) => ev.stopPropagation(),
1448
- onDrag: (ev) => ev.stopPropagation(),
1449
- onDragStart: (ev) => ev.stopPropagation(),
1450
- children: /* @__PURE__ */ jsx(R, { ...props })
1451
- }
1452
- );
1453
- };
1454
-
1455
- export { ChartComponent, PivotTableComponent, WidgetComponent };
1
+ export { WidgetComponent } from './widgets/WidgetComponent.js';
2
+ export { ChartComponent } from './charts/chartJsRenderer/ChartComponent.js';
1456
3
  //# sourceMappingURL=index.js.map