@oliasoft-open-source/charts-library 4.3.3-beta-9 → 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, isNil, debounce as debounce$3, isFunction as isFunction$2, map as map$3, find, get as get$1, values } from "lodash";
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, _b2, _c2;
25333
- if (!isNil((_b2 = (_a2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _a2.style) == null ? void 0 : _b2.cursor)) {
25334
- chart2.canvas.style.cursor = CursorStyle.Pointer;
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
- if (!isNil((_b2 = (_a2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _a2.style) == null ? void 0 : _b2.cursor)) {
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
- if (!isNil((_b2 = (_a2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _a2.style) == null ? void 0 : _b2.cursor)) {
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
- if (!isNil((_b2 = (_a2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _a2.style) == null ? void 0 : _b2.cursor)) {
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
- if (!isNil((_b2 = (_a2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _a2.style) == null ? void 0 : _b2.cursor)) {
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
- if (!isNil((_b2 = (_a2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _a2.style) == null ? void 0 : _b2.cursor)) {
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 (!isNil(parent)) {
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 == null ? void 0 : memoState.legendEnabled
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
- if (!isNil((_a2 = canvas2 == null ? void 0 : canvas2.style) == null ? void 0 : _a2.cursor)) {
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
- if (!isNil((_a2 = canvas2 == null ? void 0 : canvas2.style) == null ? void 0 : _a2.cursor)) {
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 == null ? void 0 : ctx.save();
26181
- ctx == null ? void 0 : ctx.clearRect(0, 0, width, height);
26182
- chart2 == null ? void 0 : chart2.draw();
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 == null ? void 0 : ctx.fillText(labelText, labelX, labelY);
26196
- ctx == null ? void 0 : ctx.restore();
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,16 +26185,10 @@ const handleAnnotationMouseUp = (isDragging2, activeAnnotation, chart2, setDragg
26208
26185
  cloneDeep(activeAnnotation)
26209
26186
  );
26210
26187
  }
26211
- if (!isNil((_b2 = (_a2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _a2.style) == null ? void 0 : _b2.cursor)) {
26212
- chart2.canvas.style.cursor = CursorStyle.Pointer;
26213
- }
26214
- }
26215
- if (chart2 == null ? void 0 : chart2.canvas) {
26188
+ chart2.canvas.style.cursor = CursorStyle.Pointer;
26216
26189
  setDraggingState(false, null);
26217
- chart2 == null ? void 0 : chart2.update();
26218
- } else {
26219
- console.error("Canvas is not available during mouse up");
26220
26190
  }
26191
+ chart2.update();
26221
26192
  }
26222
26193
  };
26223
26194
  const annotationLabel = (ctx, annotations, scales) => {
@@ -26225,11 +26196,11 @@ const annotationLabel = (ctx, annotations, scales) => {
26225
26196
  var _a2;
26226
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)) {
26227
26198
  const { content, font, color: color2, position, padding } = (annotation2 == null ? void 0 : annotation2.label) ?? {};
26228
- ctx == null ? void 0 : ctx.save();
26199
+ ctx.save();
26229
26200
  ctx.font = font;
26230
26201
  ctx.fillStyle = color2;
26231
26202
  const { centerX = -1, centerY = -1 } = calculateAnnotationMetricsInValuesInPixels(annotation2, scales);
26232
- const textWidth = ctx == null ? void 0 : ctx.measureText(content).width;
26203
+ const textWidth = ctx.measureText(content).width;
26233
26204
  let textX = centerX - textWidth / 2;
26234
26205
  let textY = centerY + 20;
26235
26206
  switch (position) {
@@ -26245,8 +26216,8 @@ const annotationLabel = (ctx, annotations, scales) => {
26245
26216
  textY = centerY;
26246
26217
  break;
26247
26218
  }
26248
- ctx == null ? void 0 : ctx.fillText(content, textX, textY);
26249
- ctx == null ? void 0 : ctx.restore();
26219
+ ctx.fillText(content, textX, textY);
26220
+ ctx.restore();
26250
26221
  }
26251
26222
  });
26252
26223
  };
@@ -26258,9 +26229,9 @@ const annotationDraggerPlugin = {
26258
26229
  if (!annotations)
26259
26230
  return;
26260
26231
  annotationLabel(
26261
- chart2 == null ? void 0 : chart2.ctx,
26232
+ chart2.ctx,
26262
26233
  annotations,
26263
- chart2 == null ? void 0 : chart2.scales
26234
+ chart2.scales
26264
26235
  );
26265
26236
  const pluginOptions = ((_d2 = (_c2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _c2.plugins) == null ? void 0 : _d2.annotationDraggerPlugin) || {
26266
26237
  enabled: false
@@ -26283,15 +26254,15 @@ const annotationDraggerPlugin = {
26283
26254
  };
26284
26255
  }
26285
26256
  },
26286
- afterRender(chart2) {
26287
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
26257
+ afterDraw(chart2) {
26258
+ var _a2, _b2, _c2, _d2;
26288
26259
  const { canvas: canvas2, scales, hoveredAnnotationId } = chart2;
26289
26260
  const pluginOptions = ((_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.annotationDraggerPlugin) || {
26290
26261
  enabled: false
26291
26262
  };
26292
26263
  const typedScales = { x: scales.x, y: scales.y };
26293
- let annotations = ((_e2 = (_d2 = (_c2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _c2.plugins) == null ? void 0 : _d2.annotation) == null ? void 0 : _e2.annotations) ?? {};
26294
- if (!annotations)
26264
+ let annotations = ((_d2 = (_c2 = chart2.options.plugins) == null ? void 0 : _c2.annotation) == null ? void 0 : _d2.annotations) ?? {};
26265
+ if (!chart2 && !annotations)
26295
26266
  return;
26296
26267
  let isDragging2 = false;
26297
26268
  let dragStartX, dragStartY;
@@ -26304,65 +26275,48 @@ const annotationDraggerPlugin = {
26304
26275
  dragStartY = startY;
26305
26276
  }
26306
26277
  };
26307
- if (!((_f2 = canvas2 == null ? void 0 : canvas2.dataset) == null ? void 0 : _f2.annotationDraggerInitialized) && (pluginOptions == null ? void 0 : pluginOptions.enabled) && hoveredAnnotationId) {
26308
- console.group("Condition");
26309
- console.log("addEventListener", (_g2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _g2.addEventListener);
26310
- console.log("nil", !isNil(canvas2));
26311
- console.log("isEmpty", !isEmpty(canvas2));
26312
- console.log("isFunction", isFunction$2(canvas2.addEventListener));
26313
- console.groupEnd();
26314
- if (!isNil(canvas2) && !isEmpty(canvas2) && isFunction$2(canvas2.addEventListener)) {
26315
- console.log("Canvas exists and has addEventListener:", canvas2);
26316
- canvas2.addEventListener(MouseEvents.MOUSEDOWN, (event) => {
26317
- var _a3, _b3, _c3;
26318
- handleAnnotationMouseDown(
26319
- event,
26320
- canvas2,
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
- });
26327
- canvas2.addEventListener(MouseEvents.MOUSEMOVE, (event) => {
26328
- handleAnnotationMouseMove(
26329
- event,
26330
- canvas2,
26331
- typedScales,
26332
- isDragging2,
26333
- activeAnnotation,
26334
- dragStartX,
26335
- dragStartY,
26336
- chart2
26337
- );
26338
- });
26339
- canvas2.addEventListener(MouseEvents.MOUSEUP, () => {
26340
- handleAnnotationMouseUp(
26341
- isDragging2,
26342
- activeAnnotation,
26343
- chart2,
26344
- setDraggingState
26345
- );
26346
- });
26347
- canvas2.dataset.annotationDraggerInitialized = "true";
26348
- } else {
26349
- console.error(
26350
- "Canvas is null, empty, or does not support addEventListener:",
26351
- canvas2
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
26352
26288
  );
26353
- }
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
26300
+ );
26301
+ });
26302
+ canvas2.addEventListener(MouseEvents.MOUSEUP, () => {
26303
+ handleAnnotationMouseUp(
26304
+ isDragging2,
26305
+ activeAnnotation,
26306
+ chart2,
26307
+ setDraggingState
26308
+ );
26309
+ });
26310
+ canvas2.dataset.annotationDraggerInitialized = "true";
26354
26311
  }
26355
26312
  if (!pluginOptions.enabled) {
26356
- if (canvas2 && isFunction$2(canvas2.removeEventListener)) {
26357
- console.log("Removing event listeners from canvas:", canvas2);
26358
- canvas2.removeEventListener(MouseEvents.MOUSEDOWN, () => {
26359
- });
26360
- canvas2.removeEventListener(MouseEvents.MOUSEMOVE, () => {
26361
- });
26362
- canvas2.removeEventListener(MouseEvents.MOUSEUP, () => {
26363
- });
26364
- canvas2.dataset.annotationDraggerInitialized = "";
26365
- }
26313
+ canvas2.removeEventListener(MouseEvents.MOUSEDOWN, () => {
26314
+ });
26315
+ canvas2.removeEventListener(MouseEvents.MOUSEMOVE, () => {
26316
+ });
26317
+ canvas2.removeEventListener(MouseEvents.MOUSEUP, () => {
26318
+ });
26319
+ canvas2.dataset.annotationDraggerInitialized = "";
26366
26320
  }
26367
26321
  }
26368
26322
  };