@gravity-ui/charts 1.15.0 → 1.17.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 (141) hide show
  1. package/dist/{esm/components/Axis → cjs/components/AxisX}/AxisX.js +1 -15
  2. package/dist/cjs/components/{Axis → AxisY}/AxisY.d.ts +2 -10
  3. package/dist/cjs/components/AxisY/AxisY.js +173 -0
  4. package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +9 -0
  5. package/dist/cjs/components/AxisY/prepare-axis-data.js +306 -0
  6. package/dist/cjs/components/AxisY/styles.css +15 -0
  7. package/dist/cjs/components/AxisY/types.d.ts +81 -0
  8. package/dist/cjs/components/AxisY/types.js +1 -0
  9. package/dist/cjs/components/AxisY/utils.d.ts +12 -0
  10. package/dist/cjs/components/AxisY/utils.js +71 -0
  11. package/dist/cjs/components/ChartInner/index.js +31 -3
  12. package/dist/cjs/components/ChartInner/useChartInnerProps.js +13 -1
  13. package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +4 -2
  14. package/dist/cjs/components/Tooltip/ChartTooltipContent.js +2 -2
  15. package/dist/cjs/components/Tooltip/DefaultTooltipContent/Row.d.ts +2 -1
  16. package/dist/cjs/components/Tooltip/DefaultTooltipContent/Row.js +3 -3
  17. package/dist/cjs/components/Tooltip/DefaultTooltipContent/{RowTotals.d.ts → RowWithAggregation.d.ts} +2 -1
  18. package/dist/cjs/components/Tooltip/DefaultTooltipContent/{RowTotals.js → RowWithAggregation.js} +3 -3
  19. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.d.ts +4 -2
  20. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +174 -114
  21. package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.d.ts +7 -1
  22. package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.js +12 -7
  23. package/dist/cjs/components/Tooltip/index.js +1 -1
  24. package/dist/cjs/components/Tooltip/styles.css +11 -1
  25. package/dist/cjs/constants/date.d.ts +1 -0
  26. package/dist/cjs/constants/date.js +1 -0
  27. package/dist/cjs/constants/index.d.ts +1 -0
  28. package/dist/cjs/constants/index.js +1 -0
  29. package/dist/cjs/hooks/useChartOptions/types.d.ts +7 -1
  30. package/dist/cjs/hooks/useChartOptions/x-axis.js +5 -5
  31. package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +3 -1
  32. package/dist/cjs/hooks/useChartOptions/y-axis.js +20 -20
  33. package/dist/cjs/hooks/useCrosshair/index.js +2 -1
  34. package/dist/cjs/hooks/useSeries/prepare-area.js +1 -0
  35. package/dist/cjs/hooks/useSeries/prepare-bar-x.js +1 -0
  36. package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +1 -0
  37. package/dist/cjs/hooks/useSeries/prepare-bar-y.js +1 -0
  38. package/dist/cjs/hooks/useSeries/prepare-line.js +1 -0
  39. package/dist/cjs/hooks/useSeries/prepare-pie.js +1 -0
  40. package/dist/cjs/hooks/useSeries/prepare-radar.js +1 -0
  41. package/dist/cjs/hooks/useSeries/prepare-sankey.js +1 -0
  42. package/dist/cjs/hooks/useSeries/prepare-scatter.js +1 -0
  43. package/dist/cjs/hooks/useSeries/prepare-treemap.js +1 -0
  44. package/dist/cjs/hooks/useSeries/prepare-waterfall.js +1 -0
  45. package/dist/cjs/hooks/useSeries/types.d.ts +2 -1
  46. package/dist/cjs/i18n/keysets/en.json +2 -1
  47. package/dist/cjs/i18n/keysets/ru.json +2 -1
  48. package/dist/cjs/index.d.ts +1 -1
  49. package/dist/cjs/index.js +1 -1
  50. package/dist/cjs/types/chart/axis.d.ts +11 -1
  51. package/dist/cjs/types/chart/base.d.ts +14 -0
  52. package/dist/cjs/types/chart/tooltip.d.ts +5 -1
  53. package/dist/cjs/utils/chart/axis-generators/bottom.js +3 -3
  54. package/dist/cjs/utils/chart/axis.d.ts +14 -8
  55. package/dist/cjs/utils/chart/axis.js +34 -9
  56. package/dist/cjs/utils/chart/format.d.ts +9 -2
  57. package/dist/cjs/utils/chart/format.js +40 -5
  58. package/dist/cjs/utils/chart/index.d.ts +6 -17
  59. package/dist/cjs/utils/chart/index.js +6 -43
  60. package/dist/cjs/utils/chart/text.d.ts +2 -1
  61. package/dist/cjs/utils/chart/text.js +3 -10
  62. package/dist/cjs/utils/misc.d.ts +1 -0
  63. package/dist/cjs/utils/misc.js +6 -0
  64. package/dist/{cjs/components/Axis → esm/components/AxisX}/AxisX.js +1 -15
  65. package/dist/esm/components/{Axis → AxisY}/AxisY.d.ts +2 -10
  66. package/dist/esm/components/AxisY/AxisY.js +173 -0
  67. package/dist/esm/components/AxisY/prepare-axis-data.d.ts +9 -0
  68. package/dist/esm/components/AxisY/prepare-axis-data.js +306 -0
  69. package/dist/esm/components/AxisY/styles.css +15 -0
  70. package/dist/esm/components/AxisY/types.d.ts +81 -0
  71. package/dist/esm/components/AxisY/types.js +1 -0
  72. package/dist/esm/components/AxisY/utils.d.ts +12 -0
  73. package/dist/esm/components/AxisY/utils.js +71 -0
  74. package/dist/esm/components/ChartInner/index.js +31 -3
  75. package/dist/esm/components/ChartInner/useChartInnerProps.js +13 -1
  76. package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +4 -2
  77. package/dist/esm/components/Tooltip/ChartTooltipContent.js +2 -2
  78. package/dist/esm/components/Tooltip/DefaultTooltipContent/Row.d.ts +2 -1
  79. package/dist/esm/components/Tooltip/DefaultTooltipContent/Row.js +3 -3
  80. package/dist/esm/components/Tooltip/DefaultTooltipContent/{RowTotals.d.ts → RowWithAggregation.d.ts} +2 -1
  81. package/dist/esm/components/Tooltip/DefaultTooltipContent/{RowTotals.js → RowWithAggregation.js} +3 -3
  82. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.d.ts +4 -2
  83. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +174 -114
  84. package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.d.ts +7 -1
  85. package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.js +12 -7
  86. package/dist/esm/components/Tooltip/index.js +1 -1
  87. package/dist/esm/components/Tooltip/styles.css +11 -1
  88. package/dist/esm/constants/date.d.ts +1 -0
  89. package/dist/esm/constants/date.js +1 -0
  90. package/dist/esm/constants/index.d.ts +1 -0
  91. package/dist/esm/constants/index.js +1 -0
  92. package/dist/esm/hooks/useChartOptions/types.d.ts +7 -1
  93. package/dist/esm/hooks/useChartOptions/x-axis.js +5 -5
  94. package/dist/esm/hooks/useChartOptions/y-axis.d.ts +3 -1
  95. package/dist/esm/hooks/useChartOptions/y-axis.js +20 -20
  96. package/dist/esm/hooks/useCrosshair/index.js +2 -1
  97. package/dist/esm/hooks/useSeries/prepare-area.js +1 -0
  98. package/dist/esm/hooks/useSeries/prepare-bar-x.js +1 -0
  99. package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +1 -0
  100. package/dist/esm/hooks/useSeries/prepare-bar-y.js +1 -0
  101. package/dist/esm/hooks/useSeries/prepare-line.js +1 -0
  102. package/dist/esm/hooks/useSeries/prepare-pie.js +1 -0
  103. package/dist/esm/hooks/useSeries/prepare-radar.js +1 -0
  104. package/dist/esm/hooks/useSeries/prepare-sankey.js +1 -0
  105. package/dist/esm/hooks/useSeries/prepare-scatter.js +1 -0
  106. package/dist/esm/hooks/useSeries/prepare-treemap.js +1 -0
  107. package/dist/esm/hooks/useSeries/prepare-waterfall.js +1 -0
  108. package/dist/esm/hooks/useSeries/types.d.ts +2 -1
  109. package/dist/esm/i18n/keysets/en.json +2 -1
  110. package/dist/esm/i18n/keysets/ru.json +2 -1
  111. package/dist/esm/index.d.ts +1 -1
  112. package/dist/esm/index.js +1 -1
  113. package/dist/esm/types/chart/axis.d.ts +11 -1
  114. package/dist/esm/types/chart/base.d.ts +14 -0
  115. package/dist/esm/types/chart/tooltip.d.ts +5 -1
  116. package/dist/esm/utils/chart/axis-generators/bottom.js +3 -3
  117. package/dist/esm/utils/chart/axis.d.ts +14 -8
  118. package/dist/esm/utils/chart/axis.js +34 -9
  119. package/dist/esm/utils/chart/format.d.ts +9 -2
  120. package/dist/esm/utils/chart/format.js +40 -5
  121. package/dist/esm/utils/chart/index.d.ts +6 -17
  122. package/dist/esm/utils/chart/index.js +6 -43
  123. package/dist/esm/utils/chart/text.d.ts +2 -1
  124. package/dist/esm/utils/chart/text.js +3 -10
  125. package/dist/esm/utils/misc.d.ts +1 -0
  126. package/dist/esm/utils/misc.js +6 -0
  127. package/package.json +1 -1
  128. package/dist/cjs/components/Axis/AxisY.js +0 -416
  129. package/dist/cjs/components/Axis/index.d.ts +0 -2
  130. package/dist/cjs/components/Axis/index.js +0 -2
  131. package/dist/cjs/components/Tooltip/utils.d.ts +0 -30
  132. package/dist/cjs/components/Tooltip/utils.js +0 -126
  133. package/dist/esm/components/Axis/AxisY.js +0 -416
  134. package/dist/esm/components/Axis/index.d.ts +0 -2
  135. package/dist/esm/components/Axis/index.js +0 -2
  136. package/dist/esm/components/Tooltip/utils.d.ts +0 -30
  137. package/dist/esm/components/Tooltip/utils.js +0 -126
  138. /package/dist/cjs/components/{Axis → AxisX}/AxisX.d.ts +0 -0
  139. /package/dist/cjs/components/{Axis → AxisX}/styles.css +0 -0
  140. /package/dist/esm/components/{Axis → AxisX}/AxisX.d.ts +0 -0
  141. /package/dist/esm/components/{Axis → AxisX}/styles.css +0 -0
