@gravity-ui/chartkit 7.61.0 → 7.62.1
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/build/components/SplitTooltip/SplitTooltip.d.ts +49 -0
- package/build/components/SplitTooltip/SplitTooltip.js +122 -0
- package/build/components/SplitTooltip/index.d.ts +2 -0
- package/build/components/SplitTooltip/index.js +1 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +1 -0
- package/build/plugins/gravity-charts/renderer/withSplitPane/useViewportSplitTooltipLayout.d.ts +3 -0
- package/build/plugins/gravity-charts/renderer/withSplitPane/useViewportSplitTooltipLayout.js +29 -0
- package/build/plugins/gravity-charts/renderer/withSplitPane/withSplitPane.js +9 -89
- package/package.json +2 -2
- package/build/plugins/gravity-charts/renderer/withSplitPane/useWithSplitPaneState.d.ts +0 -19
- package/build/plugins/gravity-charts/renderer/withSplitPane/useWithSplitPaneState.js +0 -45
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SplitLayout } from '../SplitPane';
|
|
3
|
+
import type { SplitLayoutType } from '../SplitPane';
|
|
4
|
+
export declare const SPLIT_TOOLTIP_RESIZER_SIZE = 24;
|
|
5
|
+
export declare const SPLIT_TOOLTIP_MAIN_PANE_RATIO = 0.6;
|
|
6
|
+
export { SplitLayout as SplitTooltipLayout };
|
|
7
|
+
export type SplitTooltipLayout = SplitLayoutType;
|
|
8
|
+
export interface SplitTooltipRenderProps {
|
|
9
|
+
/** The active pane layout. */
|
|
10
|
+
layout: SplitTooltipLayout;
|
|
11
|
+
/** The current size of the main pane in pixels. */
|
|
12
|
+
size: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SplitTooltipProps {
|
|
15
|
+
/**
|
|
16
|
+
* The controlled pane layout. When omitted, the layout is derived from the container size:
|
|
17
|
+
* vertical when width is greater than height, horizontal otherwise.
|
|
18
|
+
*/
|
|
19
|
+
layout?: SplitTooltipLayout;
|
|
20
|
+
/** The share of the container width occupied by the main pane in vertical layout. Defaults to `0.6`. */
|
|
21
|
+
mainPaneRatio?: number;
|
|
22
|
+
/** Additional styles for the main pane. */
|
|
23
|
+
mainPaneStyle?: React.CSSProperties;
|
|
24
|
+
/** Called after initialization and whenever the main pane size or layout changes. */
|
|
25
|
+
onMainPaneSizeChange?: (size: number, layout: SplitTooltipLayout) => void;
|
|
26
|
+
/** Renders the main pane with its current layout and size. */
|
|
27
|
+
renderMainPane: (props: SplitTooltipRenderProps) => React.ReactNode;
|
|
28
|
+
/** Renders the tooltip pane with the current main pane layout and size. */
|
|
29
|
+
renderTooltip: (props: SplitTooltipRenderProps) => React.ReactNode;
|
|
30
|
+
/** Controls the resizer visibility without hiding the tooltip pane. Defaults to `false`. */
|
|
31
|
+
resizerVisible?: boolean;
|
|
32
|
+
/** Additional styles for the split pane container. */
|
|
33
|
+
style?: React.CSSProperties;
|
|
34
|
+
/** Additional styles for the tooltip pane. */
|
|
35
|
+
tooltipPaneStyle?: React.CSSProperties;
|
|
36
|
+
}
|
|
37
|
+
export declare function getSplitTooltipLayout(width: number, height: number, layout?: SplitTooltipLayout): SplitTooltipLayout;
|
|
38
|
+
export declare function getSplitTooltipMainPaneSize({ containerHeight, containerWidth, layout, mainPaneRatio, tooltipHeight, }: {
|
|
39
|
+
containerHeight: number;
|
|
40
|
+
containerWidth: number;
|
|
41
|
+
layout: SplitTooltipLayout;
|
|
42
|
+
mainPaneRatio?: number;
|
|
43
|
+
tooltipHeight: number;
|
|
44
|
+
}): number;
|
|
45
|
+
export declare function getSplitTooltipSizeLimits(containerHeight: number, tooltipHeight: number): {
|
|
46
|
+
minSize: number;
|
|
47
|
+
maxSize: number;
|
|
48
|
+
};
|
|
49
|
+
export declare function SplitTooltip(props: SplitTooltipProps): React.JSX.Element;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useResizeObserver } from '@gravity-ui/uikit';
|
|
3
|
+
import { SplitLayout, StyledSplitPane } from '../SplitPane';
|
|
4
|
+
export const SPLIT_TOOLTIP_RESIZER_SIZE = 24;
|
|
5
|
+
export const SPLIT_TOOLTIP_MAIN_PANE_RATIO = 0.6;
|
|
6
|
+
export { SplitLayout as SplitTooltipLayout };
|
|
7
|
+
const hiddenResizerStyle = { display: 'none' };
|
|
8
|
+
const defaultTooltipPaneStyle = { overflow: 'auto' };
|
|
9
|
+
export function getSplitTooltipLayout(width, height, layout) {
|
|
10
|
+
return layout !== null && layout !== void 0 ? layout : (width > height ? SplitLayout.VERTICAL : SplitLayout.HORIZONTAL);
|
|
11
|
+
}
|
|
12
|
+
export function getSplitTooltipMainPaneSize({ containerHeight, containerWidth, layout, mainPaneRatio = SPLIT_TOOLTIP_MAIN_PANE_RATIO, tooltipHeight, }) {
|
|
13
|
+
if (layout === SplitLayout.VERTICAL) {
|
|
14
|
+
return containerWidth * mainPaneRatio;
|
|
15
|
+
}
|
|
16
|
+
return Math.max(0, containerHeight - SPLIT_TOOLTIP_RESIZER_SIZE - tooltipHeight);
|
|
17
|
+
}
|
|
18
|
+
export function getSplitTooltipSizeLimits(containerHeight, tooltipHeight) {
|
|
19
|
+
const maxSize = getSplitTooltipMainPaneSize({
|
|
20
|
+
containerHeight,
|
|
21
|
+
containerWidth: 0,
|
|
22
|
+
layout: SplitLayout.HORIZONTAL,
|
|
23
|
+
tooltipHeight,
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
minSize: Math.min(containerHeight / 3, maxSize),
|
|
27
|
+
maxSize,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function getNextMainPaneSize({ currentSize, nextDimensions, previousDimensions, }) {
|
|
31
|
+
if (nextDimensions.layout !== previousDimensions.layout ||
|
|
32
|
+
nextDimensions.layout === SplitLayout.VERTICAL) {
|
|
33
|
+
return getSplitTooltipMainPaneSize(nextDimensions);
|
|
34
|
+
}
|
|
35
|
+
const { maxSize: previousMaxSize } = getSplitTooltipSizeLimits(previousDimensions.containerHeight, previousDimensions.tooltipHeight);
|
|
36
|
+
const { minSize: nextMinSize, maxSize: nextMaxSize } = getSplitTooltipSizeLimits(nextDimensions.containerHeight, nextDimensions.tooltipHeight);
|
|
37
|
+
if (currentSize === previousMaxSize) {
|
|
38
|
+
return nextMaxSize;
|
|
39
|
+
}
|
|
40
|
+
return Math.max(nextMinSize, Math.min(nextMaxSize, currentSize));
|
|
41
|
+
}
|
|
42
|
+
function SplitTooltipContent(props) {
|
|
43
|
+
const { containerHeight, containerWidth, renderMainPane, renderTooltip, layout: layoutProp, mainPaneRatio = SPLIT_TOOLTIP_MAIN_PANE_RATIO, resizerVisible, onMainPaneSizeChange, style, mainPaneStyle, tooltipPaneStyle, } = props;
|
|
44
|
+
const tooltipRef = React.useRef(null);
|
|
45
|
+
const layout = getSplitTooltipLayout(containerWidth, containerHeight, layoutProp);
|
|
46
|
+
const [tooltipHeight, setTooltipHeight] = React.useState(0);
|
|
47
|
+
const [size, setSize] = React.useState(() => getSplitTooltipMainPaneSize({
|
|
48
|
+
containerHeight,
|
|
49
|
+
containerWidth,
|
|
50
|
+
layout,
|
|
51
|
+
mainPaneRatio,
|
|
52
|
+
tooltipHeight: 0,
|
|
53
|
+
}));
|
|
54
|
+
const dimensions = React.useMemo(() => ({
|
|
55
|
+
containerHeight,
|
|
56
|
+
containerWidth,
|
|
57
|
+
layout,
|
|
58
|
+
mainPaneRatio,
|
|
59
|
+
tooltipHeight,
|
|
60
|
+
}), [containerHeight, containerWidth, layout, mainPaneRatio, tooltipHeight]);
|
|
61
|
+
const previousDimensionsRef = React.useRef(dimensions);
|
|
62
|
+
const lastNotificationRef = React.useRef(null);
|
|
63
|
+
const onMainPaneSizeChangeRef = React.useRef(onMainPaneSizeChange);
|
|
64
|
+
onMainPaneSizeChangeRef.current = onMainPaneSizeChange;
|
|
65
|
+
const handleTooltipResize = React.useCallback(() => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const nextTooltipHeight = (_b = (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height) !== null && _b !== void 0 ? _b : 0;
|
|
68
|
+
setTooltipHeight(nextTooltipHeight);
|
|
69
|
+
}, []);
|
|
70
|
+
useResizeObserver({
|
|
71
|
+
ref: tooltipRef,
|
|
72
|
+
onResize: handleTooltipResize,
|
|
73
|
+
});
|
|
74
|
+
const effectiveSize = getNextMainPaneSize({
|
|
75
|
+
currentSize: size,
|
|
76
|
+
nextDimensions: dimensions,
|
|
77
|
+
previousDimensions: previousDimensionsRef.current,
|
|
78
|
+
});
|
|
79
|
+
React.useLayoutEffect(() => {
|
|
80
|
+
previousDimensionsRef.current = dimensions;
|
|
81
|
+
if (effectiveSize !== size) {
|
|
82
|
+
setSize(effectiveSize);
|
|
83
|
+
}
|
|
84
|
+
}, [dimensions, effectiveSize, size]);
|
|
85
|
+
React.useLayoutEffect(() => {
|
|
86
|
+
const previousNotification = lastNotificationRef.current;
|
|
87
|
+
if ((previousNotification === null || previousNotification === void 0 ? void 0 : previousNotification.size) === effectiveSize &&
|
|
88
|
+
previousNotification.layout === layout) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const callback = onMainPaneSizeChangeRef.current;
|
|
92
|
+
if (!callback) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
lastNotificationRef.current = { layout, size: effectiveSize };
|
|
96
|
+
return callback(effectiveSize, layout);
|
|
97
|
+
});
|
|
98
|
+
const allowResize = layout === SplitLayout.HORIZONTAL;
|
|
99
|
+
const sizeLimits = getSplitTooltipSizeLimits(containerHeight, tooltipHeight);
|
|
100
|
+
const maxSize = allowResize ? sizeLimits.maxSize : undefined;
|
|
101
|
+
const minSize = allowResize ? sizeLimits.minSize : undefined;
|
|
102
|
+
const renderProps = { layout, size: effectiveSize };
|
|
103
|
+
return (React.createElement(StyledSplitPane, { allowResize: allowResize, maxSize: maxSize, minSize: minSize, size: effectiveSize, split: layout, style: style, onChange: setSize, resizerStyle: resizerVisible ? undefined : hiddenResizerStyle, paneOneRender: () => renderMainPane(renderProps), paneTwoRender: () => React.createElement("div", { ref: tooltipRef }, renderTooltip(renderProps)), pane1Style: mainPaneStyle, pane2Style: Object.assign(Object.assign({}, defaultTooltipPaneStyle), tooltipPaneStyle) }));
|
|
104
|
+
}
|
|
105
|
+
export function SplitTooltip(props) {
|
|
106
|
+
const containerRef = React.useRef(null);
|
|
107
|
+
const [dimensions, setDimensions] = React.useState({ height: 0, width: 0 });
|
|
108
|
+
const updateDimensions = React.useCallback(() => {
|
|
109
|
+
var _a, _b, _c;
|
|
110
|
+
const rect = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
111
|
+
setDimensions({
|
|
112
|
+
height: (_b = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _b !== void 0 ? _b : 0,
|
|
113
|
+
width: (_c = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _c !== void 0 ? _c : 0,
|
|
114
|
+
});
|
|
115
|
+
}, []);
|
|
116
|
+
useResizeObserver({
|
|
117
|
+
ref: containerRef,
|
|
118
|
+
onResize: updateDimensions,
|
|
119
|
+
});
|
|
120
|
+
React.useLayoutEffect(updateDimensions, [updateDimensions]);
|
|
121
|
+
return (React.createElement("div", { ref: containerRef, style: { position: 'relative', height: '100%' } }, dimensions.height > 0 && dimensions.width > 0 ? (React.createElement(SplitTooltipContent, Object.assign({}, props, { containerHeight: dimensions.height, containerWidth: dimensions.width }))) : null));
|
|
122
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SplitTooltip, SplitTooltipLayout } from './SplitTooltip';
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ChartKit } from './components/ChartKit';
|
|
2
2
|
import { settings } from './libs';
|
|
3
3
|
export * from './libs/chartkit-error/chartkit-error';
|
|
4
|
+
export { SplitTooltip, SplitTooltipLayout } from './components/SplitTooltip';
|
|
5
|
+
export type { SplitTooltipProps, SplitTooltipRenderProps } from './components/SplitTooltip';
|
|
4
6
|
export type { ChartKitLang, ChartKitOnLoadData, ChartKitOnRenderData, ChartKitOnChartLoad, ChartKitOnError, ChartKitPlugin, ChartKitProps, ChartKitRef, ChartKitWidgetRef, ChartKitType, ChartKitWidget, } from './types';
|
|
5
7
|
export { settings };
|
|
6
8
|
export default ChartKit;
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ChartKit } from './components/ChartKit';
|
|
2
2
|
import { settings } from './libs';
|
|
3
3
|
export * from './libs/chartkit-error/chartkit-error';
|
|
4
|
+
export { SplitTooltip, SplitTooltipLayout } from './components/SplitTooltip';
|
|
4
5
|
export { settings };
|
|
5
6
|
export default ChartKit;
|
package/build/plugins/gravity-charts/renderer/withSplitPane/useViewportSplitTooltipLayout.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SplitTooltipLayout } from '../../../../components/SplitTooltip';
|
|
2
|
+
export declare function getViewportSplitTooltipLayout(width: number, height: number): SplitTooltipLayout;
|
|
3
|
+
export declare function useViewportSplitTooltipLayout(): import("../../../../components/SplitPane").SplitLayoutType;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IS_WINDOW_AVAILABLE } from '../../../../constants';
|
|
3
|
+
export function getViewportSplitTooltipLayout(width, height) {
|
|
4
|
+
return width > height ? 'vertical' : 'horizontal';
|
|
5
|
+
}
|
|
6
|
+
function getCurrentViewportLayout() {
|
|
7
|
+
if (!IS_WINDOW_AVAILABLE) {
|
|
8
|
+
return 'horizontal';
|
|
9
|
+
}
|
|
10
|
+
return getViewportSplitTooltipLayout(window.innerWidth, window.innerHeight);
|
|
11
|
+
}
|
|
12
|
+
export function useViewportSplitTooltipLayout() {
|
|
13
|
+
const [layout, setLayout] = React.useState(getCurrentViewportLayout);
|
|
14
|
+
React.useLayoutEffect(() => {
|
|
15
|
+
if (!IS_WINDOW_AVAILABLE) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const handleViewportChange = () => {
|
|
19
|
+
setLayout(getCurrentViewportLayout());
|
|
20
|
+
};
|
|
21
|
+
window.addEventListener('resize', handleViewportChange);
|
|
22
|
+
window.addEventListener('orientationchange', handleViewportChange);
|
|
23
|
+
return () => {
|
|
24
|
+
window.removeEventListener('resize', handleViewportChange);
|
|
25
|
+
window.removeEventListener('orientationchange', handleViewportChange);
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
return layout;
|
|
29
|
+
}
|
|
@@ -1,53 +1,18 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { getDefaultTooltipHeaderFormat } from '@gravity-ui/charts';
|
|
4
|
-
import { getComponentName
|
|
4
|
+
import { getComponentName } from '@gravity-ui/uikit';
|
|
5
5
|
import isEmpty from 'lodash/isEmpty';
|
|
6
|
-
import {
|
|
7
|
-
import { IS_SCREEN_ORIENTATION_AVAILABLE, IS_WINDOW_AVAILABLE } from '../../../../constants';
|
|
8
|
-
import { usePrevious } from '../../../../hooks';
|
|
9
|
-
import { isScreenOrientationEventType } from '../../../../utils';
|
|
6
|
+
import { SplitTooltip } from '../../../../components/SplitTooltip';
|
|
10
7
|
import { TooltipContent } from './TooltipContent';
|
|
11
|
-
import {
|
|
12
|
-
const tooltipPaneStyles = { overflow: 'auto' };
|
|
8
|
+
import { useViewportSplitTooltipLayout } from './useViewportSplitTooltipLayout';
|
|
13
9
|
const SplitPaneContent = (props) => {
|
|
14
10
|
var _a;
|
|
15
|
-
const { data,
|
|
16
|
-
const tooltipContainerRef = React.useRef(null);
|
|
11
|
+
const { data, ChartComponent } = props, restProps = __rest(props, ["data", "ChartComponent"]);
|
|
17
12
|
const chartRef = React.useRef(null);
|
|
18
13
|
const tooltipRef = React.useRef(null);
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
containerHeight: height,
|
|
22
|
-
});
|
|
23
|
-
const prevTooltipHeight = usePrevious(tooltipHeight);
|
|
24
|
-
const prevSplit = usePrevious(split);
|
|
25
|
-
if (prevSplit && split !== prevSplit && split === SplitLayout.VERTICAL) {
|
|
26
|
-
setSize(getVerticalSize());
|
|
27
|
-
}
|
|
28
|
-
else if (split === SplitLayout.HORIZONTAL &&
|
|
29
|
-
prevTooltipHeight === 0 &&
|
|
30
|
-
tooltipHeight !== prevTooltipHeight) {
|
|
31
|
-
const containerHeight = height;
|
|
32
|
-
if (containerHeight - RESIZER_HEIGHT === size) {
|
|
33
|
-
setSize(containerHeight - RESIZER_HEIGHT - tooltipHeight);
|
|
34
|
-
queueMicrotask(() => {
|
|
35
|
-
var _a;
|
|
36
|
-
(_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.reflow({ immediate: true });
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const handleTooltipContentResize = React.useCallback(() => {
|
|
41
|
-
if (!tooltipContainerRef.current || split !== SplitLayout.HORIZONTAL) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const nextTooltipHeight = tooltipContainerRef.current.getBoundingClientRect().height;
|
|
45
|
-
setTooltipHeight(nextTooltipHeight);
|
|
46
|
-
}, [setTooltipHeight, split]);
|
|
47
|
-
useResizeObserver({
|
|
48
|
-
ref: tooltipContainerRef,
|
|
49
|
-
onResize: handleTooltipContentResize,
|
|
50
|
-
});
|
|
14
|
+
const [tooltipVisible, setTooltipVisible] = React.useState(false);
|
|
15
|
+
const layout = useViewportSplitTooltipLayout();
|
|
51
16
|
const headerFormat = React.useMemo(() => {
|
|
52
17
|
var _a, _b;
|
|
53
18
|
return ((_b = (_a = data.tooltip) === null || _a === void 0 ? void 0 : _a.headerFormat) !== null && _b !== void 0 ? _b : getDefaultTooltipHeaderFormat({
|
|
@@ -62,7 +27,7 @@ const SplitPaneContent = (props) => {
|
|
|
62
27
|
const pointerMoveHandler = (pointerMoveData, event) => {
|
|
63
28
|
var _a;
|
|
64
29
|
if (!isEmpty(pointerMoveData === null || pointerMoveData === void 0 ? void 0 : pointerMoveData.hovered)) {
|
|
65
|
-
|
|
30
|
+
setTooltipVisible(true);
|
|
66
31
|
(_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.redraw(pointerMoveData);
|
|
67
32
|
}
|
|
68
33
|
userPointerMoveHandler === null || userPointerMoveHandler === void 0 ? void 0 : userPointerMoveHandler(pointerMoveData, event);
|
|
@@ -71,57 +36,12 @@ const SplitPaneContent = (props) => {
|
|
|
71
36
|
hoveredPosition: { x: 0, y: 0 },
|
|
72
37
|
} }, data), { chart: Object.assign(Object.assign({}, data.chart), { events: Object.assign(Object.assign({}, (_c = data.chart) === null || _c === void 0 ? void 0 : _c.events), { pointermove: pointerMoveHandler }) }), tooltip: Object.assign(Object.assign({}, data.tooltip), { enabled: false }) });
|
|
73
38
|
}, [data]);
|
|
74
|
-
|
|
75
|
-
const deviceWidth = window.innerWidth;
|
|
76
|
-
const deviceHeight = window.innerHeight;
|
|
77
|
-
const nextSplit = deviceWidth > deviceHeight ? SplitLayout.VERTICAL : SplitLayout.HORIZONTAL;
|
|
78
|
-
setSplit(nextSplit);
|
|
79
|
-
}, [setSplit]);
|
|
80
|
-
const handleScreenOrientationChange = React.useCallback((e) => {
|
|
81
|
-
const type = e.target && 'type' in e.target && e.target.type;
|
|
82
|
-
if (!isScreenOrientationEventType(type)) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
setSplit(mapScreenOrientationTypeToSplitLayout(type));
|
|
86
|
-
}, [setSplit]);
|
|
87
|
-
const handleSizeChange = React.useCallback((nextSize) => {
|
|
88
|
-
var _a;
|
|
89
|
-
(_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.reflow();
|
|
90
|
-
if (split === SplitLayout.HORIZONTAL) {
|
|
91
|
-
setSize(nextSize);
|
|
92
|
-
}
|
|
93
|
-
}, [split, setSize]);
|
|
94
|
-
React.useLayoutEffect(() => {
|
|
95
|
-
if (IS_SCREEN_ORIENTATION_AVAILABLE) {
|
|
96
|
-
screen.orientation.addEventListener('change', handleScreenOrientationChange);
|
|
97
|
-
}
|
|
98
|
-
else if (IS_WINDOW_AVAILABLE) {
|
|
99
|
-
window.addEventListener('orientationchange', handleOrientationChange);
|
|
100
|
-
}
|
|
101
|
-
return () => {
|
|
102
|
-
if (IS_SCREEN_ORIENTATION_AVAILABLE) {
|
|
103
|
-
screen.orientation.removeEventListener('change', handleScreenOrientationChange);
|
|
104
|
-
}
|
|
105
|
-
else if (IS_WINDOW_AVAILABLE) {
|
|
106
|
-
window.removeEventListener('orientationchange', handleOrientationChange);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}, [handleOrientationChange, handleScreenOrientationChange]);
|
|
110
|
-
return (React.createElement(StyledSplitPane, { allowResize: allowResize, maxSize: maxSize, minSize: minSize, size: size, split: split, onChange: handleSizeChange, resizerStyle: shouldShowTooltip.current ? undefined : { display: 'none' }, paneOneRender: () => React.createElement(ChartComponent, Object.assign({}, restProps, { ref: chartRef, data: resultData })), paneTwoRender: () => (React.createElement("div", { ref: tooltipContainerRef },
|
|
111
|
-
React.createElement(TooltipContent, { ref: tooltipRef, renderer: resultData.tooltip.renderer, headerFormat: headerFormat, valueFormat: resultData.tooltip.valueFormat, rowRenderer: resultData.tooltip.rowRenderer, totals: resultData.tooltip.totals, rows: resultData.tooltip.rows }))), pane2Style: tooltipPaneStyles }));
|
|
39
|
+
return (React.createElement(SplitTooltip, { layout: layout, resizerVisible: tooltipVisible, onMainPaneSizeChange: () => { var _a; return (_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.reflow(); }, renderMainPane: () => (React.createElement(ChartComponent, Object.assign({}, restProps, { ref: chartRef, data: resultData }))), renderTooltip: () => (React.createElement(TooltipContent, { ref: tooltipRef, renderer: resultData.tooltip.renderer, headerFormat: headerFormat, valueFormat: resultData.tooltip.valueFormat, rowRenderer: resultData.tooltip.rowRenderer, totals: resultData.tooltip.totals, rows: resultData.tooltip.rows })) }));
|
|
112
40
|
};
|
|
113
41
|
export function withSplitPane(ChartComponent) {
|
|
114
42
|
const componentName = getComponentName(ChartComponent);
|
|
115
43
|
const component = React.forwardRef(function WithSplitPaneComponent(props, _ref) {
|
|
116
|
-
|
|
117
|
-
const [height, setHeight] = React.useState(0);
|
|
118
|
-
React.useEffect(() => {
|
|
119
|
-
var _a;
|
|
120
|
-
if (containerRef.current) {
|
|
121
|
-
setHeight((_a = containerRef.current.getBoundingClientRect().height) !== null && _a !== void 0 ? _a : 0);
|
|
122
|
-
}
|
|
123
|
-
}, []);
|
|
124
|
-
return (React.createElement("div", { ref: containerRef, style: { position: 'relative', height: '100%' } }, height ? (React.createElement(SplitPaneContent, Object.assign({ ChartComponent: ChartComponent }, props, { height: height }))) : null));
|
|
44
|
+
return React.createElement(SplitPaneContent, Object.assign({ ChartComponent: ChartComponent }, props));
|
|
125
45
|
});
|
|
126
46
|
component.displayName = `withSplitPane(${componentName})`;
|
|
127
47
|
return component;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/chartkit",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.62.1",
|
|
4
4
|
"description": "React component used to render charts based on any sources you need",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "git@github.com:gravity-ui/ChartKit.git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@bem-react/classname": "^1.6.0",
|
|
50
|
-
"@gravity-ui/charts": "^1.57.
|
|
50
|
+
"@gravity-ui/charts": "^1.57.2",
|
|
51
51
|
"@gravity-ui/date-utils": "^2.1.0",
|
|
52
52
|
"@gravity-ui/i18n": "^1.0.0",
|
|
53
53
|
"@gravity-ui/yagr": "^4.13.8",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { SplitLayoutType } from '../../../../components/SplitPane';
|
|
2
|
-
export declare const RESIZER_HEIGHT = 24;
|
|
3
|
-
type WithSplitPaneState = {
|
|
4
|
-
allowResize: boolean;
|
|
5
|
-
tooltipHeight: number;
|
|
6
|
-
setTooltipHeight: (value: number) => void;
|
|
7
|
-
split: SplitLayoutType;
|
|
8
|
-
setSplit: (value: SplitLayoutType) => void;
|
|
9
|
-
size: number | string;
|
|
10
|
-
setSize: (value: number | string) => void;
|
|
11
|
-
maxSize?: number;
|
|
12
|
-
minSize?: number;
|
|
13
|
-
};
|
|
14
|
-
type UseWithSplitPaneProps = {
|
|
15
|
-
containerHeight: number;
|
|
16
|
-
};
|
|
17
|
-
export declare function getVerticalSize(): number;
|
|
18
|
-
export declare function useWithSplitPaneState(props: UseWithSplitPaneProps): WithSplitPaneState;
|
|
19
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { SplitLayout } from '../../../../components/SplitPane';
|
|
3
|
-
import { IS_WINDOW_AVAILABLE } from '../../../../constants';
|
|
4
|
-
const CHART_SECTION_PERCENTAGE = 0.6;
|
|
5
|
-
export const RESIZER_HEIGHT = 24;
|
|
6
|
-
function getInitialSplit() {
|
|
7
|
-
if (!IS_WINDOW_AVAILABLE) {
|
|
8
|
-
return SplitLayout.HORIZONTAL;
|
|
9
|
-
}
|
|
10
|
-
return window.innerWidth > window.innerHeight ? SplitLayout.VERTICAL : SplitLayout.HORIZONTAL;
|
|
11
|
-
}
|
|
12
|
-
export function getVerticalSize() {
|
|
13
|
-
return window.innerWidth * CHART_SECTION_PERCENTAGE;
|
|
14
|
-
}
|
|
15
|
-
function getInitialSize(split, containerHeight) {
|
|
16
|
-
const defaultSize = containerHeight - RESIZER_HEIGHT;
|
|
17
|
-
if (!IS_WINDOW_AVAILABLE) {
|
|
18
|
-
return defaultSize;
|
|
19
|
-
}
|
|
20
|
-
return split === SplitLayout.VERTICAL ? getVerticalSize() : defaultSize;
|
|
21
|
-
}
|
|
22
|
-
export function useWithSplitPaneState(props) {
|
|
23
|
-
const { containerHeight } = props;
|
|
24
|
-
const [tooltipHeight, setTooltipHeight] = React.useState(0);
|
|
25
|
-
const [split, setSplit] = React.useState(getInitialSplit());
|
|
26
|
-
const [size, setSize] = React.useState(getInitialSize(split, containerHeight));
|
|
27
|
-
const allowResize = split === SplitLayout.HORIZONTAL;
|
|
28
|
-
let maxSize;
|
|
29
|
-
let minSize;
|
|
30
|
-
if (IS_WINDOW_AVAILABLE && split === SplitLayout.HORIZONTAL) {
|
|
31
|
-
maxSize = containerHeight - RESIZER_HEIGHT - tooltipHeight;
|
|
32
|
-
minSize = containerHeight / 3;
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
allowResize,
|
|
36
|
-
maxSize,
|
|
37
|
-
minSize,
|
|
38
|
-
tooltipHeight,
|
|
39
|
-
setTooltipHeight,
|
|
40
|
-
split,
|
|
41
|
-
setSplit,
|
|
42
|
-
size,
|
|
43
|
-
setSize,
|
|
44
|
-
};
|
|
45
|
-
}
|