@oliasoft-open-source/charts-library 4.7.2 → 4.7.3-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +57 -25
- package/dist/index.js.map +1 -1
- package/dist/src/components/common/common.interface.d.ts +2 -0
- package/dist/src/components/common/helpers/get-chart-annotation.d.ts +2 -0
- package/dist/src/components/common/plugins/annotation-dragger-plugin/annotation-dragger-plugin.d.ts +1 -0
- package/dist/src/components/common/plugins/annotation-dragger-plugin/helpers.d.ts +6 -4
- package/dist/src/components/line-chart/line-chart.stories.d.ts +111 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25236,6 +25236,7 @@ const getLineChartAxis = (options, axisType, state, currentScales, i2 = 0) => {
|
|
|
25236
25236
|
return ticks;
|
|
25237
25237
|
};
|
|
25238
25238
|
return {
|
|
25239
|
+
display: true,
|
|
25239
25240
|
type: additionalAxesOptions.chartScaleType,
|
|
25240
25241
|
position: axisData.position,
|
|
25241
25242
|
beginAtZero: additionalAxesOptions.beginAtZero,
|
|
@@ -26360,13 +26361,14 @@ const chartAreaTextPlugin = {
|
|
|
26360
26361
|
});
|
|
26361
26362
|
}
|
|
26362
26363
|
};
|
|
26363
|
-
const getMousePositionInCoordinates = (event, canvas2, scales) => {
|
|
26364
|
-
var _a2, _b2;
|
|
26364
|
+
const getMousePositionInCoordinates = (event, canvas2, scales, xScaleID, yScaleID) => {
|
|
26365
26365
|
const rect = canvas2.getBoundingClientRect();
|
|
26366
26366
|
const x2 = event.clientX - rect.left;
|
|
26367
26367
|
const y2 = event.clientY - rect.top;
|
|
26368
|
-
const
|
|
26369
|
-
const
|
|
26368
|
+
const xScale = scales[xScaleID];
|
|
26369
|
+
const yScale = scales[yScaleID];
|
|
26370
|
+
const xValue = (xScale == null ? void 0 : xScale.getValueForPixel(x2)) ?? -1;
|
|
26371
|
+
const yValue = (yScale == null ? void 0 : yScale.getValueForPixel(y2)) ?? -1;
|
|
26370
26372
|
return { x: xValue, y: yValue };
|
|
26371
26373
|
};
|
|
26372
26374
|
const calculateAnnotationMetricsInValues = (annotation2) => {
|
|
@@ -26393,29 +26395,30 @@ const calculateAnnotationMetricsInValues = (annotation2) => {
|
|
|
26393
26395
|
height
|
|
26394
26396
|
};
|
|
26395
26397
|
};
|
|
26396
|
-
const calculateAnnotationMetricsInValuesInPixels = (annotation2, scales) => {
|
|
26398
|
+
const calculateAnnotationMetricsInValuesInPixels = (annotation2, scales, xScaleID, yScaleID) => {
|
|
26397
26399
|
const { xMin, xMax, yMin, yMax, xValue, yValue, type } = annotation2 ?? {};
|
|
26398
|
-
const { x: x2, y: y2 } = scales ?? {};
|
|
26399
26400
|
let centerX;
|
|
26400
26401
|
let centerY;
|
|
26401
26402
|
let width;
|
|
26402
26403
|
let height;
|
|
26404
|
+
const xScale = scales[xScaleID];
|
|
26405
|
+
const yScale = scales[yScaleID];
|
|
26403
26406
|
if (!isNil(xMin) && !isNil(xMax) && !isNil(yMin) && !isNil(yMax) && type === AnnotationType.BOX) {
|
|
26404
26407
|
const xCenterValue = (xMin + xMax) / 2;
|
|
26405
26408
|
const yCenterValue = (yMin + yMax) / 2;
|
|
26406
|
-
const xMinValue = (
|
|
26407
|
-
const xMaxValue = (
|
|
26408
|
-
const yMinValue = (
|
|
26409
|
-
const yMaxValue = (
|
|
26409
|
+
const xMinValue = (xScale == null ? void 0 : xScale.getPixelForValue(xMin)) ?? 0;
|
|
26410
|
+
const xMaxValue = (xScale == null ? void 0 : xScale.getPixelForValue(xMax)) ?? 0;
|
|
26411
|
+
const yMinValue = (yScale == null ? void 0 : yScale.getPixelForValue(yMin)) ?? 0;
|
|
26412
|
+
const yMaxValue = (yScale == null ? void 0 : yScale.getPixelForValue(yMax)) ?? 0;
|
|
26410
26413
|
width = xMinValue - xMaxValue;
|
|
26411
26414
|
height = yMinValue - yMaxValue;
|
|
26412
|
-
centerX = (
|
|
26413
|
-
centerY = (
|
|
26415
|
+
centerX = (xScale == null ? void 0 : xScale.getPixelForValue(xCenterValue)) ?? -1;
|
|
26416
|
+
centerY = (yScale == null ? void 0 : yScale.getPixelForValue(yCenterValue)) ?? -1;
|
|
26414
26417
|
} else if (!isNil(xValue) && !isNil(yValue) && type === AnnotationType.POINT) {
|
|
26415
26418
|
width = 0;
|
|
26416
26419
|
height = 0;
|
|
26417
|
-
centerX = (
|
|
26418
|
-
centerY = (
|
|
26420
|
+
centerX = (xScale == null ? void 0 : xScale.getPixelForValue(xValue)) ?? -1;
|
|
26421
|
+
centerY = (yScale == null ? void 0 : yScale.getPixelForValue(yValue)) ?? -1;
|
|
26419
26422
|
}
|
|
26420
26423
|
return {
|
|
26421
26424
|
centerX,
|
|
@@ -26432,7 +26435,9 @@ const isWithinChartArea = ({
|
|
|
26432
26435
|
metrics,
|
|
26433
26436
|
resizable = false,
|
|
26434
26437
|
dragRange,
|
|
26435
|
-
annotationType
|
|
26438
|
+
annotationType,
|
|
26439
|
+
xScaleID,
|
|
26440
|
+
yScaleID
|
|
26436
26441
|
}) => {
|
|
26437
26442
|
if (resizable && !dragRange) {
|
|
26438
26443
|
return true;
|
|
@@ -26442,10 +26447,12 @@ const isWithinChartArea = ({
|
|
|
26442
26447
|
const withinRangeY = y2 !== void 0 && dragRange.y ? y2 >= dragRange.y[0] && y2 <= dragRange.y[1] : true;
|
|
26443
26448
|
return withinRangeX && withinRangeY;
|
|
26444
26449
|
}
|
|
26445
|
-
const
|
|
26446
|
-
const
|
|
26447
|
-
const
|
|
26448
|
-
const
|
|
26450
|
+
const xScale = scales[xScaleID];
|
|
26451
|
+
const yScale = scales[yScaleID];
|
|
26452
|
+
const minX = (xScale == null ? void 0 : xScale.getValueForPixel(chartArea.left)) ?? Number.NEGATIVE_INFINITY;
|
|
26453
|
+
const maxX = (xScale == null ? void 0 : xScale.getValueForPixel(chartArea.right)) ?? Number.POSITIVE_INFINITY;
|
|
26454
|
+
const minY = (yScale == null ? void 0 : yScale.getValueForPixel(chartArea.bottom)) ?? Number.NEGATIVE_INFINITY;
|
|
26455
|
+
const maxY = (yScale == null ? void 0 : yScale.getValueForPixel(chartArea.top)) ?? Number.POSITIVE_INFINITY;
|
|
26449
26456
|
if (annotationType === AnnotationType.POINT) {
|
|
26450
26457
|
const withinX = x2 !== void 0 ? x2 >= minX && x2 <= maxX : true;
|
|
26451
26458
|
const withinY = y2 !== void 0 ? y2 >= minY && y2 <= maxY : true;
|
|
@@ -26462,7 +26469,7 @@ const isWithinChartArea = ({
|
|
|
26462
26469
|
}
|
|
26463
26470
|
return true;
|
|
26464
26471
|
};
|
|
26465
|
-
const updateAnnotationPositionWithinBounds = (axis, newPosition, activeAnnotation, chart2, scales, metrics) => {
|
|
26472
|
+
const updateAnnotationPositionWithinBounds = (axis, newPosition, activeAnnotation, chart2, scales, xScaleID, yScaleID, metrics) => {
|
|
26466
26473
|
const { resizable, dragRange = null } = activeAnnotation ?? {};
|
|
26467
26474
|
const checkArea = isWithinChartArea({
|
|
26468
26475
|
[axis]: newPosition,
|
|
@@ -26471,7 +26478,9 @@ const updateAnnotationPositionWithinBounds = (axis, newPosition, activeAnnotatio
|
|
|
26471
26478
|
resizable,
|
|
26472
26479
|
dragRange,
|
|
26473
26480
|
metrics: metrics || {},
|
|
26474
|
-
annotationType: activeAnnotation.type
|
|
26481
|
+
annotationType: activeAnnotation.type,
|
|
26482
|
+
xScaleID,
|
|
26483
|
+
yScaleID
|
|
26475
26484
|
});
|
|
26476
26485
|
if (!checkArea) return;
|
|
26477
26486
|
if (activeAnnotation.type === AnnotationType.POINT) {
|
|
@@ -26500,9 +26509,16 @@ const setAnnotationBorderWidth = (chart2, annotationId, borderWidth) => {
|
|
|
26500
26509
|
}
|
|
26501
26510
|
};
|
|
26502
26511
|
const handleAnnotationMouseDown = (event, canvas2, scales, annotations, setDraggingState, hoveredAnnotationId) => {
|
|
26503
|
-
const { x: x2, y: y2 } = getMousePositionInCoordinates(event, canvas2, scales);
|
|
26504
26512
|
const annotation2 = hoveredAnnotationId ? annotations == null ? void 0 : annotations[hoveredAnnotationId] : null;
|
|
26505
26513
|
if (!annotation2) return;
|
|
26514
|
+
const { xScaleID = "x", yScaleID = "y" } = annotation2;
|
|
26515
|
+
const { x: x2, y: y2 } = getMousePositionInCoordinates(
|
|
26516
|
+
event,
|
|
26517
|
+
canvas2,
|
|
26518
|
+
scales,
|
|
26519
|
+
xScaleID,
|
|
26520
|
+
yScaleID
|
|
26521
|
+
);
|
|
26506
26522
|
const metrics = calculateAnnotationMetricsInValues(annotation2);
|
|
26507
26523
|
if (annotation2 && annotation2.enableDrag && !isNil(metrics.centerY) && !isNil(metrics.centerX)) {
|
|
26508
26524
|
canvas2.style.cursor = CursorStyle.Move;
|
|
@@ -26520,7 +26536,14 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26520
26536
|
const annotationId = activeAnnotation == null ? void 0 : activeAnnotation.id;
|
|
26521
26537
|
setAnnotationBorderWidth(chart2, annotationId, BORDER_WIDTH.HOVERED);
|
|
26522
26538
|
const dragAxis = (activeAnnotation == null ? void 0 : activeAnnotation.dragAxis) ?? DragAxis.Both;
|
|
26523
|
-
const { x
|
|
26539
|
+
const { xScaleID = "x", yScaleID = "y" } = activeAnnotation;
|
|
26540
|
+
const { x: x2, y: y2 } = getMousePositionInCoordinates(
|
|
26541
|
+
event,
|
|
26542
|
+
canvas2,
|
|
26543
|
+
scales,
|
|
26544
|
+
xScaleID,
|
|
26545
|
+
yScaleID
|
|
26546
|
+
);
|
|
26524
26547
|
const metrics = calculateAnnotationMetricsInValues(activeAnnotation);
|
|
26525
26548
|
let newCenterX = x2 - dragStartX;
|
|
26526
26549
|
let newCenterY = y2 - dragStartY;
|
|
@@ -26531,6 +26554,8 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26531
26554
|
activeAnnotation,
|
|
26532
26555
|
chart2,
|
|
26533
26556
|
scales,
|
|
26557
|
+
xScaleID,
|
|
26558
|
+
yScaleID,
|
|
26534
26559
|
metrics
|
|
26535
26560
|
);
|
|
26536
26561
|
}
|
|
@@ -26541,6 +26566,8 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26541
26566
|
activeAnnotation,
|
|
26542
26567
|
chart2,
|
|
26543
26568
|
scales,
|
|
26569
|
+
xScaleID,
|
|
26570
|
+
yScaleID,
|
|
26544
26571
|
metrics
|
|
26545
26572
|
);
|
|
26546
26573
|
}
|
|
@@ -26550,7 +26577,12 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26550
26577
|
}
|
|
26551
26578
|
const { ctx, width, height } = chart2;
|
|
26552
26579
|
const { centerX, centerY } = calculateAnnotationMetricsInValues(activeAnnotation) ?? {};
|
|
26553
|
-
const { centerX: xValue, centerY: yValue } = calculateAnnotationMetricsInValuesInPixels(
|
|
26580
|
+
const { centerX: xValue, centerY: yValue } = calculateAnnotationMetricsInValuesInPixels(
|
|
26581
|
+
activeAnnotation,
|
|
26582
|
+
scales,
|
|
26583
|
+
xScaleID,
|
|
26584
|
+
yScaleID
|
|
26585
|
+
);
|
|
26554
26586
|
if (!isNil(centerX) && !isNil(centerY) && !isNil(xValue) && !isNil(yValue)) {
|
|
26555
26587
|
ctx.save();
|
|
26556
26588
|
ctx.clearRect(0, 0, width, height);
|
|
@@ -26660,7 +26692,7 @@ const annotationDraggerPlugin = {
|
|
|
26660
26692
|
const pluginOptions = ((_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.annotationDraggerPlugin) || {
|
|
26661
26693
|
enabled: false
|
|
26662
26694
|
};
|
|
26663
|
-
const typedScales = { x: scales.x, y: scales.y };
|
|
26695
|
+
const typedScales = { ...scales, x: scales.x, y: scales.y };
|
|
26664
26696
|
let annotations = ((_d2 = (_c2 = chart2.options.plugins) == null ? void 0 : _c2.annotation) == null ? void 0 : _d2.annotations) ?? {};
|
|
26665
26697
|
if (!chart2 && !annotations) return;
|
|
26666
26698
|
if (pluginOptions.enabled) {
|