@oliasoft-open-source/charts-library 4.3.3-beta-9 → 4.3.3

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();
@@ -25494,6 +25477,7 @@ const generateAnnotations = (annotationsData) => {
25494
25477
  const onDragEnd = () => (cord, annotation2) => (ann == null ? void 0 : ann.onDragEnd) ? ann == null ? void 0 : ann.onDragEnd(cord, annotation2) : void 0;
25495
25478
  return {
25496
25479
  ...ann,
25480
+ drawTime: "afterDraw",
25497
25481
  display: ann == null ? void 0 : ann.display,
25498
25482
  annotationIndex: idx,
25499
25483
  id: `${ann == null ? void 0 : ann.label}-${ann == null ? void 0 : ann.value}-${idx}`,
@@ -25826,13 +25810,13 @@ const useToggleCustomLegendVisibility = (memoState, memoOptions) => {
25826
25810
  const parent = document.getElementById(
25827
25811
  memoOptions.legend.customLegend.customLegendContainerID
25828
25812
  );
25829
- if (!isNil(parent)) {
25813
+ if (parent !== null) {
25830
25814
  parent.style.visibility = memoState.legendEnabled ? "visible" : "hidden";
25831
25815
  }
25832
25816
  }
25833
25817
  }, [
25834
25818
  (_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
25819
+ memoState.legendEnabled
25836
25820
  ]);
25837
25821
  };
25838
25822
  const useStoreChartStateInStorage = (memoState, persistenceId) => {
@@ -26129,16 +26113,13 @@ const calculateAnnotationMetricsInValuesInPixels = (annotation2, scales) => {
26129
26113
  };
26130
26114
  };
26131
26115
  const handleAnnotationMouseDown = (event, canvas2, scales, annotations, setDraggingState, hoveredAnnotationId) => {
26132
- var _a2;
26133
26116
  const { x: x2, y: y2 } = getMousePositionInCoordinates(event, canvas2, scales);
26134
26117
  const annotation2 = hoveredAnnotationId ? annotations == null ? void 0 : annotations[hoveredAnnotationId] : null;
26135
26118
  if (!annotation2)
26136
26119
  return;
26137
26120
  const metrics = calculateAnnotationMetricsInValues(annotation2);
26138
26121
  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
- }
26122
+ canvas2.style.cursor = CursorStyle.Move;
26142
26123
  const dragStartX = x2 - metrics.centerX;
26143
26124
  const dragStartY = y2 - metrics.centerY;
26144
26125
  setDraggingState(true, annotation2, dragStartX, dragStartY);
@@ -26148,11 +26129,8 @@ const handleAnnotationMouseDown = (event, canvas2, scales, annotations, setDragg
26148
26129
  }
26149
26130
  };
26150
26131
  const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAnnotation, dragStartX, dragStartY, chart2) => {
26151
- var _a2;
26152
26132
  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
- }
26133
+ canvas2.style.cursor = CursorStyle.Move;
26156
26134
  const { x: x2, y: y2 } = getMousePositionInCoordinates(event, canvas2, scales);
26157
26135
  const metrics = calculateAnnotationMetricsInValues(activeAnnotation);
26158
26136
  let newCenterX = x2 - dragStartX;
@@ -26170,6 +26148,7 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
26170
26148
  activeAnnotation.yMax = newCenterY + metrics.height / 2;
26171
26149
  }
26172
26150
  }
26151
+ chart2.update();
26173
26152
  if (activeAnnotation == null ? void 0 : activeAnnotation.onDrag) {
26174
26153
  activeAnnotation.onDrag({ x: x2, y: y2 }, cloneDeep(activeAnnotation));
26175
26154
  }
@@ -26177,9 +26156,9 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
26177
26156
  const { centerX, centerY } = calculateAnnotationMetricsInValues(activeAnnotation) ?? {};
26178
26157
  const { centerX: xValue, centerY: yValue } = calculateAnnotationMetricsInValuesInPixels(activeAnnotation, scales);
26179
26158
  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();
26159
+ ctx.save();
26160
+ ctx.clearRect(0, 0, width, height);
26161
+ chart2.draw();
26183
26162
  ctx.font = DEFAULT_FONT_FAMILY;
26184
26163
  ctx.fillStyle = "black";
26185
26164
  let labelX = xValue - 45;
@@ -26192,13 +26171,12 @@ const handleAnnotationMouseMove = (event, canvas2, scales, isDragging2, activeAn
26192
26171
  if (labelY > height) {
26193
26172
  labelY = height - 7;
26194
26173
  }
26195
- ctx == null ? void 0 : ctx.fillText(labelText, labelX, labelY);
26196
- ctx == null ? void 0 : ctx.restore();
26174
+ ctx.fillText(labelText, labelX, labelY);
26175
+ ctx.restore();
26197
26176
  }
26198
26177
  }
26199
26178
  };
26200
26179
  const handleAnnotationMouseUp = (isDragging2, activeAnnotation, chart2, setDraggingState) => {
26201
- var _a2, _b2;
26202
26180
  if (isDragging2) {
26203
26181
  if (activeAnnotation) {
26204
26182
  const { centerX = -1, centerY = -1 } = calculateAnnotationMetricsInValues(activeAnnotation) ?? {};
@@ -26208,16 +26186,10 @@ const handleAnnotationMouseUp = (isDragging2, activeAnnotation, chart2, setDragg
26208
26186
  cloneDeep(activeAnnotation)
26209
26187
  );
26210
26188
  }
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) {
26189
+ chart2.canvas.style.cursor = CursorStyle.Pointer;
26216
26190
  setDraggingState(false, null);
26217
- chart2 == null ? void 0 : chart2.update();
26218
- } else {
26219
- console.error("Canvas is not available during mouse up");
26220
26191
  }
26192
+ chart2.update();
26221
26193
  }