@@ -36,6 +36,7 @@ export function prepareBarXSeries(args) {
36
36
  cursor: get(series, 'cursor', null),
37
37
  yAxis: get(series, 'yAxis', 0),
38
38
  borderRadius: get(series, 'borderRadius', get(seriesOptions, 'bar-x.borderRadius', 0)),
39
+ tooltip: series.tooltip,
39
40
  };
40
41
  }, []);
41
42
  }
@@ -35,5 +35,6 @@ export declare function prepareBarYSeries(args: PrepareBarYSeriesArgs): Promise<
35
35
  symbol: import("./types").PreparedLegendSymbol;
36
36
  };
37
37
  cursor: string | null;
38
+ tooltip: import("../..").ChartSeries["tooltip"];
38
39
  })[]>;
39
40
  export {};
@@ -52,6 +52,7 @@ export function prepareBarYSeries(args) {
52
52
  borderRadius: (_c = (_a = series.borderRadius) !== null && _a !== void 0 ? _a : (_b = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _b === void 0 ? void 0 : _b.borderRadius) !== null && _c !== void 0 ? _c : 0,
53
53
  borderWidth: (_f = (_d = series.borderWidth) !== null && _d !== void 0 ? _d : (_e = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _e === void 0 ? void 0 : _e.borderWidth) !== null && _f !== void 0 ? _f : 0,
54
54
  borderColor: (_j = (_g = series.borderColor) !== null && _g !== void 0 ? _g : (_h = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _h === void 0 ? void 0 : _h.borderColor) !== null && _j !== void 0 ? _j : 'var(--gcharts-shape-border-color)',
55
+ tooltip: series.tooltip,
55
56
  };
56
57
  }));
