@oliasoft-open-source/charts-library 4.2.0 → 4.3.0-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 +299 -18
- package/dist/index.js.map +1 -1
- package/dist/src/components/common/common.interface.d.ts +12 -0
- package/dist/src/components/common/helpers/get-chart-annotation.d.ts +8 -2
- package/dist/src/components/common/plugins/annotation-dragger-plugin/annotation-dragger-plugin.d.ts +14 -0
- package/dist/src/components/common/plugins/annotation-dragger-plugin/enums.d.ts +15 -0
- package/dist/src/components/common/plugins/annotation-dragger-plugin/event-helpers.d.ts +6 -0
- package/dist/src/components/common/plugins/annotation-dragger-plugin/helpers.d.ts +23 -0
- package/dist/src/components/line-chart/constants/default-translations.d.ts +1 -0
- package/dist/src/components/line-chart/controls/drag-options-interfaces.d.ts +4 -1
- package/dist/src/components/line-chart/controls/drag-options.d.ts +1 -1
- package/dist/src/components/line-chart/hooks/use-toggle-handler.d.ts +1 -0
- package/dist/src/components/line-chart/line-chart.stories.d.ts +93 -0
- package/dist/src/components/line-chart/state/action-types.d.ts +1 -0
- package/dist/src/components/line-chart/state/state.interfaces.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22080,6 +22080,7 @@ const SAVE_INITIAL_AXES_RANGES = "SAVE_INITIAL_AXES_RANGES";
|
|
|
22080
22080
|
const RESET_AXES_RANGES = "RESET_AXES_RANGES";
|
|
22081
22081
|
const UPDATE_AXES_RANGES = "UPDATE_AXES_RANGES";
|
|
22082
22082
|
const TOGGLE_DRAG_POINTS = "TOGGLE_DRAG_POINTS";
|
|
22083
|
+
const TOGGLE_DRAG_ANNOTATION = "TOGGLE_DRAG_ANNOTATION";
|
|
22083
22084
|
const DISABLE_DRAG_OPTIONS = "DISABLE_DRAG_OPTIONS";
|
|
22084
22085
|
const reducer$1 = (state, action) => {
|
|
22085
22086
|
return produce(state, (draft) => {
|
|
@@ -22148,6 +22149,16 @@ const reducer$1 = (state, action) => {
|
|
|
22148
22149
|
}
|
|
22149
22150
|
break;
|
|
22150
22151
|
}
|
|
22152
|
+
case TOGGLE_DRAG_ANNOTATION: {
|
|
22153
|
+
draft.enableDragAnnotation = !draft.enableDragAnnotation;
|
|
22154
|
+
if (draft.panEnabled) {
|
|
22155
|
+
draft.panEnabled = false;
|
|
22156
|
+
}
|
|
22157
|
+
if (draft.zoomEnabled) {
|
|
22158
|
+
draft.zoomEnabled = false;
|
|
22159
|
+
}
|
|
22160
|
+
break;
|
|
22161
|
+
}
|
|
22151
22162
|
case DISABLE_DRAG_OPTIONS: {
|
|
22152
22163
|
if (draft.enableDragPoints || draft.panEnabled || draft.zoomEnabled) {
|
|
22153
22164
|
draft.enableDragPoints = false;
|
|
@@ -22208,13 +22219,13 @@ var AlignOptions = /* @__PURE__ */ ((AlignOptions2) => {
|
|
|
22208
22219
|
AlignOptions2["Left"] = "left";
|
|
22209
22220
|
return AlignOptions2;
|
|
22210
22221
|
})(AlignOptions || {});
|
|
22211
|
-
var AnnotationType = /* @__PURE__ */ ((AnnotationType2) => {
|
|
22222
|
+
var AnnotationType$1 = /* @__PURE__ */ ((AnnotationType2) => {
|
|
22212
22223
|
AnnotationType2["Box"] = "box";
|
|
22213
22224
|
AnnotationType2["Ellipse"] = "ellipse";
|
|
22214
22225
|
AnnotationType2["Line"] = "line";
|
|
22215
22226
|
AnnotationType2["Text"] = "text";
|
|
22216
22227
|
return AnnotationType2;
|
|
22217
|
-
})(AnnotationType || {});
|
|
22228
|
+
})(AnnotationType$1 || {});
|
|
22218
22229
|
var PointStyle = /* @__PURE__ */ ((PointStyle2) => {
|
|
22219
22230
|
PointStyle2["Circle"] = "circle";
|
|
22220
22231
|
return PointStyle2;
|
|
@@ -22567,7 +22578,8 @@ const initialState = ({ options, persistenceId }) => {
|
|
|
22567
22578
|
axes,
|
|
22568
22579
|
chartOptions: { enableZoom, enablePan, showPoints, showLine },
|
|
22569
22580
|
legend: { display },
|
|
22570
|
-
dragData
|
|
22581
|
+
dragData,
|
|
22582
|
+
annotations: { enableDragAnnotation }
|
|
22571
22583
|
} = options;
|
|
22572
22584
|
const getStateAxesByType = (axisType, customAxesRange2) => {
|
|
22573
22585
|
var _a2, _b2, _c2, _d2, _e2;
|
|
@@ -22614,7 +22626,8 @@ const initialState = ({ options, persistenceId }) => {
|
|
|
22614
22626
|
pointsEnabled,
|
|
22615
22627
|
lineEnabled,
|
|
22616
22628
|
legendEnabled,
|
|
22617
|
-
enableDragPoints
|
|
22629
|
+
enableDragPoints,
|
|
22630
|
+
enableDragAnnotation: enableDragAnnotationStorage
|
|
22618
22631
|
} = getChartStateFromStorage(persistenceId) || {};
|
|
22619
22632
|
return {
|
|
22620
22633
|
zoomEnabled: zoomEnabled ?? enableZoom,
|
|
@@ -22625,6 +22638,7 @@ const initialState = ({ options, persistenceId }) => {
|
|
|
22625
22638
|
axes: stateAxes,
|
|
22626
22639
|
showTable: false,
|
|
22627
22640
|
enableDragPoints: (dragData == null ? void 0 : dragData.enableDragData) && enableDragPoints,
|
|
22641
|
+
enableDragAnnotation: enableDragAnnotation && enableDragAnnotationStorage,
|
|
22628
22642
|
initialAxesRanges: []
|
|
22629
22643
|
};
|
|
22630
22644
|
};
|
|
@@ -22784,7 +22798,10 @@ const DragOptions = ({
|
|
|
22784
22798
|
panEnabled,
|
|
22785
22799
|
zoomEnabled,
|
|
22786
22800
|
enableDragPoints,
|
|
22801
|
+
enableDragAnnotation,
|
|
22787
22802
|
isDragDataAllowed,
|
|
22803
|
+
isDragAnnotationAllowed,
|
|
22804
|
+
onToggleDragAnnotation,
|
|
22788
22805
|
onToggleDragPoints,
|
|
22789
22806
|
onDisableDragOptions,
|
|
22790
22807
|
translations: {
|
|
@@ -22793,7 +22810,8 @@ const DragOptions = ({
|
|
|
22793
22810
|
dragToPan,
|
|
22794
22811
|
orDoubleClickToCanvas,
|
|
22795
22812
|
dragToMovePoints,
|
|
22796
|
-
dragDisabled
|
|
22813
|
+
dragDisabled,
|
|
22814
|
+
dragToMoveAnnotation
|
|
22797
22815
|
}
|
|
22798
22816
|
}) => {
|
|
22799
22817
|
const options = useMemo(
|
|
@@ -22827,10 +22845,19 @@ const DragOptions = ({
|
|
|
22827
22845
|
onClick: onToggleDragPoints
|
|
22828
22846
|
}
|
|
22829
22847
|
] : [],
|
|
22848
|
+
...isDragAnnotationAllowed ? [
|
|
22849
|
+
{
|
|
22850
|
+
label: dragToMoveAnnotation,
|
|
22851
|
+
icon: /* @__PURE__ */ jsx(TbHandStop, {}),
|
|
22852
|
+
selected: enableDragAnnotation,
|
|
22853
|
+
type: "Option",
|
|
22854
|
+
onClick: onToggleDragAnnotation
|
|
22855
|
+
}
|
|
22856
|
+
] : [],
|
|
22830
22857
|
{
|
|
22831
22858
|
label: dragDisabled,
|
|
22832
22859
|
icon: /* @__PURE__ */ jsx(TbBan, {}),
|
|
22833
|
-
selected: !zoomEnabled && !panEnabled && !enableDragPoints,
|
|
22860
|
+
selected: !zoomEnabled && !panEnabled && !enableDragPoints && !enableDragAnnotation,
|
|
22834
22861
|
onClick: onDisableDragOptions
|
|
22835
22862
|
}
|
|
22836
22863
|
],
|
|
@@ -22887,6 +22914,7 @@ const useToggleHandlers = (dispatch) => {
|
|
|
22887
22914
|
onToggleTable: createToggleHandler(TOGGLE_TABLE),
|
|
22888
22915
|
onToggleZoom: createToggleHandler(TOGGLE_ZOOM),
|
|
22889
22916
|
onToggleDragPoints: createToggleHandler(TOGGLE_DRAG_POINTS),
|
|
22917
|
+
onToggleDragAnnotation: createToggleHandler(TOGGLE_DRAG_ANNOTATION),
|
|
22890
22918
|
onDisableDragOptions: createToggleHandler(DISABLE_DRAG_OPTIONS)
|
|
22891
22919
|
};
|
|
22892
22920
|
return toggleHandlers;
|
|
@@ -24307,9 +24335,10 @@ const Controls = ({
|
|
|
24307
24335
|
panEnabled,
|
|
24308
24336
|
pointsEnabled,
|
|
24309
24337
|
showTable,
|
|
24310
|
-
zoomEnabled
|
|
24338
|
+
zoomEnabled,
|
|
24339
|
+
enableDragAnnotation
|
|
24311
24340
|
} = state;
|
|
24312
|
-
const { dragData, depthType } = options;
|
|
24341
|
+
const { dragData, depthType, annotations } = options;
|
|
24313
24342
|
const {
|
|
24314
24343
|
onToggleLine,
|
|
24315
24344
|
onTogglePan,
|
|
@@ -24317,6 +24346,7 @@ const Controls = ({
|
|
|
24317
24346
|
onToggleTable,
|
|
24318
24347
|
onToggleZoom,
|
|
24319
24348
|
onToggleDragPoints,
|
|
24349
|
+
onToggleDragAnnotation,
|
|
24320
24350
|
onDisableDragOptions
|
|
24321
24351
|
} = useToggleHandlers(dispatch);
|
|
24322
24352
|
const { handleDownload, controlsAxesLabels, onResetAxes, onUpdateAxes } = useChartFunctions({
|
|
@@ -24380,7 +24410,10 @@ const Controls = ({
|
|
|
24380
24410
|
onTogglePan,
|
|
24381
24411
|
onToggleZoom,
|
|
24382
24412
|
enableDragPoints,
|
|
24413
|
+
enableDragAnnotation,
|
|
24383
24414
|
isDragDataAllowed: dragData == null ? void 0 : dragData.enableDragData,
|
|
24415
|
+
isDragAnnotationAllowed: annotations == null ? void 0 : annotations.enableDragAnnotation,
|
|
24416
|
+
onToggleDragAnnotation,
|
|
24384
24417
|
onToggleDragPoints,
|
|
24385
24418
|
onDisableDragOptions,
|
|
24386
24419
|
translations
|
|
@@ -24490,6 +24523,7 @@ const defaultAnnotations$1 = (annotations) => {
|
|
|
24490
24523
|
},
|
|
24491
24524
|
showAnnotations: (annotations == null ? void 0 : annotations.showAnnotations) ?? false,
|
|
24492
24525
|
controlAnnotation: (annotations == null ? void 0 : annotations.controlAnnotation) ?? false,
|
|
24526
|
+
enableDragAnnotation: (annotations == null ? void 0 : annotations.enableDragAnnotation) ?? false,
|
|
24493
24527
|
annotationsData: defaultAnnotationsData$1(annotations == null ? void 0 : annotations.annotationsData)
|
|
24494
24528
|
};
|
|
24495
24529
|
};
|
|
@@ -25140,6 +25174,19 @@ const legendReducer = (state, action) => {
|
|
|
25140
25174
|
return state;
|
|
25141
25175
|
}
|
|
25142
25176
|
};
|
|
25177
|
+
var MouseEvents = /* @__PURE__ */ ((MouseEvents2) => {
|
|
25178
|
+
MouseEvents2["MOUSEDOWN"] = "mousedown";
|
|
25179
|
+
MouseEvents2["MOUSEMOVE"] = "mousemove";
|
|
25180
|
+
MouseEvents2["MOUSEUP"] = "mouseup";
|
|
25181
|
+
return MouseEvents2;
|
|
25182
|
+
})(MouseEvents || {});
|
|
25183
|
+
var AnnotationType = /* @__PURE__ */ ((AnnotationType2) => {
|
|
25184
|
+
AnnotationType2["POINT"] = "point";
|
|
25185
|
+
AnnotationType2["BOX"] = "box";
|
|
25186
|
+
AnnotationType2["LINE"] = "line";
|
|
25187
|
+
AnnotationType2["ELLIPSE"] = "ellipse";
|
|
25188
|
+
return AnnotationType2;
|
|
25189
|
+
})(AnnotationType || {});
|
|
25143
25190
|
const annotationEnter = (element, chart2) => {
|
|
25144
25191
|
var _a2;
|
|
25145
25192
|
if ((_a2 = element.options.scaleID) == null ? void 0 : _a2.includes(AxisType.X)) {
|
|
@@ -25172,9 +25219,13 @@ const generateAnnotations = (annotationsData) => {
|
|
|
25172
25219
|
const color2 = (ann == null ? void 0 : ann.color) || COLORS[idx];
|
|
25173
25220
|
const type = (ann == null ? void 0 : ann.type) || "line";
|
|
25174
25221
|
const adjustScaleRange2 = ann == null ? void 0 : ann.adjustScaleRange;
|
|
25175
|
-
const borderColor =
|
|
25176
|
-
|
|
25177
|
-
|
|
25222
|
+
const borderColor = {
|
|
25223
|
+
[AnnotationType.LINE]: color2,
|
|
25224
|
+
[AnnotationType.POINT]: color2,
|
|
25225
|
+
[AnnotationType.BOX]: color2
|
|
25226
|
+
}[type] || "transparent";
|
|
25227
|
+
const borderWidth = type == "line" ? BORDER_WIDTH.INITIAL : 0;
|
|
25228
|
+
const borderDash = type == "line" ? ANNOTATION_DASH : void 0;
|
|
25178
25229
|
const label = type === "line" ? {
|
|
25179
25230
|
backgroundColor: color2,
|
|
25180
25231
|
content: ann == null ? void 0 : ann.label,
|
|
@@ -25190,7 +25241,7 @@ const generateAnnotations = (annotationsData) => {
|
|
|
25190
25241
|
}, {
|
|
25191
25242
|
chart: chart2
|
|
25192
25243
|
}) => {
|
|
25193
|
-
if (type !== "line")
|
|
25244
|
+
if (type !== "line" && !ann.enableDrag)
|
|
25194
25245
|
return;
|
|
25195
25246
|
annotationEnter(element, chart2);
|
|
25196
25247
|
};
|
|
@@ -25199,10 +25250,13 @@ const generateAnnotations = (annotationsData) => {
|
|
|
25199
25250
|
}, {
|
|
25200
25251
|
chart: chart2
|
|
25201
25252
|
}) => {
|
|
25202
|
-
if (type !== "line")
|
|
25253
|
+
if (type !== "line" && !ann.enableDrag)
|
|
25203
25254
|
return;
|
|
25204
25255
|
annotationLeave(element, chart2);
|
|
25205
25256
|
};
|
|
25257
|
+
const onDragStart = () => (cord) => (ann == null ? void 0 : ann.onDragStart) ? ann == null ? void 0 : ann.onDragStart(cord) : void 0;
|
|
25258
|
+
const onDrag = () => (cord) => (ann == null ? void 0 : ann.onDrag) ? ann == null ? void 0 : ann.onDrag(cord) : void 0;
|
|
25259
|
+
const onDragEnd = () => (cord) => (ann == null ? void 0 : ann.onDragEnd) ? ann == null ? void 0 : ann.onDragEnd(cord) : void 0;
|
|
25206
25260
|
return {
|
|
25207
25261
|
...ann,
|
|
25208
25262
|
display: ann == null ? void 0 : ann.display,
|
|
@@ -25217,7 +25271,10 @@ const generateAnnotations = (annotationsData) => {
|
|
|
25217
25271
|
type,
|
|
25218
25272
|
adjustScaleRange: adjustScaleRange2,
|
|
25219
25273
|
enter,
|
|
25220
|
-
leave
|
|
25274
|
+
leave,
|
|
25275
|
+
onDragStart,
|
|
25276
|
+
onDrag,
|
|
25277
|
+
onDragEnd
|
|
25221
25278
|
};
|
|
25222
25279
|
});
|
|
25223
25280
|
};
|
|
@@ -25413,6 +25470,9 @@ const useChartOptions = ({
|
|
|
25413
25470
|
);
|
|
25414
25471
|
const plugins = {
|
|
25415
25472
|
datalabels,
|
|
25473
|
+
annotationDraggerPlugin: {
|
|
25474
|
+
enabled: state.enableDragAnnotation
|
|
25475
|
+
},
|
|
25416
25476
|
annotation: toAnnotationObject(annotation2),
|
|
25417
25477
|
zoom: { pan: panOptions, zoom: zoomOptions },
|
|
25418
25478
|
tooltip,
|
|
@@ -25769,6 +25829,224 @@ const chartAreaTextPlugin = {
|
|
|
25769
25829
|
});
|
|
25770
25830
|
}
|
|
25771
25831
|
};
|
|
25832
|
+
const getMousePositionInCoordinates = (event, canvas2, scales) => {
|
|
25833
|
+
var _a2, _b2;
|
|
25834
|
+
const rect = canvas2.getBoundingClientRect();
|
|
25835
|
+
const x2 = event.clientX - rect.left;
|
|
25836
|
+
const y2 = event.clientY - rect.top;
|
|
25837
|
+
const xValue = ((_a2 = scales == null ? void 0 : scales.x) == null ? void 0 : _a2.getValueForPixel(x2)) ?? -1;
|
|
25838
|
+
const yValue = ((_b2 = scales == null ? void 0 : scales.y) == null ? void 0 : _b2.getValueForPixel(y2)) ?? -1;
|
|
25839
|
+
return { x: xValue, y: yValue };
|
|
25840
|
+
};
|
|
25841
|
+
const getActiveAnnotation = (x2, y2, annotations) => {
|
|
25842
|
+
var _a2;
|
|
25843
|
+
return ((_a2 = Object.values(annotations)) == null ? void 0 : _a2.find((annotation2) => {
|
|
25844
|
+
const { xMin, xMax, yMin, yMax, xValue, yValue } = annotation2 ?? {};
|
|
25845
|
+
let condtion;
|
|
25846
|
+
if (xMin && xMax && yMin && yMax && (annotation2 == null ? void 0 : annotation2.type) === AnnotationType.BOX) {
|
|
25847
|
+
condtion = x2 >= xMin && x2 <= xMax && y2 >= yMin && y2 <= yMax;
|
|
25848
|
+
} else if (xValue && yValue && (annotation2 == null ? void 0 : annotation2.type) === AnnotationType.POINT) {
|
|
25849
|
+
condtion = x2 >= xValue - 2 && x2 <= xValue + 2 && y2 >= yValue - 2 && y2 <= yValue + 2;
|
|
25850
|
+
}
|
|
25851
|
+
return condtion;
|
|
25852
|
+
})) ?? {};
|
|
25853
|
+
};
|
|
25854
|
+
const calculateAnnotationMetricsInValues = (annotation2) => {
|
|
25855
|
+
const { xMin, xMax, yMin, yMax, xValue, yValue, type } = annotation2 ?? {};
|
|
25856
|
+
let centerX;
|
|
25857
|
+
let centerY;
|
|
25858
|
+
let width;
|
|
25859
|
+
let height;
|
|
25860
|
+
if (xMin && xMax && yMin && yMax && type === AnnotationType.BOX) {
|
|
25861
|
+
centerX = (xMin + xMax) / 2;
|
|
25862
|
+
centerY = (yMin + yMax) / 2;
|
|
25863
|
+
width = xMax - xMin;
|
|
25864
|
+
height = yMax - yMin;
|
|
25865
|
+
} else if (xValue && yValue && type === AnnotationType.POINT) {
|
|
25866
|
+
centerX = xValue;
|
|
25867
|
+
centerY = yValue;
|
|
25868
|
+
width = 0;
|
|
25869
|
+
height = 0;
|
|
25870
|
+
}
|
|
25871
|
+
return {
|
|
25872
|
+
centerX,
|
|
25873
|
+
centerY,
|
|
25874
|
+
width,
|
|
25875
|
+
height
|
|
25876
|
+
};
|
|
25877
|
+
};
|
|
25878
|
+
const calculateAnnotationMetricsInValuesInPixels = (annotation2, scales) => {
|
|
25879
|
+
var _a2, _b2, _c2, _d2;
|
|
25880
|
+
const { xMin, xMax, yMin, yMax, xValue, yValue, type } = annotation2 ?? {};
|
|
25881
|
+
const { x: x2, y: y2 } = scales ?? {};
|
|
25882
|
+
let centerX;
|
|
25883
|
+
let centerY;
|
|
25884
|
+
let width;
|
|
25885
|
+
let height;
|
|
25886
|
+
if (xMin && xMax && yMin && yMax && type === AnnotationType.BOX) {
|
|
25887
|
+
const xCenterValue = (xMin + xMax) / 2;
|
|
25888
|
+
const yCenterValue = (yMin + yMax) / 2;
|
|
25889
|
+
const xMinValue = (x2 == null ? void 0 : x2.getPixelForValue(xMin)) ?? 0;
|
|
25890
|
+
const xMaxValue = (x2 == null ? void 0 : x2.getPixelForValue(xMax)) ?? 0;
|
|
25891
|
+
const yMinValue = (y2 == null ? void 0 : y2.getPixelForValue(yMin)) ?? 0;
|
|
25892
|
+
const yMaxValue = (y2 == null ? void 0 : y2.getPixelForValue(yMax)) ?? 0;
|
|
25893
|
+
width = xMinValue - xMaxValue;
|
|
25894
|
+
height = yMinValue - yMaxValue;
|
|
25895
|
+
centerX = ((_a2 = scales == null ? void 0 : scales.x) == null ? void 0 : _a2.getPixelForValue(xCenterValue)) ?? -1;
|
|
25896
|
+
centerY = ((_b2 = scales == null ? void 0 : scales.y) == null ? void 0 : _b2.getPixelForValue(yCenterValue)) ?? -1;
|
|
25897
|
+
} else if (xValue && yValue && type === AnnotationType.POINT) {
|
|
25898
|
+
width = 0;
|
|
25899
|
+
height = 0;
|
|
25900
|
+
centerX = ((_c2 = scales == null ? void 0 : scales.x) == null ? void 0 : _c2.getPixelForValue(xValue)) ?? -1;
|
|
25901
|
+
centerY = ((_d2 = scales == null ? void 0 : scales.y) == null ? void 0 : _d2.getPixelForValue(yValue)) ?? -1;
|
|
25902
|
+
}
|
|
25903
|
+
return {
|
|
25904
|
+
centerX,
|
|
25905
|
+
centerY,
|
|
25906
|
+
width,
|
|
25907
|
+
height
|
|
25908
|
+
};
|
|
25909
|
+
};
|
|
25910
|
+
const handleAnnotationMouseDown = (event, canvas2, scales, annotations, setDraggingState) => {
|
|
25911
|
+
const { x: x2, y: y2 } = getMousePositionInCoordinates(event, canvas2, scales);
|
|
25912
|
+
const annotation2 = getActiveAnnotation(x2, y2, annotations);
|
|
25913
|
+
const metrics = calculateAnnotationMetricsInValues(annotation2);
|
|
25914
|
+
console.log(cloneDeep(annotations));
|
|
25915
|
+
console.log(metrics);
|
|
25916
|
+
if (annotation2 && annotation2.enableDrag && metrics.centerY && metrics.centerX) {
|
|
25917
|
+
const dragStartX = x2 - metrics.centerX;
|
|
25918
|
+
const dragStartY = y2 - metrics.centerY;
|
|
25919
|
+
setDraggingState(true, annotation2, dragStartX, dragStartY);
|
|
25920
|
+
if (annotation2 == null ? void 0 : annotation2.onDragStart) {
|
|
25921
|
+
annotation2.onDragStart({ x: x2, y: y2 });
|
|
25922
|
+
}
|
|
25923
|
+
}
|
|
25924
|
+
};
|
|
25925
|
+
const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAnnotation, dragStartX, dragStartY, chart2) => {
|
|
25926
|
+
if (isDragging2 && activeAnnotation) {
|
|
25927
|
+
const { x: x2, y: y2 } = getMousePositionInCoordinates(event, canvas2, scales);
|
|
25928
|
+
const metrics = calculateAnnotationMetricsInValues(activeAnnotation);
|
|
25929
|
+
let newCenterX = x2 - dragStartX;
|
|
25930
|
+
let newCenterY = y2 - dragStartY;
|
|
25931
|
+
if ((activeAnnotation == null ? void 0 : activeAnnotation.type) === AnnotationType.POINT) {
|
|
25932
|
+
newCenterX = x2 - dragStartX;
|
|
25933
|
+
newCenterY = y2 - dragStartY;
|
|
25934
|
+
activeAnnotation.xValue = newCenterX;
|
|
25935
|
+
activeAnnotation.yValue = newCenterY;
|
|
25936
|
+
} else if ((activeAnnotation == null ? void 0 : activeAnnotation.type) === AnnotationType.BOX) {
|
|
25937
|
+
if ((metrics == null ? void 0 : metrics.width) && metrics.height) {
|
|
25938
|
+
activeAnnotation.xMin = newCenterX - metrics.width / 2;
|
|
25939
|
+
activeAnnotation.xMax = newCenterX + metrics.width / 2;
|
|
25940
|
+
activeAnnotation.yMin = newCenterY - metrics.height / 2;
|
|
25941
|
+
activeAnnotation.yMax = newCenterY + metrics.height / 2;
|
|
25942
|
+
}
|
|
25943
|
+
}
|
|
25944
|
+
chart2.update();
|
|
25945
|
+
if (activeAnnotation == null ? void 0 : activeAnnotation.onDrag) {
|
|
25946
|
+
activeAnnotation.onDrag({ x: x2, y: y2 });
|
|
25947
|
+
}
|
|
25948
|
+
const { ctx, width, height } = chart2;
|
|
25949
|
+
const { centerX, centerY } = calculateAnnotationMetricsInValues(activeAnnotation) ?? {};
|
|
25950
|
+
const { centerX: xValue, centerY: yValue } = calculateAnnotationMetricsInValuesInPixels(activeAnnotation, scales);
|
|
25951
|
+
if (centerX && centerY && xValue && yValue) {
|
|
25952
|
+
ctx.save();
|
|
25953
|
+
ctx.clearRect(0, 0, width, height);
|
|
25954
|
+
chart2.draw();
|
|
25955
|
+
ctx.font = DEFAULT_FONT_FAMILY;
|
|
25956
|
+
ctx.fillStyle = "black";
|
|
25957
|
+
let labelX = xValue - 45;
|
|
25958
|
+
let labelY = yValue - 20;
|
|
25959
|
+
const labelText = `X: ${round$2(centerX, 2)}, Y: ${round$2(centerY, 2)}`;
|
|
25960
|
+
const labelHeight = 14;
|
|
25961
|
+
if (labelY - labelHeight < 0) {
|
|
25962
|
+
labelY = yValue + labelHeight + 15;
|
|
25963
|
+
}
|
|
25964
|
+
if (labelY > height) {
|
|
25965
|
+
labelY = height - 7;
|
|
25966
|
+
}
|
|
25967
|
+
ctx.fillText(labelText, labelX, labelY);
|
|
25968
|
+
ctx.restore();
|
|
25969
|
+
}
|
|
25970
|
+
}
|
|
25971
|
+
};
|
|
25972
|
+
const handleAnnotationMouseUp = (isDragging2, activeAnnotation, chart2, setDraggingState) => {
|
|
25973
|
+
if (isDragging2) {
|
|
25974
|
+
if (activeAnnotation) {
|
|
25975
|
+
const { centerX = -1, centerY = -1 } = calculateAnnotationMetricsInValues(activeAnnotation) ?? {};
|
|
25976
|
+
if (activeAnnotation == null ? void 0 : activeAnnotation.onDragEnd) {
|
|
25977
|
+
activeAnnotation.onDragEnd({ x: centerX, y: centerY });
|
|
25978
|
+
}
|
|
25979
|
+
setDraggingState(false, null);
|
|
25980
|
+
}
|
|
25981
|
+
chart2.update();
|
|
25982
|
+
}
|
|
25983
|
+
};
|
|
25984
|
+
const annotationDraggerPlugin = {
|
|
25985
|
+
id: "annotationDraggerPlugin",
|
|
25986
|
+
afterUpdate(chart2) {
|
|
25987
|
+
var _a2, _b2, _c2, _d2;
|
|
25988
|
+
const { canvas: canvas2, scales } = chart2;
|
|
25989
|
+
const pluginOptions = ((_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.annotationDraggerPlugin) || {
|
|
25990
|
+
enabled: false
|
|
25991
|
+
};
|
|
25992
|
+
const typedScales = { x: scales.x, y: scales.y };
|
|
25993
|
+
let annotations = ((_d2 = (_c2 = chart2.options.plugins) == null ? void 0 : _c2.annotation) == null ? void 0 : _d2.annotations) ?? {};
|
|
25994
|
+
if (!annotations)
|
|
25995
|
+
return;
|
|
25996
|
+
let isDragging2 = false;
|
|
25997
|
+
let dragStartX, dragStartY;
|
|
25998
|
+
let activeAnnotation = null;
|
|
25999
|
+
const setDraggingState = (dragging, annotation2, startX, startY) => {
|
|
26000
|
+
isDragging2 = dragging;
|
|
26001
|
+
activeAnnotation = annotation2;
|
|
26002
|
+
if (startX !== void 0 && startY !== void 0) {
|
|
26003
|
+
dragStartX = startX;
|
|
26004
|
+
dragStartY = startY;
|
|
26005
|
+
}
|
|
26006
|
+
};
|
|
26007
|
+
if (!canvas2.dataset.annotationDraggerInitialized && pluginOptions.enabled) {
|
|
26008
|
+
canvas2.addEventListener(MouseEvents.MOUSEDOWN, (event) => {
|
|
26009
|
+
handleAnnotationMouseDown(
|
|
26010
|
+
event,
|
|
26011
|
+
canvas2,
|
|
26012
|
+
typedScales,
|
|
26013
|
+
annotations,
|
|
26014
|
+
setDraggingState
|
|
26015
|
+
);
|
|
26016
|
+
});
|
|
26017
|
+
canvas2.addEventListener(MouseEvents.MOUSEMOVE, (event) => {
|
|
26018
|
+
handleAnnotationMouseMove(
|
|
26019
|
+
event,
|
|
26020
|
+
canvas2,
|
|
26021
|
+
typedScales,
|
|
26022
|
+
isDragging2,
|
|
26023
|
+
activeAnnotation,
|
|
26024
|
+
dragStartX,
|
|
26025
|
+
dragStartY,
|
|
26026
|
+
chart2
|
|
26027
|
+
);
|
|
26028
|
+
});
|
|
26029
|
+
canvas2.addEventListener(MouseEvents.MOUSEUP, () => {
|
|
26030
|
+
handleAnnotationMouseUp(
|
|
26031
|
+
isDragging2,
|
|
26032
|
+
activeAnnotation,
|
|
26033
|
+
chart2,
|
|
26034
|
+
setDraggingState
|
|
26035
|
+
);
|
|
26036
|
+
});
|
|
26037
|
+
canvas2.dataset.annotationDraggerInitialized = "true";
|
|
26038
|
+
}
|
|
26039
|
+
if (!pluginOptions.enabled) {
|
|
26040
|
+
canvas2.removeEventListener(MouseEvents.MOUSEDOWN, () => {
|
|
26041
|
+
});
|
|
26042
|
+
canvas2.removeEventListener(MouseEvents.MOUSEMOVE, () => {
|
|
26043
|
+
});
|
|
26044
|
+
canvas2.removeEventListener(MouseEvents.MOUSEUP, () => {
|
|
26045
|
+
});
|
|
26046
|
+
canvas2.dataset.annotationDraggerInitialized = "";
|
|
26047
|
+
}
|
|
26048
|
+
}
|
|
26049
|
+
};
|
|
25772
26050
|
var defaultTranslations = /* @__PURE__ */ ((defaultTranslations2) => {
|
|
25773
26051
|
defaultTranslations2["label"] = "Label";
|
|
25774
26052
|
defaultTranslations2["pointsLines"] = "Points & lines";
|
|
@@ -25783,6 +26061,7 @@ var defaultTranslations = /* @__PURE__ */ ((defaultTranslations2) => {
|
|
|
25783
26061
|
defaultTranslations2["dragToZoom"] = "Drag to zoom";
|
|
25784
26062
|
defaultTranslations2["dragToPan"] = "Drag to pan";
|
|
25785
26063
|
defaultTranslations2["dragToMovePoints"] = "Drag to move points";
|
|
26064
|
+
defaultTranslations2["dragToMoveAnnotation"] = "Drag to move annotation";
|
|
25786
26065
|
defaultTranslations2["dragDisabled"] = "Drag disabled";
|
|
25787
26066
|
defaultTranslations2["hideLegend"] = "Hide Legend";
|
|
25788
26067
|
defaultTranslations2["showLegend"] = "Show Legend";
|
|
@@ -25960,10 +26239,10 @@ const BoxItem = ({ dataset }) => {
|
|
|
25960
26239
|
const LegendItemLine = ({ dataset }) => {
|
|
25961
26240
|
const { annotationType, showLine } = dataset;
|
|
25962
26241
|
switch (annotationType) {
|
|
25963
|
-
case AnnotationType.Box:
|
|
25964
|
-
case AnnotationType.Ellipse:
|
|
26242
|
+
case AnnotationType$1.Box:
|
|
26243
|
+
case AnnotationType$1.Ellipse:
|
|
25965
26244
|
return /* @__PURE__ */ jsx(BoxItem, { dataset });
|
|
25966
|
-
case AnnotationType.Line:
|
|
26245
|
+
case AnnotationType$1.Line:
|
|
25967
26246
|
return /* @__PURE__ */ jsx(LineItem, { dataset });
|
|
25968
26247
|
default:
|
|
25969
26248
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -26261,7 +26540,8 @@ Chart$2.register(
|
|
|
26261
26540
|
plugin$1,
|
|
26262
26541
|
plugin,
|
|
26263
26542
|
annotation,
|
|
26264
|
-
chartAreaTextPlugin
|
|
26543
|
+
chartAreaTextPlugin,
|
|
26544
|
+
annotationDraggerPlugin
|
|
26265
26545
|
);
|
|
26266
26546
|
const LineChart = (props) => {
|
|
26267
26547
|
var _a2, _b2;
|
|
@@ -26367,6 +26647,7 @@ const LineChart = (props) => {
|
|
|
26367
26647
|
},
|
|
26368
26648
|
generateKey([
|
|
26369
26649
|
state.enableDragPoints,
|
|
26650
|
+
state.enableDragAnnotation,
|
|
26370
26651
|
state.zoomEnabled,
|
|
26371
26652
|
state.panEnabled,
|
|
26372
26653
|
languageKey
|