@gravity-ui/charts 1.43.1 → 1.45.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 (135) hide show
  1. package/dist/cjs/components/ChartInner/utils/zoom.js +3 -1
  2. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +31 -6
  3. package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.js +4 -5
  4. package/dist/cjs/core/constants/chart-types.d.ts +1 -0
  5. package/dist/cjs/core/constants/chart-types.js +1 -0
  6. package/dist/cjs/core/constants/defaults/annotation.d.ts +12 -0
  7. package/dist/cjs/core/constants/defaults/annotation.js +12 -0
  8. package/dist/cjs/core/constants/defaults/index.d.ts +1 -0
  9. package/dist/cjs/core/constants/defaults/index.js +1 -0
  10. package/dist/cjs/core/constants/defaults/series-options.d.ts +5 -1
  11. package/dist/cjs/core/constants/defaults/series-options.js +13 -0
  12. package/dist/cjs/core/i18n/keysets/en.json +2 -1
  13. package/dist/cjs/core/i18n/keysets/ru.json +2 -1
  14. package/dist/cjs/core/series/constants.d.ts +1 -1
  15. package/dist/cjs/core/series/constants.js +1 -1
  16. package/dist/cjs/core/series/prepare-annotation.d.ts +12 -0
  17. package/dist/cjs/core/series/prepare-annotation.js +31 -0
  18. package/dist/cjs/core/series/prepare-legend.js +2 -2
  19. package/dist/cjs/core/series/prepare-x-range.d.ts +11 -0
  20. package/dist/cjs/core/series/prepare-x-range.js +41 -0
  21. package/dist/cjs/core/series/prepareSeries.js +9 -0
  22. package/dist/cjs/core/series/types.d.ts +34 -2
  23. package/dist/cjs/core/types/chart/annotation.d.ts +45 -0
  24. package/dist/cjs/core/types/chart/annotation.js +1 -0
  25. package/dist/cjs/core/types/chart/area.d.ts +10 -1
  26. package/dist/cjs/core/types/chart/bar-x.d.ts +6 -0
  27. package/dist/cjs/core/types/chart/line.d.ts +8 -0
  28. package/dist/cjs/core/types/chart/marker.d.ts +6 -4
  29. package/dist/cjs/core/types/chart/series.d.ts +36 -2
  30. package/dist/cjs/core/types/chart/tooltip.d.ts +7 -1
  31. package/dist/cjs/core/types/chart/x-range.d.ts +59 -0
  32. package/dist/cjs/core/types/chart/x-range.js +1 -0
  33. package/dist/cjs/core/types/chart/zoom.d.ts +1 -1
  34. package/dist/cjs/core/types/index.d.ts +2 -0
  35. package/dist/cjs/core/types/index.js +2 -0
  36. package/dist/cjs/core/utils/axis/x-axis.js +9 -1
  37. package/dist/cjs/core/utils/color.js +6 -0
  38. package/dist/cjs/core/utils/common.js +10 -0
  39. package/dist/cjs/core/utils/get-closest-data.js +19 -0
  40. package/dist/cjs/core/utils/text.d.ts +8 -0
  41. package/dist/cjs/core/utils/text.js +9 -1
  42. package/dist/cjs/core/validation/index.js +13 -0
  43. package/dist/cjs/core/zoom/zoom.js +24 -7
  44. package/dist/cjs/hooks/useShapes/annotation/index.d.ts +14 -0
  45. package/dist/cjs/hooks/useShapes/annotation/index.js +200 -0
  46. package/dist/cjs/hooks/useShapes/area/index.d.ts +2 -0
  47. package/dist/cjs/hooks/useShapes/area/index.js +21 -2
  48. package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +2 -1
  49. package/dist/cjs/hooks/useShapes/area/prepare-data.js +45 -26
  50. package/dist/cjs/hooks/useShapes/area/types.d.ts +4 -0
  51. package/dist/cjs/hooks/useShapes/bar-x/index.d.ts +2 -0
  52. package/dist/cjs/hooks/useShapes/bar-x/index.js +30 -2
  53. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +32 -11
  54. package/dist/cjs/hooks/useShapes/bar-x/types.d.ts +2 -0
  55. package/dist/cjs/hooks/useShapes/index.d.ts +2 -1
  56. package/dist/cjs/hooks/useShapes/index.js +22 -3
  57. package/dist/cjs/hooks/useShapes/line/index.d.ts +2 -0
  58. package/dist/cjs/hooks/useShapes/line/index.js +21 -7
  59. package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +2 -1
  60. package/dist/cjs/hooks/useShapes/line/prepare-data.js +28 -10
  61. package/dist/cjs/hooks/useShapes/line/types.d.ts +4 -0
  62. package/dist/cjs/hooks/useShapes/x-range/index.d.ts +14 -0
  63. package/dist/cjs/hooks/useShapes/x-range/index.js +115 -0
  64. package/dist/cjs/hooks/useShapes/x-range/prepare-data.d.ts +15 -0
  65. package/dist/cjs/hooks/useShapes/x-range/prepare-data.js +147 -0
  66. package/dist/cjs/hooks/useShapes/x-range/types.d.ts +12 -0
  67. package/dist/cjs/hooks/useShapes/x-range/types.js +1 -0
  68. package/dist/esm/components/ChartInner/utils/zoom.js +3 -1
  69. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +31 -6
  70. package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.js +4 -5
  71. package/dist/esm/core/constants/chart-types.d.ts +1 -0
  72. package/dist/esm/core/constants/chart-types.js +1 -0
  73. package/dist/esm/core/constants/defaults/annotation.d.ts +12 -0
  74. package/dist/esm/core/constants/defaults/annotation.js +12 -0
  75. package/dist/esm/core/constants/defaults/index.d.ts +1 -0
  76. package/dist/esm/core/constants/defaults/index.js +1 -0
  77. package/dist/esm/core/constants/defaults/series-options.d.ts +5 -1
  78. package/dist/esm/core/constants/defaults/series-options.js +13 -0
  79. package/dist/esm/core/i18n/keysets/en.json +2 -1
  80. package/dist/esm/core/i18n/keysets/ru.json +2 -1
  81. package/dist/esm/core/series/constants.d.ts +1 -1
  82. package/dist/esm/core/series/constants.js +1 -1
  83. package/dist/esm/core/series/prepare-annotation.d.ts +12 -0
  84. package/dist/esm/core/series/prepare-annotation.js +31 -0
  85. package/dist/esm/core/series/prepare-legend.js +2 -2
  86. package/dist/esm/core/series/prepare-x-range.d.ts +11 -0
  87. package/dist/esm/core/series/prepare-x-range.js +41 -0
  88. package/dist/esm/core/series/prepareSeries.js +9 -0
  89. package/dist/esm/core/series/types.d.ts +34 -2
  90. package/dist/esm/core/types/chart/annotation.d.ts +45 -0
  91. package/dist/esm/core/types/chart/annotation.js +1 -0
  92. package/dist/esm/core/types/chart/area.d.ts +10 -1
  93. package/dist/esm/core/types/chart/bar-x.d.ts +6 -0
  94. package/dist/esm/core/types/chart/line.d.ts +8 -0
  95. package/dist/esm/core/types/chart/marker.d.ts +6 -4
  96. package/dist/esm/core/types/chart/series.d.ts +36 -2
  97. package/dist/esm/core/types/chart/tooltip.d.ts +7 -1
  98. package/dist/esm/core/types/chart/x-range.d.ts +59 -0
  99. package/dist/esm/core/types/chart/x-range.js +1 -0
  100. package/dist/esm/core/types/chart/zoom.d.ts +1 -1
  101. package/dist/esm/core/types/index.d.ts +2 -0
  102. package/dist/esm/core/types/index.js +2 -0
  103. package/dist/esm/core/utils/axis/x-axis.js +9 -1
  104. package/dist/esm/core/utils/color.js +6 -0
  105. package/dist/esm/core/utils/common.js +10 -0
  106. package/dist/esm/core/utils/get-closest-data.js +19 -0
  107. package/dist/esm/core/utils/text.d.ts +8 -0
  108. package/dist/esm/core/utils/text.js +9 -1
  109. package/dist/esm/core/validation/index.js +13 -0
  110. package/dist/esm/core/zoom/zoom.js +24 -7
  111. package/dist/esm/hooks/useShapes/annotation/index.d.ts +14 -0
  112. package/dist/esm/hooks/useShapes/annotation/index.js +200 -0
  113. package/dist/esm/hooks/useShapes/area/index.d.ts +2 -0
  114. package/dist/esm/hooks/useShapes/area/index.js +21 -2
  115. package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +2 -1
  116. package/dist/esm/hooks/useShapes/area/prepare-data.js +45 -26
  117. package/dist/esm/hooks/useShapes/area/types.d.ts +4 -0
  118. package/dist/esm/hooks/useShapes/bar-x/index.d.ts +2 -0
  119. package/dist/esm/hooks/useShapes/bar-x/index.js +30 -2
  120. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +32 -11
  121. package/dist/esm/hooks/useShapes/bar-x/types.d.ts +2 -0
  122. package/dist/esm/hooks/useShapes/index.d.ts +2 -1
  123. package/dist/esm/hooks/useShapes/index.js +22 -3
  124. package/dist/esm/hooks/useShapes/line/index.d.ts +2 -0
  125. package/dist/esm/hooks/useShapes/line/index.js +21 -7
  126. package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +2 -1
  127. package/dist/esm/hooks/useShapes/line/prepare-data.js +28 -10
  128. package/dist/esm/hooks/useShapes/line/types.d.ts +4 -0
  129. package/dist/esm/hooks/useShapes/x-range/index.d.ts +14 -0
  130. package/dist/esm/hooks/useShapes/x-range/index.js +115 -0
  131. package/dist/esm/hooks/useShapes/x-range/prepare-data.d.ts +15 -0
  132. package/dist/esm/hooks/useShapes/x-range/prepare-data.js +147 -0
  133. package/dist/esm/hooks/useShapes/x-range/types.d.ts +12 -0
  134. package/dist/esm/hooks/useShapes/x-range/types.js +1 -0
  135. package/package.json +2 -2
