@oliasoft-open-source/charts-library 4.3.3-beta-10 → 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,15 +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
- console.log("chart?.canvas MOUSE UP", chart2 == null ? void 0 : chart2.canvas);
26216
- if (chart2 == null ? void 0 : chart2.canvas) {
26189
+ chart2.canvas.style.cursor = CursorStyle.Pointer;
26217
26190
  setDraggingState(false, null);
26218
- chart2 == null ? void 0 : chart2.update();
26219
26191
  }
26192
+ chart2.update();
26220
26193
  }
26221
26194
  };
26222
26195
  const annotationLabel = (ctx, annotations, scales) => {
@@ -26224,11 +26197,11 @@ const annotationLabel = (ctx, annotations, scales) => {
26224
26197
  var _a2;
26225
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)) {
26226
26199
  const { content, font, color: color2, position, padding } = (annotation2 == null ? void 0 : annotation2.label) ?? {};
26227
- ctx == null ? void 0 : ctx.save();
26200
+ ctx.save();
26228
26201
  ctx.font = font;
26229
26202
  ctx.fillStyle = color2;
26230
26203
  const { centerX = -1, centerY = -1 } = calculateAnnotationMetricsInValuesInPixels(annotation2, scales);
26231
- const textWidth = ctx == null ? void 0 : ctx.measureText(content).width;
26204
+ const textWidth = ctx.measureText(content).width;
26232
26205
  let textX = centerX - textWidth / 2;
26233
26206
  let textY = centerY + 20;
26234
26207
  switch (position) {
@@ -26244,8 +26217,8 @@ const annotationLabel = (ctx, annotations, scales) => {
26244
26217
  textY = centerY;
26245
26218
  break;
26246
26219
  }
26247
- ctx == null ? void 0 : ctx.fillText(content, textX, textY);
26248
- ctx == null ? void 0 : ctx.restore();
26220
+ ctx.fillText(content, textX, textY);
26221
+ ctx.restore();
26249
26222
  }
26250
26223
  });
26251
26224
  };
