@oliasoft-open-source/charts-library 4.3.3-beta-10 → 4.3.4-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
CHANGED
|
@@ -11,7 +11,7 @@ import { produce } from "immer";
|
|
|
11
11
|
import { round as round$2, displayNumber, isCloseTo, roundByMagnitude } from "@oliasoft-open-source/units";
|
|
12
12
|
import cx from "classnames";
|
|
13
13
|
import { Icon, Tooltip as Tooltip$2, Button, Flex, Text, Menu, Popover, Field, InputGroup, NumberInput, InputGroupAddon, Select, ButtonGroup, Spacer, Portal } from "@oliasoft-open-source/react-ui-library";
|
|
14
|
-
import { isEmpty, isArray as isArray$2, some, has, cloneDeep, defaultTo, findIndex, set as set$2,
|
|
14
|
+
import { isEmpty, isArray as isArray$2, some, has, cloneDeep, defaultTo, findIndex, set as set$2, debounce as debounce$3, isNil, map as map$3, find, get as get$1, values } from "lodash";
|
|
15
15
|
import { roundNumberToPrecision } from "@oliasoft-open-source/units/dist/rounding/rounding";
|
|
16
16
|
/*!
|
|
17
17
|
* @kurkle/color v0.3.2
|
|
@@ -25329,11 +25329,9 @@ var AnnotationType = /* @__PURE__ */ ((AnnotationType2) => {
|
|
|
25329
25329
|
return AnnotationType2;
|
|
25330
25330
|
})(AnnotationType || {});
|
|
25331
25331
|
const handleLineEnter = (element, chart2, annotation2) => {
|
|
25332
|
-
var _a2
|
|
25333
|
-
|
|
25334
|
-
|
|
25335
|
-
}
|
|
25336
|
-
if ((_c2 = element.options.scaleID) == null ? void 0 : _c2.includes(AxisType.X)) {
|
|
25332
|
+
var _a2;
|
|
25333
|
+
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25334
|
+
if ((_a2 = element.options.scaleID) == null ? void 0 : _a2.includes(AxisType.X)) {
|
|
25337
25335
|
if (element.options.label) {
|
|
25338
25336
|
element.options.label.xAdjust = chart2.chartArea.left;
|
|
25339
25337
|
}
|
|
@@ -25350,11 +25348,8 @@ const handleLineEnter = (element, chart2, annotation2) => {
|
|
|
25350
25348
|
chart2.draw();
|
|
25351
25349
|
};
|
|
25352
25350
|
const handleLineLeave = (element, chart2, annotation2) => {
|
|
25353
|
-
var _a2, _b2;
|
|
25354
25351
|
element.options.borderWidth = BORDER_WIDTH.INITIAL;
|
|
25355
|
-
|
|
25356
|
-
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25357
|
-
}
|
|
25352
|
+
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25358
25353
|
chart2.hoveredAnnotationId = null;
|
|
25359
25354
|
if (element.options.label) {
|
|
25360
25355
|
element.label.options.display = false;
|
|
@@ -25367,49 +25362,37 @@ const handleLineLeave = (element, chart2, annotation2) => {
|
|
|
25367
25362
|
chart2.draw();
|
|
25368
25363
|
};
|
|
25369
25364
|
const handleBoxEnter = (element, chart2, annotation2) => {
|
|
25370
|
-
var _a2, _b2;
|
|
25371
25365
|
if (annotation2 == null ? void 0 : annotation2.enableDrag) {
|
|
25372
25366
|
chart2.hoveredAnnotationId = element.options.id || null;
|
|
25373
25367
|
chart2.update();
|
|
25374
25368
|
element.options.borderWidth = BORDER_WIDTH.HOVERED;
|
|
25375
|
-
|
|
25376
|
-
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25377
|
-
}
|
|
25369
|
+
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25378
25370
|
}
|
|
25379
25371
|
chart2.draw();
|
|
25380
25372
|
};
|
|
25381
25373
|
const handleBoxLeave = (element, chart2, annotation2) => {
|
|
25382
|
-
var _a2, _b2;
|
|
25383
25374
|
if (annotation2 == null ? void 0 : annotation2.enableDrag) {
|
|
25384
25375
|
chart2.hoveredAnnotationId = null;
|
|
25385
25376
|
element.options.borderWidth = BORDER_WIDTH.INITIAL;
|
|
25386
|
-
|
|
25387
|
-
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25388
|
-
}
|
|
25377
|
+
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25389
25378
|
chart2.update();
|
|
25390
25379
|
}
|
|
25391
25380
|
chart2.draw();
|
|
25392
25381
|
};
|
|
25393
25382
|
const handlePointEnter = (element, chart2, annotation2) => {
|
|
25394
|
-
var _a2, _b2;
|
|
25395
25383
|
if (annotation2 == null ? void 0 : annotation2.enableDrag) {
|
|
25396
25384
|
chart2.hoveredAnnotationId = element.options.id || null;
|
|
25397
25385
|
chart2.update();
|
|
25398
25386
|
element.options.borderWidth = BORDER_WIDTH.POINT_HOVERED;
|
|
25399
|
-
|
|
25400
|
-
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25401
|
-
}
|
|
25387
|
+
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25402
25388
|
}
|
|
25403
25389
|
chart2.draw();
|
|
25404
25390
|
};
|
|
25405
25391
|
const handlePointLeave = (element, chart2, annotation2) => {
|
|
25406
|
-
var _a2, _b2;
|
|
25407
25392
|
if (annotation2 == null ? void 0 : annotation2.enableDrag) {
|
|
25408
25393
|
chart2.hoveredAnnotationId = null;
|
|
25409
25394
|
element.options.borderWidth = BORDER_WIDTH.INITIAL;
|
|
25410
|
-
|
|
25411
|
-
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25412
|
-
}
|
|
25395
|
+
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25413
25396
|
chart2.update();
|
|
25414
25397
|
}
|
|
25415
25398
|
chart2.draw();
|
|
@@ -25826,13 +25809,13 @@ const useToggleCustomLegendVisibility = (memoState, memoOptions) => {
|
|
|
25826
25809
|
const parent = document.getElementById(
|
|
25827
25810
|
memoOptions.legend.customLegend.customLegendContainerID
|
|
25828
25811
|
);
|
|
25829
|
-
if (
|
|
25812
|
+
if (parent !== null) {
|
|
25830
25813
|
parent.style.visibility = memoState.legendEnabled ? "visible" : "hidden";
|
|
25831
25814
|
}
|
|
25832
25815
|
}
|
|
25833
25816
|
}, [
|
|
25834
25817
|
(_b2 = (_a2 = memoOptions == null ? void 0 : memoOptions.legend) == null ? void 0 : _a2.customLegend) == null ? void 0 : _b2.customLegendPlugin,
|
|
25835
|
-
memoState
|
|
25818
|
+
memoState.legendEnabled
|
|
25836
25819
|
]);
|
|
25837
25820
|
};
|
|
25838
25821
|
const useStoreChartStateInStorage = (memoState, persistenceId) => {
|
|
@@ -26129,16 +26112,13 @@ const calculateAnnotationMetricsInValuesInPixels = (annotation2, scales) => {
|
|
|
26129
26112
|
};
|
|
26130
26113
|
};
|
|
26131
26114
|
const handleAnnotationMouseDown = (event, canvas2, scales, annotations, setDraggingState, hoveredAnnotationId) => {
|
|
26132
|
-
var _a2;
|
|
26133
26115
|
const { x: x2, y: y2 } = getMousePositionInCoordinates(event, canvas2, scales);
|
|
26134
26116
|
const annotation2 = hoveredAnnotationId ? annotations == null ? void 0 : annotations[hoveredAnnotationId] : null;
|
|
26135
26117
|
if (!annotation2)
|
|
26136
26118
|
return;
|
|
26137
26119
|
const metrics = calculateAnnotationMetricsInValues(annotation2);
|
|
26138
26120
|
if (annotation2 && annotation2.enableDrag && !isNil(metrics.centerY) && !isNil(metrics.centerX)) {
|
|
26139
|
-
|
|
26140
|
-
canvas2.style.cursor = CursorStyle.Move;
|
|
26141
|
-
}
|
|
26121
|
+
canvas2.style.cursor = CursorStyle.Move;
|
|
26142
26122
|
const dragStartX = x2 - metrics.centerX;
|
|
26143
26123
|
const dragStartY = y2 - metrics.centerY;
|
|
26144
26124
|
setDraggingState(true, annotation2, dragStartX, dragStartY);
|
|
@@ -26148,11 +26128,8 @@ const handleAnnotationMouseDown = (event, canvas2, scales, annotations, setDragg
|
|
|
26148
26128
|
}
|
|
26149
26129
|
};
|
|
26150
26130
|
const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAnnotation, dragStartX, dragStartY, chart2) => {
|
|
26151
|
-
var _a2;
|
|
26152
26131
|
if (isDragging2 && activeAnnotation) {
|
|
26153
|
-
|
|
26154
|
-
canvas2.style.cursor = CursorStyle.Move;
|
|
26155
|
-
}
|
|
26132
|
+
canvas2.style.cursor = CursorStyle.Move;
|
|
26156
26133
|
const { x: x2, y: y2 } = getMousePositionInCoordinates(event, canvas2, scales);
|
|
26157
26134
|
const metrics = calculateAnnotationMetricsInValues(activeAnnotation);
|
|
26158
26135
|
let newCenterX = x2 - dragStartX;
|
|
@@ -26170,6 +26147,7 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26170
26147
|
activeAnnotation.yMax = newCenterY + metrics.height / 2;
|
|
26171
26148
|
}
|
|
26172
26149
|
}
|
|
26150
|
+
chart2.update();
|
|
26173
26151
|
if (activeAnnotation == null ? void 0 : activeAnnotation.onDrag) {
|
|
26174
26152
|
activeAnnotation.onDrag({ x: x2, y: y2 }, cloneDeep(activeAnnotation));
|
|
26175
26153
|
}
|
|
@@ -26177,9 +26155,9 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26177
26155
|
const { centerX, centerY } = calculateAnnotationMetricsInValues(activeAnnotation) ?? {};
|
|
26178
26156
|
const { centerX: xValue, centerY: yValue } = calculateAnnotationMetricsInValuesInPixels(activeAnnotation, scales);
|
|
26179
26157
|
if (!isNil(centerX) && !isNil(centerY) && !isNil(xValue) && !isNil(yValue)) {
|
|
26180
|
-
ctx
|
|
26181
|
-
ctx
|
|
26182
|
-
chart2
|
|
26158
|
+
ctx.save();
|
|
26159
|
+
ctx.clearRect(0, 0, width, height);
|
|
26160
|
+
chart2.draw();
|
|
26183
26161
|
ctx.font = DEFAULT_FONT_FAMILY;
|
|
26184
26162
|
ctx.fillStyle = "black";
|
|
26185
26163
|
let labelX = xValue - 45;
|
|
@@ -26192,13 +26170,12 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26192
26170
|
if (labelY > height) {
|
|
26193
26171
|
labelY = height - 7;
|
|
26194
26172
|
}
|
|
26195
|
-
ctx
|
|
26196
|
-
ctx
|
|
26173
|
+
ctx.fillText(labelText, labelX, labelY);
|
|
26174
|
+
ctx.restore();
|
|
26197
26175
|
}
|
|
26198
26176
|
}
|
|
26199
26177
|
};
|
|
26200
26178
|
const handleAnnotationMouseUp = (isDragging2, activeAnnotation, chart2, setDraggingState) => {
|
|
26201
|
-
var _a2, _b2;
|
|
26202
26179
|
if (isDragging2) {
|
|
26203
26180
|
if (activeAnnotation) {
|
|
26204
26181
|
const { centerX = -1, centerY = -1 } = calculateAnnotationMetricsInValues(activeAnnotation) ?? {};
|
|
@@ -26208,15 +26185,10 @@ const handleAnnotationMouseUp = (isDragging2, activeAnnotation, chart2, setDragg
|
|
|
26208
26185
|
cloneDeep(activeAnnotation)
|
|
26209
26186
|
);
|
|
26210
26187
|
}
|
|
26211
|
-
|
|
26212
|
-
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
26213
|
-
}
|
|
26214
|
-
}
|
|
26215
|
-
console.log("chart?.canvas MOUSE UP", chart2 == null ? void 0 : chart2.canvas);
|
|
26216
|
-
if (chart2 == null ? void 0 : chart2.canvas) {
|
|
26188
|
+
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
26217
26189
|
setDraggingState(false, null);
|
|
26218
|
-
chart2 == null ? void 0 : chart2.update();
|
|
26219
26190
|
}
|
|
26191
|
+
chart2.update();
|
|
26220
26192
|
}
|
|
26221
26193
|
};
|
|
26222
26194
|
const annotationLabel = (ctx, annotations, scales) => {
|
|
@@ -26224,11 +26196,11 @@ const annotationLabel = (ctx, annotations, scales) => {
|
|
|
26224
26196
|
var _a2;
|
|
26225
26197
|
if (annotation2.type === AnnotationType.POINT && !isNil(annotation2 == null ? void 0 : annotation2.label) && ((_a2 = annotation2 == null ? void 0 : annotation2.label) == null ? void 0 : _a2.display)) {
|
|
26226
26198
|
const { content, font, color: color2, position, padding } = (annotation2 == null ? void 0 : annotation2.label) ?? {};
|
|
26227
|
-
ctx
|
|
26199
|
+
ctx.save();
|
|
26228
26200
|
ctx.font = font;
|
|
26229
26201
|
ctx.fillStyle = color2;
|
|
26230
26202
|
const { centerX = -1, centerY = -1 } = calculateAnnotationMetricsInValuesInPixels(annotation2, scales);
|
|
26231
|
-
const textWidth = ctx
|
|
26203
|
+
const textWidth = ctx.measureText(content).width;
|
|
26232
26204
|
let textX = centerX - textWidth / 2;
|
|
26233
26205
|
let textY = centerY + 20;
|
|
26234
26206
|
switch (position) {
|
|
@@ -26244,8 +26216,8 @@ const annotationLabel = (ctx, annotations, scales) => {
|
|
|
26244
26216
|
textY = centerY;
|
|
26245
26217
|
break;
|
|
26246
26218
|
}
|
|
26247
|
-
ctx
|
|
26248
|
-
ctx
|
|
26219
|
+
ctx.fillText(content, textX, textY);
|
|
26220
|
+
ctx.restore();
|
|
26249
26221
|
}
|
|
26250
26222
|
});
|
|
26251
26223
|
};
|
|
@@ -26257,9 +26229,9 @@ const annotationDraggerPlugin = {
|
|
|
26257
26229
|
if (!annotations)
|
|
26258
26230
|
return;
|
|
26259
26231
|
annotationLabel(
|
|
26260
|
-
chart2
|
|
26232
|
+
chart2.ctx,
|
|
26261
26233
|
annotations,
|
|
26262
|
-
chart2
|
|
26234
|
+
chart2.scales
|
|
26263
26235
|
);
|
|
26264
26236
|
const pluginOptions = ((_d2 = (_c2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _c2.plugins) == null ? void 0 : _d2.annotationDraggerPlugin) || {
|
|
26265
26237
|
enabled: false
|
|
@@ -26282,14 +26254,15 @@ const annotationDraggerPlugin = {
|
|
|
26282
26254
|
};
|
|
26283
26255
|
}
|
|
26284
26256
|
},
|
|
26285
|
-
|
|
26286
|
-
var _a2, _b2, _c2, _d2
|
|
26257
|
+
afterDraw(chart2) {
|
|
26258
|
+
var _a2, _b2, _c2, _d2;
|
|
26259
|
+
const { canvas: canvas2, scales, hoveredAnnotationId } = chart2;
|
|
26287
26260
|
const pluginOptions = ((_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.annotationDraggerPlugin) || {
|
|
26288
26261
|
enabled: false
|
|
26289
26262
|
};
|
|
26290
|
-
const typedScales = { x:
|
|
26291
|
-
let annotations = ((
|
|
26292
|
-
if (!annotations)
|
|
26263
|
+
const typedScales = { x: scales.x, y: scales.y };
|
|
26264
|
+
let annotations = ((_d2 = (_c2 = chart2.options.plugins) == null ? void 0 : _c2.annotation) == null ? void 0 : _d2.annotations) ?? {};
|
|
26265
|
+
if (!chart2 && !annotations)
|
|
26293
26266
|
return;
|
|
26294
26267
|
let isDragging2 = false;
|
|
26295
26268
|
let dragStartX, dragStartY;
|
|
@@ -26302,71 +26275,48 @@ const annotationDraggerPlugin = {
|
|
|
26302
26275
|
dragStartY = startY;
|
|
26303
26276
|
}
|
|
26304
26277
|
};
|
|
26305
|
-
if (!
|
|
26306
|
-
|
|
26307
|
-
|
|
26308
|
-
|
|
26309
|
-
|
|
26310
|
-
|
|
26311
|
-
|
|
26312
|
-
|
|
26313
|
-
|
|
26314
|
-
|
|
26315
|
-
MouseEvents.MOUSEDOWN,
|
|
26316
|
-
(event) => {
|
|
26317
|
-
var _a3, _b3, _c3;
|
|
26318
|
-
handleAnnotationMouseDown(
|
|
26319
|
-
event,
|
|
26320
|
-
chart2 == null ? void 0 : chart2.canvas,
|
|
26321
|
-
typedScales,
|
|
26322
|
-
(_c3 = (_b3 = (_a3 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a3.plugins) == null ? void 0 : _b3.annotation) == null ? void 0 : _c3.annotations,
|
|
26323
|
-
setDraggingState,
|
|
26324
|
-
chart2.hoveredAnnotationId
|
|
26325
|
-
);
|
|
26326
|
-
}
|
|
26278
|
+
if (!canvas2.dataset.annotationDraggerInitialized && pluginOptions.enabled && hoveredAnnotationId) {
|
|
26279
|
+
canvas2.addEventListener(MouseEvents.MOUSEDOWN, (event) => {
|
|
26280
|
+
var _a3, _b3, _c3;
|
|
26281
|
+
handleAnnotationMouseDown(
|
|
26282
|
+
event,
|
|
26283
|
+
canvas2,
|
|
26284
|
+
typedScales,
|
|
26285
|
+
(_c3 = (_b3 = (_a3 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a3.plugins) == null ? void 0 : _b3.annotation) == null ? void 0 : _c3.annotations,
|
|
26286
|
+
setDraggingState,
|
|
26287
|
+
chart2.hoveredAnnotationId
|
|
26327
26288
|
);
|
|
26328
|
-
|
|
26329
|
-
|
|
26330
|
-
|
|
26331
|
-
|
|
26332
|
-
|
|
26333
|
-
|
|
26334
|
-
|
|
26335
|
-
|
|
26336
|
-
|
|
26337
|
-
|
|
26338
|
-
|
|
26339
|
-
chart2
|
|
26340
|
-
);
|
|
26341
|
-
}
|
|
26289
|
+
});
|
|
26290
|
+
canvas2.addEventListener(MouseEvents.MOUSEMOVE, (event) => {
|
|
26291
|
+
handleAnnotationMouseMove(
|
|
26292
|
+
event,
|
|
26293
|
+
canvas2,
|
|
26294
|
+
typedScales,
|
|
26295
|
+
isDragging2,
|
|
26296
|
+
activeAnnotation,
|
|
26297
|
+
dragStartX,
|
|
26298
|
+
dragStartY,
|
|
26299
|
+
chart2
|
|
26342
26300
|
);
|
|
26343
|
-
|
|
26344
|
-
|
|
26345
|
-
|
|
26346
|
-
|
|
26347
|
-
|
|
26348
|
-
|
|
26349
|
-
|
|
26350
|
-
});
|
|
26351
|
-
chart2.canvas.dataset.annotationDraggerInitialized = "true";
|
|
26352
|
-
} else {
|
|
26353
|
-
console.error(
|
|
26354
|
-
"Canvas is null, empty, or does not support addEventListener:",
|
|
26355
|
-
chart2 == null ? void 0 : chart2.canvas
|
|
26301
|
+
});
|
|
26302
|
+
canvas2.addEventListener(MouseEvents.MOUSEUP, () => {
|
|
26303
|
+
handleAnnotationMouseUp(
|
|
26304
|
+
isDragging2,
|
|
26305
|
+
activeAnnotation,
|
|
26306
|
+
chart2,
|
|
26307
|
+
setDraggingState
|
|
26356
26308
|
);
|
|
26357
|
-
}
|
|
26309
|
+
});
|
|
26310
|
+
canvas2.dataset.annotationDraggerInitialized = "true";
|
|
26358
26311
|
}
|
|
26359
26312
|
if (!pluginOptions.enabled) {
|
|
26360
|
-
|
|
26361
|
-
|
|
26362
|
-
|
|
26363
|
-
|
|
26364
|
-
|
|
26365
|
-
|
|
26366
|
-
|
|
26367
|
-
});
|
|
26368
|
-
chart2.canvas.dataset.annotationDraggerInitialized = "";
|
|
26369
|
-
}
|
|
26313
|
+
canvas2.removeEventListener(MouseEvents.MOUSEDOWN, () => {
|
|
26314
|
+
});
|
|
26315
|
+
canvas2.removeEventListener(MouseEvents.MOUSEMOVE, () => {
|
|
26316
|
+
});
|
|
26317
|
+
canvas2.removeEventListener(MouseEvents.MOUSEUP, () => {
|
|
26318
|
+
});
|
|
26319
|
+
canvas2.dataset.annotationDraggerInitialized = "";
|
|
26370
26320
|
}
|
|
26371
26321
|
}
|
|
26372
26322
|
};
|