57
58
  }
@@ -77,6 +77,7 @@ export function prepareLineSeries(args) {
77
77
  opacity: get(series, 'opacity', null),
78
78
  cursor: get(series, 'cursor', null),
79
79
  yAxis: get(series, 'yAxis', 0),
80
+ tooltip: series.tooltip,
80
81
  };
81
82
  return prepared;
82
83
  }, []);
@@ -57,6 +57,7 @@ export function preparePieSeries(args) {
57
57
  renderCustomShape: series.renderCustomShape,
58
58
  opacity: get(dataItem, 'opacity', null),
59
59
  cursor: get(series, 'cursor', null),
60
+ tooltip: series.tooltip,
60
61
  };
61
62
  return result;
62
63
  });
@@ -58,6 +58,7 @@ export function prepareRadarSeries(args) {
58
58
  },
59
59
  cursor: get(series, 'cursor', null),
60
60
  marker: prepareMarker(series, seriesOptions),
61
+ tooltip: series.tooltip,
61
62
  };
62
63
  return preparedSeries;
63
64
  });
@@ -33,6 +33,7 @@ export function prepareSankeySeries(args) {
33
33
  symbol: prepareLegendSymbol(s),
34
34
  },
35
35
  cursor: get(s, 'cursor', null),
36
+ tooltip: s.tooltip,
36
37
  };
37
38
  return preparedSeries;
38
39
  });
@@ -40,6 +40,7 @@ export function prepareScatterSeries(args) {
40
40
  marker: prepareMarker(s, seriesOptions, index),
41
41
  cursor: get(s, 'cursor', null),
42
42
  yAxis: get(s, 'yAxis', 0),
43
+ tooltip: s.tooltip,
43
44
  };
44
45
  return prepared;
45
46
  }, []);
@@ -34,6 +34,7 @@ export function prepareTreemap(args) {
34
34
  layoutAlgorithm: get(s, 'layoutAlgorithm', LayoutAlgorithm.Binary),
35
35
  cursor: get(s, 'cursor', null),
36
36
  sorting: Object.assign({ enabled: false, direction: 'desc' }, s.sorting),
37
+ tooltip: s.tooltip,
37
38
  };
38
39
  return preparedSeries;
39
40
  });
@@ -28,6 +28,7 @@ export function prepareWaterfallSeries(args) {
28
28
  },
29
29
  cursor: get(series, 'cursor', null),
30
30
  data: [],
31
+ tooltip: series.tooltip,
31
32
  };
32
33
  const positive = Object.assign(Object.assign({}, common), { name: (_g = (_f = (_e = series.legend) === null || _e === void 0 ? void 0 : _e.itemText) === null || _f === void 0 ? void 0 : _f.positive) !== null && _g !== void 0 ? _g : `${series.name} ↑`, id: getUniqId(), color: series.positiveColor || positiveColor, data: [] });
33
34
  const negative = Object.assign(Object.assign({}, common), { name: (_k = (_j = (_h = series.legend) === null || _h === void 0 ? void 0 : _h.itemText) === null || _j === void 0 ? void 0 : _j.negative) !== null && _k !== void 0 ? _k : `${series.name} ↓`, id: getUniqId(), color: series.negativeColor || negativeColor, data: [] });
@@ -1,5 +1,5 @@
1
1
  import type { DashStyle, LayoutAlgorithm, LineCap, SeriesOptionsDefaults, SymbolType } from '../../constants';
