@gravity-ui/chartkit 3.0.0-beta.7 → 3.0.0-beta.9

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.
@@ -16,7 +16,7 @@ import { formatNumber } from '../../../../shared';
16
16
  import { getCommentsOnLine, drawComments, hideComments, drawOnlyRendererComments, } from '../comments/drawing';
17
17
  import formatTooltip, { TOOLTIP_ROW_CLASS_NAME, SERIES_NAME_DATA_ATTRIBUTE, TOOLTIP_HEADER_CLASS_NAME, TOOLTIP_LIST_CLASS_NAME, TOOLTIP_FOOTER_CLASS_NAME, TOOLTIP_CONTAINER_CLASS_NAME, TOOLTIP_ROW_NAME_CLASS_NANE, } from '../tooltip';
18
18
  import defaultOptions from './options';
19
- import { calculatePrecision, isTooltipShared, isSafari, mergeArrayWithObject, concatStrings, buildNavigatorFallback, addShowInNavigatorToSeries, setNavigatorDefaultPeriod, numberFormat, getFormatOptionsFromLine, checkTooltipPinningAvailability, } from './utils';
19
+ import { calculatePrecision, isTooltipShared, isSafari, mergeArrayWithObject, concatStrings, buildNavigatorFallback, addShowInNavigatorToSeries, setNavigatorDefaultPeriod, numberFormat, getFormatOptionsFromLine, checkTooltipPinningAvailability, getSortedData, } from './utils';
20
20
  import { handleLegendItemClick } from './handleLegendItemClick';
21
21
  import { getChartKitFormattedValue } from './utils/getChartKitFormattedValue';
22
22
  const b = block('chartkit-tooltip');
@@ -381,7 +381,7 @@ function validateCellManipulationConfig(tooltipOptions, property, item) {
381
381
  }
382
382
  }
