@evergis/charts 2.0.62 → 2.0.63
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/charts/BarChart/hooks/useSelection.d.ts +2 -0
- package/dist/charts/BarChart/styled.d.ts +4 -1
- package/dist/charts/BarChart/types.d.ts +2 -0
- package/dist/charts.cjs.development.js +133 -4
- package/dist/charts.cjs.development.js.map +1 -1
- package/dist/charts.cjs.production.min.js +1 -1
- package/dist/charts.cjs.production.min.js.map +1 -1
- package/dist/charts.esm.js +133 -4
- package/dist/charts.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/charts.esm.js
CHANGED
|
@@ -1976,11 +1976,137 @@ const barChartClassNames = /*#__PURE__*/_extends({
|
|
|
1976
1976
|
barChartGridLineX: 'barChartGridLineX',
|
|
1977
1977
|
barChartGridLineXZero: 'barChartGridLineXZero',
|
|
1978
1978
|
barChartGridLineYZero: 'barChartGridLineYZero',
|
|
1979
|
-
barChartGridLineY: 'barChartGridLineY'
|
|
1979
|
+
barChartGridLineY: 'barChartGridLineY',
|
|
1980
|
+
barChartSelection: 'barChartSelection'
|
|
1980
1981
|
}, tooltipClassnames, labelClassnames, barChartLinesClassNames);
|
|
1981
|
-
const SvgWrapper$4 = /*#__PURE__*/styled(Wrapper)(_templateObject$a || (_templateObject$a = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n line {\n stroke-width: 1px;\n shape-rendering: crispEdges;\n }\n .", ",\n .", " {\n stroke: rgba(48, 69, 79, 0.06);\n }\n .", " {\n }\n .", " {\n fill: none;\n pointer-events: all;\n }\n .", " {\n stroke-width: 1.5px;\n stroke-linejoin: round;\n stroke-linecap: round;\n }\n .", " {\n shape-rendering: auto;\n }\n .", " {\n fill-opacity: 0.24;\n }\n"
|
|
1982
|
+
const SvgWrapper$4 = /*#__PURE__*/styled(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 => {
|
|
1983
|
+
let {
|
|
1984
|
+
selectable
|
|
1985
|
+
} = _ref;
|
|
1986
|
+
return selectable && "inline-block";
|
|
1987
|
+
}, _ref2 => {
|
|
1988
|
+
let {
|
|
1989
|
+
selectable
|
|
1990
|
+
} = _ref2;
|
|
1991
|
+
return selectable && "none";
|
|
1992
|
+
}, _ref3 => {
|
|
1993
|
+
let {
|
|
1994
|
+
selectable
|
|
1995
|
+
} = _ref3;
|
|
1996
|
+
return selectable && "crosshair";
|
|
1997
|
+
}, barChartClassNames.barChartGridLineX, barChartClassNames.barChartGridLineY, barChartClassNames.barChartMouseRect, barChartClassNames.barChartMouseRect, barChartClassNames.barChartLinesGlobal, barChartClassNames.barChartLine, barChartClassNames.barChartArea, barChartClassNames.barChartSelection);
|
|
1982
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);
|
|
1983
1999
|
|
|
2000
|
+
const useSelection = (node, props) => {
|
|
2001
|
+
const drawing = useRef(false);
|
|
2002
|
+
const startX = useRef(0);
|
|
2003
|
+
const selection = document.createElement("div");
|
|
2004
|
+
const onStartDrawing = useCallback(e => {
|
|
2005
|
+
const isTouch = Boolean(e.touches);
|
|
2006
|
+
e.stopPropagation();
|
|
2007
|
+
|
|
2008
|
+
if (node) {
|
|
2009
|
+
var _e$touches$;
|
|
2010
|
+
|
|
2011
|
+
drawing.current = true;
|
|
2012
|
+
startX.current = isTouch ? ((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.pageX) - node.firstChild.getBoundingClientRect().left : e.offsetX;
|
|
2013
|
+
selection.style.display = "block";
|
|
2014
|
+
selection.style.width = "0px";
|
|
2015
|
+
selection.style.left = startX.current + "px";
|
|
2016
|
+
}
|
|
2017
|
+
}, [node]);
|
|
2018
|
+
const onDraw = useCallback(e => {
|
|
2019
|
+
const isTouch = Boolean(e.touches);
|
|
2020
|
+
e.stopPropagation();
|
|
2021
|
+
|
|
2022
|
+
if (node && drawing.current) {
|
|
2023
|
+
var _e$touches$2;
|
|
2024
|
+
|
|
2025
|
+
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
2026
|
+
const offsetX = isTouch ? ((_e$touches$2 = e.touches[0]) == null ? void 0 : _e$touches$2.pageX) - node.firstChild.getBoundingClientRect().left : e.offsetX;
|
|
2027
|
+
const newWidth = offsetX - startX.current;
|
|
2028
|
+
|
|
2029
|
+
if (offsetX >= 0) {
|
|
2030
|
+
if (newWidth > 0) {
|
|
2031
|
+
selection.style.marginLeft = "0px";
|
|
2032
|
+
selection.style.width = offsetX <= nodeWidth ? newWidth + "px" : nodeWidth - startX.current + "px";
|
|
2033
|
+
} else {
|
|
2034
|
+
selection.style.right = nodeWidth - startX.current + "px";
|
|
2035
|
+
selection.style.width = Math.abs(newWidth) + "px";
|
|
2036
|
+
selection.style.marginLeft = newWidth + "px";
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
if (isTouch) {
|
|
2041
|
+
if (node.offsetLeft > e.touches[0].pageX) {
|
|
2042
|
+
selection.style.right = nodeWidth - startX.current + "px";
|
|
2043
|
+
selection.style.width = startX.current + "px";
|
|
2044
|
+
selection.style.marginLeft = "-" + startX.current + "px";
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
}, [node]);
|
|
2049
|
+
const onMouseMove = useCallback(e => {
|
|
2050
|
+
if (drawing.current && node) {
|
|
2051
|
+
if (node.offsetLeft > e.pageX) {
|
|
2052
|
+
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
2053
|
+
selection.style.right = nodeWidth - startX.current + "px";
|
|
2054
|
+
selection.style.width = startX.current + "px";
|
|
2055
|
+
selection.style.marginLeft = "-" + startX.current + "px";
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
}, [node]);
|
|
2059
|
+
const onStopDrawing = useCallback(e => {
|
|
2060
|
+
e.stopPropagation();
|
|
2061
|
+
|
|
2062
|
+
if (node) {
|
|
2063
|
+
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
2064
|
+
const selectionMinX = selection.offsetLeft >= 0 ? selection.offsetLeft <= nodeWidth ? selection.offsetLeft : nodeWidth : 0;
|
|
2065
|
+
const selectionWidth = selection.getBoundingClientRect().right - selection.getBoundingClientRect().left;
|
|
2066
|
+
const selectionMaxX = selection.offsetLeft + selectionWidth <= nodeWidth ? selection.offsetLeft + selectionWidth >= 0 ? selection.offsetLeft + selectionWidth : 0 : nodeWidth;
|
|
2067
|
+
const min = Math.round(selectionMinX);
|
|
2068
|
+
const max = Math.round(selectionMaxX);
|
|
2069
|
+
|
|
2070
|
+
if (max - min > 0 && props.onSelect) {
|
|
2071
|
+
props.onSelect([min, max]);
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
drawing.current = false;
|
|
2075
|
+
selection.style.display = "none";
|
|
2076
|
+
}
|
|
2077
|
+
}, [node]);
|
|
2078
|
+
useEffect(() => {
|
|
2079
|
+
if (node) {
|
|
2080
|
+
var _props$margin$bottom, _props$margin;
|
|
2081
|
+
|
|
2082
|
+
selection.setAttribute("class", barChartClassNames.barChartSelection);
|
|
2083
|
+
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)");
|
|
2084
|
+
selection.style.display = "none";
|
|
2085
|
+
node.childNodes.forEach(child => {
|
|
2086
|
+
child.style.userSelect = "none";
|
|
2087
|
+
});
|
|
2088
|
+
node.appendChild(selection);
|
|
2089
|
+
node.addEventListener("mousedown", onStartDrawing);
|
|
2090
|
+
node.addEventListener("touchstart", onStartDrawing);
|
|
2091
|
+
node.addEventListener("mousemove", onDraw);
|
|
2092
|
+
node.addEventListener("touchmove", onDraw);
|
|
2093
|
+
document.addEventListener("mousemove", onMouseMove);
|
|
2094
|
+
document.addEventListener("mouseup", onStopDrawing);
|
|
2095
|
+
document.addEventListener("touchend", onStopDrawing);
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
return () => {
|
|
2099
|
+
node == null ? void 0 : node.removeEventListener("mousedown", onStartDrawing);
|
|
2100
|
+
node == null ? void 0 : node.removeEventListener("touchstart", onStartDrawing);
|
|
2101
|
+
node == null ? void 0 : node.removeEventListener("mousemove", onDraw);
|
|
2102
|
+
node == null ? void 0 : node.removeEventListener("touchmove", onDraw);
|
|
2103
|
+
document.removeEventListener("mousemove", onMouseMove);
|
|
2104
|
+
document.removeEventListener("mouseup", onStopDrawing);
|
|
2105
|
+
document.removeEventListener("touchend", onStopDrawing);
|
|
2106
|
+
};
|
|
2107
|
+
}, [node]);
|
|
2108
|
+
};
|
|
2109
|
+
|
|
1984
2110
|
const drawGrid$1 = _ref => {
|
|
1985
2111
|
let {
|
|
1986
2112
|
svg,
|
|
@@ -2689,7 +2815,8 @@ const BarChart = props => {
|
|
|
2689
2815
|
const {
|
|
2690
2816
|
className,
|
|
2691
2817
|
style,
|
|
2692
|
-
children
|
|
2818
|
+
children,
|
|
2819
|
+
selectable
|
|
2693
2820
|
} = props;
|
|
2694
2821
|
const [ref, node] = useNode();
|
|
2695
2822
|
useEffect(() => {
|
|
@@ -2699,11 +2826,13 @@ const BarChart = props => {
|
|
|
2699
2826
|
const onDraw = () => draw$4(node, props);
|
|
2700
2827
|
|
|
2701
2828
|
useResize(props.width, onDraw);
|
|
2829
|
+
useSelection(selectable ? node : null, props);
|
|
2702
2830
|
return React.createElement("div", {
|
|
2703
2831
|
className: className,
|
|
2704
2832
|
style: style
|
|
2705
2833
|
}, React.createElement(TooltipStyles$1, null), React.createElement(SvgWrapper$4, {
|
|
2706
|
-
ref: ref
|
|
2834
|
+
ref: ref,
|
|
2835
|
+
selectable: selectable
|
|
2707
2836
|
}, children));
|
|
2708
2837
|
};
|
|
2709
2838
|
BarChart.defaultProps = {
|