@oliasoft-open-source/charts-library 4.1.11 → 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 +310 -25
- package/dist/index.js.map +1 -1
- package/dist/src/components/common/common.interface.d.ts +13 -1
- package/dist/src/components/common/enums.d.ts +6 -1
- package/dist/src/components/common/helpers/custom-format-number.d.ts +1 -0
- package/dist/src/components/common/helpers/get-chart-annotation.d.ts +8 -2
- package/dist/src/components/common/legend-component/legend-interface.d.ts +4 -3
- 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/dist/src/components/pie-chart/pie-chart-defalut-props.interface.d.ts +1 -1
- package/dist/src/components/pie-chart/pie-chart.interface.d.ts +2 -2
- package/dist/src/components/pie-chart/use-pie-chart-config.d.ts +1 -1
- package/dist/src/components/scatter-chart/scatter-chart-default-props.interface.d.ts +69 -0
- package/dist/src/components/scatter-chart/scatter-chart-get-default-props.d.ts +3 -0
- package/dist/src/components/scatter-chart/scatter-chart.d.ts +3 -0
- package/dist/src/components/scatter-chart/scatter-chart.interface.d.ts +80 -0
- package/dist/src/components/scatter-chart/scatter-chart.stories.d.ts +205 -0
- package/dist/src/components/scatter-chart/utils/get-scales-config.d.ts +49 -0
- package/dist/src/components/scatter-chart/utils/get-tooltip-config.d.ts +20 -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
|
};
|
|
@@ -22757,6 +22771,9 @@ function TbArrowsMove(props) {
|
|
|
22757
22771
|
function TbBan(props) {
|
|
22758
22772
|
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24", "strokeWidth": "2", "stroke": "currentColor", "fill": "none", "strokeLinecap": "round", "strokeLinejoin": "round" }, "child": [{ "tag": "path", "attr": { "stroke": "none", "d": "M0 0h24v24H0z", "fill": "none" } }, { "tag": "path", "attr": { "d": "M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" } }, { "tag": "path", "attr": { "d": "M5.7 5.7l12.6 12.6" } }] })(props);
|
|
22759
22773
|
}
|
|
22774
|
+
function TbCircleFilled(props) {
|
|
22775
|
+
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24", "strokeWidth": "2", "stroke": "currentColor", "fill": "none", "strokeLinecap": "round", "strokeLinejoin": "round" }, "child": [{ "tag": "path", "attr": { "stroke": "none", "d": "M0 0h24v24H0z", "fill": "none" } }, { "tag": "path", "attr": { "d": "M7 3.34a10 10 0 1 1 -4.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 4.995 -8.336z", "strokeWidth": "0", "fill": "currentColor" } }] })(props);
|
|
22776
|
+
}
|
|
22760
22777
|
function TbHandStop(props) {
|
|
22761
22778
|
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24", "strokeWidth": "2", "stroke": "currentColor", "fill": "none", "strokeLinecap": "round", "strokeLinejoin": "round" }, "child": [{ "tag": "path", "attr": { "stroke": "none", "d": "M0 0h24v24H0z", "fill": "none" } }, { "tag": "path", "attr": { "d": "M8 13v-7.5a1.5 1.5 0 0 1 3 0v6.5" } }, { "tag": "path", "attr": { "d": "M11 5.5v-2a1.5 1.5 0 1 1 3 0v8.5" } }, { "tag": "path", "attr": { "d": "M14 5.5a1.5 1.5 0 0 1 3 0v6.5" } }, { "tag": "path", "attr": { "d": "M17 7.5a1.5 1.5 0 0 1 3 0v8.5a6 6 0 0 1 -6 6h-2h.208a6 6 0 0 1 -5.012 -2.7a69.74 69.74 0 0 1 -.196 -.3c-.312 -.479 -1.407 -2.388 -3.286 -5.728a1.5 1.5 0 0 1 .536 -2.022a1.867 1.867 0 0 1 2.28 .28l1.47 1.47" } }] })(props);
|
|
22762
22779
|
}
|
|
@@ -22781,7 +22798,10 @@ const DragOptions = ({
|
|
|
22781
22798
|
panEnabled,
|
|
22782
22799
|
zoomEnabled,
|
|
22783
22800
|
enableDragPoints,
|
|
22801
|
+
enableDragAnnotation,
|
|
22784
22802
|
isDragDataAllowed,
|
|
22803
|
+
isDragAnnotationAllowed,
|
|
22804
|
+
onToggleDragAnnotation,
|
|
22785
22805
|
onToggleDragPoints,
|
|
22786
22806
|
onDisableDragOptions,
|
|
22787
22807
|
translations: {
|
|
@@ -22790,7 +22810,8 @@ const DragOptions = ({
|
|
|
22790
22810
|
dragToPan,
|
|
22791
22811
|
orDoubleClickToCanvas,
|
|
22792
22812
|
dragToMovePoints,
|
|
22793
|
-
dragDisabled
|
|
22813
|
+
dragDisabled,
|
|
22814
|
+
dragToMoveAnnotation
|
|
22794
22815
|
}
|
|
22795
22816
|
}) => {
|
|
22796
22817
|
const options = useMemo(
|
|
@@ -22824,10 +22845,19 @@ const DragOptions = ({
|
|
|
22824
22845
|
onClick: onToggleDragPoints
|
|
22825
22846
|
}
|
|
22826
22847
|
] : [],
|
|
22848
|
+
...isDragAnnotationAllowed ? [
|
|
22849
|
+
{
|
|
22850
|
+
label: dragToMoveAnnotation,
|
|
22851
|
+
icon: /* @__PURE__ */ jsx(TbHandStop, {}),
|
|
22852
|
+
selected: enableDragAnnotation,
|
|
22853
|
+
type: "Option",
|
|
22854
|
+
onClick: onToggleDragAnnotation
|
|
22855
|
+
}
|
|
22856
|
+
] : [],
|
|
22827
22857
|
{
|
|
22828
22858
|
label: dragDisabled,
|
|
22829
22859
|
icon: /* @__PURE__ */ jsx(TbBan, {}),
|
|
22830
|
-
selected: !zoomEnabled && !panEnabled && !enableDragPoints,
|
|
22860
|
+
selected: !zoomEnabled && !panEnabled && !enableDragPoints && !enableDragAnnotation,
|
|
22831
22861
|
onClick: onDisableDragOptions
|
|
22832
22862
|
}
|
|
22833
22863
|
],
|
|
@@ -22884,6 +22914,7 @@ const useToggleHandlers = (dispatch) => {
|
|
|
22884
22914
|
onToggleTable: createToggleHandler(TOGGLE_TABLE),
|
|
22885
22915
|
onToggleZoom: createToggleHandler(TOGGLE_ZOOM),
|
|
22886
22916
|
onToggleDragPoints: createToggleHandler(TOGGLE_DRAG_POINTS),
|
|
22917
|
+
onToggleDragAnnotation: createToggleHandler(TOGGLE_DRAG_ANNOTATION),
|
|
22887
22918
|
onDisableDragOptions: createToggleHandler(DISABLE_DRAG_OPTIONS)
|
|
22888
22919
|
};
|
|
22889
22920
|
return toggleHandlers;
|
|
@@ -24304,9 +24335,10 @@ const Controls = ({
|
|
|
24304
24335
|
panEnabled,
|
|
24305
24336
|
pointsEnabled,
|
|
24306
24337
|
showTable,
|
|
24307
|
-
zoomEnabled
|
|
24338
|
+
zoomEnabled,
|
|
24339
|
+
enableDragAnnotation
|
|
24308
24340
|
} = state;
|
|
24309
|
-
const { dragData, depthType } = options;
|
|
24341
|
+
const { dragData, depthType, annotations } = options;
|
|
24310
24342
|
const {
|
|
24311
24343
|
onToggleLine,
|
|
24312
24344
|
onTogglePan,
|
|
@@ -24314,6 +24346,7 @@ const Controls = ({
|
|
|
24314
24346
|
onToggleTable,
|
|
24315
24347
|
onToggleZoom,
|
|
24316
24348
|
onToggleDragPoints,
|
|
24349
|
+
onToggleDragAnnotation,
|
|
24317
24350
|
onDisableDragOptions
|
|
24318
24351
|
} = useToggleHandlers(dispatch);
|
|
24319
24352
|
const { handleDownload, controlsAxesLabels, onResetAxes, onUpdateAxes } = useChartFunctions({
|
|
@@ -24377,7 +24410,10 @@ const Controls = ({
|
|
|
24377
24410
|
onTogglePan,
|
|
24378
24411
|
onToggleZoom,
|
|
24379
24412
|
enableDragPoints,
|
|
24413
|
+
enableDragAnnotation,
|
|
24380
24414
|
isDragDataAllowed: dragData == null ? void 0 : dragData.enableDragData,
|
|
24415
|
+
isDragAnnotationAllowed: annotations == null ? void 0 : annotations.enableDragAnnotation,
|
|
24416
|
+
onToggleDragAnnotation,
|
|
24381
24417
|
onToggleDragPoints,
|
|
24382
24418
|
onDisableDragOptions,
|
|
24383
24419
|
translations
|
|
@@ -24487,6 +24523,7 @@ const defaultAnnotations$1 = (annotations) => {
|
|
|
24487
24523
|
},
|
|
24488
24524
|
showAnnotations: (annotations == null ? void 0 : annotations.showAnnotations) ?? false,
|
|
24489
24525
|
controlAnnotation: (annotations == null ? void 0 : annotations.controlAnnotation) ?? false,
|
|
24526
|
+
enableDragAnnotation: (annotations == null ? void 0 : annotations.enableDragAnnotation) ?? false,
|
|
24490
24527
|
annotationsData: defaultAnnotationsData$1(annotations == null ? void 0 : annotations.annotationsData)
|
|
24491
24528
|
};
|
|
24492
24529
|
};
|
|
@@ -25137,6 +25174,19 @@ const legendReducer = (state, action) => {
|
|
|
25137
25174
|
return state;
|
|
25138
25175
|
}
|
|
25139
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 || {});
|
|
25140
25190
|
const annotationEnter = (element, chart2) => {
|
|
25141
25191
|
var _a2;
|
|
25142
25192
|
if ((_a2 = element.options.scaleID) == null ? void 0 : _a2.includes(AxisType.X)) {
|
|
@@ -25169,9 +25219,13 @@ const generateAnnotations = (annotationsData) => {
|
|
|
25169
25219
|
const color2 = (ann == null ? void 0 : ann.color) || COLORS[idx];
|
|
25170
25220
|
const type = (ann == null ? void 0 : ann.type) || "line";
|
|
25171
25221
|
const adjustScaleRange2 = ann == null ? void 0 : ann.adjustScaleRange;
|
|
25172
|
-
const borderColor =
|
|
25173
|
-
|
|
25174
|
-
|
|
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;
|
|
25175
25229
|
const label = type === "line" ? {
|
|
25176
25230
|
backgroundColor: color2,
|
|
25177
25231
|
content: ann == null ? void 0 : ann.label,
|
|
@@ -25187,7 +25241,7 @@ const generateAnnotations = (annotationsData) => {
|
|
|
25187
25241
|
}, {
|
|
25188
25242
|
chart: chart2
|
|
25189
25243
|
}) => {
|
|
25190
|
-
if (type !== "line")
|
|
25244
|
+
if (type !== "line" && !ann.enableDrag)
|
|
25191
25245
|
return;
|
|
25192
25246
|
annotationEnter(element, chart2);
|
|
25193
25247
|
};
|
|
@@ -25196,10 +25250,13 @@ const generateAnnotations = (annotationsData) => {
|
|
|
25196
25250
|
}, {
|
|
25197
25251
|
chart: chart2
|
|
25198
25252
|
}) => {
|
|
25199
|
-
if (type !== "line")
|
|
25253
|
+
if (type !== "line" && !ann.enableDrag)
|
|
25200
25254
|
return;
|
|
25201
25255
|
annotationLeave(element, chart2);
|
|
25202
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;
|
|
25203
25260
|
return {
|
|
25204
25261
|
...ann,
|
|
25205
25262
|
display: ann == null ? void 0 : ann.display,
|
|
@@ -25214,7 +25271,10 @@ const generateAnnotations = (annotationsData) => {
|
|
|
25214
25271
|
type,
|
|
25215
25272
|
adjustScaleRange: adjustScaleRange2,
|
|
25216
25273
|
enter,
|
|
25217
|
-
leave
|
|
25274
|
+
leave,
|
|
25275
|
+
onDragStart,
|
|
25276
|
+
onDrag,
|
|
25277
|
+
onDragEnd
|
|
25218
25278
|
};
|
|
25219
25279
|
});
|
|
25220
25280
|
};
|
|
@@ -25410,6 +25470,9 @@ const useChartOptions = ({
|
|
|
25410
25470
|
);
|
|
25411
25471
|
const plugins = {
|
|
25412
25472
|
datalabels,
|
|
25473
|
+
annotationDraggerPlugin: {
|
|
25474
|
+
enabled: state.enableDragAnnotation
|
|
25475
|
+
},
|
|
25413
25476
|
annotation: toAnnotationObject(annotation2),
|
|
25414
25477
|
zoom: { pan: panOptions, zoom: zoomOptions },
|
|
25415
25478
|
tooltip,
|
|
@@ -25766,6 +25829,224 @@ const chartAreaTextPlugin = {
|
|
|
25766
25829
|
});
|
|
25767
25830
|
}
|
|
25768
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
|
+
};
|
|
25769
26050
|
var defaultTranslations = /* @__PURE__ */ ((defaultTranslations2) => {
|
|
25770
26051
|
defaultTranslations2["label"] = "Label";
|
|
25771
26052
|
defaultTranslations2["pointsLines"] = "Points & lines";
|
|
@@ -25780,6 +26061,7 @@ var defaultTranslations = /* @__PURE__ */ ((defaultTranslations2) => {
|
|
|
25780
26061
|
defaultTranslations2["dragToZoom"] = "Drag to zoom";
|
|
25781
26062
|
defaultTranslations2["dragToPan"] = "Drag to pan";
|
|
25782
26063
|
defaultTranslations2["dragToMovePoints"] = "Drag to move points";
|
|
26064
|
+
defaultTranslations2["dragToMoveAnnotation"] = "Drag to move annotation";
|
|
25783
26065
|
defaultTranslations2["dragDisabled"] = "Drag disabled";
|
|
25784
26066
|
defaultTranslations2["hideLegend"] = "Hide Legend";
|
|
25785
26067
|
defaultTranslations2["showLegend"] = "Show Legend";
|
|
@@ -25895,6 +26177,7 @@ var ChartType = /* @__PURE__ */ ((ChartType2) => {
|
|
|
25895
26177
|
ChartType2["LINE"] = "line";
|
|
25896
26178
|
ChartType2["BAR"] = "bar";
|
|
25897
26179
|
ChartType2["PIE"] = "pie";
|
|
26180
|
+
ChartType2["SCATTER"] = "scatter";
|
|
25898
26181
|
return ChartType2;
|
|
25899
26182
|
})(ChartType || {});
|
|
25900
26183
|
const circleSvg = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PGNpcmNsZSBjeD0iMTIiIGN5PSIxMiIgcj0iMTIiIGZpbGw9ImN1cnJlbnRDb2xvciIgLz48L3N2Zz4=";
|
|
@@ -25956,10 +26239,10 @@ const BoxItem = ({ dataset }) => {
|
|
|
25956
26239
|
const LegendItemLine = ({ dataset }) => {
|
|
25957
26240
|
const { annotationType, showLine } = dataset;
|
|
25958
26241
|
switch (annotationType) {
|
|
25959
|
-
case AnnotationType.Box:
|
|
25960
|
-
case AnnotationType.Ellipse:
|
|
26242
|
+
case AnnotationType$1.Box:
|
|
26243
|
+
case AnnotationType$1.Ellipse:
|
|
25961
26244
|
return /* @__PURE__ */ jsx(BoxItem, { dataset });
|
|
25962
|
-
case AnnotationType.Line:
|
|
26245
|
+
case AnnotationType$1.Line:
|
|
25963
26246
|
return /* @__PURE__ */ jsx(LineItem, { dataset });
|
|
25964
26247
|
default:
|
|
25965
26248
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -25977,6 +26260,8 @@ const renderLegendItemSymbol = (dataset, chartType) => {
|
|
|
25977
26260
|
return /* @__PURE__ */ jsx("span", { className: styles$2.legendItemBox, children: /* @__PURE__ */ jsx(TbSquareFilled, { color: dataset.borderColor }) });
|
|
25978
26261
|
case ChartType.PIE:
|
|
25979
26262
|
return /* @__PURE__ */ jsx("span", { className: styles$2.legendItemPoint, children: /* @__PURE__ */ jsx(Icon, { icon: circleSvg }) });
|
|
26263
|
+
case ChartType.SCATTER:
|
|
26264
|
+
return /* @__PURE__ */ jsx("span", { className: styles$2.legendItemPoint, children: /* @__PURE__ */ jsx(TbCircleFilled, { color: dataset.borderColor }) });
|
|
25980
26265
|
default:
|
|
25981
26266
|
return null;
|
|
25982
26267
|
}
|
|
@@ -26255,7 +26540,8 @@ Chart$2.register(
|
|
|
26255
26540
|
plugin$1,
|
|
26256
26541
|
plugin,
|
|
26257
26542
|
annotation,
|
|
26258
|
-
chartAreaTextPlugin
|
|
26543
|
+
chartAreaTextPlugin,
|
|
26544
|
+
annotationDraggerPlugin
|
|
26259
26545
|
);
|
|
26260
26546
|
const LineChart = (props) => {
|
|
26261
26547
|
var _a2, _b2;
|
|
@@ -26361,6 +26647,7 @@ const LineChart = (props) => {
|
|
|
26361
26647
|
},
|
|
26362
26648
|
generateKey([
|
|
26363
26649
|
state.enableDragPoints,
|
|
26650
|
+
state.enableDragAnnotation,
|
|
26364
26651
|
state.zoomEnabled,
|
|
26365
26652
|
state.panEnabled,
|
|
26366
26653
|
languageKey
|
|
@@ -26462,7 +26749,7 @@ const usePieChartConfig = (chart2) => {
|
|
|
26462
26749
|
const generatedDataset = {
|
|
26463
26750
|
label: ((_a2 = copyDataset == null ? void 0 : copyDataset[0]) == null ? void 0 : _a2.label) ?? "",
|
|
26464
26751
|
backgroundColor: [],
|
|
26465
|
-
borderColor:
|
|
26752
|
+
borderColor: "",
|
|
26466
26753
|
borderWidth: Number(copyDataset[0].borderWidth) || 1,
|
|
26467
26754
|
data: [],
|
|
26468
26755
|
borderDash: []
|
|
@@ -26475,20 +26762,18 @@ const usePieChartConfig = (chart2) => {
|
|
|
26475
26762
|
generatedDataset.backgroundColor.push(
|
|
26476
26763
|
(Array.isArray(backgroundColor) ? backgroundColor[labelIndex % ((borderColor == null ? void 0 : borderColor.length) || 1)] : backgroundColor) || COLORS[labelIndex] + `${99 - 10 * arcIndex}`
|
|
26477
26764
|
);
|
|
26478
|
-
generatedDataset.borderColor
|
|
26479
|
-
(Array.isArray(borderColor) ? borderColor[labelIndex % borderColor.length] : borderColor) || COLORS[labelIndex]
|
|
26480
|
-
);
|
|
26765
|
+
generatedDataset.borderColor = borderColor ?? "";
|
|
26481
26766
|
});
|
|
26482
26767
|
});
|
|
26483
26768
|
return [generatedDataset];
|
|
26484
26769
|
}
|
|
26485
26770
|
const generatedDatasets2 = copyDataset.map(
|
|
26486
26771
|
(pieDataset, index2) => {
|
|
26487
|
-
const { borderWidth: inputBorderWidth = "1"
|
|
26772
|
+
const { borderWidth: inputBorderWidth = "1" } = pieDataset ?? {};
|
|
26488
26773
|
const borderWidth = parseFloat(String(inputBorderWidth)) || 1;
|
|
26489
|
-
const color2 =
|
|
26774
|
+
const color2 = COLORS[index2];
|
|
26490
26775
|
const borderColor = pieDataset.borderColor || color2;
|
|
26491
|
-
const backgroundColor = pieDataset.backgroundColor ||
|
|
26776
|
+
const backgroundColor = pieDataset.backgroundColor || generateRandomColor(COLORS);
|
|
26492
26777
|
return {
|
|
26493
26778
|
...pieDataset,
|
|
26494
26779
|
borderWidth,
|