@gravity-ui/charts 1.8.0 → 1.10.0
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/cjs/components/Axis/AxisX.d.ts +2 -1
- package/dist/cjs/components/Axis/AxisX.js +147 -141
- package/dist/cjs/components/Axis/AxisY.d.ts +2 -1
- package/dist/cjs/components/Axis/AxisY.js +118 -116
- package/dist/cjs/components/ChartInner/index.js +36 -9
- package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +8 -5
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +59 -10
- package/dist/cjs/components/ChartInner/utils.d.ts +3 -0
- package/dist/cjs/components/ChartInner/utils.js +28 -0
- package/dist/cjs/components/Legend/index.js +202 -191
- package/dist/cjs/components/Legend/styles.css +2 -0
- package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -1
- package/dist/cjs/components/Tooltip/DefaultContent.d.ts +1 -1
- package/dist/cjs/components/Tooltip/DefaultContent.js +1 -1
- package/dist/cjs/components/Tooltip/index.d.ts +1 -1
- package/dist/cjs/constants/chart-types.d.ts +12 -0
- package/dist/cjs/constants/chart-types.js +12 -0
- package/dist/cjs/constants/defaults/axis.d.ts +3 -1
- package/dist/cjs/constants/defaults/axis.js +10 -0
- package/dist/cjs/constants/index.d.ts +6 -47
- package/dist/cjs/constants/index.js +6 -72
- package/dist/cjs/constants/layout-algorithms.d.ts +7 -0
- package/dist/cjs/constants/layout-algorithms.js +8 -0
- package/dist/cjs/constants/line-styles.d.ts +20 -0
- package/dist/cjs/constants/line-styles.js +20 -0
- package/dist/cjs/constants/palette.d.ts +1 -0
- package/dist/cjs/constants/palette.js +22 -0
- package/dist/cjs/constants/symbol-types.d.ts +7 -0
- package/dist/cjs/constants/symbol-types.js +8 -0
- package/dist/cjs/constants/typography.d.ts +1 -0
- package/dist/cjs/constants/typography.js +1 -0
- package/dist/cjs/hooks/hooks-utils/index.d.ts +1 -0
- package/dist/cjs/hooks/hooks-utils/index.js +1 -0
- package/dist/cjs/hooks/hooks-utils/zoom.d.ts +8 -0
- package/dist/cjs/hooks/hooks-utils/zoom.js +81 -0
- package/dist/cjs/hooks/index.d.ts +1 -0
- package/dist/cjs/hooks/index.js +1 -0
- package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -2
- package/dist/cjs/hooks/useAxisScales/index.js +22 -8
- package/dist/cjs/hooks/useBrush/index.d.ts +3 -0
- package/dist/cjs/hooks/useBrush/index.js +70 -0
- package/dist/cjs/hooks/useBrush/styles.css +10 -0
- package/dist/cjs/hooks/useBrush/types.d.ts +24 -0
- package/dist/cjs/hooks/useBrush/types.js +1 -0
- package/dist/cjs/hooks/useChartDimensions/index.d.ts +3 -3
- package/dist/cjs/hooks/useChartDimensions/index.js +2 -2
- package/dist/cjs/hooks/useChartDimensions/utils.d.ts +2 -2
- package/dist/cjs/hooks/useChartOptions/chart.d.ts +2 -1
- package/dist/cjs/hooks/useChartOptions/chart.js +80 -1
- package/dist/cjs/hooks/useChartOptions/index.js +3 -2
- package/dist/cjs/hooks/useChartOptions/types.d.ts +6 -2
- package/dist/cjs/hooks/useChartOptions/x-axis.d.ts +3 -3
- package/dist/cjs/hooks/useChartOptions/x-axis.js +22 -13
- package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +3 -3
- package/dist/cjs/hooks/useChartOptions/y-axis.js +36 -21
- package/dist/cjs/hooks/useCrosshair/index.d.ts +17 -0
- package/dist/cjs/hooks/useCrosshair/index.js +139 -0
- package/dist/cjs/hooks/useCrosshair/useCrosshairHover.d.ts +11 -0
- package/dist/cjs/hooks/useCrosshair/useCrosshairHover.js +18 -0
- package/dist/cjs/hooks/useSeries/index.d.ts +8 -6
- package/dist/cjs/hooks/useSeries/index.js +41 -22
- package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +27 -2
- package/dist/cjs/hooks/useSeries/prepare-bar-y.js +5 -5
- package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepare-legend.js +27 -9
- package/dist/cjs/hooks/useSeries/prepare-line.d.ts +1 -2
- package/dist/cjs/hooks/useSeries/prepare-line.js +3 -3
- package/dist/cjs/hooks/useSeries/prepareSeries.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepareSeries.js +2 -2
- package/dist/cjs/hooks/useSeries/types.d.ts +2 -1
- package/dist/cjs/hooks/useShapes/area/index.js +1 -1
- package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +32 -16
- package/dist/cjs/hooks/useShapes/area/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +17 -13
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +6 -6
- package/dist/cjs/hooks/useShapes/index.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/index.js +40 -31
- package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +14 -11
- package/dist/cjs/hooks/useShapes/line/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/marker.js +2 -2
- package/dist/cjs/hooks/useShapes/pie/index.js +3 -3
- package/dist/cjs/hooks/useShapes/pie/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/pie/prepare-data.js +15 -11
- package/dist/cjs/hooks/useShapes/radar/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/radar/prepare-data.js +6 -7
- package/dist/cjs/hooks/useShapes/radar/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/scatter/index.js +0 -1
- package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +2 -0
- package/dist/cjs/hooks/useShapes/scatter/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +19 -16
- package/dist/cjs/hooks/useShapes/waterfall/index.js +2 -2
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +8 -7
- package/dist/cjs/hooks/useZoom/index.d.ts +18 -0
- package/dist/cjs/hooks/useZoom/index.js +54 -0
- package/dist/cjs/hooks/useZoom/types.d.ts +19 -0
- package/dist/cjs/hooks/useZoom/types.js +1 -0
- package/dist/cjs/hooks/useZoom/utils.d.ts +12 -0
- package/dist/cjs/hooks/useZoom/utils.js +128 -0
- package/dist/cjs/types/chart/axis.d.ts +26 -21
- package/dist/cjs/types/chart/chart.d.ts +5 -0
- package/dist/cjs/types/chart/line.d.ts +1 -1
- package/dist/cjs/types/chart/pie.d.ts +1 -1
- package/dist/cjs/types/chart/series.d.ts +1 -1
- package/dist/cjs/types/chart/tooltip.d.ts +1 -1
- package/dist/cjs/types/chart/zoom.d.ts +36 -0
- package/dist/cjs/types/chart/zoom.js +1 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/types/misc.d.ts +7 -0
- package/dist/cjs/utils/chart/axis-generators/bottom.d.ts +1 -1
- package/dist/cjs/utils/chart/axis-generators/bottom.js +25 -25
- package/dist/cjs/utils/chart/axis.d.ts +2 -1
- package/dist/cjs/utils/chart/axis.js +10 -2
- package/dist/cjs/utils/chart/get-closest-data.js +1 -1
- package/dist/cjs/utils/chart/text.d.ts +7 -7
- package/dist/cjs/utils/chart/text.js +37 -29
- package/dist/cjs/utils/chart-ui/pie-center-text.d.ts +1 -1
- package/dist/cjs/utils/chart-ui/pie-center-text.js +2 -2
- package/dist/cjs/validation/index.d.ts +1 -1
- package/dist/cjs/validation/index.js +16 -16
- package/dist/esm/components/Axis/AxisX.d.ts +2 -1
- package/dist/esm/components/Axis/AxisX.js +147 -141
- package/dist/esm/components/Axis/AxisY.d.ts +2 -1
- package/dist/esm/components/Axis/AxisY.js +118 -116
- package/dist/esm/components/ChartInner/index.js +36 -9
- package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +8 -5
- package/dist/esm/components/ChartInner/useChartInnerProps.js +59 -10
- package/dist/esm/components/ChartInner/utils.d.ts +3 -0
- package/dist/esm/components/ChartInner/utils.js +28 -0
- package/dist/esm/components/Legend/index.js +202 -191
- package/dist/esm/components/Legend/styles.css +2 -0
- package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -1
- package/dist/esm/components/Tooltip/DefaultContent.d.ts +1 -1
- package/dist/esm/components/Tooltip/DefaultContent.js +1 -1
- package/dist/esm/components/Tooltip/index.d.ts +1 -1
- package/dist/esm/constants/chart-types.d.ts +12 -0
- package/dist/esm/constants/chart-types.js +12 -0
- package/dist/esm/constants/defaults/axis.d.ts +3 -1
- package/dist/esm/constants/defaults/axis.js +10 -0
- package/dist/esm/constants/index.d.ts +6 -47
- package/dist/esm/constants/index.js +6 -72
- package/dist/esm/constants/layout-algorithms.d.ts +7 -0
- package/dist/esm/constants/layout-algorithms.js +8 -0
- package/dist/esm/constants/line-styles.d.ts +20 -0
- package/dist/esm/constants/line-styles.js +20 -0
- package/dist/esm/constants/palette.d.ts +1 -0
- package/dist/esm/constants/palette.js +22 -0
- package/dist/esm/constants/symbol-types.d.ts +7 -0
- package/dist/esm/constants/symbol-types.js +8 -0
- package/dist/esm/constants/typography.d.ts +1 -0
- package/dist/esm/constants/typography.js +1 -0
- package/dist/esm/hooks/hooks-utils/index.d.ts +1 -0
- package/dist/esm/hooks/hooks-utils/index.js +1 -0
- package/dist/esm/hooks/hooks-utils/zoom.d.ts +8 -0
- package/dist/esm/hooks/hooks-utils/zoom.js +81 -0
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/useAxisScales/index.d.ts +4 -2
- package/dist/esm/hooks/useAxisScales/index.js +22 -8
- package/dist/esm/hooks/useBrush/index.d.ts +3 -0
- package/dist/esm/hooks/useBrush/index.js +70 -0
- package/dist/esm/hooks/useBrush/styles.css +10 -0
- package/dist/esm/hooks/useBrush/types.d.ts +24 -0
- package/dist/esm/hooks/useBrush/types.js +1 -0
- package/dist/esm/hooks/useChartDimensions/index.d.ts +3 -3
- package/dist/esm/hooks/useChartDimensions/index.js +2 -2
- package/dist/esm/hooks/useChartDimensions/utils.d.ts +2 -2
- package/dist/esm/hooks/useChartOptions/chart.d.ts +2 -1
- package/dist/esm/hooks/useChartOptions/chart.js +80 -1
- package/dist/esm/hooks/useChartOptions/index.js +3 -2
- package/dist/esm/hooks/useChartOptions/types.d.ts +6 -2
- package/dist/esm/hooks/useChartOptions/x-axis.d.ts +3 -3
- package/dist/esm/hooks/useChartOptions/x-axis.js +22 -13
- package/dist/esm/hooks/useChartOptions/y-axis.d.ts +3 -3
- package/dist/esm/hooks/useChartOptions/y-axis.js +36 -21
- package/dist/esm/hooks/useCrosshair/index.d.ts +17 -0
- package/dist/esm/hooks/useCrosshair/index.js +139 -0
- package/dist/esm/hooks/useCrosshair/useCrosshairHover.d.ts +11 -0
- package/dist/esm/hooks/useCrosshair/useCrosshairHover.js +18 -0
- package/dist/esm/hooks/useSeries/index.d.ts +8 -6
- package/dist/esm/hooks/useSeries/index.js +41 -22
- package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +27 -2
- package/dist/esm/hooks/useSeries/prepare-bar-y.js +5 -5
- package/dist/esm/hooks/useSeries/prepare-legend.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepare-legend.js +27 -9
- package/dist/esm/hooks/useSeries/prepare-line.d.ts +1 -2
- package/dist/esm/hooks/useSeries/prepare-line.js +3 -3
- package/dist/esm/hooks/useSeries/prepareSeries.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepareSeries.js +2 -2
- package/dist/esm/hooks/useSeries/types.d.ts +2 -1
- package/dist/esm/hooks/useShapes/area/index.js +1 -1
- package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/area/prepare-data.js +32 -16
- package/dist/esm/hooks/useShapes/area/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +17 -13
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +6 -6
- package/dist/esm/hooks/useShapes/index.d.ts +1 -1
- package/dist/esm/hooks/useShapes/index.js +40 -31
- package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/line/prepare-data.js +14 -11
- package/dist/esm/hooks/useShapes/line/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/marker.js +2 -2
- package/dist/esm/hooks/useShapes/pie/index.js +3 -3
- package/dist/esm/hooks/useShapes/pie/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/pie/prepare-data.js +15 -11
- package/dist/esm/hooks/useShapes/radar/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/radar/prepare-data.js +6 -7
- package/dist/esm/hooks/useShapes/radar/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/scatter/index.js +0 -1
- package/dist/esm/hooks/useShapes/scatter/prepare-data.js +2 -0
- package/dist/esm/hooks/useShapes/scatter/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/treemap/prepare-data.js +19 -16
- package/dist/esm/hooks/useShapes/waterfall/index.js +2 -2
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +8 -7
- package/dist/esm/hooks/useZoom/index.d.ts +18 -0
- package/dist/esm/hooks/useZoom/index.js +54 -0
- package/dist/esm/hooks/useZoom/types.d.ts +19 -0
- package/dist/esm/hooks/useZoom/types.js +1 -0
- package/dist/esm/hooks/useZoom/utils.d.ts +12 -0
- package/dist/esm/hooks/useZoom/utils.js +128 -0
- package/dist/esm/types/chart/axis.d.ts +26 -21
- package/dist/esm/types/chart/chart.d.ts +5 -0
- package/dist/esm/types/chart/line.d.ts +1 -1
- package/dist/esm/types/chart/pie.d.ts +1 -1
- package/dist/esm/types/chart/series.d.ts +1 -1
- package/dist/esm/types/chart/tooltip.d.ts +1 -1
- package/dist/esm/types/chart/zoom.d.ts +36 -0
- package/dist/esm/types/chart/zoom.js +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/misc.d.ts +7 -0
- package/dist/esm/utils/chart/axis-generators/bottom.d.ts +1 -1
- package/dist/esm/utils/chart/axis-generators/bottom.js +25 -25
- package/dist/esm/utils/chart/axis.d.ts +2 -1
- package/dist/esm/utils/chart/axis.js +10 -2
- package/dist/esm/utils/chart/get-closest-data.js +1 -1
- package/dist/esm/utils/chart/text.d.ts +7 -7
- package/dist/esm/utils/chart/text.js +37 -29
- package/dist/esm/utils/chart-ui/pie-center-text.d.ts +1 -1
- package/dist/esm/utils/chart-ui/pie-center-text.js +2 -2
- package/dist/esm/validation/index.d.ts +1 -1
- package/dist/esm/validation/index.js +16 -16
- package/package.json +2 -1
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ArrowRotateLeft } from '@gravity-ui/icons';
|
|
3
|
+
import { Button, ButtonIcon } from '@gravity-ui/uikit';
|
|
4
|
+
import { useCrosshair } from '../../hooks';
|
|
2
5
|
import { EventType, block, getDispatcher } from '../../utils';
|
|
3
6
|
import { AxisX, AxisY } from '../Axis';
|
|
4
7
|
import { Legend } from '../Legend';
|
|
@@ -14,10 +17,13 @@ export const ChartInner = (props) => {
|
|
|
14
17
|
var _a, _b, _c, _d;
|
|
15
18
|
const { width, height, data } = props;
|
|
16
19
|
const svgRef = React.useRef(null);
|
|
17
|
-
const
|
|
20
|
+
const [htmlLayout, setHtmlLayout] = React.useState(null);
|
|
18
21
|
const plotRef = React.useRef(null);
|
|
22
|
+
const plotBeforeRef = React.useRef(null);
|
|
23
|
+
const plotAfterRef = React.useRef(null);
|
|
19
24
|
const dispatcher = React.useMemo(() => getDispatcher(), []);
|
|
20
|
-
const { boundsHeight, boundsOffsetLeft, boundsOffsetTop, boundsWidth, handleLegendItemClick, legendConfig, legendItems, preparedSeries, preparedSplit, preparedLegend, prevHeight, prevWidth, shapes, shapesData, title, tooltip, xAxis, xScale, yAxis, yScale, svgXPos, svgBottomPos, } = useChartInnerProps(Object.assign(Object.assign({}, props), { dispatcher,
|
|
25
|
+
const { boundsHeight, boundsOffsetLeft, boundsOffsetTop, boundsWidth, handleLegendItemClick, handleZoomReset, legendConfig, legendItems, preparedSeries, preparedSplit, preparedLegend, prevHeight, prevWidth, shapes, shapesData, title, tooltip, xAxis, xScale, yAxis, yScale, svgXPos, svgBottomPos, } = useChartInnerProps(Object.assign(Object.assign({}, props), { dispatcher,
|
|
26
|
+
htmlLayout, svgContainer: svgRef.current, plotNode: plotRef.current }));
|
|
21
27
|
const { tooltipPinned, togglePinTooltip, unpinTooltip } = useChartInnerState({
|
|
22
28
|
dispatcher,
|
|
23
29
|
tooltip,
|
|
@@ -39,6 +45,19 @@ export const ChartInner = (props) => {
|
|
|
39
45
|
});
|
|
40
46
|
const clickHandler = (_b = (_a = data.chart) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.click;
|
|
41
47
|
const pointerMoveHandler = (_d = (_c = data.chart) === null || _c === void 0 ? void 0 : _c.events) === null || _d === void 0 ? void 0 : _d.pointermove;
|
|
48
|
+
useCrosshair({
|
|
49
|
+
split: preparedSplit,
|
|
50
|
+
plotElement: plotAfterRef.current,
|
|
51
|
+
boundsOffsetLeft,
|
|
52
|
+
boundsOffsetTop,
|
|
53
|
+
width: boundsWidth,
|
|
54
|
+
height: boundsHeight,
|
|
55
|
+
xAxis,
|
|
56
|
+
yAxes: yAxis,
|
|
57
|
+
yScale,
|
|
58
|
+
xScale,
|
|
59
|
+
dispatcher,
|
|
60
|
+
});
|
|
42
61
|
React.useEffect(() => {
|
|
43
62
|
if (clickHandler) {
|
|
44
63
|
dispatcher.on(EventType.CLICK_CHART, clickHandler);
|
|
@@ -60,20 +79,28 @@ export const ChartInner = (props) => {
|
|
|
60
79
|
}
|
|
61
80
|
}, [prevWidth, width, prevHeight, height, tooltipPinned, unpinTooltip]);
|
|
62
81
|
return (React.createElement("div", { className: b() },
|
|
63
|
-
React.createElement("svg", { ref: svgRef, width: width, height: height,
|
|
82
|
+
React.createElement("svg", { ref: svgRef, width: width, height: height,
|
|
83
|
+
// We use onPointerMove here because onMouseMove works incorrectly when the zoom setting is enabled:
|
|
84
|
+
// when starting to select an area, the tooltip remains in the position where the selection began
|
|
85
|
+
onPointerMove: throttledHandleMouseMove, onMouseLeave: handleMouseLeave, onTouchStart: throttledHandleTouchMove, onTouchMove: throttledHandleTouchMove, onClick: handleChartClick },
|
|
64
86
|
title && React.createElement(Title, Object.assign({}, title, { chartWidth: width })),
|
|
65
87
|
React.createElement("g", { transform: `translate(0, ${boundsOffsetTop})` }, preparedSplit.plots.map((plot, index) => {
|
|
66
88
|
return React.createElement(PlotTitle, { key: `plot-${index}`, title: plot.title });
|
|
67
89
|
})),
|
|
68
90
|
React.createElement("g", { width: boundsWidth, height: boundsHeight, transform: `translate(${[boundsOffsetLeft, boundsOffsetTop].join(',')})`, ref: plotRef },
|
|
69
91
|
xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length) && (React.createElement(React.Fragment, null,
|
|
70
|
-
React.createElement(AxisY, { bottomLimit: svgBottomPos, axes: yAxis, width: boundsWidth, height: boundsHeight, scale: yScale, split: preparedSplit,
|
|
71
|
-
React.createElement("g", { transform: `translate(0, ${boundsHeight})` },
|
|
72
|
-
React.createElement(AxisX, { leftmostLimit: svgXPos, axis: xAxis, width: boundsWidth, height: boundsHeight, scale: xScale, split: preparedSplit,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
92
|
+
React.createElement(AxisY, { bottomLimit: svgBottomPos, axes: yAxis, width: boundsWidth, height: boundsHeight, scale: yScale, split: preparedSplit, plotBeforeRef: plotBeforeRef, plotAfterRef: plotAfterRef }),
|
|
93
|
+
xAxis && (React.createElement("g", { transform: `translate(0, ${boundsHeight})` },
|
|
94
|
+
React.createElement(AxisX, { leftmostLimit: svgXPos, axis: xAxis, width: boundsWidth, height: boundsHeight, scale: xScale, split: preparedSplit, plotBeforeRef: plotBeforeRef, plotAfterRef: plotAfterRef }))))),
|
|
95
|
+
React.createElement("g", { ref: plotBeforeRef }),
|
|
96
|
+
shapes,
|
|
97
|
+
React.createElement("g", { ref: plotAfterRef })),
|
|
98
|
+
(preparedLegend === null || preparedLegend === void 0 ? void 0 : preparedLegend.enabled) && legendConfig && (React.createElement(Legend, { chartSeries: preparedSeries, boundsWidth: boundsWidth, legend: preparedLegend, items: legendItems, config: legendConfig, onItemClick: handleLegendItemClick, onUpdate: unpinTooltip, htmlLayout: htmlLayout }))),
|
|
99
|
+
React.createElement("div", { className: b('html-layer'), ref: setHtmlLayout, style: {
|
|
76
100
|
'--g-html-layout-transform': `translate(${boundsOffsetLeft}px, ${boundsOffsetTop}px)`,
|
|
77
101
|
} }),
|
|
102
|
+
handleZoomReset && (React.createElement(Button, { style: { position: 'absolute', top: 0, right: 0 }, onClick: handleZoomReset },
|
|
103
|
+
React.createElement(ButtonIcon, null,
|
|
104
|
+
React.createElement(ArrowRotateLeft, null)))),
|
|
78
105
|
React.createElement(Tooltip, { dispatcher: dispatcher, tooltip: tooltip, svgContainer: svgRef.current, xAxis: xAxis, yAxis: yAxis[0], onOutsideClick: unpinTooltip, tooltipPinned: tooltipPinned })));
|
|
79
106
|
};
|
|
@@ -14,7 +14,7 @@ type Props = {
|
|
|
14
14
|
togglePinTooltip: ChartInnerState['togglePinTooltip'];
|
|
15
15
|
tooltipPinned: boolean;
|
|
16
16
|
unpinTooltip: ChartInnerState['unpinTooltip'];
|
|
17
|
-
xAxis: PreparedAxis;
|
|
17
|
+
xAxis: PreparedAxis | null;
|
|
18
18
|
yAxis: PreparedAxis[];
|
|
19
19
|
tooltipThrottle: number;
|
|
20
20
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Dispatch } from 'd3';
|
|
3
|
+
import type { PreparedAxis } from '../../hooks';
|
|
3
4
|
import type { ChartInnerProps } from './types';
|
|
4
5
|
type Props = ChartInnerProps & {
|
|
5
6
|
dispatcher: Dispatch<object>;
|
|
6
7
|
htmlLayout: HTMLElement | null;
|
|
7
8
|
svgContainer: SVGGElement | null;
|
|
9
|
+
plotNode: SVGGElement | null;
|
|
8
10
|
};
|
|
9
11
|
export declare function useChartInnerProps(props: Props): {
|
|
10
12
|
svgBottomPos: number | undefined;
|
|
@@ -14,6 +16,7 @@ export declare function useChartInnerProps(props: Props): {
|
|
|
14
16
|
boundsOffsetTop: number;
|
|
15
17
|
boundsWidth: number;
|
|
16
18
|
handleLegendItemClick: import("../../hooks").OnLegendItemClick;
|
|
19
|
+
handleZoomReset: (() => void) | undefined;
|
|
17
20
|
legendConfig: {
|
|
18
21
|
offset: {
|
|
19
22
|
left: number;
|
|
@@ -25,9 +28,9 @@ export declare function useChartInnerProps(props: Props): {
|
|
|
25
28
|
end: number;
|
|
26
29
|
}[];
|
|
27
30
|
} | undefined;
|
|
28
|
-
};
|
|
29
|
-
legendItems: import("../../hooks").LegendItem[][];
|
|
30
|
-
preparedLegend: import("../../hooks").PreparedLegend;
|
|
31
|
+
} | undefined;
|
|
32
|
+
legendItems: never[] | import("../../hooks").LegendItem[][];
|
|
33
|
+
preparedLegend: import("../../hooks").PreparedLegend | null;
|
|
31
34
|
preparedSeries: import("../../hooks").PreparedSeries[];
|
|
32
35
|
preparedSplit: import("../../hooks").PreparedSplit;
|
|
33
36
|
prevHeight: number | undefined;
|
|
@@ -41,9 +44,9 @@ export declare function useChartInnerProps(props: Props): {
|
|
|
41
44
|
enabled: boolean;
|
|
42
45
|
throttle: number;
|
|
43
46
|
};
|
|
44
|
-
xAxis:
|
|
47
|
+
xAxis: PreparedAxis | null;
|
|
45
48
|
xScale: import("../../hooks").ChartScale | undefined;
|
|
46
|
-
yAxis:
|
|
49
|
+
yAxis: PreparedAxis[];
|
|
47
50
|
yScale: import("../../hooks").ChartScale[] | undefined;
|
|
48
51
|
};
|
|
49
52
|
export {};
|
|
@@ -1,28 +1,44 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useAxisScales, useChartDimensions, useChartOptions, usePrevious, useSeries, useShapes, useSplit, } from '../../hooks';
|
|
3
|
+
import { getZoomedSeriesData } from '../../hooks/hooks-utils';
|
|
3
4
|
import { getYAxisWidth } from '../../hooks/useChartDimensions/utils';
|
|
4
5
|
import { getPreparedXAxis } from '../../hooks/useChartOptions/x-axis';
|
|
5
6
|
import { getPreparedYAxis } from '../../hooks/useChartOptions/y-axis';
|
|
7
|
+
import { useZoom } from '../../hooks/useZoom';
|
|
8
|
+
import { hasAtLeastOneSeriesDataPerPlot } from './utils';
|
|
6
9
|
export function useChartInnerProps(props) {
|
|
7
10
|
var _a;
|
|
8
|
-
const { width, height, data, dispatcher, htmlLayout, svgContainer } = props;
|
|
11
|
+
const { width, height, data, dispatcher, htmlLayout, svgContainer, plotNode } = props;
|
|
9
12
|
const prevWidth = usePrevious(width);
|
|
10
13
|
const prevHeight = usePrevious(height);
|
|
14
|
+
const [zoomState, setZoomState] = React.useState({});
|
|
11
15
|
const { chart, title, tooltip, colors } = useChartOptions({ data });
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const zoomedSeriesData = React.useMemo(() => {
|
|
17
|
+
return getZoomedSeriesData({
|
|
18
|
+
seriesData: data.series.data,
|
|
19
|
+
xAxis: data.xAxis,
|
|
20
|
+
yAxises: data.yAxis,
|
|
21
|
+
zoomState,
|
|
22
|
+
});
|
|
23
|
+
}, [data.series.data, data.xAxis, data.yAxis, zoomState]);
|
|
24
|
+
const [xAxis, setXAxis] = React.useState(null);
|
|
25
|
+
React.useEffect(() => {
|
|
26
|
+
getPreparedXAxis({ xAxis: data.xAxis, width, seriesData: zoomedSeriesData }).then((val) => setXAxis(val));
|
|
27
|
+
}, [data.xAxis, width, zoomedSeriesData]);
|
|
28
|
+
const [yAxis, setYAxis] = React.useState([]);
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
getPreparedYAxis({ yAxis: data.yAxis, height, seriesData: zoomedSeriesData }).then((val) => setYAxis(val));
|
|
31
|
+
}, [data.yAxis, height, zoomedSeriesData]);
|
|
18
32
|
const { legendItems, legendConfig, preparedSeries, preparedSeriesOptions, preparedLegend, handleLegendItemClick, } = useSeries({
|
|
19
33
|
chartWidth: width,
|
|
20
34
|
chartHeight: height,
|
|
21
35
|
chartMargin: chart.margin,
|
|
22
|
-
|
|
36
|
+
colors,
|
|
23
37
|
legend: data.legend,
|
|
38
|
+
originalSeriesData: data.series.data,
|
|
39
|
+
seriesData: zoomedSeriesData,
|
|
40
|
+
seriesOptions: data.series.options,
|
|
24
41
|
preparedYAxis: yAxis,
|
|
25
|
-
colors,
|
|
26
42
|
});
|
|
27
43
|
const { boundsWidth, boundsHeight } = useChartDimensions({
|
|
28
44
|
width,
|
|
@@ -37,6 +53,8 @@ export function useChartInnerProps(props) {
|
|
|
37
53
|
const { xScale, yScale } = useAxisScales({
|
|
38
54
|
boundsWidth,
|
|
39
55
|
boundsHeight,
|
|
56
|
+
hasZoomX: Boolean(zoomState.x),
|
|
57
|
+
hasZoomY: Boolean(zoomState.y),
|
|
40
58
|
series: preparedSeries,
|
|
41
59
|
xAxis,
|
|
42
60
|
yAxis,
|
|
@@ -55,10 +73,37 @@ export function useChartInnerProps(props) {
|
|
|
55
73
|
split: preparedSplit,
|
|
56
74
|
htmlLayout,
|
|
57
75
|
});
|
|
76
|
+
const handleAttemptToSetZoomState = React.useCallback((nextZoomState) => {
|
|
77
|
+
const nextZoomedSeriesData = getZoomedSeriesData({
|
|
78
|
+
seriesData: zoomedSeriesData,
|
|
79
|
+
xAxis: data.xAxis,
|
|
80
|
+
yAxises: data.yAxis,
|
|
81
|
+
zoomState: nextZoomState,
|
|
82
|
+
});
|
|
83
|
+
const hasData = hasAtLeastOneSeriesDataPerPlot(nextZoomedSeriesData, yAxis);
|
|
84
|
+
if (hasData) {
|
|
85
|
+
setZoomState(nextZoomState);
|
|
86
|
+
}
|
|
87
|
+
}, [data.xAxis, data.yAxis, yAxis, zoomedSeriesData]);
|
|
88
|
+
useZoom({
|
|
89
|
+
node: plotNode,
|
|
90
|
+
onUpdate: handleAttemptToSetZoomState,
|
|
91
|
+
plotContainerHeight: boundsHeight,
|
|
92
|
+
plotContainerWidth: boundsWidth,
|
|
93
|
+
preparedSplit,
|
|
94
|
+
preparedZoom: chart.zoom,
|
|
95
|
+
xAxis,
|
|
96
|
+
xScale,
|
|
97
|
+
yAxis,
|
|
98
|
+
yScale,
|
|
99
|
+
});
|
|
58
100
|
const boundsOffsetTop = chart.margin.top;
|
|
59
|
-
// We need to calculate the width of each axis because the first axis can be hidden
|
|
101
|
+
// We need to calculate the width of each left axis because the first axis can be hidden
|
|
60
102
|
const boundsOffsetLeft = chart.margin.left +
|
|
61
103
|
yAxis.reduce((acc, axis) => {
|
|
104
|
+
if (axis.position !== 'left') {
|
|
105
|
+
return acc;
|
|
106
|
+
}
|
|
62
107
|
const axisWidth = getYAxisWidth(axis);
|
|
63
108
|
if (acc < axisWidth) {
|
|
64
109
|
acc = axisWidth;
|
|
@@ -66,6 +111,9 @@ export function useChartInnerProps(props) {
|
|
|
66
111
|
return acc;
|
|
67
112
|
}, 0);
|
|
68
113
|
const { x, bottom } = (_a = svgContainer === null || svgContainer === void 0 ? void 0 : svgContainer.getBoundingClientRect()) !== null && _a !== void 0 ? _a : {};
|
|
114
|
+
const handleZoomReset = React.useCallback(() => {
|
|
115
|
+
setZoomState({});
|
|
116
|
+
}, []);
|
|
69
117
|
return {
|
|
70
118
|
svgBottomPos: bottom,
|
|
71
119
|
svgXPos: x,
|
|
@@ -74,6 +122,7 @@ export function useChartInnerProps(props) {
|
|
|
74
122
|
boundsOffsetTop,
|
|
75
123
|
boundsWidth,
|
|
76
124
|
handleLegendItemClick,
|
|
125
|
+
handleZoomReset: Object.keys(zoomState).length > 0 ? handleZoomReset : undefined,
|
|
77
126
|
legendConfig,
|
|
78
127
|
legendItems,
|
|
79
128
|
preparedLegend,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function hasAtLeastOneSeriesDataPerPlot(seriesData, yAxises = []) {
|
|
2
|
+
const hasDataMap = new Map();
|
|
3
|
+
yAxises.forEach((yAxis) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const plotIndex = (_a = yAxis.plotIndex) !== null && _a !== void 0 ? _a : 0;
|
|
6
|
+
if (!hasDataMap.has(plotIndex)) {
|
|
7
|
+
hasDataMap.set(plotIndex, false);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
if (hasDataMap.size === 0) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
seriesData.forEach((seriesDataChunk) => {
|
|
14
|
+
var _a;
|
|
15
|
+
let yAxisIndex = 0;
|
|
16
|
+
if ('yAxis' in seriesDataChunk && typeof seriesDataChunk.yAxis === 'number') {
|
|
17
|
+
yAxisIndex = seriesDataChunk.yAxis;
|
|
18
|
+
}
|
|
19
|
+
const yAxis = yAxises[yAxisIndex];
|
|
20
|
+
const plotIndex = (_a = yAxis === null || yAxis === void 0 ? void 0 : yAxis.plotIndex) !== null && _a !== void 0 ? _a : 0;
|
|
21
|
+
if (!hasDataMap.get(plotIndex)) {
|
|
22
|
+
if (seriesDataChunk.data.length > 0) {
|
|
23
|
+
hasDataMap.set(plotIndex, true);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return [...hasDataMap.values()].every((hasData) => hasData);
|
|
28
|
+
}
|