@evergis/charts 2.0.64 → 2.0.66

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.
@@ -1979,7 +1979,7 @@ const barChartClassNames = /*#__PURE__*/_extends({
1979
1979
  barChartGridLineY: 'barChartGridLineY',
1980
1980
  barChartSelection: 'barChartSelection'
1981
1981
  }, tooltipClassnames, labelClassnames, barChartLinesClassNames);
1982
- const SvgWrapper$4 = /*#__PURE__*/styled(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 => {
1982
+ const SvgWrapper$4 = /*#__PURE__*/styled(Wrapper)(_templateObject$a || (_templateObject$a = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: ", ";\n user-select: ", ";\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 => {
1983
1983
  let {
1984
1984
  selectable
1985
1985
  } = _ref;
@@ -1993,11 +1993,6 @@ const SvgWrapper$4 = /*#__PURE__*/styled(Wrapper)(_templateObject$a || (_templat
1993
1993
  let {
1994
1994
  selectable
1995
1995
  } = _ref3;
1996
- return selectable && "crosshair";
1997
- }, _ref4 => {
1998
- let {
1999
- selectable
2000
- } = _ref4;
2001
1996
  return selectable && "auto";
2002
1997
  }, barChartClassNames.barChartGridLineX, barChartClassNames.barChartGridLineY, barChartClassNames.barChartMouseRect, barChartClassNames.barChartMouseRect, barChartClassNames.barChartLinesGlobal, barChartClassNames.barChartLine, barChartClassNames.barChartArea, barChartClassNames.barChartSelection);
2003
1998
  const TooltipStyles$1 = /*#__PURE__*/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);
@@ -2005,26 +2000,30 @@ const TooltipStyles$1 = /*#__PURE__*/createGlobalStyle(_templateObject2$4 || (_t
2005
2000
  const useSelection = (node, props) => {
2006
2001
  const drawing = useRef(false);
2007
2002
  const startX = useRef(0);
2008
- const selection = document.createElement("div");
2003
+ const selection = useRef();
2009
2004
  const onStartDrawing = useCallback(e => {
2010
2005
  const isTouch = Boolean(e.touches);
2011
2006
  e.stopPropagation();
2012
2007
 
2013
- if (node) {
2014
- var _e$touches$;
2008
+ if (node && e.which !== 3) {
2009
+ var _props$margin$bottom, _props$margin, _e$touches$;
2015
2010
 
2011
+ selection.current = document.createElement("div");
2012
+ selection.current.setAttribute("class", barChartClassNames.barChartSelection);
2013
+ 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)");
2014
+ node.appendChild(selection.current);
2016
2015
  drawing.current = true;
2017
2016
  startX.current = isTouch ? ((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.pageX) - node.firstChild.getBoundingClientRect().left : e.offsetX;
2018
- selection.style.display = "block";
2019
- selection.style.width = "0px";
2020
- selection.style.left = startX.current + "px";
2017
+ selection.current.style.display = "block";
2018
+ selection.current.style.width = "0px";
2019
+ selection.current.style.left = startX.current + "px";
2021
2020
  }
2022
2021
  }, [node]);
2023
2022
  const onDraw = useCallback(e => {
2024
2023
  const isTouch = Boolean(e.touches);
2025
2024
  e.stopPropagation();
2026
2025
 
2027
- if (node && drawing.current) {
2026
+ if (node && drawing.current && selection.current) {
2028
2027
  var _e$touches$2;
2029
2028
 
2030
2029
  const nodeWidth = node.firstChild.getBoundingClientRect().width;
@@ -2033,47 +2032,47 @@ const useSelection = (node, props) => {
2033
2032
 
2034
2033
  if (offsetX >= 0) {
2035
2034
  if (newWidth > 0) {
2036
- selection.style.marginLeft = "0px";
2037
- selection.style.width = offsetX <= nodeWidth ? newWidth + "px" : nodeWidth - startX.current + "px";
2035
+ selection.current.style.marginLeft = "0px";
2036
+ selection.current.style.width = offsetX <= nodeWidth ? newWidth + "px" : nodeWidth - startX.current + "px";
2038
2037
  } else {
2039
- selection.style.right = nodeWidth - startX.current + "px";
2040
- selection.style.width = Math.abs(newWidth) + "px";
2041
- selection.style.marginLeft = newWidth + "px";
2038
+ selection.current.style.right = nodeWidth - startX.current + "px";
2039
+ selection.current.style.width = Math.abs(newWidth) + "px";
2040
+ selection.current.style.marginLeft = newWidth + "px";
2042
2041
  }
2043
2042
  }
2044
2043
 
2045
2044
  if (isTouch) {
2046
2045
  if (node.offsetLeft > e.touches[0].pageX) {
2047
- selection.style.right = nodeWidth - startX.current + "px";
2048
- selection.style.width = startX.current + "px";
2049
- selection.style.marginLeft = "-" + startX.current + "px";
2046
+ selection.current.style.right = nodeWidth - startX.current + "px";
2047
+ selection.current.style.width = startX.current + "px";
2048
+ selection.current.style.marginLeft = "-" + startX.current + "px";
2050
2049
  }
2051
2050
  }
2052
2051
  }
2053
2052
  }, [node]);
2054
2053
  const onMouseLeave = useCallback(e => {
2055
- if (drawing.current && node) {
2054
+ if (drawing.current && node && selection.current) {
2056
2055
  if (node.offsetLeft > e.pageX) {
2057
2056
  const nodeWidth = node.firstChild.getBoundingClientRect().width;
2058
- selection.style.right = nodeWidth - startX.current + "px";
2059
- selection.style.width = startX.current + "px";
2060
- selection.style.marginLeft = "-" + startX.current + "px";
2057
+ selection.current.style.right = nodeWidth - startX.current + "px";
2058
+ selection.current.style.width = startX.current + "px";
2059
+ selection.current.style.marginLeft = "-" + startX.current + "px";
2061
2060
  }
2062
2061
 
2063
2062
  if (node.offsetLeft + node.offsetWidth < e.pageX) {
2064
2063
  const nodeWidth = node.firstChild.getBoundingClientRect().width;
2065
- selection.style.left = startX.current + "px";
2066
- selection.style.width = nodeWidth - startX.current + "px";
2067
- selection.style.marginLeft = "0px";
2064
+ selection.current.style.left = startX.current + "px";
2065
+ selection.current.style.width = nodeWidth - startX.current + "px";
2066
+ selection.current.style.marginLeft = "0px";
2068
2067
  }
2069
2068
  }
2070
2069
  }, [node]);
2071
2070
  const onStopDrawing = useCallback(() => {
2072
- if (node) {
2071
+ if (node && selection.current) {
2073
2072
  const nodeWidth = node.firstChild.getBoundingClientRect().width;
2074
- const selectionMinX = selection.offsetLeft >= 0 ? selection.offsetLeft <= nodeWidth ? selection.offsetLeft : nodeWidth : 0;
2075
- const selectionWidth = selection.getBoundingClientRect().right - selection.getBoundingClientRect().left;
2076
- const selectionMaxX = selection.offsetLeft + selectionWidth <= nodeWidth ? selection.offsetLeft + selectionWidth >= 0 ? selection.offsetLeft + selectionWidth : 0 : nodeWidth;
2073
+ const selectionMinX = selection.current.offsetLeft >= 0 ? selection.current.offsetLeft <= nodeWidth ? selection.current.offsetLeft : nodeWidth : 0;
2074
+ const selectionWidth = selection.current.getBoundingClientRect().right - selection.current.getBoundingClientRect().left;
2075
+ const selectionMaxX = selection.current.offsetLeft + selectionWidth <= nodeWidth ? selection.current.offsetLeft + selectionWidth >= 0 ? selection.current.offsetLeft + selectionWidth : 0 : nodeWidth;
2077
2076
  const min = Math.round(selectionMinX);
2078
2077
  const max = Math.round(selectionMaxX);
2079
2078
 
@@ -2082,20 +2081,15 @@ const useSelection = (node, props) => {
2082
2081
  }
2083
2082
 
2084
2083
  drawing.current = false;
2085
- selection.style.display = "none";
2084
+ node.removeChild(selection.current);
2085
+ selection.current = undefined;
2086
2086
  }
2087
2087
  }, [node]);
2088
2088
  useEffect(() => {
2089
2089
  if (node) {
2090
- var _props$margin$bottom, _props$margin;
2091
-
2092
- selection.setAttribute("class", barChartClassNames.barChartSelection);
2093
- 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)");
2094
- selection.style.display = "none";
2095
2090
  node.childNodes.forEach(child => {
2096
2091
  child.style.userSelect = "none";
2097
2092
  });
2098
- node.appendChild(selection);
2099
2093
  node.addEventListener("mousedown", onStartDrawing);
2100
2094
  node.addEventListener("touchstart", onStartDrawing);
2101
2095
  node.addEventListener("mousemove", onDraw);