@gravity-ui/chartkit 2.10.0 → 2.11.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/build/components/ChartKit.d.ts +1 -0
  3. package/build/components/ChartKit.js +1 -1
  4. package/build/components/ErrorBoundary/ErrorBoundary.d.ts +5 -1
  5. package/build/components/ErrorBoundary/ErrorBoundary.js +24 -2
  6. package/build/plugins/highcharts/__stories__/components/ChartStory.d.ts +5 -1
  7. package/build/plugins/highcharts/__stories__/components/ChartStory.js +9 -3
  8. package/build/plugins/highcharts/__stories__/custom-error-render/custom-error-render.stories.d.ts +4 -0
  9. package/build/plugins/highcharts/__stories__/custom-error-render/custom-error-render.stories.js +41 -0
  10. package/build/plugins/highcharts/__stories__/no-data/no-data.stories.d.ts +4 -0
  11. package/build/plugins/highcharts/__stories__/no-data/no-data.stories.js +20 -0
  12. package/build/plugins/highcharts/__stories__/pie/WithTotals.stories.d.ts +4 -0
  13. package/build/plugins/highcharts/__stories__/pie/WithTotals.stories.js +12 -0
  14. package/build/plugins/highcharts/mocks/custom-error-render.d.ts +3 -0
  15. package/build/plugins/highcharts/mocks/custom-error-render.js +69 -0
  16. package/build/plugins/highcharts/mocks/no-data.d.ts +3 -0
  17. package/build/plugins/highcharts/mocks/no-data.js +69 -0
  18. package/build/plugins/highcharts/mocks/pie-with-totals.d.ts +2 -0
  19. package/build/plugins/highcharts/mocks/pie-with-totals.js +43 -0
  20. package/build/plugins/highcharts/renderer/HighchartsWidget.d.ts +1 -0
  21. package/build/plugins/highcharts/renderer/helpers/config/config.js +4 -1
  22. package/build/plugins/highcharts/types/widget.d.ts +1 -0
  23. package/build/plugins/indicator/renderer/IndicatorWidget.d.ts +1 -0
  24. package/build/plugins/yagr/renderer/YagrWidget.d.ts +1 -0
  25. package/build/types/index.d.ts +8 -0
  26. package/build/utils/getErrorMessage.d.ts +2 -0
  27. package/build/utils/getErrorMessage.js +5 -0
  28. package/package.json +1 -1
  29. package/build/components/ErrorView/ErrorView.d.ts +0 -7
  30. package/build/components/ErrorView/ErrorView.js +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.11.0](https://github.com/gravity-ui/chartkit/compare/v2.10.1...v2.11.0) (2023-06-20)
4
+
5
+
6
+ ### Features
7
+
8
+ * add renderError property ([#175](https://github.com/gravity-ui/chartkit/issues/175)) ([84c03a9](https://github.com/gravity-ui/chartkit/commit/84c03a9f8516e9fb846e25a920aa82b00c660a02))
9
+ * **main:** Add renderErrorView prop for custom render and handle errors ([15e314f](https://github.com/gravity-ui/chartkit/commit/15e314f40c378aa65c4d83055760f49fb56af539))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * **main:** reset "No data" error on change data ([ac0da94](https://github.com/gravity-ui/chartkit/commit/ac0da94fd21ff558a739c00b8904645d5ba006ef))
15
+
16
+ ## [2.10.1](https://github.com/gravity-ui/chartkit/compare/v2.10.0...v2.10.1) (2023-06-19)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * **Highcharts plugin:** show totals of selected series on legend click ([#176](https://github.com/gravity-ui/chartkit/issues/176)) ([ac7fe22](https://github.com/gravity-ui/chartkit/commit/ac7fe224363f7379f6dd35db0a3a682cdc7a2bc2))
22
+
3
23
  ## [2.10.0](https://github.com/gravity-ui/chartkit/compare/v2.9.0...v2.10.0) (2023-06-05)
4
24
 
5
25
 
@@ -13,6 +13,7 @@ export declare const ChartKit: <T extends keyof import("../types").ChartKitWidge
13
13
  onLoad?: ((data?: import("../types").ChartKitOnLoadData<T> | undefined) => void) | undefined;
14
14
  onRender?: ((data: import("../types").ChartKitOnRenderData) => void) | undefined;
15
15
  onChartLoad?: ((data: import("../types").ChartKitOnChartLoad<T>) => void) | undefined;
16
+ renderError?: import("../types").RenderError | undefined;
16
17
  onError?: import("../types").ChartKitOnError | undefined;
17
18
  } & { [key in keyof Omit<import("../types").ChartKitWidget[T], "widget" | "data">]: import("../types").ChartKitWidget[T][key]; } & {
18
19
  ref?: React.ForwardedRef<ChartKitRef | undefined> | undefined;
@@ -36,7 +36,7 @@ const ChartKitComponent = (props) => {
36
36
  React.createElement(ChartComponent, Object.assign({ ref: widgetRef, id: id, lang: lang }, restProps)))));
37
37
  };
38
38
  const ChartKitComponentWithErrorBoundary = React.forwardRef(function ChartKitComponentWithErrorBoundary(props, ref) {
39
- return (React.createElement(ErrorBoundary, { onError: props.onError },
39
+ return (React.createElement(ErrorBoundary, { onError: props.onError, data: props.data, renderError: props.renderError },
40
40
  React.createElement(ChartKitComponent, Object.assign({ instanceRef: ref }, props))));
41
41
  }) /* https://stackoverflow.com/a/58473012 */;
42
42
  export const ChartKit = typedMemo(ChartKitComponentWithErrorBoundary);
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
2
  import type { ChartKitError } from '../../libs';
3
- import type { ChartKitOnError } from '../../types';
3
+ import type { ChartKitOnError, ChartKitType, ChartKitWidget, RenderError } from '../../types';
4
4
  declare type Props = {
5
5
  onError?: ChartKitOnError;
6
+ data: ChartKitWidget[ChartKitType]['data'];
7
+ renderError?: RenderError;
6
8
  };
7
9
  declare type State = {
8
10
  error?: ChartKitError | Error;
@@ -13,6 +15,8 @@ export declare class ErrorBoundary extends React.Component<Props, State> {
13
15
  };
14
16
  state: State;
15
17
  componentDidCatch(): void;
18
+ componentDidUpdate(prevProps: Readonly<Props>): void;
16
19
  render(): React.ReactNode;
20
+ resetError: () => void;
17
21
  }
18
22
  export {};
@@ -1,11 +1,17 @@
1
1
  import React from 'react';
2
- import { ErrorView } from '../ErrorView/ErrorView';
2
+ import { getErrorMessage } from '../../utils/getErrorMessage';
3
+ import { CHARTKIT_ERROR_CODE } from '../../libs';
3
4
  export class ErrorBoundary extends React.Component {
4
5
  constructor() {
5
6
  super(...arguments);
6
7
  this.state = {
7
8
  error: undefined,
8
9
  };
10
+ this.resetError = () => {
11
+ if (this.state.error) {
12
+ this.setState({ error: undefined });
13
+ }
14
+ };
9
15
  }
10
16
  static getDerivedStateFromError(error) {
11
17
  return { error };
@@ -17,10 +23,26 @@ export class ErrorBoundary extends React.Component {
17
23
  (_b = (_a = this.props).onError) === null || _b === void 0 ? void 0 : _b.call(_a, { error });
18
24
  }
19
25
  }
26
+ componentDidUpdate(prevProps) {
27
+ if (prevProps.data !== this.props.data) {
28
+ const { error } = this.state;
29
+ if (error && 'code' in error && error.code === CHARTKIT_ERROR_CODE.NO_DATA) {
30
+ this.resetError();
31
+ }
32
+ }
33
+ }
20
34
  render() {
21
35
  const { error } = this.state;
22
36
  if (error) {
23
- return React.createElement(ErrorView, { error: error });
37
+ const message = getErrorMessage(error);
38
+ if (this.props.renderError) {
39
+ return this.props.renderError({
40
+ error,
41
+ message,
42
+ resetError: this.resetError,
43
+ });
44
+ }
45
+ return React.createElement("div", null, message);
24
46
  }
25
47
  return this.props.children;
26
48
  }
@@ -1,8 +1,12 @@
1
1
  import React from 'react';
2
+ import { RenderError } from '../../../../types';
2
3
  import { HighchartsWidgetData } from '../../types';
3
4
  export declare type ChartStoryProps = {
5
+ data: HighchartsWidgetData;
6
+ withoutPlugin?: boolean;
7
+ visible?: boolean;
4
8
  height?: string;
5
9
  width?: string;
6
- data: HighchartsWidgetData;
10
+ renderError?: RenderError;
7
11
  };
8
12
  export declare const ChartStory: React.FC<ChartStoryProps>;
@@ -8,15 +8,21 @@ const DEFAULT_STORY_HEIGHT = '300px';
8
8
  const DEFAULT_STORY_WIDTH = '100%';
9
9
  export const ChartStory = (props) => {
10
10
  const { height, width, data } = props;
11
- const [visible, setVisible] = React.useState(false);
11
+ const initRef = React.useRef(false);
12
+ const [visible, setVisible] = React.useState(Boolean(props.visible));
12
13
  const chartKitRef = React.useRef();
14
+ if (!initRef.current) {
15
+ if (!props.withoutPlugin) {
16
+ settings.set({ plugins: [HighchartsPlugin], extra: { holidays } });
17
+ }
18
+ initRef.current = true;
19
+ }
13
20
  if (!visible) {
14
- settings.set({ plugins: [HighchartsPlugin], extra: { holidays } });
15
21
  return React.createElement(Button, { onClick: () => setVisible(true) }, "Show chart");
16
22
  }
17
23
  return (React.createElement("div", { style: {
18
24
  height: height || DEFAULT_STORY_HEIGHT,
19
25
  width: width || DEFAULT_STORY_WIDTH,
20
26
  } },
21
- React.createElement(ChartKit, { ref: chartKitRef, type: "highcharts", data: data })));
27
+ React.createElement(ChartKit, { ref: chartKitRef, type: "highcharts", data: data, renderError: props.renderError })));
22
28
  };
@@ -0,0 +1,4 @@
1
+ import { Meta, Story } from '@storybook/react';
2
+ declare const _default: Meta<import("@storybook/react").Args>;
3
+ export default _default;
4
+ export declare const CustomErrorRender: Story<import("@storybook/react").Args>;
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import { ChartStory } from '../components/ChartStory';
4
+ import { Button } from '@gravity-ui/uikit';
5
+ import { CHARTKIT_ERROR_CODE, settings } from '../../../../libs';
6
+ import { HighchartsPlugin } from '../../index';
7
+ import holidays from '../../mocks/holidays';
8
+ import { noData, filledData } from '../../mocks/custom-error-render';
9
+ export default {
10
+ title: 'Plugins/Highcharts/CustomErrorRender',
11
+ component: ChartKit,
12
+ };
13
+ const Template = () => {
14
+ const [data, setData] = React.useState(noData);
15
+ const renderErrorView = React.useCallback(({ error, message, resetError }) => {
16
+ function renderFixButton() {
17
+ if (!('code' in error)) {
18
+ return null;
19
+ }
20
+ switch (error.code) {
21
+ case CHARTKIT_ERROR_CODE.UNKNOWN_PLUGIN:
22
+ return (React.createElement(Button, { onClick: () => {
23
+ settings.set({ plugins: [HighchartsPlugin], extra: { holidays } });
24
+ resetError();
25
+ } }, "Add highcharts plugin"));
26
+ case CHARTKIT_ERROR_CODE.NO_DATA:
27
+ return (React.createElement(Button, { onClick: () => {
28
+ setData(filledData);
29
+ } }, "Add data"));
30
+ default:
31
+ return null;
32
+ }
33
+ }
34
+ return (React.createElement("div", null,
35
+ React.createElement("h2", null, message),
36
+ renderFixButton()));
37
+ }, []);
38
+ return (React.createElement("div", null,
39
+ React.createElement(ChartStory, { withoutPlugin: true, data: data, visible: true, renderError: renderErrorView })));
40
+ };
41
+ export const CustomErrorRender = Template.bind({});
@@ -0,0 +1,4 @@
1
+ import { Meta, Story } from '@storybook/react';
2
+ declare const _default: Meta<import("@storybook/react").Args>;
3
+ export default _default;
4
+ export declare const NoData: Story<import("@storybook/react").Args>;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import { noData, filledData } from '../../mocks/no-data';
4
+ import { ChartStory } from '../components/ChartStory';
5
+ import { Button } from '@gravity-ui/uikit';
6
+ export default {
7
+ title: 'Plugins/Highcharts/NoData',
8
+ component: ChartKit,
9
+ };
10
+ const Template = () => {
11
+ const [data, setData] = React.useState(noData);
12
+ const handleUpdateData = React.useCallback(() => {
13
+ setData(filledData);
14
+ }, []);
15
+ return (React.createElement("div", null,
16
+ React.createElement("div", { style: { marginBottom: 12 } },
17
+ React.createElement(Button, { onClick: handleUpdateData }, "Add data")),
18
+ React.createElement(ChartStory, { data: data, visible: true })));
19
+ };
20
+ export const NoData = Template.bind({});
@@ -0,0 +1,4 @@
1
+ import { Meta, Story } from '@storybook/react';
2
+ declare const _default: Meta<import("@storybook/react").Args>;
3
+ export default _default;
4
+ export declare const WithTotals: Story<any>;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import { data } from '../../mocks/pie-with-totals';
4
+ import { ChartStory } from '../components/ChartStory';
5
+ export default {
6
+ title: 'Plugins/Highcharts/Pie',
7
+ component: ChartKit,
8
+ };
9
+ const Template = () => {
10
+ return React.createElement(ChartStory, { data: data });
11
+ };
12
+ export const WithTotals = Template.bind({});
@@ -0,0 +1,3 @@
1
+ import type { HighchartsWidgetData } from '../types';
2
+ export declare const noData: HighchartsWidgetData;
3
+ export declare const filledData: HighchartsWidgetData;
@@ -0,0 +1,69 @@
1
+ const baseData = {
2
+ config: {
3
+ hideHolidays: false,
4
+ normalizeDiv: false,
5
+ normalizeSub: false,
6
+ },
7
+ libraryConfig: {
8
+ chart: {
9
+ type: 'arearange',
10
+ },
11
+ title: {
12
+ text: 'Temperature variation by day',
13
+ },
14
+ xAxis: {
15
+ type: 'datetime',
16
+ },
17
+ tooltip: {
18
+ valueSuffix: '°C',
19
+ },
20
+ },
21
+ };
22
+ export const noData = Object.assign(Object.assign({}, baseData), { data: {
23
+ graphs: [
24
+ {
25
+ name: 'Temperatures',
26
+ data: [],
27
+ },
28
+ ],
29
+ } });
30
+ export const filledData = Object.assign(Object.assign({}, baseData), { data: {
31
+ graphs: [
32
+ {
33
+ name: 'Temperatures',
34
+ data: [
35
+ [1246406400000, 10.4, 17],
36
+ [1246492800000, 10.3, 28.6],
37
+ [1246579200000, 14.8, 18.4],
38
+ [1246665600000, 11.5, 25.8],
39
+ [1246752000000, 11.1, 24.4],
40
+ [1246838400000, 17.7, 19.6],
41
+ [1246924800000, 15.1, 18.1],
42
+ [1247011200000, 15.1, 27.2],
43
+ [1247097600000, 17, 17.5],
44
+ [1247184000000, 12.6, 18.5],
45
+ [1247270400000, 12.2, 26],
46
+ [1247356800000, 15.9, 22.9],
47
+ [1247443200000, 17.1, 18.1],
48
+ [1247529600000, 13.3, 24.2],
49
+ [1247616000000, 17, 28.1],
50
+ [1247702400000, 16.2, 22.6],
51
+ [1247788800000, 10.6, 19],
52
+ [1247875200000, 11.3, 19.7],
53
+ [1247961600000, 14.1, 24.6],
54
+ [1248048000000, 14.2, 22.5],
55
+ [1248134400000, 14.1, 28.5],
56
+ [1248220800000, 14, 27],
57
+ [1248307200000, 10.2, 20.6],
58
+ [1248393600000, 13.1, 29.9],
59
+ [1248480000000, 13.7, 21.1],
60
+ [1248566400000, 15, 28.6],
61
+ [1248652800000, 12, 17.5],
62
+ [1248739200000, 17.8, 24.4],
63
+ [1248825600000, 11.7, 25.9],
64
+ [1248912000000, 13.6, 25.6],
65
+ [1248998400000, 17.3, 22.2],
66
+ ],
67
+ },
68
+ ],
69
+ } });
@@ -0,0 +1,3 @@
1
+ import type { HighchartsWidgetData } from '../types';
2
+ export declare const noData: HighchartsWidgetData;
3
+ export declare const filledData: HighchartsWidgetData;
@@ -0,0 +1,69 @@
1
+ const baseData = {
2
+ config: {
3
+ hideHolidays: false,
4
+ normalizeDiv: false,
5
+ normalizeSub: false,
6
+ },
7
+ libraryConfig: {
8
+ chart: {
9
+ type: 'arearange',
10
+ },
11
+ title: {
12
+ text: 'Temperature variation by day',
13
+ },
14
+ xAxis: {
15
+ type: 'datetime',
16
+ },
17
+ tooltip: {
18
+ valueSuffix: '°C',
19
+ },
20
+ },
21
+ };
22
+ export const noData = Object.assign(Object.assign({}, baseData), { data: {
23
+ graphs: [
24
+ {
25
+ name: 'Temperatures',
26
+ data: [],
27
+ },
28
+ ],
29
+ } });
30
+ export const filledData = Object.assign(Object.assign({}, baseData), { data: {
31
+ graphs: [
32
+ {
33
+ name: 'Temperatures',
34
+ data: [
35
+ [1246406400000, 10.4, 17],
36
+ [1246492800000, 10.3, 28.6],
37
+ [1246579200000, 14.8, 18.4],
38
+ [1246665600000, 11.5, 25.8],
39
+ [1246752000000, 11.1, 24.4],
40
+ [1246838400000, 17.7, 19.6],
41
+ [1246924800000, 15.1, 18.1],
42
+ [1247011200000, 15.1, 27.2],
43
+ [1247097600000, 17, 17.5],
44
+ [1247184000000, 12.6, 18.5],
45
+ [1247270400000, 12.2, 26],
46
+ [1247356800000, 15.9, 22.9],
47
+ [1247443200000, 17.1, 18.1],
48
+ [1247529600000, 13.3, 24.2],
49
+ [1247616000000, 17, 28.1],
50
+ [1247702400000, 16.2, 22.6],
51
+ [1247788800000, 10.6, 19],
52
+ [1247875200000, 11.3, 19.7],
53
+ [1247961600000, 14.1, 24.6],
54
+ [1248048000000, 14.2, 22.5],
55
+ [1248134400000, 14.1, 28.5],
56
+ [1248220800000, 14, 27],
57
+ [1248307200000, 10.2, 20.6],
58
+ [1248393600000, 13.1, 29.9],
59
+ [1248480000000, 13.7, 21.1],
60
+ [1248566400000, 15, 28.6],
61
+ [1248652800000, 12, 17.5],
62
+ [1248739200000, 17.8, 24.4],
63
+ [1248825600000, 11.7, 25.9],
64
+ [1248912000000, 13.6, 25.6],
65
+ [1248998400000, 17.3, 22.2],
66
+ ],
67
+ },
68
+ ],
69
+ } });
@@ -0,0 +1,2 @@
1
+ import { HighchartsWidgetData } from '../types';
2
+ export declare const data: HighchartsWidgetData;
@@ -0,0 +1,43 @@
1
+ export const data = {
2
+ data: {
3
+ graphs: [
4
+ {
5
+ name: 'Number of requests',
6
+ tooltip: {
7
+ chartKitFormatting: true,
8
+ chartKitPrecision: 0,
9
+ },
10
+ dataLabels: {
11
+ format: null,
12
+ chartKitFormatting: true,
13
+ chartKitPrecision: 0,
14
+ chartKitPrefix: '',
15
+ chartKitPostfix: '',
16
+ chartKitLabelMode: 'absolute',
17
+ chartKitFormat: 'number',
18
+ chartKitShowRankDelimiter: true,
19
+ },
20
+ data: [
21
+ { name: 'Furniture', y: 14344, label: 14344 },
22
+ { name: 'Domestic chemistry', y: 14244, label: 14244 },
23
+ { name: 'Household goods', y: 14181, label: 14181 },
24
+ ],
25
+ },
26
+ ],
27
+ categories: ['Furniture', 'Domestic chemistry', 'Household goods'],
28
+ totals: 42769,
29
+ },
30
+ config: {
31
+ showPercentInTooltip: true,
32
+ },
33
+ libraryConfig: {
34
+ chart: {
35
+ type: 'pie',
36
+ },
37
+ plotOptions: {
38
+ pie: {
39
+ innerSize: '50%',
40
+ },
41
+ },
42
+ },
43
+ };
@@ -8,6 +8,7 @@ declare const HighchartsWidget: React.ForwardRefExoticComponent<{
8
8
  onLoad?: ((data?: import("../../../types").ChartKitOnLoadData<"highcharts"> | undefined) => void) | undefined;
9
9
  onRender?: ((data: import("../../../types").ChartKitOnRenderData) => void) | undefined;
10
10
  onChartLoad?: ((data: import("../../../types").ChartKitOnChartLoad<"highcharts">) => void) | undefined;
11
+ renderError?: import("../../../types").RenderError | undefined;
11
12
  onError?: import("../../../types").ChartKitOnError | undefined;
12
13
  } & {
13
14
  hoistConfigError?: boolean | undefined;
@@ -1227,11 +1227,14 @@ export function prepareConfig(data, options, isMobile, holidays) {
1227
1227
  } }, (chartType === 'pie' &&
1228
1228
  totals && {
1229
1229
  render: function () {
1230
+ var _a;
1230
1231
  const chart = this;
1231
1232
  const chartSeries = chart.series[0];
1232
1233
  const innerWidth = chartSeries === null || chartSeries === void 0 ? void 0 : chartSeries.center[3];
1234
+ const formatOptions = (_a = chartSeries === null || chartSeries === void 0 ? void 0 : chartSeries.userOptions) === null || _a === void 0 ? void 0 : _a.tooltip;
1235
+ const value = formatDonutTotals(chartSeries === null || chartSeries === void 0 ? void 0 : chartSeries.total, formatOptions) || totals;
1233
1236
  if (innerWidth) {
1234
- debouncedAdjustDonutFontSize(chart, chartSeries, innerWidth, totals);
1237
+ debouncedAdjustDonutFontSize(chart, chartSeries, innerWidth, value);
1235
1238
  }
1236
1239
  },
1237
1240
  })),
@@ -34,6 +34,7 @@ export declare type HighchartsWidgetData = {
34
34
  } | {
35
35
  graphs: CkHighchartsSeriesOptionsType[];
36
36
  categories: string[];
37
+ totals?: number | string;
37
38
  } | {
38
39
  graphs: CkHighchartsSeriesOptionsType[];
39
40
  }) & {
@@ -9,6 +9,7 @@ declare const IndicatorWidget: React.ForwardRefExoticComponent<{
9
9
  onLoad?: ((data?: import("../../../types").ChartKitOnLoadData<"indicator"> | undefined) => void) | undefined;
10
10
  onRender?: ((data: import("../../../types").ChartKitOnRenderData) => void) | undefined;
11
11
  onChartLoad?: ((data: import("../../../types").ChartKitOnChartLoad<"indicator">) => void) | undefined;
12
+ renderError?: import("../../../types").RenderError | undefined;
12
13
  onError?: import("../../../types").ChartKitOnError | undefined;
13
14
  } & {
14
15
  formatNumber?: (<T = any>(value: number, options?: T | undefined) => string) | undefined;
@@ -11,6 +11,7 @@ declare const YagrWidget: React.ForwardRefExoticComponent<{
11
11
  onLoad?: ((data?: import("../../../types").ChartKitOnLoadData<"yagr"> | undefined) => void) | undefined;
12
12
  onRender?: ((data: import("../../../types").ChartKitOnRenderData) => void) | undefined;
13
13
  onChartLoad?: ((data: import("../../../types").ChartKitOnChartLoad<"yagr">) => void) | undefined;
14
+ renderError?: import("../../../types").RenderError | undefined;
14
15
  onError?: import("../../../types").ChartKitOnError | undefined;
15
16
  } & {} & {
16
17
  id: string;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { ChartKitWidget } from './widget';
3
+ import { ChartKitError } from '../libs';
3
4
  export type { ChartKitHolidays } from './misc';
4
5
  export declare type ChartKitLang = 'ru' | 'en';
5
6
  export declare type ChartKitType = keyof ChartKitWidget;
@@ -38,6 +39,7 @@ export declare type ChartKitProps<T extends ChartKitType> = {
38
39
  * @param data
39
40
  */
40
41
  onChartLoad?: (data: ChartKitOnChartLoad<T>) => void;
42
+ renderError?: RenderError;
41
43
  onError?: ChartKitOnError;
42
44
  } & {
43
45
  [key in keyof Omit<ChartKitWidget[T], 'data' | 'widget'>]: ChartKitWidget[T][key];
@@ -46,4 +48,10 @@ export declare type ChartKitPlugin = {
46
48
  type: ChartKitType;
47
49
  renderer: React.LazyExoticComponent<any>;
48
50
  };
51
+ export declare type RenderErrorOpts = {
52
+ message: string;
53
+ error: ChartKitError | Error;
54
+ resetError: () => void;
55
+ };
56
+ export declare type RenderError = (opts: RenderErrorOpts) => React.ReactNode;
49
57
  export type { ChartKitWidget };
@@ -0,0 +1,2 @@
1
+ import type { ChartKitError } from '../libs';
2
+ export declare function getErrorMessage(error: ChartKitError | Error): string;
@@ -0,0 +1,5 @@
1
+ import { i18n } from '../i18n';
2
+ export function getErrorMessage(error) {
3
+ const code = 'code' in error && error.code;
4
+ return (error.message || code || i18n('error', 'label_unknown-error')).toString();
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "2.10.0",
3
+ "version": "2.11.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",
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- import type { ChartKitError } from '../../libs';
3
- declare type Props = {
4
- error: ChartKitError | Error;
5
- };
6
- export declare const ErrorView: ({ error }: Props) => JSX.Element;
7
- export {};
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- import { i18n } from '../../i18n';
3
- export const ErrorView = ({ error }) => {
4
- const code = 'code' in error && error.code;
5
- const message = error.message || code || i18n('error', 'label_unknown-error');
6
- return React.createElement("div", null, message);
7
- };