@gravity-ui/charts 1.43.0 → 1.44.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 (125) hide show
  1. package/dist/cjs/components/ChartInner/index.js +3 -3
  2. package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +3 -3
  3. package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +10 -12
  4. package/dist/cjs/components/ChartInner/useChartInnerProps.js +8 -4
  5. package/dist/cjs/components/ChartInner/utils/title.d.ts +3 -2
  6. package/dist/cjs/components/ChartInner/utils/title.js +19 -14
  7. package/dist/cjs/components/ChartInner/utils/zoom.js +3 -1
  8. package/dist/cjs/components/Title/index.d.ts +1 -3
  9. package/dist/cjs/components/Title/index.js +2 -2
  10. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +31 -6
  11. package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.js +4 -5
  12. package/dist/cjs/core/constants/chart-types.d.ts +1 -0
  13. package/dist/cjs/core/constants/chart-types.js +1 -0
  14. package/dist/cjs/core/constants/defaults/series-options.d.ts +5 -1
  15. package/dist/cjs/core/constants/defaults/series-options.js +13 -0
  16. package/dist/cjs/core/constants/index.d.ts +0 -1
  17. package/dist/cjs/core/constants/index.js +0 -1
  18. package/dist/cjs/core/i18n/keysets/en.json +2 -1
  19. package/dist/cjs/core/i18n/keysets/ru.json +2 -1
  20. package/dist/cjs/core/series/prepare-legend.js +2 -2
  21. package/dist/cjs/core/series/prepare-x-range.d.ts +11 -0
  22. package/dist/cjs/core/series/prepare-x-range.js +41 -0
  23. package/dist/cjs/core/series/prepareSeries.js +9 -0
  24. package/dist/cjs/core/series/types.d.ts +18 -2
  25. package/dist/cjs/core/types/chart/area.d.ts +2 -1
  26. package/dist/cjs/core/types/chart/series.d.ts +29 -2
  27. package/dist/cjs/core/types/chart/tooltip.d.ts +6 -1
  28. package/dist/cjs/core/types/chart/x-range.d.ts +59 -0
  29. package/dist/cjs/core/types/chart/x-range.js +1 -0
  30. package/dist/cjs/core/types/chart/zoom.d.ts +1 -1
  31. package/dist/cjs/core/types/index.d.ts +1 -0
  32. package/dist/cjs/core/types/index.js +1 -0
  33. package/dist/cjs/core/utils/axis/x-axis.js +9 -1
  34. package/dist/cjs/core/utils/color.js +6 -0
  35. package/dist/cjs/core/utils/common.js +10 -0
  36. package/dist/cjs/core/utils/get-closest-data.js +19 -0
  37. package/dist/cjs/core/utils/labels.d.ts +1 -1
  38. package/dist/cjs/core/utils/labels.js +3 -2
  39. package/dist/cjs/core/validation/index.js +13 -0
  40. package/dist/cjs/core/zoom/zoom.js +24 -7
  41. package/dist/cjs/hooks/useSeries/index.js +8 -2
  42. package/dist/cjs/hooks/useShapes/area/index.js +2 -2
  43. package/dist/cjs/hooks/useShapes/area/prepare-data.js +19 -18
  44. package/dist/cjs/hooks/useShapes/area/types.d.ts +2 -2
  45. package/dist/cjs/hooks/useShapes/bar-x/index.js +2 -2
  46. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +37 -21
  47. package/dist/cjs/hooks/useShapes/bar-x/types.d.ts +2 -2
  48. package/dist/cjs/hooks/useShapes/index.d.ts +2 -1
  49. package/dist/cjs/hooks/useShapes/index.js +35 -5
  50. package/dist/cjs/hooks/useShapes/line/index.js +7 -16
  51. package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +2 -0
  52. package/dist/cjs/hooks/useShapes/line/prepare-data.js +11 -7
  53. package/dist/cjs/hooks/useShapes/line/types.d.ts +2 -2
  54. package/dist/cjs/hooks/useShapes/x-range/index.d.ts +14 -0
  55. package/dist/cjs/hooks/useShapes/x-range/index.js +115 -0
  56. package/dist/cjs/hooks/useShapes/x-range/prepare-data.d.ts +15 -0
  57. package/dist/cjs/hooks/useShapes/x-range/prepare-data.js +147 -0
  58. package/dist/cjs/hooks/useShapes/x-range/types.d.ts +12 -0
  59. package/dist/cjs/hooks/useShapes/x-range/types.js +1 -0
  60. package/dist/cjs/types/chart-ui.d.ts +4 -0
  61. package/dist/esm/components/ChartInner/index.js +3 -3
  62. package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +3 -3
  63. package/dist/esm/components/ChartInner/useChartInnerHandlers.js +10 -12
  64. package/dist/esm/components/ChartInner/useChartInnerProps.js +8 -4
  65. package/dist/esm/components/ChartInner/utils/title.d.ts +3 -2
  66. package/dist/esm/components/ChartInner/utils/title.js +19 -14
  67. package/dist/esm/components/ChartInner/utils/zoom.js +3 -1
  68. package/dist/esm/components/Title/index.d.ts +1 -3
  69. package/dist/esm/components/Title/index.js +2 -2
  70. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +31 -6
  71. package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.js +4 -5
  72. package/dist/esm/core/constants/chart-types.d.ts +1 -0
  73. package/dist/esm/core/constants/chart-types.js +1 -0
  74. package/dist/esm/core/constants/defaults/series-options.d.ts +5 -1
  75. package/dist/esm/core/constants/defaults/series-options.js +13 -0
  76. package/dist/esm/core/constants/index.d.ts +0 -1
  77. package/dist/esm/core/constants/index.js +0 -1
  78. package/dist/esm/core/i18n/keysets/en.json +2 -1
  79. package/dist/esm/core/i18n/keysets/ru.json +2 -1
  80. package/dist/esm/core/series/prepare-legend.js +2 -2
  81. package/dist/esm/core/series/prepare-x-range.d.ts +11 -0
  82. package/dist/esm/core/series/prepare-x-range.js +41 -0
  83. package/dist/esm/core/series/prepareSeries.js +9 -0
  84. package/dist/esm/core/series/types.d.ts +18 -2
  85. package/dist/esm/core/types/chart/area.d.ts +2 -1
  86. package/dist/esm/core/types/chart/series.d.ts +29 -2
  87. package/dist/esm/core/types/chart/tooltip.d.ts +6 -1
  88. package/dist/esm/core/types/chart/x-range.d.ts +59 -0
  89. package/dist/esm/core/types/chart/x-range.js +1 -0
  90. package/dist/esm/core/types/chart/zoom.d.ts +1 -1
  91. package/dist/esm/core/types/index.d.ts +1 -0
  92. package/dist/esm/core/types/index.js +1 -0
  93. package/dist/esm/core/utils/axis/x-axis.js +9 -1
  94. package/dist/esm/core/utils/color.js +6 -0
  95. package/dist/esm/core/utils/common.js +10 -0
  96. package/dist/esm/core/utils/get-closest-data.js +19 -0
  97. package/dist/esm/core/utils/labels.d.ts +1 -1
  98. package/dist/esm/core/utils/labels.js +3 -2
  99. package/dist/esm/core/validation/index.js +13 -0
  100. package/dist/esm/core/zoom/zoom.js +24 -7
  101. package/dist/esm/hooks/useSeries/index.js +8 -2
  102. package/dist/esm/hooks/useShapes/area/index.js +2 -2
  103. package/dist/esm/hooks/useShapes/area/prepare-data.js +19 -18
  104. package/dist/esm/hooks/useShapes/area/types.d.ts +2 -2
  105. package/dist/esm/hooks/useShapes/bar-x/index.js +2 -2
  106. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +37 -21
  107. package/dist/esm/hooks/useShapes/bar-x/types.d.ts +2 -2
  108. package/dist/esm/hooks/useShapes/index.d.ts +2 -1
  109. package/dist/esm/hooks/useShapes/index.js +35 -5
  110. package/dist/esm/hooks/useShapes/line/index.js +7 -16
  111. package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +2 -0
  112. package/dist/esm/hooks/useShapes/line/prepare-data.js +11 -7
  113. package/dist/esm/hooks/useShapes/line/types.d.ts +2 -2
  114. package/dist/esm/hooks/useShapes/x-range/index.d.ts +14 -0
  115. package/dist/esm/hooks/useShapes/x-range/index.js +115 -0
  116. package/dist/esm/hooks/useShapes/x-range/prepare-data.d.ts +15 -0
  117. package/dist/esm/hooks/useShapes/x-range/prepare-data.js +147 -0
  118. package/dist/esm/hooks/useShapes/x-range/types.d.ts +12 -0
  119. package/dist/esm/hooks/useShapes/x-range/types.js +1 -0
  120. package/dist/esm/types/chart-ui.d.ts +4 -0
  121. package/package.json +1 -1
  122. package/dist/cjs/core/constants/misc.d.ts +0 -1
  123. package/dist/cjs/core/constants/misc.js +0 -7
  124. package/dist/esm/core/constants/misc.d.ts +0 -1
  125. package/dist/esm/core/constants/misc.js +0 -7
