@oliasoft-open-source/charts-library 4.3.0-beta-1 → 4.3.0-beta-2

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, debounce as debounce$3, 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
@@ -25195,21 +25195,25 @@ const annotationEnter = (element, chart2) => {
25195
25195
  }
25196
25196
  }
25197
25197
  element.options.borderWidth = BORDER_WIDTH.HOVERED;
25198
+ chart2.hoveredAnnotationId = element.options.id || null;
25198
25199
  if (element.options.label) {
25199
25200
  element.label.options.display = true;
25200
25201
  element.options.label.enabled = true;
25201
25202
  }
25202
25203
  chart2.draw();
25204
+ chart2.update();
25203
25205
  chart2.canvas.style.cursor = CursorStyle.Pointer;
25204
25206
  return true;
25205
25207
  };
25206
25208
  const annotationLeave = (element, chart2) => {
25207
25209
  element.options.borderWidth = BORDER_WIDTH.INITIAL;
25210
+ chart2.hoveredAnnotationId = null;
25208
25211
  if (element.options.label) {
25209
25212
  element.label.options.display = false;
25210
25213
  element.options.label.enabled = false;
25211
25214
  }
25212
25215
  chart2.draw();
25216
+ chart2.update();
25213
25217
  chart2.canvas.style.cursor = CursorStyle.Initial;
25214
25218
  return true;
25215
25219
  };
@@ -25838,31 +25842,18 @@ const getMousePositionInCoordinates = (event, canvas2, scales) => {
25838
25842
  const yValue = ((_b2 = scales == null ? void 0 : scales.y) == null ? void 0 : _b2.getValueForPixel(y2)) ?? -1;
25839
25843
  return { x: xValue, y: yValue };
25840
25844
  };
