@apia/charts 0.1.0
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.md +21 -0
- package/README.md +1 -0
- package/dist/index.d.ts +207 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2475 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2475 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import React, { createContext, useContext, useState, useMemo, useLayoutEffect, useEffect, useRef } from 'react';
|
|
3
|
+
import { Box, Select } from 'theme-ui';
|
|
4
|
+
import { ThemeProviderContext, spacing, makeStyledComponent, getVariant } from '@apia/theme';
|
|
5
|
+
import { uniqueId } from 'lodash';
|
|
6
|
+
import { makeImperativeComponent, arrayOrArray, useImperativeComponentEvents, getValueByPath, usePanAndZoom, usePrevious, getIndex } from '@apia/util';
|
|
7
|
+
import { scaleBand, scaleLog, scaleLinear, scaleOrdinal } from '@visx/scale';
|
|
8
|
+
import { Grid } from '@visx/visx';
|
|
9
|
+
import { Group } from '@visx/group';
|
|
10
|
+
import { BarGroupHorizontal, BarGroup, LinePath, Line } from '@visx/shape';
|
|
11
|
+
import { AxisLeft, AxisBottom } from '@visx/axis';
|
|
12
|
+
import { usePanelParametersSelector } from '@apia/dashboard';
|
|
13
|
+
import tinycolor from 'tinycolor2';
|
|
14
|
+
import { localPoint } from '@visx/event';
|
|
15
|
+
import { SimpleButton, useTooltip } from '@apia/components';
|
|
16
|
+
import { icons } from '@apia/icons';
|
|
17
|
+
import Pie from '@visx/shape/lib/shapes/Pie';
|
|
18
|
+
import { min, max, extent } from 'd3-array';
|
|
19
|
+
import * as allCurves from '@visx/curve';
|
|
20
|
+
import { Fragment as Fragment$1 } from 'theme-ui/jsx-runtime';
|
|
21
|
+
import { GridRows } from '@visx/grid';
|
|
22
|
+
import { useGauge } from 'use-gauge';
|
|
23
|
+
|
|
24
|
+
function parseMargin(margin = {
|
|
25
|
+
left: 100,
|
|
26
|
+
right: 50,
|
|
27
|
+
top: 50,
|
|
28
|
+
bottom: 70
|
|
29
|
+
}) {
|
|
30
|
+
return typeof margin === "number" ? { left: margin, right: margin, top: margin, bottom: margin } : margin;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ChartContext = createContext({});
|
|
34
|
+
|
|
35
|
+
const LegendItem = ({
|
|
36
|
+
groupId,
|
|
37
|
+
title,
|
|
38
|
+
color,
|
|
39
|
+
className,
|
|
40
|
+
isHighlighted,
|
|
41
|
+
isAnyHighlighted,
|
|
42
|
+
avoidEvent
|
|
43
|
+
}) => {
|
|
44
|
+
const { chartId } = useContext(ChartContext);
|
|
45
|
+
return /* @__PURE__ */ jsx(
|
|
46
|
+
SimpleButton,
|
|
47
|
+
{
|
|
48
|
+
variant: "icon-outline",
|
|
49
|
+
className: `${className != null ? className : ""} ${isHighlighted ? "highlight" : ""}`,
|
|
50
|
+
iconColor: color || "black",
|
|
51
|
+
icon: color === "transparent" ? void 0 : icons.SquareFilled,
|
|
52
|
+
sx: {
|
|
53
|
+
opacity: isAnyHighlighted && !isHighlighted ? "0.15" : "1"
|
|
54
|
+
},
|
|
55
|
+
onMouseEnter: () => {
|
|
56
|
+
if (avoidEvent) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
chartMethods(chartId, "highlight", groupId);
|
|
60
|
+
},
|
|
61
|
+
onMouseLeave: () => {
|
|
62
|
+
if (avoidEvent) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
chartMethods(chartId, "highlight", "");
|
|
66
|
+
},
|
|
67
|
+
children: title
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const [legendContainerMethods, , LegendContainer] = makeImperativeComponent()({
|
|
73
|
+
initialState: {
|
|
74
|
+
highlightedBarGroup: ""
|
|
75
|
+
},
|
|
76
|
+
methods: {
|
|
77
|
+
highlight(setState, highlightedBarGroup) {
|
|
78
|
+
setState({ highlightedBarGroup });
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
Component: ({
|
|
82
|
+
references,
|
|
83
|
+
containerClassName,
|
|
84
|
+
highlightedBarGroup,
|
|
85
|
+
avoidEvent
|
|
86
|
+
}) => {
|
|
87
|
+
return /* @__PURE__ */ jsx(Box, { className: containerClassName, children: references.map((data) => {
|
|
88
|
+
return /* @__PURE__ */ jsx(
|
|
89
|
+
LegendItem,
|
|
90
|
+
{
|
|
91
|
+
isHighlighted: data.title === highlightedBarGroup,
|
|
92
|
+
isAnyHighlighted: highlightedBarGroup !== "",
|
|
93
|
+
groupId: data.title,
|
|
94
|
+
color: data.color,
|
|
95
|
+
title: data.title,
|
|
96
|
+
avoidEvent: avoidEvent != null ? avoidEvent : false
|
|
97
|
+
},
|
|
98
|
+
data.title
|
|
99
|
+
);
|
|
100
|
+
}) });
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const Bar$1 = ({
|
|
105
|
+
bar,
|
|
106
|
+
barGroup,
|
|
107
|
+
chart,
|
|
108
|
+
parsedData,
|
|
109
|
+
isSingle,
|
|
110
|
+
effectiveMargin,
|
|
111
|
+
setsWithColor
|
|
112
|
+
}) => {
|
|
113
|
+
var _a;
|
|
114
|
+
const column = arrayOrArray(chart.dataSets.data)[bar.index];
|
|
115
|
+
const set = arrayOrArray(column == null ? void 0 : column.sets)[barGroup.index];
|
|
116
|
+
const currentBarColor = (_a = setsWithColor.find(
|
|
117
|
+
(innerSet) => innerSet.columnName === column.name && innerSet.key === set.key
|
|
118
|
+
)) == null ? void 0 : _a.color;
|
|
119
|
+
const [isHighlighted, setIsHighlighted] = useState(false);
|
|
120
|
+
const [isAnyHighlighted, setIsAnyHighlighted] = useState(false);
|
|
121
|
+
const { open } = useTooltip({
|
|
122
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
123
|
+
/* @__PURE__ */ jsx(
|
|
124
|
+
"div",
|
|
125
|
+
{
|
|
126
|
+
style: {
|
|
127
|
+
color: currentBarColor
|
|
128
|
+
},
|
|
129
|
+
children: /* @__PURE__ */ jsx("strong", { children: parsedData[barGroup.index].columnName })
|
|
130
|
+
}
|
|
131
|
+
),
|
|
132
|
+
chart.showValues && /* @__PURE__ */ jsx("div", { children: bar.value }),
|
|
133
|
+
/* @__PURE__ */ jsx("div", { children: bar.key })
|
|
134
|
+
] })
|
|
135
|
+
});
|
|
136
|
+
useImperativeComponentEvents({
|
|
137
|
+
highlight(barName) {
|
|
138
|
+
if (barName.split(" - ").length === 1) {
|
|
139
|
+
setIsHighlighted(barName === bar.key);
|
|
140
|
+
setIsAnyHighlighted(barName !== bar.key && barName !== "");
|
|
141
|
+
} else if (barName.split(" - ").length === 2) {
|
|
142
|
+
setIsHighlighted(
|
|
143
|
+
barName.split(" - ")[0] === bar.key && barName.split(" - ")[1] === set.key
|
|
144
|
+
);
|
|
145
|
+
setIsAnyHighlighted(
|
|
146
|
+
barName.split(" - ")[0] !== bar.key && barName.split(" - ")[0] !== ""
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
const { chartId } = useContext(ChartContext);
|
|
152
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
153
|
+
/* @__PURE__ */ jsxs(
|
|
154
|
+
"text",
|
|
155
|
+
{
|
|
156
|
+
x: bar.x + 5,
|
|
157
|
+
y: bar.y - 5,
|
|
158
|
+
width: bar.width,
|
|
159
|
+
height: bar.height,
|
|
160
|
+
textAnchor: "start",
|
|
161
|
+
style: {
|
|
162
|
+
display: isHighlighted ? "block" : "none",
|
|
163
|
+
opacity: isHighlighted ? 1 : 0,
|
|
164
|
+
transition: "opacity 500ms"
|
|
165
|
+
},
|
|
166
|
+
children: [
|
|
167
|
+
bar.value,
|
|
168
|
+
" - ",
|
|
169
|
+
parsedData[barGroup.index].columnName
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
),
|
|
173
|
+
/* @__PURE__ */ jsx(
|
|
174
|
+
Box,
|
|
175
|
+
{
|
|
176
|
+
as: "rect",
|
|
177
|
+
className: "chart__barRect",
|
|
178
|
+
sx: useMemo(
|
|
179
|
+
() => ({
|
|
180
|
+
fill: isAnyHighlighted ? `#${tinycolor(currentBarColor).desaturate(70).toHex()}` : currentBarColor,
|
|
181
|
+
"&:hover": {
|
|
182
|
+
fill: `#${tinycolor(currentBarColor).saturate(25).toHex()}`
|
|
183
|
+
},
|
|
184
|
+
transition: "fill 500ms, opacity 500ms",
|
|
185
|
+
x: bar.x,
|
|
186
|
+
y: bar.y,
|
|
187
|
+
width: bar.width - effectiveMargin.left,
|
|
188
|
+
opacity: isAnyHighlighted && !isHighlighted ? 0.15 : 1,
|
|
189
|
+
height: bar.height > 0 ? bar.height : 0
|
|
190
|
+
}),
|
|
191
|
+
[
|
|
192
|
+
bar.height,
|
|
193
|
+
bar.width,
|
|
194
|
+
bar.x,
|
|
195
|
+
bar.y,
|
|
196
|
+
currentBarColor,
|
|
197
|
+
effectiveMargin.left,
|
|
198
|
+
isAnyHighlighted,
|
|
199
|
+
isHighlighted
|
|
200
|
+
]
|
|
201
|
+
),
|
|
202
|
+
onMouseEnter: (ev) => {
|
|
203
|
+
var _a2, _b, _c;
|
|
204
|
+
if (!isSingle) {
|
|
205
|
+
legendContainerMethods.highlight(chartId, bar.key);
|
|
206
|
+
}
|
|
207
|
+
(_a2 = ev.target.classList) == null ? void 0 : _a2.add("over");
|
|
208
|
+
const point = {
|
|
209
|
+
x: (_b = localPoint(ev)) == null ? void 0 : _b.x,
|
|
210
|
+
y: (_c = localPoint(ev)) == null ? void 0 : _c.y
|
|
211
|
+
};
|
|
212
|
+
if (!point)
|
|
213
|
+
return;
|
|
214
|
+
open({
|
|
215
|
+
attachToElement: () => ev.target,
|
|
216
|
+
attachToElementAnchorPoint: "center"
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
onMouseLeave: (ev) => {
|
|
220
|
+
var _a2;
|
|
221
|
+
if (!isSingle) {
|
|
222
|
+
legendContainerMethods.highlight(chartId, "");
|
|
223
|
+
}
|
|
224
|
+
(_a2 = ev.target.classList) == null ? void 0 : _a2.remove("over");
|
|
225
|
+
},
|
|
226
|
+
children: /* @__PURE__ */ jsx(
|
|
227
|
+
"animate",
|
|
228
|
+
{
|
|
229
|
+
attributeName: "width",
|
|
230
|
+
from: 0,
|
|
231
|
+
to: bar.width,
|
|
232
|
+
dur: "0.5s",
|
|
233
|
+
calcMode: "paced",
|
|
234
|
+
keySplines: "0.5 0 0.5 1;",
|
|
235
|
+
keyTimes: "0; 1"
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
)
|
|
240
|
+
] });
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
function getBarColor(colors, index, alwaysDiffer = false) {
|
|
244
|
+
const module = colors.length;
|
|
245
|
+
let count = 0;
|
|
246
|
+
let barColor = "";
|
|
247
|
+
if (!alwaysDiffer) {
|
|
248
|
+
if (colors[index]) {
|
|
249
|
+
barColor = colors[index];
|
|
250
|
+
} else {
|
|
251
|
+
let innerIndex = index;
|
|
252
|
+
while (innerIndex >= module) {
|
|
253
|
+
innerIndex = index / module;
|
|
254
|
+
count++;
|
|
255
|
+
}
|
|
256
|
+
barColor = tinycolor(colors[index % module]).desaturate(count * 5).toHex();
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
if (colors[index]) {
|
|
260
|
+
barColor = colors[index];
|
|
261
|
+
} else {
|
|
262
|
+
barColor = tinycolor(colors[index % module]).toHex();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return barColor;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
var __defProp$7 = Object.defineProperty;
|
|
269
|
+
var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
|
|
270
|
+
var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
|
|
271
|
+
var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
|
|
272
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
273
|
+
var __spreadValues$7 = (a, b) => {
|
|
274
|
+
for (var prop in b || (b = {}))
|
|
275
|
+
if (__hasOwnProp$7.call(b, prop))
|
|
276
|
+
__defNormalProp$7(a, prop, b[prop]);
|
|
277
|
+
if (__getOwnPropSymbols$7)
|
|
278
|
+
for (var prop of __getOwnPropSymbols$7(b)) {
|
|
279
|
+
if (__propIsEnum$7.call(b, prop))
|
|
280
|
+
__defNormalProp$7(a, prop, b[prop]);
|
|
281
|
+
}
|
|
282
|
+
return a;
|
|
283
|
+
};
|
|
284
|
+
function useChartStyles(schemeName) {
|
|
285
|
+
var _a, _b, _c;
|
|
286
|
+
const theme = useContext(ThemeProviderContext);
|
|
287
|
+
if (!theme.layout)
|
|
288
|
+
console.error("The layout property is missing in the current theme");
|
|
289
|
+
const charts = (_b = (_a = theme.layout) == null ? void 0 : _a.charts) != null ? _b : {};
|
|
290
|
+
const defaultStyles = charts.common;
|
|
291
|
+
const currentStylescheme = {
|
|
292
|
+
schema: getValueByPath(
|
|
293
|
+
theme.colors,
|
|
294
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
295
|
+
(_c = charts[schemeName || "blue"]) == null ? void 0 : _c.schema
|
|
296
|
+
)
|
|
297
|
+
};
|
|
298
|
+
return __spreadValues$7(__spreadValues$7({}, defaultStyles), currentStylescheme);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
var __defProp$6 = Object.defineProperty;
|
|
302
|
+
var __defProps$6 = Object.defineProperties;
|
|
303
|
+
var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
|
|
304
|
+
var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
|
|
305
|
+
var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
|
|
306
|
+
var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
|
|
307
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
308
|
+
var __spreadValues$6 = (a, b) => {
|
|
309
|
+
for (var prop in b || (b = {}))
|
|
310
|
+
if (__hasOwnProp$6.call(b, prop))
|
|
311
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
312
|
+
if (__getOwnPropSymbols$6)
|
|
313
|
+
for (var prop of __getOwnPropSymbols$6(b)) {
|
|
314
|
+
if (__propIsEnum$6.call(b, prop))
|
|
315
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
316
|
+
}
|
|
317
|
+
return a;
|
|
318
|
+
};
|
|
319
|
+
var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
320
|
+
function adjustDimensions$4({
|
|
321
|
+
width,
|
|
322
|
+
height,
|
|
323
|
+
maxWidth
|
|
324
|
+
}) {
|
|
325
|
+
if (width <= maxWidth) {
|
|
326
|
+
return { width, height };
|
|
327
|
+
}
|
|
328
|
+
const ratio = width / height;
|
|
329
|
+
const newWidth = maxWidth;
|
|
330
|
+
const newHeight = Math.floor(newWidth / ratio);
|
|
331
|
+
return { width: newWidth, height: newHeight };
|
|
332
|
+
}
|
|
333
|
+
const getYValue = (d) => d.columnName;
|
|
334
|
+
const HorizontalBars = ({
|
|
335
|
+
margin = { top: 20, left: 50, bottom: 150, right: 20 },
|
|
336
|
+
chart,
|
|
337
|
+
className,
|
|
338
|
+
chartId,
|
|
339
|
+
outerClassName,
|
|
340
|
+
allowZoom
|
|
341
|
+
}) => {
|
|
342
|
+
var _a;
|
|
343
|
+
const effectiveMargin = parseMargin(margin);
|
|
344
|
+
let innerWidth = chart.ratio.width + (-effectiveMargin.left - effectiveMargin.right) / 2;
|
|
345
|
+
let innerHeight = chart.ratio.height + (-effectiveMargin.top - effectiveMargin.bottom) / 2;
|
|
346
|
+
if (innerWidth > chart.ratio.maxWidth) {
|
|
347
|
+
const newValues = adjustDimensions$4({
|
|
348
|
+
height: innerHeight,
|
|
349
|
+
width: innerWidth,
|
|
350
|
+
maxWidth: chart.ratio.maxWidth
|
|
351
|
+
});
|
|
352
|
+
innerWidth = newValues.width;
|
|
353
|
+
innerHeight = newValues.height;
|
|
354
|
+
}
|
|
355
|
+
const columnas = arrayOrArray((_a = chart.dataSets) == null ? void 0 : _a.data).filter((column) => !!column.sets).map((column) => {
|
|
356
|
+
return __spreadProps$6(__spreadValues$6({}, column), {
|
|
357
|
+
sets: column.sets
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
const xValues = arrayOrArray(columnas[0].sets).map(
|
|
361
|
+
(innerCoord) => innerCoord.key
|
|
362
|
+
);
|
|
363
|
+
const columnNames = columnas.map((col) => {
|
|
364
|
+
return col.name;
|
|
365
|
+
});
|
|
366
|
+
const parsedData = xValues.map((x) => {
|
|
367
|
+
const obj = columnas.reduce(
|
|
368
|
+
(acc, column) => {
|
|
369
|
+
return __spreadProps$6(__spreadValues$6({}, acc), {
|
|
370
|
+
[column.name]: arrayOrArray(column.sets).filter((coord) => {
|
|
371
|
+
return coord.key === x;
|
|
372
|
+
})[0].value
|
|
373
|
+
});
|
|
374
|
+
},
|
|
375
|
+
{ columnName: x }
|
|
376
|
+
);
|
|
377
|
+
return obj;
|
|
378
|
+
});
|
|
379
|
+
const yScale = scaleBand({
|
|
380
|
+
range: [
|
|
381
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top,
|
|
382
|
+
innerHeight
|
|
383
|
+
],
|
|
384
|
+
domain: parsedData.map(getYValue),
|
|
385
|
+
padding: 0.2
|
|
386
|
+
});
|
|
387
|
+
const columnGroupScale = scaleBand({
|
|
388
|
+
domain: columnNames,
|
|
389
|
+
range: [0, yScale.bandwidth()]
|
|
390
|
+
});
|
|
391
|
+
const xScaleLog = scaleLog({
|
|
392
|
+
range: [
|
|
393
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.left,
|
|
394
|
+
innerWidth
|
|
395
|
+
],
|
|
396
|
+
domain: [
|
|
397
|
+
1,
|
|
398
|
+
Math.max(
|
|
399
|
+
...parsedData.map(
|
|
400
|
+
(d) => Math.max(...columnNames.map((key) => Number(d[key])))
|
|
401
|
+
)
|
|
402
|
+
)
|
|
403
|
+
],
|
|
404
|
+
base: 10
|
|
405
|
+
});
|
|
406
|
+
const xScaleLine = scaleLinear({
|
|
407
|
+
range: [
|
|
408
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.left,
|
|
409
|
+
innerWidth
|
|
410
|
+
],
|
|
411
|
+
domain: [
|
|
412
|
+
0,
|
|
413
|
+
Math.max(
|
|
414
|
+
...parsedData.map(
|
|
415
|
+
(d) => Math.max(...columnNames.map((key) => Number(d[key])))
|
|
416
|
+
)
|
|
417
|
+
)
|
|
418
|
+
]
|
|
419
|
+
});
|
|
420
|
+
const color = scaleOrdinal({
|
|
421
|
+
domain: columnNames,
|
|
422
|
+
range: columnas.map((col) => col.color)
|
|
423
|
+
});
|
|
424
|
+
const parameters = usePanelParametersSelector((global) => {
|
|
425
|
+
return global;
|
|
426
|
+
});
|
|
427
|
+
const scale = parameters.PRMT_CHART_SCALE;
|
|
428
|
+
const isLogScale = scale === "0";
|
|
429
|
+
const xScale = useMemo(() => {
|
|
430
|
+
if (!isLogScale) {
|
|
431
|
+
return xScaleLine;
|
|
432
|
+
}
|
|
433
|
+
return xScaleLog;
|
|
434
|
+
}, [isLogScale, xScaleLine, xScaleLog]);
|
|
435
|
+
const id = useMemo(() => `VerticalBars${uniqueId()}`, []);
|
|
436
|
+
useLayoutEffect(() => {
|
|
437
|
+
document.querySelectorAll(
|
|
438
|
+
`#${id} .__${chartId != null ? chartId : outerClassName}`
|
|
439
|
+
).forEach((current) => {
|
|
440
|
+
const width = current.getBoundingClientRect().width;
|
|
441
|
+
current.style.transformOrigin = current.getAttribute("x") + "px 14px";
|
|
442
|
+
current.style.transform = `rotate(15deg) translateX(${width / 2}px)`;
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
const styles = useChartStyles(chart.colorSchema);
|
|
446
|
+
const { boxRef, elementRef } = usePanAndZoom(
|
|
447
|
+
void 0,
|
|
448
|
+
!allowZoom
|
|
449
|
+
);
|
|
450
|
+
const setsWithColor = arrayOrArray(chart.dataSets.data).map((data, index) => {
|
|
451
|
+
const isSingle = arrayOrArray(chart.dataSets.data).length === 1;
|
|
452
|
+
const dataColor = data.color !== "" && data.color !== void 0 ? data.color : arrayOrArray(styles.schema).length > 0 ? getBarColor(arrayOrArray(styles.schema), index, isSingle) : "";
|
|
453
|
+
const returnColumnsArray = [];
|
|
454
|
+
arrayOrArray(data.sets).forEach((set) => {
|
|
455
|
+
if (set.color !== "" && set.color !== void 0) {
|
|
456
|
+
returnColumnsArray.push(__spreadProps$6(__spreadValues$6({}, set), { columnName: data.name }));
|
|
457
|
+
} else {
|
|
458
|
+
returnColumnsArray.push(__spreadProps$6(__spreadValues$6({}, set), {
|
|
459
|
+
color: dataColor,
|
|
460
|
+
columnName: data.name
|
|
461
|
+
}));
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
return returnColumnsArray;
|
|
465
|
+
});
|
|
466
|
+
const colorReference = setsWithColor.map((column) => {
|
|
467
|
+
var _a2;
|
|
468
|
+
return {
|
|
469
|
+
color: (_a2 = column[0].color) != null ? _a2 : "",
|
|
470
|
+
title: column[0].columnName
|
|
471
|
+
};
|
|
472
|
+
});
|
|
473
|
+
arrayOrArray(chart.dataSets.data).map((data) => {
|
|
474
|
+
const returnArray = [];
|
|
475
|
+
arrayOrArray(data.sets).forEach((set) => {
|
|
476
|
+
if (set.color !== "" && set.color !== void 0) {
|
|
477
|
+
returnArray.push({
|
|
478
|
+
color: set.color,
|
|
479
|
+
title: data.name + " - " + set.key
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
return returnArray;
|
|
484
|
+
}).flat().forEach((addRef) => colorReference.push(addRef));
|
|
485
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
486
|
+
/* @__PURE__ */ jsx(
|
|
487
|
+
Box,
|
|
488
|
+
{
|
|
489
|
+
ref: boxRef,
|
|
490
|
+
id,
|
|
491
|
+
className: `${outerClassName != null ? outerClassName : ""} ${chartId} ${chart.title}`,
|
|
492
|
+
sx: React.useMemo(() => {
|
|
493
|
+
return {
|
|
494
|
+
[`.__${chartId != null ? chartId : outerClassName}`]: {
|
|
495
|
+
transform: "rotate(45deg)",
|
|
496
|
+
transformOrigin: "attr(x) 18px"
|
|
497
|
+
},
|
|
498
|
+
overflow: "auto",
|
|
499
|
+
position: "relative",
|
|
500
|
+
height: `${chart.ratio.height}px`,
|
|
501
|
+
width: `${chart.ratio.width}px`
|
|
502
|
+
};
|
|
503
|
+
}, [chart.ratio.height, chart.ratio.width, chartId, outerClassName]),
|
|
504
|
+
children: /* @__PURE__ */ jsxs(
|
|
505
|
+
"svg",
|
|
506
|
+
{
|
|
507
|
+
ref: elementRef,
|
|
508
|
+
className: `_${chartId} ${className ? className : ""} chart__svg`,
|
|
509
|
+
height: chart.ratio.height,
|
|
510
|
+
width: chart.ratio.width,
|
|
511
|
+
style: {
|
|
512
|
+
position: "absolute"
|
|
513
|
+
},
|
|
514
|
+
children: [
|
|
515
|
+
chart.showGrid && /* @__PURE__ */ jsx(
|
|
516
|
+
Grid.Grid,
|
|
517
|
+
{
|
|
518
|
+
xScale,
|
|
519
|
+
yScale,
|
|
520
|
+
left: 0,
|
|
521
|
+
width: innerWidth,
|
|
522
|
+
height: innerHeight,
|
|
523
|
+
numTicksRows: 10,
|
|
524
|
+
numTicksColumns: 10,
|
|
525
|
+
top: (typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top) - 20
|
|
526
|
+
}
|
|
527
|
+
),
|
|
528
|
+
/* @__PURE__ */ jsx(
|
|
529
|
+
Group,
|
|
530
|
+
{
|
|
531
|
+
top: (typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top) - 20,
|
|
532
|
+
left: effectiveMargin.left,
|
|
533
|
+
children: /* @__PURE__ */ jsx(
|
|
534
|
+
BarGroupHorizontal,
|
|
535
|
+
{
|
|
536
|
+
data: parsedData,
|
|
537
|
+
keys: columnNames,
|
|
538
|
+
width: innerWidth,
|
|
539
|
+
y0: getYValue,
|
|
540
|
+
y0Scale: yScale,
|
|
541
|
+
y1Scale: columnGroupScale,
|
|
542
|
+
xScale,
|
|
543
|
+
color,
|
|
544
|
+
children: (barGroups) => barGroups.map((barGroup) => {
|
|
545
|
+
return /* @__PURE__ */ jsx(
|
|
546
|
+
Group,
|
|
547
|
+
{
|
|
548
|
+
top: barGroup.y0,
|
|
549
|
+
children: barGroup.bars.map((bar) => {
|
|
550
|
+
const key = `${barGroup.index}-${bar.index}-${bar.key}`;
|
|
551
|
+
return /* @__PURE__ */ jsx(
|
|
552
|
+
Bar$1,
|
|
553
|
+
{
|
|
554
|
+
isSingle: barGroup.bars.length === 1,
|
|
555
|
+
bar,
|
|
556
|
+
barGroup,
|
|
557
|
+
chart,
|
|
558
|
+
parsedData,
|
|
559
|
+
effectiveMargin,
|
|
560
|
+
setsWithColor: setsWithColor.flat()
|
|
561
|
+
},
|
|
562
|
+
key
|
|
563
|
+
);
|
|
564
|
+
})
|
|
565
|
+
},
|
|
566
|
+
`bar-group-${barGroup.index}-${barGroup.y0}`
|
|
567
|
+
);
|
|
568
|
+
})
|
|
569
|
+
}
|
|
570
|
+
)
|
|
571
|
+
}
|
|
572
|
+
),
|
|
573
|
+
/* @__PURE__ */ jsx(
|
|
574
|
+
AxisLeft,
|
|
575
|
+
{
|
|
576
|
+
scale: yScale,
|
|
577
|
+
left: effectiveMargin.left,
|
|
578
|
+
label: chart.chartType !== "pie2D" && chart.showAxisYTitle ? chart.axisYTitle : "",
|
|
579
|
+
tickLabelProps: () => ({
|
|
580
|
+
display: "none"
|
|
581
|
+
})
|
|
582
|
+
}
|
|
583
|
+
),
|
|
584
|
+
/* @__PURE__ */ jsx(
|
|
585
|
+
AxisBottom,
|
|
586
|
+
{
|
|
587
|
+
top: innerHeight,
|
|
588
|
+
scale: xScale,
|
|
589
|
+
label: chart.chartType !== "pie2D" && chart.showAxisXTitle ? chart.axisXTitle : "",
|
|
590
|
+
tickLabelProps: {
|
|
591
|
+
className: "tickLabel"
|
|
592
|
+
},
|
|
593
|
+
labelOffset: 50
|
|
594
|
+
}
|
|
595
|
+
)
|
|
596
|
+
]
|
|
597
|
+
}
|
|
598
|
+
)
|
|
599
|
+
}
|
|
600
|
+
),
|
|
601
|
+
colorReference.length > 1 && /* @__PURE__ */ jsx(
|
|
602
|
+
LegendContainer,
|
|
603
|
+
{
|
|
604
|
+
id: chartId,
|
|
605
|
+
containerClassName: "legendContainer",
|
|
606
|
+
references: colorReference
|
|
607
|
+
}
|
|
608
|
+
)
|
|
609
|
+
] });
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
const Slice = ({
|
|
613
|
+
arc,
|
|
614
|
+
arcPath,
|
|
615
|
+
chart,
|
|
616
|
+
actualColor
|
|
617
|
+
}) => {
|
|
618
|
+
const [isHighlighted, setIsHighlighted] = useState(false);
|
|
619
|
+
const [isAnyHighlighted, setIsAnyHighlighted] = useState(false);
|
|
620
|
+
const { open } = useTooltip({
|
|
621
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
622
|
+
/* @__PURE__ */ jsx(
|
|
623
|
+
"div",
|
|
624
|
+
{
|
|
625
|
+
style: {
|
|
626
|
+
color: `#${tinycolor(actualColor).toHex()}`
|
|
627
|
+
},
|
|
628
|
+
children: /* @__PURE__ */ jsx("strong", { children: arc.data.key })
|
|
629
|
+
}
|
|
630
|
+
),
|
|
631
|
+
chart.showValues && /* @__PURE__ */ jsx("div", { children: `${arc.value} ${arc.data.percentage ? "- " + arc.data.percentage : ""}${arc.data.percentage ? "%" : ""}` })
|
|
632
|
+
] })
|
|
633
|
+
});
|
|
634
|
+
useImperativeComponentEvents({
|
|
635
|
+
highlight(barName) {
|
|
636
|
+
setIsHighlighted(barName === arc.data.key);
|
|
637
|
+
setIsAnyHighlighted(barName !== arc.data.key && barName !== "");
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
const { chartId } = useContext(ChartContext);
|
|
641
|
+
const name = arc.data;
|
|
642
|
+
return /* @__PURE__ */ jsx(
|
|
643
|
+
"path",
|
|
644
|
+
{
|
|
645
|
+
style: useMemo(
|
|
646
|
+
() => ({
|
|
647
|
+
"&:hover": {
|
|
648
|
+
fill: `#${tinycolor(actualColor).saturate(25).toHex()}`
|
|
649
|
+
},
|
|
650
|
+
transition: "fill 500ms, opacity 500ms"
|
|
651
|
+
}),
|
|
652
|
+
[actualColor]
|
|
653
|
+
),
|
|
654
|
+
fill: isAnyHighlighted ? `#${tinycolor(actualColor).desaturate(70).toHex()}` : actualColor,
|
|
655
|
+
opacity: isAnyHighlighted && !isHighlighted ? 0.15 : 1,
|
|
656
|
+
d: arcPath != null ? arcPath : "",
|
|
657
|
+
onMouseEnter: (ev) => {
|
|
658
|
+
var _a, _b, _c;
|
|
659
|
+
legendContainerMethods.highlight(chartId, arc.data.key);
|
|
660
|
+
(_a = ev.target.classList) == null ? void 0 : _a.add("over");
|
|
661
|
+
const point = {
|
|
662
|
+
x: (_b = localPoint(ev)) == null ? void 0 : _b.x,
|
|
663
|
+
y: (_c = localPoint(ev)) == null ? void 0 : _c.y
|
|
664
|
+
};
|
|
665
|
+
if (!point)
|
|
666
|
+
return;
|
|
667
|
+
open({
|
|
668
|
+
attachToElement: () => ev.target,
|
|
669
|
+
attachToElementAnchorPoint: "center"
|
|
670
|
+
});
|
|
671
|
+
},
|
|
672
|
+
onMouseLeave: (ev) => {
|
|
673
|
+
var _a;
|
|
674
|
+
legendContainerMethods.highlight(chartId, "");
|
|
675
|
+
(_a = ev.target.classList) == null ? void 0 : _a.remove("over");
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
`arc-${name.key}-${name.value}`
|
|
679
|
+
);
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
function ChartSelector({
|
|
683
|
+
chartId,
|
|
684
|
+
pieces,
|
|
685
|
+
className,
|
|
686
|
+
current,
|
|
687
|
+
setCurrent
|
|
688
|
+
}) {
|
|
689
|
+
return /* @__PURE__ */ jsxs(
|
|
690
|
+
Select,
|
|
691
|
+
{
|
|
692
|
+
sx: { width: "auto" },
|
|
693
|
+
name: `chartSelector_${chartId}`,
|
|
694
|
+
className: `chartSelector_${chartId} ${className != null ? className : ""}`,
|
|
695
|
+
value: current != null ? current : "0",
|
|
696
|
+
onChange: (ev) => {
|
|
697
|
+
ev.preventDefault();
|
|
698
|
+
setCurrent(ev.target.value);
|
|
699
|
+
},
|
|
700
|
+
children: [
|
|
701
|
+
pieces.map((piece, i) => {
|
|
702
|
+
return {
|
|
703
|
+
label: piece,
|
|
704
|
+
value: `${i}`
|
|
705
|
+
};
|
|
706
|
+
}).map((option) => /* @__PURE__ */ jsx("option", { value: option.value, children: option.label }, option.value)),
|
|
707
|
+
" "
|
|
708
|
+
]
|
|
709
|
+
}
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
const TextSlice = ({
|
|
714
|
+
arc,
|
|
715
|
+
x,
|
|
716
|
+
y,
|
|
717
|
+
dy
|
|
718
|
+
}) => {
|
|
719
|
+
const [isHighlighted, setIsHighlighted] = useState(false);
|
|
720
|
+
useImperativeComponentEvents({
|
|
721
|
+
highlight(barName) {
|
|
722
|
+
setIsHighlighted(barName === arc.data.key);
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
return /* @__PURE__ */ jsx(
|
|
726
|
+
"text",
|
|
727
|
+
{
|
|
728
|
+
textAnchor: "middle",
|
|
729
|
+
style: {
|
|
730
|
+
opacity: isHighlighted ? 1 : 0,
|
|
731
|
+
display: isHighlighted ? "block" : "none",
|
|
732
|
+
transition: "opacity 500ms"
|
|
733
|
+
},
|
|
734
|
+
x,
|
|
735
|
+
y,
|
|
736
|
+
dy,
|
|
737
|
+
children: arc.value
|
|
738
|
+
}
|
|
739
|
+
);
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
var __defProp$5 = Object.defineProperty;
|
|
743
|
+
var __defProps$5 = Object.defineProperties;
|
|
744
|
+
var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
|
|
745
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
746
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
747
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
748
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
749
|
+
var __spreadValues$5 = (a, b) => {
|
|
750
|
+
for (var prop in b || (b = {}))
|
|
751
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
752
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
753
|
+
if (__getOwnPropSymbols$5)
|
|
754
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
755
|
+
if (__propIsEnum$5.call(b, prop))
|
|
756
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
757
|
+
}
|
|
758
|
+
return a;
|
|
759
|
+
};
|
|
760
|
+
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
761
|
+
function adjustDimensions$3({
|
|
762
|
+
width,
|
|
763
|
+
height,
|
|
764
|
+
maxWidth
|
|
765
|
+
}) {
|
|
766
|
+
if (width <= maxWidth) {
|
|
767
|
+
return { width, height };
|
|
768
|
+
}
|
|
769
|
+
const ratio = width / height;
|
|
770
|
+
const newWidth = maxWidth;
|
|
771
|
+
const newHeight = Math.floor(newWidth / ratio);
|
|
772
|
+
return { width: newWidth, height: newHeight };
|
|
773
|
+
}
|
|
774
|
+
const PieChart = ({
|
|
775
|
+
// margin = { top: 20, left: 100, bottom: 150, right: 20 },
|
|
776
|
+
chart,
|
|
777
|
+
className,
|
|
778
|
+
chartId,
|
|
779
|
+
allowZoom
|
|
780
|
+
}) => {
|
|
781
|
+
var _a;
|
|
782
|
+
const [chartData, setChartData] = useState(
|
|
783
|
+
{}
|
|
784
|
+
);
|
|
785
|
+
let innerWidth = chart.ratio.width > chart.ratio.height ? chart.ratio.width : chart.ratio.height;
|
|
786
|
+
let innerHeight = chart.ratio.width > chart.ratio.height ? chart.ratio.width : chart.ratio.height;
|
|
787
|
+
if (innerWidth > chart.ratio.maxWidth) {
|
|
788
|
+
const newValues = adjustDimensions$3({
|
|
789
|
+
height: innerHeight,
|
|
790
|
+
width: innerWidth,
|
|
791
|
+
maxWidth: chart.ratio.maxWidth
|
|
792
|
+
});
|
|
793
|
+
innerWidth = newValues.width;
|
|
794
|
+
innerHeight = newValues.height;
|
|
795
|
+
}
|
|
796
|
+
const piezas = arrayOrArray((_a = chart.dataSets) == null ? void 0 : _a.data).filter((piece) => !!piece.sets).map((piece) => {
|
|
797
|
+
return __spreadProps$5(__spreadValues$5({}, piece), {
|
|
798
|
+
coordinate: piece.sets
|
|
799
|
+
});
|
|
800
|
+
});
|
|
801
|
+
const [currentPie, setCurrentPie] = useState("0");
|
|
802
|
+
useEffect(() => {
|
|
803
|
+
setChartData(piezas[currentPie != null ? currentPie : 0]);
|
|
804
|
+
}, [currentPie]);
|
|
805
|
+
const centerY = useMemo(() => {
|
|
806
|
+
return innerHeight / 2.5;
|
|
807
|
+
}, [innerHeight]);
|
|
808
|
+
const centerX = useMemo(() => {
|
|
809
|
+
return innerWidth / 2.5;
|
|
810
|
+
}, [innerWidth]);
|
|
811
|
+
const top = centerY;
|
|
812
|
+
const left = centerX;
|
|
813
|
+
const getValue = (d) => Number(d.value) === 0 && piezas.length === 1 && arrayOrArray(piezas.map((p) => p.coordinate)[0]).length === 1 ? 100 : Number(d.value);
|
|
814
|
+
const radius = Math.min(innerHeight, innerWidth) / 2.5;
|
|
815
|
+
const piecesNames = piezas.map((piece) => {
|
|
816
|
+
return piece.name;
|
|
817
|
+
});
|
|
818
|
+
const styles = useChartStyles(chart.colorSchema);
|
|
819
|
+
const colorsArray = styles.schema;
|
|
820
|
+
const names = arrayOrArray(arrayOrArray(chart.dataSets.data)[0].sets).map(
|
|
821
|
+
(coord) => {
|
|
822
|
+
return coord.key;
|
|
823
|
+
}
|
|
824
|
+
);
|
|
825
|
+
const colorReference = names.map((name, index) => {
|
|
826
|
+
return {
|
|
827
|
+
title: name,
|
|
828
|
+
color: getBarColor(arrayOrArray(colorsArray), index)
|
|
829
|
+
};
|
|
830
|
+
});
|
|
831
|
+
const { boxRef, elementRef } = usePanAndZoom(
|
|
832
|
+
void 0,
|
|
833
|
+
!allowZoom
|
|
834
|
+
);
|
|
835
|
+
const previousPaths = useRef([]);
|
|
836
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
837
|
+
piezas.length > 1 && /* @__PURE__ */ jsx(Box, { className: "chart__combo__wrapper", children: /* @__PURE__ */ jsx(
|
|
838
|
+
ChartSelector,
|
|
839
|
+
{
|
|
840
|
+
chartId,
|
|
841
|
+
pieces: piecesNames,
|
|
842
|
+
className: "chartSelectorCombo",
|
|
843
|
+
current: currentPie,
|
|
844
|
+
setCurrent: setCurrentPie
|
|
845
|
+
}
|
|
846
|
+
) }),
|
|
847
|
+
/* @__PURE__ */ jsx(
|
|
848
|
+
Box,
|
|
849
|
+
{
|
|
850
|
+
ref: boxRef,
|
|
851
|
+
className: `${className ? className : ""} ${chartId}`,
|
|
852
|
+
sx: { textAlign: "center", pb: spacing(5) },
|
|
853
|
+
children: /* @__PURE__ */ jsx(
|
|
854
|
+
"svg",
|
|
855
|
+
{
|
|
856
|
+
ref: elementRef,
|
|
857
|
+
height: radius * 2,
|
|
858
|
+
width: radius * 2,
|
|
859
|
+
className: `_${chartId} chart__svg`,
|
|
860
|
+
children: /* @__PURE__ */ jsxs(Group, { top: top != null ? top : 0, left: left != null ? left : 0, children: [
|
|
861
|
+
/* @__PURE__ */ jsx(
|
|
862
|
+
Pie,
|
|
863
|
+
{
|
|
864
|
+
data: arrayOrArray(chartData.coordinate),
|
|
865
|
+
pieValue: getValue,
|
|
866
|
+
pieSort: null,
|
|
867
|
+
outerRadius: radius,
|
|
868
|
+
children: (pie) => {
|
|
869
|
+
const paths = arrayOrArray(pie.arcs).map((arc) => {
|
|
870
|
+
return pie.path(arc);
|
|
871
|
+
});
|
|
872
|
+
const result = pie.arcs.map((arc) => {
|
|
873
|
+
var _a2, _b;
|
|
874
|
+
const name = arc.data;
|
|
875
|
+
const arcPath = pie.path(arc);
|
|
876
|
+
return /* @__PURE__ */ jsx(
|
|
877
|
+
Slice,
|
|
878
|
+
{
|
|
879
|
+
arc,
|
|
880
|
+
arcPath,
|
|
881
|
+
chart,
|
|
882
|
+
actualColor: (_b = (_a2 = colorReference.find((color) => {
|
|
883
|
+
return color.title === name.key;
|
|
884
|
+
})) == null ? void 0 : _a2.color) != null ? _b : ""
|
|
885
|
+
},
|
|
886
|
+
`${name.key}_${name.value}`
|
|
887
|
+
);
|
|
888
|
+
});
|
|
889
|
+
previousPaths.current = paths;
|
|
890
|
+
return result;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
),
|
|
894
|
+
/* @__PURE__ */ jsx(
|
|
895
|
+
Pie,
|
|
896
|
+
{
|
|
897
|
+
data: arrayOrArray(chartData.coordinate),
|
|
898
|
+
pieValue: getValue,
|
|
899
|
+
pieSort: null,
|
|
900
|
+
outerRadius: radius,
|
|
901
|
+
children: (pie) => {
|
|
902
|
+
return pie.arcs.map((arc) => {
|
|
903
|
+
const name = arc.data;
|
|
904
|
+
const angle = (arc.startAngle - Math.PI + arc.endAngle) / 2;
|
|
905
|
+
const x = Math.cos(angle) * (radius * 0.75);
|
|
906
|
+
const y = Math.sin(angle) * (radius * 0.75);
|
|
907
|
+
return /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
|
|
908
|
+
TextSlice,
|
|
909
|
+
{
|
|
910
|
+
arc,
|
|
911
|
+
chart,
|
|
912
|
+
dy: "0.33em",
|
|
913
|
+
x,
|
|
914
|
+
y
|
|
915
|
+
}
|
|
916
|
+
) }, `arc-${name.key}-${name.value}`);
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
)
|
|
921
|
+
] })
|
|
922
|
+
}
|
|
923
|
+
)
|
|
924
|
+
},
|
|
925
|
+
chartData.name
|
|
926
|
+
),
|
|
927
|
+
colorReference.length > 1 && /* @__PURE__ */ jsx(
|
|
928
|
+
LegendContainer,
|
|
929
|
+
{
|
|
930
|
+
id: chartId,
|
|
931
|
+
containerClassName: "legendContainer",
|
|
932
|
+
references: colorReference
|
|
933
|
+
}
|
|
934
|
+
)
|
|
935
|
+
] });
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
const Bar = ({
|
|
939
|
+
bar,
|
|
940
|
+
barGroup,
|
|
941
|
+
chart,
|
|
942
|
+
parsedData,
|
|
943
|
+
isSingle,
|
|
944
|
+
setsWithColor
|
|
945
|
+
}) => {
|
|
946
|
+
var _a;
|
|
947
|
+
const column = arrayOrArray(chart.dataSets.data)[bar.index];
|
|
948
|
+
const set = arrayOrArray(column == null ? void 0 : column.sets)[barGroup.index];
|
|
949
|
+
const currentBarColor = (_a = setsWithColor.find(
|
|
950
|
+
(innerSet) => innerSet.columnName === column.name && innerSet.key === set.key
|
|
951
|
+
)) == null ? void 0 : _a.color;
|
|
952
|
+
const [isHighlighted, setIsHighlighted] = useState(false);
|
|
953
|
+
const [isAnyHighlighted, setIsAnyHighlighted] = useState(false);
|
|
954
|
+
const { open } = useTooltip({
|
|
955
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
956
|
+
/* @__PURE__ */ jsx(
|
|
957
|
+
"div",
|
|
958
|
+
{
|
|
959
|
+
style: {
|
|
960
|
+
color: currentBarColor
|
|
961
|
+
},
|
|
962
|
+
children: /* @__PURE__ */ jsx("strong", { children: parsedData[barGroup.index].columnName })
|
|
963
|
+
}
|
|
964
|
+
),
|
|
965
|
+
chart.showValues && /* @__PURE__ */ jsx("div", { children: bar.value }),
|
|
966
|
+
/* @__PURE__ */ jsx("div", { children: bar.key })
|
|
967
|
+
] })
|
|
968
|
+
});
|
|
969
|
+
useImperativeComponentEvents({
|
|
970
|
+
highlight(barName) {
|
|
971
|
+
if (barName.split(" - ").length === 1) {
|
|
972
|
+
setIsHighlighted(barName === bar.key);
|
|
973
|
+
setIsAnyHighlighted(barName !== bar.key && barName !== "");
|
|
974
|
+
} else if (barName.split(" - ").length === 2) {
|
|
975
|
+
setIsHighlighted(
|
|
976
|
+
barName.split(" - ")[0] === bar.key && barName.split(" - ")[1] === set.key
|
|
977
|
+
);
|
|
978
|
+
setIsAnyHighlighted(
|
|
979
|
+
barName.split(" - ")[0] !== bar.key && barName.split(" - ")[0] !== ""
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
const { chartId } = useContext(ChartContext);
|
|
985
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
986
|
+
/* @__PURE__ */ jsx(
|
|
987
|
+
"text",
|
|
988
|
+
{
|
|
989
|
+
x: bar.x + bar.width / 2,
|
|
990
|
+
y: bar.y - 5,
|
|
991
|
+
width: bar.width,
|
|
992
|
+
height: bar.height,
|
|
993
|
+
textAnchor: "middle",
|
|
994
|
+
style: {
|
|
995
|
+
display: isHighlighted ? "block" : "none",
|
|
996
|
+
opacity: isHighlighted ? 1 : 0,
|
|
997
|
+
transition: "opacity 500ms"
|
|
998
|
+
},
|
|
999
|
+
children: bar.value
|
|
1000
|
+
}
|
|
1001
|
+
),
|
|
1002
|
+
/* @__PURE__ */ jsxs(
|
|
1003
|
+
Box,
|
|
1004
|
+
{
|
|
1005
|
+
as: "rect",
|
|
1006
|
+
className: "chart__barRect",
|
|
1007
|
+
sx: useMemo(
|
|
1008
|
+
() => ({
|
|
1009
|
+
fill: isAnyHighlighted ? `#${tinycolor(currentBarColor).desaturate(70).toHex()}` : currentBarColor,
|
|
1010
|
+
"&:hover": {
|
|
1011
|
+
fill: `#${tinycolor(currentBarColor).saturate(25).toHex()}`
|
|
1012
|
+
},
|
|
1013
|
+
transition: "fill 500ms, opacity 500ms",
|
|
1014
|
+
x: bar.x,
|
|
1015
|
+
y: bar.y,
|
|
1016
|
+
width: bar.width,
|
|
1017
|
+
opacity: isAnyHighlighted && !isHighlighted ? 0.15 : 1,
|
|
1018
|
+
height: bar.height > 0 ? bar.height : 0
|
|
1019
|
+
}),
|
|
1020
|
+
[
|
|
1021
|
+
bar.height,
|
|
1022
|
+
bar.width,
|
|
1023
|
+
bar.x,
|
|
1024
|
+
bar.y,
|
|
1025
|
+
currentBarColor,
|
|
1026
|
+
isAnyHighlighted,
|
|
1027
|
+
isHighlighted
|
|
1028
|
+
]
|
|
1029
|
+
),
|
|
1030
|
+
onMouseEnter: (ev) => {
|
|
1031
|
+
var _a2, _b, _c;
|
|
1032
|
+
if (!isSingle) {
|
|
1033
|
+
legendContainerMethods.highlight(chartId, bar.key);
|
|
1034
|
+
}
|
|
1035
|
+
(_a2 = ev.target.classList) == null ? void 0 : _a2.add("over");
|
|
1036
|
+
const point = {
|
|
1037
|
+
x: (_b = localPoint(ev)) == null ? void 0 : _b.x,
|
|
1038
|
+
y: (_c = localPoint(ev)) == null ? void 0 : _c.y
|
|
1039
|
+
};
|
|
1040
|
+
if (!point)
|
|
1041
|
+
return;
|
|
1042
|
+
open({
|
|
1043
|
+
attachToElement: () => ev.target,
|
|
1044
|
+
attachToElementAnchorPoint: "center"
|
|
1045
|
+
});
|
|
1046
|
+
},
|
|
1047
|
+
onMouseLeave: (ev) => {
|
|
1048
|
+
var _a2;
|
|
1049
|
+
if (!isSingle) {
|
|
1050
|
+
legendContainerMethods.highlight(chartId, "");
|
|
1051
|
+
}
|
|
1052
|
+
(_a2 = ev.target.classList) == null ? void 0 : _a2.remove("over");
|
|
1053
|
+
},
|
|
1054
|
+
children: [
|
|
1055
|
+
/* @__PURE__ */ jsx(
|
|
1056
|
+
"animate",
|
|
1057
|
+
{
|
|
1058
|
+
attributeName: "height",
|
|
1059
|
+
from: 0,
|
|
1060
|
+
to: bar.height,
|
|
1061
|
+
dur: "0.5s",
|
|
1062
|
+
calcMode: "paced",
|
|
1063
|
+
keySplines: "0.5 0 0.5 1;",
|
|
1064
|
+
keyTimes: "0; 1"
|
|
1065
|
+
}
|
|
1066
|
+
),
|
|
1067
|
+
/* @__PURE__ */ jsx(
|
|
1068
|
+
"animate",
|
|
1069
|
+
{
|
|
1070
|
+
attributeName: "y",
|
|
1071
|
+
from: bar.y + bar.height,
|
|
1072
|
+
to: bar.y,
|
|
1073
|
+
dur: "0.5s",
|
|
1074
|
+
calcMode: "paced",
|
|
1075
|
+
keySplines: "0.5 0 0.5 1;",
|
|
1076
|
+
keyTimes: "0; 1"
|
|
1077
|
+
}
|
|
1078
|
+
)
|
|
1079
|
+
]
|
|
1080
|
+
}
|
|
1081
|
+
)
|
|
1082
|
+
] });
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
var __defProp$4 = Object.defineProperty;
|
|
1086
|
+
var __defProps$4 = Object.defineProperties;
|
|
1087
|
+
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
1088
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
1089
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
1090
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
1091
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1092
|
+
var __spreadValues$4 = (a, b) => {
|
|
1093
|
+
for (var prop in b || (b = {}))
|
|
1094
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
1095
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
1096
|
+
if (__getOwnPropSymbols$4)
|
|
1097
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
1098
|
+
if (__propIsEnum$4.call(b, prop))
|
|
1099
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
1100
|
+
}
|
|
1101
|
+
return a;
|
|
1102
|
+
};
|
|
1103
|
+
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
1104
|
+
function adjustDimensions$2({
|
|
1105
|
+
width,
|
|
1106
|
+
height,
|
|
1107
|
+
maxWidth
|
|
1108
|
+
}) {
|
|
1109
|
+
if (width <= maxWidth) {
|
|
1110
|
+
return { width, height };
|
|
1111
|
+
}
|
|
1112
|
+
const ratio = width / height;
|
|
1113
|
+
const newWidth = maxWidth;
|
|
1114
|
+
const newHeight = Math.floor(newWidth / ratio);
|
|
1115
|
+
return { width: newWidth, height: newHeight };
|
|
1116
|
+
}
|
|
1117
|
+
const getXValue = (d) => d.columnName;
|
|
1118
|
+
const VerticalBars = ({
|
|
1119
|
+
margin = { top: 20, left: 100, bottom: 150, right: 20 },
|
|
1120
|
+
chart,
|
|
1121
|
+
className,
|
|
1122
|
+
chartId,
|
|
1123
|
+
allowZoom
|
|
1124
|
+
}) => {
|
|
1125
|
+
var _a;
|
|
1126
|
+
const effectiveMargin = parseMargin(margin);
|
|
1127
|
+
if (!chart.showAxisYTitle) {
|
|
1128
|
+
effectiveMargin.left = 50;
|
|
1129
|
+
}
|
|
1130
|
+
let innerWidth = chart.ratio.width + (-effectiveMargin.left - effectiveMargin.right) / 2;
|
|
1131
|
+
let innerHeight = chart.ratio.height + (-effectiveMargin.top - effectiveMargin.bottom) / 2;
|
|
1132
|
+
if (innerWidth > chart.ratio.maxWidth) {
|
|
1133
|
+
const newValues = adjustDimensions$2({
|
|
1134
|
+
height: innerHeight,
|
|
1135
|
+
width: innerWidth,
|
|
1136
|
+
maxWidth: chart.ratio.maxWidth
|
|
1137
|
+
});
|
|
1138
|
+
innerWidth = newValues.width;
|
|
1139
|
+
innerHeight = newValues.height;
|
|
1140
|
+
}
|
|
1141
|
+
const styles = useChartStyles(chart.colorSchema);
|
|
1142
|
+
const columnas = arrayOrArray((_a = chart.dataSets) == null ? void 0 : _a.data).filter((column) => !!column.sets).map((column) => {
|
|
1143
|
+
return __spreadProps$4(__spreadValues$4({}, column), {
|
|
1144
|
+
sets: column.sets
|
|
1145
|
+
});
|
|
1146
|
+
});
|
|
1147
|
+
const xValues = arrayOrArray(columnas[0].sets).map(
|
|
1148
|
+
(innerCoord) => innerCoord.key
|
|
1149
|
+
);
|
|
1150
|
+
const columnNames = columnas.map((col) => {
|
|
1151
|
+
return col.name;
|
|
1152
|
+
});
|
|
1153
|
+
const parsedData = xValues.map((x) => {
|
|
1154
|
+
const obj = columnas.reduce(
|
|
1155
|
+
(acc, column) => {
|
|
1156
|
+
return __spreadProps$4(__spreadValues$4({}, acc), {
|
|
1157
|
+
[column.name]: arrayOrArray(column.sets).filter((coord) => {
|
|
1158
|
+
return coord.key === x;
|
|
1159
|
+
})[0].value
|
|
1160
|
+
});
|
|
1161
|
+
},
|
|
1162
|
+
{ columnName: x }
|
|
1163
|
+
);
|
|
1164
|
+
return obj;
|
|
1165
|
+
});
|
|
1166
|
+
const xScale = scaleBand({
|
|
1167
|
+
range: [
|
|
1168
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.left,
|
|
1169
|
+
innerWidth
|
|
1170
|
+
],
|
|
1171
|
+
domain: parsedData.map(getXValue),
|
|
1172
|
+
padding: 0.2
|
|
1173
|
+
});
|
|
1174
|
+
const columnGroupScale = scaleBand({
|
|
1175
|
+
domain: columnNames,
|
|
1176
|
+
range: [0, xScale.bandwidth()]
|
|
1177
|
+
});
|
|
1178
|
+
const yScaleLog = scaleLog({
|
|
1179
|
+
range: [
|
|
1180
|
+
innerHeight,
|
|
1181
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top
|
|
1182
|
+
],
|
|
1183
|
+
domain: [
|
|
1184
|
+
1,
|
|
1185
|
+
Math.max(
|
|
1186
|
+
...parsedData.map(
|
|
1187
|
+
(d) => Math.max(...columnNames.map((key) => Number(d[key])))
|
|
1188
|
+
)
|
|
1189
|
+
)
|
|
1190
|
+
],
|
|
1191
|
+
base: 10
|
|
1192
|
+
});
|
|
1193
|
+
const yScaleLine = scaleLinear({
|
|
1194
|
+
range: [
|
|
1195
|
+
innerHeight,
|
|
1196
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top
|
|
1197
|
+
],
|
|
1198
|
+
domain: [
|
|
1199
|
+
0,
|
|
1200
|
+
Math.max(
|
|
1201
|
+
...parsedData.map(
|
|
1202
|
+
(d) => Math.max(...columnNames.map((key) => Number(d[key])))
|
|
1203
|
+
)
|
|
1204
|
+
)
|
|
1205
|
+
]
|
|
1206
|
+
});
|
|
1207
|
+
const color = scaleOrdinal({
|
|
1208
|
+
domain: columnNames,
|
|
1209
|
+
range: columnas.map((col) => col.color)
|
|
1210
|
+
});
|
|
1211
|
+
const parameters = usePanelParametersSelector((global) => {
|
|
1212
|
+
return global;
|
|
1213
|
+
});
|
|
1214
|
+
const scale = parameters.PRMT_CHART_SCALE;
|
|
1215
|
+
const isLogScale = scale === "0";
|
|
1216
|
+
const yScale = useMemo(() => {
|
|
1217
|
+
if (!isLogScale) {
|
|
1218
|
+
return yScaleLine;
|
|
1219
|
+
}
|
|
1220
|
+
return yScaleLog;
|
|
1221
|
+
}, [isLogScale, yScaleLine, yScaleLog]);
|
|
1222
|
+
const id = useMemo(() => `VerticalBars${uniqueId()}`, []);
|
|
1223
|
+
useLayoutEffect(() => {
|
|
1224
|
+
document.querySelectorAll(`#${id} .tickLabel`).forEach((current) => {
|
|
1225
|
+
const width = current.getBoundingClientRect().width;
|
|
1226
|
+
current.style.transformOrigin = current.getAttribute("x") + "px 14px";
|
|
1227
|
+
current.style.transform = `rotate(25deg) translateX(${width / 2}px)`;
|
|
1228
|
+
});
|
|
1229
|
+
});
|
|
1230
|
+
const { boxRef, elementRef } = usePanAndZoom(
|
|
1231
|
+
void 0,
|
|
1232
|
+
!allowZoom
|
|
1233
|
+
);
|
|
1234
|
+
const setsWithColor = arrayOrArray(chart.dataSets.data).map((data, index) => {
|
|
1235
|
+
const isSingle = arrayOrArray(chart.dataSets.data).length === 1;
|
|
1236
|
+
const dataColor = data.color !== "" && data.color !== void 0 ? data.color : arrayOrArray(styles.schema).length > 0 ? getBarColor(arrayOrArray(styles.schema), index, isSingle) : "";
|
|
1237
|
+
const returnColumnsArray = [];
|
|
1238
|
+
arrayOrArray(data.sets).forEach((set) => {
|
|
1239
|
+
if (set.color !== "" && set.color !== void 0) {
|
|
1240
|
+
returnColumnsArray.push(__spreadProps$4(__spreadValues$4({}, set), { columnName: data.name }));
|
|
1241
|
+
} else {
|
|
1242
|
+
returnColumnsArray.push(__spreadProps$4(__spreadValues$4({}, set), {
|
|
1243
|
+
color: dataColor,
|
|
1244
|
+
columnName: data.name
|
|
1245
|
+
}));
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
return returnColumnsArray;
|
|
1249
|
+
});
|
|
1250
|
+
const colorReference = arrayOrArray(chart.dataSets.data).map(
|
|
1251
|
+
(data, index) => {
|
|
1252
|
+
const isSingle = arrayOrArray(chart.dataSets.data).length === 1;
|
|
1253
|
+
const dataColor = data.color !== "" && data.color !== void 0 ? data.color : arrayOrArray(styles.schema).length > 0 ? getBarColor(arrayOrArray(styles.schema), index, isSingle) : "";
|
|
1254
|
+
return {
|
|
1255
|
+
color: dataColor,
|
|
1256
|
+
title: data.name
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
);
|
|
1260
|
+
arrayOrArray(chart.dataSets.data).map((data) => {
|
|
1261
|
+
const returnArray = [];
|
|
1262
|
+
arrayOrArray(data.sets).forEach((set) => {
|
|
1263
|
+
if (set.color !== "" && set.color !== void 0) {
|
|
1264
|
+
returnArray.push({
|
|
1265
|
+
color: set.color,
|
|
1266
|
+
title: data.name + " - " + set.key
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
return returnArray;
|
|
1271
|
+
}).flat().forEach((addRef) => colorReference.push(addRef));
|
|
1272
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1273
|
+
/* @__PURE__ */ jsx(
|
|
1274
|
+
Box,
|
|
1275
|
+
{
|
|
1276
|
+
ref: boxRef,
|
|
1277
|
+
id,
|
|
1278
|
+
className: `${className != null ? className : ""} ${chart.title}`,
|
|
1279
|
+
sx: {
|
|
1280
|
+
overflow: "hidden"
|
|
1281
|
+
},
|
|
1282
|
+
children: /* @__PURE__ */ jsxs(
|
|
1283
|
+
"svg",
|
|
1284
|
+
{
|
|
1285
|
+
ref: elementRef,
|
|
1286
|
+
className: `_${chartId} chart__svg`,
|
|
1287
|
+
height: chart.ratio.height,
|
|
1288
|
+
width: chart.ratio.width,
|
|
1289
|
+
children: [
|
|
1290
|
+
chart.showGrid && /* @__PURE__ */ jsx(
|
|
1291
|
+
Grid.Grid,
|
|
1292
|
+
{
|
|
1293
|
+
xScale,
|
|
1294
|
+
yScale,
|
|
1295
|
+
left: 0,
|
|
1296
|
+
width: innerWidth,
|
|
1297
|
+
height: innerHeight,
|
|
1298
|
+
numTicksRows: 10,
|
|
1299
|
+
numTicksColumns: 10,
|
|
1300
|
+
top: (typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top) - 20
|
|
1301
|
+
}
|
|
1302
|
+
),
|
|
1303
|
+
/* @__PURE__ */ jsx(
|
|
1304
|
+
Group,
|
|
1305
|
+
{
|
|
1306
|
+
top: (typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top) - 20,
|
|
1307
|
+
children: /* @__PURE__ */ jsx(
|
|
1308
|
+
BarGroup,
|
|
1309
|
+
{
|
|
1310
|
+
data: parsedData,
|
|
1311
|
+
keys: columnNames,
|
|
1312
|
+
height: innerHeight,
|
|
1313
|
+
x0: getXValue,
|
|
1314
|
+
x0Scale: xScale,
|
|
1315
|
+
x1Scale: columnGroupScale,
|
|
1316
|
+
yScale,
|
|
1317
|
+
color,
|
|
1318
|
+
children: (barGroups) => barGroups.map((barGroup) => {
|
|
1319
|
+
return /* @__PURE__ */ jsx(
|
|
1320
|
+
Group,
|
|
1321
|
+
{
|
|
1322
|
+
left: barGroup.x0,
|
|
1323
|
+
children: barGroup.bars.map((bar) => {
|
|
1324
|
+
const key = `${barGroup.index}-${bar.index}-${bar.key}`;
|
|
1325
|
+
return /* @__PURE__ */ jsx(
|
|
1326
|
+
Bar,
|
|
1327
|
+
{
|
|
1328
|
+
isSingle: barGroup.bars.length === 1,
|
|
1329
|
+
bar,
|
|
1330
|
+
barGroup,
|
|
1331
|
+
chart,
|
|
1332
|
+
parsedData,
|
|
1333
|
+
setsWithColor: setsWithColor.flat()
|
|
1334
|
+
},
|
|
1335
|
+
key
|
|
1336
|
+
);
|
|
1337
|
+
})
|
|
1338
|
+
},
|
|
1339
|
+
`bar-group-${barGroup.index}-${barGroup.x0}`
|
|
1340
|
+
);
|
|
1341
|
+
})
|
|
1342
|
+
}
|
|
1343
|
+
)
|
|
1344
|
+
}
|
|
1345
|
+
),
|
|
1346
|
+
/* @__PURE__ */ jsx(
|
|
1347
|
+
AxisLeft,
|
|
1348
|
+
{
|
|
1349
|
+
scale: yScale,
|
|
1350
|
+
left: effectiveMargin.left,
|
|
1351
|
+
label: chart.chartType !== "pie2D" && chart.showAxisYTitle ? chart.axisYTitle : ""
|
|
1352
|
+
}
|
|
1353
|
+
),
|
|
1354
|
+
/* @__PURE__ */ jsx(
|
|
1355
|
+
AxisBottom,
|
|
1356
|
+
{
|
|
1357
|
+
top: innerHeight,
|
|
1358
|
+
scale: xScale,
|
|
1359
|
+
label: chart.chartType !== "pie2D" && chart.showAxisXTitle ? chart.axisXTitle : "",
|
|
1360
|
+
tickLabelProps: {
|
|
1361
|
+
className: "tickLabel"
|
|
1362
|
+
},
|
|
1363
|
+
labelOffset: 50
|
|
1364
|
+
}
|
|
1365
|
+
)
|
|
1366
|
+
]
|
|
1367
|
+
}
|
|
1368
|
+
)
|
|
1369
|
+
}
|
|
1370
|
+
),
|
|
1371
|
+
colorReference.length > 1 && /* @__PURE__ */ jsx(
|
|
1372
|
+
LegendContainer,
|
|
1373
|
+
{
|
|
1374
|
+
id: chartId,
|
|
1375
|
+
containerClassName: "legendContainer",
|
|
1376
|
+
references: (
|
|
1377
|
+
// hideLegendsColors
|
|
1378
|
+
// ? colorReference.map((ref) => {
|
|
1379
|
+
// return { ...ref, color: 'transparent' };
|
|
1380
|
+
// })
|
|
1381
|
+
colorReference
|
|
1382
|
+
)
|
|
1383
|
+
}
|
|
1384
|
+
)
|
|
1385
|
+
] });
|
|
1386
|
+
};
|
|
1387
|
+
|
|
1388
|
+
const Node = ({
|
|
1389
|
+
currentCircle,
|
|
1390
|
+
innerKey,
|
|
1391
|
+
cx,
|
|
1392
|
+
cy,
|
|
1393
|
+
// coordinate,
|
|
1394
|
+
color,
|
|
1395
|
+
setCurrentCircle
|
|
1396
|
+
}) => {
|
|
1397
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
1398
|
+
currentCircle.includes(innerKey) && /* @__PURE__ */ jsx(
|
|
1399
|
+
"circle",
|
|
1400
|
+
{
|
|
1401
|
+
r: 6,
|
|
1402
|
+
cx,
|
|
1403
|
+
cy,
|
|
1404
|
+
stroke: `#${tinycolor(color).saturate(25).toHex()}`,
|
|
1405
|
+
fill: `#${tinycolor(color).saturate(25).toHex()}`
|
|
1406
|
+
}
|
|
1407
|
+
),
|
|
1408
|
+
/* @__PURE__ */ jsx(
|
|
1409
|
+
"circle",
|
|
1410
|
+
{
|
|
1411
|
+
r: 3,
|
|
1412
|
+
cx,
|
|
1413
|
+
cy,
|
|
1414
|
+
stroke: `#${tinycolor(color).darken(15).toHex()}`,
|
|
1415
|
+
fill: `#${tinycolor(color).darken(15).toHex()}`
|
|
1416
|
+
}
|
|
1417
|
+
),
|
|
1418
|
+
/* @__PURE__ */ jsx(
|
|
1419
|
+
"circle",
|
|
1420
|
+
{
|
|
1421
|
+
r: 10,
|
|
1422
|
+
cx,
|
|
1423
|
+
cy,
|
|
1424
|
+
stroke: "transparent",
|
|
1425
|
+
fill: "transparent",
|
|
1426
|
+
onMouseEnter: () => {
|
|
1427
|
+
setCurrentCircle([innerKey]);
|
|
1428
|
+
},
|
|
1429
|
+
onMouseLeave: () => {
|
|
1430
|
+
setCurrentCircle([]);
|
|
1431
|
+
},
|
|
1432
|
+
style: { cursor: "pointer" }
|
|
1433
|
+
}
|
|
1434
|
+
)
|
|
1435
|
+
] }, innerKey);
|
|
1436
|
+
};
|
|
1437
|
+
|
|
1438
|
+
var __defProp$3 = Object.defineProperty;
|
|
1439
|
+
var __defProps$3 = Object.defineProperties;
|
|
1440
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
1441
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
1442
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
1443
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
1444
|
+
var __pow = Math.pow;
|
|
1445
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1446
|
+
var __spreadValues$3 = (a, b) => {
|
|
1447
|
+
for (var prop in b || (b = {}))
|
|
1448
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
1449
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
1450
|
+
if (__getOwnPropSymbols$3)
|
|
1451
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
1452
|
+
if (__propIsEnum$3.call(b, prop))
|
|
1453
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
1454
|
+
}
|
|
1455
|
+
return a;
|
|
1456
|
+
};
|
|
1457
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
1458
|
+
function adjustDimensions$1({
|
|
1459
|
+
width,
|
|
1460
|
+
height,
|
|
1461
|
+
maxWidth
|
|
1462
|
+
}) {
|
|
1463
|
+
if (width <= maxWidth) {
|
|
1464
|
+
return { width, height };
|
|
1465
|
+
}
|
|
1466
|
+
const ratio = width / height;
|
|
1467
|
+
const newWidth = maxWidth;
|
|
1468
|
+
const newHeight = Math.floor(newWidth / ratio);
|
|
1469
|
+
return { width: newWidth, height: newHeight };
|
|
1470
|
+
}
|
|
1471
|
+
function getX(coordinate) {
|
|
1472
|
+
return coordinate.key;
|
|
1473
|
+
}
|
|
1474
|
+
function getY(coordinate) {
|
|
1475
|
+
return Number(coordinate.value);
|
|
1476
|
+
}
|
|
1477
|
+
function parseData(chart) {
|
|
1478
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1479
|
+
const columns = arrayOrArray((_a = chart.dataSets) == null ? void 0 : _a.data);
|
|
1480
|
+
const data = columns.map((column) => column.sets);
|
|
1481
|
+
const allData = data.reduce(
|
|
1482
|
+
(rec, d) => arrayOrArray(rec).concat(d),
|
|
1483
|
+
[]
|
|
1484
|
+
);
|
|
1485
|
+
return {
|
|
1486
|
+
columns,
|
|
1487
|
+
xScale: scaleOrdinal({
|
|
1488
|
+
domain: arrayOrArray(columns[0].sets).map(getX)
|
|
1489
|
+
}),
|
|
1490
|
+
yScale: scaleLinear({
|
|
1491
|
+
domain: [
|
|
1492
|
+
((_b = min(allData, getY)) != null ? _b : 0 < 0) ? (_c = min(allData, getY)) != null ? _c : 0 : 0,
|
|
1493
|
+
(_d = max(allData, getY)) != null ? _d : 1
|
|
1494
|
+
]
|
|
1495
|
+
}),
|
|
1496
|
+
yScaleLog: scaleLog({
|
|
1497
|
+
domain: [
|
|
1498
|
+
((_e = min(allData, getY)) != null ? _e : 1 > 0) ? (_f = min(allData, getY)) != null ? _f : 1 : 1,
|
|
1499
|
+
(_g = max(allData, getY)) != null ? _g : 10
|
|
1500
|
+
]
|
|
1501
|
+
})
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
const LineChart = ({
|
|
1505
|
+
chart,
|
|
1506
|
+
margin = { top: 20, left: 100, bottom: 150, right: 70 },
|
|
1507
|
+
chartId,
|
|
1508
|
+
allowZoom
|
|
1509
|
+
}) => {
|
|
1510
|
+
const effectiveMargin = parseMargin(margin);
|
|
1511
|
+
if (!chart.showAxisYTitle) {
|
|
1512
|
+
effectiveMargin.left = 50;
|
|
1513
|
+
}
|
|
1514
|
+
let innerWidth = chart.ratio.width;
|
|
1515
|
+
let innerHeight = chart.ratio.height - (effectiveMargin.top + effectiveMargin.bottom) / 2;
|
|
1516
|
+
if (innerWidth > chart.ratio.maxWidth) {
|
|
1517
|
+
const newValues = adjustDimensions$1({
|
|
1518
|
+
height: innerHeight,
|
|
1519
|
+
width: innerWidth,
|
|
1520
|
+
maxWidth: chart.ratio.maxWidth
|
|
1521
|
+
});
|
|
1522
|
+
innerWidth = newValues.width;
|
|
1523
|
+
innerHeight = newValues.height;
|
|
1524
|
+
}
|
|
1525
|
+
const { columns, xScale, yScale, yScaleLog } = parseData(chart);
|
|
1526
|
+
const styles = useChartStyles(chart.colorSchema);
|
|
1527
|
+
const coordinates = arrayOrArray(columns[0].sets);
|
|
1528
|
+
const coordinatesArray = columns.map((col) => {
|
|
1529
|
+
return col.sets;
|
|
1530
|
+
});
|
|
1531
|
+
const step = innerWidth / coordinates.length;
|
|
1532
|
+
xScale.range(
|
|
1533
|
+
coordinates.map((_, i) => {
|
|
1534
|
+
if (i === 0) {
|
|
1535
|
+
return effectiveMargin.left;
|
|
1536
|
+
}
|
|
1537
|
+
return i * step + effectiveMargin.left;
|
|
1538
|
+
})
|
|
1539
|
+
);
|
|
1540
|
+
yScale.range([
|
|
1541
|
+
innerHeight - (effectiveMargin.top + effectiveMargin.bottom) / 2,
|
|
1542
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top
|
|
1543
|
+
]);
|
|
1544
|
+
yScaleLog.range([
|
|
1545
|
+
innerHeight,
|
|
1546
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top
|
|
1547
|
+
]);
|
|
1548
|
+
const [currentCircle, setCurrentCircle] = useState([]);
|
|
1549
|
+
const actualYScale = useMemo(() => {
|
|
1550
|
+
return yScale;
|
|
1551
|
+
}, [yScale]);
|
|
1552
|
+
const id = useMemo(() => `VerticalBars${uniqueId()}`, []);
|
|
1553
|
+
useLayoutEffect(() => {
|
|
1554
|
+
document.querySelectorAll(`#${id} .tickLabel`).forEach((current) => {
|
|
1555
|
+
const width = current.getBoundingClientRect().width;
|
|
1556
|
+
current.style.transformOrigin = current.getAttribute("x") + "px 14px";
|
|
1557
|
+
current.style.transform = `rotate(25deg) translateX(${width / 2}px)`;
|
|
1558
|
+
});
|
|
1559
|
+
});
|
|
1560
|
+
function addNameToProps(names, objects, fixedValue) {
|
|
1561
|
+
return objects.map((object, index) => {
|
|
1562
|
+
const nameIndex = Math.floor(index / fixedValue);
|
|
1563
|
+
const name = names[nameIndex];
|
|
1564
|
+
return __spreadProps$3(__spreadValues$3({}, object), { columnName: name });
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
const [nodes, setNodes] = useState([]);
|
|
1568
|
+
useEffect(() => {
|
|
1569
|
+
const coords = coordinatesArray.flat().map((coord) => {
|
|
1570
|
+
return {
|
|
1571
|
+
xValue: coord.key,
|
|
1572
|
+
yValue: coord.value,
|
|
1573
|
+
x: xScale(getX(coord)),
|
|
1574
|
+
y: actualYScale(getY(coord))
|
|
1575
|
+
};
|
|
1576
|
+
});
|
|
1577
|
+
const columnNames = columns.map((column) => {
|
|
1578
|
+
return column.name;
|
|
1579
|
+
});
|
|
1580
|
+
const nodesData = addNameToProps(columnNames, coords, coordinates.length);
|
|
1581
|
+
setNodes(nodesData);
|
|
1582
|
+
}, []);
|
|
1583
|
+
const [nearNodesArray, setNearNodesArray] = useState([]);
|
|
1584
|
+
const previousNearNodesArray = usePrevious(nearNodesArray);
|
|
1585
|
+
const setsWithColor = arrayOrArray(chart.dataSets.data).map((data, index) => {
|
|
1586
|
+
const isSingle = arrayOrArray(chart.dataSets.data).length === 1;
|
|
1587
|
+
const dataColor = data.color !== "" && data.color !== void 0 ? data.color : arrayOrArray(styles.schema).length > 0 ? getBarColor(arrayOrArray(styles.schema), index, isSingle) : "";
|
|
1588
|
+
const returnColumnsArray = [];
|
|
1589
|
+
arrayOrArray(data.sets).forEach((set) => {
|
|
1590
|
+
if (set.color !== "" && set.color !== void 0) {
|
|
1591
|
+
returnColumnsArray.push(__spreadProps$3(__spreadValues$3({}, set), { columnName: data.name }));
|
|
1592
|
+
} else {
|
|
1593
|
+
returnColumnsArray.push(__spreadProps$3(__spreadValues$3({}, set), {
|
|
1594
|
+
color: dataColor,
|
|
1595
|
+
columnName: data.name
|
|
1596
|
+
}));
|
|
1597
|
+
}
|
|
1598
|
+
});
|
|
1599
|
+
return { returnColumnsArray, columnColor: dataColor };
|
|
1600
|
+
});
|
|
1601
|
+
const colorReference = setsWithColor.map((column) => {
|
|
1602
|
+
var _a;
|
|
1603
|
+
return {
|
|
1604
|
+
color: (_a = column.columnColor) != null ? _a : "",
|
|
1605
|
+
title: column.returnColumnsArray[0].columnName
|
|
1606
|
+
};
|
|
1607
|
+
});
|
|
1608
|
+
arrayOrArray(chart.dataSets.data).map((data) => {
|
|
1609
|
+
const returnArray = [];
|
|
1610
|
+
arrayOrArray(data.sets).forEach((set) => {
|
|
1611
|
+
if (set.color !== "" && set.color !== void 0) {
|
|
1612
|
+
returnArray.push({
|
|
1613
|
+
color: set.color,
|
|
1614
|
+
title: data.name + " - " + set.key
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
return returnArray;
|
|
1619
|
+
}).flat().forEach((addRef) => colorReference.push(addRef));
|
|
1620
|
+
const { open } = useTooltip({
|
|
1621
|
+
children: nearNodesArray.sort((a, b) => Number(b.yValue) - Number(a.yValue)).map((node, i) => {
|
|
1622
|
+
const useSpecific = colorReference.some(
|
|
1623
|
+
(ref) => ref.title === node.columnName + " - " + node.xValue
|
|
1624
|
+
);
|
|
1625
|
+
return /* @__PURE__ */ jsxs(Box, { children: [
|
|
1626
|
+
/* @__PURE__ */ jsx(
|
|
1627
|
+
"div",
|
|
1628
|
+
{
|
|
1629
|
+
style: {
|
|
1630
|
+
color: colorReference[colorReference.findIndex((ref) => {
|
|
1631
|
+
return ref.title === (useSpecific ? node.columnName + " - " + node.xValue : node.columnName);
|
|
1632
|
+
})].color
|
|
1633
|
+
},
|
|
1634
|
+
children: /* @__PURE__ */ jsx("strong", { children: node.columnName })
|
|
1635
|
+
}
|
|
1636
|
+
),
|
|
1637
|
+
chart.showValues && /* @__PURE__ */ jsx("div", { children: node.yValue }),
|
|
1638
|
+
/* @__PURE__ */ jsx("div", { children: node.xValue }),
|
|
1639
|
+
nearNodesArray[i + 1] && /* @__PURE__ */ jsx("hr", {})
|
|
1640
|
+
] }, `${node.columnName}_${node.xValue}_${node.yValue}`);
|
|
1641
|
+
})
|
|
1642
|
+
});
|
|
1643
|
+
const [highlightedBar, setHighlightedBar] = useState("");
|
|
1644
|
+
useImperativeComponentEvents({
|
|
1645
|
+
highlight(barName) {
|
|
1646
|
+
if (barName.split(" - ").length === 1) {
|
|
1647
|
+
setHighlightedBar(barName);
|
|
1648
|
+
} else if (barName.split(" - ").length === 2) {
|
|
1649
|
+
setHighlightedBar(barName.split(" - ")[0]);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
});
|
|
1653
|
+
const { boxRef, elementRef } = usePanAndZoom(
|
|
1654
|
+
void 0,
|
|
1655
|
+
!allowZoom
|
|
1656
|
+
);
|
|
1657
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1658
|
+
/* @__PURE__ */ jsx(Box, { id, ref: boxRef, children: /* @__PURE__ */ jsxs(
|
|
1659
|
+
"svg",
|
|
1660
|
+
{
|
|
1661
|
+
ref: elementRef,
|
|
1662
|
+
width: innerWidth,
|
|
1663
|
+
height: innerHeight,
|
|
1664
|
+
id: "LinesChart",
|
|
1665
|
+
className: `_${chartId} chart__svg`,
|
|
1666
|
+
onMouseMove: (ev) => {
|
|
1667
|
+
var _a;
|
|
1668
|
+
const rect = (_a = elementRef.current) == null ? void 0 : _a.getBoundingClientRect();
|
|
1669
|
+
let clientX = ev.clientX;
|
|
1670
|
+
let clientY = ev.clientY - (effectiveMargin.top + effectiveMargin.bottom) / 2;
|
|
1671
|
+
if (rect) {
|
|
1672
|
+
clientX = ev.clientX - rect.left;
|
|
1673
|
+
clientY = ev.clientY - rect.top;
|
|
1674
|
+
}
|
|
1675
|
+
const nearNodes = nodes.filter((node) => {
|
|
1676
|
+
return Math.sqrt(__pow(node.x - clientX, 2) + __pow(node.y - clientY, 2)) < 20;
|
|
1677
|
+
});
|
|
1678
|
+
if (previousNearNodesArray.current && nearNodes.length > 0) {
|
|
1679
|
+
const currentColumns = columns.map((col) => {
|
|
1680
|
+
let colNames = "";
|
|
1681
|
+
nearNodes.forEach((node) => {
|
|
1682
|
+
if (col.name === node.columnName) {
|
|
1683
|
+
colNames = node.columnName;
|
|
1684
|
+
}
|
|
1685
|
+
});
|
|
1686
|
+
return colNames;
|
|
1687
|
+
}).filter((name) => name !== "");
|
|
1688
|
+
const currentIndex = coordinates.findIndex((coord) => {
|
|
1689
|
+
return coord.key === nearNodes[0].xValue;
|
|
1690
|
+
});
|
|
1691
|
+
if (currentColumns && currentIndex !== void 0) {
|
|
1692
|
+
const newCircleValues = currentColumns.map((col) => {
|
|
1693
|
+
return `${col}${currentIndex}`;
|
|
1694
|
+
});
|
|
1695
|
+
setCurrentCircle([...newCircleValues]);
|
|
1696
|
+
}
|
|
1697
|
+
setNearNodesArray(nearNodes);
|
|
1698
|
+
open({
|
|
1699
|
+
attachToElement: () => ev.target,
|
|
1700
|
+
attachToElementAnchorPoint: "center"
|
|
1701
|
+
});
|
|
1702
|
+
} else if (nearNodes.length === 0) {
|
|
1703
|
+
setCurrentCircle([]);
|
|
1704
|
+
}
|
|
1705
|
+
},
|
|
1706
|
+
children: [
|
|
1707
|
+
chart.showGrid && /* @__PURE__ */ jsx(
|
|
1708
|
+
Grid.Grid,
|
|
1709
|
+
{
|
|
1710
|
+
top: (typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top) - 20,
|
|
1711
|
+
left: 0,
|
|
1712
|
+
xScale,
|
|
1713
|
+
yScale: actualYScale,
|
|
1714
|
+
width: innerWidth,
|
|
1715
|
+
height: innerHeight,
|
|
1716
|
+
stroke: styles.grid.stroke,
|
|
1717
|
+
strokeOpacity: styles.grid.opacity
|
|
1718
|
+
}
|
|
1719
|
+
),
|
|
1720
|
+
columns.map((column, i) => {
|
|
1721
|
+
var _a;
|
|
1722
|
+
const currentCoordinates = arrayOrArray(column.sets);
|
|
1723
|
+
const newColor = (_a = setsWithColor.find(
|
|
1724
|
+
(data) => data.returnColumnsArray[0].columnName === column.name
|
|
1725
|
+
)) == null ? void 0 : _a.columnColor;
|
|
1726
|
+
return /* @__PURE__ */ jsxs(
|
|
1727
|
+
Group,
|
|
1728
|
+
{
|
|
1729
|
+
top: (typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top) - 20,
|
|
1730
|
+
style: {
|
|
1731
|
+
opacity: highlightedBar !== "" && highlightedBar !== column.name ? 0.15 : 1,
|
|
1732
|
+
transition: "opacity 500ms"
|
|
1733
|
+
},
|
|
1734
|
+
children: [
|
|
1735
|
+
/* @__PURE__ */ jsx(
|
|
1736
|
+
LinePath,
|
|
1737
|
+
{
|
|
1738
|
+
curve: allCurves.curveMonotoneX,
|
|
1739
|
+
data: currentCoordinates,
|
|
1740
|
+
x: (coordinate) => {
|
|
1741
|
+
var _a2;
|
|
1742
|
+
return (_a2 = xScale(getX(coordinate))) != null ? _a2 : 0;
|
|
1743
|
+
},
|
|
1744
|
+
y: (coordinate) => {
|
|
1745
|
+
var _a2;
|
|
1746
|
+
return (_a2 = actualYScale(getY(coordinate))) != null ? _a2 : 0;
|
|
1747
|
+
},
|
|
1748
|
+
stroke: newColor != null ? newColor : "black",
|
|
1749
|
+
strokeWidth: 2,
|
|
1750
|
+
strokeOpacity: 1,
|
|
1751
|
+
shapeRendering: "geometricPrecision"
|
|
1752
|
+
}
|
|
1753
|
+
),
|
|
1754
|
+
currentCoordinates.map((coordinate, j) => {
|
|
1755
|
+
var _a2;
|
|
1756
|
+
const key = column.name + j.toString();
|
|
1757
|
+
const realColor = (_a2 = setsWithColor.map((sets) => sets.returnColumnsArray).flat().find(
|
|
1758
|
+
(set) => set.columnName === column.name && set.key === coordinate.key
|
|
1759
|
+
)) == null ? void 0 : _a2.color;
|
|
1760
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
1761
|
+
/* @__PURE__ */ jsx(
|
|
1762
|
+
"text",
|
|
1763
|
+
{
|
|
1764
|
+
x: xScale(getX(coordinate)) + 10,
|
|
1765
|
+
y: actualYScale(getY(coordinate)) - 5,
|
|
1766
|
+
textAnchor: "middle",
|
|
1767
|
+
style: {
|
|
1768
|
+
display: highlightedBar === column.name ? "block" : "none",
|
|
1769
|
+
opacity: highlightedBar === column.name ? 1 : 0,
|
|
1770
|
+
transition: "opacity 500ms"
|
|
1771
|
+
},
|
|
1772
|
+
children: coordinate.value
|
|
1773
|
+
}
|
|
1774
|
+
),
|
|
1775
|
+
/* @__PURE__ */ jsx(
|
|
1776
|
+
Node,
|
|
1777
|
+
{
|
|
1778
|
+
color: realColor != null ? realColor : "black",
|
|
1779
|
+
coordinate,
|
|
1780
|
+
currentCircle,
|
|
1781
|
+
cx: xScale(getX(coordinate)),
|
|
1782
|
+
cy: actualYScale(getY(coordinate)),
|
|
1783
|
+
setCurrentCircle,
|
|
1784
|
+
innerKey: key,
|
|
1785
|
+
column
|
|
1786
|
+
}
|
|
1787
|
+
)
|
|
1788
|
+
] }, key);
|
|
1789
|
+
})
|
|
1790
|
+
]
|
|
1791
|
+
},
|
|
1792
|
+
`lines-${column.name + i.toString()}`
|
|
1793
|
+
);
|
|
1794
|
+
}),
|
|
1795
|
+
/* @__PURE__ */ jsx(
|
|
1796
|
+
AxisLeft,
|
|
1797
|
+
{
|
|
1798
|
+
scale: actualYScale,
|
|
1799
|
+
left: effectiveMargin.left,
|
|
1800
|
+
label: chart.chartType !== "pie2D" && chart.showAxisYTitle ? chart.axisYTitle : ""
|
|
1801
|
+
}
|
|
1802
|
+
),
|
|
1803
|
+
/* @__PURE__ */ jsx(
|
|
1804
|
+
AxisBottom,
|
|
1805
|
+
{
|
|
1806
|
+
top: innerHeight - (effectiveMargin.top + effectiveMargin.bottom) / 2,
|
|
1807
|
+
scale: xScale,
|
|
1808
|
+
label: chart.chartType !== "pie2D" && chart.showAxisXTitle ? chart.axisXTitle : "",
|
|
1809
|
+
tickLabelProps: {
|
|
1810
|
+
className: "tickLabel"
|
|
1811
|
+
},
|
|
1812
|
+
labelOffset: 50
|
|
1813
|
+
}
|
|
1814
|
+
)
|
|
1815
|
+
]
|
|
1816
|
+
}
|
|
1817
|
+
) }),
|
|
1818
|
+
colorReference.length > 1 && /* @__PURE__ */ jsx(
|
|
1819
|
+
LegendContainer,
|
|
1820
|
+
{
|
|
1821
|
+
id: chartId,
|
|
1822
|
+
containerClassName: "legendContainer",
|
|
1823
|
+
references: colorReference
|
|
1824
|
+
}
|
|
1825
|
+
)
|
|
1826
|
+
] });
|
|
1827
|
+
};
|
|
1828
|
+
|
|
1829
|
+
const WaterfallBar = ({
|
|
1830
|
+
width,
|
|
1831
|
+
height,
|
|
1832
|
+
x,
|
|
1833
|
+
y,
|
|
1834
|
+
fill,
|
|
1835
|
+
x1,
|
|
1836
|
+
lineY,
|
|
1837
|
+
x2,
|
|
1838
|
+
stroke,
|
|
1839
|
+
strokeDashArray,
|
|
1840
|
+
textX,
|
|
1841
|
+
textY,
|
|
1842
|
+
textContent,
|
|
1843
|
+
isLast,
|
|
1844
|
+
step,
|
|
1845
|
+
columnName,
|
|
1846
|
+
chart
|
|
1847
|
+
}) => {
|
|
1848
|
+
const { open } = useTooltip({
|
|
1849
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1850
|
+
/* @__PURE__ */ jsx(
|
|
1851
|
+
"div",
|
|
1852
|
+
{
|
|
1853
|
+
style: {
|
|
1854
|
+
color: step.color
|
|
1855
|
+
},
|
|
1856
|
+
children: /* @__PURE__ */ jsx("strong", { children: columnName })
|
|
1857
|
+
}
|
|
1858
|
+
),
|
|
1859
|
+
chart.showValues && /* @__PURE__ */ jsx("div", { children: step.y }),
|
|
1860
|
+
/* @__PURE__ */ jsx("div", { children: step.x })
|
|
1861
|
+
] })
|
|
1862
|
+
});
|
|
1863
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1864
|
+
/* @__PURE__ */ jsx(
|
|
1865
|
+
Box,
|
|
1866
|
+
{
|
|
1867
|
+
as: "rect",
|
|
1868
|
+
sx: useMemo(() => {
|
|
1869
|
+
return {
|
|
1870
|
+
width: `${width}px`,
|
|
1871
|
+
height: `${height}px`,
|
|
1872
|
+
x: `${x}px`,
|
|
1873
|
+
y: `${y}px`,
|
|
1874
|
+
fill: `${fill}`,
|
|
1875
|
+
"&:hover": {
|
|
1876
|
+
fill: `#${tinycolor(fill).saturate(25).toHex()}`
|
|
1877
|
+
},
|
|
1878
|
+
transition: "fill 500ms"
|
|
1879
|
+
};
|
|
1880
|
+
}, [fill, height, width, x, y]),
|
|
1881
|
+
onMouseEnter: (ev) => {
|
|
1882
|
+
open({
|
|
1883
|
+
attachToElement: () => ev.target,
|
|
1884
|
+
attachToElementAnchorPoint: "center"
|
|
1885
|
+
});
|
|
1886
|
+
},
|
|
1887
|
+
onMouseLeave: () => {
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
),
|
|
1891
|
+
!isLast && /* @__PURE__ */ jsx(
|
|
1892
|
+
Line,
|
|
1893
|
+
{
|
|
1894
|
+
x1,
|
|
1895
|
+
x2,
|
|
1896
|
+
y1: lineY,
|
|
1897
|
+
y2: lineY,
|
|
1898
|
+
stroke,
|
|
1899
|
+
strokeDasharray: strokeDashArray
|
|
1900
|
+
}
|
|
1901
|
+
),
|
|
1902
|
+
/* @__PURE__ */ jsx("text", { textAnchor: "middle", x: textX, y: textY, children: textContent })
|
|
1903
|
+
] });
|
|
1904
|
+
};
|
|
1905
|
+
|
|
1906
|
+
var __defProp$2 = Object.defineProperty;
|
|
1907
|
+
var __defProps$2 = Object.defineProperties;
|
|
1908
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
1909
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
1910
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
1911
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
1912
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1913
|
+
var __spreadValues$2 = (a, b) => {
|
|
1914
|
+
for (var prop in b || (b = {}))
|
|
1915
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
1916
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
1917
|
+
if (__getOwnPropSymbols$2)
|
|
1918
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
1919
|
+
if (__propIsEnum$2.call(b, prop))
|
|
1920
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
1921
|
+
}
|
|
1922
|
+
return a;
|
|
1923
|
+
};
|
|
1924
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
1925
|
+
var __objRest = (source, exclude) => {
|
|
1926
|
+
var target = {};
|
|
1927
|
+
for (var prop in source)
|
|
1928
|
+
if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1929
|
+
target[prop] = source[prop];
|
|
1930
|
+
if (source != null && __getOwnPropSymbols$2)
|
|
1931
|
+
for (var prop of __getOwnPropSymbols$2(source)) {
|
|
1932
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
|
|
1933
|
+
target[prop] = source[prop];
|
|
1934
|
+
}
|
|
1935
|
+
return target;
|
|
1936
|
+
};
|
|
1937
|
+
const calculateWaterfallSteps = ({
|
|
1938
|
+
data,
|
|
1939
|
+
xAccessor,
|
|
1940
|
+
yAccessor,
|
|
1941
|
+
showFinal,
|
|
1942
|
+
colors
|
|
1943
|
+
}) => {
|
|
1944
|
+
let cumulativeTotal = 0;
|
|
1945
|
+
const steps = data.map((datum) => {
|
|
1946
|
+
const xValue = xAccessor(datum);
|
|
1947
|
+
const yValue = yAccessor(datum);
|
|
1948
|
+
const prevTotal = cumulativeTotal;
|
|
1949
|
+
cumulativeTotal += Number(yValue);
|
|
1950
|
+
return {
|
|
1951
|
+
x: xValue,
|
|
1952
|
+
y: yValue,
|
|
1953
|
+
start: prevTotal,
|
|
1954
|
+
end: cumulativeTotal,
|
|
1955
|
+
color: Number(yValue) > 0 ? colors.positive : colors.negative
|
|
1956
|
+
};
|
|
1957
|
+
});
|
|
1958
|
+
if (showFinal) {
|
|
1959
|
+
steps.push({
|
|
1960
|
+
x: "Total",
|
|
1961
|
+
y: cumulativeTotal,
|
|
1962
|
+
start: 0,
|
|
1963
|
+
end: cumulativeTotal,
|
|
1964
|
+
color: colors.total
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
return steps;
|
|
1968
|
+
};
|
|
1969
|
+
function adjustDimensions({
|
|
1970
|
+
width,
|
|
1971
|
+
height,
|
|
1972
|
+
maxWidth
|
|
1973
|
+
}) {
|
|
1974
|
+
if (width <= maxWidth) {
|
|
1975
|
+
return { width, height };
|
|
1976
|
+
}
|
|
1977
|
+
const ratio = width / height;
|
|
1978
|
+
const newWidth = maxWidth;
|
|
1979
|
+
const newHeight = Math.floor(newWidth / ratio);
|
|
1980
|
+
return { width: newWidth, height: newHeight };
|
|
1981
|
+
}
|
|
1982
|
+
const WaterfallBars = (_a) => {
|
|
1983
|
+
var _b = _a, {
|
|
1984
|
+
margin = { top: 20, left: 100, bottom: 150, right: 70 },
|
|
1985
|
+
chart: _c
|
|
1986
|
+
} = _b, _d = _c, {
|
|
1987
|
+
waterfallColors = {
|
|
1988
|
+
positive: "#49b86f",
|
|
1989
|
+
negative: "#c92e5b",
|
|
1990
|
+
total: "#434857",
|
|
1991
|
+
stepConnector: "#888d94"
|
|
1992
|
+
}
|
|
1993
|
+
} = _d, chart = __objRest(_d, [
|
|
1994
|
+
"waterfallColors"
|
|
1995
|
+
]), {
|
|
1996
|
+
className,
|
|
1997
|
+
chartId,
|
|
1998
|
+
allowZoom
|
|
1999
|
+
} = _b;
|
|
2000
|
+
var _a2;
|
|
2001
|
+
const effectiveMargin = parseMargin(margin);
|
|
2002
|
+
if (!chart.showAxisYTitle) {
|
|
2003
|
+
effectiveMargin.left = 50;
|
|
2004
|
+
}
|
|
2005
|
+
let innerWidth = chart.ratio.width + (-effectiveMargin.left - effectiveMargin.right) / 2;
|
|
2006
|
+
let innerHeight = chart.ratio.height + (-effectiveMargin.top - effectiveMargin.bottom) / 2;
|
|
2007
|
+
if (innerWidth > chart.ratio.maxWidth) {
|
|
2008
|
+
const newValues = adjustDimensions({
|
|
2009
|
+
height: innerHeight,
|
|
2010
|
+
width: innerWidth,
|
|
2011
|
+
maxWidth: chart.ratio.maxWidth
|
|
2012
|
+
});
|
|
2013
|
+
innerWidth = newValues.width;
|
|
2014
|
+
innerHeight = newValues.height;
|
|
2015
|
+
}
|
|
2016
|
+
const getXValue = (d) => d.key;
|
|
2017
|
+
const getYValue = (d) => d.value;
|
|
2018
|
+
const charts = arrayOrArray((_a2 = chart.dataSets) == null ? void 0 : _a2.data).filter((piece) => !!piece.sets).map((piece) => {
|
|
2019
|
+
return __spreadProps$2(__spreadValues$2({}, piece), {
|
|
2020
|
+
coordinate: piece.sets
|
|
2021
|
+
});
|
|
2022
|
+
});
|
|
2023
|
+
const [currentPie, setCurrentPie] = useState("0");
|
|
2024
|
+
const chartNames = charts.map((piece) => {
|
|
2025
|
+
return piece.name;
|
|
2026
|
+
});
|
|
2027
|
+
const steps = useMemo(
|
|
2028
|
+
() => {
|
|
2029
|
+
var _a3;
|
|
2030
|
+
return calculateWaterfallSteps({
|
|
2031
|
+
data: arrayOrArray(chart.dataSets.data)[currentPie].sets,
|
|
2032
|
+
xAccessor: getXValue,
|
|
2033
|
+
yAccessor: getYValue,
|
|
2034
|
+
showFinal: (_a3 = chart.showTotal) != null ? _a3 : true,
|
|
2035
|
+
colors: waterfallColors
|
|
2036
|
+
});
|
|
2037
|
+
},
|
|
2038
|
+
[chart.dataSets.data, chart.showTotal, currentPie, waterfallColors]
|
|
2039
|
+
);
|
|
2040
|
+
const padding = 0.2;
|
|
2041
|
+
const xScale = scaleBand({
|
|
2042
|
+
domain: steps.map((step) => step.x),
|
|
2043
|
+
padding,
|
|
2044
|
+
range: [0, innerWidth]
|
|
2045
|
+
});
|
|
2046
|
+
const yDomain = useMemo(() => {
|
|
2047
|
+
const values = steps.flatMap((step) => [step.start, step.end]);
|
|
2048
|
+
const [min, max] = extent(values);
|
|
2049
|
+
return min != null && max != null ? [min - 5, max + 5] : void 0;
|
|
2050
|
+
}, [steps]);
|
|
2051
|
+
const yScale = scaleLinear({
|
|
2052
|
+
domain: yDomain,
|
|
2053
|
+
nice: true,
|
|
2054
|
+
range: [innerHeight, 0]
|
|
2055
|
+
});
|
|
2056
|
+
const id = useMemo(() => `VerticalBars${uniqueId()}`, []);
|
|
2057
|
+
useLayoutEffect(() => {
|
|
2058
|
+
document.querySelectorAll(`#${id} .tickLabel`).forEach((current) => {
|
|
2059
|
+
const width = current.getBoundingClientRect().width;
|
|
2060
|
+
current.style.transformOrigin = current.getAttribute("x") + "px 14px";
|
|
2061
|
+
current.style.transform = `rotate(25deg) translateX(${width / 2}px)`;
|
|
2062
|
+
});
|
|
2063
|
+
});
|
|
2064
|
+
const { boxRef, elementRef } = usePanAndZoom(
|
|
2065
|
+
void 0,
|
|
2066
|
+
!allowZoom
|
|
2067
|
+
);
|
|
2068
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2069
|
+
charts.length > 1 && /* @__PURE__ */ jsx(Box, { className: "chart__combo__wrapper", children: /* @__PURE__ */ jsx(
|
|
2070
|
+
ChartSelector,
|
|
2071
|
+
{
|
|
2072
|
+
chartId,
|
|
2073
|
+
pieces: chartNames,
|
|
2074
|
+
className: "chartSelectorCombo",
|
|
2075
|
+
current: currentPie,
|
|
2076
|
+
setCurrent: setCurrentPie
|
|
2077
|
+
}
|
|
2078
|
+
) }),
|
|
2079
|
+
/* @__PURE__ */ jsx(Box, { id, className, ref: boxRef, children: /* @__PURE__ */ jsx(
|
|
2080
|
+
"svg",
|
|
2081
|
+
{
|
|
2082
|
+
height: chart.ratio.height,
|
|
2083
|
+
width: chart.ratio.width,
|
|
2084
|
+
ref: elementRef,
|
|
2085
|
+
children: /* @__PURE__ */ jsxs(Group, { left: effectiveMargin.left, top: effectiveMargin.top, children: [
|
|
2086
|
+
/* @__PURE__ */ jsx(GridRows, { scale: yScale, width: innerWidth, strokeDasharray: "5" }),
|
|
2087
|
+
steps.map((step, index) => {
|
|
2088
|
+
var _a3;
|
|
2089
|
+
const x = xScale(step.x);
|
|
2090
|
+
const y = yScale(Math.max(step.start, step.end));
|
|
2091
|
+
if (x == null || y == null) {
|
|
2092
|
+
return null;
|
|
2093
|
+
}
|
|
2094
|
+
const barHeight = Math.abs(yScale(step.start) - yScale(step.end));
|
|
2095
|
+
const isLast = index === steps.length - 1;
|
|
2096
|
+
const linePadding = 2;
|
|
2097
|
+
const x1 = x + xScale.bandwidth() + linePadding;
|
|
2098
|
+
const x2 = x + xScale.bandwidth() / (1 - padding) - linePadding;
|
|
2099
|
+
const lineY = step.end < step.start ? y + barHeight : y;
|
|
2100
|
+
const labelOffset = 10;
|
|
2101
|
+
const labelY = yScale(step.end) + (step.y < 0 ? labelOffset : -labelOffset);
|
|
2102
|
+
let currentYValue = 0;
|
|
2103
|
+
steps.filter((_, i) => {
|
|
2104
|
+
var _a4;
|
|
2105
|
+
if (((_a4 = chart.showTotal) != null ? _a4 : true) && !steps[i + 1]) {
|
|
2106
|
+
return false;
|
|
2107
|
+
}
|
|
2108
|
+
return i <= index;
|
|
2109
|
+
}).forEach((step2) => {
|
|
2110
|
+
currentYValue += Number(step2.y);
|
|
2111
|
+
});
|
|
2112
|
+
return /* @__PURE__ */ jsx(
|
|
2113
|
+
WaterfallBar,
|
|
2114
|
+
{
|
|
2115
|
+
chart,
|
|
2116
|
+
columnName: chartNames[currentPie],
|
|
2117
|
+
fill: step.color,
|
|
2118
|
+
height: barHeight,
|
|
2119
|
+
isLast,
|
|
2120
|
+
lineY,
|
|
2121
|
+
step,
|
|
2122
|
+
stroke: waterfallColors.stepConnector,
|
|
2123
|
+
strokeDashArray: 2,
|
|
2124
|
+
textContent: ((_a3 = chart.showTotal) != null ? _a3 : true) ? step.y : currentYValue,
|
|
2125
|
+
textX: x + xScale.bandwidth() / 2,
|
|
2126
|
+
textY: labelY + 5,
|
|
2127
|
+
width: xScale.bandwidth(),
|
|
2128
|
+
x,
|
|
2129
|
+
y,
|
|
2130
|
+
x1,
|
|
2131
|
+
x2
|
|
2132
|
+
},
|
|
2133
|
+
index
|
|
2134
|
+
);
|
|
2135
|
+
}),
|
|
2136
|
+
/* @__PURE__ */ jsx(
|
|
2137
|
+
AxisLeft,
|
|
2138
|
+
{
|
|
2139
|
+
label: "",
|
|
2140
|
+
scale: yScale,
|
|
2141
|
+
hideAxisLine: true,
|
|
2142
|
+
hideTicks: true,
|
|
2143
|
+
tickLabelProps: () => ({
|
|
2144
|
+
textAnchor: "end",
|
|
2145
|
+
verticalAnchor: "middle"
|
|
2146
|
+
})
|
|
2147
|
+
}
|
|
2148
|
+
),
|
|
2149
|
+
/* @__PURE__ */ jsx(
|
|
2150
|
+
AxisBottom,
|
|
2151
|
+
{
|
|
2152
|
+
scale: xScale,
|
|
2153
|
+
top: innerHeight,
|
|
2154
|
+
tickLabelProps: () => ({
|
|
2155
|
+
textAnchor: "middle",
|
|
2156
|
+
verticalAnchor: "middle",
|
|
2157
|
+
className: "tickLabel"
|
|
2158
|
+
})
|
|
2159
|
+
}
|
|
2160
|
+
)
|
|
2161
|
+
] })
|
|
2162
|
+
}
|
|
2163
|
+
) }),
|
|
2164
|
+
/* @__PURE__ */ jsx(
|
|
2165
|
+
LegendContainer,
|
|
2166
|
+
{
|
|
2167
|
+
id: chartId,
|
|
2168
|
+
avoidEvent: true,
|
|
2169
|
+
references: [
|
|
2170
|
+
{
|
|
2171
|
+
title: arrayOrArray(chart.dataSets.data)[currentPie].name,
|
|
2172
|
+
color: "transparent"
|
|
2173
|
+
}
|
|
2174
|
+
]
|
|
2175
|
+
}
|
|
2176
|
+
)
|
|
2177
|
+
] });
|
|
2178
|
+
};
|
|
2179
|
+
|
|
2180
|
+
var __defProp$1 = Object.defineProperty;
|
|
2181
|
+
var __defProps$1 = Object.defineProperties;
|
|
2182
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
2183
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
2184
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
2185
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
2186
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2187
|
+
var __spreadValues$1 = (a, b) => {
|
|
2188
|
+
for (var prop in b || (b = {}))
|
|
2189
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
2190
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
2191
|
+
if (__getOwnPropSymbols$1)
|
|
2192
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
2193
|
+
if (__propIsEnum$1.call(b, prop))
|
|
2194
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
2195
|
+
}
|
|
2196
|
+
return a;
|
|
2197
|
+
};
|
|
2198
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
2199
|
+
const frontColor = "hsl(196, 37%, 13%)";
|
|
2200
|
+
function useMultipleRefs(...refs) {
|
|
2201
|
+
return React.useCallback(
|
|
2202
|
+
function setRef(element) {
|
|
2203
|
+
refs.forEach((current) => {
|
|
2204
|
+
if (current)
|
|
2205
|
+
current.current = element;
|
|
2206
|
+
});
|
|
2207
|
+
},
|
|
2208
|
+
[refs]
|
|
2209
|
+
);
|
|
2210
|
+
}
|
|
2211
|
+
const [, chartMethods, ChartRenderer] = makeImperativeComponent()({
|
|
2212
|
+
Component: makeStyledComponent(
|
|
2213
|
+
"ChartRenderer",
|
|
2214
|
+
"layout.charts",
|
|
2215
|
+
{
|
|
2216
|
+
red: {
|
|
2217
|
+
schema: "schemas.red"
|
|
2218
|
+
},
|
|
2219
|
+
orange: {
|
|
2220
|
+
schema: "schemas.orange"
|
|
2221
|
+
},
|
|
2222
|
+
green: {
|
|
2223
|
+
schema: "schemas.green"
|
|
2224
|
+
},
|
|
2225
|
+
blue: {
|
|
2226
|
+
schema: "schemas.blue"
|
|
2227
|
+
},
|
|
2228
|
+
violet: {
|
|
2229
|
+
schema: "schemas.violet"
|
|
2230
|
+
},
|
|
2231
|
+
turquoise: {
|
|
2232
|
+
schema: "schemas.turquoise"
|
|
2233
|
+
},
|
|
2234
|
+
yellow: {
|
|
2235
|
+
schema: "schemas.yellow"
|
|
2236
|
+
},
|
|
2237
|
+
grey: {
|
|
2238
|
+
schema: "schemas.grey"
|
|
2239
|
+
},
|
|
2240
|
+
ocean: {
|
|
2241
|
+
schema: "schemas.ocean"
|
|
2242
|
+
},
|
|
2243
|
+
sunset: {
|
|
2244
|
+
schema: "schemas.sunset"
|
|
2245
|
+
},
|
|
2246
|
+
common: {
|
|
2247
|
+
axis: {
|
|
2248
|
+
stroke: frontColor,
|
|
2249
|
+
title: frontColor
|
|
2250
|
+
},
|
|
2251
|
+
schema: frontColor,
|
|
2252
|
+
background: "hsl(200deg 20% 98%)",
|
|
2253
|
+
grid: {
|
|
2254
|
+
stroke: frontColor,
|
|
2255
|
+
opacity: "0.1"
|
|
2256
|
+
},
|
|
2257
|
+
toolTip: {
|
|
2258
|
+
backgroundColor: "rgb(232, 241, 255)",
|
|
2259
|
+
border: "1px solid #07c",
|
|
2260
|
+
color: frontColor,
|
|
2261
|
+
padding: ".3rem .5rem",
|
|
2262
|
+
borderRadius: "3px",
|
|
2263
|
+
fontSize: "18px",
|
|
2264
|
+
boxShadow: "0 1px 2px rgba(33,33,33,0.2)",
|
|
2265
|
+
lineHeight: "1em"
|
|
2266
|
+
}
|
|
2267
|
+
},
|
|
2268
|
+
".legendContainer": {
|
|
2269
|
+
display: "flex",
|
|
2270
|
+
flexDirection: "row",
|
|
2271
|
+
gap: spacing(3),
|
|
2272
|
+
flexWrap: "wrap"
|
|
2273
|
+
},
|
|
2274
|
+
".chart__combo__wrapper": {
|
|
2275
|
+
position: "absolute"
|
|
2276
|
+
}
|
|
2277
|
+
},
|
|
2278
|
+
// eslint-disable-next-line react/display-name
|
|
2279
|
+
React.forwardRef(
|
|
2280
|
+
({
|
|
2281
|
+
currentChart,
|
|
2282
|
+
chartId,
|
|
2283
|
+
allowZoom
|
|
2284
|
+
}, ref) => {
|
|
2285
|
+
const innerRef = React.useRef(null);
|
|
2286
|
+
const setRefs = useMultipleRefs(
|
|
2287
|
+
ref,
|
|
2288
|
+
innerRef
|
|
2289
|
+
);
|
|
2290
|
+
const contextValue = useMemo(() => ({ chartId }), [chartId]);
|
|
2291
|
+
const CurrentChart = getIndex(
|
|
2292
|
+
[PieChart, HorizontalBars, VerticalBars, LineChart, WaterfallBars],
|
|
2293
|
+
[
|
|
2294
|
+
currentChart.chartType === "pie2D",
|
|
2295
|
+
currentChart.chartType === "barH2D",
|
|
2296
|
+
currentChart.chartType === "barV2D",
|
|
2297
|
+
currentChart.chartType === "linear",
|
|
2298
|
+
currentChart.chartType === "waterfall"
|
|
2299
|
+
],
|
|
2300
|
+
0
|
|
2301
|
+
);
|
|
2302
|
+
return /* @__PURE__ */ jsx(ChartContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
2303
|
+
Box,
|
|
2304
|
+
__spreadProps$1(__spreadValues$1({
|
|
2305
|
+
ref: setRefs,
|
|
2306
|
+
className: "chart__chartRenderer"
|
|
2307
|
+
}, getVariant("layout.charts")), {
|
|
2308
|
+
children: /* @__PURE__ */ jsx(
|
|
2309
|
+
CurrentChart,
|
|
2310
|
+
{
|
|
2311
|
+
chart: currentChart,
|
|
2312
|
+
chartId,
|
|
2313
|
+
parentRef: innerRef,
|
|
2314
|
+
allowZoom
|
|
2315
|
+
}
|
|
2316
|
+
)
|
|
2317
|
+
})
|
|
2318
|
+
) });
|
|
2319
|
+
}
|
|
2320
|
+
),
|
|
2321
|
+
true
|
|
2322
|
+
)
|
|
2323
|
+
});
|
|
2324
|
+
|
|
2325
|
+
var __defProp = Object.defineProperty;
|
|
2326
|
+
var __defProps = Object.defineProperties;
|
|
2327
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2328
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
2329
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2330
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
2331
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2332
|
+
var __spreadValues = (a, b) => {
|
|
2333
|
+
for (var prop in b || (b = {}))
|
|
2334
|
+
if (__hasOwnProp.call(b, prop))
|
|
2335
|
+
__defNormalProp(a, prop, b[prop]);
|
|
2336
|
+
if (__getOwnPropSymbols)
|
|
2337
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
2338
|
+
if (__propIsEnum.call(b, prop))
|
|
2339
|
+
__defNormalProp(a, prop, b[prop]);
|
|
2340
|
+
}
|
|
2341
|
+
return a;
|
|
2342
|
+
};
|
|
2343
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
2344
|
+
const START_ANGLE = 0;
|
|
2345
|
+
const END_ANGLE = 360;
|
|
2346
|
+
const TLight = ({
|
|
2347
|
+
addBorder = false,
|
|
2348
|
+
colorRanges,
|
|
2349
|
+
maxValue,
|
|
2350
|
+
minValue,
|
|
2351
|
+
currentValue,
|
|
2352
|
+
height,
|
|
2353
|
+
valueRanges,
|
|
2354
|
+
width,
|
|
2355
|
+
currentValueColor,
|
|
2356
|
+
currentValueFontSize
|
|
2357
|
+
}) => {
|
|
2358
|
+
const value = currentValue;
|
|
2359
|
+
const diameter = Math.min(height, width);
|
|
2360
|
+
const domainMax = maxValue != null ? maxValue : valueRanges[valueRanges.length - 1];
|
|
2361
|
+
const domainMin = minValue != null ? minValue : valueRanges[0];
|
|
2362
|
+
const gauge = useGauge({
|
|
2363
|
+
domain: [domainMin, domainMax],
|
|
2364
|
+
startAngle: START_ANGLE,
|
|
2365
|
+
endAngle: END_ANGLE,
|
|
2366
|
+
numTicks: 0,
|
|
2367
|
+
diameter
|
|
2368
|
+
});
|
|
2369
|
+
function getColor(value2) {
|
|
2370
|
+
var _a;
|
|
2371
|
+
const index = valueRanges.findIndex((range) => value2 < range);
|
|
2372
|
+
if (index === -1) {
|
|
2373
|
+
return colorRanges[0];
|
|
2374
|
+
}
|
|
2375
|
+
return (_a = colorRanges[index - 1]) != null ? _a : colorRanges[index];
|
|
2376
|
+
}
|
|
2377
|
+
return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs("svg", __spreadProps(__spreadValues({}, gauge.getSVGProps()), { viewBox: "-325 -325 600 600", children: [
|
|
2378
|
+
/* @__PURE__ */ jsx("g", { id: "arcs", children: /* @__PURE__ */ jsx(
|
|
2379
|
+
"path",
|
|
2380
|
+
__spreadProps(__spreadValues({}, gauge.getArcProps({
|
|
2381
|
+
offset: 20,
|
|
2382
|
+
startAngle: START_ANGLE,
|
|
2383
|
+
endAngle: END_ANGLE
|
|
2384
|
+
})), {
|
|
2385
|
+
stroke: addBorder ? "black" : "transparent",
|
|
2386
|
+
fill: getColor(value),
|
|
2387
|
+
strokeLinecap: "round",
|
|
2388
|
+
strokeWidth: 5
|
|
2389
|
+
})
|
|
2390
|
+
) }),
|
|
2391
|
+
/* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
|
|
2392
|
+
"text",
|
|
2393
|
+
{
|
|
2394
|
+
textAnchor: "middle",
|
|
2395
|
+
style: { fontSize: `${currentValueFontSize != null ? currentValueFontSize : 100}px` },
|
|
2396
|
+
alignmentBaseline: "central",
|
|
2397
|
+
fill: currentValueColor,
|
|
2398
|
+
children: value
|
|
2399
|
+
}
|
|
2400
|
+
) })
|
|
2401
|
+
] })) });
|
|
2402
|
+
};
|
|
2403
|
+
|
|
2404
|
+
const WidgetContainer = () => {
|
|
2405
|
+
const mockData = {
|
|
2406
|
+
addBorder: true,
|
|
2407
|
+
backgColor: "white",
|
|
2408
|
+
currentValue: 1010,
|
|
2409
|
+
height: 400,
|
|
2410
|
+
width: 400,
|
|
2411
|
+
maxValue: 1050,
|
|
2412
|
+
minValue: 1e3,
|
|
2413
|
+
noValueColor: "",
|
|
2414
|
+
pointerColor: "blue",
|
|
2415
|
+
ringAnchor: 5,
|
|
2416
|
+
scaleFontSize: 20,
|
|
2417
|
+
valueColor: "darkblue",
|
|
2418
|
+
valueDecimals: 1,
|
|
2419
|
+
valueFontSize: 50,
|
|
2420
|
+
valueType: "",
|
|
2421
|
+
widKpiType: 0,
|
|
2422
|
+
zones: [
|
|
2423
|
+
{
|
|
2424
|
+
color: "blue",
|
|
2425
|
+
maximum: 1020,
|
|
2426
|
+
minimum: 1e3,
|
|
2427
|
+
transparency: 20
|
|
2428
|
+
},
|
|
2429
|
+
{
|
|
2430
|
+
color: "purple",
|
|
2431
|
+
maximum: 1040,
|
|
2432
|
+
minimum: 1020,
|
|
2433
|
+
transparency: 50
|
|
2434
|
+
},
|
|
2435
|
+
{
|
|
2436
|
+
color: "red",
|
|
2437
|
+
maximum: 1050,
|
|
2438
|
+
minimum: 1040,
|
|
2439
|
+
transparency: 0
|
|
2440
|
+
}
|
|
2441
|
+
]
|
|
2442
|
+
};
|
|
2443
|
+
const valueRanges = Array.from(
|
|
2444
|
+
new Set(
|
|
2445
|
+
arrayOrArray(mockData.zones).map((zone) => {
|
|
2446
|
+
return [zone.minimum, zone.maximum];
|
|
2447
|
+
}).flat().sort((a, b) => a - b)
|
|
2448
|
+
)
|
|
2449
|
+
);
|
|
2450
|
+
const colorRanges = arrayOrArray(mockData.zones).map((zone) => {
|
|
2451
|
+
return tinycolor(zone.color).setAlpha(1 - zone.transparency / 100).toPercentageRgbString();
|
|
2452
|
+
}).flat();
|
|
2453
|
+
return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
2454
|
+
TLight,
|
|
2455
|
+
{
|
|
2456
|
+
addBorder: mockData.addBorder,
|
|
2457
|
+
backgroundColor: mockData.backgColor,
|
|
2458
|
+
colorRanges,
|
|
2459
|
+
currentValue: mockData.currentValue,
|
|
2460
|
+
decimals: mockData.valueDecimals,
|
|
2461
|
+
currentValueColor: mockData.valueColor,
|
|
2462
|
+
currentValueFontSize: mockData.valueFontSize,
|
|
2463
|
+
height: mockData.height,
|
|
2464
|
+
maxValue: mockData.maxValue,
|
|
2465
|
+
minValue: mockData.minValue,
|
|
2466
|
+
pointerColor: mockData.pointerColor,
|
|
2467
|
+
scaleValuesSize: mockData.scaleFontSize,
|
|
2468
|
+
valueRanges,
|
|
2469
|
+
width: mockData.width
|
|
2470
|
+
}
|
|
2471
|
+
) });
|
|
2472
|
+
};
|
|
2473
|
+
|
|
2474
|
+
export { ChartRenderer, WidgetContainer };
|
|
2475
|
+
//# sourceMappingURL=index.js.map
|