@gravity-ui/chartkit 3.0.0-beta.0 → 3.0.0-beta.10

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 (78) hide show
  1. package/build/components/ChartKit.d.ts +6 -4
  2. package/build/components/ChartKit.js +2 -2
  3. package/build/components/ErrorBoundary/ErrorBoundary.d.ts +2 -2
  4. package/build/components/Loader/Loader.d.ts +3 -3
  5. package/build/i18n/index.d.ts +2 -2
  6. package/build/libs/chartkit-error/chartkit-error.d.ts +1 -1
  7. package/build/libs/settings/__tests__/settings.test.js +2 -9
  8. package/build/libs/settings/eventEmitter.d.ts +11 -0
  9. package/build/libs/settings/eventEmitter.js +25 -0
  10. package/build/libs/settings/settings.d.ts +7 -4
  11. package/build/libs/settings/settings.js +8 -13
  12. package/build/plugins/highcharts/__stories__/Line.stories.d.ts +2 -3
  13. package/build/plugins/highcharts/__stories__/Pie.stories.d.ts +2 -3
  14. package/build/plugins/highcharts/__stories__/area/Range.stories.d.ts +2 -3
  15. package/build/plugins/highcharts/__stories__/area/Stacked.stories.d.ts +2 -3
  16. package/build/plugins/highcharts/__stories__/column/HorizontalStacked.stories.d.ts +2 -3
  17. package/build/plugins/highcharts/__stories__/column/Vertical.stories.d.ts +2 -3
  18. package/build/plugins/highcharts/__stories__/column/VerticalStacked.stories.d.ts +2 -3
  19. package/build/plugins/highcharts/__stories__/combined/ComboChartWithSameLegendValues.stories.d.ts +2 -3
  20. package/build/plugins/highcharts/__stories__/complex/TwoAxis.stories.d.ts +2 -3
  21. package/build/plugins/highcharts/__stories__/components/ChartStory.d.ts +1 -1
  22. package/build/plugins/highcharts/__stories__/custom-error-render/custom-error-render.stories.d.ts +2 -3
  23. package/build/plugins/highcharts/__stories__/no-data/no-data.stories.d.ts +2 -3
  24. package/build/plugins/highcharts/__stories__/pie/WithTotals.stories.d.ts +2 -3
  25. package/build/plugins/highcharts/renderer/HighchartsWidget.d.ts +3 -1
  26. package/build/plugins/highcharts/renderer/components/HighchartsComponent.d.ts +3 -3
  27. package/build/plugins/highcharts/renderer/components/HighchartsComponent.js +6 -0
  28. package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.d.ts +3 -3
  29. package/build/plugins/highcharts/renderer/components/withSplitPane/withSplitPane.js +2 -5
  30. package/build/plugins/highcharts/renderer/helpers/config/config.d.ts +0 -1
  31. package/build/plugins/highcharts/renderer/helpers/config/config.js +10 -10
  32. package/build/plugins/highcharts/renderer/helpers/config/types.d.ts +2 -2
  33. package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.d.ts +1 -1
  34. package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.d.ts +1 -1
  35. package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.d.ts +1 -1
  36. package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.d.ts +1 -1
  37. package/build/plugins/highcharts/renderer/helpers/config/utils/index.d.ts +33 -0
  38. package/build/plugins/highcharts/renderer/helpers/config/utils/index.js +8 -0
  39. package/build/plugins/highcharts/renderer/helpers/config/utils/isNavigatorSeries.d.ts +1 -1
  40. package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.d.ts +1 -1
  41. package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.d.ts +2 -2
  42. package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.js +2 -2
  43. package/build/plugins/highcharts/renderer/helpers/graph.d.ts +1 -1
  44. package/build/plugins/highcharts/renderer/helpers/graph.js +2 -2
  45. package/build/plugins/highcharts/renderer/helpers/highcharts/highcharts.d.ts +1 -0
  46. package/build/plugins/highcharts/renderer/helpers/highcharts/highcharts.js +5 -2
  47. package/build/plugins/highcharts/renderer/helpers/prepare-data.js +3 -3
  48. package/build/plugins/highcharts/renderer/helpers/tooltip/helpers.d.ts +0 -2
  49. package/build/plugins/highcharts/renderer/helpers/tooltip/helpers.js +0 -9
  50. package/build/plugins/highcharts/renderer/helpers/tooltip/index.d.ts +1 -1
  51. package/build/plugins/highcharts/renderer/helpers/tooltip/index.js +4 -5
  52. package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/types.d.ts +1 -1
  53. package/build/plugins/highcharts/renderer/helpers/tooltip/types.d.ts +3 -12
  54. package/build/plugins/highcharts/renderer/helpers/types.d.ts +2 -2
  55. package/build/plugins/highcharts/types/comments.d.ts +1 -1
  56. package/build/plugins/highcharts/types/misc.d.ts +4 -4
  57. package/build/plugins/highcharts/types/widget.d.ts +13 -5
  58. package/build/plugins/indicator/__stories__/Indicator.stories.d.ts +2 -2
  59. package/build/plugins/indicator/renderer/IndicatorItem.d.ts +2 -2
  60. package/build/plugins/indicator/renderer/IndicatorWidget.d.ts +3 -1
  61. package/build/plugins/indicator/types.d.ts +2 -2
  62. package/build/plugins/shared/format-number/i18n/i18n.d.ts +1 -1
  63. package/build/plugins/shared/format-number/types.d.ts +2 -2
  64. package/build/plugins/yagr/__stories__/Yagr.stories.d.ts +3 -4
  65. package/build/plugins/yagr/__stories__/Yagr.stories.js +3 -1
  66. package/build/plugins/yagr/__stories__/mocks/line10.d.ts +1 -0
  67. package/build/plugins/yagr/renderer/YagrWidget.d.ts +4 -1
  68. package/build/plugins/yagr/renderer/YagrWidget.js +13 -12
  69. package/build/plugins/yagr/renderer/tooltip/renderTooltip.js +2 -2
  70. package/build/plugins/yagr/renderer/tooltip/types.d.ts +4 -4
  71. package/build/plugins/yagr/renderer/utils.d.ts +1 -1
  72. package/build/plugins/yagr/renderer/utils.js +3 -3
  73. package/build/plugins/yagr/types.d.ts +2 -1
  74. package/build/types/index.d.ts +22 -22
  75. package/build/types/misc.d.ts +1 -1
  76. package/build/types/widget.d.ts +5 -1
  77. package/package.json +14 -9
  78. package/CHANGELOG.md +0 -489