25841
- const getActiveAnnotation = (x2, y2, annotations) => {
25842
- var _a2;
25843
- return ((_a2 = Object.values(annotations)) == null ? void 0 : _a2.find((annotation2) => {
25844
- const { xMin, xMax, yMin, yMax, xValue, yValue } = annotation2 ?? {};
25845
- let condtion;
25846
- if (xMin && xMax && yMin && yMax && (annotation2 == null ? void 0 : annotation2.type) === AnnotationType.BOX) {
25847
- condtion = x2 >= xMin && x2 <= xMax && y2 >= yMin && y2 <= yMax;
25848
- } else if (xValue && yValue && (annotation2 == null ? void 0 : annotation2.type) === AnnotationType.POINT) {
25849
- condtion = x2 >= xValue - 2 && x2 <= xValue + 2 && y2 >= yValue - 2 && y2 <= yValue + 2;
25850
- }
25851
- return condtion;
25852
- })) ?? {};
25853
- };
25854
25845
  const calculateAnnotationMetricsInValues = (annotation2) => {
25855
25846
  const { xMin, xMax, yMin, yMax, xValue, yValue, type } = annotation2 ?? {};
25856
25847
  let centerX;
25857
25848
  let centerY;
25858
25849
  let width;
25859
25850
  let height;
25860
- if (xMin && xMax && yMin && yMax && type === AnnotationType.BOX) {
25851
+ if (!isNil(xMin) && !isNil(xMax) && !isNil(yMin) && !isNil(yMax) && type === AnnotationType.BOX) {
25861
25852
  centerX = (xMin + xMax) / 2;
25862
25853
  centerY = (yMin + yMax) / 2;
25863
25854
  width = xMax - xMin;
25864
25855
  height = yMax - yMin;
25865
- } else if (xValue && yValue && type === AnnotationType.POINT) {
25856
+ } else if (!isNil(xValue) && !isNil(yValue) && type === AnnotationType.POINT) {
25866
25857
  centerX = xValue;
25867
25858
  centerY = yValue;
25868
25859
  width = 0;
@@ -25876,14 +25867,13 @@ const calculateAnnotationMetricsInValues = (annotation2) => {
25876
25867
  };
25877
25868
  };
25878
25869
  const calculateAnnotationMetricsInValuesInPixels = (annotation2, scales) => {
25879
- var _a2, _b2, _c2, _d2;
25880
25870
  const { xMin, xMax, yMin, yMax, xValue, yValue, type } = annotation2 ?? {};
25881
25871
  const { x: x2, y: y2 } = scales ?? {};
25882
25872
  let centerX;
25883
25873
  let centerY;
25884
25874
  let width;
25885
25875
  let height;
25886
- if (xMin && xMax && yMin && yMax && type === AnnotationType.BOX) {
25876
+ if (!isNil(xMin) && !isNil(xMax) && !isNil(yMin) && !isNil(yMax) && type === AnnotationType.BOX) {
25887
25877
  const xCenterValue = (xMin + xMax) / 2;
25888
25878
  const yCenterValue = (yMin + yMax) / 2;
25889
25879
  const xMinValue = (x2 == null ? void 0 : x2.getPixelForValue(xMin)) ?? 0;
@@ -25892,13 +25882,13 @@ const calculateAnnotationMetricsInValuesInPixels = (annotation2, scales) => {
25892
25882
  const yMaxValue = (y2 == null ? void 0 : y2.getPixelForValue(yMax)) ?? 0;
25893
25883
  width = xMinValue - xMaxValue;
25894
25884
  height = yMinValue - yMaxValue;
25895
- centerX = ((_a2 = scales == null ? void 0 : scales.x) == null ? void 0 : _a2.getPixelForValue(xCenterValue)) ?? -1;
25896
- centerY = ((_b2 = scales == null ? void 0 : scales.y) == null ? void 0 : _b2.getPixelForValue(yCenterValue)) ?? -1;
25897
- } else if (xValue && yValue && type === AnnotationType.POINT) {
25885
+ centerX = (x2 == null ? void 0 : x2.getPixelForValue(xCenterValue)) ?? -1;
25886
+ centerY = (y2 == null ? void 0 : y2.getPixelForValue(yCenterValue)) ?? -1;
25887
+ } else if (!isNil(xValue) && !isNil(yValue) && type === AnnotationType.POINT) {
25898
25888
  width = 0;
25899
25889
  height = 0;
25900
- centerX = ((_c2 = scales == null ? void 0 : scales.x) == null ? void 0 : _c2.getPixelForValue(xValue)) ?? -1;
25901
- centerY = ((_d2 = scales == null ? void 0 : scales.y) == null ? void 0 : _d2.getPixelForValue(yValue)) ?? -1;
25890
+ centerX = (x2 == null ? void 0 : x2.getPixelForValue(xValue)) ?? -1;
25891
+ centerY = (y2 == null ? void 0 : y2.getPixelForValue(yValue)) ?? -1;
25902
25892
  }
25903
25893
  return {
25904
25894
  centerX,
@@ -25907,12 +25897,12 @@ const calculateAnnotationMetricsInValuesInPixels = (annotation2, scales) => {
25907
25897
  height
25908
25898
  };
25909
25899
  };
25910
- const handleAnnotationMouseDown = (event, canvas2, scales, annotations, setDraggingState) => {
25900
+ const handleAnnotationMouseDown = (event, canvas2, scales, annotations, setDraggingState, hoveredAnnotationId) => {
25911
25901
  const { x: x2, y: y2 } = getMousePositionInCoordinates(event, canvas2, scales);
25912
- const annotation2 = getActiveAnnotation(x2, y2, annotations);
25902
+ const annotation2 = hoveredAnnotationId ? annotations == null ? void 0 : annotations[hoveredAnnotationId] : null;
25903
+ if (!annotation2)
25904
+ return;
25913
25905
  const metrics = calculateAnnotationMetricsInValues(annotation2);
25914
- console.log(cloneDeep(annotations));
25915
- console.log(metrics);
25916
25906
  if (annotation2 && annotation2.enableDrag && metrics.centerY && metrics.centerX) {
25917
25907
  const dragStartX = x2 - metrics.centerX;
25918
25908
  const dragStartY = y2 - metrics.centerY;
@@ -25985,7 +25975,7 @@ const annotationDraggerPlugin = {
25985
25975
  id: "annotationDraggerPlugin",
25986
25976
  afterUpdate(chart2) {
25987
25977
  var _a2, _b2, _c2, _d2;
25988
- const { canvas: canvas2, scales } = chart2;
25978
+ const { canvas: canvas2, scales, hoveredAnnotationId } = chart2;
25989
25979
  const pluginOptions = ((_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.annotationDraggerPlugin) || {
25990
25980
  enabled: false
25991
25981
  };
@@ -26004,14 +25994,15 @@ const annotationDraggerPlugin = {
26004
25994
  dragStartY = startY;
26005
25995
  }
26006
25996
  };
26007
- if (!canvas2.dataset.annotationDraggerInitialized && pluginOptions.enabled) {
25997
+ if (!canvas2.dataset.annotationDraggerInitialized && pluginOptions.enabled && hoveredAnnotationId) {
26008
25998
  canvas2.addEventListener(MouseEvents.MOUSEDOWN, (event) => {
26009
25999
  handleAnnotationMouseDown(
26010
26000
  event,
26011
26001
  canvas2,
26012
26002
  typedScales,
26013
26003
  annotations,
26014
- setDraggingState
26004
+ setDraggingState,
26005
+ chart2.hoveredAnnotationId
26015
26006
  );
26016
26007
  });
26017
26008
  canvas2.addEventListener(MouseEvents.MOUSEMOVE, (event) => {