383
383
  function getTooltip(tooltip, options, comments, holidays) {
384
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
384
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
385
385
  const serieType = (this.series && this.series.type) || tooltip.chart.options.chart.type;
386
386
  const chart = tooltip.chart;
387
387
  const xAxis = chart.xAxis[0];
@@ -412,7 +412,6 @@ function getTooltip(tooltip, options, comments, holidays) {
412
412
  count: 1,
413
413
  shared: true,
414
414
  unsafe: Boolean(options.unsafe),
415
- sort: (_b = options === null || options === void 0 ? void 0 : options.tooltip) === null || _b === void 0 ? void 0 : _b.sort,
416
415
  };
417
416
  if (typeof options.manageTooltipConfig === 'function') {
418
417
  json = callManageTooltipConfig(options, json, chart);
@@ -440,7 +439,7 @@ function getTooltip(tooltip, options, comments, holidays) {
440
439
  let points = [];
441
440
  let shared;
442
441
  if (this.points) {
443
- points = this.points;
442
+ points = getSortedData(this.points, (_b = options === null || options === void 0 ? void 0 : options.tooltip) === null || _b === void 0 ? void 0 : _b.sort);
444
443
  shared = true;
445
444
  }
446
445
  else {
@@ -459,7 +458,6 @@ function getTooltip(tooltip, options, comments, holidays) {
459
458
  withPercent: false,
460
459
  tooltipHeader: null,
461
460
  unsafe: Boolean(options.unsafe),
462
- sort: (_c = options === null || options === void 0 ? void 0 : options.tooltip) === null || _c === void 0 ? void 0 : _c.sort,
463
461
  };
464
462
  if (isDatetimeXAxis) {
465
463
  const items = this.points || Highcharts.splat(this);
@@ -476,9 +474,9 @@ function getTooltip(tooltip, options, comments, holidays) {
476
474
  }
477
475
  json.tooltipHeader = chart.time.dateFormat(xDateFormat, this.x);
478
476
  }
479
- else if ((_f = (_e = (_d = extendedPoint.point) === null || _d === void 0 ? void 0 : _d.options) === null || _e === void 0 ? void 0 : _e.xFormatted) !== null && _f !== void 0 ? _f : (extendedPoint.x || extendedPoint.x === 0)) {
480
- const customTooltipHeaderFormatter = (_g = options === null || options === void 0 ? void 0 : options.highcharts) === null || _g === void 0 ? void 0 : _g.tooltipHeaderFormatter;
481
- const tooltipHeaderStringValue = String((_k = (_j = (_h = extendedPoint.point) === null || _h === void 0 ? void 0 : _h.options) === null || _j === void 0 ? void 0 : _j.xFormatted) !== null && _k !== void 0 ? _k : extendedPoint.x);
477
+ else if ((_e = (_d = (_c = extendedPoint.point) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.xFormatted) !== null && _e !== void 0 ? _e : (extendedPoint.x || extendedPoint.x === 0)) {
478
+ const customTooltipHeaderFormatter = (_f = options === null || options === void 0 ? void 0 : options.highcharts) === null || _f === void 0 ? void 0 : _f.tooltipHeaderFormatter;
479
+ const tooltipHeaderStringValue = String((_j = (_h = (_g = extendedPoint.point) === null || _g === void 0 ? void 0 : _g.options) === null || _h === void 0 ? void 0 : _h.xFormatted) !== null && _j !== void 0 ? _j : extendedPoint.x);
482
480
  json.tooltipHeader = customTooltipHeaderFormatter
483
481
  ? customTooltipHeaderFormatter(tooltipHeaderStringValue)
484
482
  : tooltipHeaderStringValue;
@@ -1,3 +1,4 @@
1
+ import type { HighchartsSortData } from '../../../../types/widget';
1
2
  export { addShowInNavigatorToSeries } from './addShowInNavigatorToSeries';
2
3
  export { buildNavigatorFallback } from './buildNavigatorFallback';
3
4
  export { calculatePrecision } from './calculatePrecision';
@@ -11,3 +12,35 @@ export { isSafari } from './isSafari';
11
12
  export { mergeArrayWithObject } from './mergeArrayWithObject';
12
13
  export { numberFormat } from './numberFormat';
13
14
  export { setNavigatorDefaultPeriod } from './setNavigatorDefaultPeriod';
15
+ export declare const getSortedData: <T extends Record<string, any>>(data: T[], sort?: HighchartsSortData) => (number | T | (() => IterableIterator<T>) | (() => {
16
+ copyWithin: boolean;
17
+ entries: boolean;
18
+ fill: boolean;
19
+ find: boolean;
20
+ findIndex: boolean;
21
+ keys: boolean;
22
+ values: boolean;
23
+ }) | (() => string) | (() => string) | (() => T | undefined) | ((...items: T[]) => number) | {
24
+ (...items: ConcatArray<T>[]): T[];
25
+ (...items: (T | ConcatArray<T>)[]): T[];
26
+ } | ((separator?: string | undefined) => string) | (() => T[]) | (() => T | undefined) | ((start?: number | undefined, end?: number | undefined) => T[]) | ((compareFn?: ((a: T, b: T) => number) | undefined) => T[]) | {
27
+ (start: number, deleteCount?: number | undefined): T[];
28
+ (start: number, deleteCount: number, ...items: T[]): T[];
29
+ } | ((...items: T[]) => number) | ((searchElement: T, fromIndex?: number | undefined) => number) | ((searchElement: T, fromIndex?: number | undefined) => number) | {
30
+ <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is S[];
31
+ (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
32
+ } | ((predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean) | ((callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any) => void) | (<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[]) | {
33
+ <S_1 extends T>(predicate: (value: T, index: number, array: T[]) => value is S_1, thisArg?: any): S_1[];
34
+ (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[];
35
+ } | {
36
+ (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
37
+ (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
38
+ <U_1>(callbackfn: (previousValue: U_1, currentValue: T, currentIndex: number, array: T[]) => U_1, initialValue: U_1): U_1;
39
+ } | {
40
+ (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
41
+ (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
42
+ <U_2>(callbackfn: (previousValue: U_2, currentValue: T, currentIndex: number, array: T[]) => U_2, initialValue: U_2): U_2;
43
+ } | {
44
+ <S_2 extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S_2, thisArg?: any): S_2 | undefined;
45
+ (predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
46
+ } | ((predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any) => number) | ((value: T, start?: number | undefined, end?: number | undefined) => T[]) | ((target: number, start: number, end?: number | undefined) => T[]) | (() => IterableIterator<[number, T]>) | (() => IterableIterator<number>) | (() => IterableIterator<T>) | ((searchElement: T, fromIndex?: number | undefined) => boolean) | (<U_3, This = undefined>(callback: (this: This, value: T, index: number, array: T[]) => U_3 | readonly U_3[], thisArg?: This | undefined) => U_3[]) | (<A, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]) | ((index: number) => T | undefined))[];
@@ -1,3 +1,4 @@
1
+ import orderBy from 'lodash/orderBy';
1
2
  export { addShowInNavigatorToSeries } from './addShowInNavigatorToSeries';
2
3
  export { buildNavigatorFallback } from './buildNavigatorFallback';
3
4
  export { calculatePrecision } from './calculatePrecision';
@@ -11,3 +12,10 @@ export { isSafari } from './isSafari';
11
12
  export { mergeArrayWithObject } from './mergeArrayWithObject';
12
13
  export { numberFormat } from './numberFormat';
13
14
  export { setNavigatorDefaultPeriod } from './setNavigatorDefaultPeriod';
15
+ export const getSortedData = (data, sort = {}) => {
16
+ const { enabled = true, order = 'desc', iteratee = 'y' } = sort;
17
+ if (!enabled) {
18
+ return [...data];
19
+ }
20
+ return orderBy(data, iteratee, order);
21
+ };
@@ -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,13 +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
- const { enabled = true, order = 'desc', iteratee = 'originalValue' } = sort;
9
- if (!enabled) {
10
- return [...lines];
11
- }
12
- return orderBy(lines, iteratee, order);
13
- };
@@ -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>
@@ -38,15 +38,6 @@ export 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
42
  export type TooltipLine = {
52
43
  /** Color displayed in a separate cell */
@@ -27,6 +27,14 @@ export type HighchartsManageTooltipConfigOptions = {
27
27
  xComments?: TooltipData['xComments'];
28
28
  };
29
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
+ };
30
38
  export type HighchartsWidgetData = {
31
39
  data: (CkHighchartsSeriesOptionsType[] | {
32
40
  graphs: CkHighchartsSeriesOptionsType[];
@@ -95,7 +103,7 @@ export 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "3.0.0-beta.7",
3
+ "version": "3.0.0-beta.9",
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",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@gravity-ui/date-utils": "^1.4.1",
17
- "@gravity-ui/yagr": "^3.3.5",
17
+ "@gravity-ui/yagr": "^3.3.6",
18
18
  "bem-cn-lite": "^4.1.0",
19
19
  "highcharts": "^8.2.2",
20
20
  "highcharts-react-official": "^3.0.0",