@gravity-ui/charts 1.26.1 → 1.27.1

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 (113) hide show
  1. package/dist/cjs/components/AxisX/AxisX.d.ts +5 -20
  2. package/dist/cjs/components/AxisX/AxisX.js +167 -212
  3. package/dist/cjs/components/AxisX/prepare-axis-data.d.ts +12 -0
  4. package/dist/cjs/components/AxisX/prepare-axis-data.js +310 -0
  5. package/dist/cjs/components/AxisX/styles.css +7 -10
  6. package/dist/cjs/components/AxisX/types.d.ts +85 -0
  7. package/dist/cjs/components/AxisX/types.js +1 -0
  8. package/dist/cjs/components/AxisY/AxisY.js +9 -3
  9. package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +1 -1
  10. package/dist/cjs/components/AxisY/prepare-axis-data.js +17 -81
  11. package/dist/cjs/components/AxisY/prepare-axis-title.d.ts +16 -0
  12. package/dist/cjs/components/AxisY/prepare-axis-title.js +149 -0
  13. package/dist/cjs/components/AxisY/types.d.ts +16 -4
  14. package/dist/cjs/components/AxisY/utils.js +1 -8
  15. package/dist/cjs/components/ChartInner/index.js +66 -50
  16. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +7 -7
  17. package/dist/cjs/components/ChartInner/useChartInnerProps.js +15 -20
  18. package/dist/cjs/components/ChartInner/useChartInnerState.d.ts +3 -2
  19. package/dist/cjs/components/ChartInner/useChartInnerState.js +23 -4
  20. package/dist/cjs/components/RangeSlider/index.d.ts +5 -3
  21. package/dist/cjs/components/RangeSlider/index.js +36 -4
  22. package/dist/cjs/components/Title/index.js +2 -2
  23. package/dist/cjs/components/utils.d.ts +9 -0
  24. package/dist/cjs/components/utils.js +34 -0
  25. package/dist/cjs/constants/defaults/axis.js +1 -1
  26. package/dist/cjs/hooks/index.d.ts +0 -1
  27. package/dist/cjs/hooks/index.js +0 -1
  28. package/dist/cjs/hooks/useAxis/index.js +10 -0
  29. package/dist/cjs/hooks/useAxis/types.d.ts +3 -0
  30. package/dist/cjs/hooks/useAxis/x-axis.d.ts +2 -1
  31. package/dist/cjs/hooks/useAxis/x-axis.js +42 -32
  32. package/dist/cjs/hooks/useAxis/y-axis.js +38 -11
  33. package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -1
  34. package/dist/cjs/hooks/useAxisScales/index.js +8 -7
  35. package/dist/cjs/hooks/useAxisScales/utils.d.ts +6 -0
  36. package/dist/cjs/hooks/useAxisScales/utils.js +17 -0
  37. package/dist/cjs/hooks/useChartDimensions/utils.js +7 -1
  38. package/dist/cjs/hooks/useNormalizedOriginalData/index.d.ts +1 -7
  39. package/dist/cjs/hooks/useRangeSlider/index.js +1 -2
  40. package/dist/cjs/hooks/useRangeSlider/types.d.ts +1 -3
  41. package/dist/cjs/hooks/useSplit/index.js +6 -2
  42. package/dist/cjs/hooks/useZoom/index.d.ts +1 -0
  43. package/dist/cjs/hooks/useZoom/index.js +12 -2
  44. package/dist/cjs/types/chart/axis.d.ts +45 -17
  45. package/dist/cjs/types/chart/title.d.ts +3 -0
  46. package/dist/{esm/utils/chart/axis.d.ts → cjs/utils/chart/axis/common.d.ts} +4 -16
  47. package/dist/{esm/utils/chart/axis.js → cjs/utils/chart/axis/common.js} +7 -40
  48. package/dist/cjs/utils/chart/axis/x-axis.d.ts +12 -0
  49. package/dist/cjs/utils/chart/axis/x-axis.js +78 -0
  50. package/dist/cjs/utils/chart/axis-generators/bottom.js +1 -1
  51. package/dist/cjs/utils/chart/index.d.ts +1 -1
  52. package/dist/cjs/utils/chart/index.js +1 -1
  53. package/dist/cjs/utils/chart/text.d.ts +0 -6
  54. package/dist/cjs/utils/chart/text.js +7 -19
  55. package/dist/esm/components/AxisX/AxisX.d.ts +5 -20
  56. package/dist/esm/components/AxisX/AxisX.js +167 -212
  57. package/dist/esm/components/AxisX/prepare-axis-data.d.ts +12 -0
  58. package/dist/esm/components/AxisX/prepare-axis-data.js +310 -0
  59. package/dist/esm/components/AxisX/styles.css +7 -10
  60. package/dist/esm/components/AxisX/types.d.ts +85 -0
  61. package/dist/esm/components/AxisX/types.js +1 -0
  62. package/dist/esm/components/AxisY/AxisY.js +9 -3
  63. package/dist/esm/components/AxisY/prepare-axis-data.d.ts +1 -1
  64. package/dist/esm/components/AxisY/prepare-axis-data.js +17 -81
  65. package/dist/esm/components/AxisY/prepare-axis-title.d.ts +16 -0
  66. package/dist/esm/components/AxisY/prepare-axis-title.js +149 -0
  67. package/dist/esm/components/AxisY/types.d.ts +16 -4
  68. package/dist/esm/components/AxisY/utils.js +1 -8
  69. package/dist/esm/components/ChartInner/index.js +66 -50
  70. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +7 -7
  71. package/dist/esm/components/ChartInner/useChartInnerProps.js +15 -20
  72. package/dist/esm/components/ChartInner/useChartInnerState.d.ts +3 -2
  73. package/dist/esm/components/ChartInner/useChartInnerState.js +23 -4
  74. package/dist/esm/components/RangeSlider/index.d.ts +5 -3
  75. package/dist/esm/components/RangeSlider/index.js +36 -4
  76. package/dist/esm/components/Title/index.js +2 -2
  77. package/dist/esm/components/utils.d.ts +9 -0
  78. package/dist/esm/components/utils.js +34 -0
  79. package/dist/esm/constants/defaults/axis.js +1 -1
  80. package/dist/esm/hooks/index.d.ts +0 -1
  81. package/dist/esm/hooks/index.js +0 -1
  82. package/dist/esm/hooks/useAxis/index.js +10 -0
  83. package/dist/esm/hooks/useAxis/types.d.ts +3 -0
  84. package/dist/esm/hooks/useAxis/x-axis.d.ts +2 -1
  85. package/dist/esm/hooks/useAxis/x-axis.js +42 -32
  86. package/dist/esm/hooks/useAxis/y-axis.js +38 -11
  87. package/dist/esm/hooks/useAxisScales/index.d.ts +4 -1
  88. package/dist/esm/hooks/useAxisScales/index.js +8 -7
  89. package/dist/esm/hooks/useAxisScales/utils.d.ts +6 -0
  90. package/dist/esm/hooks/useAxisScales/utils.js +17 -0
  91. package/dist/esm/hooks/useChartDimensions/utils.js +7 -1
  92. package/dist/esm/hooks/useNormalizedOriginalData/index.d.ts +1 -7
  93. package/dist/esm/hooks/useRangeSlider/index.js +1 -2
  94. package/dist/esm/hooks/useRangeSlider/types.d.ts +1 -3
  95. package/dist/esm/hooks/useSplit/index.js +6 -2
  96. package/dist/esm/hooks/useZoom/index.d.ts +1 -0
  97. package/dist/esm/hooks/useZoom/index.js +12 -2
  98. package/dist/esm/types/chart/axis.d.ts +45 -17
  99. package/dist/esm/types/chart/title.d.ts +3 -0
  100. package/dist/{cjs/utils/chart/axis.d.ts → esm/utils/chart/axis/common.d.ts} +4 -16
  101. package/dist/{cjs/utils/chart/axis.js → esm/utils/chart/axis/common.js} +7 -40
  102. package/dist/esm/utils/chart/axis/x-axis.d.ts +12 -0
  103. package/dist/esm/utils/chart/axis/x-axis.js +78 -0
  104. package/dist/esm/utils/chart/axis-generators/bottom.js +1 -1
  105. package/dist/esm/utils/chart/index.d.ts +1 -1
  106. package/dist/esm/utils/chart/index.js +1 -1
  107. package/dist/esm/utils/chart/text.d.ts +0 -6
  108. package/dist/esm/utils/chart/text.js +7 -19
  109. package/package.json +1 -1
  110. package/dist/cjs/hooks/useChartOptions/index.d.ts +0 -16
  111. package/dist/cjs/hooks/useChartOptions/index.js +0 -21
  112. package/dist/esm/hooks/useChartOptions/index.d.ts +0 -16
  113. package/dist/esm/hooks/useChartOptions/index.js +0 -21