@@ -48,15 +48,19 @@ export function useChartInnerProps(props) {
48
48
  currentRunRef.current++;
49
49
  const currentRun = currentRunRef.current;
50
50
  (async function () {
51
- var _a, _b, _c;
51
+ var _a, _b, _c, _d;
52
52
  const chartDataChanged = !(previousChartData.current && isEqual(previousChartData.current, data));
53
- const preparedTitle = await getPreparedTitle({ title: data.title, chartWidth: width });
53
+ const preparedTitle = await getPreparedTitle({
54
+ title: data.title,
55
+ chartWidth: width,
56
+ chartMargin: (_a = data.chart) === null || _a === void 0 ? void 0 : _a.margin,
57
+ });
54
58
  const preparedChart = getPreparedChart({
55
59
  chart: data.chart,
56
60
  seriesData: data.series.data,
57
61
  preparedTitle,
58
62
  });
59
- const colors = (_a = data.colors) !== null && _a !== void 0 ? _a : DEFAULT_PALETTE;
63
+ const colors = (_b = data.colors) !== null && _b !== void 0 ? _b : DEFAULT_PALETTE;
60
64
  const normalizedSeriesData = getSortedSeriesData({
61
65
  seriesData: data.series.data,
62
66
  xAxis: data.xAxis,
@@ -79,7 +83,7 @@ export function useChartInnerProps(props) {
79
83
  });
80
84
  }
81
85
  else {
82
- allPreparedSeries = (_c = (_b = prevStateValue.current) === null || _b === void 0 ? void 0 : _b.allPreparedSeries) !== null && _c !== void 0 ? _c : [];
86
+ allPreparedSeries = (_d = (_c = prevStateValue.current) === null || _c === void 0 ? void 0 : _c.allPreparedSeries) !== null && _d !== void 0 ? _d : [];
83
87
  }
84
88
  const activeLegendItems = selectedLegendItems !== null && selectedLegendItems !== void 0 ? selectedLegendItems : getActiveLegendItems(allPreparedSeries);
85
89
  const visiblePreparedSeries = getVisibleSeries({
@@ -1,6 +1,7 @@
1
1
  import type { PreparedTitle } from '../../../hooks/types';
2
- import type { ChartData } from '../../../types';
3
- export declare const getPreparedTitle: ({ title, chartWidth, }: {
2
+ import type { ChartData, ChartMargin } from '../../../types';
3
+ export declare const getPreparedTitle: ({ title, chartWidth, chartMargin, }: {
4
4
  title: ChartData["title"];
5
5
  chartWidth: number;
6
+ chartMargin?: Partial<ChartMargin>;
6
7
  }) => Promise<PreparedTitle | undefined>;
@@ -2,25 +2,30 @@ import get from 'lodash/get';
2
2
  import { getTextSizeFn, getTextWithElipsis, wrapText } from '../../../core/utils';
3
3
  const DEFAULT_TITLE_FONT_SIZE = '15px';
4
4
  const DEFAULT_TITLE_MARGIN = 10;
5
- export const getPreparedTitle = async ({ title, chartWidth, }) => {
6
- var _a, _b, _c, _d, _e, _f, _g, _h;
5
+ export const getPreparedTitle = async ({ title, chartWidth, chartMargin, }) => {
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
7
+ const chartMarginTop = (_a = chartMargin === null || chartMargin === void 0 ? void 0 : chartMargin.top) !== null && _a !== void 0 ? _a : 0;
8
+ const chartMarginLeft = (_b = chartMargin === null || chartMargin === void 0 ? void 0 : chartMargin.left) !== null && _b !== void 0 ? _b : 0;
9
+ const chartMarginRight = (_c = chartMargin === null || chartMargin === void 0 ? void 0 : chartMargin.right) !== null && _c !== void 0 ? _c : 0;
7
10
  const titleText = get(title, 'text');
8
11
  const titleStyle = {
9
- fontSize: (_b = (_a = title === null || title === void 0 ? void 0 : title.style) === null || _a === void 0 ? void 0 : _a.fontSize) !== null && _b !== void 0 ? _b : DEFAULT_TITLE_FONT_SIZE,
10
- fontWeight: (_d = (_c = title === null || title === void 0 ? void 0 : title.style) === null || _c === void 0 ? void 0 : _c.fontWeight) !== null && _d !== void 0 ? _d : 'var(--g-text-subheader-font-weight)',
11
- fontColor: (_f = (_e = title === null || title === void 0 ? void 0 : title.style) === null || _e === void 0 ? void 0 : _e.fontColor) !== null && _f !== void 0 ? _f : 'var(--g-color-text-primary)',
12
+ fontSize: (_e = (_d = title === null || title === void 0 ? void 0 : title.style) === null || _d === void 0 ? void 0 : _d.fontSize) !== null && _e !== void 0 ? _e : DEFAULT_TITLE_FONT_SIZE,
13
+ fontWeight: (_g = (_f = title === null || title === void 0 ? void 0 : title.style) === null || _f === void 0 ? void 0 : _f.fontWeight) !== null && _g !== void 0 ? _g : 'var(--g-text-subheader-font-weight)',
14
+ fontColor: (_j = (_h = title === null || title === void 0 ? void 0 : title.style) === null || _h === void 0 ? void 0 : _h.fontColor) !== null && _j !== void 0 ? _j : 'var(--g-color-text-primary)',
12
15
  };
13
16
  if (!titleText) {
14
17
  return undefined;
15
18
  }
16
19
  const getTitleTextSize = getTextSizeFn({ style: titleStyle });
17
- const maxRowCount = (_g = title === null || title === void 0 ? void 0 : title.maxRowCount) !== null && _g !== void 0 ? _g : 1;
20
+ const maxRowCount = (_k = title === null || title === void 0 ? void 0 : title.maxRowCount) !== null && _k !== void 0 ? _k : 1;
18
21
  const contentRows = [];
22
+ const usableWidth = chartWidth - chartMarginLeft - chartMarginRight;
23
+ const xCenter = chartMarginLeft + usableWidth / 2;
19
24
  if (maxRowCount > 1) {
20
25
  let titleTextRows = await wrapText({
21
26
  text: titleText,
22
27
  style: titleStyle,
23
- width: chartWidth,
28
+ width: usableWidth,
24
29
  getTextSize: getTitleTextSize,
25
30
  });
26
31
  titleTextRows = titleTextRows.reduce((acc, row, index) => {
@@ -38,15 +43,15 @@ export const getPreparedTitle = async ({ title, chartWidth, }) => {
38
43
  if (i === titleTextRows.length - 1) {
39
44
  textRowContent = await getTextWithElipsis({
40
45
  text: textRowContent,
41
- maxWidth: chartWidth,
46
+ maxWidth: usableWidth,
42
47
  getTextWidth: async (s) => (await getTitleTextSize(s)).width,
43
48
  });
44
49
  }
45
50
  const textRowSize = await getTitleTextSize(textRowContent);
46
51
  contentRows.push({
47
52
  text: textRowContent,
48
- x: 0,
49
- y: textRow.y + textRowSize.hangingOffset,
53
+ x: xCenter,
54
+ y: textRow.y + textRowSize.hangingOffset + chartMarginTop,
50
55
  size: textRowSize,
51
56
  });
52
57
  }
@@ -54,14 +59,14 @@ export const getPreparedTitle = async ({ title, chartWidth, }) => {
54
59
  else {
55
60
  const truncatedText = await getTextWithElipsis({
56
61
  text: titleText,
57
- maxWidth: chartWidth,
62
+ maxWidth: usableWidth,
58
63
  getTextWidth: async (s) => (await getTitleTextSize(s)).width,
59
64
  });
60
65
  const textSize = await getTitleTextSize(truncatedText);
61
66
  contentRows.push({
62
67
  text: truncatedText,
63
- x: 0,
64
- y: textSize.hangingOffset,
68
+ x: xCenter,
69
+ y: textSize.hangingOffset + chartMarginTop,
65
70
  size: textSize,
66
71
  });
67
72
  }
@@ -71,7 +76,7 @@ export const getPreparedTitle = async ({ title, chartWidth, }) => {
71
76
  text: titleText,
72
77
  style: titleStyle,
73
78
  height: titleHeight,
74
- margin: (_h = title === null || title === void 0 ? void 0 : title.margin) !== null && _h !== void 0 ? _h : DEFAULT_TITLE_MARGIN,
79
+ margin: (_l = title === null || title === void 0 ? void 0 : title.margin) !== null && _l !== void 0 ? _l : DEFAULT_TITLE_MARGIN,
75
80
  qa: title === null || title === void 0 ? void 0 : title.qa,
76
81
  contentRows,
77
82
  };
@@ -6,7 +6,8 @@ function mapSeriesTypeToZoomType(seriesType) {
6
6
  case SERIES_TYPE.Area: {
7
7
  return [ZOOM_TYPE.X, ZOOM_TYPE.XY, ZOOM_TYPE.Y];
8
8
  }
9
- case SERIES_TYPE.BarX: {
9
+ case SERIES_TYPE.BarX:
10
+ case SERIES_TYPE.XRange: {
10
11
  return [ZOOM_TYPE.X];
11
12
  }
12
13
  case SERIES_TYPE.BarY: {
@@ -36,6 +37,7 @@ function getDefaultZoomType(seriesType) {
36
37
  }
37
38
  case SERIES_TYPE.Area:
38
39
  case SERIES_TYPE.BarX:
40
+ case SERIES_TYPE.XRange:
39
41
  case SERIES_TYPE.Line:
40
42
  case SERIES_TYPE.Waterfall: {
41
43
  return ZOOM_TYPE.X;
@@ -1,7 +1,5 @@
1
1
  import React from 'react';
2
2
  import type { PreparedTitle } from '../../hooks';
3
- type Props = PreparedTitle & {
4
- chartWidth: number;
5
- };
3
+ type Props = PreparedTitle;
6
4
  export declare const Title: (props: Props) => React.JSX.Element;
7
5
  export {};
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
2
  export const Title = (props) => {
3
- const { chartWidth, style, qa, contentRows } = props;
3
+ const { style, qa, contentRows } = props;
4
4
  return (React.createElement("text", { dominantBaseline: "hanging", textAnchor: "middle", style: {
5
5
  fill: style === null || style === void 0 ? void 0 : style.fontColor,
6
6
  fontSize: style === null || style === void 0 ? void 0 : style.fontSize,
7
7
  fontWeight: style === null || style === void 0 ? void 0 : style.fontWeight,
8
- }, "data-qa": qa }, contentRows.map((row, i) => (React.createElement("tspan", { key: i, x: chartWidth / 2, y: row.y, dominantBaseline: "hanging", dangerouslySetInnerHTML: { __html: row.text } })))));
8
+ }, "data-qa": qa }, contentRows.map((row, i) => (React.createElement("tspan", { key: i, x: row.x, y: row.y, dominantBaseline: "hanging", dangerouslySetInnerHTML: { __html: row.text } })))));
9
9
  };
@@ -43,12 +43,15 @@ export const DefaultTooltipContent = ({ hovered, pinned, rowRenderer, totals, va
43
43
  const colorSymbol = getTooltipRowColorSymbol({ series, color });
44
44
  return (React.createElement(Row, { key: id, active: active, color: color, colorSymbol: colorSymbol ? (React.createElement("div", { dangerouslySetInnerHTML: { __html: colorSymbol.outerHTML } })) : undefined, label: React.createElement("span", { dangerouslySetInnerHTML: { __html: name } }), striped: striped, value: formattedValue }));
45
45
  };
46
- const formattedHeadValue = headerFormat
47
- ? getFormattedValue({
48
- value: measureValue === null || measureValue === void 0 ? void 0 : measureValue.value,
49
- format: headerFormat,
50
- })
51
- : measureValue === null || measureValue === void 0 ? void 0 : measureValue.formattedValue;
46
+ let formattedHeadValue;
47
+ if (measureValue) {
48
+ formattedHeadValue = headerFormat
49
+ ? getFormattedValue({
50
+ value: measureValue.value,
51
+ format: headerFormat,
52
+ })
53
+ : measureValue.formattedValue;
54
+ }
52
55
  React.useEffect(() => {
53
56
  if (!contentRowsRef.current) {
54
57
  return;
@@ -186,6 +189,28 @@ export const DefaultTooltipContent = ({ hovered, pinned, rowRenderer, totals, va
186
189
  formattedValue,
187
190
  });
188
191
  }
192
+ case 'x-range': {
193
+ const xRangeData = data;
194
+ const format = rowValueFormat || getDefaultValueFormat({ axis: xAxis });
195
+ const x0Formatted = getFormattedValue({
196
+ value: xRangeData.x0,
197
+ format,
198
+ });
199
+ const x1Formatted = getFormattedValue({
200
+ value: xRangeData.x1,
201
+ format,
202
+ });
203
+ return renderRow({
204
+ id,
205
+ active,
206
+ color,
207
+ name: series.name,
208
+ striped,
209
+ value: hoveredValues[i],
210
+ formattedValue: `${x0Formatted} — ${x1Formatted}`,
211
+ series,
212
+ });
213
+ }
189
214
  default: {
190
215
  return null;
191
216
  }
@@ -48,7 +48,7 @@ export const getMeasureValue = ({ data, xAxis, yAxis, headerFormat, }) => {
48
48
  const value = (_b = (_a = data[0].category) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : null;
49
49
  return { value };
50
50
  }
51
- if (data.some((item) => item.series.type === 'bar-y')) {
51
+ if (data.some((item) => ['bar-y', 'x-range'].includes(item.series.type))) {
52
52
  const value = getYRowData((_c = data[0]) === null || _c === void 0 ? void 0 : _c.data, yAxis);
53
53
  const formattedValue = getFormattedValue({
54
54
  value: getYRowData((_d = data[0]) === null || _d === void 0 ? void 0 : _d.data, yAxis),
@@ -72,7 +72,9 @@ export function getHoveredValues(args) {
72
72
  case 'area':
73
73
  case 'line':
74
74
  case 'bar-x':
75
- case 'scatter': {
75
+ case 'waterfall':
76
+ case 'scatter':
77
+ case 'x-range': {
76
78
  return getYRowData(data, yAxis);
77
79
  }
78
80
  case 'bar-y': {
@@ -90,9 +92,6 @@ export function getHoveredValues(args) {
90
92
  const { target, data: source } = seriesItem;
91
93
  return (_a = source.links.find((d) => d.name === (target === null || target === void 0 ? void 0 : target.name))) === null || _a === void 0 ? void 0 : _a.value;
92
94
  }
93
- case 'waterfall': {
94
- return getYRowData(data, yAxis);
95
- }
96
95
  default: {
97
96
  return undefined;
98
97
  }
@@ -11,5 +11,6 @@ export declare const SERIES_TYPE: {
11
11
  readonly Radar: "radar";
12
12
  readonly Heatmap: "heatmap";
13
13
  readonly Funnel: "funnel";
14
+ readonly XRange: "x-range";
14
15
  };
15
16
  export type SeriesType = (typeof SERIES_TYPE)[keyof typeof SERIES_TYPE];
@@ -11,4 +11,5 @@ export const SERIES_TYPE = {
11
11
  Radar: 'radar',
12
12
  Heatmap: 'heatmap',
13
13
  Funnel: 'funnel',
14
+ XRange: 'x-range',
14
15
  };
@@ -21,7 +21,11 @@ type DefaultWaterfallSeriesOptions = Partial<ChartSeriesOptions['waterfall']> &
21
21
  barPadding: number;
22
22
  };
23
23
  };
24
- export type SeriesOptionsDefaults = Partial<ChartSeriesOptions> & DefaultBarXSeriesOptions & DefaultBarYSeriesOptions & DefaultWaterfallSeriesOptions;
24
+ export type SeriesOptionsDefaults = Partial<ChartSeriesOptions> & DefaultBarXSeriesOptions & DefaultBarYSeriesOptions & DefaultWaterfallSeriesOptions & {
25
+ 'x-range': {
26
+ borderRadius: number;
27
+ };
28
+ };
25
29
  export declare const seriesOptionsDefaults: SeriesOptionsDefaults;
26
30
  export declare const seriesRangeSliderOptionsDefaults: Required<ChartSeriesRangeSliderOptions>;
27
31
  export {};
@@ -133,6 +133,19 @@ export const seriesOptionsDefaults = {
133
133
  },
134
134
  },
135
135
  },
136
+ 'x-range': {
137
+ borderRadius: 0,
138
+ states: {
139
+ hover: {
140
+ enabled: true,
141
+ brightness: 0.3,
142
+ },
143
+ inactive: {
144
+ enabled: false,
145
+ opacity: 0.5,
146
+ },
147
+ },
148
+ },
136
149
  };
137
150
  export const seriesRangeSliderOptionsDefaults = {
138
151
  visible: true,
@@ -4,7 +4,6 @@ export * from './datetime';
4
4
  export * from './defaults';
5
5
  export * from './layout-algorithms';
6
6
  export * from './line-styles';
7
- export * from './misc';
8
7
  export * from './palette';
9
8
  export * from './symbol-types';
10
9
  export * from './tooltip';
@@ -4,7 +4,6 @@ export * from './datetime';
4
4
  export * from './defaults';
5
5
  export * from './layout-algorithms';
6
6
  export * from './line-styles';
7
- export * from './misc';
8
7
  export * from './palette';
9
8
  export * from './symbol-types';
10
9
  export * from './tooltip';
@@ -21,7 +21,8 @@
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
  "label_duplicate-axis-categories": "It seems you have duplicate value \"{{duplicate}}\" found in {{key}}[{{axisIndex}}].",
23
23
  "label_invalid-axis-categories": "It seems you are trying to use inappropriate value for \"categories\", or defined it incorrectly. Categories must be a non-empty array for an axis with \"category\" type.",
24
- "label_inconsistent-y-axis-configuration": "It seems you have inconsistent Y-axis configuration. Possible reasons:\n1. Multiple Y axes with the same position and plot index.\n2. At the moment, 'category' axis is not supported in dual Y-axis configurations."
24
+ "label_inconsistent-y-axis-configuration": "It seems you have inconsistent Y-axis configuration. Possible reasons:\n1. Multiple Y axes with the same position and plot index.\n2. At the moment, 'category' axis is not supported in dual Y-axis configurations.",
25
+ "label_stacking-area-connect-null-mode": "It seems you are using \"nullMode: 'connect'\" with a stacking area series. The \"connect\" null mode is not supported in stacking mode. Use \"zero\" or \"skip\" instead."
25
26
  },
26
27
  "tooltip": {
27
28
  "label_totals_sum": "Sum",
@@ -21,7 +21,8 @@
21
21
  "label_invalid-axis-labels-html-not-supported-axis-type": "Похоже, что вы пытаетесь использовать свойство \"labels.html\" для оси с неподдерживаемым типом. Это свойство поддерживается только для оси типа \"category\".",
22
22
  "label_duplicate-axis-categories": "Похоже, что у вас есть дублирующееся значение категории \"{{duplicate}}\" в оси {{key}}[{{axisIndex}}].",
23
23
  "label_invalid-axis-categories": "Похоже, что вы пытаетесь использовать недопустимое значение для \"categories\", или указали его неверно. Категории для оси типа \"category\" должны быть непустым массивом.",
24
- "label_inconsistent-y-axis-configuration": "Похоже, что конфигурация осей Y неконсистентна. Возможные причины:\n1. Несколько осей Y имеют одинаковые значения position и plotIndex.\n2. На данный момент категорийные оси не поддерживаются в конфигурациях с двумя осями Y."
24
+ "label_inconsistent-y-axis-configuration": "Похоже, что конфигурация осей Y неконсистентна. Возможные причины:\n1. Несколько осей Y имеют одинаковые значения position и plotIndex.\n2. На данный момент категорийные оси не поддерживаются в конфигурациях с двумя осями Y.",
25
+ "label_stacking-area-connect-null-mode": "Похоже, что вы используете \"nullMode: 'connect'\" с серией area с накоплением. Режим null \"connect\" не поддерживается в режиме накопления. Используйте \"zero\" или \"skip\"."
25
26
  },
26
27
  "tooltip": {
27
28
  "label_totals_sum": "Сумма",
@@ -136,7 +136,7 @@ async function getGroupedLegendItems(args) {
136
136
  else {
137
137
  resultItem.textWidth = textWidth;
138
138
  }
139
- textWidthsInLine.push(textWidth);
139
+ textWidthsInLine.push(resultItem.textWidth);
140
140
  const textsWidth = textWidthsInLine.reduce((acc, width) => acc + width, 0);
141
141
  if (!result[lineIndex]) {
142
142
  result[lineIndex] = [];
@@ -155,7 +155,7 @@ async function getGroupedLegendItems(args) {
155
155
  else if (isCurrentLineOverMaxWidth) {
156
156
  result[lineIndex].pop();
157
157
  lineIndex += 1;
158
- textWidthsInLine = [textWidth];
158
+ textWidthsInLine = [resultItem.textWidth];
159
159
  const nextLineIndex = lineIndex;
160
160
  result[nextLineIndex] = [];
161
161
  result[nextLineIndex].push(resultItem);
@@ -0,0 +1,11 @@
1
+ import type { ScaleOrdinal } from 'd3-scale';
2
+ import type { ChartSeriesOptions, XRangeSeries } from '../../types';
3
+ import type { PreparedLegend, PreparedXRangeSeries } from './types';
4
+ type PrepareXRangeSeriesArgs = {
5
+ colorScale: ScaleOrdinal<string, string>;
6
+ series: XRangeSeries[];
7
+ legend: PreparedLegend;
8
+ seriesOptions?: ChartSeriesOptions;
9
+ };
10
+ export declare function prepareXRangeSeries(args: PrepareXRangeSeriesArgs): PreparedXRangeSeries[];
11
+ export {};
@@ -0,0 +1,41 @@
1
+ import get from 'lodash/get';
2
+ import { getUniqId } from '../utils';
3
+ import { DASH_STYLE, DEFAULT_DATALABELS_STYLE } from '../constants';
4
+ import { DEFAULT_DATALABELS_PADDING } from './constants';
5
+ import { prepareLegendSymbol } from './utils';
6
+ export function prepareXRangeSeries(args) {
7
+ const { colorScale, series: seriesList, seriesOptions, legend } = args;
8
+ return seriesList.map((series) => {
9
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
10
+ const name = series.name || '';
11
+ const color = series.color || colorScale(name);
12
+ return {
13
+ type: series.type,
14
+ color,
15
+ name,
16
+ id: getUniqId(),
17
+ visible: get(series, 'visible', true),
18
+ legend: {
19
+ enabled: get(series, 'legend.enabled', legend.enabled),
20
+ symbol: prepareLegendSymbol(series),
21
+ groupId: (_b = (_a = series.legend) === null || _a === void 0 ? void 0 : _a.groupId) !== null && _b !== void 0 ? _b : getUniqId(),
22
+ itemText: (_d = (_c = series.legend) === null || _c === void 0 ? void 0 : _c.itemText) !== null && _d !== void 0 ? _d : name,
23
+ },
24
+ data: series.data,
25
+ opacity: (_e = series.opacity) !== null && _e !== void 0 ? _e : null,
26
+ borderRadius: (_h = (_f = series.borderRadius) !== null && _f !== void 0 ? _f : (_g = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['x-range']) === null || _g === void 0 ? void 0 : _g.borderRadius) !== null && _h !== void 0 ? _h : 0,
27
+ borderWidth: (_l = (_j = series.borderWidth) !== null && _j !== void 0 ? _j : (_k = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['x-range']) === null || _k === void 0 ? void 0 : _k.borderWidth) !== null && _l !== void 0 ? _l : 0,
28
+ borderColor: (_p = (_m = series.borderColor) !== null && _m !== void 0 ? _m : (_o = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['x-range']) === null || _o === void 0 ? void 0 : _o.borderColor) !== null && _p !== void 0 ? _p : 'var(--gcharts-shape-border-color)',
29
+ borderDashStyle: (_s = (_q = series.borderDashStyle) !== null && _q !== void 0 ? _q : (_r = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['x-range']) === null || _r === void 0 ? void 0 : _r.borderDashStyle) !== null && _s !== void 0 ? _s : DASH_STYLE.Solid,
30
+ cursor: get(series, 'cursor', null),
31
+ tooltip: series.tooltip,
32
+ dataLabels: {
33
+ enabled: get(series, 'dataLabels.enabled', false),
34
+ style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_t = series.dataLabels) === null || _t === void 0 ? void 0 : _t.style),
35
+ html: get(series, 'dataLabels.html', false),
36
+ padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
37
+ format: (_u = series.dataLabels) === null || _u === void 0 ? void 0 : _u.format,
38
+ },
39
+ };
40
+ });
41
+ }
@@ -11,6 +11,7 @@ import { prepareSankeySeries } from './prepare-sankey';
11
11
  import { prepareScatterSeries } from './prepare-scatter';
12
12
  import { prepareTreemap } from './prepare-treemap';
13
13
  import { prepareWaterfallSeries } from './prepare-waterfall';
14
+ import { prepareXRangeSeries } from './prepare-x-range';
14
15
  export async function prepareSeries(args) {
15
16
  const { type, series, seriesOptions, legend, colors, colorScale } = args;
16
17
  switch (type) {
@@ -108,6 +109,14 @@ export async function prepareSeries(args) {
108
109
  colors,
109
110
  });
110
111
  }
112
+ case 'x-range': {
113
+ return prepareXRangeSeries({
114
+ series: series,
115
+ seriesOptions,
116
+ legend,
117
+ colorScale,
118
+ });
119
+ }
111
120
  default: {
112
121
  throw new ChartError({
113
122
  message: `Series type "${type}" does not support data preparation for series that do not support the presence of axes`,
@@ -1,4 +1,4 @@
1
- import type { AreaSeries, AreaSeriesData, BarXSeries, BarXSeriesData, BarYSeries, BarYSeriesData, BaseTextStyle, ChartLegend, ChartSeries, ChartSeriesRangeSliderOptions, ConnectorCurve, ConnectorShape, FunnelSeries, FunnelSeriesData, HeatmapSeries, HeatmapSeriesData, LineSeries, LineSeriesData, LineSeriesLineBaseStyle, PathLegendSymbolOptions, PieSeries, PieSeriesData, RadarSeries, RadarSeriesCategory, RadarSeriesData, RectLegendSymbolOptions, SankeySeries, SankeySeriesData, ScatterSeries, ScatterSeriesData, SymbolLegendSymbolOptions, TreemapSeries, TreemapSeriesData, ValueFormat, WaterfallSeries, WaterfallSeriesData } from '../../types';
1
+ import type { AreaSeries, AreaSeriesData, BarXSeries, BarXSeriesData, BarYSeries, BarYSeriesData, BaseTextStyle, ChartLegend, ChartSeries, ChartSeriesRangeSliderOptions, ConnectorCurve, ConnectorShape, FunnelSeries, FunnelSeriesData, HeatmapSeries, HeatmapSeriesData, LineSeries, LineSeriesData, LineSeriesLineBaseStyle, PathLegendSymbolOptions, PieSeries, PieSeriesData, RadarSeries, RadarSeriesCategory, RadarSeriesData, RectLegendSymbolOptions, SankeySeries, SankeySeriesData, ScatterSeries, ScatterSeriesData, SymbolLegendSymbolOptions, TreemapSeries, TreemapSeriesData, ValueFormat, WaterfallSeries, WaterfallSeriesData, XRangeSeries, XRangeSeriesData } from '../../types';
2
2
  import type { DashStyle, LayoutAlgorithm, LineCap, LineJoin, SeriesOptionsDefaults, SymbolType } from '../constants';
3
3
  export type RectLegendSymbol = {
4
4
  shape: 'rect';
@@ -339,7 +339,23 @@ export type PreparedFunnelSeries = {
339
339
  };
340
340
  connectors: Required<FunnelSeries['connectors']>;
341
341
  } & BasePreparedSeries;
342
- export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries | PreparedAreaSeries | PreparedTreemapSeries | PreparedWaterfallSeries | PreparedSankeySeries | PreparedRadarSeries | PreparedHeatmapSeries | PreparedFunnelSeries;
342
+ export type PreparedXRangeSeries = {
343
+ type: XRangeSeries['type'];
344
+ data: XRangeSeriesData[];
345
+ borderRadius: number;
346
+ borderWidth: number;
347
+ borderColor: string;
348
+ borderDashStyle: DashStyle;
349
+ opacity: number | null;
350
+ dataLabels: {
351
+ enabled: boolean;
352
+ style: BaseTextStyle;
353
+ html: boolean;
354
+ padding: number;
355
+ format?: ValueFormat;
356
+ };
357
+ } & BasePreparedSeries;
358
+ export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries | PreparedAreaSeries | PreparedTreemapSeries | PreparedWaterfallSeries | PreparedSankeySeries | PreparedRadarSeries | PreparedHeatmapSeries | PreparedFunnelSeries | PreparedXRangeSeries;
343
359
  export type PreparedZoomableSeries = Extract<PreparedSeries, {
344
360
  data: Array<unknown>;
345
361
  }>;
@@ -76,9 +76,10 @@ export interface AreaSeries<T = MeaningfulAny> extends BaseSeries {
76
76
  /**
77
77
  * Specifies how null or undefined values should be handled in the series.
78
78
  *
79
- * - `'connect'`: Connect points across null values (skip nulls in rendering)
79
+ * - `'connect'`: Connect points across null values (skip nulls in rendering). **Not supported with `stacking`.**
80
80
  * - `'zero'`: Treat null values as zero
81
81
  * - `'skip'`: Omit the data point (creates gap in area)
82
+ *
82
83
  * @default 'skip'
83
84
  */
84
85
  nullMode?: 'connect' | 'zero' | 'skip';
@@ -15,8 +15,9 @@ import type { SankeySeries, SankeySeriesData } from './sankey';
15
15
  import type { ScatterSeries, ScatterSeriesData } from './scatter';
16
16
  import type { TreemapSeries, TreemapSeriesData } from './treemap';
17
17
  import type { WaterfallSeries, WaterfallSeriesData } from './waterfall';
18
- export type ChartSeries<T = MeaningfulAny> = ScatterSeries<T> | PieSeries<T> | BarXSeries<T> | BarYSeries<T> | LineSeries<T> | AreaSeries<T> | TreemapSeries<T> | WaterfallSeries<T> | SankeySeries<T> | RadarSeries<T> | HeatmapSeries<T> | FunnelSeries<T>;
19
- export type ChartSeriesData<T = MeaningfulAny> = ScatterSeriesData<T> | PieSeriesData<T> | BarXSeriesData<T> | BarYSeriesData<T> | LineSeriesData<T> | AreaSeriesData<T> | TreemapSeriesData<T> | WaterfallSeriesData<T> | SankeySeriesData<T> | RadarSeriesData<T> | HeatmapSeriesData<T> | FunnelSeriesData<T>;
18
+ import type { XRangeSeries, XRangeSeriesData } from './x-range';
19
+ export type ChartSeries<T = MeaningfulAny> = ScatterSeries<T> | PieSeries<T> | BarXSeries<T> | BarYSeries<T> | LineSeries<T> | AreaSeries<T> | TreemapSeries<T> | WaterfallSeries<T> | SankeySeries<T> | RadarSeries<T> | HeatmapSeries<T> | FunnelSeries<T> | XRangeSeries<T>;
20
+ export type ChartSeriesData<T = MeaningfulAny> = ScatterSeriesData<T> | PieSeriesData<T> | BarXSeriesData<T> | BarYSeriesData<T> | LineSeriesData<T> | AreaSeriesData<T> | TreemapSeriesData<T> | WaterfallSeriesData<T> | SankeySeriesData<T> | RadarSeriesData<T> | HeatmapSeriesData<T> | FunnelSeriesData<T> | XRangeSeriesData<T>;
20
21
  export interface DataLabelRendererData<T = MeaningfulAny> {
21
22
  data: ChartSeriesData<T>;
22
23
  }
@@ -291,6 +292,32 @@ export interface ChartSeriesOptions {
291
292
  hover?: BasicHoverState;
292
293
  };
293
294
  };
295
+ 'x-range'?: {
296
+ /**
297
+ * The corner radius of the border surrounding each bar.
298
+ * @default 0
299
+ */
300
+ borderRadius?: number;
301
+ /**
302
+ * The width of the border surrounding each bar.
303
+ * @default 0
304
+ */
305
+ borderWidth?: number;
306
+ /**
307
+ * The color of the border surrounding each bar.
308
+ */
309
+ borderColor?: string;
310
+ /**
311
+ * The dash style of the border surrounding each bar.
312
+ * @default 'Solid'
313
+ */
314
+ borderDashStyle?: DashStyle;
315
+ /** Options for the series states that provide additional styling information to the series. */
316
+ states?: {
317
+ hover?: BasicHoverState;
318
+ inactive?: BasicInactiveState;
319
+ };
320
+ };
294
321
  }
295
322
  export type ChartSeriesRangeSliderOptions = {
296
323
  /**
@@ -15,6 +15,7 @@ import type { SankeySeries, SankeySeriesData } from './sankey';
15
15
  import type { ScatterSeries, ScatterSeriesData } from './scatter';
16
16
  import type { TreemapSeries, TreemapSeriesData } from './treemap';
17
17
  import type { WaterfallSeries, WaterfallSeriesData } from './waterfall';
18
+ import type { XRangeSeries, XRangeSeriesData } from './x-range';
18
19
  export interface TooltipDataChunkBarX<T = MeaningfulAny> {
19
20
  data: BarXSeriesData<T>;
20
21
  series: BarXSeries<T>;
@@ -87,7 +88,11 @@ export interface TooltipDataChunkFunnel<T = MeaningfulAny> {
87
88
  name: string;
88
89
  };
89
90
  }
90
- export type TooltipDataChunk<T = MeaningfulAny> = (TooltipDataChunkBarX<T> | TooltipDataChunkBarY<T> | TooltipDataChunkPie<T> | TooltipDataChunkScatter<T> | TooltipDataChunkLine<T> | TooltipDataChunkArea<T> | TooltipDataChunkTreemap<T> | TooltipDataChunkSankey<T> | TooltipDataChunkWaterfall<T> | TooltipDataChunkRadar<T> | TooltipDataChunkHeatmap<T> | TooltipDataChunkFunnel<T>) & {
91
+ export interface TooltipDataChunkXRange<T = MeaningfulAny> {
92
+ data: XRangeSeriesData<T>;
93
+ series: XRangeSeries<T>;
94
+ }
95
+ export type TooltipDataChunk<T = MeaningfulAny> = (TooltipDataChunkBarX<T> | TooltipDataChunkBarY<T> | TooltipDataChunkPie<T> | TooltipDataChunkScatter<T> | TooltipDataChunkLine<T> | TooltipDataChunkArea<T> | TooltipDataChunkTreemap<T> | TooltipDataChunkSankey<T> | TooltipDataChunkWaterfall<T> | TooltipDataChunkRadar<T> | TooltipDataChunkHeatmap<T> | TooltipDataChunkFunnel<T> | TooltipDataChunkXRange<T>) & {
91
96
  closest?: boolean;
92
97
  };
93
98
  export interface ChartTooltipRendererArgs<T = MeaningfulAny> {
@@ -0,0 +1,59 @@
1
+ import type { DashStyle, SERIES_TYPE } from '../../constants';
2
+ import type { MeaningfulAny } from '../misc';
3
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { RectLegendSymbolOptions } from './legend';
5
+ export interface XRangeSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
+ /**
7
+ * The start value of the bar on the x-axis. Can be a numeric or timestamp value.
8
+ */
9
+ x0: number | string;
10
+ /**
11
+ * The end value of the bar on the x-axis. Can be a numeric or timestamp value.
12
+ */
13
+ x1: number | string;
14
+ /**
15
+ * The `y` value. Depending on the context it may represent:
16
+ * - a category value (for `category` y axis). If string, it is the category itself. If number, it is the index in `yAxis[0].categories`.
17
+ * - a numeric value (for `linear` y axis)
18
+ */
19
+ y?: string | number;
20
+ /** Individual color for the bar. Overrides the series color. */
21
+ color?: string;
22
+ /** Data label value. If not specified, the series name is used. */
23
+ label?: string | number;
24
+ /** Individual opacity for the bar. */
25
+ opacity?: number;
26
+ }
27
+ export interface XRangeSeries<T = MeaningfulAny> extends BaseSeries {
28
+ type: typeof SERIES_TYPE.XRange;
29
+ data: XRangeSeriesData<T>[];
30
+ /** The name of the series (used in legend, tooltip etc) */
31
+ name: string;
32
+ /** The main color of the series (hex, rgba) */
33
+ color?: string;
34
+ /** Individual opacity for the entire series. */
35
+ opacity?: number | null;
36
+ /**
37
+ * The corner radius of the border surrounding each bar.
38
+ * @default 0
39
+ */
40
+ borderRadius?: number;
41
+ /**
42
+ * The width of the border surrounding each bar.
43
+ * @default 0
44
+ */
45
+ borderWidth?: number;
46
+ /**
47
+ * The color of the border surrounding each bar.
48
+ */
49
+ borderColor?: string;
50
+ /**
51
+ * The dash style of the border surrounding each bar.
52
+ * @default 'Solid'
53
+ */
54
+ borderDashStyle?: DashStyle;
55
+ /** Individual series legend options. Has higher priority than legend options in widget data */
56
+ legend?: BaseSeriesLegend & {
57
+ symbol?: RectLegendSymbolOptions;
58
+ };
59
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -18,7 +18,7 @@ export interface ChartZoom {
18
18
  *
19
19
  * Supported zoom types by series type:
20
20
  * - `Area`, `Line`, `Scatter`: `x`, `y`, `xy`
21
- * - `BarX`: `x`
21
+ * - `BarX`, `XRange`: `x`
22
22
  * - `BarY`: `y`
23
23
  *
24
24
  * Default zoom type by series type: