@gravity-ui/chartkit 2.11.1-beta.0 → 2.13.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.13.0](https://github.com/gravity-ui/chartkit/compare/v2.12.0...v2.13.0) (2023-06-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * **Yagr plugin:** update to v 2.2.6 ([#186](https://github.com/gravity-ui/chartkit/issues/186)) ([bddd692](https://github.com/gravity-ui/chartkit/commit/bddd6920742b398b35ce4ef6d8b78d87d50148db))
9
+
10
+ ## [2.12.0](https://github.com/gravity-ui/chartkit/compare/v2.11.0...v2.12.0) (2023-06-30)
11
+
12
+
13
+ ### Features
14
+
15
+ * add renderPluginLoader property ([#184](https://github.com/gravity-ui/chartkit/issues/184)) ([3955d2f](https://github.com/gravity-ui/chartkit/commit/3955d2f1995fb204c16cda53e96b4eca50c2ef0e))
16
+
3
17
  ## [2.11.0](https://github.com/gravity-ui/chartkit/compare/v2.10.1...v2.11.0) (2023-06-20)
4
18
 
5
19
 
@@ -13,8 +13,9 @@ 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;
17
16
  onError?: import("../types").ChartKitOnError | undefined;
17
+ renderError?: import("../types").RenderError | undefined;
18
+ renderPluginLoader?: (() => React.ReactNode) | undefined;
18
19
  } & { [key in keyof Omit<import("../types").ChartKitWidget[T], "widget" | "data">]: import("../types").ChartKitWidget[T][key]; } & {
19
20
  ref?: React.ForwardedRef<ChartKitRef | undefined> | undefined;
20
21
  }) => ReturnType<typeof ChartKitComponent>;
@@ -10,7 +10,7 @@ import './ChartKit.css';
10
10
  const b = block('chartkit');
11
11
  const ChartKitComponent = (props) => {
12
12
  const widgetRef = React.useRef();
13
- const { instanceRef, id: propsId, type, isMobile } = props, restProps = __rest(props, ["instanceRef", "id", "type", "isMobile"]);
13
+ const { instanceRef, id: propsId, type, isMobile, renderPluginLoader } = props, restProps = __rest(props, ["instanceRef", "id", "type", "isMobile", "renderPluginLoader"]);
14
14
  const ckId = React.useMemo(() => getRandomCKId(), []);
15
15
  const id = propsId || ckId;
16
16
  const lang = settings.get('lang');
@@ -31,7 +31,7 @@ const ChartKitComponent = (props) => {
31
31
  }
32
32
  },
33
33
  }), []);
34
- return (React.createElement(React.Suspense, { fallback: React.createElement(Loader, null) },
34
+ return (React.createElement(React.Suspense, { fallback: (renderPluginLoader === null || renderPluginLoader === void 0 ? void 0 : renderPluginLoader()) || React.createElement(Loader, null) },
35
35
  React.createElement("div", { className: b({ mobile: isMobile }, 'chartkit-theme_common') },
36
36
  React.createElement(ChartComponent, Object.assign({ ref: widgetRef, id: id, lang: lang }, restProps)))));
37
37
  };
@@ -8,8 +8,9 @@ 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;
12
11
  onError?: import("../../../types").ChartKitOnError | undefined;
12
+ renderError?: import("../../../types").RenderError | undefined;
13
+ renderPluginLoader?: (() => React.ReactNode) | undefined;
13
14
  } & {
14
15
  hoistConfigError?: boolean | undefined;
15
16
  nonBodyScroll?: boolean | undefined;
@@ -43,9 +43,6 @@ function getPointsForInitialRefresh(chart) {
43
43
  }
44
44
  function forceHoverState(chart, activePoints) {
45
45
  const chartType = get(chart, 'userOptions.chart.type');
46
- if (!chartType) {
47
- return;
48
- }
49
46
  if (chartType === 'pie') {
50
47
  chart.tooltip.refresh(activePoints);
51
48
  chart.pointsForInitialRefresh = activePoints;
@@ -208,6 +205,6 @@ export const withSplitPane = (ComposedComponent) => {
208
205
  }
209
206
  }
210
207
  return React.forwardRef((props, ref) => {
211
- return React.createElement(WithSplitPane, Object.assign({}, props, { forwardedRef: ref }));
208
+ return React.createElement(WithSplitPane, Object.assign({ forwardedRef: ref }, props));
212
209
  });
213
210
  };
@@ -9,8 +9,9 @@ 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;
13
12
  onError?: import("../../../types").ChartKitOnError | undefined;
13
+ renderError?: import("../../../types").RenderError | undefined;
14
+ renderPluginLoader?: (() => React.ReactNode) | undefined;
14
15
  } & {
15
16
  formatNumber?: (<T = any>(value: number, options?: T | undefined) => string) | undefined;
16
17
  } & React.RefAttributes<ChartKitWidgetRef | undefined>>;