@@ -1,2 +1,2 @@
1
1
  import type { FormatNumberOptions } from '../../../../../shared';
2
- export declare const numberFormat: (val: number, round?: number | undefined, options?: FormatNumberOptions) => string | null;
2
+ export declare const numberFormat: (val: number, round?: number, options?: FormatNumberOptions) => string | null;
@@ -1,10 +1,10 @@
1
1
  import type { Highcharts } from '../../../../types';
2
2
  import type { NavigatorPeriod } from '../types';
3
- declare type SetNavigatorDefaultPeriod = {
3
+ type SetNavigatorDefaultPeriod = {
4
4
  params: Record<string, any>;
5
5
  periodSettings: NavigatorPeriod;
6
6
  };
7
- declare type NavigatorPeriodInMS = {
7
+ type NavigatorPeriodInMS = {
8
8
  minRange: number;
9
9
  range: number;
10
10
  };
@@ -1,4 +1,4 @@
1
- import moment from 'moment';
1
+ import { dateTime } from '@gravity-ui/date-utils';
2
2
  import { getXAxisThresholdValue } from './getXAxisThresholdValue';
3
3
  const HOUR_IN_MS = 1000 * 60 * 60;
4
4
  const DAY_IN_MS = HOUR_IN_MS * 24;
@@ -18,7 +18,7 @@ export const getDefaultPeriodInMS = (periodSettings, series) => {
18
18
  if (maxXValue === null) {
19
19
  return null;
20
20
  }
21
- const minXValue = moment(maxXValue).subtract(value, period);
21
+ const minXValue = dateTime({ input: maxXValue }).subtract(value, period);
22
22
  const range = maxXValue - minXValue.valueOf();
23
23
  return {
24
24
  minRange,
@@ -2,7 +2,7 @@ import type { ChartKitHolidays } from '../../../../types';
2
2
  import type { Highcharts, HighchartsWidgetData, HighchartsComment, ExtendedHChart } from '../../types';
3
3
  import type { ConfigOptions } from './types';
4
4
  import './graph.css';
5
- declare type GetGraphArgs = {
5
+ type GetGraphArgs = {
6
6
  options: ConfigOptions;
7
7
  data: HighchartsWidgetData['data'];
8
8
  comments?: HighchartsComment[];
@@ -14,7 +14,7 @@ function getGraph({ options, data, comments, isMobile, holidays }) {
14
14
  return {
15
15
  config: Object.assign({ _externalComments: (!options.disableExternalComments && comments) || [], _internalComments: data.comments || [] }, prepareConfig(data, options, isMobile, holidays)),
16
16
  callback: (chart) => {
17
- var _a, _b, _c;
17
+ var _a, _b;
18
18
  if (!chart) {
19
19
  console.error('CHARTKIT_NO_CHART_CALLBACK');
20
20
  return;
@@ -63,7 +63,7 @@ function getGraph({ options, data, comments, isMobile, holidays }) {
63
63
  xAxis !== chart.navigator.xAxis) || ((_a = chart.navigator) === null || _a === void 0 ? void 0 : _a.xAxis);
64
64
  extmin = Math.max((_b = chart.xAxis[0]) === null || _b === void 0 ? void 0 : _b.dataMin, extmin);
65
65
  extmax = Math.min(chart.xAxis[0].dataMax, extmax);
66
- (_c = xAxis) === null || _c === void 0 ? void 0 : _c.setExtremes(extmin, extmax, false, false);
66
+ xAxis === null || xAxis === void 0 ? void 0 : xAxis.setExtremes(extmin, extmax, false, false);
67
67
  needRedraw = true;
68
68
  }
69
69
  }
@@ -2,3 +2,4 @@ export function initHighcharts({ isMobile }: {
2
2
  isMobile: any;
3
3
  }): void;
4
4
  export function initHighchartsMap(): void;
5
+ export function initHighchartsLangOptions(): void;
@@ -113,7 +113,7 @@ Highcharts.setOptions({
113
113
  },
114
114
  },
115
115
  });
116
- function initHighcharts({ isMobile }) {
116
+ function initHighchartsLangOptions() {
117
117
  Highcharts.setOptions({
118
118
  lang: {
119
119
  resetZoom: '⟲',
@@ -159,6 +159,9 @@ function initHighcharts({ isMobile }) {
159
159
  thousandsSep: i18n('highcharts', 'thousands-sep'),
160
160
  },
161
161
  });
162
+ }
163
+ function initHighcharts({ isMobile }) {
164
+ initHighchartsLangOptions();
162
165
  // https://github.com/highcharts/highcharts/issues/11494
163
166
  (function (H) {
164
167
  H.wrap(H.Tooltip.prototype, 'getLabel', function (proceed, ...rest) {
@@ -347,4 +350,4 @@ function initHighchartsMap() {
347
350
  }
348
351
  });
349
352
  }
350
- export { initHighcharts, initHighchartsMap };
353
+ export { initHighcharts, initHighchartsMap, initHighchartsLangOptions };
@@ -1,5 +1,5 @@
1
- import moment from 'moment';
2
1
  import lodashMin from 'lodash/min';
2
+ import { dateTime } from '@gravity-ui/date-utils';
3
3
  import { i18n } from '../../../../i18n';
4
4
  import { ChartKitError, CHARTKIT_ERROR_CODE } from '../../../../libs';
5
5
  import { DEFAULT_LINES_LIMIT } from './constants';
@@ -70,9 +70,9 @@ function removeHolidays(data, options, holidays) {
70
70
  graphsData[i] = [];
71
71
  });
72
72
  data.categories_ms.forEach((ts, i) => {
73
- const datetime = moment(ts).format('YYYYMMDD');
73
+ const key = dateTime({ input: ts }).format('YYYYMMDD');
74
74
  const region = (options.region && options.region.toLowerCase()) || 'tot';
75
- const holiday = holidays.holiday[region][datetime] || holidays.weekend[region][datetime];
75
+ const holiday = holidays.holiday[region][key] || holidays.weekend[region][key];
76
76
  if (!holiday) {
77
77
  timeline.push(ts);
78
78
  data.graphs.forEach((graph, j) => graphsData[j].push(graph.data[i]));
@@ -1,3 +1 @@
1
- import type { TooltipData, TooltipLine } from './types';
2
1
  export declare const escapeHTML: (html?: string) => string;
3
- export declare const getSortedLines: (lines: TooltipLine[], sort?: TooltipData['sort']) => TooltipLine[];
@@ -1,14 +1,5 @@
1
- import orderBy from 'lodash/orderBy';
2
1
  export const escapeHTML = (html = '') => {
3
2
  const elem = document.createElement('span');
4
3
  elem.innerText = html;
5
4
  return elem.innerHTML;
6
5
  };
7
- export const getSortedLines = (lines, sort = {}) => {
8
- // set eneabled to true after https://github.com/gravity-ui/chartkit/issues/171
9
- const { enabled = false, order = 'desc', iteratee = 'originalValue' } = sort;
10
- if (!enabled) {
11
- return [...lines];
12
- }
13
- return orderBy(lines, iteratee, order);
14
- };
@@ -9,5 +9,5 @@ export declare const TOOLTIP_ROW_CLASS_NAME = "_tooltip-row";
9
9
  export declare const TOOLTIP_HEADER_CLASS_NAME = "_tooltip-header";
10
10
  export declare const TOOLTIP_LIST_CLASS_NAME = "_tooltip-list";
11
11
  export declare const TOOLTIP_FOOTER_CLASS_NAME = "_tooltip-footer";
12
- export declare const formatTooltip: (data: TooltipData, tooltip: Highcharts.Tooltip, isMobile?: boolean | undefined) => string;
12
+ export declare const formatTooltip: (data: TooltipData, tooltip: Highcharts.Tooltip, isMobile?: boolean) => string;
13
13
  export default formatTooltip;
@@ -2,7 +2,7 @@
2
2
  import _escape from 'lodash/escape';
3
3
  import { i18n } from '../../../../../i18n';
4
4
  import { renderShapeIcon } from './render-shape-icon';
5
- import { escapeHTML, getSortedLines } from './helpers';
5
+ import { escapeHTML } from './helpers';
6
6
  import './tooltip.css';
7
7
  export const SERIES_NAME_DATA_ATTRIBUTE = 'data-series-name';
8
8
  export const SERIES_IDX_DATA_ATTRIBUTE = 'data-series-idx';
@@ -129,9 +129,8 @@ export const formatTooltip = (data, tooltip, isMobile) => {
129
129
  var _a, _b, _c;
130
130
  const { splitTooltip, activeRowAlwaysFirstInTooltip } = data;
131
131
  const lines = data.lines.slice(0, (tooltip.lastVisibleRowIndex || data.lines.length) + 1);
132
- const sortedLines = getSortedLines(lines, data.sort);
133
- const selectedLineIndex = sortedLines.findIndex(({ selectedSeries }) => selectedSeries);
134
- const selectedLine = sortedLines[selectedLineIndex];
132
+ const selectedLineIndex = lines.findIndex(({ selectedSeries }) => selectedSeries);
133
+ const selectedLine = lines[selectedLineIndex];
135
134
  const withShapes = lines.every((line) => line.seriesShape);
136
135
  const unsafe = data.unsafe;
137
136
  const tooltipHeaderRaw = (_a = data.tooltipHeader) === null || _a === void 0 ? void 0 : _a.trim();
@@ -213,7 +212,7 @@ export const formatTooltip = (data, tooltip, isMobile) => {
213
212
  .join('')}</tr>
214
213
  </thead>`}
215
214
  <tbody class="${TOOLTIP_LIST_CLASS_NAME}">
216
- ${sortedLines
215
+ ${lines
217
216
  .map((line, index) => renderRow(line, getRowRenderConfig(index)))
218
217
  .join('')}
219
218
  </tbody>
@@ -1,4 +1,4 @@
1
- export declare type CommonIconProps = {
1
+ export type CommonIconProps = {
2
2
  width: string;
3
3
  height: string;
4
4
  };
@@ -1,6 +1,6 @@
1
1
  import type { FormatNumberOptions } from '../../../../shared';
2
2
  import type { LineShapeType } from './constants';
3
- export declare type TooltipData = {
3
+ export type TooltipData = {
4
4
  /** Tooltip lines data */
5
5
  lines: Array<TooltipLine>;
6
6
  /** Tooltip comments */
@@ -38,17 +38,8 @@ export declare type TooltipData = {
38
38
  /** Sum of the values of the hidden ("not fit" in the tooltip) rows */
39
39
  hiddenRowsSum?: number | string;
40
40
  unsafe?: boolean;
41
- /** Used to manage tooltip lines sorting */
42
- sort?: {
43
- /** Enable tooltip lines sorting. `false` by default */
44
- enabled?: boolean;
45
- /** The sort orders. `'desc'` by default */
46
- order?: 'asc' | 'desc';
47
- /** The iteratees to sort by key(s) from `TooltipLine`. `'originalValue'` by default */
48
- iteratee?: keyof TooltipLine | keyof TooltipLine[] | ((line: TooltipLine) => TooltipLine[keyof TooltipLine] | TooltipLine[keyof TooltipLine][]);
49
- };
50
41
  };
51
- export declare type TooltipLine = {
42
+ export type TooltipLine = {
52
43
  /** Color displayed in a separate cell */
53
44
  seriesColor: string;
54
45
  /** Series name */
@@ -84,7 +75,7 @@ export declare type TooltipLine = {
84
75
  chartKitShowRankDelimiter?: FormatNumberOptions['showRankDelimiter'];
85
76
  chartKitUnit?: FormatNumberOptions['unit'];
86
77
  };
87
- export declare type RowRenderingConfig = {
78
+ export type RowRenderingConfig = {
88
79
  cellsRenderers: Array<(line: TooltipLine) => string>;
89
80
  isSelectedLine?: boolean;
90
81
  allowComment?: boolean;
@@ -1,6 +1,6 @@
1
1
  import type { FormatNumberOptions } from '../../../shared';
2
2
  import type { DrillDownConfig, HighchartsWidgetData } from '../../types';
3
- export declare type ConfigOptions = {
3
+ export type ConfigOptions = {
4
4
  highcharts: HighchartsWidgetData['libraryConfig'];
5
5
  nonBodyScroll?: boolean;
6
6
  splitTooltip?: boolean;
@@ -10,7 +10,7 @@ export declare type ConfigOptions = {
10
10
  max?: number;
11
11
  };
12
12
  } & HighchartsWidgetData['config'];
13
- export declare type ChartKitFormatNumberSettings = {
13
+ export type ChartKitFormatNumberSettings = {
14
14
  chartKitFormatting?: boolean;
15
15
  chartKitFormat?: FormatNumberOptions['format'];
16
16
  chartKitPostfix?: FormatNumberOptions['postfix'];
@@ -47,5 +47,5 @@ interface CommentFlagX extends CommentBase {
47
47
  shape: string;
48
48
  };
49
49
  }
50
- export declare type HighchartsComment = CommentDotXY | CommentBandX | CommentLineX | CommentFlagX;
50
+ export type HighchartsComment = CommentDotXY | CommentBandX | CommentLineX | CommentFlagX;
51
51
  export {};
@@ -1,14 +1,14 @@
1
1
  import type { HighchartsComment } from './comments';
2
- export declare type StringParams = Record<string, string | string[]>;
3
- export declare type DrillDownConfig = {
2
+ export type StringParams = Record<string, string | string[]>;
3
+ export type DrillDownConfig = {
4
4
  breadcrumbs: string[];
5
5
  };
6
- export declare type XAxisItem = Highcharts.Axis & {
6
+ export type XAxisItem = Highcharts.Axis & {
7
7
  dataMin: number;
8
8
  dataMax: number;
9
9
  setExtremes: (...args: any[]) => void;
10
10
  };
11
- export declare type ExtendedHChart = Highcharts.Chart & {
11
+ export type ExtendedHChart = Highcharts.Chart & {
12
12
  userOptions: Highcharts.Options & {
13
13
  _internalComments: HighchartsComment[];
14
14
  _externalComments: HighchartsComment[];
@@ -2,12 +2,12 @@ import type { Highcharts } from './lib';
2
2
  import type { HighchartsComment } from './comments';
3
3
  import type { DrillDownConfig, StringParams } from './misc';
4
4
  import type { TooltipData, TooltipLine } from '../renderer/helpers/tooltip/types';
5
- export declare type CkHighchartsSeriesOptionsType = Highcharts.SeriesOptionsType & {
5
+ export type CkHighchartsSeriesOptionsType = Highcharts.SeriesOptionsType & {
6
6
  title?: string;
7
7
  sname?: string;
8
8
  fname?: string;
9
9
  };
10
- export declare type HighchartsManageTooltipConfigOptions = {
10
+ export type HighchartsManageTooltipConfigOptions = {
11
11
  count: number;
12
12
  lines: TooltipLine[];
13
13
  shared: boolean;
@@ -26,8 +26,16 @@ export declare type HighchartsManageTooltipConfigOptions = {
26
26
  withPercent?: boolean;
27
27
  xComments?: TooltipData['xComments'];
28
28
  };
29
- export declare type HighchartsManageTooltipConfig = (options: HighchartsManageTooltipConfigOptions, chart: Highcharts.Chart) => HighchartsManageTooltipConfigOptions;
30
- export declare type HighchartsWidgetData = {
29
+ export type HighchartsManageTooltipConfig = (options: HighchartsManageTooltipConfigOptions, chart: Highcharts.Chart) => HighchartsManageTooltipConfigOptions;
30
+ export type HighchartsSortData = {
31
+ /** Enable tooltip lines sorting. `false` by default */
32
+ enabled?: boolean;
33
+ /** The sort orders. `'desc'` by default */
34
+ order?: 'asc' | 'desc';
35
+ /** The iteratees to sort by key(s) from `TooltipLine`. `'originalValue'` by default */
36
+ iteratee?: keyof TooltipLine | keyof TooltipLine[] | ((line: TooltipLine) => TooltipLine[keyof TooltipLine] | TooltipLine[keyof TooltipLine][]);
37
+ };
38
+ export type HighchartsWidgetData = {
31
39
  data: (CkHighchartsSeriesOptionsType[] | {
32
40
  graphs: CkHighchartsSeriesOptionsType[];
33
41
  categories_ms: number[];
@@ -95,7 +103,7 @@ export declare type HighchartsWidgetData = {
95
103
  metaKey?: boolean;
96
104
  };
97
105
  /** Used to manage tooltip lines sorting */
98
- sort?: TooltipData['sort'];
106
+ sort?: HighchartsSortData;
99
107
  };
100
108
  /**
101
109
  * Used to modify tooltip data
@@ -1,4 +1,4 @@
1
- import { Meta, Story } from '@storybook/react';
2
- export declare const Showcase: Story<import("@storybook/react").Args>;
1
+ import { Meta } from '@storybook/react';
2
+ export declare const Showcase: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
3
3
  declare const meta: Meta;
4
4
  export default meta;
@@ -1,7 +1,7 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import type { ChartKitProps } from '../../../types';
3
3
  import type { IndicatorWidgetDataItem } from '../types';
4
4
  export declare const IndicatorItem: (props: IndicatorWidgetDataItem & {
5
5
  defaultColor?: string;
6
6
  formatNumber?: ChartKitProps<'indicator'>['formatNumber'];
7
- }) => JSX.Element;
7
+ }) => React.JSX.Element;
@@ -4,13 +4,15 @@ import './IndicatorWidget.css';
4
4
  declare const IndicatorWidget: React.ForwardRefExoticComponent<{
5
5
  type: "indicator";
6
6
  data: import("../types").IndicatorWidgetData;
7
+ pluginRef?: undefined;
7
8
  id?: string | undefined;
8
9
  isMobile?: boolean | undefined;
9
10
  onLoad?: ((data?: import("../../../types").ChartKitOnLoadData<"indicator"> | undefined) => void) | undefined;
10
11
  onRender?: ((data: import("../../../types").ChartKitOnRenderData) => void) | undefined;
11
12
  onChartLoad?: ((data: import("../../../types").ChartKitOnChartLoad<"indicator">) => void) | undefined;
12
- renderError?: import("../../../types").RenderError | undefined;
13
13
  onError?: import("../../../types").ChartKitOnError | undefined;
14
+ renderError?: import("../../../types").RenderError | undefined;
15
+ renderPluginLoader?: (() => React.ReactNode) | undefined;
14
16
  } & {
15
17
  formatNumber?: (<T = any>(value: number, options?: T | undefined) => string) | undefined;
16
18
  } & React.RefAttributes<ChartKitWidgetRef | undefined>>;
@@ -1,4 +1,4 @@
1
- export declare type IndicatorWidgetDataItem = {
1
+ export type IndicatorWidgetDataItem = {
2
2
  content: {
3
3
  current: {
4
4
  value: string | number;
@@ -9,7 +9,7 @@ export declare type IndicatorWidgetDataItem = {
9
9
  title?: string;
10
10
  nowrap?: boolean;
11
11
  };
12
- export declare type IndicatorWidgetData = {
12
+ export type IndicatorWidgetData = {
13
13
  data?: IndicatorWidgetDataItem[];
14
14
  defaultColor?: string;
15
15
  };
@@ -1,5 +1,5 @@
1
1
  import { I18N } from '@gravity-ui/i18n';
2
- declare type KeysetData = Parameters<InstanceType<typeof I18N>['registerKeysets']>[1];
2
+ type KeysetData = Parameters<InstanceType<typeof I18N>['registerKeysets']>[1];
3
3
  declare const i18nInstance: I18N;
4
4
  declare const makeInstance: (keysetName: string, keysetsData: Record<string, KeysetData>) => (key: string, params?: import("@gravity-ui/i18n").Params | undefined) => string;
5
5
  export { i18nInstance, makeInstance };
@@ -1,11 +1,11 @@
1
- export declare type FormatOptions = {
1
+ export type FormatOptions = {
2
2
  precision?: number | 'auto';
3
3
  unitRate?: number;
4
4
  showRankDelimiter?: boolean;
5
5
  lang?: string;
6
6
  labelMode?: string;
7
7
  };
8
- export declare type FormatNumberOptions = FormatOptions & {
8
+ export type FormatNumberOptions = FormatOptions & {
9
9
  format?: 'number' | 'percent';
10
10
  multiplier?: number;
11
11
  prefix?: string;
@@ -1,6 +1,5 @@
1
- import { Meta, Story } from '@storybook/react';
2
1
  import '@gravity-ui/yagr/dist/index.css';
3
- declare const _default: Meta<import("@storybook/react").Args>;
2
+ declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
4
3
  export default _default;
5
- export declare const Line: Story<any>;
6
- export declare const Updates: Story<any>;
4
+ export declare const Line: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
5
+ export declare const Updates: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
@@ -12,12 +12,14 @@ export default {
12
12
  const LineTemplate = () => {
13
13
  const [shown, setShown] = React.useState(false);
14
14
  const chartkitRef = React.useRef();
15
+ // Example of usage pluginRef property
16
+ const yagrPluginRef = React.useRef(null);
15
17
  if (!shown) {
16
18
  settings.set({ plugins: [YagrPlugin] });
17
19
  return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
18
20
  }
19
21
  return (React.createElement("div", { style: { height: 300, width: '100%' } },
20
- React.createElement(ChartKit, { ref: chartkitRef, id: "1", type: "yagr", data: line10 })));
22
+ React.createElement(ChartKit, { ref: chartkitRef, id: "1", type: "yagr", data: line10, pluginRef: yagrPluginRef })));
21
23
  };
22
24
  const UpdatesTemplate = () => {
23
25
  const [shown, setShown] = React.useState(false);
@@ -41,6 +41,7 @@ export declare const getNewConfig: () => {
41
41
  title?: string | ((sIdx: number) => string) | undefined;
42
42
  transform?: ((val: string | number | null, series: import("@gravity-ui/yagr/dist/YagrCore/types").DataSeries[], idx: number) => number | null) | undefined;
43
43
  showInTooltip?: boolean | undefined;
44
+ postProcess?: ((data: (number | null)[], idx: number, y: import("@gravity-ui/yagr/dist/YagrCore").default<import("@gravity-ui/yagr/dist/YagrCore/types").MinimalValidConfig>) => (number | null)[]) | undefined;
44
45
  type?: import("@gravity-ui/yagr/dist/YagrCore/types").ChartType | undefined;
45
46
  }[];
46
47
  };
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { YagrReactRef } from '@gravity-ui/yagr/dist/react';
2
3
  import type { ChartKitWidgetRef } from '../../../types';
3
4
  import './polyfills';
4
5
  import '@gravity-ui/yagr/dist/index.css';
@@ -6,13 +7,15 @@ import './YagrWidget.css';
6
7
  declare const YagrWidget: React.ForwardRefExoticComponent<{
7
8
  type: "yagr";
8
9
  data: import("../types").YagrWidgetData;
10
+ pluginRef?: React.MutableRefObject<YagrReactRef | null> | undefined;
9
11
  id?: string | undefined;
10
12
  isMobile?: boolean | undefined;
11
13
  onLoad?: ((data?: import("../../../types").ChartKitOnLoadData<"yagr"> | undefined) => void) | undefined;
12
14
  onRender?: ((data: import("../../../types").ChartKitOnRenderData) => void) | undefined;
13
15
  onChartLoad?: ((data: import("../../../types").ChartKitOnChartLoad<"yagr">) => void) | undefined;
14
- renderError?: import("../../../types").RenderError | undefined;
15
16
  onError?: import("../../../types").ChartKitOnError | undefined;
17
+ renderError?: import("../../../types").RenderError | undefined;
18
+ renderPluginLoader?: (() => React.ReactNode) | undefined;
16
19
  } & {} & {
17
20
  id: string;
18
21
  } & React.RefAttributes<ChartKitWidgetRef | undefined>>;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import isEmpty from 'lodash/isEmpty';
3
+ import { useForkRef } from '@gravity-ui/uikit';
3
4
  import YagrComponent from '@gravity-ui/yagr/dist/react';
4
5
  import { i18n } from '../../../i18n';
5
6
  import { CHARTKIT_ERROR_CODE, ChartKitError } from '../../../libs';
@@ -9,8 +10,9 @@ import './polyfills';
9
10
  import '@gravity-ui/yagr/dist/index.css';
10
11
  import './YagrWidget.css';
11
12
  const YagrWidget = React.forwardRef((props, forwardedRef) => {
12
- const { id, data: { data }, onLoad, onRender, onChartLoad, } = props;
13
+ const { id, data: { data }, pluginRef, onLoad, onRender, onChartLoad, } = props;
13
14
  const yagrRef = React.useRef(null);
15
+ const handleRef = useForkRef(pluginRef, yagrRef);
14
16
  if (!data || isEmpty(data)) {
15
17
  throw new ChartKitError({
16
18
  code: CHARTKIT_ERROR_CODE.NO_DATA,
@@ -21,18 +23,14 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
21
23
  const handleChartLoading = React.useCallback((chart, { renderTime }) => {
22
24
  onLoad === null || onLoad === void 0 ? void 0 : onLoad(Object.assign(Object.assign({}, data), { widget: chart, widgetRendering: renderTime }));
23
25
  onRender === null || onRender === void 0 ? void 0 : onRender({ renderTime });
24
- }, [onLoad, data]);
26
+ }, [onLoad, onRender, data]);
25
27
  const onWindowResize = React.useCallback(() => {
26
28
  if (yagrRef.current) {
27
29
  const chart = yagrRef.current.yagr();
28
30
  if (!chart) {
29
31
  return;
30
32
  }
31
- const root = chart.root;
32
- const height = root.offsetHeight;
33
- const width = root.offsetWidth;
34
- chart.uplot.setSize({ width, height });
35
- chart.uplot.redraw();
33
+ chart.reflow();
36
34
  }
37
35
  }, []);
38
36
  React.useImperativeHandle(forwardedRef, () => ({
@@ -41,25 +39,28 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
41
39
  },
42
40
  }), [onWindowResize]);
43
41
  React.useEffect(() => {
44
- var _a, _b, _c, _d;
42
+ var _a, _b, _c, _d, _e, _f;
45
43
  const yagr = (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.yagr();
46
44
  if (!yagr) {
47
45
  return;
48
46
  }
47
+ if ((_c = (_b = yagr.config) === null || _b === void 0 ? void 0 : _b.tooltip) === null || _c === void 0 ? void 0 : _c.virtual) {
48
+ return;
49
+ }
49
50
  const handlers = {
50
51
  mouseMove: null,
51
52
  mouseDown: null,
52
53
  };
53
- (_b = yagr.plugins.tooltip) === null || _b === void 0 ? void 0 : _b.on('render', (tooltip) => {
54
+ (_d = yagr.plugins.tooltip) === null || _d === void 0 ? void 0 : _d.on('render', (tooltip) => {
54
55
  synchronizeTooltipTablesCellsWidth(tooltip);
55
56
  });
56
- (_c = yagr.plugins.tooltip) === null || _c === void 0 ? void 0 : _c.on('pin', (tooltip, { actions }) => {
57
+ (_e = yagr.plugins.tooltip) === null || _e === void 0 ? void 0 : _e.on('pin', (tooltip, { actions }) => {
57
58
  handlers.mouseMove = checkFocus({ tooltip, yagr });
58
59
  handlers.mouseDown = detectClickOutside({ tooltip, actions, yagr });
59
60
  document.addEventListener('mousemove', handlers.mouseMove);
60
61
  document.addEventListener('mousedown', handlers.mouseDown);
61
62
  });
62
- (_d = yagr.plugins.tooltip) === null || _d === void 0 ? void 0 : _d.on('unpin', () => {
63
+ (_f = yagr.plugins.tooltip) === null || _f === void 0 ? void 0 : _f.on('unpin', () => {
63
64
  if (handlers.mouseMove) {
64
65
  document.removeEventListener('mousemove', handlers.mouseMove);
65
66
  handlers.mouseMove = null;
@@ -74,6 +75,6 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
74
75
  var _a;
75
76
  onChartLoad === null || onChartLoad === void 0 ? void 0 : onChartLoad({ widget: (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.yagr() });
76
77
  }, [yagrRef, onChartLoad]);
77
- return (React.createElement(YagrComponent, { ref: yagrRef, id: id, config: config, debug: debug, onChartLoad: handleChartLoading }));
78
+ return (React.createElement(YagrComponent, { ref: handleRef, id: id, config: config, debug: debug, onChartLoad: handleChartLoading }));
78
79
  });
79
80
  export default YagrWidget;
@@ -1,4 +1,4 @@
1
- import moment from 'moment';
1
+ import { dateTime } from '@gravity-ui/date-utils';
2
2
  import { formatTooltip } from './tooltip';
3
3
  const calcOption = (d) => {
4
4
  return typeof d === 'object' && d !== null
@@ -39,7 +39,7 @@ export const renderTooltip = (data) => {
39
39
  : undefined;
40
40
  const tooltipFormatOptions = {
41
41
  activeRowAlwaysFirstInTooltip: rows.length > 1,
42
- tooltipHeader: moment(x / timeMultiplier).format('DD MMMM YYYY HH:mm:ss'),
42
+ tooltipHeader: dateTime({ input: x / timeMultiplier }).format('DD MMMM YYYY HH:mm:ss'),
43
43
  shared: true,
44
44
  lines: rows.map((row, i) => (Object.assign(Object.assign({}, row), { seriesName: row.name || 'Serie ' + (i + 1), seriesColor: row.color, selectedSeries: row.active, seriesIdx: row.seriesIdx, percentValue: typeof row.transformed === 'number' ? row.transformed.toFixed(1) : '' }))),
45
45
  withPercent: calcOption(opts.percent),
@@ -1,4 +1,4 @@
1
- export declare type TooltipData = {
1
+ export type TooltipData = {
2
2
  /** Tooltip lines data */
3
3
  lines: Array<TooltipLine>;
4
4
  /** Tooltip comments */
@@ -35,10 +35,10 @@ export declare type TooltipData = {
35
35
  /** Sum of the values of the hidden ("not fit" in the tooltip) rows */
36
36
  hiddenRowsSum?: number | string;
37
37
  };
38
- export declare type TooltipExtraData = {
38
+ export type TooltipExtraData = {
39
39
  lastVisibleRowIndex: number;
40
40
  };
41
- export declare type TooltipLine = {
41
+ export type TooltipLine = {
42
42
  /** Color displayed in a separate cell */
43
43
  seriesColor: string;
44
44
  /** Series name */
@@ -64,7 +64,7 @@ export declare type TooltipLine = {
64
64
  replaceCellAt?: Record<number, (line: TooltipLine) => string>;
65
65
  insertCellAt?: Record<number, (line: TooltipLine) => string>;
66
66
  };
67
- export declare type RowRenderingConfig = {
67
+ export type RowRenderingConfig = {
68
68
  cellsRenderers: Array<(line: TooltipLine) => string>;
69
69
  isSelectedLine?: boolean;
70
70
  allowComment?: boolean;
@@ -1,5 +1,5 @@
1
1
  import type { Yagr, YagrWidgetData, YagrTheme, MinimalValidConfig } from '../types';
2
- declare type ShapeYagrConfigArgs = {
2
+ type ShapeYagrConfigArgs = {
3
3
  data: YagrWidgetData['data'];
4
4
  libraryConfig: YagrWidgetData['libraryConfig'];
5
5
  theme: YagrTheme;
@@ -1,5 +1,5 @@
1
- import moment from 'moment';
2
1
  import merge from 'lodash/merge';
2
+ import { dateTime } from '@gravity-ui/date-utils';
3
3
  import { defaults } from '@gravity-ui/yagr';
4
4
  import { settings } from '../../../libs';
5
5
  import { renderTooltip } from './tooltip';
@@ -75,8 +75,8 @@ export const detectClickOutside = (args) => (event) => {
75
75
  const getXAxisFormatter = (msm = 1) => (_, ticks) => {
76
76
  const range = (ticks[ticks.length - 1] - ticks[0]) / msm;
77
77
  return ticks.map((rawValue) => {
78
- const d = moment(rawValue / msm);
79
- if (d.hour() === 0 && d.minutes() === 0 && d.seconds() === 0) {
78
+ const d = dateTime({ input: rawValue / msm });
79
+ if (d.hour() === 0 && d.minute() === 0 && d.second() === 0) {
80
80
  return d.format('DD.MM.YY');
81
81
  }
82
82
  return d.format(range < 300 ? 'HH:mm:ss' : 'HH:mm');
@@ -1,7 +1,8 @@
1
1
  import type { RawSerieData, YagrConfig } from '@gravity-ui/yagr';
2
2
  export type { default as Yagr } from '@gravity-ui/yagr';
3
+ export type { YagrReactRef } from '@gravity-ui/yagr/dist/react';
3
4
  export * from '@gravity-ui/yagr/dist/types';
4
- export declare type YagrWidgetData = {
5
+ export type YagrWidgetData = {
5
6
  data: {
6
7
  graphs: RawSerieData[];
7
8
  timeline: number[];