@marcoschwartz/lite-ui 0.11.0 → 0.15.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/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +623 -412
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +623 -412
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3182,6 +3182,7 @@ var RichTextEditor = ({
|
|
|
3182
3182
|
const [showImageModal, setShowImageModal] = useState12(false);
|
|
3183
3183
|
const [imageUrl, setImageUrl] = useState12("");
|
|
3184
3184
|
const [imageAlt, setImageAlt] = useState12("");
|
|
3185
|
+
const savedSelection = useRef7(null);
|
|
3185
3186
|
useLayoutEffect(() => {
|
|
3186
3187
|
const styleId = "rich-text-editor-styles";
|
|
3187
3188
|
if (!document.getElementById(styleId)) {
|
|
@@ -3208,6 +3209,15 @@ var RichTextEditor = ({
|
|
|
3208
3209
|
font-weight: bold;
|
|
3209
3210
|
margin: 0.83em 0;
|
|
3210
3211
|
}
|
|
3212
|
+
[contenteditable] p {
|
|
3213
|
+
margin: 0.5em 0;
|
|
3214
|
+
}
|
|
3215
|
+
[contenteditable] p:first-child {
|
|
3216
|
+
margin-top: 0;
|
|
3217
|
+
}
|
|
3218
|
+
[contenteditable] p:last-child {
|
|
3219
|
+
margin-bottom: 0;
|
|
3220
|
+
}
|
|
3211
3221
|
[contenteditable] ul, [contenteditable] ol {
|
|
3212
3222
|
margin: 1em 0;
|
|
3213
3223
|
padding-left: 2em;
|
|
@@ -3236,11 +3246,60 @@ var RichTextEditor = ({
|
|
|
3236
3246
|
}
|
|
3237
3247
|
}, []);
|
|
3238
3248
|
const isInitialRender = useRef7(true);
|
|
3249
|
+
const isInternalUpdate = useRef7(false);
|
|
3239
3250
|
useEffect8(() => {
|
|
3240
|
-
if (
|
|
3251
|
+
if (isInitialRender.current && editorRef.current) {
|
|
3241
3252
|
editorRef.current.innerHTML = value;
|
|
3253
|
+
isInitialRender.current = false;
|
|
3254
|
+
try {
|
|
3255
|
+
document.execCommand("defaultParagraphSeparator", false, "p");
|
|
3256
|
+
} catch (e) {
|
|
3257
|
+
console.warn("Could not set defaultParagraphSeparator", e);
|
|
3258
|
+
}
|
|
3242
3259
|
}
|
|
3243
|
-
|
|
3260
|
+
}, []);
|
|
3261
|
+
useEffect8(() => {
|
|
3262
|
+
if (!isInitialRender.current && !isInternalUpdate.current && editorRef.current) {
|
|
3263
|
+
const currentHtml = editorRef.current.innerHTML;
|
|
3264
|
+
if (currentHtml !== value) {
|
|
3265
|
+
const selection = window.getSelection();
|
|
3266
|
+
const range = selection && selection.rangeCount > 0 ? selection.getRangeAt(0) : null;
|
|
3267
|
+
const preSelectionRange = range ? range.cloneRange() : null;
|
|
3268
|
+
if (preSelectionRange && editorRef.current.contains(preSelectionRange.startContainer)) {
|
|
3269
|
+
preSelectionRange.selectNodeContents(editorRef.current);
|
|
3270
|
+
preSelectionRange.setEnd(range.startContainer, range.startOffset);
|
|
3271
|
+
const start = preSelectionRange.toString().length;
|
|
3272
|
+
editorRef.current.innerHTML = value;
|
|
3273
|
+
const textNodes = [];
|
|
3274
|
+
const getTextNodes = (node) => {
|
|
3275
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
3276
|
+
textNodes.push(node);
|
|
3277
|
+
} else {
|
|
3278
|
+
node.childNodes.forEach(getTextNodes);
|
|
3279
|
+
}
|
|
3280
|
+
};
|
|
3281
|
+
getTextNodes(editorRef.current);
|
|
3282
|
+
let charCount = 0;
|
|
3283
|
+
let foundStart = false;
|
|
3284
|
+
for (const textNode of textNodes) {
|
|
3285
|
+
const textLength = textNode.textContent?.length || 0;
|
|
3286
|
+
if (!foundStart && charCount + textLength >= start) {
|
|
3287
|
+
const newRange = document.createRange();
|
|
3288
|
+
newRange.setStart(textNode, start - charCount);
|
|
3289
|
+
newRange.collapse(true);
|
|
3290
|
+
selection?.removeAllRanges();
|
|
3291
|
+
selection?.addRange(newRange);
|
|
3292
|
+
foundStart = true;
|
|
3293
|
+
break;
|
|
3294
|
+
}
|
|
3295
|
+
charCount += textLength;
|
|
3296
|
+
}
|
|
3297
|
+
} else {
|
|
3298
|
+
editorRef.current.innerHTML = value;
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
isInternalUpdate.current = false;
|
|
3244
3303
|
}, [value]);
|
|
3245
3304
|
const updateActiveFormats = useCallback(() => {
|
|
3246
3305
|
const formats = /* @__PURE__ */ new Set();
|
|
@@ -3261,10 +3320,25 @@ var RichTextEditor = ({
|
|
|
3261
3320
|
}, []);
|
|
3262
3321
|
const handleInput = useCallback(() => {
|
|
3263
3322
|
if (editorRef.current && onChange) {
|
|
3323
|
+
isInternalUpdate.current = true;
|
|
3264
3324
|
onChange(editorRef.current.innerHTML);
|
|
3265
3325
|
}
|
|
3266
3326
|
updateActiveFormats();
|
|
3267
3327
|
}, [onChange, updateActiveFormats]);
|
|
3328
|
+
const handleFocus = useCallback(() => {
|
|
3329
|
+
setIsFocused(true);
|
|
3330
|
+
if (editorRef.current && (!editorRef.current.innerHTML || editorRef.current.innerHTML === "")) {
|
|
3331
|
+
editorRef.current.innerHTML = "<p><br></p>";
|
|
3332
|
+
const selection = window.getSelection();
|
|
3333
|
+
const range = document.createRange();
|
|
3334
|
+
if (editorRef.current.firstChild) {
|
|
3335
|
+
range.setStart(editorRef.current.firstChild, 0);
|
|
3336
|
+
range.collapse(true);
|
|
3337
|
+
selection?.removeAllRanges();
|
|
3338
|
+
selection?.addRange(range);
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
}, []);
|
|
3268
3342
|
const handleFormat = useCallback((command) => {
|
|
3269
3343
|
if (disabled) return;
|
|
3270
3344
|
document.execCommand(command, false);
|
|
@@ -3288,16 +3362,29 @@ var RichTextEditor = ({
|
|
|
3288
3362
|
}, [disabled, updateActiveFormats, handleInput]);
|
|
3289
3363
|
const handleLink = useCallback(() => {
|
|
3290
3364
|
if (disabled) return;
|
|
3365
|
+
const selection = window.getSelection();
|
|
3366
|
+
if (selection && selection.rangeCount > 0) {
|
|
3367
|
+
savedSelection.current = selection.getRangeAt(0).cloneRange();
|
|
3368
|
+
}
|
|
3291
3369
|
setShowLinkModal(true);
|
|
3292
3370
|
}, [disabled]);
|
|
3293
3371
|
const insertLink = useCallback(() => {
|
|
3294
|
-
if (linkUrl)
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3372
|
+
if (!linkUrl || !editorRef.current) return;
|
|
3373
|
+
const selection = window.getSelection();
|
|
3374
|
+
if (savedSelection.current && selection) {
|
|
3375
|
+
try {
|
|
3376
|
+
selection.removeAllRanges();
|
|
3377
|
+
selection.addRange(savedSelection.current);
|
|
3378
|
+
document.execCommand("createLink", false, linkUrl);
|
|
3379
|
+
savedSelection.current = null;
|
|
3380
|
+
} catch (e) {
|
|
3381
|
+
console.warn("Could not insert link at saved position", e);
|
|
3382
|
+
}
|
|
3300
3383
|
}
|
|
3384
|
+
setShowLinkModal(false);
|
|
3385
|
+
setLinkUrl("");
|
|
3386
|
+
editorRef.current?.focus();
|
|
3387
|
+
handleInput();
|
|
3301
3388
|
}, [linkUrl, handleInput]);
|
|
3302
3389
|
const handleCode = useCallback(() => {
|
|
3303
3390
|
if (disabled) return;
|
|
@@ -3317,33 +3404,82 @@ var RichTextEditor = ({
|
|
|
3317
3404
|
}, [disabled, handleInput]);
|
|
3318
3405
|
const handleImage = useCallback(() => {
|
|
3319
3406
|
if (disabled) return;
|
|
3407
|
+
const selection = window.getSelection();
|
|
3408
|
+
if (selection && selection.rangeCount > 0) {
|
|
3409
|
+
savedSelection.current = selection.getRangeAt(0).cloneRange();
|
|
3410
|
+
}
|
|
3320
3411
|
setShowImageModal(true);
|
|
3321
3412
|
}, [disabled]);
|
|
3322
3413
|
const insertImage = useCallback(() => {
|
|
3323
|
-
if (!imageUrl) return;
|
|
3414
|
+
if (!imageUrl || !editorRef.current) return;
|
|
3415
|
+
editorRef.current.focus();
|
|
3324
3416
|
const img = document.createElement("img");
|
|
3325
3417
|
img.src = imageUrl;
|
|
3326
3418
|
img.alt = imageAlt || "";
|
|
3327
3419
|
img.style.maxWidth = "100%";
|
|
3328
3420
|
img.style.height = "auto";
|
|
3329
3421
|
const selection = window.getSelection();
|
|
3330
|
-
if (
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3422
|
+
if (savedSelection.current && selection && editorRef.current.contains(savedSelection.current.commonAncestorContainer)) {
|
|
3423
|
+
try {
|
|
3424
|
+
selection.removeAllRanges();
|
|
3425
|
+
selection.addRange(savedSelection.current);
|
|
3426
|
+
savedSelection.current.deleteContents();
|
|
3427
|
+
savedSelection.current.insertNode(img);
|
|
3428
|
+
const br = document.createElement("br");
|
|
3429
|
+
savedSelection.current.setStartAfter(img);
|
|
3430
|
+
savedSelection.current.insertNode(br);
|
|
3431
|
+
savedSelection.current.setStartAfter(br);
|
|
3432
|
+
savedSelection.current.collapse(true);
|
|
3433
|
+
selection.removeAllRanges();
|
|
3434
|
+
selection.addRange(savedSelection.current);
|
|
3435
|
+
savedSelection.current = null;
|
|
3436
|
+
} catch (e) {
|
|
3437
|
+
console.warn("Could not insert at saved position", e);
|
|
3438
|
+
if (selection.rangeCount > 0) {
|
|
3439
|
+
const range = selection.getRangeAt(0);
|
|
3440
|
+
if (editorRef.current.contains(range.commonAncestorContainer)) {
|
|
3441
|
+
range.insertNode(img);
|
|
3442
|
+
const br = document.createElement("br");
|
|
3443
|
+
range.setStartAfter(img);
|
|
3444
|
+
range.insertNode(br);
|
|
3445
|
+
range.setStartAfter(br);
|
|
3446
|
+
range.collapse(true);
|
|
3447
|
+
} else {
|
|
3448
|
+
editorRef.current.appendChild(img);
|
|
3449
|
+
editorRef.current.appendChild(document.createElement("br"));
|
|
3450
|
+
}
|
|
3451
|
+
} else {
|
|
3452
|
+
editorRef.current.appendChild(img);
|
|
3453
|
+
editorRef.current.appendChild(document.createElement("br"));
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
} else {
|
|
3457
|
+
if (selection && selection.rangeCount > 0) {
|
|
3458
|
+
const range = selection.getRangeAt(0);
|
|
3459
|
+
if (editorRef.current.contains(range.commonAncestorContainer)) {
|
|
3460
|
+
range.deleteContents();
|
|
3461
|
+
range.insertNode(img);
|
|
3462
|
+
const br = document.createElement("br");
|
|
3463
|
+
range.setStartAfter(img);
|
|
3464
|
+
range.insertNode(br);
|
|
3465
|
+
range.setStartAfter(br);
|
|
3466
|
+
range.collapse(true);
|
|
3467
|
+
selection.removeAllRanges();
|
|
3468
|
+
selection.addRange(range);
|
|
3469
|
+
} else {
|
|
3470
|
+
editorRef.current.appendChild(img);
|
|
3471
|
+
editorRef.current.appendChild(document.createElement("br"));
|
|
3472
|
+
}
|
|
3473
|
+
} else {
|
|
3474
|
+
editorRef.current.appendChild(img);
|
|
3475
|
+
editorRef.current.appendChild(document.createElement("br"));
|
|
3476
|
+
}
|
|
3340
3477
|
}
|
|
3341
3478
|
setShowImageModal(false);
|
|
3342
3479
|
setImageUrl("");
|
|
3343
3480
|
setImageAlt("");
|
|
3344
|
-
editorRef.current?.focus();
|
|
3345
3481
|
handleInput();
|
|
3346
|
-
}, [imageUrl, imageAlt, handleInput
|
|
3482
|
+
}, [imageUrl, imageAlt, handleInput]);
|
|
3347
3483
|
const getButtonClass = (isActive) => {
|
|
3348
3484
|
const baseClass = themeName === "minimalistic" ? "border border-white text-white transition-colors" : "border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 transition-colors";
|
|
3349
3485
|
const activeClass = themeName === "minimalistic" ? "bg-white text-black" : "bg-blue-100 dark:bg-blue-900 border-blue-500 dark:border-blue-400";
|
|
@@ -3507,11 +3643,10 @@ var RichTextEditor = ({
|
|
|
3507
3643
|
ref: editorRef,
|
|
3508
3644
|
contentEditable: !disabled,
|
|
3509
3645
|
onInput: handleInput,
|
|
3510
|
-
onFocus:
|
|
3646
|
+
onFocus: handleFocus,
|
|
3511
3647
|
onBlur: () => setIsFocused(false),
|
|
3512
3648
|
onMouseUp: updateActiveFormats,
|
|
3513
3649
|
onKeyUp: updateActiveFormats,
|
|
3514
|
-
dangerouslySetInnerHTML: { __html: value },
|
|
3515
3650
|
className: `
|
|
3516
3651
|
w-full px-4 py-3 rounded-b-lg outline-none overflow-y-auto
|
|
3517
3652
|
${editorBaseClass} ${focusClass} ${errorClass}
|
|
@@ -5000,8 +5135,10 @@ var defaultColors = [
|
|
|
5000
5135
|
];
|
|
5001
5136
|
var LineChart = ({
|
|
5002
5137
|
data,
|
|
5003
|
-
width
|
|
5004
|
-
height
|
|
5138
|
+
width: providedWidth,
|
|
5139
|
+
height: providedHeight,
|
|
5140
|
+
aspectRatio = 16 / 9,
|
|
5141
|
+
responsive = true,
|
|
5005
5142
|
showGrid = true,
|
|
5006
5143
|
showXAxis = true,
|
|
5007
5144
|
showYAxis = true,
|
|
@@ -5014,6 +5151,8 @@ var LineChart = ({
|
|
|
5014
5151
|
xAxisLabel,
|
|
5015
5152
|
yAxisLabel
|
|
5016
5153
|
}) => {
|
|
5154
|
+
const height = providedHeight ?? 400;
|
|
5155
|
+
const width = providedWidth ?? (responsive ? 600 : 600);
|
|
5017
5156
|
const [hoveredPoint, setHoveredPoint] = React26.useState(null);
|
|
5018
5157
|
const padding = { top: 20, right: 20, bottom: showXAxis ? 60 : 20, left: showYAxis ? 60 : 20 };
|
|
5019
5158
|
const chartWidth = width - padding.left - padding.right;
|
|
@@ -5088,7 +5227,8 @@ var LineChart = ({
|
|
|
5088
5227
|
x: -10,
|
|
5089
5228
|
y: y + 4,
|
|
5090
5229
|
textAnchor: "end",
|
|
5091
|
-
|
|
5230
|
+
fontSize: "16",
|
|
5231
|
+
className: "fill-gray-600 dark:fill-gray-400",
|
|
5092
5232
|
children: yValue.toFixed(1)
|
|
5093
5233
|
}
|
|
5094
5234
|
)
|
|
@@ -5120,7 +5260,8 @@ var LineChart = ({
|
|
|
5120
5260
|
x,
|
|
5121
5261
|
y: chartHeight + 20,
|
|
5122
5262
|
textAnchor: "middle",
|
|
5123
|
-
|
|
5263
|
+
fontSize: "14",
|
|
5264
|
+
className: "fill-gray-600 dark:fill-gray-400",
|
|
5124
5265
|
children: xValue
|
|
5125
5266
|
}
|
|
5126
5267
|
)
|
|
@@ -5128,108 +5269,121 @@ var LineChart = ({
|
|
|
5128
5269
|
);
|
|
5129
5270
|
}
|
|
5130
5271
|
}
|
|
5131
|
-
return /* @__PURE__ */ jsxs35(
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
{
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
},
|
|
5151
|
-
`line-${seriesIndex}`
|
|
5152
|
-
)),
|
|
5153
|
-
showDots && data.map(
|
|
5154
|
-
(series, seriesIndex) => series.data.map((point, pointIndex) => {
|
|
5155
|
-
const x = scaleX(point.x, pointIndex);
|
|
5156
|
-
const y = scaleY(point.y);
|
|
5157
|
-
const isHovered = hoveredPoint?.seriesIndex === seriesIndex && hoveredPoint?.pointIndex === pointIndex;
|
|
5158
|
-
return /* @__PURE__ */ jsx108(
|
|
5159
|
-
"circle",
|
|
5272
|
+
return /* @__PURE__ */ jsxs35(
|
|
5273
|
+
"div",
|
|
5274
|
+
{
|
|
5275
|
+
className: `relative ${responsive ? "w-full" : "inline-block"} ${className}`,
|
|
5276
|
+
style: responsive ? { aspectRatio: `${width} / ${height}` } : void 0,
|
|
5277
|
+
children: [
|
|
5278
|
+
/* @__PURE__ */ jsx108(
|
|
5279
|
+
"svg",
|
|
5280
|
+
{
|
|
5281
|
+
width: "100%",
|
|
5282
|
+
height: "100%",
|
|
5283
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
5284
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
5285
|
+
className: "bg-white dark:bg-gray-800 block",
|
|
5286
|
+
style: { overflow: "visible" },
|
|
5287
|
+
children: /* @__PURE__ */ jsxs35("g", { transform: `translate(${padding.left}, ${padding.top})`, children: [
|
|
5288
|
+
gridLines,
|
|
5289
|
+
data.map((series, seriesIndex) => /* @__PURE__ */ jsx108(
|
|
5290
|
+
"path",
|
|
5160
5291
|
{
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
className: "cursor-pointer transition-all",
|
|
5168
|
-
onMouseEnter: () => showTooltip && setHoveredPoint({ seriesIndex, pointIndex, x, y }),
|
|
5169
|
-
onMouseLeave: () => setHoveredPoint(null)
|
|
5292
|
+
d: generatePath(series),
|
|
5293
|
+
fill: "none",
|
|
5294
|
+
stroke: series.color || defaultColors[seriesIndex % defaultColors.length],
|
|
5295
|
+
strokeWidth,
|
|
5296
|
+
strokeLinecap: "round",
|
|
5297
|
+
strokeLinejoin: "round"
|
|
5170
5298
|
},
|
|
5171
|
-
`
|
|
5172
|
-
)
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5299
|
+
`line-${seriesIndex}`
|
|
5300
|
+
)),
|
|
5301
|
+
showDots && data.map(
|
|
5302
|
+
(series, seriesIndex) => series.data.map((point, pointIndex) => {
|
|
5303
|
+
const x = scaleX(point.x, pointIndex);
|
|
5304
|
+
const y = scaleY(point.y);
|
|
5305
|
+
const isHovered = hoveredPoint?.seriesIndex === seriesIndex && hoveredPoint?.pointIndex === pointIndex;
|
|
5306
|
+
return /* @__PURE__ */ jsx108(
|
|
5307
|
+
"circle",
|
|
5308
|
+
{
|
|
5309
|
+
cx: x,
|
|
5310
|
+
cy: y,
|
|
5311
|
+
r: isHovered ? 6 : 4,
|
|
5312
|
+
fill: series.color || defaultColors[seriesIndex % defaultColors.length],
|
|
5313
|
+
stroke: "white",
|
|
5314
|
+
strokeWidth: "2",
|
|
5315
|
+
className: "cursor-pointer transition-all",
|
|
5316
|
+
onMouseEnter: () => showTooltip && setHoveredPoint({ seriesIndex, pointIndex, x, y }),
|
|
5317
|
+
onMouseLeave: () => setHoveredPoint(null)
|
|
5318
|
+
},
|
|
5319
|
+
`point-${seriesIndex}-${pointIndex}`
|
|
5320
|
+
);
|
|
5321
|
+
})
|
|
5322
|
+
),
|
|
5323
|
+
xAxisLabel && showXAxis && /* @__PURE__ */ jsx108(
|
|
5324
|
+
"text",
|
|
5325
|
+
{
|
|
5326
|
+
x: chartWidth / 2,
|
|
5327
|
+
y: chartHeight + 50,
|
|
5328
|
+
textAnchor: "middle",
|
|
5329
|
+
fontSize: "16",
|
|
5330
|
+
fontWeight: "500",
|
|
5331
|
+
className: "fill-gray-700 dark:fill-gray-300",
|
|
5332
|
+
children: xAxisLabel
|
|
5333
|
+
}
|
|
5334
|
+
),
|
|
5335
|
+
yAxisLabel && showYAxis && /* @__PURE__ */ jsx108(
|
|
5336
|
+
"text",
|
|
5337
|
+
{
|
|
5338
|
+
x: -chartHeight / 2,
|
|
5339
|
+
y: -45,
|
|
5340
|
+
textAnchor: "middle",
|
|
5341
|
+
fontSize: "16",
|
|
5342
|
+
fontWeight: "500",
|
|
5343
|
+
transform: `rotate(-90, 0, 0)`,
|
|
5344
|
+
className: "fill-gray-700 dark:fill-gray-300",
|
|
5345
|
+
children: yAxisLabel
|
|
5346
|
+
}
|
|
5347
|
+
)
|
|
5348
|
+
] })
|
|
5349
|
+
}
|
|
5350
|
+
),
|
|
5351
|
+
showLegend && /* @__PURE__ */ jsx108("div", { className: "flex flex-wrap gap-4 mt-4 justify-center", children: data.map((series, index) => /* @__PURE__ */ jsxs35("div", { className: "flex items-center gap-2", children: [
|
|
5352
|
+
/* @__PURE__ */ jsx108(
|
|
5353
|
+
"div",
|
|
5177
5354
|
{
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
children: xAxisLabel
|
|
5355
|
+
className: "w-4 h-4 rounded-sm",
|
|
5356
|
+
style: {
|
|
5357
|
+
backgroundColor: series.color || defaultColors[index % defaultColors.length]
|
|
5358
|
+
}
|
|
5183
5359
|
}
|
|
5184
5360
|
),
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
}
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5361
|
+
/* @__PURE__ */ jsx108("span", { className: "text-sm text-gray-700 dark:text-gray-300", children: series.name })
|
|
5362
|
+
] }, `legend-${index}`)) }),
|
|
5363
|
+
showTooltip && hoveredPoint && /* @__PURE__ */ jsxs35(
|
|
5364
|
+
"div",
|
|
5365
|
+
{
|
|
5366
|
+
className: "absolute bg-gray-900 dark:bg-gray-700 text-white px-3 py-2 rounded shadow-lg text-sm pointer-events-none z-50",
|
|
5367
|
+
style: {
|
|
5368
|
+
left: `${padding.left + hoveredPoint.x + 10}px`,
|
|
5369
|
+
top: `${padding.top + hoveredPoint.y - 30}px`
|
|
5370
|
+
},
|
|
5371
|
+
children: [
|
|
5372
|
+
/* @__PURE__ */ jsx108("div", { className: "font-semibold", children: data[hoveredPoint.seriesIndex].name }),
|
|
5373
|
+
/* @__PURE__ */ jsxs35("div", { children: [
|
|
5374
|
+
"x: ",
|
|
5375
|
+
data[hoveredPoint.seriesIndex].data[hoveredPoint.pointIndex].x
|
|
5376
|
+
] }),
|
|
5377
|
+
/* @__PURE__ */ jsxs35("div", { children: [
|
|
5378
|
+
"y: ",
|
|
5379
|
+
data[hoveredPoint.seriesIndex].data[hoveredPoint.pointIndex].y
|
|
5380
|
+
] })
|
|
5381
|
+
]
|
|
5206
5382
|
}
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
showTooltip && hoveredPoint && /* @__PURE__ */ jsxs35(
|
|
5212
|
-
"div",
|
|
5213
|
-
{
|
|
5214
|
-
className: "absolute bg-gray-900 dark:bg-gray-700 text-white px-3 py-2 rounded shadow-lg text-sm pointer-events-none z-50",
|
|
5215
|
-
style: {
|
|
5216
|
-
left: `${padding.left + hoveredPoint.x + 10}px`,
|
|
5217
|
-
top: `${padding.top + hoveredPoint.y - 30}px`
|
|
5218
|
-
},
|
|
5219
|
-
children: [
|
|
5220
|
-
/* @__PURE__ */ jsx108("div", { className: "font-semibold", children: data[hoveredPoint.seriesIndex].name }),
|
|
5221
|
-
/* @__PURE__ */ jsxs35("div", { children: [
|
|
5222
|
-
"x: ",
|
|
5223
|
-
data[hoveredPoint.seriesIndex].data[hoveredPoint.pointIndex].x
|
|
5224
|
-
] }),
|
|
5225
|
-
/* @__PURE__ */ jsxs35("div", { children: [
|
|
5226
|
-
"y: ",
|
|
5227
|
-
data[hoveredPoint.seriesIndex].data[hoveredPoint.pointIndex].y
|
|
5228
|
-
] })
|
|
5229
|
-
]
|
|
5230
|
-
}
|
|
5231
|
-
)
|
|
5232
|
-
] });
|
|
5383
|
+
)
|
|
5384
|
+
]
|
|
5385
|
+
}
|
|
5386
|
+
);
|
|
5233
5387
|
};
|
|
5234
5388
|
|
|
5235
5389
|
// src/components/BarChart.tsx
|
|
@@ -5251,8 +5405,10 @@ var defaultColors2 = [
|
|
|
5251
5405
|
];
|
|
5252
5406
|
var BarChart = ({
|
|
5253
5407
|
data,
|
|
5254
|
-
width
|
|
5255
|
-
height
|
|
5408
|
+
width: providedWidth,
|
|
5409
|
+
height: providedHeight,
|
|
5410
|
+
aspectRatio = 16 / 9,
|
|
5411
|
+
responsive = true,
|
|
5256
5412
|
showGrid = true,
|
|
5257
5413
|
showXAxis = true,
|
|
5258
5414
|
showYAxis = true,
|
|
@@ -5266,6 +5422,8 @@ var BarChart = ({
|
|
|
5266
5422
|
xAxisLabel,
|
|
5267
5423
|
yAxisLabel
|
|
5268
5424
|
}) => {
|
|
5425
|
+
const height = providedHeight ?? 400;
|
|
5426
|
+
const width = providedWidth ?? (responsive ? 800 : 600);
|
|
5269
5427
|
const [hoveredBar, setHoveredBar] = React27.useState(null);
|
|
5270
5428
|
const padding = {
|
|
5271
5429
|
top: 20,
|
|
@@ -5319,7 +5477,8 @@ var BarChart = ({
|
|
|
5319
5477
|
x: -10,
|
|
5320
5478
|
y: y + 4,
|
|
5321
5479
|
textAnchor: "end",
|
|
5322
|
-
|
|
5480
|
+
fontSize: "14",
|
|
5481
|
+
className: "fill-gray-600 dark:fill-gray-400",
|
|
5323
5482
|
children: yValue.toFixed(0)
|
|
5324
5483
|
}
|
|
5325
5484
|
)
|
|
@@ -5415,7 +5574,9 @@ var BarChart = ({
|
|
|
5415
5574
|
x: xPos + actualBarWidth / 2,
|
|
5416
5575
|
y: yPos - 5,
|
|
5417
5576
|
textAnchor: "middle",
|
|
5418
|
-
|
|
5577
|
+
fontSize: "14",
|
|
5578
|
+
fontWeight: "500",
|
|
5579
|
+
className: "fill-gray-700 dark:fill-gray-300",
|
|
5419
5580
|
children: point.y
|
|
5420
5581
|
},
|
|
5421
5582
|
`value-${seriesIndex}-${barIndex}`
|
|
@@ -5435,79 +5596,93 @@ var BarChart = ({
|
|
|
5435
5596
|
x: xPos,
|
|
5436
5597
|
y: chartHeight + 20,
|
|
5437
5598
|
textAnchor: "middle",
|
|
5438
|
-
|
|
5599
|
+
fontSize: "14",
|
|
5600
|
+
className: "fill-gray-600 dark:fill-gray-400",
|
|
5439
5601
|
children: point.x
|
|
5440
5602
|
},
|
|
5441
5603
|
`x-label-${i}`
|
|
5442
5604
|
);
|
|
5443
5605
|
});
|
|
5444
|
-
return /* @__PURE__ */ jsxs36(
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
{
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
"
|
|
5606
|
+
return /* @__PURE__ */ jsxs36(
|
|
5607
|
+
"div",
|
|
5608
|
+
{
|
|
5609
|
+
className: `relative ${responsive ? "w-full" : "inline-block"} ${className}`,
|
|
5610
|
+
style: responsive ? { aspectRatio: `${width} / ${height}` } : void 0,
|
|
5611
|
+
children: [
|
|
5612
|
+
/* @__PURE__ */ jsx109(
|
|
5613
|
+
"svg",
|
|
5614
|
+
{
|
|
5615
|
+
width: "100%",
|
|
5616
|
+
height: "100%",
|
|
5617
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
5618
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
5619
|
+
className: "bg-white dark:bg-gray-800 block",
|
|
5620
|
+
style: { overflow: "visible" },
|
|
5621
|
+
children: /* @__PURE__ */ jsxs36("g", { transform: `translate(${padding.left}, ${padding.top})`, children: [
|
|
5622
|
+
gridLines,
|
|
5623
|
+
renderBars(),
|
|
5624
|
+
showXAxis && xAxisLabels,
|
|
5625
|
+
xAxisLabel && showXAxis && /* @__PURE__ */ jsx109(
|
|
5626
|
+
"text",
|
|
5627
|
+
{
|
|
5628
|
+
x: chartWidth / 2,
|
|
5629
|
+
y: chartHeight + 50,
|
|
5630
|
+
textAnchor: "middle",
|
|
5631
|
+
fontSize: "16",
|
|
5632
|
+
fontWeight: "500",
|
|
5633
|
+
className: "fill-gray-700 dark:fill-gray-300",
|
|
5634
|
+
children: xAxisLabel
|
|
5635
|
+
}
|
|
5636
|
+
),
|
|
5637
|
+
yAxisLabel && showYAxis && /* @__PURE__ */ jsx109(
|
|
5638
|
+
"text",
|
|
5639
|
+
{
|
|
5640
|
+
x: -chartHeight / 2,
|
|
5641
|
+
y: -45,
|
|
5642
|
+
textAnchor: "middle",
|
|
5643
|
+
fontSize: "16",
|
|
5644
|
+
fontWeight: "500",
|
|
5645
|
+
transform: `rotate(-90, 0, 0)`,
|
|
5646
|
+
className: "fill-gray-700 dark:fill-gray-300",
|
|
5647
|
+
children: yAxisLabel
|
|
5648
|
+
}
|
|
5649
|
+
)
|
|
5650
|
+
] })
|
|
5651
|
+
}
|
|
5652
|
+
),
|
|
5653
|
+
showLegend && /* @__PURE__ */ jsx109("div", { className: "flex flex-wrap gap-4 mt-4 justify-center", children: data.map((series, index) => /* @__PURE__ */ jsxs36("div", { className: "flex items-center gap-2", children: [
|
|
5654
|
+
/* @__PURE__ */ jsx109(
|
|
5655
|
+
"div",
|
|
5458
5656
|
{
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
children: xAxisLabel
|
|
5657
|
+
className: "w-4 h-4 rounded-sm",
|
|
5658
|
+
style: {
|
|
5659
|
+
backgroundColor: series.color || defaultColors2[index % defaultColors2.length]
|
|
5660
|
+
}
|
|
5464
5661
|
}
|
|
5465
5662
|
),
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
}
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
className: "w-4 h-4 rounded-sm",
|
|
5485
|
-
style: {
|
|
5486
|
-
backgroundColor: series.color || defaultColors2[index % defaultColors2.length]
|
|
5663
|
+
/* @__PURE__ */ jsx109("span", { className: "text-sm text-gray-700 dark:text-gray-300", children: series.name })
|
|
5664
|
+
] }, `legend-${index}`)) }),
|
|
5665
|
+
showTooltip && hoveredBar && /* @__PURE__ */ jsxs36(
|
|
5666
|
+
"div",
|
|
5667
|
+
{
|
|
5668
|
+
className: "absolute bg-gray-900 dark:bg-gray-700 text-white px-3 py-2 rounded shadow-lg text-sm pointer-events-none z-50",
|
|
5669
|
+
style: {
|
|
5670
|
+
left: `${padding.left + hoveredBar.x + 10}px`,
|
|
5671
|
+
top: `${padding.top + hoveredBar.y - 30}px`
|
|
5672
|
+
},
|
|
5673
|
+
children: [
|
|
5674
|
+
/* @__PURE__ */ jsx109("div", { className: "font-semibold", children: data[hoveredBar.seriesIndex].name }),
|
|
5675
|
+
/* @__PURE__ */ jsxs36("div", { children: [
|
|
5676
|
+
data[hoveredBar.seriesIndex].data[hoveredBar.barIndex].x,
|
|
5677
|
+
": ",
|
|
5678
|
+
data[hoveredBar.seriesIndex].data[hoveredBar.barIndex].y
|
|
5679
|
+
] })
|
|
5680
|
+
]
|
|
5487
5681
|
}
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
showTooltip && hoveredBar && /* @__PURE__ */ jsxs36(
|
|
5493
|
-
"div",
|
|
5494
|
-
{
|
|
5495
|
-
className: "absolute bg-gray-900 dark:bg-gray-700 text-white px-3 py-2 rounded shadow-lg text-sm pointer-events-none z-50",
|
|
5496
|
-
style: {
|
|
5497
|
-
left: `${padding.left + hoveredBar.x + 10}px`,
|
|
5498
|
-
top: `${padding.top + hoveredBar.y - 30}px`
|
|
5499
|
-
},
|
|
5500
|
-
children: [
|
|
5501
|
-
/* @__PURE__ */ jsx109("div", { className: "font-semibold", children: data[hoveredBar.seriesIndex].name }),
|
|
5502
|
-
/* @__PURE__ */ jsxs36("div", { children: [
|
|
5503
|
-
data[hoveredBar.seriesIndex].data[hoveredBar.barIndex].x,
|
|
5504
|
-
": ",
|
|
5505
|
-
data[hoveredBar.seriesIndex].data[hoveredBar.barIndex].y
|
|
5506
|
-
] })
|
|
5507
|
-
]
|
|
5508
|
-
}
|
|
5509
|
-
)
|
|
5510
|
-
] });
|
|
5682
|
+
)
|
|
5683
|
+
]
|
|
5684
|
+
}
|
|
5685
|
+
);
|
|
5511
5686
|
};
|
|
5512
5687
|
|
|
5513
5688
|
// src/components/AreaChart.tsx
|
|
@@ -5529,8 +5704,10 @@ var defaultColors3 = [
|
|
|
5529
5704
|
];
|
|
5530
5705
|
var AreaChart = ({
|
|
5531
5706
|
data,
|
|
5532
|
-
width
|
|
5533
|
-
height
|
|
5707
|
+
width: providedWidth,
|
|
5708
|
+
height: providedHeight,
|
|
5709
|
+
aspectRatio = 16 / 9,
|
|
5710
|
+
responsive = true,
|
|
5534
5711
|
showGrid = true,
|
|
5535
5712
|
showXAxis = true,
|
|
5536
5713
|
showYAxis = true,
|
|
@@ -5545,6 +5722,8 @@ var AreaChart = ({
|
|
|
5545
5722
|
xAxisLabel,
|
|
5546
5723
|
yAxisLabel
|
|
5547
5724
|
}) => {
|
|
5725
|
+
const height = providedHeight ?? 400;
|
|
5726
|
+
const width = providedWidth ?? 800;
|
|
5548
5727
|
const [hoveredPoint, setHoveredPoint] = React28.useState(null);
|
|
5549
5728
|
const padding = { top: 20, right: 20, bottom: showXAxis ? 60 : 20, left: showYAxis ? 60 : 20 };
|
|
5550
5729
|
const chartWidth = width - padding.left - padding.right;
|
|
@@ -5654,7 +5833,8 @@ var AreaChart = ({
|
|
|
5654
5833
|
x: -10,
|
|
5655
5834
|
y: y + 4,
|
|
5656
5835
|
textAnchor: "end",
|
|
5657
|
-
|
|
5836
|
+
fontSize: "12",
|
|
5837
|
+
className: "fill-gray-600 dark:fill-gray-400",
|
|
5658
5838
|
children: yValue.toFixed(0)
|
|
5659
5839
|
}
|
|
5660
5840
|
)
|
|
@@ -5686,7 +5866,8 @@ var AreaChart = ({
|
|
|
5686
5866
|
x,
|
|
5687
5867
|
y: chartHeight + 20,
|
|
5688
5868
|
textAnchor: "middle",
|
|
5689
|
-
|
|
5869
|
+
fontSize: "12",
|
|
5870
|
+
className: "fill-gray-600 dark:fill-gray-400",
|
|
5690
5871
|
children: xValue
|
|
5691
5872
|
}
|
|
5692
5873
|
)
|
|
@@ -5698,130 +5879,142 @@ var AreaChart = ({
|
|
|
5698
5879
|
if (stacked) {
|
|
5699
5880
|
cumulativeValues = Array(data[0]?.data.length || 0).fill(0);
|
|
5700
5881
|
}
|
|
5701
|
-
return /* @__PURE__ */ jsxs37(
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
{
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5882
|
+
return /* @__PURE__ */ jsxs37(
|
|
5883
|
+
"div",
|
|
5884
|
+
{
|
|
5885
|
+
className: `relative ${responsive ? "w-full" : "inline-block"} ${className}`,
|
|
5886
|
+
style: responsive ? { width: "100%", aspectRatio: `${width} / ${height}` } : void 0,
|
|
5887
|
+
children: [
|
|
5888
|
+
/* @__PURE__ */ jsx110(
|
|
5889
|
+
"svg",
|
|
5890
|
+
{
|
|
5891
|
+
width: "100%",
|
|
5892
|
+
height: "100%",
|
|
5893
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
5894
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
5895
|
+
className: "bg-white dark:bg-gray-800 block",
|
|
5896
|
+
children: /* @__PURE__ */ jsxs37("g", { transform: `translate(${padding.left}, ${padding.top})`, children: [
|
|
5897
|
+
gridLines,
|
|
5898
|
+
data.map((series, seriesIndex) => {
|
|
5899
|
+
const baselineYValues = stacked ? [...cumulativeValues] : void 0;
|
|
5900
|
+
const areaPath = generateAreaPath(series, baselineYValues);
|
|
5901
|
+
const linePath = generateLinePath(series, baselineYValues);
|
|
5902
|
+
if (stacked) {
|
|
5903
|
+
series.data.forEach((point, i) => {
|
|
5904
|
+
cumulativeValues[i] += point.y;
|
|
5905
|
+
});
|
|
5906
|
+
}
|
|
5907
|
+
return /* @__PURE__ */ jsxs37("g", { children: [
|
|
5908
|
+
/* @__PURE__ */ jsx110(
|
|
5909
|
+
"path",
|
|
5910
|
+
{
|
|
5911
|
+
d: areaPath,
|
|
5912
|
+
fill: series.color || defaultColors3[seriesIndex % defaultColors3.length],
|
|
5913
|
+
opacity: fillOpacity
|
|
5914
|
+
}
|
|
5915
|
+
),
|
|
5916
|
+
/* @__PURE__ */ jsx110(
|
|
5917
|
+
"path",
|
|
5918
|
+
{
|
|
5919
|
+
d: linePath,
|
|
5920
|
+
fill: "none",
|
|
5921
|
+
stroke: series.color || defaultColors3[seriesIndex % defaultColors3.length],
|
|
5922
|
+
strokeWidth,
|
|
5923
|
+
strokeLinecap: "round",
|
|
5924
|
+
strokeLinejoin: "round"
|
|
5925
|
+
}
|
|
5926
|
+
)
|
|
5927
|
+
] }, `area-${seriesIndex}`);
|
|
5928
|
+
}),
|
|
5929
|
+
showDots && data.map((series, seriesIndex) => {
|
|
5930
|
+
const baselineYValues = stacked ? data.slice(0, seriesIndex).reduce((acc, s) => {
|
|
5931
|
+
return acc.map((val, i) => val + (s.data[i]?.y || 0));
|
|
5932
|
+
}, Array(series.data.length).fill(0)) : void 0;
|
|
5933
|
+
return series.data.map((point, pointIndex) => {
|
|
5934
|
+
const x = scaleX(point.x, pointIndex);
|
|
5935
|
+
const y = baselineYValues ? scaleY(baselineYValues[pointIndex] + point.y) : scaleY(point.y);
|
|
5936
|
+
const isHovered = hoveredPoint?.seriesIndex === seriesIndex && hoveredPoint?.pointIndex === pointIndex;
|
|
5937
|
+
return /* @__PURE__ */ jsx110(
|
|
5938
|
+
"circle",
|
|
5939
|
+
{
|
|
5940
|
+
cx: x,
|
|
5941
|
+
cy: y,
|
|
5942
|
+
r: isHovered ? 6 : 4,
|
|
5943
|
+
fill: series.color || defaultColors3[seriesIndex % defaultColors3.length],
|
|
5944
|
+
stroke: "white",
|
|
5945
|
+
strokeWidth: "2",
|
|
5946
|
+
className: "cursor-pointer transition-all",
|
|
5947
|
+
onMouseEnter: () => showTooltip && setHoveredPoint({ seriesIndex, pointIndex, x, y }),
|
|
5948
|
+
onMouseLeave: () => setHoveredPoint(null)
|
|
5949
|
+
},
|
|
5950
|
+
`point-${seriesIndex}-${pointIndex}`
|
|
5951
|
+
);
|
|
5952
|
+
});
|
|
5953
|
+
}),
|
|
5954
|
+
xAxisLabel && showXAxis && /* @__PURE__ */ jsx110(
|
|
5955
|
+
"text",
|
|
5723
5956
|
{
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5957
|
+
x: chartWidth / 2,
|
|
5958
|
+
y: chartHeight + 50,
|
|
5959
|
+
textAnchor: "middle",
|
|
5960
|
+
fontSize: "14",
|
|
5961
|
+
fontWeight: "500",
|
|
5962
|
+
className: "fill-gray-700 dark:fill-gray-300",
|
|
5963
|
+
children: xAxisLabel
|
|
5727
5964
|
}
|
|
5728
5965
|
),
|
|
5729
|
-
/* @__PURE__ */ jsx110(
|
|
5730
|
-
"
|
|
5966
|
+
yAxisLabel && showYAxis && /* @__PURE__ */ jsx110(
|
|
5967
|
+
"text",
|
|
5731
5968
|
{
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5969
|
+
x: -chartHeight / 2,
|
|
5970
|
+
y: -45,
|
|
5971
|
+
textAnchor: "middle",
|
|
5972
|
+
fontSize: "14",
|
|
5973
|
+
fontWeight: "500",
|
|
5974
|
+
transform: "rotate(-90, 0, 0)",
|
|
5975
|
+
className: "fill-gray-700 dark:fill-gray-300",
|
|
5976
|
+
children: yAxisLabel
|
|
5738
5977
|
}
|
|
5739
5978
|
)
|
|
5740
|
-
] }
|
|
5741
|
-
}
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
return series.data.map((point, pointIndex) => {
|
|
5747
|
-
const x = scaleX(point.x, pointIndex);
|
|
5748
|
-
const y = baselineYValues ? scaleY(baselineYValues[pointIndex] + point.y) : scaleY(point.y);
|
|
5749
|
-
const isHovered = hoveredPoint?.seriesIndex === seriesIndex && hoveredPoint?.pointIndex === pointIndex;
|
|
5750
|
-
return /* @__PURE__ */ jsx110(
|
|
5751
|
-
"circle",
|
|
5752
|
-
{
|
|
5753
|
-
cx: x,
|
|
5754
|
-
cy: y,
|
|
5755
|
-
r: isHovered ? 6 : 4,
|
|
5756
|
-
fill: series.color || defaultColors3[seriesIndex % defaultColors3.length],
|
|
5757
|
-
stroke: "white",
|
|
5758
|
-
strokeWidth: "2",
|
|
5759
|
-
className: "cursor-pointer transition-all",
|
|
5760
|
-
onMouseEnter: () => showTooltip && setHoveredPoint({ seriesIndex, pointIndex, x, y }),
|
|
5761
|
-
onMouseLeave: () => setHoveredPoint(null)
|
|
5762
|
-
},
|
|
5763
|
-
`point-${seriesIndex}-${pointIndex}`
|
|
5764
|
-
);
|
|
5765
|
-
});
|
|
5766
|
-
}),
|
|
5767
|
-
xAxisLabel && showXAxis && /* @__PURE__ */ jsx110(
|
|
5768
|
-
"text",
|
|
5979
|
+
] })
|
|
5980
|
+
}
|
|
5981
|
+
),
|
|
5982
|
+
showLegend && /* @__PURE__ */ jsx110("div", { className: "flex flex-wrap gap-4 mt-4 justify-center", children: data.map((series, index) => /* @__PURE__ */ jsxs37("div", { className: "flex items-center gap-2", children: [
|
|
5983
|
+
/* @__PURE__ */ jsx110(
|
|
5984
|
+
"div",
|
|
5769
5985
|
{
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
children: xAxisLabel
|
|
5986
|
+
className: "w-4 h-4 rounded-sm",
|
|
5987
|
+
style: {
|
|
5988
|
+
backgroundColor: series.color || defaultColors3[index % defaultColors3.length]
|
|
5989
|
+
}
|
|
5775
5990
|
}
|
|
5776
5991
|
),
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
}
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5992
|
+
/* @__PURE__ */ jsx110("span", { className: "text-sm text-gray-700 dark:text-gray-300", children: series.name })
|
|
5993
|
+
] }, `legend-${index}`)) }),
|
|
5994
|
+
showTooltip && hoveredPoint && /* @__PURE__ */ jsxs37(
|
|
5995
|
+
"div",
|
|
5996
|
+
{
|
|
5997
|
+
className: "absolute bg-gray-900 dark:bg-gray-700 text-white px-3 py-2 rounded shadow-lg text-sm pointer-events-none z-50",
|
|
5998
|
+
style: {
|
|
5999
|
+
left: `${padding.left + hoveredPoint.x + 10}px`,
|
|
6000
|
+
top: `${padding.top + hoveredPoint.y - 30}px`
|
|
6001
|
+
},
|
|
6002
|
+
children: [
|
|
6003
|
+
/* @__PURE__ */ jsx110("div", { className: "font-semibold", children: data[hoveredPoint.seriesIndex].name }),
|
|
6004
|
+
/* @__PURE__ */ jsxs37("div", { children: [
|
|
6005
|
+
"x: ",
|
|
6006
|
+
data[hoveredPoint.seriesIndex].data[hoveredPoint.pointIndex].x
|
|
6007
|
+
] }),
|
|
6008
|
+
/* @__PURE__ */ jsxs37("div", { children: [
|
|
6009
|
+
"y: ",
|
|
6010
|
+
data[hoveredPoint.seriesIndex].data[hoveredPoint.pointIndex].y
|
|
6011
|
+
] })
|
|
6012
|
+
]
|
|
5798
6013
|
}
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
showTooltip && hoveredPoint && /* @__PURE__ */ jsxs37(
|
|
5804
|
-
"div",
|
|
5805
|
-
{
|
|
5806
|
-
className: "absolute bg-gray-900 dark:bg-gray-700 text-white px-3 py-2 rounded shadow-lg text-sm pointer-events-none z-50",
|
|
5807
|
-
style: {
|
|
5808
|
-
left: `${padding.left + hoveredPoint.x + 10}px`,
|
|
5809
|
-
top: `${padding.top + hoveredPoint.y - 30}px`
|
|
5810
|
-
},
|
|
5811
|
-
children: [
|
|
5812
|
-
/* @__PURE__ */ jsx110("div", { className: "font-semibold", children: data[hoveredPoint.seriesIndex].name }),
|
|
5813
|
-
/* @__PURE__ */ jsxs37("div", { children: [
|
|
5814
|
-
"x: ",
|
|
5815
|
-
data[hoveredPoint.seriesIndex].data[hoveredPoint.pointIndex].x
|
|
5816
|
-
] }),
|
|
5817
|
-
/* @__PURE__ */ jsxs37("div", { children: [
|
|
5818
|
-
"y: ",
|
|
5819
|
-
data[hoveredPoint.seriesIndex].data[hoveredPoint.pointIndex].y
|
|
5820
|
-
] })
|
|
5821
|
-
]
|
|
5822
|
-
}
|
|
5823
|
-
)
|
|
5824
|
-
] });
|
|
6014
|
+
)
|
|
6015
|
+
]
|
|
6016
|
+
}
|
|
6017
|
+
);
|
|
5825
6018
|
};
|
|
5826
6019
|
|
|
5827
6020
|
// src/components/PieChart.tsx
|
|
@@ -5847,8 +6040,10 @@ var defaultColors4 = [
|
|
|
5847
6040
|
];
|
|
5848
6041
|
var PieChart = ({
|
|
5849
6042
|
data,
|
|
5850
|
-
width
|
|
5851
|
-
height
|
|
6043
|
+
width: providedWidth,
|
|
6044
|
+
height: providedHeight,
|
|
6045
|
+
aspectRatio = 1,
|
|
6046
|
+
responsive = true,
|
|
5852
6047
|
showLegend = true,
|
|
5853
6048
|
showLabels = true,
|
|
5854
6049
|
showValues = false,
|
|
@@ -5857,6 +6052,8 @@ var PieChart = ({
|
|
|
5857
6052
|
donutWidth = 60,
|
|
5858
6053
|
className = ""
|
|
5859
6054
|
}) => {
|
|
6055
|
+
const height = providedHeight ?? 400;
|
|
6056
|
+
const width = providedWidth ?? 400;
|
|
5860
6057
|
const [hoveredSlice, setHoveredSlice] = React29.useState(null);
|
|
5861
6058
|
const total = data.reduce((sum, item) => sum + item.value, 0);
|
|
5862
6059
|
const centerX = width / 2;
|
|
@@ -5914,112 +6111,126 @@ var PieChart = ({
|
|
|
5914
6111
|
index
|
|
5915
6112
|
};
|
|
5916
6113
|
});
|
|
5917
|
-
return /* @__PURE__ */ jsxs38(
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
{
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
6114
|
+
return /* @__PURE__ */ jsxs38(
|
|
6115
|
+
"div",
|
|
6116
|
+
{
|
|
6117
|
+
className: `relative ${responsive ? "w-full flex justify-center" : "inline-block"} ${className}`,
|
|
6118
|
+
style: responsive ? { aspectRatio: `${width} / ${height}` } : void 0,
|
|
6119
|
+
children: [
|
|
6120
|
+
/* @__PURE__ */ jsxs38(
|
|
6121
|
+
"svg",
|
|
6122
|
+
{
|
|
6123
|
+
width: "100%",
|
|
6124
|
+
height: "100%",
|
|
6125
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
6126
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
6127
|
+
className: "bg-white dark:bg-gray-800 block",
|
|
6128
|
+
children: [
|
|
6129
|
+
slices.map((slice) => {
|
|
6130
|
+
const isHovered = hoveredSlice === slice.index;
|
|
6131
|
+
return /* @__PURE__ */ jsxs38("g", { children: [
|
|
6132
|
+
/* @__PURE__ */ jsx111(
|
|
6133
|
+
"path",
|
|
6134
|
+
{
|
|
6135
|
+
d: slice.path,
|
|
6136
|
+
fill: slice.color,
|
|
6137
|
+
stroke: "white",
|
|
6138
|
+
strokeWidth: "2",
|
|
6139
|
+
className: "cursor-pointer transition-opacity",
|
|
6140
|
+
opacity: isHovered ? 0.8 : 1,
|
|
6141
|
+
onMouseEnter: () => setHoveredSlice(slice.index),
|
|
6142
|
+
onMouseLeave: () => setHoveredSlice(null)
|
|
6143
|
+
}
|
|
6144
|
+
),
|
|
6145
|
+
showLabels && slice.percentage > 5 && /* @__PURE__ */ jsxs38(
|
|
6146
|
+
"text",
|
|
6147
|
+
{
|
|
6148
|
+
x: slice.labelX,
|
|
6149
|
+
y: slice.labelY,
|
|
6150
|
+
textAnchor: "middle",
|
|
6151
|
+
dominantBaseline: "middle",
|
|
6152
|
+
fontSize: "14",
|
|
6153
|
+
fontWeight: "600",
|
|
6154
|
+
className: "fill-gray-700 dark:fill-gray-200 pointer-events-none",
|
|
6155
|
+
children: [
|
|
6156
|
+
showPercentages && `${slice.percentage.toFixed(1)}%`,
|
|
6157
|
+
showPercentages && showValues && " ",
|
|
6158
|
+
showValues && `(${slice.value})`,
|
|
6159
|
+
!showPercentages && !showValues && slice.label
|
|
6160
|
+
]
|
|
6161
|
+
}
|
|
6162
|
+
)
|
|
6163
|
+
] }, slice.index);
|
|
6164
|
+
}),
|
|
6165
|
+
donut && /* @__PURE__ */ jsxs38("g", { children: [
|
|
6166
|
+
/* @__PURE__ */ jsx111(
|
|
6167
|
+
"text",
|
|
6168
|
+
{
|
|
6169
|
+
x: centerX,
|
|
6170
|
+
y: centerY - 10,
|
|
6171
|
+
textAnchor: "middle",
|
|
6172
|
+
fontSize: "32",
|
|
6173
|
+
fontWeight: "700",
|
|
6174
|
+
className: "fill-gray-900 dark:fill-gray-100",
|
|
6175
|
+
children: total
|
|
6176
|
+
}
|
|
6177
|
+
),
|
|
6178
|
+
/* @__PURE__ */ jsx111(
|
|
6179
|
+
"text",
|
|
6180
|
+
{
|
|
6181
|
+
x: centerX,
|
|
6182
|
+
y: centerY + 15,
|
|
6183
|
+
textAnchor: "middle",
|
|
6184
|
+
fontSize: "16",
|
|
6185
|
+
className: "fill-gray-600 dark:fill-gray-400",
|
|
6186
|
+
children: "Total"
|
|
6187
|
+
}
|
|
6188
|
+
)
|
|
6189
|
+
] })
|
|
6190
|
+
]
|
|
6191
|
+
}
|
|
6192
|
+
),
|
|
6193
|
+
showLegend && /* @__PURE__ */ jsx111("div", { className: "flex flex-wrap gap-4 mt-4 justify-center", children: data.map((item, index) => /* @__PURE__ */ jsxs38(
|
|
6194
|
+
"div",
|
|
6195
|
+
{
|
|
6196
|
+
className: "flex items-center gap-2 cursor-pointer",
|
|
6197
|
+
onMouseEnter: () => setHoveredSlice(index),
|
|
6198
|
+
onMouseLeave: () => setHoveredSlice(null),
|
|
6199
|
+
children: [
|
|
5928
6200
|
/* @__PURE__ */ jsx111(
|
|
5929
|
-
"
|
|
6201
|
+
"div",
|
|
5930
6202
|
{
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
className: "cursor-pointer transition-opacity",
|
|
5936
|
-
opacity: isHovered ? 0.8 : 1,
|
|
5937
|
-
onMouseEnter: () => setHoveredSlice(slice.index),
|
|
5938
|
-
onMouseLeave: () => setHoveredSlice(null)
|
|
6203
|
+
className: "w-4 h-4 rounded-sm",
|
|
6204
|
+
style: {
|
|
6205
|
+
backgroundColor: item.color || defaultColors4[index % defaultColors4.length]
|
|
6206
|
+
}
|
|
5939
6207
|
}
|
|
5940
6208
|
),
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
"text",
|
|
5962
|
-
{
|
|
5963
|
-
x: centerX,
|
|
5964
|
-
y: centerY - 10,
|
|
5965
|
-
textAnchor: "middle",
|
|
5966
|
-
className: "text-2xl font-bold fill-gray-900 dark:fill-gray-100",
|
|
5967
|
-
children: total
|
|
5968
|
-
}
|
|
5969
|
-
),
|
|
5970
|
-
/* @__PURE__ */ jsx111(
|
|
5971
|
-
"text",
|
|
5972
|
-
{
|
|
5973
|
-
x: centerX,
|
|
5974
|
-
y: centerY + 15,
|
|
5975
|
-
textAnchor: "middle",
|
|
5976
|
-
className: "text-sm fill-gray-600 dark:fill-gray-400",
|
|
5977
|
-
children: "Total"
|
|
5978
|
-
}
|
|
5979
|
-
)
|
|
5980
|
-
] })
|
|
5981
|
-
]
|
|
5982
|
-
}
|
|
5983
|
-
),
|
|
5984
|
-
showLegend && /* @__PURE__ */ jsx111("div", { className: "flex flex-wrap gap-4 mt-4 justify-center", children: data.map((item, index) => /* @__PURE__ */ jsxs38(
|
|
5985
|
-
"div",
|
|
5986
|
-
{
|
|
5987
|
-
className: "flex items-center gap-2 cursor-pointer",
|
|
5988
|
-
onMouseEnter: () => setHoveredSlice(index),
|
|
5989
|
-
onMouseLeave: () => setHoveredSlice(null),
|
|
5990
|
-
children: [
|
|
5991
|
-
/* @__PURE__ */ jsx111(
|
|
5992
|
-
"div",
|
|
5993
|
-
{
|
|
5994
|
-
className: "w-4 h-4 rounded-sm",
|
|
5995
|
-
style: {
|
|
5996
|
-
backgroundColor: item.color || defaultColors4[index % defaultColors4.length]
|
|
5997
|
-
}
|
|
5998
|
-
}
|
|
5999
|
-
),
|
|
6000
|
-
/* @__PURE__ */ jsxs38("span", { className: "text-sm text-gray-700 dark:text-gray-300", children: [
|
|
6001
|
-
item.label,
|
|
6002
|
-
": ",
|
|
6003
|
-
item.value,
|
|
6004
|
-
showPercentages && ` (${(item.value / total * 100).toFixed(1)}%)`
|
|
6209
|
+
/* @__PURE__ */ jsxs38("span", { className: "text-sm text-gray-700 dark:text-gray-300", children: [
|
|
6210
|
+
item.label,
|
|
6211
|
+
": ",
|
|
6212
|
+
item.value,
|
|
6213
|
+
showPercentages && ` (${(item.value / total * 100).toFixed(1)}%)`
|
|
6214
|
+
] })
|
|
6215
|
+
]
|
|
6216
|
+
},
|
|
6217
|
+
`legend-${index}`
|
|
6218
|
+
)) }),
|
|
6219
|
+
hoveredSlice !== null && /* @__PURE__ */ jsxs38("div", { className: "absolute top-2 right-2 bg-gray-900 dark:bg-gray-700 text-white px-3 py-2 rounded shadow-lg text-sm pointer-events-none z-50", children: [
|
|
6220
|
+
/* @__PURE__ */ jsx111("div", { className: "font-semibold", children: data[hoveredSlice].label }),
|
|
6221
|
+
/* @__PURE__ */ jsxs38("div", { children: [
|
|
6222
|
+
"Value: ",
|
|
6223
|
+
data[hoveredSlice].value
|
|
6224
|
+
] }),
|
|
6225
|
+
/* @__PURE__ */ jsxs38("div", { children: [
|
|
6226
|
+
"Percentage: ",
|
|
6227
|
+
(data[hoveredSlice].value / total * 100).toFixed(1),
|
|
6228
|
+
"%"
|
|
6005
6229
|
] })
|
|
6006
|
-
]
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
hoveredSlice !== null && /* @__PURE__ */ jsxs38("div", { className: "absolute top-2 right-2 bg-gray-900 dark:bg-gray-700 text-white px-3 py-2 rounded shadow-lg text-sm pointer-events-none z-50", children: [
|
|
6011
|
-
/* @__PURE__ */ jsx111("div", { className: "font-semibold", children: data[hoveredSlice].label }),
|
|
6012
|
-
/* @__PURE__ */ jsxs38("div", { children: [
|
|
6013
|
-
"Value: ",
|
|
6014
|
-
data[hoveredSlice].value
|
|
6015
|
-
] }),
|
|
6016
|
-
/* @__PURE__ */ jsxs38("div", { children: [
|
|
6017
|
-
"Percentage: ",
|
|
6018
|
-
(data[hoveredSlice].value / total * 100).toFixed(1),
|
|
6019
|
-
"%"
|
|
6020
|
-
] })
|
|
6021
|
-
] })
|
|
6022
|
-
] });
|
|
6230
|
+
] })
|
|
6231
|
+
]
|
|
6232
|
+
}
|
|
6233
|
+
);
|
|
6023
6234
|
};
|
|
6024
6235
|
|
|
6025
6236
|
// src/utils/theme-script.ts
|