@oliasoft-open-source/charts-library 4.7.2 → 4.7.3-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/index.js +59 -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,8 +26536,17 @@ 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
|
+
);
|
|
26547
|
+
console.log("Mouse Coordinates:", x2, y2);
|
|
26524
26548
|
const metrics = calculateAnnotationMetricsInValues(activeAnnotation);
|
|
26549
|
+
console.log("Metrics:", metrics);
|
|
26525
26550
|
let newCenterX = x2 - dragStartX;
|
|
26526
26551
|
let newCenterY = y2 - dragStartY;
|
|
26527
26552
|
if (dragAxis !== DragAxis.Y) {
|
|
@@ -26531,6 +26556,8 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26531
26556
|
activeAnnotation,
|
|
26532
26557
|
chart2,
|
|
26533
26558
|
scales,
|
|
26559
|
+
xScaleID,
|
|
26560
|
+
yScaleID,
|
|
26534
26561
|
metrics
|
|
26535
26562
|
);
|
|
26536
26563
|
}
|
|
@@ -26541,6 +26568,8 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26541
26568
|
activeAnnotation,
|
|
26542
26569
|
chart2,
|
|
26543
26570
|
scales,
|
|
26571
|
+
xScaleID,
|
|
26572
|
+
yScaleID,
|
|
26544
26573
|
metrics
|
|
26545
26574
|
);
|
|
26546
26575
|
}
|
|
@@ -26550,7 +26579,12 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26550
26579
|
}
|
|
26551
26580
|
const { ctx, width, height } = chart2;
|
|
26552
26581
|
const { centerX, centerY } = calculateAnnotationMetricsInValues(activeAnnotation) ?? {};
|
|
26553
|
-
const { centerX: xValue, centerY: yValue } = calculateAnnotationMetricsInValuesInPixels(
|
|
26582
|
+
const { centerX: xValue, centerY: yValue } = calculateAnnotationMetricsInValuesInPixels(
|
|
26583
|
+
activeAnnotation,
|
|
26584
|
+
scales,
|
|
26585
|
+
xScaleID,
|
|
26586
|
+
yScaleID
|
|
26587
|
+
);
|
|
26554
26588
|
if (!isNil(centerX) && !isNil(centerY) && !isNil(xValue) && !isNil(yValue)) {
|
|
26555
26589
|
ctx.save();
|
|
26556
26590
|
ctx.clearRect(0, 0, width, height);
|
|
@@ -26660,7 +26694,7 @@ const annotationDraggerPlugin = {
|
|
|
26660
26694
|
const pluginOptions = ((_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.annotationDraggerPlugin) || {
|
|
26661
26695
|
enabled: false
|
|
26662
26696
|
};
|
|
26663
|
-
const typedScales = { x: scales.x, y: scales.y };
|
|
26697
|
+
const typedScales = { ...scales, x: scales.x, y: scales.y };
|
|
26664
26698
|
let annotations = ((_d2 = (_c2 = chart2.options.plugins) == null ? void 0 : _c2.annotation) == null ? void 0 : _d2.annotations) ?? {};
|
|
26665
26699
|
if (!chart2 && !annotations) return;
|
|
26666
26700
|
if (pluginOptions.enabled) {
|