@evergis/charts 2.0.64 → 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.
|
@@ -2013,26 +2013,30 @@ const TooltipStyles$1 = /*#__PURE__*/styled.createGlobalStyle(_templateObject2$4
|
|
|
2013
2013
|
const useSelection = (node, props) => {
|
|
2014
2014
|
const drawing = React.useRef(false);
|
|
2015
2015
|
const startX = React.useRef(0);
|
|
2016
|
-
const selection =
|
|
2016
|
+
const selection = React.useRef();
|
|
2017
2017
|
const onStartDrawing = React.useCallback(e => {
|
|
2018
2018
|
const isTouch = Boolean(e.touches);
|
|
2019
2019
|
e.stopPropagation();
|
|
2020
2020
|
|
|
2021
|
-
if (node) {
|
|
2022
|
-
var _e$touches$;
|
|
2021
|
+
if (node && e.which !== 3) {
|
|
2022
|
+
var _props$margin$bottom, _props$margin, _e$touches$;
|
|
2023
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);
|
|
2024
2028
|
drawing.current = true;
|
|
2025
2029
|
startX.current = isTouch ? ((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.pageX) - node.firstChild.getBoundingClientRect().left : e.offsetX;
|
|
2026
|
-
selection.style.display = "block";
|
|
2027
|
-
selection.style.width = "0px";
|
|
2028
|
-
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";
|
|
2029
2033
|
}
|
|
2030
2034
|
}, [node]);
|
|
2031
2035
|
const onDraw = React.useCallback(e => {
|
|
2032
2036
|
const isTouch = Boolean(e.touches);
|
|
2033
2037
|
e.stopPropagation();
|
|
2034
2038
|
|
|
2035
|
-
if (node && drawing.current) {
|
|
2039
|
+
if (node && drawing.current && selection.current) {
|
|
2036
2040
|
var _e$touches$2;
|
|
2037
2041
|
|
|
2038
2042
|
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
@@ -2041,47 +2045,47 @@ const useSelection = (node, props) => {
|
|
|
2041
2045
|
|
|
2042
2046
|
if (offsetX >= 0) {
|
|
2043
2047
|
if (newWidth > 0) {
|
|
2044
|
-
selection.style.marginLeft = "0px";
|
|
2045
|
-
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";
|
|
2046
2050
|
} else {
|
|
2047
|
-
selection.style.right = nodeWidth - startX.current + "px";
|
|
2048
|
-
selection.style.width = Math.abs(newWidth) + "px";
|
|
2049
|
-
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";
|
|
2050
2054
|
}
|
|
2051
2055
|
}
|
|
2052
2056
|
|
|
2053
2057
|
if (isTouch) {
|
|
2054
2058
|
if (node.offsetLeft > e.touches[0].pageX) {
|
|
2055
|
-
selection.style.right = nodeWidth - startX.current + "px";
|
|
2056
|
-
selection.style.width = startX.current + "px";
|
|
2057
|
-
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";
|
|
2058
2062
|
}
|
|
2059
2063
|
}
|
|
2060
2064
|
}
|
|
2061
2065
|
}, [node]);
|
|
2062
2066
|
const onMouseLeave = React.useCallback(e => {
|
|
2063
|
-
if (drawing.current && node) {
|
|
2067
|
+
if (drawing.current && node && selection.current) {
|
|
2064
2068
|
if (node.offsetLeft > e.pageX) {
|
|
2065
2069
|
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
2066
|
-
selection.style.right = nodeWidth - startX.current + "px";
|
|
2067
|
-
selection.style.width = startX.current + "px";
|
|
2068
|
-
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";
|
|
2069
2073
|
}
|
|
2070
2074
|
|
|
2071
2075
|
if (node.offsetLeft + node.offsetWidth < e.pageX) {
|
|
2072
2076
|
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
2073
|
-
selection.style.left = startX.current + "px";
|
|
2074
|
-
selection.style.width = nodeWidth - startX.current + "px";
|
|
2075
|
-
selection.style.marginLeft = "0px";
|
|
2077
|
+
selection.current.style.left = startX.current + "px";
|
|
2078
|
+
selection.current.style.width = nodeWidth - startX.current + "px";
|
|
2079
|
+
selection.current.style.marginLeft = "0px";
|
|
2076
2080
|
}
|
|
2077
2081
|
}
|
|
2078
2082
|
}, [node]);
|
|
2079
2083
|
const onStopDrawing = React.useCallback(() => {
|
|
2080
|
-
if (node) {
|
|
2084
|
+
if (node && selection.current) {
|
|
2081
2085
|
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
2082
|
-
const selectionMinX = selection.offsetLeft >= 0 ? selection.offsetLeft <= nodeWidth ? selection.offsetLeft : nodeWidth : 0;
|
|
2083
|
-
const selectionWidth = selection.getBoundingClientRect().right - selection.getBoundingClientRect().left;
|
|
2084
|
-
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;
|
|
2085
2089
|
const min = Math.round(selectionMinX);
|
|
2086
2090
|
const max = Math.round(selectionMaxX);
|
|
2087
2091
|
|
|
@@ -2090,20 +2094,15 @@ const useSelection = (node, props) => {
|
|
|
2090
2094
|
}
|
|
2091
2095
|
|
|
2092
2096
|
drawing.current = false;
|
|
2093
|
-
selection.
|
|
2097
|
+
node.removeChild(selection.current);
|
|
2098
|
+
selection.current = undefined;
|
|
2094
2099
|
}
|
|
2095
2100
|
}, [node]);
|
|
2096
2101
|
React.useEffect(() => {
|
|
2097
2102
|
if (node) {
|
|
2098
|
-
var _props$margin$bottom, _props$margin;
|
|
2099
|
-
|
|
2100
|
-
selection.setAttribute("class", barChartClassNames.barChartSelection);
|
|
2101
|
-
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)");
|
|
2102
|
-
selection.style.display = "none";
|
|
2103
2103
|
node.childNodes.forEach(child => {
|
|
2104
2104
|
child.style.userSelect = "none";
|
|
2105
2105
|
});
|
|
2106
|
-
node.appendChild(selection);
|
|
2107
2106
|
node.addEventListener("mousedown", onStartDrawing);
|
|
2108
2107
|
node.addEventListener("touchstart", onStartDrawing);
|
|
2109
2108
|
node.addEventListener("mousemove", onDraw);
|