@@ -1,26 +1,11 @@
1
1
  import React from 'react';
2
- import type { ChartScale, PreparedSplit, PreparedXAxis } from '../../hooks';
2
+ import type { AxisXData } from './types';
3
3
  import './styles.css';
4
- type Props = {
5
- axis: PreparedXAxis;
6
- boundsOffsetLeft: number;
7
- boundsOffsetTop: number;
8
- height: number;
4
+ interface Props {
5
+ preparedAxisData: AxisXData;
9
6
  htmlLayout: HTMLElement | null;
10
- scale: ChartScale;
11
- split: PreparedSplit;
12
- width: number;
13
- leftmostLimit?: number;
14
7
  plotBeforeRef?: React.MutableRefObject<SVGGElement | null>;
15
8
  plotAfterRef?: React.MutableRefObject<SVGGElement | null>;
16
- };
17
- export declare function getTitlePosition(args: {
18
- axis: PreparedXAxis;
19
- width: number;
20
- rowCount: number;
21
- }): {
22
- x: number;
23
- y: number;
24
- };
25
- export declare const AxisX: React.NamedExoticComponent<Props>;
9
+ }
10
+ export declare const AxisX: (props: Props) => React.JSX.Element;
26
11
  export {};
@@ -1,227 +1,182 @@
1
1
  import React from 'react';
