@gravity-ui/chartkit 7.43.1 → 7.44.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/README.md CHANGED
@@ -1,73 +1,198 @@
1
- # @gravity-ui/chartkit · [![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) [![npm package](https://img.shields.io/npm/v/@gravity-ui/chartkit)](https://www.npmjs.com/package/@gravity-ui/chartkit) [![storybook](https://img.shields.io/badge/Storybook-deployed-ff4685)](https://preview.gravity-ui.com/chartkit/)
1
+ # Gravity UI ChartKit · [![npm package](https://img.shields.io/npm/v/@gravity-ui/chartkit)](https://www.npmjs.com/package/@gravity-ui/chartkit) [![License](https://img.shields.io/github/license/gravity-ui/ChartKit)](LICENSE) [![CI](https://img.shields.io/github/actions/workflow/status/gravity-ui/ChartKit/.github/workflows/ci.yml?label=CI&logo=github)](https://github.com/gravity-ui/ChartKit/actions/workflows/ci.yml?query=branch:main) [![storybook](https://img.shields.io/badge/Storybook-deployed-ff4685)](https://preview.gravity-ui.com/chartkit/)
2
2
 
3
- React component used to render charts based on any sources you need
3
+ Plugin-based React component that provides a unified rendering interface for multiple charting libraries. You register one or more plugins and render charts via `<ChartKit type="..." data={...} />` — ChartKit dispatches to the correct renderer automatically.
4
4
 
