@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
@@ -1,416 +0,0 @@
1
- import React from 'react';
2
- import { axisLeft, axisRight, line, select } from 'd3';
3
- import { block, calculateCos, calculateSin, formatAxisTickLabel, getAxisHeight, getAxisPlotsPosition, getAxisTitleRows, getBandsPosition, getClosestPointsRange, getLineDashArray, getScaleTicks, getTicksCount, handleOverflowingText, parseTransformStyle, setEllipsisForOverflowTexts, wrapText, } from '../../utils';
4
- import './styles.css';
5
- const b = block('axis');
6
- const AXIS_LEFT_HTML_LABELS_DATA_ATTR = 'data-axis-left-html-labels';
7
- const AXIS_RIGHT_HTML_LABELS_DATA_ATTR = 'data-axis-right-html-labels';
8
- function transformLabel(args) {
9
- const { node, axis, startTopOffset } = args;
10
- let topOffset = startTopOffset !== null && startTopOffset !== void 0 ? startTopOffset : axis.labels.lineHeight / 2;
11
- let leftOffset = axis.labels.margin;
12
- if (axis.position === 'left') {
13
- leftOffset = leftOffset * -1;
14
- }
15
- if (axis.labels.rotation) {
16
- if (axis.labels.rotation > 0) {
17
- leftOffset -= axis.labels.lineHeight * calculateSin(axis.labels.rotation);
18
- topOffset = axis.labels.lineHeight * calculateCos(axis.labels.rotation);
19
- if (axis.labels.rotation % 360 === 90) {
20
- topOffset = ((node === null || node === void 0 ? void 0 : node.getBoundingClientRect().width) || 0) / 2;
21
- }
22
- }
23
- else {
24
- topOffset = 0;
25
- if (axis.labels.rotation % 360 === -90) {
26
- topOffset = -((node === null || node === void 0 ? void 0 : node.getBoundingClientRect().width) || 0) / 2;
27
- }
28
- }
29
- return `translate(${leftOffset}px, ${topOffset}px) rotate(${axis.labels.rotation}deg)`;
30
- }
31
- return `translate(${leftOffset}px, ${topOffset}px)`;
32
- }
33
- function getAxisGenerator(args) {
34
- const { preparedAxis, axisGenerator: generator, width, height, scale } = args;
35
- const tickSize = preparedAxis.grid.enabled ? width * -1 : 0;
36
- const step = getClosestPointsRange(preparedAxis, getScaleTicks(scale));
37
- let axisGenerator = generator
38
- .tickSize(tickSize)
39
- .tickPadding(preparedAxis.labels.margin)
40
- .tickFormat((value) => {
41
- if (!preparedAxis.labels.enabled || preparedAxis.labels.html) {
42
- return '';
43
- }
44
- return formatAxisTickLabel({
45
- axis: preparedAxis,
46
- value,
47
- step,
48
- });
49
- });
50
- const ticksCount = getTicksCount({ axis: preparedAxis, range: height });
51
- if (ticksCount) {
52
- axisGenerator = axisGenerator.ticks(ticksCount);
53
- }
54
- return axisGenerator;
55
- }
56
- function getTitlePosition(args) {
57
- const { axis, axisHeight, rowCount } = args;
58
- if (rowCount < 1) {
59
- return { x: 0, y: 0 };
60
- }
61
- let x = axis.title.height -
62
- axis.title.height / rowCount +
63
- axis.title.margin +
64
- axis.labels.margin +
65
- axis.labels.width;
66
- if (axis.position === 'left') {
67
- x = x * -1;
68
- }
69
- let y;
70
- switch (axis.title.align) {
71
- case 'left': {
72
- y = axisHeight - axis.title.width / 2;
73
- break;
74
- }
75
- case 'right': {
76
- y = axis.title.width / 2;
77
- break;
78
- }
79
- case 'center': {
80
- y = axisHeight / 2;
81
- break;
82
- }
83
- }
84
- return { x, y };
85
- }
86
- export const AxisY = (props) => {
87
- const { axes: allAxes, bottomLimit = 0, boundsOffsetLeft, boundsOffsetTop, height: totalHeight, htmlLayout, plotAfterRef, plotBeforeRef, scale, split, topLimit = 0, width, } = props;
88
- const height = getAxisHeight({ split, boundsHeight: totalHeight });
89
- const ref = React.useRef(null);
90
- const lineGenerator = line();
91
- React.useEffect(() => {
92
- if (!ref.current || !htmlLayout) {
93
- return;
94
- }
95
- const axes = allAxes.filter((a) => a.visible);
96
- const svgElement = select(ref.current);
97
- svgElement.selectAll('*').remove();
98
- const htmlSelection = select(htmlLayout);
99
- htmlSelection.selectAll(`[${AXIS_LEFT_HTML_LABELS_DATA_ATTR}]`).remove();
100
- htmlSelection.selectAll(`[${AXIS_RIGHT_HTML_LABELS_DATA_ATTR}]`).remove();
101
- let plotBeforeContainer = null;
102
- let plotAfterContainer = null;
103
- const plotDataAttr = 'data-plot-y';
104
- if (plotBeforeRef === null || plotBeforeRef === void 0 ? void 0 : plotBeforeRef.current) {
105
- plotBeforeContainer = select(plotBeforeRef.current);
106
- plotBeforeContainer.selectAll(`[${plotDataAttr}]`).remove();
107
- }
108
- if (plotAfterRef === null || plotAfterRef === void 0 ? void 0 : plotAfterRef.current) {
109
- plotAfterContainer = select(plotAfterRef.current);
110
- plotAfterContainer.selectAll(`[${plotDataAttr}]`).remove();
111
- }
112
- const axisSelection = svgElement
113
- .selectAll('axis')
114
- .data(axes)
115
- .join('g')
116
- .attr('class', b())
117
- .style('transform', (d) => getAxisPlotsPosition(d, split, width));
118
- axisSelection.each((d, index, node) => {
119
- var _a, _b;
120
- const seriesScale = scale[index];
121
- const axisItem = select(node[index]);
122
- const axisScale = seriesScale;
123
- const yAxisGenerator = getAxisGenerator({
124
- axisGenerator: d.position === 'left' ? axisLeft(axisScale) : axisRight(axisScale),
125
- preparedAxis: d,
126
- height,
127
- width,
128
- scale: seriesScale,
129
- });
130
- yAxisGenerator(axisItem);
131
- // because the standard generator interrupts the desired font
132
- // https://github.com/d3/d3-axis/blob/main/src/axis.js#L110
133
- axisItem.attr('font-family', null);
134
- if (d.labels.enabled && d.labels.html) {
135
- const offsetTop = ((_a = svgElement.node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().top) || 0;
136
- const offsetLeft = ((_b = svgElement.node()) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect().left) || 0;
137
- const htmlLabelsData = [];
138
- axisItem
139
- .selectAll('.tick')
140
- .data(axisScale.domain())
141
- .each(function (tickContent) {
142
- const rect = this.getBoundingClientRect();
143
- htmlLabelsData.push({
144
- content: tickContent,
145
- right: rect.right,
146
- top: rect.top,
147
- });
148
- });
149
- const dataAttr = d.position === 'left'
150
- ? AXIS_LEFT_HTML_LABELS_DATA_ATTR
151
- : AXIS_RIGHT_HTML_LABELS_DATA_ATTR;
152
- htmlSelection.append('div').attr(dataAttr, 1).style('position', 'absolute');
153
- htmlLabelsData.forEach((labelData) => {
154
- htmlSelection
155
- .selectAll(`[${dataAttr}]`)
156
- .data([labelData])
157
- .append('div')
158
- .html(function (l) {
159
- return l.content;
160
- })
161
- .style('font-size', d.labels.style.fontSize || '')
162
- .style('position', 'absolute')
163
- .style('white-space', 'nowrap')
164
- .style('color', 'var(--g-color-text-secondary)')
165
- .style('overflow', 'hidden')
166
- .style('text-overflow', 'ellipsis')
167
- .style('height', `${d.labels.height}px`)
168
- .style('display', 'inline-flex')
169
- .style('align-items', 'center')
170
- .style('left', function (l) {
171
- if (d.position === 'right') {
172
- return `${l.right - offsetLeft + d.labels.margin + boundsOffsetLeft}px`;
173
- }
174
- const rect = this.getBoundingClientRect();
175
- return `${boundsOffsetLeft - rect.width - d.labels.margin}px`;
176
- })
177
- .style('top', function (l) {
178
- const rect = this.getBoundingClientRect();
179
- return `${l.top + boundsOffsetTop - offsetTop - rect.height / 2}px`;
180
- });
181
- });
182
- }
183
- else if (d.labels.enabled) {
184
- const labels = axisItem.selectAll('.tick text');
185
- const tickTexts = labels
186
- // The offset must be applied before the labels are rotated.
187
- // Therefore, we reset the values and make an offset in transform attribute.
188
- // FIXME: give up axisLeft(d3) and switch to our own generation method
189
- .attr('x', null)
190
- .attr('dy', null)
191
- .style('font-size', d.labels.style.fontSize)
192
- .style('transform', function () {
193
- return transformLabel({ node: this, axis: d });
194
- });
195
- labels.each(function (_d, i, nodes) {
196
- const isFirstNode = i === 0;
197
- const isLastNode = i === nodes.length - 1;
198
- if (isFirstNode || isLastNode) {
199
- const labelNode = this;
200
- const labelNodeRect = labelNode.getBoundingClientRect();
201
- const shouldBeTransformed = (isFirstNode && labelNodeRect.bottom > bottomLimit) ||
202
- (isLastNode && labelNodeRect.top < topLimit);
203
- if (shouldBeTransformed) {
204
- const text = select(labelNode);
205
- const transform = transformLabel({
206
- node: this,
207
- axis: d,
208
- startTopOffset: isLastNode ? labelNodeRect.height : 0,
209
- });
210
- text.style('transform', transform);
211
- if (d.labels.rotation) {
212
- text.attr('text-anchor', () => {
213
- return d.labels.rotation < 0 ? 'start' : 'end';
214
- });
215
- }
216
- }
217
- }
218
- });
219
- const textMaxWidth = !d.labels.rotation || Math.abs(d.labels.rotation) % 360 !== 90
220
- ? d.labels.maxWidth
221
- : (height - d.labels.padding * (tickTexts.size() - 1)) / tickTexts.size();
222
- tickTexts.call(setEllipsisForOverflowTexts, textMaxWidth);
223
- }
224
- // remove overlapping ticks
225
- // Note: this method do not prepared for rotated labels
226
- if (!d.labels.rotation) {
227
- let elementY = 0;
228
- axisItem
229
- .selectAll('.tick')
230
- .nodes()
231
- .map((element) => {
232
- const r = element.getBoundingClientRect();
233
- return {
234
- top: r.top,
235
- bottom: r.bottom,
236
- node: element,
237
- };
238
- }, {})
239
- .sort((item1, item2) => {
240
- return item2.top - item1.top;
241
- })
242
- .filter(function ({ top, bottom }, tickIndex) {
243
- if (bottom > elementY && tickIndex !== 0) {
244
- return true;
245
- }
246
- elementY = top - d.labels.padding;
247
- return false;
248
- })
249
- .forEach((item) => {
250
- item.node.remove();
251
- });
252
- }
253
- if (d.plotBands.length > 0) {
254
- const plotBandDataAttr = `data-plot-y-band-${index}`;
255
- const setPlotBands = (plotContainer, plotBands) => {
256
- if (!plotContainer || !plotBands.length) {
257
- return;
258
- }
259
- const plotBandsSelection = plotContainer
260
- .selectAll(`[${plotBandDataAttr}]`)
261
- .remove()
262
- .data(plotBands)
263
- .join('g')
264
- .attr(plotDataAttr, 1)
265
- .attr(plotBandDataAttr, 1)
266
- .style('transform', getAxisPlotsPosition(d, split));
267
- plotBandsSelection.each(function () {
268
- var _a, _b, _c, _e;
269
- const plotBandSelection = select(this);
270
- const band = plotBandSelection.datum();
271
- const { from, to } = getBandsPosition({ band, axisScale, axis: 'y' });
272
- const halfBandwidth = ((_b = (_a = axisScale.bandwidth) === null || _a === void 0 ? void 0 : _a.call(axisScale)) !== null && _b !== void 0 ? _b : 0) / 2;
273
- const startPos = halfBandwidth + Math.min(from, to);
274
- const endPos = Math.min(Math.abs(to - from), height - Math.min(from, to));
275
- const y = Math.max(0, startPos);
276
- plotBandSelection
277
- .append('rect')
278
- .attr('x', 0)
279
- .attr('width', width)
280
- .attr('y', y)
281
- .attr('height', Math.min(endPos, height))
282
- .attr('fill', () => band.color)
283
- .attr('opacity', () => band.opacity);
284
- if (band.label.text) {
285
- const labelPadding = (_e = (_c = band.label) === null || _c === void 0 ? void 0 : _c.padding) !== null && _e !== void 0 ? _e : 0;
286
- plotBandSelection
287
- .append('text')
288
- .text(band.label.text)
289
- .style('fill', () => { var _a, _b; return (_b = (_a = band.label.style) === null || _a === void 0 ? void 0 : _a.fontColor) !== null && _b !== void 0 ? _b : null; })
290
- .style('font-size', () => { var _a, _b; return (_b = (_a = band.label.style) === null || _a === void 0 ? void 0 : _a.fontSize) !== null && _b !== void 0 ? _b : null; })
291
- .style('font-weight', () => { var _a, _b; return (_b = (_a = band.label.style) === null || _a === void 0 ? void 0 : _a.fontWeight) !== null && _b !== void 0 ? _b : null; })
292
- .style('dominant-baseline', 'text-before-edge')
293
- .attr('x', labelPadding)
294
- .attr('y', y + labelPadding);
295
- }
296
- });
297
- };
298
- setPlotBands(plotBeforeContainer, d.plotBands.filter((item) => item.layerPlacement === 'before'));
299
- setPlotBands(plotAfterContainer, d.plotBands.filter((item) => item.layerPlacement === 'after'));
300
- }
301
- if (d.plotLines.length > 0) {
302
- const plotLineDataAttr = `data-plot-y-line-${index}`;
303
- const setPlotLines = (plotContainer, plotLines) => {
304
- if (!plotContainer || !plotLines.length) {
305
- return;
306
- }
307
- const plotLinesSelection = plotContainer
308
- .selectAll(`[${plotLineDataAttr}]`)
309
- .remove()
310
- .data(plotLines)
311
- .join('g')
312
- .attr(plotDataAttr, 1)
313
- .attr(plotLineDataAttr, 1)
314
- .style('transform', getAxisPlotsPosition(d, split));
315
- plotLinesSelection.each(function () {
316
- const itemSelection = select(this);
317
- const plotLine = itemSelection.datum();
318
- const plotLineValue = Number(axisScale(plotLine.value));
319
- const points = [
320
- [0, plotLineValue],
321
- [width, plotLineValue],
322
- ];
323
- itemSelection
324
- .append('path')
325
- .attr('d', lineGenerator(points))
326
- .attr('stroke', plotLine.color)
327
- .attr('stroke-width', plotLine.width)
328
- .attr('stroke-dasharray', getLineDashArray(plotLine.dashStyle, plotLine.width))
329
- .attr('opacity', plotLine.opacity);
330
- if (plotLine.label.text) {
331
- itemSelection
332
- .append('text')
333
- .text(plotLine.label.text)
334
- .style('fill', () => { var _a; return (_a = plotLine.label.style.fontColor) !== null && _a !== void 0 ? _a : null; })
335
- .attr('font-size', plotLine.label.style.fontSize)
336
- .style('font-weight', () => { var _a; return (_a = plotLine.label.style.fontWeight) !== null && _a !== void 0 ? _a : null; })
337
- .attr('x', plotLine.label.padding)
338
- .attr('y', plotLineValue - plotLine.label.padding);
339
- }
340
- });
341
- };
342
- setPlotLines(plotBeforeContainer, d.plotLines.filter((item) => item.layerPlacement === 'before'));
343
- setPlotLines(plotAfterContainer, d.plotLines.filter((item) => item.layerPlacement === 'after'));
344
- }
345
- return axisItem;
346
- });
347
- axisSelection
348
- .select('.domain')
349
- .attr('d', () => {
350
- const points = [
351
- [0, 0],
352
- [0, height],
353
- ];
354
- return lineGenerator(points);
355
- })
356
- .style('stroke', (d) => d.lineColor || '');
357
- svgElement.selectAll('.tick').each((_d, index, nodes) => {
358
- const tickNode = select(nodes[index]);
359
- if (parseTransformStyle(tickNode.attr('transform')).y === height) {
360
- // Remove stroke from tick that has the same y coordinate like domain
361
- tickNode.select('line').style('stroke', 'none');
362
- }
363
- });
364
- axisSelection
365
- .append('text')
366
- .attr('class', b('title'))
367
- .attr('text-anchor', 'middle')
368
- .attr('font-size', (d) => d.title.style.fontSize)
369
- .call(async (s) => {
370
- s.each(async function prepareAxisTitle(d) {
371
- if (!this) {
372
- return;
373
- }
374
- const selection = select(this);
375
- const titleRows = await wrapText({
376
- text: d.title.text,
377
- style: d.title.style,
378
- width: height,
379
- });
380
- const rowCount = Math.min(titleRows.length, d.title.maxRowCount);
381
- const { x, y } = getTitlePosition({ axis: d, axisHeight: height, rowCount });
382
- const angle = d.position === 'left' ? -90 : 90;
383
- selection.attr('transform', `translate(${x}, ${y}) rotate(${angle})`);
384
- const axisTitleRows = await getAxisTitleRows({ axis: d, textMaxWidth: height });
385
- selection
386
- .selectAll('tspan')
387
- .data(axisTitleRows)
388
- .join('tspan')
389
- .attr('x', 0)
390
- .attr('y', (titleRow) => titleRow.y)
391
- .text((titleRow) => titleRow.text)
392
- .each((_d, index, nodes) => {
393
- if (index === nodes.length - 1) {
394
- handleOverflowingText(nodes[index], height);
395
- }
396
- });
397
- });
398
- return s;
399
- });
400
- }, [
401
- allAxes,
402
- bottomLimit,
403
- boundsOffsetLeft,
404
- boundsOffsetTop,
405
- height,
406
- htmlLayout,
407
- lineGenerator,
408
- plotAfterRef,
409
- plotBeforeRef,
410
- scale,
411
- split,
412
- topLimit,
413
- width,
414
- ]);
415
- return React.createElement("g", { ref: ref, className: b('container') });
416
- };
@@ -1,2 +0,0 @@
1
- export * from './AxisX';
2
- export * from './AxisY';
@@ -1,2 +0,0 @@
1
- export * from './AxisX';
2
- export * from './AxisY';
@@ -1,30 +0,0 @@
1
- import type { ChartSeriesData, ChartTooltip, ChartTooltipTotalsAggregationValue, ChartTooltipTotalsBuiltInAggregation, ChartXAxis, ChartYAxis, TooltipDataChunk, ValueFormat } from '../../types';
2
- export type HoveredValue = string | number | null | undefined;
3
- export declare function getXRowData(data: ChartSeriesData, xAxis?: ChartXAxis | null): string | number | undefined;
4
- export declare function getDefaultValueFormat({ axis, }: {
5
- axis?: ChartXAxis | ChartYAxis | null;
6
- }): ValueFormat | undefined;
7
- export declare const getMeasureValue: ({ data, xAxis, yAxis, valueFormat, }: {
8
- data: TooltipDataChunk[];
9
- xAxis?: ChartXAxis | null;
10
- yAxis?: ChartYAxis;
11
- valueFormat?: ValueFormat;
12
- }) => string | null;
13
- export declare function getHoveredValues(args: {
14
- hovered: TooltipDataChunk[];
15
- xAxis?: ChartXAxis | null;
16
- yAxis?: ChartYAxis;
17
- }): HoveredValue[];
18
- export declare function getBuiltInAggregatedValue(args: {
19
- aggregation: ChartTooltipTotalsBuiltInAggregation;
20
- values: HoveredValue[];
21
- }): number | undefined;
22
- export declare function getBuiltInAggregationLabel(args: {
23
- aggregation: ChartTooltipTotalsBuiltInAggregation;
24
- }): string;
25
- export declare function getPreparedAggregation(args: {
26
- hovered: TooltipDataChunk[];
27
- totals?: ChartTooltip['totals'];
28
- xAxis?: ChartXAxis | null;
29
- yAxis?: ChartYAxis;
30
- }): ChartTooltipTotalsBuiltInAggregation | (() => ChartTooltipTotalsAggregationValue);
@@ -1,126 +0,0 @@
1
- import get from 'lodash/get';
2
- import { i18n } from '../../i18n';
3
- import { getDataCategoryValue } from '../../utils';
4
- import { getFormattedValue } from '../../utils/chart/format';
5
- const DEFAULT_DATE_FORMAT = 'DD.MM.YY';
6
- function getRowData(fieldName, data, axis) {
7
- switch (axis === null || axis === void 0 ? void 0 : axis.type) {
8
- case 'category': {
9
- const categories = get(axis, 'categories', []);
10
- return getDataCategoryValue({ axisDirection: fieldName, categories, data });
11
- }
12
- default: {
13
- return get(data, fieldName);
14
- }
15
- }
16
- }
17
- export function getXRowData(data, xAxis) {
18
- return getRowData('x', data, xAxis);
19
- }
20
- function getYRowData(data, yAxis) {
21
- return getRowData('y', data, yAxis);
22
- }
23
- export function getDefaultValueFormat({ axis, }) {
24
- switch (axis === null || axis === void 0 ? void 0 : axis.type) {
25
- case 'linear':
26
- case 'logarithmic': {
27
- return {
28
- type: 'number',
29
- };
30
- }
31
- case 'datetime': {
32
- return {
33
- type: 'date',
34
- format: DEFAULT_DATE_FORMAT,
35
- };
36
- }
37
- default:
38
- return undefined;
39
- }
40
- }
41
- export const getMeasureValue = ({ data, xAxis, yAxis, valueFormat, }) => {
42
- var _a, _b, _c, _d;
43
- if (data.every((item) => ['pie', 'treemap', 'waterfall', 'sankey'].includes(item.series.type))) {
44
- return null;
45
- }
46
- if (data.some((item) => item.series.type === 'radar')) {
47
- return (_b = (_a = data[0].category) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : null;
48
- }
49
- if (data.some((item) => item.series.type === 'bar-y')) {
50
- const format = valueFormat !== null && valueFormat !== void 0 ? valueFormat : getDefaultValueFormat({ axis: yAxis });
51
- return getFormattedValue({
52
- value: getYRowData((_c = data[0]) === null || _c === void 0 ? void 0 : _c.data, yAxis),
53
- format,
54
- });
55
- }
56
- const format = valueFormat !== null && valueFormat !== void 0 ? valueFormat : getDefaultValueFormat({ axis: xAxis });
57
- return getFormattedValue({
58
- value: getXRowData((_d = data[0]) === null || _d === void 0 ? void 0 : _d.data, xAxis),
59
- format,
60
- });
61
- };
62
- export function getHoveredValues(args) {
63
- const { hovered, xAxis, yAxis } = args;
64
- return hovered.map((seriesItem) => {
65
- var _a;
66
- const { data, series } = seriesItem;
67
- switch (series.type) {
68
- case 'area':
69
- case 'line':
70
- case 'bar-x':
71
- case 'scatter': {
72
- return getYRowData(data, yAxis);
73
- }
74
- case 'bar-y': {
75
- return getXRowData(data, xAxis);
76
- }
77
- case 'pie':
78
- case 'radar':
79
- case 'treemap': {
80
- const seriesData = data;
81
- return seriesData.value;
82
- }
83
- case 'sankey': {
84
- const { target, data: source } = seriesItem;
85
- 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;
86
- }
87
- case 'waterfall': {
88
- return getYRowData(data, yAxis);
89
- }
90
- default: {
91
- return undefined;
92
- }
93
- }
94
- });
95
- }
96
- export function getBuiltInAggregatedValue(args) {
97
- const { aggregation, values } = args;
98
- switch (aggregation) {
99
- case 'sum':
100
- return values.reduce((acc, value) => {
101
- return acc + (typeof value === 'number' ? value : 0);
102
- }, 0);
103
- default:
104
- return undefined;
105
- }
106
- }
107
- export function getBuiltInAggregationLabel(args) {
108
- const { aggregation } = args;
109
- switch (aggregation) {
110
- case 'sum':
111
- return i18n('tooltip', 'label_totals_sum');
112
- default:
113
- return '';
114
- }
115
- }
116
- export function getPreparedAggregation(args) {
117
- const { hovered, totals, xAxis, yAxis } = args;
118
- const aggregation = totals === null || totals === void 0 ? void 0 : totals.aggregation;
119
- if (typeof aggregation === 'string') {
120
- return aggregation;
121
- }
122
- if (typeof aggregation === 'function') {
123
- return () => aggregation({ hovered, xAxis, yAxis });
124
- }
125
- return 'sum';
126
- }