@evergis/charts 2.0.63 → 2.0.65

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.
@@ -1987,7 +1987,7 @@ const barChartClassNames = /*#__PURE__*/_extends({
1987
1987
  barChartGridLineY: 'barChartGridLineY',
1988
1988
  barChartSelection: 'barChartSelection'
1989
1989
  }, tooltipClassnames, labelClassnames, barChartLinesClassNames);
1990
- const SvgWrapper$4 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$a || (_templateObject$a = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: ", ";\n user-select: ", ";\n cursor: ", ";\n \n line {\n stroke-width: 1px;\n shape-rendering: crispEdges;\n }\n \n .", ",\n .", " {\n stroke: rgba(48, 69, 79, 0.06);\n }\n \n .", " {\n }\n \n .", " {\n fill: none;\n pointer-events: all;\n }\n \n .", " {\n stroke-width: 1.5px;\n stroke-linejoin: round;\n stroke-linecap: round;\n }\n \n .", " {\n shape-rendering: auto;\n }\n \n .", " {\n fill-opacity: 0.24;\n }\n \n .", " {\n position: absolute;\n top: 0;\n width: 0;\n background: rgba(0, 170, 255, 0.06);\n box-shadow: 1px 0 0 #00AAFF, -1px 0 0 #00AAFF;\n pointer-events: none;\n }\n"])), _ref => {
1990
+ const SvgWrapper$4 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$a || (_templateObject$a = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: ", ";\n user-select: ", ";\n cursor: ", ";\n width: ", ";\n \n line {\n stroke-width: 1px;\n shape-rendering: crispEdges;\n }\n \n .", ",\n .", " {\n stroke: rgba(48, 69, 79, 0.06);\n }\n \n .", " {\n }\n \n .", " {\n fill: none;\n pointer-events: all;\n }\n \n .", " {\n stroke-width: 1.5px;\n stroke-linejoin: round;\n stroke-linecap: round;\n }\n \n .", " {\n shape-rendering: auto;\n }\n \n .", " {\n fill-opacity: 0.24;\n }\n \n .", " {\n position: absolute;\n top: 0;\n width: 0;\n background: rgba(0, 170, 255, 0.06);\n box-shadow: 1px 0 0 #00AAFF, -1px 0 0 #00AAFF;\n pointer-events: none;\n }\n"])), _ref => {
1991
1991
  let {
1992
1992
  selectable
1993
1993
  } = _ref;
@@ -2002,32 +2002,41 @@ const SvgWrapper$4 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$a ||
2002
2002
  selectable
2003
2003
  } = _ref3;
2004
2004
  return selectable && "crosshair";
2005
+ }, _ref4 => {
2006
+ let {
2007
+ selectable
2008
+ } = _ref4;
2009
+ return selectable && "auto";
2005
2010
  }, barChartClassNames.barChartGridLineX, barChartClassNames.barChartGridLineY, barChartClassNames.barChartMouseRect, barChartClassNames.barChartMouseRect, barChartClassNames.barChartLinesGlobal, barChartClassNames.barChartLine, barChartClassNames.barChartArea, barChartClassNames.barChartSelection);
2006
2011
  const TooltipStyles$1 = /*#__PURE__*/styled.createGlobalStyle(_templateObject2$4 || (_templateObject2$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n z-index: 1;\n transition: all linear 144ms;\n\n .", " {\n margin-bottom: 4px;\n :last-of-type {\n margin-bottom: 0;\n }\n }\n }\n"])), barChartClassNames.barChartMouseTooltip, barChartClassNames.barChartTooltipItem);
2007
2012
 
2008
2013
  const useSelection = (node, props) => {
2009
2014
  const drawing = React.useRef(false);
2010
2015
  const startX = React.useRef(0);
2011
- const selection = document.createElement("div");
2016
+ const selection = React.useRef();
2012
2017
  const onStartDrawing = React.useCallback(e => {
2013
2018
  const isTouch = Boolean(e.touches);
2014
2019
  e.stopPropagation();
2015
2020
 
2016
- if (node) {
2017
- var _e$touches$;
2021
+ if (node && e.which !== 3) {
2022
+ var _props$margin$bottom, _props$margin, _e$touches$;
2018
2023
 
2024
+ selection.current = document.createElement("div");
2025
+ selection.current.setAttribute("class", barChartClassNames.barChartSelection);
2026
+ selection.current.setAttribute("style", "height: calc(100% - " + ((_props$margin$bottom = (_props$margin = props.margin) == null ? void 0 : _props$margin.bottom) != null ? _props$margin$bottom : 0) + "px)");
2027
+ node.appendChild(selection.current);
2019
2028
  drawing.current = true;
2020
2029
  startX.current = isTouch ? ((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.pageX) - node.firstChild.getBoundingClientRect().left : e.offsetX;
2021
- selection.style.display = "block";
2022
- selection.style.width = "0px";
2023
- selection.style.left = startX.current + "px";
2030
+ selection.current.style.display = "block";
2031
+ selection.current.style.width = "0px";
2032
+ selection.current.style.left = startX.current + "px";
2024
2033
  }
2025
2034
  }, [node]);
2026
2035
  const onDraw = React.useCallback(e => {
2027
2036
  const isTouch = Boolean(e.touches);
2028
2037
  e.stopPropagation();
2029
2038
 
2030
- if (node && drawing.current) {
2039
+ if (node && drawing.current && selection.current) {
2031
2040
  var _e$touches$2;
2032
2041
 
2033
2042
  const nodeWidth = node.firstChild.getBoundingClientRect().width;
@@ -2036,42 +2045,47 @@ const useSelection = (node, props) => {
2036
2045
 
2037
2046
  if (offsetX >= 0) {
2038
2047
  if (newWidth > 0) {
2039
- selection.style.marginLeft = "0px";
2040
- selection.style.width = offsetX <= nodeWidth ? newWidth + "px" : nodeWidth - startX.current + "px";
2048
+ selection.current.style.marginLeft = "0px";
2049
+ selection.current.style.width = offsetX <= nodeWidth ? newWidth + "px" : nodeWidth - startX.current + "px";
2041
2050
  } else {
2042
- selection.style.right = nodeWidth - startX.current + "px";
2043
- selection.style.width = Math.abs(newWidth) + "px";
2044
- selection.style.marginLeft = newWidth + "px";
2051
+ selection.current.style.right = nodeWidth - startX.current + "px";
2052
+ selection.current.style.width = Math.abs(newWidth) + "px";
2053
+ selection.current.style.marginLeft = newWidth + "px";
2045
2054
  }
2046
2055
  }
2047
2056
 
2048
2057
  if (isTouch) {
2049
2058
  if (node.offsetLeft > e.touches[0].pageX) {
2050
- selection.style.right = nodeWidth - startX.current + "px";
2051
- selection.style.width = startX.current + "px";
2052
- selection.style.marginLeft = "-" + startX.current + "px";
2059
+ selection.current.style.right = nodeWidth - startX.current + "px";
2060
+ selection.current.style.width = startX.current + "px";
2061
+ selection.current.style.marginLeft = "-" + startX.current + "px";
2053
2062
  }
2054
2063
  }
2055
2064
  }
2056
2065
  }, [node]);
2057
- const onMouseMove = React.useCallback(e => {
2058
- if (drawing.current && node) {
2066
+ const onMouseLeave = React.useCallback(e => {
2067
+ if (drawing.current && node && selection.current) {
2059
2068
  if (node.offsetLeft > e.pageX) {
2060
2069
  const nodeWidth = node.firstChild.getBoundingClientRect().width;
2061
- selection.style.right = nodeWidth - startX.current + "px";
2062
- selection.style.width = startX.current + "px";
2063
- selection.style.marginLeft = "-" + startX.current + "px";
2070
+ selection.current.style.right = nodeWidth - startX.current + "px";
2071
+ selection.current.style.width = startX.current + "px";
2072
+ selection.current.style.marginLeft = "-" + startX.current + "px";
2073
+ }
2074
+
2075
+ if (node.offsetLeft + node.offsetWidth < e.pageX) {
2076
+ const nodeWidth = node.firstChild.getBoundingClientRect().width;
2077
+ selection.current.style.left = startX.current + "px";
2078
+ selection.current.style.width = nodeWidth - startX.current + "px";
2079
+ selection.current.style.marginLeft = "0px";
2064
2080
  }
2065
2081
  }
2066
2082
  }, [node]);
2067
- const onStopDrawing = React.useCallback(e => {
2068
- e.stopPropagation();
2069
-
2070
- if (node) {
2083
+ const onStopDrawing = React.useCallback(() => {
2084
+ if (node && selection.current) {
2071
2085
  const nodeWidth = node.firstChild.getBoundingClientRect().width;
2072
- const selectionMinX = selection.offsetLeft >= 0 ? selection.offsetLeft <= nodeWidth ? selection.offsetLeft : nodeWidth : 0;
2073
- const selectionWidth = selection.getBoundingClientRect().right - selection.getBoundingClientRect().left;
2074
- const selectionMaxX = selection.offsetLeft + selectionWidth <= nodeWidth ? selection.offsetLeft + selectionWidth >= 0 ? selection.offsetLeft + selectionWidth : 0 : nodeWidth;
2086
+ const selectionMinX = selection.current.offsetLeft >= 0 ? selection.current.offsetLeft <= nodeWidth ? selection.current.offsetLeft : nodeWidth : 0;
2087
+ const selectionWidth = selection.current.getBoundingClientRect().right - selection.current.getBoundingClientRect().left;
2088
+ const selectionMaxX = selection.current.offsetLeft + selectionWidth <= nodeWidth ? selection.current.offsetLeft + selectionWidth >= 0 ? selection.current.offsetLeft + selectionWidth : 0 : nodeWidth;
2075
2089
  const min = Math.round(selectionMinX);
2076
2090
  const max = Math.round(selectionMaxX);
2077
2091
 
@@ -2080,27 +2094,23 @@ const useSelection = (node, props) => {
2080
2094
  }
2081
2095
 
2082
2096
  drawing.current = false;
2083
- selection.style.display = "none";
2097
+ node.removeChild(selection.current);
2098
+ selection.current = undefined;
2084
2099
  }
2085
2100
  }, [node]);
2086
2101
  React.useEffect(() => {
2087
2102
  if (node) {
2088
- var _props$margin$bottom, _props$margin;
2089
-
2090
- selection.setAttribute("class", barChartClassNames.barChartSelection);
2091
- selection.setAttribute("style", "height: calc(100% - " + ((_props$margin$bottom = (_props$margin = props.margin) == null ? void 0 : _props$margin.bottom) != null ? _props$margin$bottom : 0) + "px)");
2092
- selection.style.display = "none";
2093
2103
  node.childNodes.forEach(child => {
2094
2104
  child.style.userSelect = "none";
2095
2105
  });
2096
- node.appendChild(selection);
2097
2106
  node.addEventListener("mousedown", onStartDrawing);
2098
2107
  node.addEventListener("touchstart", onStartDrawing);
2099
2108
  node.addEventListener("mousemove", onDraw);
2100
2109
  node.addEventListener("touchmove", onDraw);
2101
- document.addEventListener("mousemove", onMouseMove);
2110
+ node.addEventListener("mouseleave", onMouseLeave);
2111
+ node.addEventListener("mouseup", onStopDrawing);
2112
+ node.addEventListener("touchend", onStopDrawing);
2102
2113
  document.addEventListener("mouseup", onStopDrawing);
2103
- document.addEventListener("touchend", onStopDrawing);
2104
2114
  }
2105
2115
 
2106
2116
  return () => {
@@ -2108,9 +2118,10 @@ const useSelection = (node, props) => {
2108
2118
  node == null ? void 0 : node.removeEventListener("touchstart", onStartDrawing);
2109
2119
  node == null ? void 0 : node.removeEventListener("mousemove", onDraw);
2110
2120
  node == null ? void 0 : node.removeEventListener("touchmove", onDraw);
2111
- document.removeEventListener("mousemove", onMouseMove);
2121
+ node == null ? void 0 : node.removeEventListener("mouseleave", onMouseLeave);
2122
+ node == null ? void 0 : node.removeEventListener("mouseup", onStopDrawing);
2123
+ node == null ? void 0 : node.removeEventListener("touchend", onStopDrawing);
2112
2124
  document.removeEventListener("mouseup", onStopDrawing);
2113
- document.removeEventListener("touchend", onStopDrawing);
2114
2125
  };
2115
2126
  }, [node]);
2116
2127
  };