2
2
  import { line, select } from 'd3';
3
- import { block, getAxisTitleRows, getBandsPosition, getLabelFormatter, getLineDashArray, getMaxTickCount, getTicksCount, handleOverflowingText, } from '../../utils';
4
- import { axisBottom } from '../../utils/chart/axis-generators';
3
+ import { HtmlLayer } from '../../hooks/useShapes/HtmlLayer';
4
+ import { block, getLineDashArray } from '../../utils';
5
5
  import './styles.css';
6
- const b = block('axis');
7
- export function getTitlePosition(args) {
8
- const { axis, width, rowCount } = args;
9
- if (rowCount < 1) {
10
- return { x: 0, y: 0 };
11
- }
12
- let x;
13
- const y = axis.title.height / rowCount + axis.title.margin + axis.labels.height + axis.labels.margin;
14
- switch (axis.title.align) {
15
- case 'left': {
16
- x = axis.title.width / 2;
17
- break;
6
+ const b = block('x-axis');
7
+ export const AxisX = (props) => {
8
+ const { htmlLayout, plotBeforeRef, plotAfterRef, preparedAxisData } = props;
9
+ const ref = React.useRef(null);
10
+ const lineGenerator = line();
11
+ const htmlLabels = preparedAxisData.ticks.map((d) => d.htmlLabel).filter(Boolean);
12
+ React.useEffect(() => {
13
+ if (!ref.current) {
14
+ return;
18
15
  }
19
- case 'right': {
20
- x = width - axis.title.width / 2;
21
- break;
16
+ const svgElement = select(ref.current);
17
+ svgElement.selectAll('*').remove();
18
+ let plotBeforeContainer = null;
19
+ let plotAfterContainer = null;
20
+ const plotDataAttr = 'data-plot-x';
21
+ if (plotBeforeRef === null || plotBeforeRef === void 0 ? void 0 : plotBeforeRef.current) {
22
+ plotBeforeContainer = select(plotBeforeRef.current);
23
+ plotBeforeContainer.selectAll(`[${plotDataAttr}]`).remove();
22
24
  }
23
- case 'center': {
24
- x = width / 2;
25
- break;
25
+ if (plotAfterRef === null || plotAfterRef === void 0 ? void 0 : plotAfterRef.current) {
26
+ plotAfterContainer = select(plotAfterRef.current);
27
+ plotAfterContainer.selectAll(`[${plotDataAttr}]`).remove();
26
28
  }
27
- }
28
- return { x, y };
29
- }
30
- export const AxisX = React.memo(function AxisX(props) {
31
- const { axis, boundsOffsetLeft, boundsOffsetTop, height: totalHeight, htmlLayout, leftmostLimit, plotAfterRef, plotBeforeRef, split, scale, width, } = props;
32
- const ref = React.useRef(null);
33
- React.useEffect(() => {
34
- (async () => {
35
- if (!ref.current || !htmlLayout) {
36
- return;
37
- }
38
- const svgElement = select(ref.current);
39
- svgElement.selectAll('*').remove();
40
- if (!axis.visible) {
41
- return;
42
- }
43
- let tickItems = [];
44
- if (axis.grid.enabled) {
45
- tickItems = new Array(split.plots.length || 1).fill(null).map((_, index) => {
46
- var _a, _b;
47
- const top = ((_a = split.plots[index]) === null || _a === void 0 ? void 0 : _a.top) || 0;
48
- const height = ((_b = split.plots[index]) === null || _b === void 0 ? void 0 : _b.height) || totalHeight;
49
- return [-top, -(top + height)];
50
- });
29
+ if (preparedAxisData.title) {
30
+ svgElement
31
+ .append('g')
32
+ .attr('class', b('title'))
33
+ .append('text')
34
+ .attr('text-anchor', 'start')
35
+ .style('dominant-baseline', 'text-after-edge')
36
+ .style('transform', `translate(${preparedAxisData.title.x}px, ${preparedAxisData.title.y}px) rotate(${preparedAxisData.title.rotate}deg) translate(0px, ${preparedAxisData.title.offset}px)`)
37
+ .attr('font-size', preparedAxisData.title.style.fontSize)
38
+ .selectAll('tspan')
39
+ .data(preparedAxisData.title.content)
40
+ .join('tspan')
41
+ .html((d) => d.text)
42
+ .attr('x', (d) => d.x)
43
+ .attr('y', (d) => d.y)
44
+ .attr('text-anchor', 'start');
45
+ }
46
+ if (preparedAxisData.domain) {
47
+ svgElement
48
+ .append('path')
49
+ .attr('class', b('domain'))
50
+ .attr('d', lineGenerator([preparedAxisData.domain.start, preparedAxisData.domain.end]))
51
+ .style('stroke', preparedAxisData.domain.lineColor);
52
+ }
53
+ const tickClassName = b('tick');
54
+ const ticks = svgElement
55
+ .selectAll(`.${tickClassName}`)
56
+ .remove()
57
+ .data(preparedAxisData.ticks)
58
+ .join('g')
59
+ .attr('class', tickClassName);
60
+ const labelClassName = b('label');
61
+ ticks.each(function () {
62
+ var _a;
63
+ const tickSelection = select(this);
64
+ const tickData = tickSelection.datum();
65
+ if (tickData.line) {
66
+ tickSelection.append('path').attr('d', lineGenerator(tickData.line.points));
51
67
  }
52
- const axisScale = scale;
53
- const xAxisGenerator = await axisBottom({
54
- boundsOffsetLeft,
55
- boundsOffsetTop,
56
- domain: {
57
- size: width,
58
- color: axis.lineColor,
59
- },
60
- htmlLayout,
61
- leftmostLimit,
62
- scale: axisScale,
63
- ticks: {
64
- count: getTicksCount({ axis, range: width }),
65
- labelsHtml: axis.labels.html,
66
- items: tickItems,
67
- labelFormat: getLabelFormatter({ axis, scale }),
68
- labelsHeight: axis.labels.height,
69
- labelsLineHeight: axis.labels.lineHeight,
70
- labelsMargin: axis.labels.margin,
71
- labelsMaxWidth: axis.labels.maxWidth,
72
- labelsPaddings: axis.labels.padding,
73
- labelsStyle: axis.labels.style,
74
- maxTickCount: getMaxTickCount({ axis, width }),
75
- rotation: axis.labels.rotation,
76
- },
77
- });
78
- svgElement.call(xAxisGenerator).attr('class', b());
79
- // add an axis header if necessary
80
- if (axis.title.text) {
81
- const titleRows = await getAxisTitleRows({ axis, textMaxWidth: width });
82
- const titleClassName = b('title');
83
- svgElement.selectAll(`.${titleClassName}`).remove();
84
- svgElement
68
+ if (tickData.svgLabel) {
69
+ const label = tickData.svgLabel;
70
+ const textSelection = tickSelection
85
71
  .append('text')
86
- .attr('class', titleClassName)
87
- .attr('transform', () => {
88
- const { x, y } = getTitlePosition({ axis, width, rowCount: titleRows.length });
89
- return `translate(${x}, ${y})`;
90
- })
91
- .attr('font-size', axis.title.style.fontSize)
92
- .attr('text-anchor', 'middle')
72
+ .style('transform', [
73
+ `translate(${label.x}px, ${label.y}px)`,
74
+ label.angle ? `rotate(${label.angle}deg)` : '',
75
+ ]
76
+ .filter(Boolean)
77
+ .join(' '));
78
+ if (label.title) {
79
+ textSelection.append('title').html(label.title);
80
+ }
81
+ textSelection
93
82
  .selectAll('tspan')
94
- .data(titleRows)
83
+ .data(label.content)
95
84
  .join('tspan')
96
- .attr('x', 0)
85
+ .html((d) => d.text)
86
+ .attr('x', (d) => d.x)
97
87
  .attr('y', (d) => d.y)
98
- .text((d) => d.text)
99
- .each((_d, index, nodes) => {
100
- if (index === axis.title.maxRowCount - 1) {
101
- handleOverflowingText(nodes[index], width);
102
- }
103
- });
88
+ .attr('text-anchor', 'start')
89
+ .attr('class', labelClassName)
90
+ .style('dominant-baseline', 'text-before-edge')
91
+ .style('font-size', label.style.fontSize)
92
+ .style('fill', (_a = label.style.fontColor) !== null && _a !== void 0 ? _a : '');
104
93
  }
105
- const plotDataAttr = 'data-plot-x';
106
- let plotBeforeContainer = null;
107
- let plotAfterContainer = null;
108
- if (plotBeforeRef === null || plotBeforeRef === void 0 ? void 0 : plotBeforeRef.current) {
109
- plotBeforeContainer = select(plotBeforeRef.current);
110
- plotBeforeContainer.selectAll(`[${plotDataAttr}]`).remove();
111
- }
112
- if (plotAfterRef === null || plotAfterRef === void 0 ? void 0 : plotAfterRef.current) {
113
- plotAfterContainer = select(plotAfterRef.current);
114
- plotAfterContainer.selectAll(`[${plotDataAttr}]`).remove();
115
- }
116
- // add plot bands
117
- if (axis.plotBands.length > 0) {
118
- const plotBandDataAttr = 'plot-x-band';
119
- const setPlotBands = (plotContainer, plotBands) => {
120
- if (!plotContainer || !plotBands.length) {
121
- return;
122
- }
123
- const plotBandsSelection = plotContainer
124
- .selectAll(`[${plotBandDataAttr}]`)
125
- .remove()
126
- .data(plotBands)
127
- .join('g')
128
- .attr(plotDataAttr, 1)
129
- .attr(plotBandDataAttr, 1);
130
- plotBandsSelection.each(function () {
131
- var _a, _b, _c, _e;
132
- const plotBandSelection = select(this);
133
- const band = plotBandSelection.datum();
134
- const { from, to } = getBandsPosition({ band, axisScale, axis: 'x' });
135
- const halfBandwidth = ((_b = (_a = axisScale.bandwidth) === null || _a === void 0 ? void 0 : _a.call(axisScale)) !== null && _b !== void 0 ? _b : 0) / 2;
136
- const startPos = halfBandwidth + Math.min(from, to);
137
- const x = Math.max(0, startPos);
94
+ });
95
+ if (preparedAxisData.plotBands.length > 0) {
96
+ const plotBandDataAttr = `data-plot-x-band-${preparedAxisData.id}`;
97
+ const setPlotBands = (plotContainer, plotBands) => {
98
+ if (!plotContainer || !plotBands.length) {
99
+ return;
100
+ }
101
+ const plotBandsSelection = plotContainer
102
+ .selectAll(`[${plotBandDataAttr}]`)
103
+ .remove()
104
+ .data(plotBands)
105
+ .join('g')
106
+ .attr(plotDataAttr, 1)
107
+ .attr(plotBandDataAttr, 1)
108
+ .style('transform', (d) => `translate(${d.x}px, ${d.y}px)`);
109
+ plotBandsSelection
110
+ .append('rect')
111
+ .attr('width', (d) => d.width)
112
+ .attr('height', (d) => d.height)
113
+ .attr('fill', (d) => d.color)
114
+ .attr('opacity', (d) => d.opacity);
115
+ plotBandsSelection.each(function () {
116
+ var _a, _b;
117
+ const plotBandSelection = select(this);
118
+ const band = plotBandSelection.datum();
119
+ const label = band.label;
120
+ if (label) {
138
121
  plotBandSelection
139
- .append('rect')
140
- .attr('x', x)
141
- .attr('width', () => {
142
- const endPos = Math.min(Math.abs(to - from), width - Math.min(from, to));
143
- return Math.min(endPos, width);
144
- })
145
- .attr('y', 0)
146
- .attr('height', totalHeight)
147
- .attr('fill', () => band.color)
148
- .attr('opacity', () => band.opacity);
149
- if (band.label.text) {
150
- const labelPadding = (_e = (_c = band.label) === null || _c === void 0 ? void 0 : _c.padding) !== null && _e !== void 0 ? _e : 0;
151
- plotBandSelection
152
- .append('text')
153
- .text(band.label.text)
154
- .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; })
155
- .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; })
156
- .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; })
157
- .style('dominant-baseline', 'text-before-edge')
158
- .style('text-anchor', 'end')
159
- .style('transform', `translate(${x + labelPadding}px, ${labelPadding}px) rotate(-90deg)`);
160
- }
161
- });
162
- };
163
- setPlotBands(plotBeforeContainer, axis.plotBands.filter((d) => d.layerPlacement === 'before'));
164
- setPlotBands(plotAfterContainer, axis.plotBands.filter((d) => d.layerPlacement === 'after'));
165
- }
166
- // add plot lines
167
- if (axis.plotLines.length > 0) {
168
- const plotLineDataAttr = 'plot-x-line';
169
- const setPlotLines = (plotContainer, plotLines) => {
170
- if (!plotContainer || !plotLines.length) {
171
- return;
122
+ .append('text')
123
+ .html(label.text)
124
+ .style('fill', (_a = label.style.fontColor) !== null && _a !== void 0 ? _a : '')
125
+ .style('font-size', label.style.fontSize)
126
+ .style('font-weight', (_b = label.style.fontWeight) !== null && _b !== void 0 ? _b : '')
127
+ .style('dominant-baseline', 'text-before-edge')
128
+ .style('text-anchor', 'start')
129
+ .style('transform', `translate(${label.x}px, ${label.y}px) rotate(${label.rotate}deg)`);
172
130
  }
173
- const plotLinesSelection = plotContainer
174
- .selectAll(`[${plotLineDataAttr}]`)
175
- .remove()
176
- .data(plotLines)
177
- .join('g')
178
- .attr(plotDataAttr, 1)
179
- .attr(plotLineDataAttr, 1);
180
- const lineGenerator = line();
181
- plotLinesSelection.each(function () {
182
- const itemSelection = select(this);
183
- const plotLine = itemSelection.datum();
184
- const plotLineValue = Number(axisScale(plotLine.value));
185
- const points = [
186
- [plotLineValue, 0],
187
- [plotLineValue, totalHeight],
188
- ];
131
+ });
132
+ };
133
+ setPlotBands(plotBeforeContainer, preparedAxisData.plotBands.filter((item) => item.layerPlacement === 'before'));
134
+ setPlotBands(plotAfterContainer, preparedAxisData.plotBands.filter((item) => item.layerPlacement === 'after'));
135
+ }
136
+ if (preparedAxisData.plotLines.length > 0) {
137
+ const plotLineDataAttr = `data-plot-x-line-${preparedAxisData.id}`;
138
+ const setPlotLines = (plotContainer, plotLines) => {
139
+ if (!plotContainer || !plotLines.length) {
140
+ return;
141
+ }
142
+ const plotLinesSelection = plotContainer
143
+ .selectAll(`[${plotLineDataAttr}]`)
144
+ .remove()
145
+ .data(plotLines)
146
+ .join('g')
147
+ .attr(plotDataAttr, 1)
148
+ .attr(plotLineDataAttr, 1)
149
+ .style('transform', (d) => `translate(${d.x}px, ${d.y}px)`);
150
+ plotLinesSelection
151
+ .append('path')
152
+ .attr('d', (d) => lineGenerator(d.points))
153
+ .attr('stroke', (d) => d.color)
154
+ .attr('stroke-width', (d) => d.lineWidth)
155
+ .attr('stroke-dasharray', (d) => getLineDashArray(d.dashStyle, d.lineWidth))
156
+ .attr('opacity', (d) => d.opacity);
157
+ plotLinesSelection.each(function () {
158
+ var _a, _b;
159
+ const itemSelection = select(this);
160
+ const plotLine = itemSelection.datum();
161
+ const label = plotLine.label;
162
+ if (label) {
189
163
  itemSelection
190
- .append('path')
191
- .attr('d', lineGenerator(points))
192
- .attr('stroke', plotLine.color)
193
- .attr('stroke-width', plotLine.width)
194
- .attr('stroke-dasharray', getLineDashArray(plotLine.dashStyle, plotLine.width))
195
- .attr('opacity', plotLine.opacity);
196
- if (plotLine.label.text) {
197
- itemSelection
198
- .append('text')
199
- .text(plotLine.label.text)
200
- .style('fill', () => { var _a; return (_a = plotLine.label.style.fontColor) !== null && _a !== void 0 ? _a : null; })
201
- .attr('font-size', plotLine.label.style.fontSize)
202
- .style('font-weight', () => { var _a; return (_a = plotLine.label.style.fontWeight) !== null && _a !== void 0 ? _a : null; })
203
- .style('dominant-baseline', 'text-after-edge')
204
- .style('text-anchor', 'end')
205
- .style('transform', `translate(${plotLineValue - plotLine.label.padding}px, ${plotLine.label.padding}px) rotate(-90deg)`);
206
- }
207
- });
208
- };
209
- setPlotLines(plotBeforeContainer, axis.plotLines.filter((d) => d.layerPlacement === 'before'));
210
- setPlotLines(plotAfterContainer, axis.plotLines.filter((d) => d.layerPlacement === 'after'));
211
- }
212
- })();
213
- }, [
214
- axis,
215
- boundsOffsetLeft,
216
- boundsOffsetTop,
217
- htmlLayout,
218
- leftmostLimit,
219
- plotAfterRef,
220
- plotBeforeRef,
221
- scale,
222
- split,
223
- totalHeight,
224
- width,
225
- ]);
226
- return React.createElement("g", { ref: ref });
227
- });
164
+ .append('text')
165
+ .text(label.text)
166
+ .style('fill', (_a = label.style.fontColor) !== null && _a !== void 0 ? _a : '')
167
+ .style('font-size', label.style.fontSize)
168
+ .style('font-weight', (_b = label.style.fontWeight) !== null && _b !== void 0 ? _b : '')
169
+ .style('dominant-baseline', 'text-before-edge')
170
+ .style('text-anchor', 'start')
171
+ .style('transform', `translate(${label.x}px, ${label.y}px) rotate(${label.rotate}deg)`);
172
+ }
173
+ });
174
+ };
175
+ setPlotLines(plotBeforeContainer, preparedAxisData.plotLines.filter((item) => item.layerPlacement === 'before'));
176
+ setPlotLines(plotAfterContainer, preparedAxisData.plotLines.filter((item) => item.layerPlacement === 'after'));
177
+ }
178
+ }, [lineGenerator, plotAfterRef, plotBeforeRef, preparedAxisData]);
179
+ return (React.createElement(React.Fragment, null,
180
+ React.createElement(HtmlLayer, { preparedData: { htmlElements: htmlLabels }, htmlLayout: htmlLayout }),
181
+ React.createElement("g", { ref: ref, className: b() })));
182
+ };
@@ -0,0 +1,12 @@
1
+ import type { ChartScale, PreparedAxis, PreparedSplit } from '../../hooks';
2
+ import type { AxisXData } from './types';
3
+ export declare function prepareXAxisData({ axis, yAxis, scale, boundsWidth, boundsOffsetLeft, boundsOffsetRight, height, split, }: {
4
+ axis: PreparedAxis;
5
+ yAxis: PreparedAxis[];
6
+ scale: ChartScale;
7
+ boundsWidth: number;
8
+ boundsOffsetLeft: number;
9
+ boundsOffsetRight: number;
10
+ height: number;
11
+ split: PreparedSplit;
12
+ }): Promise<AxisXData[]>;