5
- ## Install
5
+ Each plugin renderer is lazy-loaded, so the underlying library code is only downloaded when ChartKit is actually rendered in the UI. ChartKit also handles mobile-friendly tooltip display out of the box. You can use the built-in plugins or implement your own.
6
+
7
+ **When to use:**
8
+
9
+ - You need modern declarative charts (`gravity-charts`) or time-series / monitoring charts (`yagr`)
10
+ - You need multiple chart types under a single consistent API
11
+ - You're building in the Gravity UI ecosystem
12
+
13
+ **When not to use:**
14
+
15
+ - You only need one specific chart library — prefer using [@gravity-ui/charts](https://github.com/gravity-ui/charts) directly
16
+
17
+ ## Table of contents
18
+
19
+ - [Get started](#get-started)
20
+ - [Development](#development)
21
+
22
+ ## Get started
23
+
24
+ ### Requirements
25
+
26
+ - React 16, 17, or 18
27
+ - `[@gravity-ui/uikit](https://github.com/gravity-ui/uikit)` — required peer dependency (provides theming and UI primitives)
28
+
29
+ ### Install
6
30
 
7
31
  ```shell
8
- npm i --save-dev @gravity-ui/chartkit @gravity-ui/uikit
32
+ npm install @gravity-ui/chartkit @gravity-ui/uikit
9
33
  ```
10
34
 
11
- Make sure you have `@gravity-ui/uikit` styles enabled in your project.
35
+ ### Styles
12
36
 
13
- ```typescript
14
- import '@gravity-ui/uikit/styles/styles.scss';
37
+ Import the styles from `@gravity-ui/uikit` in your entry point:
38
+
39
+ ```tsx
40
+ import '@gravity-ui/uikit/styles/fonts.css';
41
+ import '@gravity-ui/uikit/styles/styles.css';
42
+ ```
43
+
44
+ For full setup details see the [uikit styles guide](https://github.com/gravity-ui/uikit?tab=readme-ov-file#styles).
45
+
46
+ ### Basic usage
47
+
48
+ 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.
49
+
50
+ You can register multiple plugins at once:
51
+
52
+ ```ts
53
+ settings.set({plugins: [GravityChartsPlugin, YagrPlugin]});
15
54
  ```
16
55
 
17
- ## Usage
56
+ Or call `settings.set` multiple times — it merges the plugin list rather than replacing it.
57
+
58
+ **Basic example:**
18
59
 
19
- ```typescript
60
+ ```tsx
20
61
  import {ThemeProvider} from '@gravity-ui/uikit';
21
62
  import ChartKit, {settings} from '@gravity-ui/chartkit';
22
- import {YagrPlugin} from '@gravity-ui/chartkit/yagr';
23
- import type {YagrWidgetData} from '@gravity-ui/chartkit/yagr';
63
+ import {GravityChartsPlugin} from '@gravity-ui/chartkit/gravity-charts';
24
64
 
25
- import '@gravity-ui/uikit/styles/styles.scss';
65
+ import '@gravity-ui/uikit/styles/fonts.css';
66
+ import '@gravity-ui/uikit/styles/styles.css';
26
67
 
27
- settings.set({plugins: [YagrPlugin]});
68
+ settings.set({plugins: [GravityChartsPlugin]});
28
69
 
29
- const data: YagrWidgetData = {
30
- data: {
31
- timeline: [
32
- 1636838612441, 1636925012441, 1637011412441, 1637097812441, 1637184212441, 1637270612441,
33
- 1637357012441, 1637443412441, 1637529812441, 1637616212441,
34
- ],
35
- graphs: [
36
- {
37
- id: '0',
38
- name: 'Serie 1',
39
- color: '#6c59c2',
40
- data: [25, 52, 89, 72, 39, 49, 82, 59, 36, 5],
41
- },
70
+ const data = {
71
+ series: {
72
+ data: [
42
73
  {
43
- id: '1',
44
- name: 'Serie 2',
45
- color: '#6e8188',
46
- data: [37, 6, 51, 10, 65, 35, 72, 0, 94, 54],
47
- },
48
- ],
49
- },
50
- libraryConfig: {
51
- chart: {
52
- series: {
53
74
  type: 'line',
75
+ name: 'Series',
76
+ data: [
77
+ {x: 0, y: 10},
78
+ {x: 1, y: 25},
79
+ {x: 2, y: 18},
80
+ {x: 3, y: 30},
81
+ ],
54
82
  },
55
- },
56
- title: {
57
- text: 'line: random 10 pts',
58
- },
83
+ ],
59
84
  },
60
85
  };
61
86
 
62
- function App() {
87
+ export default function App() {
63
88
  return (
64
- <ThemeProvider>
65
- <div className="app" style={{height: 500}}>
66
- <ChartKit type="yagr" data={data} />
89
+ <ThemeProvider theme="light">
90
+ <div style={{height: 300}}>
91
+ <ChartKit type="gravity-charts" data={data} />
67
92
  </div>
68
93
  </ThemeProvider>
69
94
  );
70
95
  }
96
+ ```
97
+
98
+ `ChartKit` adapts to its parent's size — make sure the container has an explicit height.
99
+
100
+ ## Development
101
+
102
+ ### Prerequisites
103
+
104
+ - [Node.js](https://nodejs.org/) 22 (see [.nvmrc](https://github.com/gravity-ui/ChartKit/blob/main/.nvmrc))
105
+ - [npm](https://www.npmjs.com/) 10 or later
71
106
 
72
- export default App;
107
+ ### Setup
108
+
109
+ Clone the repository and install dependencies:
110
+
111
+ ```shell
112
+ git clone https://github.com/gravity-ui/ChartKit.git
113
+ cd ChartKit
114
+ npm ci
115
+ ```
116
+
117
+ ### Running Storybook
118
+
119
+ ```shell
120
+ npm run start
73
121
  ```
122
+
123
+ Storybook will be available at `http://localhost:7007`.
124
+
125
+ ### Developing with a local dependency
126
+
127
+ To work on a dependency (e.g. `@gravity-ui/charts`) and see your changes live in Storybook without publishing to npm:
128
+
129
+ **1. Link the local package**
130
+
131
+ ```shell
132
+ # In your local clone of @gravity-ui/charts:
133
+ git clone https://github.com/gravity-ui/charts.git
134
+ cd charts
135
+ npm ci
136
+ # make your changes
137
+ npm run build
138
+ npm link
139
+
140
+ # In ChartKit:
141
+ npm link @gravity-ui/charts
142
+ ```
143
+
144
+ **2. Configure local package watching**
145
+
146
+ Create a `.env.local` file in the ChartKit root (it is gitignored):
147
+
148
+ ```shell
149
+ LOCAL_PKG=@gravity-ui/charts
150
+ ```
151
+
152
+ This tells Vite to watch that package in `node_modules` and skip pre-bundling it. After rebuilding `@gravity-ui/charts`, Storybook will hot-reload automatically.
153
+
154
+ For multiple packages, use a comma-separated list:
155
+
156
+ ```shell
157
+ LOCAL_PKG=@gravity-ui/charts,@gravity-ui/uikit
158
+ ```
159
+
160
+ **3. Start Storybook**
161
+
162
+ ```shell
163
+ npm run start
164
+ ```
165
+
166
+ **4. Restore the original package**
167
+
168
+ When you're done:
169
+
170
+ 1. Comment out `LOCAL_PKG` in `.env.local`
171
+ 2. Run `npm install` in ChartKit — it replaces the symlink with the registry version
172
+
173
+ ```shell
174
+ # In ChartKit:
175
+ npm ci
176
+ ```
177
+
178
+ ### Running tests
179
+
180
+ ```shell
181
+ npm test
182
+ ```
183
+
184
+ Visual regression tests run in Docker to ensure consistent screenshots across environments:
185
+
186
+ ```shell
187
+ npm run test:docker
188
+ ```
189
+
190
+ To update the reference screenshots after intentional UI changes:
191
+
192
+ ```shell
193
+ npm run test:docker:update
194
+ ```
195
+
196
+ ### Contributing
197
+
198
+ Please refer to the [contributing guide](CONTRIBUTING.md) before submitting a pull request.
@@ -1,5 +1,5 @@
1
1
  .styled-split-pane__pane-resizer {
2
- background: var(--g-color-base-generic);
2
+ background: linear-gradient(to right, var(--g-color-base-generic), var(--g-color-base-generic)), linear-gradient(to right, var(--g-color-base-background), var(--g-color-base-background));
3
3
  z-index: 1;
4
4
  box-sizing: border-box;
5
5
  position: relative;
@@ -41,10 +41,12 @@
41
41
  height: 100%;
42
42
  width: 1px;
43
43
  min-width: 1px;
44
- background: var(--data-table-border-color);
45
44
  }
46
45
 
47
46
  .styled-split-pane .Pane {
48
47
  height: 100%;
49
- background: var(--ck-split-pane-background);
48
+ }
49
+
50
+ .styled-split-pane .Pane2 {
51
+ background: linear-gradient(to right, var(--g-color-infographics-tooltip-bg), var(--g-color-infographics-tooltip-bg)), linear-gradient(to right, var(--g-color-base-background), var(--g-color-base-background));
50
52
  }
@@ -11,7 +11,7 @@ import { TooltipContent } from './TooltipContent';
11
11
  import { RESIZER_HEIGHT, getVerticalSize, useWithSplitPaneState } from './useWithSplitPaneState';
12
12
  const tooltipPaneStyles = { overflow: 'auto' };
13
13
  const SplitPaneContent = (props) => {
14
- var _a, _b;
14
+ var _a;
15
15
  const { data, height, ChartComponent } = props, restProps = __rest(props, ["data", "height", "ChartComponent"]);
16
16
  const tooltipContainerRef = React.useRef(null);
17
17
  const chartRef = React.useRef(null);
@@ -31,7 +31,10 @@ const SplitPaneContent = (props) => {
31
31
  const containerHeight = height;
32
32
  if (containerHeight - RESIZER_HEIGHT === size) {
33
33
  setSize(containerHeight - RESIZER_HEIGHT - tooltipHeight);
34
- (_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.reflow();
34
+ queueMicrotask(() => {
35
+ var _a;
36
+ (_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.reflow({ immediate: true });
37
+ });
35
38
  }
36
39
  }
37
40
  const handleTooltipContentResize = React.useCallback(() => {
@@ -52,7 +55,7 @@ const SplitPaneContent = (props) => {
52
55
  yAxes: data.yAxis,
53
56
  xAxis: data.xAxis,
54
57
  }));
55
- }, [(_b = data.tooltip) === null || _b === void 0 ? void 0 : _b.headerFormat, data.series.data, data.yAxis, data.xAxis]);
58
+ }, [(_a = data.tooltip) === null || _a === void 0 ? void 0 : _a.headerFormat, data.series.data, data.yAxis, data.xAxis]);
56
59
  const resultData = React.useMemo(() => {
57
60
  var _a, _b, _c;
58
61
  const userPointerMoveHandler = (_b = (_a = data.chart) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.pointermove;
@@ -64,7 +67,9 @@ const SplitPaneContent = (props) => {
64
67
  }
65
68
  userPointerMoveHandler === null || userPointerMoveHandler === void 0 ? void 0 : userPointerMoveHandler(pointerMoveData, event);
66
69
  };
67
- return Object.assign(Object.assign({}, 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 }) });
70
+ return Object.assign(Object.assign({ defaultState: {
71
+ hoveredPosition: { x: 0, y: 0 },
72
+ } }, 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 }) });
68
73
  }, [data]);