2
- import type { AreaSeries, AreaSeriesData, BarXSeries, BarXSeriesData, BarYSeries, BarYSeriesData, BaseTextStyle, ChartLegend, ConnectorCurve, ConnectorShape, LineSeries, LineSeriesData, PathLegendSymbolOptions, PieSeries, PieSeriesData, RadarSeries, RadarSeriesCategory, RadarSeriesData, RectLegendSymbolOptions, SankeySeries, SankeySeriesData, ScatterSeries, ScatterSeriesData, SymbolLegendSymbolOptions, TreemapSeries, TreemapSeriesData, ValueFormat, WaterfallSeries, WaterfallSeriesData } from '../../types';
2
+ import type { AreaSeries, AreaSeriesData, BarXSeries, BarXSeriesData, BarYSeries, BarYSeriesData, BaseTextStyle, ChartLegend, ChartSeries, ConnectorCurve, ConnectorShape, LineSeries, LineSeriesData, PathLegendSymbolOptions, PieSeries, PieSeriesData, RadarSeries, RadarSeriesCategory, RadarSeriesData, RectLegendSymbolOptions, SankeySeries, SankeySeriesData, ScatterSeries, ScatterSeriesData, SymbolLegendSymbolOptions, TreemapSeries, TreemapSeriesData, ValueFormat, WaterfallSeries, WaterfallSeriesData } from '../../types';
3
3
  export type RectLegendSymbol = {
4
4
  shape: 'rect';
5
5
  } & Required<RectLegendSymbolOptions>;
@@ -76,6 +76,7 @@ type BasePreparedSeries = {
76
76
  symbol: PreparedLegendSymbol;
77
77
  };
78
78
  cursor: string | null;
79
+ tooltip: ChartSeries['tooltip'];
79
80
  };
80
81
  export type PreparedScatterSeries = {
81
82
  type: ScatterSeries['type'];
@@ -21,6 +21,7 @@
21
21
  "label_invalid-axis-labels-html-not-supported-axis-type": "It seems you are trying to use \"labels.html\" property for an axis with an unsupported type. This property is supported only for \"category\" axis."
22
22
  },
23
23
  "tooltip": {
24
- "label_totals_sum": "Sum"
24
+ "label_totals_sum": "Sum",
25
+ "label_more": "{{count}} more"
25
26
  }
26
27
  }
@@ -21,6 +21,7 @@
21
21
  "label_invalid-axis-labels-html-not-supported-axis-type": "Похоже, что вы пытаетесь использовать свойство \"labels.html\" для оси с неподдерживаемым типом. Это свойство поддерживается только для оси типа \"category\"."
22
22
  },
23
23
  "tooltip": {
24
- "label_totals_sum": "Сумма"
24
+ "label_totals_sum": "Сумма",
25
+ "label_more": "Еще {{count}}"
25
26
  }
26
27
  }
@@ -1,3 +1,3 @@
1
- export { CustomShapeRenderer } from './utils';
1
+ export { CustomShapeRenderer, getFormattedValue } from './utils';
2
2
  export * from './components';
3
3
  export * from './types';
package/dist/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { CustomShapeRenderer } from './utils';
1
+ export { CustomShapeRenderer, getFormattedValue } from './utils';
2
2
  export * from './components';
3
3
  export * from './types';
@@ -35,6 +35,10 @@ export interface ChartAxisLabels {
35
35
  * @default false
36
36
  * */
37
37
  html?: boolean;
38
+ /** The maximum width of the axis labels(absolute or relative to the chart area).
39
+ * If more than that, it collapses into three points.
40
+ * */
41
+ maxWidth?: number | string;
38
42
  }
39
43
  export interface ChartAxis {
40
44
  categories?: string[];
@@ -74,8 +78,14 @@ export interface ChartAxis {
74
78
  };
75
79
  ticks?: {
76
80
  /** Pixel interval of the tick marks. Not applicable to categorized axis.
77
- * The specified value is only a hint; the interval between ticks can be greater or less depending on the data. */
81
+ * The specified value is only a hint; the interval between ticks can be greater or less depending on the data.
82
+ *
83
+ * @deprecated use `interval` instead
84
+ * */
78
85
  pixelInterval?: number;
86
+ /** Interval of the tick marks(absolute or relative to the chart area). Not applicable to categorized axis.
87
+ * The specified value is only a hint; the interval between ticks can be greater or less depending on the data. */
88
+ interval?: number | string;
79
89
  };
80
90
  /** Padding of the max value relative to the length of the axis.
81
91
  * A padding of 0.05 will make a 100px axis 5px longer.
@@ -7,6 +7,13 @@ type DateFormat = {
7
7
  type: 'date';
8
8
  format?: string;
9
9
  };
10
+ export type CustomFormat = {
11
+ type: 'custom';
12
+ formatter: (args: {
13
+ value: unknown;
14
+ formattedValue?: string;
15
+ }) => string;
16
+ };
10
17
  export type ValueFormat = NumberFormat | DateFormat;
11
18
  export interface BaseSeries {
12
19
  /** Initial visibility of the series */
@@ -41,6 +48,13 @@ export interface BaseSeries {
41
48
  };
42
49
  /** You can set the cursor to "pointer" if you have click events attached to the series, to signal to the user that the points and lines can be clicked. */
43
50
  cursor?: string;
51
+ /**
52
+ * Options for the tooltip that appears when the user hovers over a series or point.
53
+ */
54
+ tooltip?: {
55
+ /** Formatting settings for tooltip value. */
56
+ valueFormat?: ValueFormat;
57
+ };
44
58
  }