@@ -1,6 +1,4 @@
1
1
  import { Meta, Story } from '@storybook/react';
2
- import '@gravity-ui/yagr/dist/index.css';
3
2
  declare const _default: Meta<import("@storybook/react").Args>;
4
3
  export default _default;
5
4
  export declare const Line: Story<any>;
6
- export declare const Updates: Story<any>;
@@ -3,13 +3,12 @@ import { Button } from '@gravity-ui/uikit';
3
3
  import { settings } from '../../../libs';
4
4
  import { YagrPlugin } from '../../../plugins';
5
5
  import { ChartKit } from '../../../components/ChartKit';
6
- import { getNewConfig, line10 } from './mocks/line10';
7
- import '@gravity-ui/yagr/dist/index.css';
6
+ import { line10 } from './mocks/line10';
8
7
  export default {
9
8
  title: 'Plugins/Yagr',
10
9
  component: ChartKit,
11
10
  };
12
- const LineTemplate = () => {
11
+ const Template = () => {
13
12
  const [shown, setShown] = React.useState(false);
14
13
  const chartkitRef = React.useRef();
15
14
  if (!shown) {
@@ -19,23 +18,4 @@ const LineTemplate = () => {
19
18
  return (React.createElement("div", { style: { height: 300, width: '100%' } },
20
19
  React.createElement(ChartKit, { ref: chartkitRef, id: "1", type: "yagr", data: line10 })));
21
20
  };
22
- const UpdatesTemplate = () => {
23
- const [shown, setShown] = React.useState(false);
24
- const chartkitRef = React.useRef();
25
- const [state, setState] = React.useState(line10);
26
- const onStartUpdates = React.useCallback(() => {
27
- setInterval(() => {
28
- setState(getNewConfig());
29
- }, 1000);
30
- }, []);
31
- if (!shown) {
32
- settings.set({ plugins: [YagrPlugin] });
33
- return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
34
- }
35
- return (React.createElement("div", { style: { height: 300, width: '100%' } },
36
- React.createElement(ChartKit, { ref: chartkitRef, id: "1", type: "yagr", data: state }),
37
- React.createElement(Button, { onClick: onStartUpdates }, "Start Updates"),
38
- React.createElement(Button, { onClick: () => setState(getNewConfig()) }, "Once")));
39
- };
40
- export const Line = LineTemplate.bind({});
41
- export const Updates = UpdatesTemplate.bind({});
21
+ export const Line = Template.bind({});
@@ -1,52 +1,2 @@
1
1
  import type { YagrWidgetData } from '../../types';
2
2
  export declare const line10: YagrWidgetData;
3
- export declare const getNewConfig: () => {
4
- libraryConfig: {
5
- title: {
6
- text: string;
7
- };
8
- chart?: import("@gravity-ui/yagr/dist/YagrCore/types").YagrChartOptions | undefined;
9
- legend?: import("@gravity-ui/yagr/dist/YagrCore/plugins/legend/legend").LegendOptions | undefined;
10
- axes?: Record<string, import("@gravity-ui/yagr/dist/YagrCore/types").AxisOptions> | undefined;
11
- cursor?: import("@gravity-ui/yagr/dist/YagrCore/plugins/cursor/cursor").CursorOptions | undefined;
12
- timeline?: number[] | undefined;
13
- tooltip?: Partial<import("@gravity-ui/yagr/dist/YagrCore/plugins/tooltip/types").TooltipOptions> | undefined;
14
- grid?: import("uplot").Axis.Grid | undefined;
15
- markers?: import("@gravity-ui/yagr/dist/YagrCore/types").MarkersOptions | undefined;
16
- scales?: Record<string, import("@gravity-ui/yagr/dist/YagrCore/types").Scale> | undefined;
17
- series?: import("@gravity-ui/yagr/dist/YagrCore/types").RawSerieData<Omit<import("@gravity-ui/yagr/dist/YagrCore/types").SeriesOptions, "type"> & {
18
- type?: import("@gravity-ui/yagr/dist/YagrCore/types").ChartType | undefined;
19
- }>[] | undefined;
20
- hooks?: import("@gravity-ui/yagr/dist/YagrCore/types").YagrHooks | undefined;
21
- processing?: import("@gravity-ui/yagr/dist/YagrCore/types").ProcessingSettings | undefined;
22
- editUplotOptions?: ((opts: import("uplot").Options) => import("uplot").Options) | undefined;
23
- plugins?: Record<string, import("@gravity-ui/yagr/dist/YagrCore/types").YagrPlugin<{}, []>> | undefined;
24
- };
25
- data: {
26
- timeline: number[];
27
- graphs: {
28
- data: number[];
29
- name?: string | undefined;
30
- id?: string | undefined;
31
- scale?: string | undefined;
32
- focus?: boolean | undefined;
33
- show?: boolean | undefined;
34
- color?: string | undefined;
35
- spanGaps?: boolean | undefined;
36
- cursorOptions?: Pick<import("@gravity-ui/yagr/dist/YagrCore/plugins/cursor/cursor").CursorOptions, "snapToValues" | "markersSize"> | undefined;
37
- formatter?: ((value: string | number | null, serie: import("uplot").Series) => string) | undefined;
38
- precision?: number | undefined;
39
- snapToValues?: false | import("@gravity-ui/yagr/dist/YagrCore/types").SnapToValue | undefined;
40
- stackGroup?: number | undefined;
41
- title?: string | ((sIdx: number) => string) | undefined;
42
- transform?: ((val: string | number | null, series: import("@gravity-ui/yagr/dist/YagrCore/types").DataSeries[], idx: number) => number | null) | undefined;
43
- showInTooltip?: boolean | undefined;
44
- type?: import("@gravity-ui/yagr/dist/YagrCore/types").ChartType | undefined;
45
- }[];
46
- };
47
- sources?: Record<number, {
48
- data: {
49
- program: string;
50
- };
51
- }> | undefined;
52
- };
@@ -61,18 +61,3 @@ export const line10 = {
61
61
  processing: {},
62
62
  },
63
63
  };
64
- export const getNewConfig = () => {
65
- const startPoint = (Math.random() * 10 ** 5) >> 0; // eslint-disable-line no-bitwise
66
- return Object.assign(Object.assign({}, line10), { libraryConfig: Object.assign(Object.assign({}, line10.libraryConfig), { title: {
67
- text: 'line: random 100 pts',
68
- } }), data: {
69
- timeline: new Array(100).fill(0).map((_, i) => {
70
- return startPoint + i * 1000;
71
- }),
72
- graphs: line10.data.graphs.map((graph) => {
73
- return Object.assign(Object.assign({}, graph), { data: new Array(100).fill(0).map(() => {
74
- return (Math.random() * 100) >> 0; // eslint-disable-line no-bitwise
75
- }) });
76
- }),
77
- } });
78
- };
@@ -6,13 +6,13 @@ const DATA = {
6
6
  describe('plugins/yagr/utils', () => {
7
7
  describe('shapeYagrConfig > check chart property', () => {
8
8
  test.each([
9
- [{}, { appearance: { locale: 'en', theme: 'dark' } }],
10
- [{ appearance: { locale: 'ru' } }, { appearance: { locale: 'ru', theme: 'dark' } }],
11
- [{ appearance: { theme: 'light' } }, { appearance: { locale: 'en', theme: 'light' } }],
9
+ [{}, { appereance: { locale: 'en', theme: 'dark' } }],
10
+ [{ appereance: { locale: 'ru' } }, { appereance: { locale: 'ru', theme: 'dark' } }],
11
+ [{ appereance: { theme: 'light' } }, { appereance: { locale: 'en', theme: 'light' } }],
12
12
  [
13
13
  { series: { type: 'dots' }, select: { zoom: false }, timeMultiplier: 1 },
14
14
  {
15
- appearance: { locale: 'en', theme: 'dark' },
15
+ appereance: { locale: 'en', theme: 'dark' },
16
16
  series: { type: 'dots' },
17
17
  select: { zoom: false },
18
18
  timeMultiplier: 1,
@@ -11,8 +11,9 @@ 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;
15
14
  onError?: import("../../../types").ChartKitOnError | undefined;
15
+ renderError?: import("../../../types").RenderError | undefined;
16
+ renderPluginLoader?: (() => React.ReactNode) | undefined;
16
17
  } & {} & {
17
18
  id: string;
18
19
  } & React.RefAttributes<ChartKitWidgetRef | undefined>>;
@@ -23,11 +23,9 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
23
23
  onRender === null || onRender === void 0 ? void 0 : onRender({ renderTime });
24
24
  }, [onLoad, data]);
25
25
  const onWindowResize = React.useCallback(() => {
26
- if (yagrRef.current) {
27
- const chart = yagrRef.current.yagr();
28
- if (!chart) {
29
- return;
30
- }
26
+ var _a;
27
+ if ((_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.chart) {
28
+ const chart = yagrRef.current.chart;
31
29
  const root = chart.root;
32
30
  const height = root.offsetHeight;
33
31
  const width = root.offsetWidth;
@@ -40,9 +38,9 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
40
38
  onWindowResize();
41
39
  },
42
40
  }), [onWindowResize]);
43
- React.useEffect(() => {
41
+ React.useLayoutEffect(() => {
44
42
  var _a, _b, _c, _d;
45
- const yagr = (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.yagr();
43
+ const yagr = (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.chart;
46
44
  if (!yagr) {
47
45
  return;
48
46
  }
@@ -69,11 +67,11 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
69
67
  handlers.mouseDown = null;
70
68
  }
71
69
  });
72
- }, []);
70
+ });
73
71
  React.useLayoutEffect(() => {
74
72
  var _a;
75
- onChartLoad === null || onChartLoad === void 0 ? void 0 : onChartLoad({ widget: (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.yagr() });
76
- }, [yagrRef, onChartLoad]);
73
+ onChartLoad === null || onChartLoad === void 0 ? void 0 : onChartLoad({ widget: (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.chart });
74
+ }, []);
77
75
  return (React.createElement(YagrComponent, { ref: yagrRef, id: id, config: config, debug: debug, onChartLoad: handleChartLoading }));
78
76
  });
79
77
  export default YagrWidget;
@@ -1,7 +1,7 @@
1
1
  import moment from 'moment';
2
2
  import { formatTooltip } from './tooltip';
3
3
  const calcOption = (d) => {
4
- return typeof d === 'object' && d !== null
4
+ return typeof d === 'object'
5
5
  ? Object.values(d).reduce((_, t) => {
6
6
  return t;
7
7
  })
@@ -16,7 +16,7 @@ export const renderTooltip = (data) => {
16
16
  const cfg = data.yagr.config;
17
17
  const timeMultiplier = cfg.chart.timeMultiplier || 1;
18
18
  const opts = data.options;
19
- const { x, state } = data;
19
+ const { x, pinned } = data;
20
20
  let sumTotal = 0;
21
21
  const rows = Object.values(data.scales).reduce((acc, scale) => {
22
22
  sumTotal += scale.sum || 0;
@@ -27,7 +27,7 @@ export const renderTooltip = (data) => {
27
27
  const maxLines = calcOption(opts.maxLines);
28
28
  const valueFormatter = calcOption(opts.value);
29
29
  // eslint-disable-next-line no-nested-ternary
30
- const hiddenRowsNumber = state.pinned
30
+ const hiddenRowsNumber = pinned
31
31
  ? undefined
32
32
  : lines > maxLines
33
33
  ? Math.abs(maxLines - lines)
@@ -50,6 +50,6 @@ export const renderTooltip = (data) => {
50
50
  tooltipFormatOptions.sum = valueFormatter(sumTotal);
51
51
  }
52
52
  return formatTooltip(tooltipFormatOptions, {
53
- lastVisibleRowIndex: state.pinned ? rows.length - 1 : maxLines - 1,
53
+ lastVisibleRowIndex: pinned ? rows.length - 1 : maxLines - 1,
54
54
  });
55
55
  };
@@ -87,7 +87,7 @@ export const shapeYagrConfig = (args) => {
87
87
  const { data, libraryConfig, theme } = args;
88
88
  const config = Object.assign(Object.assign({}, libraryConfig), { timeline: data.timeline, series: data.graphs });
89
89
  const chart = {
90
- appearance: {
90
+ appereance: {
91
91
  locale: settings.get('lang'),
92
92
  theme,
93
93
  },
@@ -29,18 +29,16 @@ export declare type ChartKitProps<T extends ChartKitType> = {
29
29
  id?: string;
30
30
  isMobile?: boolean;
31
31
  onLoad?: (data?: ChartKitOnLoadData<T>) => void;
32
- /**
33
- * called on each render
34
- * @param data
35
- */
32
+ /** Fires on each chartkit plugin's component render */
36
33
  onRender?: (data: ChartKitOnRenderData) => void;
37
- /**
38
- * called on chart mount
39
- * @param data
40
- */
34
+ /** Fires on chartkit plugin's component mount */
41
35
  onChartLoad?: (data: ChartKitOnChartLoad<T>) => void;
42
- renderError?: RenderError;
36
+ /** Fires in case of unhandled plugin's exception */
43
37
  onError?: ChartKitOnError;
38
+ /** Used to render user's error component */
39
+ renderError?: RenderError;
40
+ /** Used to render user's plugin loader component */
41
+ renderPluginLoader?: () => React.ReactNode;
44
42
  } & {
45
43
  [key in keyof Omit<ChartKitWidget[T], 'data' | 'widget'>]: ChartKitWidget[T][key];
46
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "2.11.1-beta.0",
3
+ "version": "2.13.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",
@@ -13,7 +13,7 @@
13
13
  "access": "public"
14
14
  },
15
15
  "dependencies": {
16
- "@gravity-ui/yagr": "^3.1.0",
16
+ "@gravity-ui/yagr": "^2.2.6",
17
17
  "bem-cn-lite": "^4.1.0",
18
18
  "highcharts": "^8.2.2",
19
19
  "highcharts-react-official": "^3.0.0",
@@ -65,9 +65,9 @@
65
65
  "typescript": "^4.2.3"
66
66
  },
67
67
  "peerDependencies": {
68
- "@gravity-ui/uikit": "^4.0.0",
68
+ "react": "^16.0.0 || ^17.0.0 || ^18.0.0",
69
69
  "moment": "^2.19.3",
70
- "react": "^16.0.0 || ^17.0.0 || ^18.0.0"
70
+ "@gravity-ui/uikit": "^4.0.0"
71
71
  },
72
72
  "scripts": {
73
73
  "test": "jest",