@@ -0,0 +1,147 @@
1
+ import get from 'lodash/get';
2
+ import { getDataCategoryValue, getLabelsSize, getTextSizeFn, getTextWithElipsis } from '../../../core/utils';
3
+ import { getFormattedValue } from '../../../core/utils/format';
4
+ import { MIN_BAR_WIDTH } from '../../constants';
5
+ import { getBandSize } from '../../utils/get-band-size';
6
+ const DEFAULT_BAR_PADDING = 0.2;
7
+ export async function prepareXRangeData(args) {
8
+ var _a;
9
+ const { series, xAxis, xScale, yAxis, yScale: [yScale], boundsWidth, isRangeSlider, } = args;
10
+ if (!yScale) {
11
+ return [];
12
+ }
13
+ // Collect unique y-domain values
14
+ const domain = [];
15
+ const seen = new Set();
16
+ const categories = get(yAxis[0], 'categories', []);
17
+ series.forEach((s) => {
18
+ s.data.forEach((d) => {
19
+ const key = yAxis[0].type === 'category'
20
+ ? getDataCategoryValue({ axisDirection: 'y', categories, data: d })
21
+ : d.y;
22
+ if (key !== undefined && !seen.has(key)) {
23
+ seen.add(key);
24
+ domain.push(key);
25
+ }
26
+ });
27
+ });
28
+ const bandSize = getBandSize({ domain, scale: yScale });
29
+ const barSize = Math.max(MIN_BAR_WIDTH, bandSize * (1 - DEFAULT_BAR_PADDING));
30
+ const result = [];
31
+ series.forEach((s) => {
32
+ s.data.forEach((d) => {
33
+ let center;
34
+ if (yAxis[0].type === 'category') {
35
+ const bandScale = yScale;
36
+ const yCategory = getDataCategoryValue({ axisDirection: 'y', categories, data: d });
37
+ if (!bandScale.domain().includes(yCategory)) {
38
+ return;
39
+ }
40
+ center = (bandScale(yCategory) || 0) + bandSize / 2;
41
+ }
42
+ else {
43
+ const linearScale = yScale;
44
+ if (d.y === undefined) {
45
+ return;
46
+ }
47
+ center = linearScale(Number(d.y));
48
+ }
49
+ let xStart;
50
+ let xEnd;
51
+ if (xAxis.type === 'category') {
52
+ // x-range on a category x-axis is unusual but supported
53
+ const xBandScale = xScale;
54
+ const xCategories = get(xAxis, 'categories', []);
55
+ const startCategory = getDataCategoryValue({
56
+ axisDirection: 'x',
57
+ categories: xCategories,
58
+ data: { x: d.x0 },
59
+ });
60
+ const endCategory = getDataCategoryValue({
61
+ axisDirection: 'x',
62
+ categories: xCategories,
63
+ data: { x: d.x1 },
64
+ });
65
+ xStart = xBandScale(startCategory) || 0;
66
+ xEnd = (xBandScale(endCategory) || 0) + xBandScale.bandwidth();
67
+ }
68
+ else {
69
+ const linearScale = xScale;
70
+ xStart = linearScale(Number(d.x0));
71
+ xEnd = linearScale(Number(d.x1));
72
+ }
73
+ const width = xEnd - xStart;
74
+ if (width <= 0) {
75
+ return;
76
+ }
77
+ result.push({
78
+ x: xStart,
79
+ y: center - barSize / 2,
80
+ width,
81
+ height: barSize,
82
+ color: d.color || s.color,
83
+ data: d,
84
+ series: s,
85
+ htmlLabels: [],
86
+ svgLabels: [],
87
+ });
88
+ });
89
+ });
90
+ const textSizeFnCache = new Map();
91
+ for (let i = 0; i < result.length; i++) {
92
+ const item = result[i];
93
+ const { dataLabels } = item.series;
94
+ if (!dataLabels.enabled || item.data.label === null || isRangeSlider) {
95
+ continue;
96
+ }
97
+ const content = getFormattedValue(Object.assign({ value: item.data.label }, dataLabels));
98
+ const visibleStart = Math.max(0, item.x);
99
+ const visibleEnd = boundsWidth === undefined
100
+ ? item.x + item.width
101
+ : Math.min(boundsWidth, item.x + item.width);
102
+ const visibleWidth = visibleEnd - visibleStart;
103
+ const visibleCenterX = visibleStart + visibleWidth / 2;
104
+ if (dataLabels.html) {
105
+ const { maxHeight: height, maxWidth: width } = await getLabelsSize({
106
+ labels: [content],
107
+ style: dataLabels.style,
108
+ html: true,
109
+ });
110
+ const htmlItem = {
111
+ content,
112
+ size: { width, height },
113
+ style: dataLabels.style,
114
+ x: visibleCenterX - width / 2,
115
+ y: item.y + item.height / 2 - height / 2,
116
+ };
117
+ item.htmlLabels.push(htmlItem);
118
+ }
119
+ else {
120
+ if (!textSizeFnCache.has(dataLabels.style)) {
121
+ textSizeFnCache.set(dataLabels.style, getTextSizeFn({ style: dataLabels.style }));
122
+ }
123
+ const getTextSize = (_a = textSizeFnCache.get(dataLabels.style)) !== null && _a !== void 0 ? _a : getTextSizeFn({ style: dataLabels.style });
124
+ const availableWidth = Math.max(0, visibleWidth - 2 * dataLabels.padding);
125
+ const text = await getTextWithElipsis({
126
+ text: content,
127
+ getTextWidth: (s) => getTextSize(s).then((r) => r.width),
128
+ maxWidth: availableWidth,
129
+ });
130
+ if (!text) {
131
+ continue;
132
+ }
133
+ const { width, height, hangingOffset } = await getTextSize(text);
134
+ const svgItem = {
135
+ text,
136
+ size: { width, height, hangingOffset },
137
+ style: dataLabels.style,
138
+ textAnchor: 'middle',
139
+ x: visibleCenterX,
140
+ y: item.y + item.height / 2,
141
+ series: item.series,
142
+ };
143
+ item.svgLabels.push(svgItem);
144
+ }
145
+ }
146
+ return result;
147
+ }
@@ -0,0 +1,12 @@
1
+ import type { HtmlItem, LabelData, TooltipDataChunkXRange } from '../../../types';
2
+ import type { PreparedXRangeSeries } from '../../useSeries/types';
3
+ export type PreparedXRangeData = Omit<TooltipDataChunkXRange, 'series'> & {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ color: string;
9
+ series: PreparedXRangeSeries;
10
+ svgLabels: LabelData[];
11
+ htmlLabels: HtmlItem[];
12
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.43.1",
3
+ "version": "1.45.0",
4
4
  "description": "A flexible JavaScript library for data visualization and chart rendering using React",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",
@@ -96,7 +96,7 @@
96
96
  "@gravity-ui/prettier-config": "^1.1.0",
97
97
  "@gravity-ui/stylelint-config": "^4.0.1",
98
98
  "@gravity-ui/tsconfig": "^1.0.0",
99
- "@gravity-ui/uikit": "^7.4.0",
99
+ "@gravity-ui/uikit": "^7.18.0",
100
100
  "@playwright/experimental-ct-react": "^1.56.1",
101
101
  "@playwright/test": "^1.56.1",
102
102
  "@storybook/addon-a11y": "^10.2.16",