45
59
  export interface BaseSeriesData<T = MeaningfulAny> {
46
60
  /**
@@ -4,7 +4,7 @@ import type { AreaSeries, AreaSeriesData } from './area';
4
4
  import type { ChartXAxis, ChartYAxis } from './axis';
5
5
  import type { BarXSeries, BarXSeriesData } from './bar-x';
6
6
  import type { BarYSeries, BarYSeriesData } from './bar-y';
7
- import type { ValueFormat } from './base';
7
+ import type { CustomFormat, ValueFormat } from './base';
8
8
  import type { LineSeries, LineSeriesData } from './line';
9
9
  import type { PieSeries, PieSeriesData } from './pie';
10
10
  import type { RadarSeries, RadarSeriesCategory, RadarSeriesData } from './radar';
@@ -110,6 +110,8 @@ export interface ChartTooltip<T = MeaningfulAny> {
110
110
  throttle?: number;
111
111
  /** Formatting settings for tooltip value. */
112
112
  valueFormat?: ValueFormat;
113
+ /** Formatting settings for tooltip header row. */
114
+ headerFormat?: ValueFormat | CustomFormat;
113
115
  /** Settings for totals block in tooltip */
114
116
  totals?: {
115
117
  /**
@@ -125,5 +127,7 @@ export interface ChartTooltip<T = MeaningfulAny> {
125
127
  enabled?: boolean;
126
128
  /** The label text for the totals. For built-in aggregations, the label can be omitted. */
127
129
  label?: string;
130
+ /** Formatting settings for totals tooltip value. */
131
+ valueFormat?: ValueFormat;
128
132
  };
129
133
  }
@@ -1,5 +1,5 @@
1
1
  import { path, select } from 'd3';
2
- import { getXAxisItems, getXAxisOffset, getXTickPosition } from '../axis';
2
+ import { getAxisItems, getXAxisOffset, getXTickPosition } from '../axis';
3
3
  import { calculateCos, calculateSin } from '../math';
4
4
  import { getLabelsSize, setEllipsisForOverflowText } from '../text';
5
5
  const AXIS_BOTTOM_HTML_LABELS_DATA_ATTR = 'data-axis-bottom-html-labels';
