@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.
- package/dist/cjs/components/AxisX/AxisX.d.ts +5 -20
- package/dist/cjs/components/AxisX/AxisX.js +167 -212
- package/dist/cjs/components/AxisX/prepare-axis-data.d.ts +12 -0
- package/dist/cjs/components/AxisX/prepare-axis-data.js +310 -0
- package/dist/cjs/components/AxisX/styles.css +7 -10
- package/dist/cjs/components/AxisX/types.d.ts +85 -0
- package/dist/cjs/components/AxisX/types.js +1 -0
- package/dist/cjs/components/AxisY/AxisY.js +9 -3
- package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +1 -1
- package/dist/cjs/components/AxisY/prepare-axis-data.js +17 -81
- package/dist/cjs/components/AxisY/prepare-axis-title.d.ts +16 -0
- package/dist/cjs/components/AxisY/prepare-axis-title.js +149 -0
- package/dist/cjs/components/AxisY/types.d.ts +16 -4
- package/dist/cjs/components/AxisY/utils.js +1 -8
- package/dist/cjs/components/ChartInner/index.js +66 -50
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +7 -7
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +15 -20
- package/dist/cjs/components/ChartInner/useChartInnerState.d.ts +3 -2
- package/dist/cjs/components/ChartInner/useChartInnerState.js +23 -4
- package/dist/cjs/components/RangeSlider/index.d.ts +5 -3
- package/dist/cjs/components/RangeSlider/index.js +36 -4
- package/dist/cjs/components/Title/index.js +2 -2
- package/dist/cjs/components/utils.d.ts +9 -0
- package/dist/cjs/components/utils.js +34 -0
- package/dist/cjs/constants/defaults/axis.js +1 -1
- package/dist/cjs/hooks/index.d.ts +0 -1
- package/dist/cjs/hooks/index.js +0 -1
- package/dist/cjs/hooks/useAxis/index.js +10 -0
- package/dist/cjs/hooks/useAxis/types.d.ts +3 -0
- package/dist/cjs/hooks/useAxis/x-axis.d.ts +2 -1
- package/dist/cjs/hooks/useAxis/x-axis.js +42 -32
- package/dist/cjs/hooks/useAxis/y-axis.js +38 -11
- package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -1
- package/dist/cjs/hooks/useAxisScales/index.js +8 -7
- package/dist/cjs/hooks/useAxisScales/utils.d.ts +6 -0
- package/dist/cjs/hooks/useAxisScales/utils.js +17 -0
- package/dist/cjs/hooks/useChartDimensions/utils.js +7 -1
- package/dist/cjs/hooks/useNormalizedOriginalData/index.d.ts +1 -7
- package/dist/cjs/hooks/useRangeSlider/index.js +1 -2
- package/dist/cjs/hooks/useRangeSlider/types.d.ts +1 -3
- package/dist/cjs/hooks/useSplit/index.js +6 -2
- package/dist/cjs/hooks/useZoom/index.d.ts +1 -0
- package/dist/cjs/hooks/useZoom/index.js +12 -2
- package/dist/cjs/types/chart/axis.d.ts +45 -17
- package/dist/cjs/types/chart/title.d.ts +3 -0
- package/dist/{esm/utils/chart/axis.d.ts → cjs/utils/chart/axis/common.d.ts} +4 -16
- package/dist/{esm/utils/chart/axis.js → cjs/utils/chart/axis/common.js} +7 -40
- package/dist/cjs/utils/chart/axis/x-axis.d.ts +12 -0
- package/dist/cjs/utils/chart/axis/x-axis.js +78 -0
- package/dist/cjs/utils/chart/axis-generators/bottom.js +1 -1
- package/dist/cjs/utils/chart/index.d.ts +1 -1
- package/dist/cjs/utils/chart/index.js +1 -1
- package/dist/cjs/utils/chart/text.d.ts +0 -6
- package/dist/cjs/utils/chart/text.js +7 -19
- package/dist/esm/components/AxisX/AxisX.d.ts +5 -20
- package/dist/esm/components/AxisX/AxisX.js +167 -212
- package/dist/esm/components/AxisX/prepare-axis-data.d.ts +12 -0
- package/dist/esm/components/AxisX/prepare-axis-data.js +310 -0
- package/dist/esm/components/AxisX/styles.css +7 -10
- package/dist/esm/components/AxisX/types.d.ts +85 -0
- package/dist/esm/components/AxisX/types.js +1 -0
- package/dist/esm/components/AxisY/AxisY.js +9 -3
- package/dist/esm/components/AxisY/prepare-axis-data.d.ts +1 -1
- package/dist/esm/components/AxisY/prepare-axis-data.js +17 -81
- package/dist/esm/components/AxisY/prepare-axis-title.d.ts +16 -0
- package/dist/esm/components/AxisY/prepare-axis-title.js +149 -0
- package/dist/esm/components/AxisY/types.d.ts +16 -4
- package/dist/esm/components/AxisY/utils.js +1 -8
- package/dist/esm/components/ChartInner/index.js +66 -50
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +7 -7
- package/dist/esm/components/ChartInner/useChartInnerProps.js +15 -20
- package/dist/esm/components/ChartInner/useChartInnerState.d.ts +3 -2
- package/dist/esm/components/ChartInner/useChartInnerState.js +23 -4
- package/dist/esm/components/RangeSlider/index.d.ts +5 -3
- package/dist/esm/components/RangeSlider/index.js +36 -4
- package/dist/esm/components/Title/index.js +2 -2
- package/dist/esm/components/utils.d.ts +9 -0
- package/dist/esm/components/utils.js +34 -0
- package/dist/esm/constants/defaults/axis.js +1 -1
- package/dist/esm/hooks/index.d.ts +0 -1
- package/dist/esm/hooks/index.js +0 -1
- package/dist/esm/hooks/useAxis/index.js +10 -0
- package/dist/esm/hooks/useAxis/types.d.ts +3 -0
- package/dist/esm/hooks/useAxis/x-axis.d.ts +2 -1
- package/dist/esm/hooks/useAxis/x-axis.js +42 -32
- package/dist/esm/hooks/useAxis/y-axis.js +38 -11
- package/dist/esm/hooks/useAxisScales/index.d.ts +4 -1
- package/dist/esm/hooks/useAxisScales/index.js +8 -7
- package/dist/esm/hooks/useAxisScales/utils.d.ts +6 -0
- package/dist/esm/hooks/useAxisScales/utils.js +17 -0
- package/dist/esm/hooks/useChartDimensions/utils.js +7 -1
- package/dist/esm/hooks/useNormalizedOriginalData/index.d.ts +1 -7
- package/dist/esm/hooks/useRangeSlider/index.js +1 -2
- package/dist/esm/hooks/useRangeSlider/types.d.ts +1 -3
- package/dist/esm/hooks/useSplit/index.js +6 -2
- package/dist/esm/hooks/useZoom/index.d.ts +1 -0
- package/dist/esm/hooks/useZoom/index.js +12 -2
- package/dist/esm/types/chart/axis.d.ts +45 -17
- package/dist/esm/types/chart/title.d.ts +3 -0
- package/dist/{cjs/utils/chart/axis.d.ts → esm/utils/chart/axis/common.d.ts} +4 -16
- package/dist/{cjs/utils/chart/axis.js → esm/utils/chart/axis/common.js} +7 -40
- package/dist/esm/utils/chart/axis/x-axis.d.ts +12 -0
- package/dist/esm/utils/chart/axis/x-axis.js +78 -0
- package/dist/esm/utils/chart/axis-generators/bottom.js +1 -1
- package/dist/esm/utils/chart/index.d.ts +1 -1
- package/dist/esm/utils/chart/index.js +1 -1
- package/dist/esm/utils/chart/text.d.ts +0 -6
- package/dist/esm/utils/chart/text.js +7 -19
- package/package.json +1 -1
- package/dist/cjs/hooks/useChartOptions/index.d.ts +0 -16
- package/dist/cjs/hooks/useChartOptions/index.js +0 -21
- package/dist/esm/hooks/useChartOptions/index.d.ts +0 -16
- package/dist/esm/hooks/useChartOptions/index.js +0 -21
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AxisXData } from './types';
|
|
3
3
|
import './styles.css';
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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 {
|
|
4
|
-
import {
|
|
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
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
.
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
.
|
|
92
|
-
|
|
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(
|
|
83
|
+
.data(label.content)
|
|
95
84
|
.join('tspan')
|
|
96
|
-
.
|
|
85
|
+
.html((d) => d.text)
|
|
86
|
+
.attr('x', (d) => d.x)
|
|
97
87
|
.attr('y', (d) => d.y)
|
|
98
|
-
.text
|
|
99
|
-
.
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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('
|
|
140
|
-
.
|
|
141
|
-
.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
.
|
|
146
|
-
.
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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('
|
|
191
|
-
.
|
|
192
|
-
.
|
|
193
|
-
.
|
|
194
|
-
.
|
|
195
|
-
.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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[]>;
|