@gravity-ui/chartkit 4.22.0 → 4.23.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.
@@ -7,4 +7,5 @@ export declare const withSplitPane: <ComposedComponentProps extends {}>(Composed
7
7
  } & {
8
8
  current: any;
9
9
  forwardedRef: React.Ref<ComposedComponentProps>;
10
+ callback?: Highcharts.ChartCallbackFunction | undefined;
10
11
  }> & React.RefAttributes<ComposedComponentProps>>;
@@ -110,8 +110,10 @@ export const withSplitPane = (ComposedComponent) => {
110
110
  }
111
111
  };
112
112
  this.afterCreateCallback = (chart) => {
113
+ var _a, _b;
113
114
  chart.tooltip.splitTooltip = true;
114
115
  chart.tooltip.getTooltipContainer = this.getTooltipContainer;
116
+ (_b = (_a = this.props).callback) === null || _b === void 0 ? void 0 : _b.call(_a, chart);
115
117
  };
116
118
  this.setInitialPaneSize = (callback) => {
117
119
  if (!this.tooltipContainerRef.current || !this.rootRef.current) {
@@ -1,2 +1,2 @@
1
- import type { TooltipRenderOptions } from '../../types';
2
- export declare const getRenderTooltip: (timeZone?: string) => (data: TooltipRenderOptions) => string;
1
+ import type { TooltipRenderOptions, YagrWidgetData } from '../../types';
2
+ export declare const getRenderTooltip: (userData: YagrWidgetData['data']) => (data: TooltipRenderOptions) => string;
@@ -7,12 +7,33 @@ const calcOption = (d) => {
7
7
  })
8
8
  : d;
9
9
  };
10
+ const getSeriesColorProperty = (args) => {
11
+ var _a;
12
+ const { data, userData, row, rowIndex } = args;
13
+ const userSeries = userData.graphs[rowIndex];
14
+ const lineColor = (_a = data.yagr.getSeriesById(row.id)) === null || _a === void 0 ? void 0 : _a.lineColor;
15
+ let seriesColor = row.color;
16
+ switch (userSeries === null || userSeries === void 0 ? void 0 : userSeries.legendColorKey) {
17
+ case 'lineColor': {
18
+ if (lineColor) {
19
+ seriesColor = lineColor;
20
+ }
21
+ break;
22
+ }
23
+ case 'color':
24
+ default: {
25
+ seriesColor = row.color;
26
+ }
27
+ }
28
+ return seriesColor;
29
+ };
10
30
  /*
11
31
  * Default tooltip renderer.
12
32
  * Adapter between native Yagr tooltip config and ChartKit
13
33
  * tooltip renderer.
14
34
  */
15
- export const getRenderTooltip = (timeZone) => (data) => {
35
+ export const getRenderTooltip = (userData) => (data) => {
36
+ const { timeZone } = userData;
16
37
  const cfg = data.yagr.config;
17
38
  const timeMultiplier = cfg.chart.timeMultiplier || 1;
18
39
  const opts = data.options;
@@ -41,7 +62,7 @@ export const getRenderTooltip = (timeZone) => (data) => {
41
62
  activeRowAlwaysFirstInTooltip: rows.length > 1,
42
63
  tooltipHeader: dateTime({ input: x / timeMultiplier, timeZone }).format('DD MMMM YYYY HH:mm:ss'),
43
64
  shared: true,
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) : '' }))),
65
+ lines: rows.map((row, i) => (Object.assign(Object.assign({}, row), { seriesName: row.name || 'Serie ' + (i + 1), seriesColor: getSeriesColorProperty({ data, userData, row, rowIndex: i }), selectedSeries: row.active, seriesIdx: row.seriesIdx, percentValue: typeof row.transformed === 'number' ? row.transformed.toFixed(1) : '' }))),
45
66
  withPercent: calcOption(opts.percent),
46
67
  hiddenRowsNumber: hiddenRowsNumber,
47
68
  hiddenRowsSum,
@@ -111,7 +111,7 @@ export const shapeYagrConfig = (args) => {
111
111
  config.chart = chart;
112
112
  if ((_a = config.tooltip) === null || _a === void 0 ? void 0 : _a.show) {
113
113
  config.tooltip = config.tooltip || {};
114
- config.tooltip.render = ((_b = config.tooltip) === null || _b === void 0 ? void 0 : _b.render) || getRenderTooltip(timeZone);
114
+ config.tooltip.render = ((_b = config.tooltip) === null || _b === void 0 ? void 0 : _b.render) || getRenderTooltip(data);
115
115
  if (!config.tooltip.className) {
116
116
  // "className" property prevent default yagr styles adding
117
117
  config.tooltip.className = 'chartkit-yagr-tooltip';
@@ -1,4 +1,4 @@
1
- import type { MinimalValidConfig, RawSerieData, YagrConfig } from '@gravity-ui/yagr';
1
+ import type { MinimalValidConfig, RawSerieData, SeriesOptions, YagrConfig } from '@gravity-ui/yagr';
2
2
  import type Yagr from '@gravity-ui/yagr';
3
3
  import { ChartKitProps } from 'src/types';
4
4
  export type { default as Yagr } from '@gravity-ui/yagr';
@@ -10,9 +10,19 @@ export interface CustomTooltipProps {
10
10
  export type YagrWidgetProps = ChartKitProps<'yagr'> & {
11
11
  id: string;
12
12
  };
13
+ export type YagrSeriesData<T = Omit<SeriesOptions, 'type'>> = RawSerieData<T> & {
14
+ /**
15
+ * Determines what data value should be used to get a color for tooltip series. Does not work in case of using custom tooltip rendered via `tooltip` property.
16
+ * - `lineColor` indicates that lineColor property should be used
17
+ * - `color` indicates that color property should be used
18
+ *
19
+ * @default 'color'
20
+ */
21
+ legendColorKey?: 'color' | 'lineColor';
22
+ };
13
23
  export type YagrWidgetData = {
14
24
  data: {
15
- graphs: RawSerieData[];
25
+ graphs: YagrSeriesData[];
16
26
  timeline: number[];
17
27
  /**
18
28
  * Allow to setup timezone for X axis and tooltip's header.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "4.22.0",
3
+ "version": "4.23.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",