@@ -151,7 +151,7 @@ export async function axisBottom(args) {
151
151
  const htmlSelection = select(htmlLayout);
152
152
  const offset = getXAxisOffset();
153
153
  const position = getXTickPosition({ scale, offset });
154
- const values = getXAxisItems({ scale, count: ticksCount, maxCount: maxTickCount });
154
+ const values = getAxisItems({ scale, count: ticksCount, maxCount: maxTickCount });
155
155
  const labelHeight = (await getLabelsSize({
156
156
  labels: values.map(labelFormat),
157
157
  style: labelsStyle,
@@ -183,7 +183,7 @@ export async function axisBottom(args) {
183
183
  ? values.map((v) => {
184
184
  var _a;
185
185
  return {
186
- content: v,
186
+ content: String(v),
187
187
  left: position(v) + offset + boundsOffsetLeft,
188
188
  top: Math.abs(((_a = tickItems === null || tickItems === void 0 ? void 0 : tickItems[0]) === null || _a === void 0 ? void 0 : _a[1]) || 0) + labelsMargin + boundsOffsetTop,
189
189
  };
@@ -1,23 +1,24 @@
1
1
  import type { AxisDomain, AxisScale, ScaleBand } from 'd3';
2
- import type { PreparedAxis, PreparedAxisPlotBand, PreparedSplit } from '../../hooks';
2
+ import type { ChartScale, PreparedAxis, PreparedAxisPlotBand, PreparedSplit } from '../../hooks';
3
3
  import type { TextRow } from './text';
4
4
  import type { AxisDirection } from './types';
5
+ type Ticks = number[] | string[] | Date[];
5
6
  export declare function getTicksCount({ axis, range }: {
6
7
  axis: PreparedAxis;
7
8
  range: number;
8
9
  }): number | undefined;
9
- export declare function isBandScale(scale: AxisScale<AxisDomain>): scale is ScaleBand<AxisDomain>;
10
- export declare function getScaleTicks(scale: AxisScale<AxisDomain>, ticksCount?: number): any;
10
+ export declare function isBandScale(scale: ChartScale | AxisScale<AxisDomain>): scale is ScaleBand<string>;
11
+ export declare function getScaleTicks(scale: ChartScale | AxisScale<AxisDomain>, ticksCount?: number): Ticks;
11
12
  export declare function getXAxisOffset(): 0 | 0.5;
12
13
  export declare function getXTickPosition({ scale, offset }: {
13
14
  scale: AxisScale<AxisDomain>;
14
15
  offset: number;
15
- }): (d: AxisDomain) => number;
16
- export declare function getXAxisItems({ scale, count, maxCount, }: {
17
- scale: AxisScale<AxisDomain>;
16
+ }): (d: unknown) => number;
17
+ export declare function getAxisItems({ scale, count, maxCount, }: {
18
+ scale: ChartScale | AxisScale<AxisDomain>;
18
19
  count?: number;
19
20
  maxCount?: number;
20
- }): any;
21
+ }): Ticks;
21
22
  export declare function getMaxTickCount({ axis, width }: {
22
23
  axis: PreparedAxis;
23
24
  width: number;
@@ -35,9 +36,14 @@ interface GetBandsPositionArgs {
35
36
  axisScale: AxisScale<AxisDomain>;
36
37
  axis: AxisDirection;
37
38
  }
38
- export declare const getAxisPlotsPosition: (axis: PreparedAxis, split: PreparedSplit, width?: number) => string;
39
+ export declare const getAxisPlotsPosition: (axis: PreparedAxis, split: PreparedSplit, width?: number) => number[];
39
40
  export declare function getBandsPosition(args: GetBandsPositionArgs): {
40
41
  from: number;
41
42
  to: number;
42
43
  };
44
+ export declare function getClosestPointsRange(axis: PreparedAxis, points: AxisDomain[]): number | undefined;
45
+ export declare function getLabelFormatter({ axis, scale }: {
46
+ axis: PreparedAxis;
47
+ scale: ChartScale;
48
+ }): (value: AxisDomain) => string;
43
49
  export {};
@@ -1,4 +1,5 @@
1
1
  import clamp from 'lodash/clamp';
2
+ import { formatAxisTickLabel } from './format';
2
3
  import { wrapText } from './text';
3
4
  export function getTicksCount({ axis, range }) {
4
5
  let ticksCount;
@@ -11,9 +12,13 @@ export function isBandScale(scale) {
11
12
  return 'bandwidth' in scale && typeof scale.bandwidth === 'function';
12
13
  }
13
14
  export function getScaleTicks(scale, ticksCount) {
14
- return 'ticks' in scale && typeof scale.ticks === 'function'
15
- ? scale.ticks(ticksCount)
16
- : scale.domain();
15
+ if ('ticks' in scale && typeof scale.ticks === 'function') {
16
+ return scale.ticks(ticksCount);
17
+ }
18
+ if (isBandScale(scale)) {
19
+ return scale.domain();
20
+ }
21
+ return [];
17
22
  }
18
23
  export function getXAxisOffset() {
19
24
  return typeof window !== 'undefined' && window.devicePixelRatio > 1 ? 0 : 0.5;
@@ -26,12 +31,12 @@ function center(scale, offset) {
26
31
  if (scale.round()) {
27
32
  offset = Math.round(offset);
28
33
  }
29
- return (d) => Number(scale(d)) + offset;
34
+ return (d) => Number(scale(String(d))) + offset;
30
35
  }
31
36
  export function getXTickPosition({ scale, offset }) {
32
- return isBandScale(scale) ? center(scale.copy(), offset) : number(scale.copy());
37
+ return isBandScale(scale) ? center(scale, offset) : number(scale);
33
38
  }
34
- export function getXAxisItems({ scale, count, maxCount, }) {
39
+ export function getAxisItems({ scale, count, maxCount, }) {
35
40
  let values = getScaleTicks(scale, count);
36
41
  if (maxCount && values.length > maxCount) {
37
42
  const step = Math.ceil(values.length / maxCount);
@@ -40,7 +45,7 @@ export function getXAxisItems({ scale, count, maxCount, }) {
40
45
  return values;
41
46
  }
42
47
  export function getMaxTickCount({ axis, width }) {
43
- const minTickWidth = parseInt(axis.labels.style.fontSize) + axis.labels.padding;
48
+ const minTickWidth = parseInt(axis.labels.style.fontSize, 10) + axis.labels.padding;
44
49
  return Math.floor(width / minTickWidth);
45
50
  }
46
51
  export function getAxisHeight(args) {
@@ -74,9 +79,9 @@ export const getAxisPlotsPosition = (axis, split, width = 0) => {
74
79
  var _a;
75
80
  const top = ((_a = split.plots[axis.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
76
81
  if (axis.position === 'left') {
77
- return `translate(0, ${top}px)`;
82
+ return [0, top];
78
83
  }
79
- return `translate(${width}px, ${top}px)`;
84
+ return [width, top];
80
85
  };
81
86
  export function getBandsPosition(args) {
82
87
  var _a, _b, _c;
@@ -112,3 +117,23 @@ export function getBandsPosition(args) {
112
117
  to: clamp(to, -halfBandwidth, maxPos),
113
118
  };
114
119
  }
120
+ export function getClosestPointsRange(axis, points) {
121
+ if (axis.type === 'category') {
122
+ return undefined;
123
+ }
124
+ return Math.abs(points[1] - points[0]);
125
+ }
126
+ export function getLabelFormatter({ axis, scale }) {
127
+ const ticks = getScaleTicks(scale);
128
+ const tickStep = getClosestPointsRange(axis, ticks);
129
+ return (value) => {
130
+ if (!axis.labels.enabled) {
131
+ return '';
132
+ }
133
+ return formatAxisTickLabel({
134
+ axis,
135
+ value,
136
+ step: tickStep,
137
+ });
138
+ };
139
+ }
@@ -1,5 +1,12 @@
1
- import type { ValueFormat } from '../../types';
1
+ import type { AxisDomain } from 'd3';
2
+ import type { PreparedAxis } from '../../hooks';
3
+ import type { CustomFormat, ValueFormat } from '../../types';
2
4
  export declare function getFormattedValue(args: {
3
5
  value: string | number | undefined | null;
4
- format?: ValueFormat;
6
+ format?: ValueFormat | CustomFormat;
7
+ }): string;
8
+ export declare function formatAxisTickLabel(args: {
9
+ axis: PreparedAxis;
10
+ value: AxisDomain;
11
+ step?: number;
5
12
  }): string;
@@ -1,17 +1,52 @@
1
1
  import { dateTime } from '@gravity-ui/date-utils';
2
- import { formatNumber } from '../../libs';
2
+ import capitalize from 'lodash/capitalize';
3
+ import { DEFAULT_DATE_FORMAT } from '../../constants';
4
+ import { formatNumber, getDefaultUnit } from '../../libs';
5
+ import { getDefaultDateFormat } from './time';
6
+ const LETTER_MOUNTH_AT_START_FORMAT_REGEXP = /^M{3,}/;
7
+ function getFormattedDate(args) {
8
+ const { value, format = DEFAULT_DATE_FORMAT } = args;
9
+ const date = dateTime({ input: value });
10
+ if (date === null || date === void 0 ? void 0 : date.isValid()) {
11
+ const formattedDate = date.format(format);
12
+ if (LETTER_MOUNTH_AT_START_FORMAT_REGEXP.test(format)) {
13
+ return capitalize(formattedDate);
14
+ }
15
+ return formattedDate;
16
+ }
17
+ return String(value);
18
+ }
3
19
  export function getFormattedValue(args) {
20
+ var _a;
4
21
  const { value, format } = args;
5
22
  switch (format === null || format === void 0 ? void 0 : format.type) {
6
23
  case 'number': {
7
24
  return formatNumber(Number(value), format);
8
25
  }
9
26
  case 'date': {
10
- const date = dateTime({ input: value });
11
- if (date === null || date === void 0 ? void 0 : date.isValid()) {
12
- return date.format(format.format);
13
- }
27
+ return getFormattedDate({ value, format: format.format });
28
+ }
29
+ case 'custom': {
30
+ return (_a = format.formatter) === null || _a === void 0 ? void 0 : _a.call(format, { value });
14
31
  }
15
32
  }
16
33
  return String(value);
17
34
  }
35
+ export function formatAxisTickLabel(args) {
36
+ const { axis, value, step } = args;
37
+ switch (axis.type) {
38
+ case 'category': {
39
+ return value;
40
+ }
41
+ case 'datetime': {
42
+ const date = value;
43
+ const format = axis.labels.dateFormat || getDefaultDateFormat(step);
44
+ return getFormattedDate({ value: date, format });
45
+ }
46
+ case 'linear':
47
+ default: {
48
+ const numberFormat = Object.assign({ unit: value && step ? getDefaultUnit(step) : undefined }, axis.labels.numberFormat);
49
+ return formatNumber(value, numberFormat);
50
+ }
51
+ }
52
+ }
@@ -1,16 +1,15 @@
1
- import type { AxisDomain } from 'd3';
2
- import type { PreparedAxis } from '../../hooks';
3
1
  import type { BaseTextStyle, ChartSeries, ChartSeriesData } from '../../types';
4
2
  import type { AxisDirection } from './types';
5
- export * from './math';
6
- export * from './text';
7
- export * from './time';
8
3
  export * from './axis';
4
+ export * from './color';
5
+ export * from './format';
9
6
  export * from './labels';
10
7
  export * from './legend';
11
- export * from './symbol';
8
+ export * from './math';
12
9
  export * from './series';
13
- export * from './color';
10
+ export * from './symbol';
11
+ export * from './text';
12
+ export * from './time';
14
13
  export * from './zoom';
15
14
  export declare const CHART_SERIES_WITH_VOLUME_ON_Y_AXIS: ChartSeries['type'][];
16
15
  export declare const CHART_SERIES_WITH_VOLUME_ON_X_AXIS: ChartSeries['type'][];
@@ -52,15 +51,6 @@ export declare const getSeriesNames: (series: ChartSeries[]) => string[];
52
51
  export declare const getOnlyVisibleSeries: <T extends {
53
52
  visible: boolean;
54
53
  }>(series: T[]) => T[];
55
- export declare const parseTransformStyle: (style: string | null) => {
56
- x?: number;
57
- y?: number;
58
- };
59
- export declare const formatAxisTickLabel: (args: {
60
- axis: PreparedAxis;
61
- value: AxisDomain;
62
- step?: number;
63
- }) => string;
64
54
  export declare const getHorizontalHtmlTextHeight: (args: {
65
55
  text: string;
66
56
  style?: Partial<BaseTextStyle>;
@@ -74,5 +64,4 @@ export declare const getDataCategoryValue: (args: {
74
64
  categories: string[];
75
65
  data: ChartSeriesData;
76
66
  }) => string;
77
- export declare function getClosestPointsRange(axis: PreparedAxis, points: AxisDomain[]): number | undefined;
78
67
  export { AxisDirection };
@@ -1,22 +1,20 @@
1
- import { dateTime } from '@gravity-ui/date-utils';
2
1
  import { group, select } from 'd3';
3
2
  import get from 'lodash/get';
4
3
  import isNil from 'lodash/isNil';
5
4
  import sortBy from 'lodash/sortBy';
6
5
  import { DEFAULT_AXIS_LABEL_FONT_SIZE } from '../../constants';
7
6
  import { getSeriesStackId } from '../../hooks/useSeries/utils';
8
- import { formatNumber, getDefaultUnit } from '../../libs/format-number';
9
7
  import { getWaterfallPointSubtotal } from './series/waterfall';
10
- import { getDefaultDateFormat } from './time';
11
- export * from './math';
12
- export * from './text';
13
- export * from './time';
14
8
  export * from './axis';
9
+ export * from './color';
10
+ export * from './format';
15
11
  export * from './labels';
16
12
  export * from './legend';
17
- export * from './symbol';
13
+ export * from './math';
18
14
  export * from './series';
19
- export * from './color';
15
+ export * from './symbol';
16
+ export * from './text';
17
+ export * from './time';
20
18
  export * from './zoom';
21
19
  const CHARTS_WITHOUT_AXIS = ['pie', 'treemap', 'sankey', 'radar'];
22
20
  export const CHART_SERIES_WITH_VOLUME_ON_Y_AXIS = [
@@ -166,35 +164,6 @@ export const getSeriesNames = (series) => {
166
164
  export const getOnlyVisibleSeries = (series) => {
167
165
  return series.filter((s) => s.visible);
168
166
  };
169
- export const parseTransformStyle = (style) => {
170
- var _a;
171
- if (!style) {
172
- return {};
173
- }
174
- const stringifiedValue = ((_a = style.match(/\((.*?)\)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
175
- const [xString, yString] = stringifiedValue.split(',');
176
- const x = Number.isNaN(Number(xString)) ? undefined : Number(xString);
177
- const y = Number.isNaN(Number(yString)) ? undefined : Number(yString);
178
- return { x, y };
179
- };
180
- export const formatAxisTickLabel = (args) => {
181
- const { axis, value, step } = args;
182
- switch (axis.type) {
183
- case 'category': {
184
- return value;
185
- }
186
- case 'datetime': {
187
- const date = value;
188
- const format = axis.labels.dateFormat || getDefaultDateFormat(step);
189
- return dateTime({ input: date }).format(format);
190
- }
191
- case 'linear':
192
- default: {
193
- const numberFormat = Object.assign({ unit: value && step ? getDefaultUnit(step) : undefined }, axis.labels.numberFormat);
194
- return formatNumber(value, numberFormat);
195
- }
196
- }
197
- };
198
167
  export const getHorizontalHtmlTextHeight = (args) => {
199
168
  var _a;
200
169
  const { text, style } = args;
@@ -248,9 +217,3 @@ export const getDataCategoryValue = (args) => {
248
217
  const categoryValue = extractCategoryValue({ axisDirection, categories, data });
249
218
  return categoryValue;
250
219
  };
251
- export function getClosestPointsRange(axis, points) {
252
- if (axis.type === 'category') {
253
- return undefined;
254
- }
255
- return Math.abs(points[1] - points[0]);
256
- }
@@ -26,9 +26,10 @@ export declare function wrapText(args: {
26
26
  text: string;
27
27
  style?: BaseTextStyle;
28
28
  width: number;
29
+ getTextSize?: ReturnType<typeof getTextSizeFn>;
29
30
  }): Promise<TextRow[]>;
30
31
  export declare function getTextSizeFn({ style }: {
31
- style: BaseTextStyle;
32
+ style?: BaseTextStyle;
32
33
  }): (str: string) => Promise<{
33
34
  width: number;
34
35
  height: number;
@@ -144,11 +144,8 @@ export async function getLabelsSize({ labels, style, rotation, html, }) {
144
144
  return result;
145
145
  }
146
146
  export async function wrapText(args) {
147
- const { text, style, width } = args;
148
- const height = (await getLabelsSize({
149
- labels: [text],
150
- style: style,
151
- })).maxHeight;
147
+ const { text, style, width, getTextSize = getTextSizeFn({ style }) } = args;
148
+ const height = (await getTextSize(text)).height;
152
149
  // @ts-ignore
153
150
  const segmenter = new Intl.Segmenter([], { granularity: 'word' });
154
151
  const segments = Array.from(segmenter.segment(text));
@@ -163,11 +160,7 @@ export async function wrapText(args) {
163
160
  });
164
161
  }
165
162
  let lastRow = acc[acc.length - 1];
166
- if (item.isWordLike &&
167
- (await getLabelsSize({
168
- labels: [lastRow.text + item.segment],
169
- style,
170
- })).maxWidth > width) {
163
+ if (item.isWordLike && (await getTextSize(lastRow.text + item.segment)).width > width) {
171
164
  lastRow = {
172
165
  text: '',
173
166
  y: acc.length * height,
@@ -11,3 +11,4 @@ export declare function isMacintosh(): boolean;
11
11
  export declare function measurePerformance(): {
12
12
  end(): number;
13
13
  };
14
+ export declare function hasVerticalScrollbar(node: HTMLElement | null): boolean;
@@ -26,3 +26,9 @@ export function measurePerformance() {
26
26
  },
27
27
  };
28
28
  }
29
+ export function hasVerticalScrollbar(node) {
30
+ if (!node) {
31
+ return false;
32
+ }
33
+ return node.scrollHeight > node.clientHeight;
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "description": "React component used to render charts",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",