26222
26194
  };
26223
26195
  const annotationLabel = (ctx, annotations, scales) => {
@@ -26225,11 +26197,11 @@ const annotationLabel = (ctx, annotations, scales) => {
26225
26197
  var _a2;
26226
26198
  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
26199
  const { content, font, color: color2, position, padding } = (annotation2 == null ? void 0 : annotation2.label) ?? {};
26228
- ctx == null ? void 0 : ctx.save();
26200
+ ctx.save();
26229
26201
  ctx.font = font;
26230
26202
  ctx.fillStyle = color2;
26231
26203
  const { centerX = -1, centerY = -1 } = calculateAnnotationMetricsInValuesInPixels(annotation2, scales);
26232
- const textWidth = ctx == null ? void 0 : ctx.measureText(content).width;
26204
+ const textWidth = ctx.measureText(content).width;
26233
26205
  let textX = centerX - textWidth / 2;
26234
26206
  let textY = centerY + 20;
26235
26207
  switch (position) {
@@ -26245,8 +26217,8 @@ const annotationLabel = (ctx, annotations, scales) => {
26245
26217
  textY = centerY;
26246
26218
  break;
26247
26219
  }
26248
- ctx == null ? void 0 : ctx.fillText(content, textX, textY);
26249
- ctx == null ? void 0 : ctx.restore();
26220
+ ctx.fillText(content, textX, textY);
26221
+ ctx.restore();
26250
26222
  }
26251
26223
  });
26252
26224
  };
@@ -26258,9 +26230,9 @@ const annotationDraggerPlugin = {
26258
26230
  if (!annotations)
26259
26231
  return;
26260
26232
  annotationLabel(
26261
- chart2 == null ? void 0 : chart2.ctx,
26233
+ chart2.ctx,
26262
26234
  annotations,
26263
- chart2 == null ? void 0 : chart2.scales
26235
+ chart2.scales
26264
26236
  );
26265
26237
  const pluginOptions = ((_d2 = (_c2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _c2.plugins) == null ? void 0 : _d2.annotationDraggerPlugin) || {
26266
26238
  enabled: false
@@ -26283,15 +26255,15 @@ const annotationDraggerPlugin = {
26283
26255
  };
26284
26256
  }
26285
26257
  },
26286
- afterRender(chart2) {
26287
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
26258
+ afterUpdate(chart2) {
26259
+ var _a2, _b2, _c2, _d2;
26288
26260
  const { canvas: canvas2, scales, hoveredAnnotationId } = chart2;
26289
26261
  const pluginOptions = ((_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.annotationDraggerPlugin) || {
26290
26262
  enabled: false
26291
26263
  };
26292
26264
  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)
26265
+ let annotations = ((_d2 = (_c2 = chart2.options.plugins) == null ? void 0 : _c2.annotation) == null ? void 0 : _d2.annotations) ?? {};
26266
+ if (!chart2 && !annotations)
26295
26267
  return;
26296
26268
  let isDragging2 = false;
26297
26269
  let dragStartX, dragStartY;
@@ -26304,65 +26276,48 @@ const annotationDraggerPlugin = {
26304
26276
  dragStartY = startY;
26305
26277
  }
26306
26278
  };
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
26279
+ if (!canvas2.dataset.annotationDraggerInitialized && pluginOptions.enabled && hoveredAnnotationId) {
26280
+ canvas2.addEventListener(MouseEvents.MOUSEDOWN, (event) => {
26281
+ var _a3, _b3, _c3;
26282
+ handleAnnotationMouseDown(
26283
+ event,
26284
+ canvas2,
26285
+ typedScales,
26286
+ (_c3 = (_b3 = (_a3 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a3.plugins) == null ? void 0 : _b3.annotation) == null ? void 0 : _c3.annotations,
26287
+ setDraggingState,
26288
+ chart2.hoveredAnnotationId
26352
26289
  );
26353
- }
26290
+ });
26291
+ canvas2.addEventListener(MouseEvents.MOUSEMOVE, (event) => {
26292
+ handleAnnotationMouseMove(
26293
+ event,
26294
+ canvas2,
26295
+ typedScales,
26296
+ isDragging2,
26297
+ activeAnnotation,
26298
+ dragStartX,
26299
+ dragStartY,
26300
+ chart2
26301
+ );
26302
+ });
26303
+ canvas2.addEventListener(MouseEvents.MOUSEUP, () => {
26304
+ handleAnnotationMouseUp(
26305
+ isDragging2,
26306
+ activeAnnotation,
26307
+ chart2,
26308
+ setDraggingState
26309
+ );
26310
+ });
26311
+ canvas2.dataset.annotationDraggerInitialized = "true";
26354
26312
  }
26355
26313
  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
- }
26314
+ canvas2.removeEventListener(MouseEvents.MOUSEDOWN, () => {
26315
+ });
26316
+ canvas2.removeEventListener(MouseEvents.MOUSEMOVE, () => {
26317
+ });
26318
+ canvas2.removeEventListener(MouseEvents.MOUSEUP, () => {
26319
+ });
26320
+ canvas2.dataset.annotationDraggerInitialized = "";
26366
26321
  }
26367
26322
  }
26368
26323
  };