@oliasoft-open-source/charts-library 5.4.0 → 5.5.0-beta-2
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/assets/{Color-AVL7NMMY-994VbFdE.js → Color-AVL7NMMY-Q1jtZEj4.js} +1 -1
- package/dist/assets/{DocsRenderer-PQXLIZUC-bAUpr2nb.js → DocsRenderer-PQXLIZUC-DH8_P5-s.js} +2 -2
- package/dist/assets/{bar-chart.stories-BgSpvkVq.js → bar-chart.stories-Dxq2MpGf.js} +1 -1
- package/dist/assets/client-D6AIHE8P.js +1 -0
- package/dist/assets/{components-Dh2frV4l.js → components-iTRs0GNG.js} +1 -1
- package/dist/assets/{get-draggableData-DaqZhgHK.js → get-draggableData-BhNReYKn.js} +1 -1
- package/dist/assets/{iframe-D8t45Jkw.js → iframe-BXFCu_25.js} +5 -5
- package/dist/assets/{legend-CPlrxuvf.js → legend-axxK95g8.js} +2 -2
- package/dist/assets/{legend-context-SNdgAaoM.js → legend-context-DWzlUfd5.js} +3 -3
- package/dist/assets/line-chart-DCxYmFrH.js +1 -0
- package/dist/assets/{line-chart.stories-ChpI0UHM.js → line-chart.stories-xyxJIMgK.js} +57 -45
- package/dist/assets/{line-chart.test-case.stories-B-SWX8h6.js → line-chart.test-case.stories-DtWmVHPp.js} +1 -1
- package/dist/assets/{pie-chart.stories-CBcjkrFA.js → pie-chart.stories-BnXOfjZV.js} +1 -1
- package/dist/assets/{react-18-DMqmYXih.js → react-18-BZQFBYmq.js} +1 -1
- package/dist/assets/{react-BgjAoB93.js → react-BnokuHUr.js} +1 -1
- package/dist/assets/{scatter-chart.stories-BqsR5bsR.js → scatter-chart.stories-CKOOIigg.js} +1 -1
- package/dist/common/common.interface.d.ts +9 -0
- package/dist/common/helpers/callout-helpers/callout-helpers.d.ts +5 -0
- package/dist/common/helpers/enums.d.ts +2 -1
- package/dist/common/helpers/get-chart-annotation.d.ts +5 -3
- package/dist/common/plugins/annotation-dragger-plugin/enums.d.ts +2 -1
- package/dist/iframe.html +1 -1
- package/dist/index.js +343 -110
- package/dist/index.json +1 -1
- package/dist/line-chart/plugins/callout-plugin/callout-plugin.d.ts +11 -0
- package/dist/line-chart/plugins/callout-plugin/helpers.d.ts +25 -0
- package/dist/line-chart/utils/get-line-chart-tooltips.d.ts +4 -8
- package/dist/project.json +1 -1
- package/dist/src/components/common/common.interface.d.ts +3 -0
- package/dist/src/components/common/helpers/callout-helpers/callout-helpers.d.ts +5 -0
- package/dist/src/components/common/helpers/enums.d.ts +2 -1
- package/dist/src/components/common/helpers/get-chart-annotation.d.ts +5 -3
- package/dist/src/components/common/plugins/annotation-dragger-plugin/enums.d.ts +2 -1
- package/dist/src/components/line-chart/plugins/callout-plugin/callout-plugin.d.ts +11 -0
- package/dist/src/components/line-chart/plugins/callout-plugin/helpers.d.ts +25 -0
- package/package.json +1 -1
- package/dist/assets/client-BDy5C6da.js +0 -1
- package/dist/assets/line-chart-WOEGLOk2.js +0 -1
package/dist/index.js
CHANGED
|
@@ -17632,6 +17632,7 @@ let AnnotationType = /* @__PURE__ */ function(AnnotationType$2) {
|
|
|
17632
17632
|
AnnotationType$2["Ellipse"] = "ellipse";
|
|
17633
17633
|
AnnotationType$2["Line"] = "line";
|
|
17634
17634
|
AnnotationType$2["Text"] = "text";
|
|
17635
|
+
AnnotationType$2["Label"] = "label";
|
|
17635
17636
|
return AnnotationType$2;
|
|
17636
17637
|
}({});
|
|
17637
17638
|
let PointStyle = /* @__PURE__ */ function(PointStyle$1) {
|
|
@@ -18727,6 +18728,7 @@ var defaultAnnotations$2 = (annotations) => ({
|
|
|
18727
18728
|
showAnnotations: annotations?.showAnnotations ?? false,
|
|
18728
18729
|
controlAnnotation: annotations?.controlAnnotation ?? false,
|
|
18729
18730
|
enableDragAnnotation: annotations?.enableDragAnnotation ?? false,
|
|
18731
|
+
enableCalloutAnnotation: annotations?.enableCalloutAnnotation ?? false,
|
|
18730
18732
|
annotationsData: defaultAnnotationsData$2(annotations?.annotationsData)
|
|
18731
18733
|
});
|
|
18732
18734
|
var defaultLegend$3 = (legend$1) => ({
|
|
@@ -19286,6 +19288,7 @@ let AnnotationType$1 = /* @__PURE__ */ function(AnnotationType$2) {
|
|
|
19286
19288
|
AnnotationType$2["BOX"] = "box";
|
|
19287
19289
|
AnnotationType$2["LINE"] = "line";
|
|
19288
19290
|
AnnotationType$2["ELLIPSE"] = "ellipse";
|
|
19291
|
+
AnnotationType$2["LABEL"] = "label";
|
|
19289
19292
|
return AnnotationType$2;
|
|
19290
19293
|
}({});
|
|
19291
19294
|
let DragAxis = /* @__PURE__ */ function(DragAxis$1) {
|
|
@@ -19302,6 +19305,64 @@ function addTransparency(input, alpha$1, out = "rgb") {
|
|
|
19302
19305
|
const c = color$3.alpha(a);
|
|
19303
19306
|
return out === "hex" ? c.toHex() : c.toRgbString();
|
|
19304
19307
|
}
|
|
19308
|
+
var getXScale = (chart$4, axisId) => {
|
|
19309
|
+
if (axisId && chart$4?.scales?.[axisId]) return chart$4.scales[axisId];
|
|
19310
|
+
if (chart$4?.scales?.x) return chart$4.scales.x;
|
|
19311
|
+
const key = Object.keys(chart$4?.scales ?? {})?.find((k) => k?.toLowerCase()?.includes("x"));
|
|
19312
|
+
return key ? chart$4?.scales?.[key] : void 0;
|
|
19313
|
+
};
|
|
19314
|
+
var getYScale = (chart$4, axisId) => {
|
|
19315
|
+
if (axisId && chart$4?.scales?.[axisId]) return chart$4.scales[axisId];
|
|
19316
|
+
if (chart$4?.scales?.y) return chart$4.scales.y;
|
|
19317
|
+
const key = Object.keys(chart$4?.scales ?? {})?.find((k) => k?.toLowerCase()?.includes("y"));
|
|
19318
|
+
return key ? chart$4?.scales?.[key] : void 0;
|
|
19319
|
+
};
|
|
19320
|
+
const resolveCalloutXAdjust = (ctx, refAnnotation, calloutCfg, index$2) => {
|
|
19321
|
+
if (typeof calloutCfg?.xAdjust === "function") return calloutCfg?.xAdjust?.(ctx);
|
|
19322
|
+
const chart$4 = ctx?.chart;
|
|
19323
|
+
const scale = getXScale(chart$4, refAnnotation?.annotationAxis);
|
|
19324
|
+
const xVal = refAnnotation?.xValue;
|
|
19325
|
+
if (!scale || typeof xVal !== "number") return 0;
|
|
19326
|
+
const area = chart$4?.chartArea;
|
|
19327
|
+
const halfW = ((ctx?.element)?.width ?? 0) / 2;
|
|
19328
|
+
const margin = calloutCfg?.margin ?? 8;
|
|
19329
|
+
const basePx = scale?.getPixelForValue(xVal);
|
|
19330
|
+
let dx = 0;
|
|
19331
|
+
if (typeof calloutCfg?.xAdjust === "number") dx = scale?.getPixelForValue(calloutCfg.xAdjust) - basePx;
|
|
19332
|
+
else dx = (index$2 % 2 === 0 ? 1 : -1) * 60;
|
|
19333
|
+
let cx$1 = basePx + dx;
|
|
19334
|
+
if (cx$1 - halfW < area.left + margin) {
|
|
19335
|
+
dx += area.left + margin + halfW - cx$1;
|
|
19336
|
+
cx$1 = basePx + dx;
|
|
19337
|
+
} else if (cx$1 + halfW > area.right - margin) {
|
|
19338
|
+
dx += area.right - margin - halfW - cx$1;
|
|
19339
|
+
cx$1 = basePx + dx;
|
|
19340
|
+
}
|
|
19341
|
+
return dx;
|
|
19342
|
+
};
|
|
19343
|
+
const resolveCalloutYAdjust = (ctx, refAnnotation, calloutCfg, index$2) => {
|
|
19344
|
+
if (typeof calloutCfg?.yAdjust === "function") return calloutCfg.yAdjust(ctx);
|
|
19345
|
+
const chart$4 = ctx?.chart;
|
|
19346
|
+
const scale = getYScale(chart$4, refAnnotation?.annotationAxis);
|
|
19347
|
+
const yVal = refAnnotation?.yValue;
|
|
19348
|
+
if (!scale || typeof yVal !== "number") return 0;
|
|
19349
|
+
const area = chart$4?.chartArea;
|
|
19350
|
+
const halfH = ((ctx?.element)?.height ?? 0) / 2;
|
|
19351
|
+
const margin = calloutCfg?.margin ?? 8;
|
|
19352
|
+
const basePx = scale?.getPixelForValue(yVal);
|
|
19353
|
+
let dy = 0;
|
|
19354
|
+
if (typeof calloutCfg?.yAdjust === "number") dy = scale?.getPixelForValue(calloutCfg.yAdjust) - basePx;
|
|
19355
|
+
else dy = -40 - Math.floor(index$2 / 2) * 22;
|
|
19356
|
+
let cy = basePx + dy;
|
|
19357
|
+
if (cy - halfH < area.top + margin) {
|
|
19358
|
+
dy += area.top + margin + halfH - cy;
|
|
19359
|
+
cy = basePx + dy;
|
|
19360
|
+
} else if (cy + halfH > area.bottom - margin) {
|
|
19361
|
+
dy += area.bottom - margin - halfH - cy;
|
|
19362
|
+
cy = basePx + dy;
|
|
19363
|
+
}
|
|
19364
|
+
return dy;
|
|
19365
|
+
};
|
|
19305
19366
|
var handleLineEnter = (element, chart$4, annotation$1) => {
|
|
19306
19367
|
chart$4.canvas.style.cursor = CursorStyle.Pointer;
|
|
19307
19368
|
if (element.options.scaleID?.includes(AxisType.X)) {
|
|
@@ -19368,112 +19429,199 @@ var handlePointLeave = (element, chart$4, annotation$1) => {
|
|
|
19368
19429
|
}
|
|
19369
19430
|
chart$4.draw();
|
|
19370
19431
|
};
|
|
19371
|
-
var
|
|
19372
|
-
|
|
19373
|
-
|
|
19374
|
-
|
|
19375
|
-
|
|
19376
|
-
|
|
19377
|
-
|
|
19378
|
-
|
|
19379
|
-
|
|
19380
|
-
|
|
19381
|
-
|
|
19382
|
-
|
|
19383
|
-
|
|
19384
|
-
|
|
19385
|
-
|
|
19386
|
-
|
|
19387
|
-
|
|
19388
|
-
|
|
19389
|
-
|
|
19390
|
-
|
|
19391
|
-
|
|
19392
|
-
|
|
19393
|
-
|
|
19394
|
-
|
|
19395
|
-
|
|
19396
|
-
|
|
19397
|
-
|
|
19398
|
-
|
|
19399
|
-
|
|
19400
|
-
|
|
19401
|
-
|
|
19402
|
-
|
|
19403
|
-
|
|
19404
|
-
|
|
19405
|
-
|
|
19406
|
-
|
|
19407
|
-
|
|
19408
|
-
|
|
19409
|
-
|
|
19410
|
-
|
|
19411
|
-
|
|
19412
|
-
|
|
19413
|
-
|
|
19414
|
-
|
|
19415
|
-
|
|
19416
|
-
|
|
19417
|
-
}[type] || defLabel;
|
|
19418
|
-
const enter = ({ element }, { chart: chart$4 }) => {
|
|
19419
|
-
switch (type) {
|
|
19420
|
-
case AnnotationType$1.LINE:
|
|
19421
|
-
handleLineEnter(element, chart$4, ann);
|
|
19422
|
-
break;
|
|
19423
|
-
case AnnotationType$1.BOX:
|
|
19424
|
-
handleBoxEnter(element, chart$4, ann);
|
|
19425
|
-
break;
|
|
19426
|
-
case AnnotationType$1.POINT:
|
|
19427
|
-
handlePointEnter(element, chart$4, ann);
|
|
19428
|
-
break;
|
|
19429
|
-
default: break;
|
|
19430
|
-
}
|
|
19431
|
-
};
|
|
19432
|
-
const leave = ({ element }, { chart: chart$4 }) => {
|
|
19433
|
-
switch (type) {
|
|
19434
|
-
case AnnotationType$1.LINE:
|
|
19435
|
-
handleLineLeave(element, chart$4, ann);
|
|
19436
|
-
break;
|
|
19437
|
-
case AnnotationType$1.BOX:
|
|
19438
|
-
handleBoxLeave(element, chart$4, ann);
|
|
19439
|
-
break;
|
|
19440
|
-
case AnnotationType$1.POINT:
|
|
19441
|
-
handlePointLeave(element, chart$4, ann);
|
|
19442
|
-
break;
|
|
19443
|
-
default: break;
|
|
19444
|
-
}
|
|
19445
|
-
};
|
|
19446
|
-
const onDragStart = () => (cord, annotation$1) => ann?.onDragStart ? ann?.onDragStart(cord, annotation$1) : void 0;
|
|
19447
|
-
const onDrag = () => (cord, annotation$1) => ann?.onDrag ? ann?.onDrag(cord, annotation$1) : void 0;
|
|
19448
|
-
const onDragEnd = () => (cord, annotation$1) => ann?.onDragEnd ? ann?.onDragEnd(cord, annotation$1) : void 0;
|
|
19449
|
-
return {
|
|
19450
|
-
...ann,
|
|
19451
|
-
display: ann?.display,
|
|
19452
|
-
annotationIndex: idx,
|
|
19453
|
-
id: `${ann?.label}-${ann?.value}-${idx}`,
|
|
19454
|
-
scaleID,
|
|
19455
|
-
label,
|
|
19432
|
+
var handleLabelEnter = (element, chart$4, annotation$1) => {
|
|
19433
|
+
if (annotation$1?.enableDrag) {
|
|
19434
|
+
chart$4.hoveredAnnotationId = element.options.id || null;
|
|
19435
|
+
chart$4.update("none");
|
|
19436
|
+
element.options.borderWidth = BORDER_WIDTH.POINT_HOVERED;
|
|
19437
|
+
chart$4.canvas.style.cursor = CursorStyle.Pointer;
|
|
19438
|
+
}
|
|
19439
|
+
chart$4.draw();
|
|
19440
|
+
};
|
|
19441
|
+
var handleLabelLeave = (element, chart$4, annotation$1) => {
|
|
19442
|
+
if (annotation$1?.enableDrag) {
|
|
19443
|
+
chart$4.hoveredAnnotationId = null;
|
|
19444
|
+
element.options.borderWidth = BORDER_WIDTH.INITIAL;
|
|
19445
|
+
chart$4.canvas.style.cursor = CursorStyle.Initial;
|
|
19446
|
+
chart$4.update("none");
|
|
19447
|
+
}
|
|
19448
|
+
chart$4.draw();
|
|
19449
|
+
};
|
|
19450
|
+
const generateAnn = (ann, index$2) => {
|
|
19451
|
+
const scaleID = ann?.annotationAxis ?? void 0;
|
|
19452
|
+
const inputColor = ann?.color ?? COLORS[index$2];
|
|
19453
|
+
const color$3 = !!ann?.opacity ? addTransparency(inputColor, ann?.opacity) : inputColor;
|
|
19454
|
+
const type = ann?.type ?? AnnotationType$1.LINE;
|
|
19455
|
+
const adjustScaleRange$1 = ann?.adjustScaleRange;
|
|
19456
|
+
const borderColor = {
|
|
19457
|
+
[AnnotationType$1.LINE]: color$3,
|
|
19458
|
+
[AnnotationType$1.POINT]: color$3,
|
|
19459
|
+
[AnnotationType$1.LABEL]: color$3,
|
|
19460
|
+
[AnnotationType$1.BOX]: color$3,
|
|
19461
|
+
[AnnotationType$1.ELLIPSE]: "transparent"
|
|
19462
|
+
}[type] || "transparent";
|
|
19463
|
+
const borderWidth = {
|
|
19464
|
+
[AnnotationType$1.LINE]: BORDER_WIDTH.INITIAL,
|
|
19465
|
+
[AnnotationType$1.BOX]: BORDER_WIDTH.ZERO,
|
|
19466
|
+
[AnnotationType$1.POINT]: BORDER_WIDTH.ZERO,
|
|
19467
|
+
[AnnotationType$1.LABEL]: BORDER_WIDTH.ZERO,
|
|
19468
|
+
[AnnotationType$1.ELLIPSE]: ann?.borderWidth ?? 0
|
|
19469
|
+
}[type] ?? 0;
|
|
19470
|
+
const borderDash = type === AnnotationType$1.LINE ? ANNOTATION_DASH : void 0;
|
|
19471
|
+
const defLabel = {
|
|
19472
|
+
content: ann?.label,
|
|
19473
|
+
display: true,
|
|
19474
|
+
font: { weight: "normal" }
|
|
19475
|
+
};
|
|
19476
|
+
const label = {
|
|
19477
|
+
[AnnotationType$1.LINE]: {
|
|
19456
19478
|
backgroundColor: color$3,
|
|
19457
|
-
|
|
19458
|
-
|
|
19459
|
-
|
|
19460
|
-
|
|
19461
|
-
|
|
19462
|
-
|
|
19463
|
-
|
|
19464
|
-
|
|
19465
|
-
|
|
19466
|
-
|
|
19467
|
-
|
|
19468
|
-
|
|
19469
|
-
|
|
19470
|
-
|
|
19479
|
+
content: ann?.label,
|
|
19480
|
+
display: false,
|
|
19481
|
+
position: Position.Top
|
|
19482
|
+
},
|
|
19483
|
+
[AnnotationType$1.POINT]: {
|
|
19484
|
+
backgroundColor: ann?.labelConfig?.backgroundColor ?? "transparent",
|
|
19485
|
+
content: ann?.label,
|
|
19486
|
+
display: ann?.labelConfig?.display ?? !!ann?.label,
|
|
19487
|
+
position: ann?.labelConfig?.position ?? Position.Bottom,
|
|
19488
|
+
color: ann?.labelConfig?.color ?? "hsl(60, 10.34482759%, 12.5%)",
|
|
19489
|
+
font: ann?.labelConfig?.font ?? `12px "Roobert", "Noto Sans", sans-serif`,
|
|
19490
|
+
borderWidth: BORDER_WIDTH.INITIAL,
|
|
19491
|
+
padding: 5,
|
|
19492
|
+
borderRadius: 3,
|
|
19493
|
+
borderColor: ann?.labelConfig?.borderColor ?? "transparent"
|
|
19494
|
+
},
|
|
19495
|
+
[AnnotationType$1.LABEL]: defLabel,
|
|
19496
|
+
[AnnotationType$1.BOX]: defLabel,
|
|
19497
|
+
[AnnotationType$1.ELLIPSE]: defLabel
|
|
19498
|
+
}[type] || defLabel;
|
|
19499
|
+
const enter = ({ element }, { chart: chart$4 }) => {
|
|
19500
|
+
console.log("enter");
|
|
19501
|
+
switch (type) {
|
|
19502
|
+
case AnnotationType$1.LINE:
|
|
19503
|
+
handleLineEnter(element, chart$4, ann);
|
|
19504
|
+
break;
|
|
19505
|
+
case AnnotationType$1.BOX:
|
|
19506
|
+
handleBoxEnter(element, chart$4, ann);
|
|
19507
|
+
break;
|
|
19508
|
+
case AnnotationType$1.LABEL:
|
|
19509
|
+
handleLabelEnter(element, chart$4, ann);
|
|
19510
|
+
break;
|
|
19511
|
+
case AnnotationType$1.POINT:
|
|
19512
|
+
handlePointEnter(element, chart$4, ann);
|
|
19513
|
+
break;
|
|
19514
|
+
default: break;
|
|
19515
|
+
}
|
|
19516
|
+
};
|
|
19517
|
+
const leave = ({ element }, { chart: chart$4 }) => {
|
|
19518
|
+
switch (type) {
|
|
19519
|
+
case AnnotationType$1.LINE:
|
|
19520
|
+
handleLineLeave(element, chart$4, ann);
|
|
19521
|
+
break;
|
|
19522
|
+
case AnnotationType$1.BOX:
|
|
19523
|
+
handleBoxLeave(element, chart$4, ann);
|
|
19524
|
+
break;
|
|
19525
|
+
case AnnotationType$1.LABEL:
|
|
19526
|
+
handleLabelLeave(element, chart$4, ann);
|
|
19527
|
+
break;
|
|
19528
|
+
case AnnotationType$1.POINT:
|
|
19529
|
+
handlePointLeave(element, chart$4, ann);
|
|
19530
|
+
break;
|
|
19531
|
+
default: break;
|
|
19532
|
+
}
|
|
19533
|
+
};
|
|
19534
|
+
const onDragStart = () => (cord, annotation$1) => ann?.onDragStart ? ann?.onDragStart(cord, annotation$1) : void 0;
|
|
19535
|
+
const onDrag = () => (cord, annotation$1) => ann?.onDrag ? ann?.onDrag(cord, annotation$1) : void 0;
|
|
19536
|
+
const onDragEnd = () => (cord, annotation$1) => ann?.onDragEnd ? ann?.onDragEnd(cord, annotation$1) : void 0;
|
|
19537
|
+
return {
|
|
19538
|
+
...ann,
|
|
19539
|
+
display: ann?.display,
|
|
19540
|
+
annotationIndex: index$2,
|
|
19541
|
+
id: ann?.id ?? `${ann?.label}-${index$2}`,
|
|
19542
|
+
scaleID,
|
|
19543
|
+
label,
|
|
19544
|
+
backgroundColor: color$3,
|
|
19545
|
+
borderColor,
|
|
19546
|
+
borderWidth,
|
|
19547
|
+
borderDash,
|
|
19548
|
+
type,
|
|
19549
|
+
adjustScaleRange: adjustScaleRange$1,
|
|
19550
|
+
enter,
|
|
19551
|
+
leave,
|
|
19552
|
+
onDragStart,
|
|
19553
|
+
onDrag,
|
|
19554
|
+
onDragEnd,
|
|
19555
|
+
pointStyle: ann?.pointStyle ?? PointStyle.Circle,
|
|
19556
|
+
resizable: ann?.resizable ?? true,
|
|
19557
|
+
displayDragCoordinates: ann?.displayDragCoordinates ?? true
|
|
19558
|
+
};
|
|
19559
|
+
};
|
|
19560
|
+
var getCalloutAnnotation = (refAnnotation, index$2) => {
|
|
19561
|
+
const generated = generateAnn(refAnnotation, index$2);
|
|
19562
|
+
if (!generated) return [];
|
|
19563
|
+
const { label,...baseRest } = generated;
|
|
19564
|
+
const baseId = baseRest.id;
|
|
19565
|
+
const calloutCfg = refAnnotation?.labelConfig?.callout ?? {};
|
|
19566
|
+
const baseAnnotation = {
|
|
19567
|
+
...baseRest,
|
|
19568
|
+
label: { display: false }
|
|
19569
|
+
};
|
|
19570
|
+
const color$3 = calloutCfg?.color ?? "hsl(60, 10.34482759%, 12.5%)";
|
|
19571
|
+
const font = calloutCfg?.font ?? `12px "Roobert", "Noto Sans", sans-serif`;
|
|
19572
|
+
const borderColor = calloutCfg?.borderColor ?? "transparent";
|
|
19573
|
+
const strokeStyle = calloutCfg.strokeStyle ?? baseAnnotation.borderColor;
|
|
19574
|
+
const lineWidth = typeof calloutCfg.lineWidth === "number" ? calloutCfg.lineWidth : 1;
|
|
19575
|
+
const startOffset = typeof calloutCfg.startOffset === "number" ? calloutCfg.startOffset : 4;
|
|
19576
|
+
const endOffset = typeof calloutCfg.endOffset === "number" ? calloutCfg.endOffset : 4;
|
|
19577
|
+
return [baseAnnotation, {
|
|
19578
|
+
...baseAnnotation,
|
|
19579
|
+
id: `callout-annotation-${index$2}`,
|
|
19580
|
+
type: "label",
|
|
19581
|
+
backgroundColor: "transparent",
|
|
19582
|
+
content: `${label?.content ?? refAnnotation?.label ?? ""}`,
|
|
19583
|
+
color: color$3,
|
|
19584
|
+
font,
|
|
19585
|
+
borderColor,
|
|
19586
|
+
borderWidth: BORDER_WIDTH.INITIAL,
|
|
19587
|
+
padding: 5,
|
|
19588
|
+
xAdjust: (ctx) => {
|
|
19589
|
+
return resolveCalloutXAdjust(ctx, refAnnotation, calloutCfg, index$2);
|
|
19590
|
+
},
|
|
19591
|
+
yAdjust: (ctx) => {
|
|
19592
|
+
return resolveCalloutYAdjust(ctx, refAnnotation, calloutCfg, index$2);
|
|
19593
|
+
},
|
|
19594
|
+
resizable: false,
|
|
19595
|
+
displayDragCoordinates: false,
|
|
19596
|
+
enableDrag: true,
|
|
19597
|
+
enter: ({ element }, { chart: chart$4 }) => {
|
|
19598
|
+
return handleLabelEnter(element, chart$4, { enableDrag: true });
|
|
19599
|
+
},
|
|
19600
|
+
leave: ({ element }, { chart: chart$4 }) => {
|
|
19601
|
+
return handleLabelLeave(element, chart$4, { enableDrag: true });
|
|
19602
|
+
},
|
|
19603
|
+
onDragStart: calloutCfg?.onDragStart ? () => (coords) => calloutCfg?.onDragStart?.(coords, refAnnotation) : void 0,
|
|
19604
|
+
onDrag: calloutCfg?.onDrag ? () => (coords) => calloutCfg?.onDrag?.(coords, refAnnotation) : void 0,
|
|
19605
|
+
onDragEnd: calloutCfg?.onDragEnd ? () => (coords) => calloutCfg?.onDragEnd?.(coords, refAnnotation) : void 0,
|
|
19606
|
+
calloutConnector: {
|
|
19607
|
+
enabled: true,
|
|
19608
|
+
fromId: baseId,
|
|
19609
|
+
strokeStyle,
|
|
19610
|
+
lineWidth,
|
|
19611
|
+
startOffset,
|
|
19612
|
+
endOffset
|
|
19613
|
+
}
|
|
19614
|
+
}];
|
|
19615
|
+
};
|
|
19616
|
+
var generateAnnotations = (annotationsData) => {
|
|
19617
|
+
return annotationsData?.flatMap((ann, idx) => {
|
|
19618
|
+
if (ann?.labelConfig?.callout?.enabled ?? false) return getCalloutAnnotation(ann, idx);
|
|
19619
|
+
return generateAnn(ann, idx);
|
|
19471
19620
|
});
|
|
19472
19621
|
};
|
|
19473
|
-
|
|
19622
|
+
const getAnnotation = ({ showAnnotations, annotationsData }) => {
|
|
19474
19623
|
return showAnnotations && annotationsData && annotationsData?.length ? generateAnnotations(annotationsData) ?? [] : [];
|
|
19475
19624
|
};
|
|
19476
|
-
var get_chart_annotation_default = getAnnotation;
|
|
19477
19625
|
const useUpdateAnnotations = (options, dispatch) => {
|
|
19478
19626
|
if (!options.annotations?.controlAnnotation) return;
|
|
19479
19627
|
const prevAnnotationsRef = useRef(null);
|
|
@@ -19483,7 +19631,7 @@ const useUpdateAnnotations = (options, dispatch) => {
|
|
|
19483
19631
|
if (!prev || prev.showAnnotations !== showAnnotations || !isEqual(prev.annotationsData, annotationsData)) {
|
|
19484
19632
|
dispatch({
|
|
19485
19633
|
type: SET_ANNOTATION,
|
|
19486
|
-
payload:
|
|
19634
|
+
payload: getAnnotation({
|
|
19487
19635
|
showAnnotations,
|
|
19488
19636
|
annotationsData
|
|
19489
19637
|
})
|
|
@@ -19502,7 +19650,7 @@ const LegendProvider = ({ children, options, datasets }) => {
|
|
|
19502
19650
|
...ds,
|
|
19503
19651
|
hidden: false
|
|
19504
19652
|
} })) ?? [];
|
|
19505
|
-
const annotation$1 =
|
|
19653
|
+
const annotation$1 = getAnnotation({
|
|
19506
19654
|
showAnnotations,
|
|
19507
19655
|
annotationsData
|
|
19508
19656
|
});
|
|
@@ -19581,7 +19729,11 @@ const useLegendState = ({ chartRef, options }) => {
|
|
|
19581
19729
|
const toAnnotationObject = (annotationArr = []) => {
|
|
19582
19730
|
let annotations = {};
|
|
19583
19731
|
if (annotationArr.length) annotations = annotationArr.reduce((acc, annotation$1, idx) => {
|
|
19584
|
-
|
|
19732
|
+
const key = annotation$1?.id ?? `annotation${idx + 1}`;
|
|
19733
|
+
acc[key] = {
|
|
19734
|
+
...annotation$1,
|
|
19735
|
+
id: key
|
|
19736
|
+
};
|
|
19585
19737
|
return acc;
|
|
19586
19738
|
}, {});
|
|
19587
19739
|
return { annotations };
|
|
@@ -19603,7 +19755,7 @@ const useChartOptions = ({ chartRef, state, options, dispatch, generatedDatasets
|
|
|
19603
19755
|
}) ?? {};
|
|
19604
19756
|
const { state: legendState } = useLegend() ?? {};
|
|
19605
19757
|
const { annotation: annotationFromLegend } = legendState ?? {};
|
|
19606
|
-
const annotation$1 = (controlAnnotation ? annotationFromLegend :
|
|
19758
|
+
const annotation$1 = (controlAnnotation ? annotationFromLegend : getAnnotation({
|
|
19607
19759
|
showAnnotations,
|
|
19608
19760
|
annotationsData
|
|
19609
19761
|
})) ?? [];
|
|
@@ -19641,6 +19793,7 @@ const useChartOptions = ({ chartRef, state, options, dispatch, generatedDatasets
|
|
|
19641
19793
|
const plugins$1 = {
|
|
19642
19794
|
datalabels,
|
|
19643
19795
|
annotationDraggerPlugin: { enabled: state?.enableDragAnnotation },
|
|
19796
|
+
calloutConnectorPlugin: { enableCalloutAnnotation: options?.annotations.enableCalloutAnnotation },
|
|
19644
19797
|
annotation: toAnnotationObject(annotation$1),
|
|
19645
19798
|
zoom: {
|
|
19646
19799
|
pan: panOptions,
|
|
@@ -19860,7 +20013,7 @@ const calculateAnnotationMetricsInValues = (annotation$1) => {
|
|
|
19860
20013
|
centerY = (yMin + yMax) / 2;
|
|
19861
20014
|
width = xMax - xMin;
|
|
19862
20015
|
height = yMax - yMin;
|
|
19863
|
-
} else if (!isNil(xValue) && !isNil(yValue) && type === AnnotationType$1.POINT) {
|
|
20016
|
+
} else if (!isNil(xValue) && !isNil(yValue) && (type === AnnotationType$1.POINT || type === AnnotationType$1.LABEL)) {
|
|
19864
20017
|
centerX = xValue;
|
|
19865
20018
|
centerY = yValue;
|
|
19866
20019
|
width = 0;
|
|
@@ -19898,7 +20051,7 @@ const calculateAnnotationMetricsInValuesInPixels = (annotation$1, scales$1, xSca
|
|
|
19898
20051
|
height = yMinValue - yMaxValue;
|
|
19899
20052
|
centerX = xScale?.getPixelForValue(xCenterValue) ?? -1;
|
|
19900
20053
|
centerY = yScale?.getPixelForValue(yCenterValue) ?? -1;
|
|
19901
|
-
} else if (!isNil(xValue) && !isNil(yValue) && type === AnnotationType$1.POINT) {
|
|
20054
|
+
} else if (!isNil(xValue) && !isNil(yValue) && (type === AnnotationType$1.POINT || type === AnnotationType$1.LABEL)) {
|
|
19902
20055
|
width = 0;
|
|
19903
20056
|
height = 0;
|
|
19904
20057
|
centerX = xScale?.getPixelForValue(xValue) ?? -1;
|
|
@@ -19925,7 +20078,7 @@ const isWithinChartArea = ({ x, y, chartArea, scales: scales$1, metrics, resizab
|
|
|
19925
20078
|
const maxX = xScale?.getValueForPixel(chartArea.right) ?? Number.POSITIVE_INFINITY;
|
|
19926
20079
|
const minY = yScale?.getValueForPixel(chartArea.bottom) ?? Number.NEGATIVE_INFINITY;
|
|
19927
20080
|
const maxY = yScale?.getValueForPixel(chartArea.top) ?? Number.POSITIVE_INFINITY;
|
|
19928
|
-
if (annotationType === AnnotationType$1.POINT) return (x !== void 0 ? x >= minX && x <= maxX : true) && (y !== void 0 ? y >= minY && y <= maxY : true);
|
|
20081
|
+
if (annotationType === AnnotationType$1.POINT || annotationType === AnnotationType$1.LABEL) return (x !== void 0 ? x >= minX && x <= maxX : true) && (y !== void 0 ? y >= minY && y <= maxY : true);
|
|
19929
20082
|
if (annotationType === AnnotationType$1.BOX && metrics.width !== void 0 && metrics.height !== void 0) {
|
|
19930
20083
|
const boxXMin = x !== void 0 ? x - metrics.width / 2 : void 0;
|
|
19931
20084
|
const boxXMax = x !== void 0 ? x + metrics.width / 2 : void 0;
|
|
@@ -19949,7 +20102,7 @@ const updateAnnotationPositionWithinBounds = (axis, newPosition, activeAnnotatio
|
|
|
19949
20102
|
xScaleID,
|
|
19950
20103
|
yScaleID
|
|
19951
20104
|
})) return;
|
|
19952
|
-
if (activeAnnotation.type === AnnotationType$1.POINT) {
|
|
20105
|
+
if (activeAnnotation.type === AnnotationType$1.POINT || activeAnnotation.type === AnnotationType$1.LABEL) {
|
|
19953
20106
|
if (axis === "x") activeAnnotation.xValue = newPosition;
|
|
19954
20107
|
else if (axis === "y") activeAnnotation.yValue = newPosition;
|
|
19955
20108
|
} else if (activeAnnotation.type === AnnotationType$1.BOX && metrics) {
|
|
@@ -20142,6 +20295,86 @@ const annotationDraggerPlugin = {
|
|
|
20142
20295
|
}
|
|
20143
20296
|
}
|
|
20144
20297
|
};
|
|
20298
|
+
var getRadius = (el) => {
|
|
20299
|
+
if (typeof el.options?.radius === "number") return el.options.radius;
|
|
20300
|
+
if (typeof el.width === "number" && typeof el.height === "number") return Math.min(el.width, el.height) / 2;
|
|
20301
|
+
return 0;
|
|
20302
|
+
};
|
|
20303
|
+
const computeConnectorPoints = (fromEl, labelEl, connector) => {
|
|
20304
|
+
const x1c = fromEl?.centerX;
|
|
20305
|
+
const y1c = fromEl?.centerY;
|
|
20306
|
+
const cx$1 = labelEl?.centerX;
|
|
20307
|
+
const cy = labelEl?.centerY;
|
|
20308
|
+
const labelWidth = labelEl?.width ?? 0;
|
|
20309
|
+
const labelHeight = labelEl?.height ?? 0;
|
|
20310
|
+
const ux = cx$1 - x1c;
|
|
20311
|
+
const uy = cy - y1c;
|
|
20312
|
+
const len = Math.sqrt(ux * ux + uy * uy) || 1;
|
|
20313
|
+
const dx = ux / len;
|
|
20314
|
+
const dy = uy / len;
|
|
20315
|
+
const fromRadius = getRadius(fromEl);
|
|
20316
|
+
const startOffset = (connector?.startOffset ?? 4) + fromRadius;
|
|
20317
|
+
const startX = x1c + dx * startOffset;
|
|
20318
|
+
const startY = y1c + dy * startOffset;
|
|
20319
|
+
let endX = cx$1;
|
|
20320
|
+
let endY = cy;
|
|
20321
|
+
if (labelWidth > 0 && labelHeight > 0) {
|
|
20322
|
+
const hw = labelWidth / 2;
|
|
20323
|
+
const hh = labelHeight / 2;
|
|
20324
|
+
const vx = x1c - cx$1;
|
|
20325
|
+
const vy = y1c - cy;
|
|
20326
|
+
const vlen = Math.sqrt(vx * vx + vy * vy) || 1;
|
|
20327
|
+
const vxn = vx / vlen;
|
|
20328
|
+
const vyn = vy / vlen;
|
|
20329
|
+
const tx = Math.abs(vxn) > 1e-6 ? hw / Math.abs(vxn) : Number.POSITIVE_INFINITY;
|
|
20330
|
+
const ty = Math.abs(vyn) > 1e-6 ? hh / Math.abs(vyn) : Number.POSITIVE_INFINITY;
|
|
20331
|
+
const total = Math.min(tx, ty) + (connector.endOffset ?? 4);
|
|
20332
|
+
endX = cx$1 + vxn * total;
|
|
20333
|
+
endY = cy + vyn * total;
|
|
20334
|
+
} else {
|
|
20335
|
+
const endOffset = connector.endOffset ?? 4;
|
|
20336
|
+
endX = cx$1 - dx * endOffset;
|
|
20337
|
+
endY = cy - dy * endOffset;
|
|
20338
|
+
}
|
|
20339
|
+
return {
|
|
20340
|
+
startX,
|
|
20341
|
+
startY,
|
|
20342
|
+
endX,
|
|
20343
|
+
endY
|
|
20344
|
+
};
|
|
20345
|
+
};
|
|
20346
|
+
const calloutConnectorPlugin = {
|
|
20347
|
+
id: "calloutConnector",
|
|
20348
|
+
afterDraw(chart$4) {
|
|
20349
|
+
const { enableCalloutAnnotation } = chart$4?.options?.plugins?.calloutConnectorPlugin || { enableCalloutAnnotation: false };
|
|
20350
|
+
if (!enableCalloutAnnotation) return;
|
|
20351
|
+
const elements$1 = annotation.getAnnotations(chart$4);
|
|
20352
|
+
if (!elements$1 || !elements$1.length) return;
|
|
20353
|
+
const annRoot = chart$4.options.plugins?.annotation;
|
|
20354
|
+
if (!annRoot) return;
|
|
20355
|
+
const raw = annRoot.annotations;
|
|
20356
|
+
if (!raw) return;
|
|
20357
|
+
(Array.isArray(raw) ? raw : Object.values(raw)).forEach((opt) => {
|
|
20358
|
+
const connector = opt?.calloutConnector;
|
|
20359
|
+
if (!connector || !connector.enabled || !opt?.id) return;
|
|
20360
|
+
const labelEl = elements$1.find((el) => el.options && el.options.id === opt.id);
|
|
20361
|
+
const fromEl = elements$1.find((el) => el.options && el.options.id === connector.fromId);
|
|
20362
|
+
if (!labelEl || !fromEl) return;
|
|
20363
|
+
const { startX, startY, endX, endY } = computeConnectorPoints(fromEl, labelEl, connector) ?? {};
|
|
20364
|
+
const ctx = chart$4?.ctx;
|
|
20365
|
+
ctx?.save?.();
|
|
20366
|
+
ctx?.beginPath?.();
|
|
20367
|
+
ctx?.moveTo?.(startX, startY);
|
|
20368
|
+
ctx?.lineTo?.(endX, endY);
|
|
20369
|
+
ctx.lineWidth = connector?.lineWidth ?? 1;
|
|
20370
|
+
ctx.strokeStyle = connector?.strokeStyle ?? "rgba(120,120,120,0.9)";
|
|
20371
|
+
if (connector?.lineDash && connector?.lineDash?.length) ctx?.setLineDash?.(connector.lineDash);
|
|
20372
|
+
ctx.lineCap = "round";
|
|
20373
|
+
ctx?.stroke?.();
|
|
20374
|
+
ctx?.restore?.();
|
|
20375
|
+
});
|
|
20376
|
+
}
|
|
20377
|
+
};
|
|
20145
20378
|
let defaultTranslations = /* @__PURE__ */ function(defaultTranslations$1) {
|
|
20146
20379
|
defaultTranslations$1["label"] = "Label";
|
|
20147
20380
|
defaultTranslations$1["pointsLines"] = "Points & lines";
|
|
@@ -20578,7 +20811,7 @@ var Legend$1 = ({ chartRef, legendConfig }) => {
|
|
|
20578
20811
|
] });
|
|
20579
20812
|
};
|
|
20580
20813
|
var legend_default = Legend$1;
|
|
20581
|
-
Chart.register(LinearScale, PointElement, LineElement, CategoryScale, LogarithmicScale, plugin_legend, plugin_tooltip, plugin_title, index, plugin, plugin$1, annotation, chartAreaTextPlugin, annotationDraggerPlugin, ellipsisAnnotationPlugin);
|
|
20814
|
+
Chart.register(LinearScale, PointElement, LineElement, CategoryScale, LogarithmicScale, plugin_legend, plugin_tooltip, plugin_title, index, plugin, plugin$1, annotation, chartAreaTextPlugin, annotationDraggerPlugin, ellipsisAnnotationPlugin, calloutConnectorPlugin);
|
|
20582
20815
|
var LineChart = (props) => {
|
|
20583
20816
|
setDefaultTheme();
|
|
20584
20817
|
const chartRef = useRef(null);
|