@oliasoft-open-source/charts-library 4.3.3-beta-10 → 4.4.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 +201 -173
- package/dist/index.js.map +1 -1
- package/dist/src/components/bar-chart/bar-chart.stories.d.ts +1 -1
- package/dist/src/components/common/common.interface.d.ts +2 -0
- package/dist/src/components/common/helpers/get-chart-annotation.d.ts +1 -0
- package/dist/src/components/common/plugins/ellipsis-annotation-plugin/ellipsis-annotation-plugin.d.ts +5 -0
- package/dist/src/components/line-chart/line-chart.stories.d.ts +66 -1
- package/package.json +1 -1
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
|
|
@@ -22173,6 +22173,127 @@ class HTML5BackendImpl {
|
|
|
22173
22173
|
const HTML5Backend = function createBackend(manager, context, options) {
|
|
22174
22174
|
return new HTML5BackendImpl(manager, context, options);
|
|
22175
22175
|
};
|
|
22176
|
+
const BORDER_WIDTH = {
|
|
22177
|
+
INITIAL: 2,
|
|
22178
|
+
HOVERED: 6,
|
|
22179
|
+
POINT_HOVERED: 8
|
|
22180
|
+
};
|
|
22181
|
+
const BORDER_COLOR = "rgba(0,0,0,0.1)";
|
|
22182
|
+
const ANNOTATION_DASH = [10, 2];
|
|
22183
|
+
const DEFAULT_FONT_SIZE = 12;
|
|
22184
|
+
const DEFAULT_FONT_FAMILY = '"Roobert", "Noto Sans", sans-serif';
|
|
22185
|
+
const DEFAULT_COLOR = "hsl(60, 10.34482759%, 12.5%)";
|
|
22186
|
+
const LEGEND_LABEL_BOX_SIZE = 12;
|
|
22187
|
+
const TOOLTIP_PADDING = 8;
|
|
22188
|
+
const TOOLTIP_BOX_PADDING = 4;
|
|
22189
|
+
const TRANSPARENT = "transparent";
|
|
22190
|
+
const LOGARITHMIC_STEPS = [1, 10, 100, 1e3, 1e4];
|
|
22191
|
+
const COLORS = [
|
|
22192
|
+
"#3366cc",
|
|
22193
|
+
"#dc3912",
|
|
22194
|
+
"#ff9900",
|
|
22195
|
+
"#109618",
|
|
22196
|
+
"#990099",
|
|
22197
|
+
"#0099c6",
|
|
22198
|
+
"#dd4477",
|
|
22199
|
+
"#66aa00",
|
|
22200
|
+
"#b82e2e",
|
|
22201
|
+
"#316395",
|
|
22202
|
+
"#994499",
|
|
22203
|
+
"#22aa99",
|
|
22204
|
+
"#aaaa11",
|
|
22205
|
+
"#6633cc",
|
|
22206
|
+
"#e67300",
|
|
22207
|
+
"#8b0707",
|
|
22208
|
+
"#651067",
|
|
22209
|
+
"#329262",
|
|
22210
|
+
"#5574a6",
|
|
22211
|
+
"#3b3eac"
|
|
22212
|
+
];
|
|
22213
|
+
const ALPHA_CHANEL = "99";
|
|
22214
|
+
const WHITE_COLOR_AS_DECIMAL = 16777215;
|
|
22215
|
+
const AUTO = "auto";
|
|
22216
|
+
const ANIMATION_DURATION = {
|
|
22217
|
+
NO: 0,
|
|
22218
|
+
SLOW: 400,
|
|
22219
|
+
FAST: 1e3
|
|
22220
|
+
};
|
|
22221
|
+
const DEFAULT_CHART_NAME = "new_chart";
|
|
22222
|
+
const CUSTOM_LEGEND_PLUGIN_NAME = "htmlLegend";
|
|
22223
|
+
const DECIMAL_POINT_TOLERANCE = 9;
|
|
22224
|
+
const MAX_DECIMAL_DIFF = 1 / 10 ** DECIMAL_POINT_TOLERANCE;
|
|
22225
|
+
const findRadii = (points, mainPoint, isXReverse, isYReverse) => {
|
|
22226
|
+
if ((points == null ? void 0 : points.length) === 0) {
|
|
22227
|
+
throw new Error("Array of points is empty");
|
|
22228
|
+
}
|
|
22229
|
+
let top2 = mainPoint;
|
|
22230
|
+
let bottom2 = mainPoint;
|
|
22231
|
+
let left2 = mainPoint;
|
|
22232
|
+
let right2 = mainPoint;
|
|
22233
|
+
for (const point of points) {
|
|
22234
|
+
if (isYReverse ? point.y < top2.y : point.y > top2.y) {
|
|
22235
|
+
top2 = point;
|
|
22236
|
+
}
|
|
22237
|
+
if (isYReverse ? point.y > bottom2.y : point.y < bottom2.y) {
|
|
22238
|
+
bottom2 = point;
|
|
22239
|
+
}
|
|
22240
|
+
if (isXReverse ? point.x > left2.x : point.x < left2.x) {
|
|
22241
|
+
left2 = point;
|
|
22242
|
+
}
|
|
22243
|
+
if (isXReverse ? point.x < right2.x : point.x > right2.x) {
|
|
22244
|
+
right2 = point;
|
|
22245
|
+
}
|
|
22246
|
+
}
|
|
22247
|
+
const radiusX = Math.abs(right2.x - left2.x) / 2;
|
|
22248
|
+
const radiusY = Math.abs(bottom2.y - top2.y) / 2;
|
|
22249
|
+
return { radiusX, radiusY };
|
|
22250
|
+
};
|
|
22251
|
+
const ellipsisAnnotationPlugin = {
|
|
22252
|
+
id: "ellipsisAnnotationPlugin",
|
|
22253
|
+
afterDraw: (chart2) => {
|
|
22254
|
+
var _a2, _b2, _c2, _d2;
|
|
22255
|
+
const {
|
|
22256
|
+
ctx,
|
|
22257
|
+
scales: { x: x2, y: y2 },
|
|
22258
|
+
data: { datasets },
|
|
22259
|
+
options
|
|
22260
|
+
} = chart2;
|
|
22261
|
+
const isXReverse = ((_b2 = (_a2 = options == null ? void 0 : options.scales) == null ? void 0 : _a2.x) == null ? void 0 : _b2.reverse) || false;
|
|
22262
|
+
const isYReverse = ((_d2 = (_c2 = options == null ? void 0 : options.scales) == null ? void 0 : _c2.y) == null ? void 0 : _d2.reverse) || false;
|
|
22263
|
+
datasets.forEach((dataset) => {
|
|
22264
|
+
dataset.data.forEach((item) => {
|
|
22265
|
+
if (item.ellipsePoints && item.ellipsePoints.length) {
|
|
22266
|
+
const centerX = x2.getPixelForValue(item.x);
|
|
22267
|
+
const centerY = y2.getPixelForValue(item.y);
|
|
22268
|
+
const points = item.ellipsePoints.map((point) => ({
|
|
22269
|
+
x: x2.getPixelForValue(point.x),
|
|
22270
|
+
y: y2.getPixelForValue(point.y)
|
|
22271
|
+
}));
|
|
22272
|
+
const mainPoint = { x: centerX, y: centerY };
|
|
22273
|
+
const { radiusX, radiusY } = findRadii(
|
|
22274
|
+
points,
|
|
22275
|
+
mainPoint,
|
|
22276
|
+
isXReverse,
|
|
22277
|
+
isYReverse
|
|
22278
|
+
);
|
|
22279
|
+
const rotationAngle = item.ellipseRotation * Math.PI / 180;
|
|
22280
|
+
ctx.beginPath();
|
|
22281
|
+
ctx.ellipse(
|
|
22282
|
+
centerX,
|
|
22283
|
+
centerY,
|
|
22284
|
+
radiusX,
|
|
22285
|
+
radiusY,
|
|
22286
|
+
rotationAngle,
|
|
22287
|
+
0,
|
|
22288
|
+
2 * Math.PI
|
|
22289
|
+
);
|
|
22290
|
+
ctx.strokeStyle = (dataset == null ? void 0 : dataset.borderColor) ?? DEFAULT_COLOR;
|
|
22291
|
+
ctx.stroke();
|
|
22292
|
+
}
|
|
22293
|
+
});
|
|
22294
|
+
});
|
|
22295
|
+
}
|
|
22296
|
+
};
|
|
22176
22297
|
const chart$3 = "_chart_e3qdd_1";
|
|
22177
22298
|
const canvas$1 = "_canvas_e3qdd_11";
|
|
22178
22299
|
const fixedHeight$3 = "_fixedHeight_e3qdd_20";
|
|
@@ -22466,55 +22587,6 @@ const chartMinorGridlinesPlugin = {
|
|
|
22466
22587
|
Object.keys(scales).forEach((id) => drawMinorTicksForScale(scales[id]));
|
|
22467
22588
|
}
|
|
22468
22589
|
};
|
|
22469
|
-
const BORDER_WIDTH = {
|
|
22470
|
-
INITIAL: 2,
|
|
22471
|
-
HOVERED: 6,
|
|
22472
|
-
POINT_HOVERED: 8
|
|
22473
|
-
};
|
|
22474
|
-
const BORDER_COLOR = "rgba(0,0,0,0.1)";
|
|
22475
|
-
const ANNOTATION_DASH = [10, 2];
|
|
22476
|
-
const DEFAULT_FONT_SIZE = 12;
|
|
22477
|
-
const DEFAULT_FONT_FAMILY = '"Roobert", "Noto Sans", sans-serif';
|
|
22478
|
-
const DEFAULT_COLOR = "hsl(60, 10.34482759%, 12.5%)";
|
|
22479
|
-
const LEGEND_LABEL_BOX_SIZE = 12;
|
|
22480
|
-
const TOOLTIP_PADDING = 8;
|
|
22481
|
-
const TOOLTIP_BOX_PADDING = 4;
|
|
22482
|
-
const TRANSPARENT = "transparent";
|
|
22483
|
-
const LOGARITHMIC_STEPS = [1, 10, 100, 1e3, 1e4];
|
|
22484
|
-
const COLORS = [
|
|
22485
|
-
"#3366cc",
|
|
22486
|
-
"#dc3912",
|
|
22487
|
-
"#ff9900",
|
|
22488
|
-
"#109618",
|
|
22489
|
-
"#990099",
|
|
22490
|
-
"#0099c6",
|
|
22491
|
-
"#dd4477",
|
|
22492
|
-
"#66aa00",
|
|
22493
|
-
"#b82e2e",
|
|
22494
|
-
"#316395",
|
|
22495
|
-
"#994499",
|
|
22496
|
-
"#22aa99",
|
|
22497
|
-
"#aaaa11",
|
|
22498
|
-
"#6633cc",
|
|
22499
|
-
"#e67300",
|
|
22500
|
-
"#8b0707",
|
|
22501
|
-
"#651067",
|
|
22502
|
-
"#329262",
|
|
22503
|
-
"#5574a6",
|
|
22504
|
-
"#3b3eac"
|
|
22505
|
-
];
|
|
22506
|
-
const ALPHA_CHANEL = "99";
|
|
22507
|
-
const WHITE_COLOR_AS_DECIMAL = 16777215;
|
|
22508
|
-
const AUTO = "auto";
|
|
22509
|
-
const ANIMATION_DURATION = {
|
|
22510
|
-
NO: 0,
|
|
22511
|
-
SLOW: 400,
|
|
22512
|
-
FAST: 1e3
|
|
22513
|
-
};
|
|
22514
|
-
const DEFAULT_CHART_NAME = "new_chart";
|
|
22515
|
-
const CUSTOM_LEGEND_PLUGIN_NAME = "htmlLegend";
|
|
22516
|
-
const DECIMAL_POINT_TOLERANCE = 9;
|
|
22517
|
-
const MAX_DECIMAL_DIFF = 1 / 10 ** DECIMAL_POINT_TOLERANCE;
|
|
22518
22590
|
const chartAreaBorderPlugin = {
|
|
22519
22591
|
id: "chartAreaBorder",
|
|
22520
22592
|
beforeDraw(chart2, _2, options) {
|
|
@@ -25329,11 +25401,9 @@ var AnnotationType = /* @__PURE__ */ ((AnnotationType2) => {
|
|
|
25329
25401
|
return AnnotationType2;
|
|
25330
25402
|
})(AnnotationType || {});
|
|
25331
25403
|
const handleLineEnter = (element, chart2, annotation2) => {
|
|
25332
|
-
var _a2
|
|
25333
|
-
|
|
25334
|
-
|
|
25335
|
-
}
|
|
25336
|
-
if ((_c2 = element.options.scaleID) == null ? void 0 : _c2.includes(AxisType.X)) {
|
|
25404
|
+
var _a2;
|
|
25405
|
+
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25406
|
+
if ((_a2 = element.options.scaleID) == null ? void 0 : _a2.includes(AxisType.X)) {
|
|
25337
25407
|
if (element.options.label) {
|
|
25338
25408
|
element.options.label.xAdjust = chart2.chartArea.left;
|
|
25339
25409
|
}
|
|
@@ -25350,11 +25420,8 @@ const handleLineEnter = (element, chart2, annotation2) => {
|
|
|
25350
25420
|
chart2.draw();
|
|
25351
25421
|
};
|
|
25352
25422
|
const handleLineLeave = (element, chart2, annotation2) => {
|
|
25353
|
-
var _a2, _b2;
|
|
25354
25423
|
element.options.borderWidth = BORDER_WIDTH.INITIAL;
|
|
25355
|
-
|
|
25356
|
-
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25357
|
-
}
|
|
25424
|
+
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25358
25425
|
chart2.hoveredAnnotationId = null;
|
|
25359
25426
|
if (element.options.label) {
|
|
25360
25427
|
element.label.options.display = false;
|
|
@@ -25367,49 +25434,37 @@ const handleLineLeave = (element, chart2, annotation2) => {
|
|
|
25367
25434
|
chart2.draw();
|
|
25368
25435
|
};
|
|
25369
25436
|
const handleBoxEnter = (element, chart2, annotation2) => {
|
|
25370
|
-
var _a2, _b2;
|
|
25371
25437
|
if (annotation2 == null ? void 0 : annotation2.enableDrag) {
|
|
25372
25438
|
chart2.hoveredAnnotationId = element.options.id || null;
|
|
25373
25439
|
chart2.update();
|
|
25374
25440
|
element.options.borderWidth = BORDER_WIDTH.HOVERED;
|
|
25375
|
-
|
|
25376
|
-
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25377
|
-
}
|
|
25441
|
+
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25378
25442
|
}
|
|
25379
25443
|
chart2.draw();
|
|
25380
25444
|
};
|
|
25381
25445
|
const handleBoxLeave = (element, chart2, annotation2) => {
|
|
25382
|
-
var _a2, _b2;
|
|
25383
25446
|
if (annotation2 == null ? void 0 : annotation2.enableDrag) {
|
|
25384
25447
|
chart2.hoveredAnnotationId = null;
|
|
25385
25448
|
element.options.borderWidth = BORDER_WIDTH.INITIAL;
|
|
25386
|
-
|
|
25387
|
-
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25388
|
-
}
|
|
25449
|
+
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25389
25450
|
chart2.update();
|
|
25390
25451
|
}
|
|
25391
25452
|
chart2.draw();
|
|
25392
25453
|
};
|
|
25393
25454
|
const handlePointEnter = (element, chart2, annotation2) => {
|
|
25394
|
-
var _a2, _b2;
|
|
25395
25455
|
if (annotation2 == null ? void 0 : annotation2.enableDrag) {
|
|
25396
25456
|
chart2.hoveredAnnotationId = element.options.id || null;
|
|
25397
25457
|
chart2.update();
|
|
25398
25458
|
element.options.borderWidth = BORDER_WIDTH.POINT_HOVERED;
|
|
25399
|
-
|
|
25400
|
-
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25401
|
-
}
|
|
25459
|
+
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25402
25460
|
}
|
|
25403
25461
|
chart2.draw();
|
|
25404
25462
|
};
|
|
25405
25463
|
const handlePointLeave = (element, chart2, annotation2) => {
|
|
25406
|
-
var _a2, _b2;
|
|
25407
25464
|
if (annotation2 == null ? void 0 : annotation2.enableDrag) {
|
|
25408
25465
|
chart2.hoveredAnnotationId = null;
|
|
25409
25466
|
element.options.borderWidth = BORDER_WIDTH.INITIAL;
|
|
25410
|
-
|
|
25411
|
-
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25412
|
-
}
|
|
25467
|
+
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25413
25468
|
chart2.update();
|
|
25414
25469
|
}
|
|
25415
25470
|
chart2.draw();
|
|
@@ -25424,9 +25479,13 @@ const generateAnnotations = (annotationsData) => {
|
|
|
25424
25479
|
const borderColor = {
|
|
25425
25480
|
[AnnotationType.LINE]: color2,
|
|
25426
25481
|
[AnnotationType.POINT]: color2,
|
|
25427
|
-
[AnnotationType.BOX]: color2
|
|
25482
|
+
[AnnotationType.BOX]: color2,
|
|
25483
|
+
[AnnotationType.ELLIPSE]: color2
|
|
25428
25484
|
}[type] || TRANSPARENT;
|
|
25429
|
-
const borderWidth =
|
|
25485
|
+
const borderWidth = {
|
|
25486
|
+
[AnnotationType.LINE]: BORDER_WIDTH.INITIAL,
|
|
25487
|
+
[AnnotationType.ELLIPSE]: (ann == null ? void 0 : ann.borderWidth) ?? 0
|
|
25488
|
+
}[type] ?? 0;
|
|
25430
25489
|
const borderDash = type === AnnotationType.LINE ? ANNOTATION_DASH : void 0;
|
|
25431
25490
|
const defLabel = {
|
|
25432
25491
|
content: ann == null ? void 0 : ann.label,
|
|
@@ -25494,12 +25553,13 @@ const generateAnnotations = (annotationsData) => {
|
|
|
25494
25553
|
const onDragEnd = () => (cord, annotation2) => (ann == null ? void 0 : ann.onDragEnd) ? ann == null ? void 0 : ann.onDragEnd(cord, annotation2) : void 0;
|
|
25495
25554
|
return {
|
|
25496
25555
|
...ann,
|
|
25556
|
+
drawTime: "afterDraw",
|
|
25497
25557
|
display: ann == null ? void 0 : ann.display,
|
|
25498
25558
|
annotationIndex: idx,
|
|
25499
25559
|
id: `${ann == null ? void 0 : ann.label}-${ann == null ? void 0 : ann.value}-${idx}`,
|
|
25500
25560
|
scaleID,
|
|
25501
25561
|
label,
|
|
25502
|
-
backgroundColor: color2,
|
|
25562
|
+
backgroundColor: (ann == null ? void 0 : ann.backgroundColor) ?? color2,
|
|
25503
25563
|
borderColor,
|
|
25504
25564
|
borderWidth,
|
|
25505
25565
|
borderDash,
|
|
@@ -25826,13 +25886,13 @@ const useToggleCustomLegendVisibility = (memoState, memoOptions) => {
|
|
|
25826
25886
|
const parent = document.getElementById(
|
|
25827
25887
|
memoOptions.legend.customLegend.customLegendContainerID
|
|
25828
25888
|
);
|
|
25829
|
-
if (
|
|
25889
|
+
if (parent !== null) {
|
|
25830
25890
|
parent.style.visibility = memoState.legendEnabled ? "visible" : "hidden";
|
|
25831
25891
|
}
|
|
25832
25892
|
}
|
|
25833
25893
|
}, [
|
|
25834
25894
|
(_b2 = (_a2 = memoOptions == null ? void 0 : memoOptions.legend) == null ? void 0 : _a2.customLegend) == null ? void 0 : _b2.customLegendPlugin,
|
|
25835
|
-
memoState
|
|
25895
|
+
memoState.legendEnabled
|
|
25836
25896
|
]);
|
|
25837
25897
|
};
|
|
25838
25898
|
const useStoreChartStateInStorage = (memoState, persistenceId) => {
|
|
@@ -26129,16 +26189,13 @@ const calculateAnnotationMetricsInValuesInPixels = (annotation2, scales) => {
|
|
|
26129
26189
|
};
|
|
26130
26190
|
};
|
|
26131
26191
|
const handleAnnotationMouseDown = (event, canvas2, scales, annotations, setDraggingState, hoveredAnnotationId) => {
|
|
26132
|
-
var _a2;
|
|
26133
26192
|
const { x: x2, y: y2 } = getMousePositionInCoordinates(event, canvas2, scales);
|
|
26134
26193
|
const annotation2 = hoveredAnnotationId ? annotations == null ? void 0 : annotations[hoveredAnnotationId] : null;
|
|
26135
26194
|
if (!annotation2)
|
|
26136
26195
|
return;
|
|
26137
26196
|
const metrics = calculateAnnotationMetricsInValues(annotation2);
|
|
26138
26197
|
if (annotation2 && annotation2.enableDrag && !isNil(metrics.centerY) && !isNil(metrics.centerX)) {
|
|
26139
|
-
|
|
26140
|
-
canvas2.style.cursor = CursorStyle.Move;
|
|
26141
|
-
}
|
|
26198
|
+
canvas2.style.cursor = CursorStyle.Move;
|
|
26142
26199
|
const dragStartX = x2 - metrics.centerX;
|
|
26143
26200
|
const dragStartY = y2 - metrics.centerY;
|
|
26144
26201
|
setDraggingState(true, annotation2, dragStartX, dragStartY);
|
|
@@ -26148,11 +26205,8 @@ const handleAnnotationMouseDown = (event, canvas2, scales, annotations, setDragg
|
|
|
26148
26205
|
}
|
|
26149
26206
|
};
|
|
26150
26207
|
const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAnnotation, dragStartX, dragStartY, chart2) => {
|
|
26151
|
-
var _a2;
|
|
26152
26208
|
if (isDragging2 && activeAnnotation) {
|
|
26153
|
-
|
|
26154
|
-
canvas2.style.cursor = CursorStyle.Move;
|
|
26155
|
-
}
|
|
26209
|
+
canvas2.style.cursor = CursorStyle.Move;
|
|
26156
26210
|
const { x: x2, y: y2 } = getMousePositionInCoordinates(event, canvas2, scales);
|
|
26157
26211
|
const metrics = calculateAnnotationMetricsInValues(activeAnnotation);
|
|
26158
26212
|
let newCenterX = x2 - dragStartX;
|
|
@@ -26170,6 +26224,7 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26170
26224
|
activeAnnotation.yMax = newCenterY + metrics.height / 2;
|
|
26171
26225
|
}
|
|
26172
26226
|
}
|
|
26227
|
+
chart2.update();
|
|
26173
26228
|
if (activeAnnotation == null ? void 0 : activeAnnotation.onDrag) {
|
|
26174
26229
|
activeAnnotation.onDrag({ x: x2, y: y2 }, cloneDeep(activeAnnotation));
|
|
26175
26230
|
}
|
|
@@ -26177,9 +26232,9 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26177
26232
|
const { centerX, centerY } = calculateAnnotationMetricsInValues(activeAnnotation) ?? {};
|
|
26178
26233
|
const { centerX: xValue, centerY: yValue } = calculateAnnotationMetricsInValuesInPixels(activeAnnotation, scales);
|
|
26179
26234
|
if (!isNil(centerX) && !isNil(centerY) && !isNil(xValue) && !isNil(yValue)) {
|
|
26180
|
-
ctx
|
|
26181
|
-
ctx
|
|
26182
|
-
chart2
|
|
26235
|
+
ctx.save();
|
|
26236
|
+
ctx.clearRect(0, 0, width, height);
|
|
26237
|
+
chart2.draw();
|
|
26183
26238
|
ctx.font = DEFAULT_FONT_FAMILY;
|
|
26184
26239
|
ctx.fillStyle = "black";
|
|
26185
26240
|
let labelX = xValue - 45;
|
|
@@ -26192,13 +26247,12 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
|
|
|
26192
26247
|
if (labelY > height) {
|
|
26193
26248
|
labelY = height - 7;
|
|
26194
26249
|
}
|
|
26195
|
-
ctx
|
|
26196
|
-
ctx
|
|
26250
|
+
ctx.fillText(labelText, labelX, labelY);
|
|
26251
|
+
ctx.restore();
|
|
26197
26252
|
}
|
|
26198
26253
|
}
|
|
26199
26254
|
};
|
|
26200
26255
|
const handleAnnotationMouseUp = (isDragging2, activeAnnotation, chart2, setDraggingState) => {
|
|
26201
|
-
var _a2, _b2;
|
|
26202
26256
|
if (isDragging2) {
|
|
26203
26257
|
if (activeAnnotation) {
|
|
26204
26258
|
const { centerX = -1, centerY = -1 } = calculateAnnotationMetricsInValues(activeAnnotation) ?? {};
|
|
@@ -26208,15 +26262,10 @@ const handleAnnotationMouseUp = (isDragging2, activeAnnotation, chart2, setDragg
|
|
|
26208
26262
|
cloneDeep(activeAnnotation)
|
|
26209
26263
|
);
|
|
26210
26264
|
}
|
|
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) {
|
|
26265
|
+
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
26217
26266
|
setDraggingState(false, null);
|
|
26218
|
-
chart2 == null ? void 0 : chart2.update();
|
|
26219
26267
|
}
|
|
26268
|
+
chart2.update();
|
|
26220
26269
|
}
|
|
26221
26270
|
};
|
|
26222
26271
|
const annotationLabel = (ctx, annotations, scales) => {
|
|
@@ -26224,11 +26273,11 @@ const annotationLabel = (ctx, annotations, scales) => {
|
|
|
26224
26273
|
var _a2;
|
|
26225
26274
|
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
26275
|
const { content, font, color: color2, position, padding } = (annotation2 == null ? void 0 : annotation2.label) ?? {};
|
|
26227
|
-
ctx
|
|
26276
|
+
ctx.save();
|
|
26228
26277
|
ctx.font = font;
|
|
26229
26278
|
ctx.fillStyle = color2;
|
|
26230
26279
|
const { centerX = -1, centerY = -1 } = calculateAnnotationMetricsInValuesInPixels(annotation2, scales);
|
|
26231
|
-
const textWidth = ctx
|
|
26280
|
+
const textWidth = ctx.measureText(content).width;
|
|
26232
26281
|
let textX = centerX - textWidth / 2;
|
|
26233
26282
|
let textY = centerY + 20;
|
|
26234
26283
|
switch (position) {
|
|
@@ -26244,8 +26293,8 @@ const annotationLabel = (ctx, annotations, scales) => {
|
|
|
26244
26293
|
textY = centerY;
|
|
26245
26294
|
break;
|
|
26246
26295
|
}
|
|
26247
|
-
ctx
|
|
26248
|
-
ctx
|
|
26296
|
+
ctx.fillText(content, textX, textY);
|
|
26297
|
+
ctx.restore();
|
|
26249
26298
|
}
|
|
26250
26299
|
});
|
|
26251
26300
|
};
|
|
@@ -26257,9 +26306,9 @@ const annotationDraggerPlugin = {
|
|
|
26257
26306
|
if (!annotations)
|
|
26258
26307
|
return;
|
|
26259
26308
|
annotationLabel(
|
|
26260
|
-
chart2
|
|
26309
|
+
chart2.ctx,
|
|
26261
26310
|
annotations,
|
|
26262
|
-
chart2
|
|
26311
|
+
chart2.scales
|
|
26263
26312
|
);
|
|
26264
26313
|
const pluginOptions = ((_d2 = (_c2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _c2.plugins) == null ? void 0 : _d2.annotationDraggerPlugin) || {
|
|
26265
26314
|
enabled: false
|
|
@@ -26282,14 +26331,15 @@ const annotationDraggerPlugin = {
|
|
|
26282
26331
|
};
|
|
26283
26332
|
}
|
|
26284
26333
|
},
|
|
26285
|
-
|
|
26286
|
-
var _a2, _b2, _c2, _d2
|
|
26334
|
+
afterUpdate(chart2) {
|
|
26335
|
+
var _a2, _b2, _c2, _d2;
|
|
26336
|
+
const { canvas: canvas2, scales, hoveredAnnotationId } = chart2;
|
|
26287
26337
|
const pluginOptions = ((_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.annotationDraggerPlugin) || {
|
|
26288
26338
|
enabled: false
|
|
26289
26339
|
};
|
|
26290
|
-
const typedScales = { x:
|
|
26291
|
-
let annotations = ((
|
|
26292
|
-
if (!annotations)
|
|
26340
|
+
const typedScales = { x: scales.x, y: scales.y };
|
|
26341
|
+
let annotations = ((_d2 = (_c2 = chart2.options.plugins) == null ? void 0 : _c2.annotation) == null ? void 0 : _d2.annotations) ?? {};
|
|
26342
|
+
if (!chart2 && !annotations)
|
|
26293
26343
|
return;
|
|
26294
26344
|
let isDragging2 = false;
|
|
26295
26345
|
let dragStartX, dragStartY;
|
|
@@ -26302,71 +26352,48 @@ const annotationDraggerPlugin = {
|
|
|
26302
26352
|
dragStartY = startY;
|
|
26303
26353
|
}
|
|
26304
26354
|
};
|
|
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
|
-
}
|
|
26355
|
+
if (!canvas2.dataset.annotationDraggerInitialized && pluginOptions.enabled && hoveredAnnotationId) {
|
|
26356
|
+
canvas2.addEventListener(MouseEvents.MOUSEDOWN, (event) => {
|
|
26357
|
+
var _a3, _b3, _c3;
|
|
26358
|
+
handleAnnotationMouseDown(
|
|
26359
|
+
event,
|
|
26360
|
+
canvas2,
|
|
26361
|
+
typedScales,
|
|
26362
|
+
(_c3 = (_b3 = (_a3 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a3.plugins) == null ? void 0 : _b3.annotation) == null ? void 0 : _c3.annotations,
|
|
26363
|
+
setDraggingState,
|
|
26364
|
+
chart2.hoveredAnnotationId
|
|
26327
26365
|
);
|
|
26328
|
-
|
|
26329
|
-
|
|
26330
|
-
|
|
26331
|
-
|
|
26332
|
-
|
|
26333
|
-
|
|
26334
|
-
|
|
26335
|
-
|
|
26336
|
-
|
|
26337
|
-
|
|
26338
|
-
|
|
26339
|
-
chart2
|
|
26340
|
-
);
|
|
26341
|
-
}
|
|
26366
|
+
});
|
|
26367
|
+
canvas2.addEventListener(MouseEvents.MOUSEMOVE, (event) => {
|
|
26368
|
+
handleAnnotationMouseMove(
|
|
26369
|
+
event,
|
|
26370
|
+
canvas2,
|
|
26371
|
+
typedScales,
|
|
26372
|
+
isDragging2,
|
|
26373
|
+
activeAnnotation,
|
|
26374
|
+
dragStartX,
|
|
26375
|
+
dragStartY,
|
|
26376
|
+
chart2
|
|
26342
26377
|
);
|
|
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
|
|
26378
|
+
});
|
|
26379
|
+
canvas2.addEventListener(MouseEvents.MOUSEUP, () => {
|
|
26380
|
+
handleAnnotationMouseUp(
|
|
26381
|
+
isDragging2,
|
|
26382
|
+
activeAnnotation,
|
|
26383
|
+
chart2,
|
|
26384
|
+
setDraggingState
|
|
26356
26385
|
);
|
|
26357
|
-
}
|
|
26386
|
+
});
|
|
26387
|
+
canvas2.dataset.annotationDraggerInitialized = "true";
|
|
26358
26388
|
}
|
|
26359
26389
|
if (!pluginOptions.enabled) {
|
|
26360
|
-
|
|
26361
|
-
|
|
26362
|
-
|
|
26363
|
-
|
|
26364
|
-
|
|
26365
|
-
|
|
26366
|
-
|
|
26367
|
-
});
|
|
26368
|
-
chart2.canvas.dataset.annotationDraggerInitialized = "";
|
|
26369
|
-
}
|
|
26390
|
+
canvas2.removeEventListener(MouseEvents.MOUSEDOWN, () => {
|
|
26391
|
+
});
|
|
26392
|
+
canvas2.removeEventListener(MouseEvents.MOUSEMOVE, () => {
|
|
26393
|
+
});
|
|
26394
|
+
canvas2.removeEventListener(MouseEvents.MOUSEUP, () => {
|
|
26395
|
+
});
|
|
26396
|
+
canvas2.dataset.annotationDraggerInitialized = "";
|
|
26370
26397
|
}
|
|
26371
26398
|
}
|
|
26372
26399
|
};
|
|
@@ -26869,7 +26896,8 @@ Chart$2.register(
|
|
|
26869
26896
|
plugin,
|
|
26870
26897
|
annotation,
|
|
26871
26898
|
chartAreaTextPlugin,
|
|
26872
|
-
annotationDraggerPlugin
|
|
26899
|
+
annotationDraggerPlugin,
|
|
26900
|
+
ellipsisAnnotationPlugin
|
|
26873
26901
|
);
|
|
26874
26902
|
const LineChart = (props) => {
|
|
26875
26903
|
var _a2, _b2;
|