69
74
  const handleOrientationChange = React.useCallback(() => {
70
75
  const deviceWidth = window.innerWidth;
@@ -1074,7 +1074,7 @@ function drillOnClick(event, { options, chartType }) {
1074
1074
  const point = event.point;
1075
1075
  const series = point.series;
1076
1076
  if (isColorDrillDown) {
1077
- return series.name;
1077
+ return series.drillDownFilterValue || series.name;
1078
1078
  }
1079
1079
  let drillDownFilter = point.options.drillDownFilterValue || point.category || point.name;
1080
1080
  const isDateTime = chartType !== 'pie' &&
@@ -49,13 +49,13 @@ export declare const getSortedData: <T extends Record<string, any>>(data: T[], s
49
49
  [Symbol.iterator]?: boolean | undefined;
50
50
  readonly [Symbol.unscopables]?: boolean | undefined;
51
51
  at?: boolean | undefined;
52
- } | ((start?: number, end?: number) => T[]) | (() => string) | {
52
+ } | (() => string) | {
53
53
  (): string;
54
54
  (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
55
55
  } | (() => T | undefined) | ((...items: T[]) => number) | {
56
56
  (...items: ConcatArray<T>[]): T[];
57
57
  (...items: (T | ConcatArray<T>)[]): T[];
58
- } | ((separator?: string) => string) | (() => T[]) | (() => T | undefined) | ((compareFn?: ((a: T, b: T) => number) | undefined) => T[]) | {
58
+ } | ((separator?: string) => string) | (() => T[]) | (() => T | undefined) | ((start?: number, end?: number) => T[]) | ((compareFn?: ((a: T, b: T) => number) | undefined) => T[]) | {
59
59
  (start: number, deleteCount?: number): T[];
60
60
  (start: number, deleteCount: number, ...items: T[]): T[];
61
61
  } | ((...items: T[]) => number) | ((searchElement: T, fromIndex?: number) => number) | ((searchElement: T, fromIndex?: number) => number) | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "7.43.1",
3
+ "version": "7.44.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.41.1",
50
+ "@gravity-ui/charts": "^1.42.2",
51
51
  "@gravity-ui/date-utils": "^2.1.0",
52
52
  "@gravity-ui/i18n": "^1.0.0",
53
53
  "@gravity-ui/yagr": "^4.11.0",