@gravity-ui/chartkit 7.60.5 → 7.62.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/README.md +33 -2
- 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/docs/INDEX.md +111 -0
- package/build/docs/guides/testing.md +136 -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/build/plugins/yagr/types.d.ts +1 -1
- package/package.json +4 -2
- package/build/plugins/gravity-charts/renderer/withSplitPane/useWithSplitPaneState.d.ts +0 -19
- package/build/plugins/gravity-charts/renderer/withSplitPane/useWithSplitPaneState.js +0 -45
package/README.md
CHANGED
|
@@ -16,11 +16,11 @@ Each plugin renderer is lazy-loaded, so the underlying library code is only down
|
|
|
16
16
|
|
|
17
17
|
## Table of contents
|
|
18
18
|
|
|
19
|
-
- [Get started](#
|
|
19
|
+
- [Get started](#getting-started)
|
|
20
20
|
- [Updating charting packages](#updating-charting-packages)
|
|
21
21
|
- [Development](#development)
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Getting started
|
|
24
24
|
|
|
25
25
|
### Requirements
|
|
26
26
|
|
|
@@ -206,3 +206,34 @@ npm run test:docker:update
|
|
|
206
206
|
### Contributing
|
|
207
207
|
|
|
208
208
|
Please refer to the [contributing guide](CONTRIBUTING.md) before submitting a pull request.
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
Distributed under the MIT License. See [LICENSE](LICENSE) for details.
|
|
213
|
+
|
|
214
|
+
## For AI agents
|
|
215
|
+
|
|
216
|
+
A plugin-dispatching React component that renders charts from multiple Gravity UI charting libraries through one `<ChartKit type="..." data={...} />` API — reach for it when you need a single lazy-loading entry point for mixed chart types, instead of importing each chart library directly.
|
|
217
|
+
|
|
218
|
+
### When to use
|
|
219
|
+
|
|
220
|
+
- Rendering more than one charting engine (e.g. `gravity-charts` + `yagr`) behind one consistent component.
|
|
221
|
+
- Lazy-loading chart bundles — each plugin's renderer is `React.lazy`, so a library's code is only fetched when its chart type is actually shown.
|
|
222
|
+
- Bundling charts into a Gravity UI app that wants mobile-friendly tooltips and unified theming out of the box.
|
|
223
|
+
|
|
224
|
+
### When not to use
|
|
225
|
+
|
|
226
|
+
- For a single chart type only, import [`@gravity-ui/charts`](https://github.com/gravity-ui/charts) (general) or [`@gravity-ui/yagr`](https://github.com/gravity-ui/yagr) (high-performance time-series) directly — the plugin registry is overhead for one engine.
|
|
227
|
+
- To compose a dashboard grid of widgets, use [`@gravity-ui/dashkit`](https://github.com/gravity-ui/dashkit) — ChartKit renders a chart; DashKit arranges many widgets.
|
|
228
|
+
|
|
229
|
+
### Common pitfalls
|
|
230
|
+
|
|
231
|
+
- **Rendering `<ChartKit>` before `settings.set({plugins: [...]})`** — the global plugin registry must be populated at app entry; an unregistered `type` throws at render time.
|
|
232
|
+
- **Hallucinated prop `chartType` / `library`** — the dispatch prop is `type` (e.g. `type="gravity-charts"`), and the data is `data`.
|
|
233
|
+
- **Forgetting a container height** — `ChartKit` fills its parent; without an explicit height on the wrapper, the chart collapses to zero.
|
|
234
|
+
- **Expecting plugins to be bundled** — plugin renderers (`@gravity-ui/chartkit/gravity-charts`, `.../yagr`) are lazy; the first render of a type fetches its bundle.
|
|
235
|
+
- **Missing the uikit styles import** — theming depends on `@gravity-ui/uikit/styles/styles.css`; without it, charts render unstyled.
|
|
236
|
+
|
|
237
|
+
## Documentation for AI agents
|
|
238
|
+
|
|
239
|
+
Agent-readable documentation for the installed version is located in `node_modules/@gravity-ui/chartkit/build/docs/INDEX.md`.
|
|
@@ -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';
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @gravity-ui/chartkit documentation
|
|
2
|
+
|
|
3
|
+
Documentation for the **installed** version of `@gravity-ui/chartkit`.
|
|
4
|
+
Your training data may be outdated — these files are the source of truth.
|
|
5
|
+
|
|
6
|
+
Paths are relative to this file (`node_modules/@gravity-ui/chartkit/build/docs/`).
|
|
7
|
+
|
|
8
|
+
## For AI agents
|
|
9
|
+
|
|
10
|
+
A plugin-dispatching React component that renders charts from multiple Gravity UI charting libraries through one `<ChartKit type="..." data={...} />` API — reach for it when you need a single lazy-loading entry point for mixed chart types, instead of importing each chart library directly.
|
|
11
|
+
|
|
12
|
+
### When to use
|
|
13
|
+
|
|
14
|
+
- Rendering more than one charting engine (e.g. `gravity-charts` + `yagr`) behind one consistent component.
|
|
15
|
+
- Lazy-loading chart bundles — each plugin's renderer is `React.lazy`, so a library's code is only fetched when its chart type is actually shown.
|
|
16
|
+
- Bundling charts into a Gravity UI app that wants mobile-friendly tooltips and unified theming out of the box.
|
|
17
|
+
|
|
18
|
+
### When not to use
|
|
19
|
+
|
|
20
|
+
- For a single chart type only, import [`@gravity-ui/charts`](https://github.com/gravity-ui/charts) (general) or [`@gravity-ui/yagr`](https://github.com/gravity-ui/yagr) (high-performance time-series) directly — the plugin registry is overhead for one engine.
|
|
21
|
+
- To compose a dashboard grid of widgets, use [`@gravity-ui/dashkit`](https://github.com/gravity-ui/dashkit) — ChartKit renders a chart; DashKit arranges many widgets.
|
|
22
|
+
|
|
23
|
+
### Common pitfalls
|
|
24
|
+
|
|
25
|
+
- **Rendering `<ChartKit>` before `settings.set({plugins: [...]})`** — the global plugin registry must be populated at app entry; an unregistered `type` throws at render time.
|
|
26
|
+
- **Hallucinated prop `chartType` / `library`** — the dispatch prop is `type` (e.g. `type="gravity-charts"`), and the data is `data`.
|
|
27
|
+
- **Forgetting a container height** — `ChartKit` fills its parent; without an explicit height on the wrapper, the chart collapses to zero.
|
|
28
|
+
- **Expecting plugins to be bundled** — plugin renderers (`@gravity-ui/chartkit/gravity-charts`, `.../yagr`) are lazy; the first render of a type fetches its bundle.
|
|
29
|
+
- **Missing the uikit styles import** — theming depends on `@gravity-ui/uikit/styles/styles.css`; without it, charts render unstyled.
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```shell
|
|
34
|
+
npm install @gravity-ui/chartkit @gravity-ui/uikit
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
### Requirements
|
|
40
|
+
|
|
41
|
+
- React 16, 17, or 18
|
|
42
|
+
- `[@gravity-ui/uikit](https://github.com/gravity-ui/uikit)` — required peer dependency (provides theming and UI primitives)
|
|
43
|
+
|
|
44
|
+
### Styles
|
|
45
|
+
|
|
46
|
+
Import the styles from `@gravity-ui/uikit` in your entry point:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import '@gravity-ui/uikit/styles/fonts.css';
|
|
50
|
+
import '@gravity-ui/uikit/styles/styles.css';
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
For full setup details see the [uikit styles guide](https://github.com/gravity-ui/uikit?tab=readme-ov-file#styles).
|
|
54
|
+
|
|
55
|
+
### Basic usage
|
|
56
|
+
|
|
57
|
+
ChartKit uses a global plugin registry. Call `settings.set` once at your app entry point to register the plugins you need. When `<ChartKit type="..." />` renders, it looks up the matching plugin — if none is found, an error is thrown. Each plugin's renderer is a `React.lazy` component, so its code is fetched only when ChartKit first appears in the UI.
|
|
58
|
+
|
|
59
|
+
You can register multiple plugins at once:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
settings.set({plugins: [GravityChartsPlugin, YagrPlugin]});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Or call `settings.set` multiple times — it merges the plugin list rather than replacing it.
|
|
66
|
+
|
|
67
|
+
**Basic example:**
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import {ThemeProvider} from '@gravity-ui/uikit';
|
|
71
|
+
import ChartKit, {settings} from '@gravity-ui/chartkit';
|
|
72
|
+
import {GravityChartsPlugin} from '@gravity-ui/chartkit/gravity-charts';
|
|
73
|
+
|
|
74
|
+
import '@gravity-ui/uikit/styles/fonts.css';
|
|
75
|
+
import '@gravity-ui/uikit/styles/styles.css';
|
|
76
|
+
|
|
77
|
+
settings.set({plugins: [GravityChartsPlugin]});
|
|
78
|
+
|
|
79
|
+
const data = {
|
|
80
|
+
series: {
|
|
81
|
+
data: [
|
|
82
|
+
{
|
|
83
|
+
type: 'line',
|
|
84
|
+
name: 'Series',
|
|
85
|
+
data: [
|
|
86
|
+
{x: 0, y: 10},
|
|
87
|
+
{x: 1, y: 25},
|
|
88
|
+
{x: 2, y: 18},
|
|
89
|
+
{x: 3, y: 30},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export default function App() {
|
|
97
|
+
return (
|
|
98
|
+
<ThemeProvider theme="light">
|
|
99
|
+
<div style={{height: 300}}>
|
|
100
|
+
<ChartKit type="gravity-charts" data={data} />
|
|
101
|
+
</div>
|
|
102
|
+
</ThemeProvider>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`ChartKit` adapts to its parent's size — make sure the container has an explicit height.
|
|
108
|
+
|
|
109
|
+
## Guides
|
|
110
|
+
|
|
111
|
+
- [Testing Guide](./guides/testing.md)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Testing Guide
|
|
2
|
+
|
|
3
|
+
## Scripts
|
|
4
|
+
|
|
5
|
+
| Script | Description |
|
|
6
|
+
| --------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
7
|
+
| `npm test` | Run unit tests once |
|
|
8
|
+
| `npm run test:watch` | Run unit tests in watch mode |
|
|
9
|
+
| `npm run test:unit` | Alias for `npm test` |
|
|
10
|
+
| `npm run test:coverage` | Unit tests with coverage report (saved to `reports/coverage/`) |
|
|
11
|
+
| `npm run test:storybook` | Run all Storybook stories as tests |
|
|
12
|
+
| `npm run test:docker` | Run visual tests in Docker (Linux) — use this for visual testing |
|
|
13
|
+
| `npm run test:docker:update` | Update baseline screenshots via Docker |
|
|
14
|
+
| `npm run test:docker:clear-cache` | Clear Docker image cache |
|
|
15
|
+
| `npm run test:visual` | Run visual tests locally (macOS) — used internally by Docker scripts, not for regular use |
|
|
16
|
+
|
|
17
|
+
## Test Projects
|
|
18
|
+
|
|
19
|
+
The project uses [Vitest](https://vitest.dev/) with three test projects:
|
|
20
|
+
|
|
21
|
+
| Project | Environment | Pattern |
|
|
22
|
+
| ----------- | ------------------ | ----------------------------- |
|
|
23
|
+
| `unit` | Node | `src/**/*.test.ts?(x)` |
|
|
24
|
+
| `storybook` | Browser (Chromium) | Storybook stories |
|
|
25
|
+
| `visual` | Browser (Chromium) | `src/**/*.visual.test.ts?(x)` |
|
|
26
|
+
|
|
27
|
+
## Unit Tests
|
|
28
|
+
|
|
29
|
+
Standard Vitest tests running in Node. No browser, no screenshots.
|
|
30
|
+
|
|
31
|
+
Coverage report is saved to `reports/coverage/`.
|
|
32
|
+
|
|
33
|
+
## Visual (Screenshot) Tests
|
|
34
|
+
|
|
35
|
+
Visual tests use Playwright via `vitest-browser-react` and capture screenshots to compare against baselines.
|
|
36
|
+
|
|
37
|
+
### Running visual tests
|
|
38
|
+
|
|
39
|
+
**Always run visual tests via Docker** to ensure consistent Linux-based screenshots:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm run test:docker # run visual tests in Docker
|
|
43
|
+
npm run test:docker:update # update baseline screenshots
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Running `npm run test:visual` directly produces macOS screenshots (darwin) which are not committed and not used as baselines. This command is used internally by the Docker scripts.
|
|
47
|
+
|
|
48
|
+
### How screenshots work
|
|
49
|
+
|
|
50
|
+
Screenshots are stored next to the test file in a `__screenshots__/` directory. The filename is generated automatically.
|
|
51
|
+
|
|
52
|
+
Only Linux screenshots (generated via Docker) are committed to the repository — they serve as the CI baseline.
|
|
53
|
+
|
|
54
|
+
### Adding a new visual test
|
|
55
|
+
|
|
56
|
+
1. Create `src/plugins/<plugin>/__tests__/<Name>.visual.test.tsx`
|
|
57
|
+
2. Use `toMatchScreenshot()` for screenshot assertions:
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import React from 'react';
|
|
61
|
+
import {render} from '../../../../test-utils/utils.js';
|
|
62
|
+
import {ChartKit} from '../../../components/ChartKit.js';
|
|
63
|
+
import {settings} from '../../../libs/index.js';
|
|
64
|
+
import {MyPlugin} from '../index.js';
|
|
65
|
+
|
|
66
|
+
describe('MyPlugin visual tests', () => {
|
|
67
|
+
const options = {providers: {theme: 'light'}};
|
|
68
|
+
|
|
69
|
+
test('default state', async () => {
|
|
70
|
+
settings.set({plugins: [MyPlugin]});
|
|
71
|
+
const screen = await render(
|
|
72
|
+
<div style={{height: 300, width: '100%'}}>
|
|
73
|
+
<ChartKit id="my-chart" type="my-type" data={data} />
|
|
74
|
+
</div>,
|
|
75
|
+
options,
|
|
76
|
+
);
|
|
77
|
+
await expect(screen.getByRole('img')).toMatchScreenshot();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
3. Generate the baseline screenshot:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm run test:docker:update
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
4. Commit the generated `*-linux.png` file.
|
|
89
|
+
|
|
90
|
+
### Behavior-only visual tests
|
|
91
|
+
|
|
92
|
+
Not every visual test needs a screenshot. Use `expect.element().toBeVisible()` for asserting rendered state without capturing a screenshot:
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
test('no data state', async () => {
|
|
96
|
+
const screen = await render(<ChartKit id="empty" type="my-type" data={emptyData} />, options);
|
|
97
|
+
await expect.element(screen.getByText('No data')).toBeVisible();
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Updating screenshots
|
|
102
|
+
|
|
103
|
+
If a visual change is intentional, update the baselines:
|
|
104
|
+
|
|
105
|
+
**Locally (via Docker):**
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm run test:docker:update
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**On a pull request** — comment `/update-screenshots` on the PR. The bot will run the update workflow and push the new screenshots to the branch.
|
|
112
|
+
|
|
113
|
+
## Storybook Tests
|
|
114
|
+
|
|
115
|
+
Story-based tests run all stories through `@storybook/addon-vitest`. They verify stories render without errors and can include story-level play functions.
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm run test:storybook
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## CI
|
|
122
|
+
|
|
123
|
+
The CI pipeline (`.github/workflows/ci.yml`) runs:
|
|
124
|
+
|
|
125
|
+
- Lint + typecheck (`verify_files` job)
|
|
126
|
+
- Unit tests with coverage (`tests` job — runs `npm run test:unit -- --coverage`)
|
|
127
|
+
- Visual tests (`visual_tests` job — runs `npm run test:visual` on Ubuntu, matching the committed Linux baselines)
|
|
128
|
+
|
|
129
|
+
To update baselines after an intentional visual change, comment `/update-screenshots` on the PR.
|
|
130
|
+
|
|
131
|
+
### Test reports
|
|
132
|
+
|
|
133
|
+
After CI completes, test and coverage reports are uploaded to S3 and linked in a PR comment:
|
|
134
|
+
|
|
135
|
+
- Tests report: HTML Vitest report
|
|
136
|
+
- Coverage report: LCOV coverage report
|
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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MinimalValidConfig, RawSerieData, YagrConfig } from '@gravity-ui/yagr';
|
|
2
2
|
import type Yagr from '@gravity-ui/yagr';
|
|
3
|
-
import { ChartKitProps } from '
|
|
3
|
+
import type { ChartKitProps } from '../../types';
|
|
4
4
|
export type { default as Yagr } from '@gravity-ui/yagr';
|
|
5
5
|
export type { YagrReactRef } from '@gravity-ui/yagr/react';
|
|
6
6
|
export * from '@gravity-ui/yagr/dist/types';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/chartkit",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.62.0",
|
|
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.
|
|
50
|
+
"@gravity-ui/charts": "^1.57.1",
|
|
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",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@gravity-ui/eslint-config": "^4.2.1",
|
|
60
60
|
"@gravity-ui/prettier-config": "^1.1.0",
|
|
61
|
+
"@gravity-ui/readme-validator": "^1.3.0",
|
|
61
62
|
"@gravity-ui/stylelint-config": "^4.0.1",
|
|
62
63
|
"@gravity-ui/tsconfig": "^1.0.0",
|
|
63
64
|
"@gravity-ui/uikit": "^7.4.0",
|
|
@@ -121,6 +122,7 @@
|
|
|
121
122
|
"clean": "gulp clean",
|
|
122
123
|
"start": "storybook dev -p 7007",
|
|
123
124
|
"build": "gulp",
|
|
125
|
+
"build:docs": "gulp copy-docs",
|
|
124
126
|
"lint:js": "eslint .",
|
|
125
127
|
"lint:js:fix": "eslint . --fix",
|
|
126
128
|
"lint:styles": "cross-env stylelint '{styles,src}/**/*.scss'",
|
|
@@ -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
|
-
}
|