@@ -26257,9 +26230,9 @@ const annotationDraggerPlugin = {
26257
26230
  if (!annotations)
26258
26231
  return;
26259
26232
  annotationLabel(
26260
- chart2 == null ? void 0 : chart2.ctx,
26233
+ chart2.ctx,
26261
26234
  annotations,
26262
- chart2 == null ? void 0 : chart2.scales
26235
+ chart2.scales
26263
26236
  );
26264
26237
  const pluginOptions = ((_d2 = (_c2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _c2.plugins) == null ? void 0 : _d2.annotationDraggerPlugin) || {
26265
26238
  enabled: false
@@ -26282,14 +26255,15 @@ const annotationDraggerPlugin = {
26282
26255
  };
26283
26256
  }
26284
26257
  },
26285
- afterRender(chart2) {
26286
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2;
26258
+ afterUpdate(chart2) {
26259
+ var _a2, _b2, _c2, _d2;
26260
+ const { canvas: canvas2, scales, hoveredAnnotationId } = chart2;
26287
26261
  const pluginOptions = ((_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.annotationDraggerPlugin) || {
26288
26262
  enabled: false
26289
26263
  };
26290
- const typedScales = { x: (_c2 = chart2 == null ? void 0 : chart2.scales) == null ? void 0 : _c2.x, y: (_d2 = chart2 == null ? void 0 : chart2.scales) == null ? void 0 : _d2.y };
26291
- let annotations = ((_g2 = (_f2 = (_e2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _e2.plugins) == null ? void 0 : _f2.annotation) == null ? void 0 : _g2.annotations) ?? {};
26292
- if (!annotations)
26264
+ const typedScales = { x: scales.x, y: scales.y };
26265
+ let annotations = ((_d2 = (_c2 = chart2.options.plugins) == null ? void 0 : _c2.annotation) == null ? void 0 : _d2.annotations) ?? {};
26266
+ if (!chart2 && !annotations)
26293
26267
  return;
26294
26268
  let isDragging2 = false;
26295
26269
  let dragStartX, dragStartY;
@@ -26302,71 +26276,48 @@ const annotationDraggerPlugin = {
26302
26276
  dragStartY = startY;
26303
26277
  }
26304
26278
  };
26305
- if (!((_i2 = (_h2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _h2.dataset) == null ? void 0 : _i2.annotationDraggerInitialized) && (pluginOptions == null ? void 0 : pluginOptions.enabled) && (chart2 == null ? void 0 : chart2.hoveredAnnotationId)) {
26306
- console.group("Condition");
26307
- console.log("addEventListener", (_j2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _j2.addEventListener);
26308
- console.log("nil", !isNil(chart2 == null ? void 0 : chart2.canvas));
26309
- console.log("isEmpty", !isEmpty(chart2 == null ? void 0 : chart2.canvas));
26310
- console.log("isFunction", isFunction$2(chart2 == null ? void 0 : chart2.canvas.addEventListener));
26311
- console.groupEnd();
26312
- if (!isNil(chart2 == null ? void 0 : chart2.canvas) && !isEmpty(chart2 == null ? void 0 : chart2.canvas) && isFunction$2(chart2 == null ? void 0 : chart2.canvas.addEventListener)) {
26313
- console.log("Canvas exists and has addEventListener:", chart2 == null ? void 0 : chart2.canvas);
26314
- (_k2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _k2.addEventListener(
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
- }
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
26327
26289
  );
26328
- (_l2 = chart2 == null ? void 0 : chart2.canvas) == null ? void 0 : _l2.addEventListener(
26329
- MouseEvents.MOUSEMOVE,
26330
- (event) => {
26331
- handleAnnotationMouseMove(
26332
- event,
26333
- chart2 == null ? void 0 : chart2.canvas,
26334
- typedScales,
26335
- isDragging2,
26336
- activeAnnotation,
26337
- dragStartX,
26338
- dragStartY,
26339
- chart2
26340
- );
26341
- }
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
26342
26301
  );
26343
- chart2 == null ? void 0 : chart2.canvas.addEventListener(MouseEvents.MOUSEUP, () => {
26344
- handleAnnotationMouseUp(
26345
- isDragging2,
26346
- activeAnnotation,
26347
- chart2,
26348
- setDraggingState
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
26302
+ });
26303
+ canvas2.addEventListener(MouseEvents.MOUSEUP, () => {
26304
+ handleAnnotationMouseUp(
26305
+ isDragging2,
26306
+ activeAnnotation,
26307
+ chart2,
26308
+ setDraggingState
26356
26309
  );
26357
- }
26310
+ });
26311
+ canvas2.dataset.annotationDraggerInitialized = "true";
26358
26312
  }
26359
26313
  if (!pluginOptions.enabled) {
26360
- if ((chart2 == null ? void 0 : chart2.canvas) && isFunction$2(chart2 == null ? void 0 : chart2.canvas.removeEventListener)) {
26361
- console.log("Removing event listeners from canvas:", chart2 == null ? void 0 : chart2.canvas);
26362
- chart2 == null ? void 0 : chart2.canvas.removeEventListener(MouseEvents.MOUSEDOWN, () => {
26363
- });
26364
- chart2 == null ? void 0 : chart2.canvas.removeEventListener(MouseEvents.MOUSEMOVE, () => {
26365
- });
26366
- chart2 == null ? void 0 : chart2.canvas.removeEventListener(MouseEvents.MOUSEUP, () => {
26367
- });
26368
- chart2.canvas.dataset.annotationDraggerInitialized = "";
26369
- }
26314
+ canvas2.removeEventListener(MouseEvents.MOUSEDOWN, () => {
26315
+ });
26316
+ canvas2.removeEventListener(MouseEvents.MOUSEMOVE, () => {
26317
+ });
26318
+ canvas2.removeEventListener(MouseEvents.MOUSEUP, () => {
26319
+ });
26320
+ canvas2.dataset.annotationDraggerInitialized = "";
26370
26321
  }
26371
26322
  }
26372
26323
  };