@gravity-ui/charts 1.16.0 → 1.18.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.
- package/dist/{esm/components/Axis → cjs/components/AxisX}/AxisX.js +1 -15
- package/dist/{esm/components/Axis → cjs/components/AxisY}/AxisY.d.ts +2 -10
- package/dist/cjs/components/AxisY/AxisY.js +173 -0
- package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +10 -0
- package/dist/cjs/components/AxisY/prepare-axis-data.js +307 -0
- package/dist/cjs/components/AxisY/styles.css +15 -0
- package/dist/cjs/components/AxisY/types.d.ts +81 -0
- package/dist/cjs/components/AxisY/types.js +1 -0
- package/dist/cjs/components/AxisY/utils.d.ts +12 -0
- package/dist/cjs/components/AxisY/utils.js +62 -0
- package/dist/cjs/components/ChartInner/index.js +39 -6
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +1 -1
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +15 -1
- package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -0
- package/dist/cjs/components/Tooltip/ChartTooltipContent.js +2 -2
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.d.ts +2 -1
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +8 -5
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.d.ts +11 -4
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.js +17 -15
- package/dist/cjs/components/Tooltip/index.js +1 -1
- package/dist/cjs/constants/date.d.ts +1 -0
- package/dist/cjs/constants/date.js +1 -0
- package/dist/cjs/constants/index.d.ts +1 -0
- package/dist/cjs/constants/index.js +1 -0
- package/dist/cjs/hooks/useAxisScales/index.d.ts +3 -3
- package/dist/cjs/hooks/useAxisScales/index.js +40 -7
- package/dist/cjs/hooks/useChartOptions/index.d.ts +3 -1
- package/dist/cjs/hooks/useChartOptions/index.js +3 -3
- package/dist/cjs/hooks/useChartOptions/tooltip.d.ts +4 -1
- package/dist/cjs/hooks/useChartOptions/tooltip.js +18 -3
- package/dist/cjs/hooks/useChartOptions/types.d.ts +7 -1
- package/dist/cjs/hooks/useChartOptions/x-axis.js +23 -11
- package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +3 -1
- package/dist/cjs/hooks/useChartOptions/y-axis.js +30 -17
- package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
- package/dist/cjs/hooks/useCrosshair/index.js +4 -2
- package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +3 -0
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +3 -0
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +8 -1
- package/dist/cjs/hooks/useShapes/index.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +3 -0
- package/dist/cjs/hooks/useShapes/scatter/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +6 -0
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +6 -3
- package/dist/cjs/hooks/useZoom/index.d.ts +1 -1
- package/dist/cjs/hooks/useZoom/types.d.ts +1 -1
- package/dist/cjs/hooks/useZoom/utils.d.ts +1 -1
- package/dist/cjs/hooks/useZoom/utils.js +22 -10
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/types/chart/axis.d.ts +11 -1
- package/dist/cjs/types/chart/base.d.ts +1 -0
- package/dist/cjs/types/chart/tooltip.d.ts +3 -0
- package/dist/cjs/utils/chart/array.d.ts +1 -0
- package/dist/cjs/utils/chart/array.js +9 -0
- package/dist/cjs/utils/chart/axis-generators/bottom.js +3 -3
- package/dist/cjs/utils/chart/axis.d.ts +14 -8
- package/dist/cjs/utils/chart/axis.js +34 -9
- package/dist/cjs/utils/chart/format.js +2 -1
- package/dist/cjs/utils/chart/index.d.ts +1 -7
- package/dist/cjs/utils/chart/index.js +1 -17
- package/dist/cjs/utils/chart/text.d.ts +2 -1
- package/dist/cjs/utils/chart/text.js +3 -10
- package/dist/cjs/utils/chart/zoom.js +14 -8
- package/dist/{cjs/components/Axis → esm/components/AxisX}/AxisX.js +1 -15
- package/dist/{cjs/components/Axis → esm/components/AxisY}/AxisY.d.ts +2 -10
- package/dist/esm/components/AxisY/AxisY.js +173 -0
- package/dist/esm/components/AxisY/prepare-axis-data.d.ts +10 -0
- package/dist/esm/components/AxisY/prepare-axis-data.js +307 -0
- package/dist/esm/components/AxisY/styles.css +15 -0
- package/dist/esm/components/AxisY/types.d.ts +81 -0
- package/dist/esm/components/AxisY/types.js +1 -0
- package/dist/esm/components/AxisY/utils.d.ts +12 -0
- package/dist/esm/components/AxisY/utils.js +62 -0
- package/dist/esm/components/ChartInner/index.js +39 -6
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +1 -1
- package/dist/esm/components/ChartInner/useChartInnerProps.js +15 -1
- package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -0
- package/dist/esm/components/Tooltip/ChartTooltipContent.js +2 -2
- package/dist/esm/components/Tooltip/DefaultTooltipContent/index.d.ts +2 -1
- package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +8 -5
- package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.d.ts +11 -4
- package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.js +17 -15
- package/dist/esm/components/Tooltip/index.js +1 -1
- package/dist/esm/constants/date.d.ts +1 -0
- package/dist/esm/constants/date.js +1 -0
- package/dist/esm/constants/index.d.ts +1 -0
- package/dist/esm/constants/index.js +1 -0
- package/dist/esm/hooks/useAxisScales/index.d.ts +3 -3
- package/dist/esm/hooks/useAxisScales/index.js +40 -7
- package/dist/esm/hooks/useChartOptions/index.d.ts +3 -1
- package/dist/esm/hooks/useChartOptions/index.js +3 -3
- package/dist/esm/hooks/useChartOptions/tooltip.d.ts +4 -1
- package/dist/esm/hooks/useChartOptions/tooltip.js +18 -3
- package/dist/esm/hooks/useChartOptions/types.d.ts +7 -1
- package/dist/esm/hooks/useChartOptions/x-axis.js +23 -11
- package/dist/esm/hooks/useChartOptions/y-axis.d.ts +3 -1
- package/dist/esm/hooks/useChartOptions/y-axis.js +30 -17
- package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
- package/dist/esm/hooks/useCrosshair/index.js +4 -2
- package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/area/prepare-data.js +3 -0
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +3 -0
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +8 -1
- package/dist/esm/hooks/useShapes/index.d.ts +1 -1
- package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/line/prepare-data.js +3 -0
- package/dist/esm/hooks/useShapes/scatter/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/scatter/prepare-data.js +6 -0
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +6 -3
- package/dist/esm/hooks/useZoom/index.d.ts +1 -1
- package/dist/esm/hooks/useZoom/types.d.ts +1 -1
- package/dist/esm/hooks/useZoom/utils.d.ts +1 -1
- package/dist/esm/hooks/useZoom/utils.js +22 -10
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/types/chart/axis.d.ts +11 -1
- package/dist/esm/types/chart/base.d.ts +1 -0
- package/dist/esm/types/chart/tooltip.d.ts +3 -0
- package/dist/esm/utils/chart/array.d.ts +1 -0
- package/dist/esm/utils/chart/array.js +9 -0
- package/dist/esm/utils/chart/axis-generators/bottom.js +3 -3
- package/dist/esm/utils/chart/axis.d.ts +14 -8
- package/dist/esm/utils/chart/axis.js +34 -9
- package/dist/esm/utils/chart/format.js +2 -1
- package/dist/esm/utils/chart/index.d.ts +1 -7
- package/dist/esm/utils/chart/index.js +1 -17
- package/dist/esm/utils/chart/text.d.ts +2 -1
- package/dist/esm/utils/chart/text.js +3 -10
- package/dist/esm/utils/chart/zoom.js +14 -8
- package/package.json +1 -1
- package/dist/cjs/components/Axis/AxisY.js +0 -416
- package/dist/cjs/components/Axis/index.d.ts +0 -2
- package/dist/cjs/components/Axis/index.js +0 -2
- package/dist/cjs/components/Tooltip/utils.d.ts +0 -30
- package/dist/cjs/components/Tooltip/utils.js +0 -126
- package/dist/esm/components/Axis/AxisY.js +0 -416
- package/dist/esm/components/Axis/index.d.ts +0 -2
- package/dist/esm/components/Axis/index.js +0 -2
- package/dist/esm/components/Tooltip/utils.d.ts +0 -30
- package/dist/esm/components/Tooltip/utils.js +0 -126
- /package/dist/cjs/components/{Axis → AxisX}/AxisX.d.ts +0 -0
- /package/dist/cjs/components/{Axis → AxisX}/styles.css +0 -0
- /package/dist/esm/components/{Axis → AxisX}/AxisX.d.ts +0 -0
- /package/dist/esm/components/{Axis → AxisX}/styles.css +0 -0
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import { DASH_STYLE, DEFAULT_AXIS_LABEL_FONT_SIZE, axisCrosshairDefaults, axisLabelsDefaults, xAxisTitleDefaults, } from '../../constants';
|
|
3
|
-
import { calculateCos, formatAxisTickLabel, getClosestPointsRange, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight, getLabelsSize, getMaxTickCount, getTicksCount,
|
|
3
|
+
import { calculateCos, calculateNumericProperty, formatAxisTickLabel, getAxisItems, getClosestPointsRange, getDefaultDateFormat, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight, getLabelsSize, getMaxTickCount, getTicksCount, hasOverlappingLabels, wrapText, } from '../../utils';
|
|
4
4
|
import { createXScale } from '../useAxisScales';
|
|
5
5
|
import { getAxisCategories, prepareAxisPlotLabel } from './utils';
|
|
6
|
-
async function
|
|
6
|
+
async function setLabelSettings({ axis, seriesData, seriesOptions, width, autoRotation = true, }) {
|
|
7
7
|
const scale = createXScale({ axis, series: seriesData, seriesOptions, boundsWidth: width });
|
|
8
|
+
if (!scale) {
|
|
9
|
+
axis.labels.height = 0;
|
|
10
|
+
axis.labels.rotation = 0;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
8
13
|
const tickCount = getTicksCount({ axis, range: width });
|
|
9
|
-
const ticks =
|
|
14
|
+
const ticks = getAxisItems({
|
|
10
15
|
scale: scale,
|
|
11
16
|
count: tickCount,
|
|
12
17
|
maxCount: getMaxTickCount({ width, axis }),
|
|
13
18
|
});
|
|
14
19
|
const step = getClosestPointsRange(axis, ticks);
|
|
20
|
+
if (axis.type === 'datetime' && !axis.labels.dateFormat) {
|
|
21
|
+
axis.labels.dateFormat = getDefaultDateFormat(step);
|
|
22
|
+
}
|
|
15
23
|
const labels = ticks.map((value) => {
|
|
16
24
|
return formatAxisTickLabel({
|
|
17
25
|
axis,
|
|
@@ -38,10 +46,11 @@ async function getLabelSettings({ axis, seriesData, seriesOptions, width, autoRo
|
|
|
38
46
|
})).maxHeight
|
|
39
47
|
: axis.labels.lineHeight;
|
|
40
48
|
const maxHeight = rotation ? calculateCos(rotation) * axis.labels.maxWidth : labelsHeight;
|
|
41
|
-
|
|
49
|
+
axis.labels.height = Math.min(maxHeight, labelsHeight);
|
|
50
|
+
axis.labels.rotation = rotation;
|
|
42
51
|
}
|
|
43
52
|
export const getPreparedXAxis = async ({ xAxis, seriesData, seriesOptions, width, }) => {
|
|
44
|
-
var _a;
|
|
53
|
+
var _a, _b, _c, _d, _e;
|
|
45
54
|
const titleText = get(xAxis, 'title.text', '');
|
|
46
55
|
const titleStyle = Object.assign(Object.assign({}, xAxisTitleDefaults.style), get(xAxis, 'title.style'));
|
|
47
56
|
const titleMaxRowsCount = get(xAxis, 'title.maxRowCount', xAxisTitleDefaults.maxRowCount);
|
|
@@ -74,7 +83,7 @@ export const getPreparedXAxis = async ({ xAxis, seriesData, seriesOptions, width
|
|
|
74
83
|
width: 0,
|
|
75
84
|
height: 0,
|
|
76
85
|
lineHeight: labelsLineHeight,
|
|
77
|
-
maxWidth:
|
|
86
|
+
maxWidth: (_b = calculateNumericProperty({ base: width, value: (_a = xAxis === null || xAxis === void 0 ? void 0 : xAxis.labels) === null || _a === void 0 ? void 0 : _a.maxWidth })) !== null && _b !== void 0 ? _b : axisLabelsDefaults.maxWidth,
|
|
78
87
|
html: labelsHtml,
|
|
79
88
|
},
|
|
80
89
|
lineColor: get(xAxis, 'lineColor'),
|
|
@@ -96,7 +105,12 @@ export const getPreparedXAxis = async ({ xAxis, seriesData, seriesOptions, width
|
|
|
96
105
|
enabled: get(xAxis, 'grid.enabled', true),
|
|
97
106
|
},
|
|
98
107
|
ticks: {
|
|
99
|
-
pixelInterval:
|
|
108
|
+
pixelInterval: ((_c = xAxis === null || xAxis === void 0 ? void 0 : xAxis.ticks) === null || _c === void 0 ? void 0 : _c.interval)
|
|
109
|
+
? calculateNumericProperty({
|
|
110
|
+
base: width,
|
|
111
|
+
value: xAxis.ticks.interval,
|
|
112
|
+
})
|
|
113
|
+
: (_d = xAxis === null || xAxis === void 0 ? void 0 : xAxis.ticks) === null || _d === void 0 ? void 0 : _d.pixelInterval,
|
|
100
114
|
},
|
|
101
115
|
position: 'bottom',
|
|
102
116
|
plotIndex: 0,
|
|
@@ -129,14 +143,12 @@ export const getPreparedXAxis = async ({ xAxis, seriesData, seriesOptions, width
|
|
|
129
143
|
visible: get(xAxis, 'visible', true),
|
|
130
144
|
order: xAxis === null || xAxis === void 0 ? void 0 : xAxis.order,
|
|
131
145
|
};
|
|
132
|
-
|
|
146
|
+
await setLabelSettings({
|
|
133
147
|
axis: preparedXAxis,
|
|
134
148
|
seriesData,
|
|
135
149
|
seriesOptions,
|
|
136
150
|
width,
|
|
137
|
-
autoRotation: (
|
|
151
|
+
autoRotation: (_e = xAxis === null || xAxis === void 0 ? void 0 : xAxis.labels) === null || _e === void 0 ? void 0 : _e.autoRotation,
|
|
138
152
|
});
|
|
139
|
-
preparedXAxis.labels.height = height;
|
|
140
|
-
preparedXAxis.labels.rotation = rotation;
|
|
141
153
|
return preparedXAxis;
|
|
142
154
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { ChartSeries, ChartYAxis } from '../../types';
|
|
2
2
|
import type { PreparedSeriesOptions } from '../useSeries/types';
|
|
3
3
|
import type { PreparedAxis } from './types';
|
|
4
|
-
export declare const getPreparedYAxis: ({ height, seriesData, seriesOptions, yAxis, }: {
|
|
4
|
+
export declare const getPreparedYAxis: ({ height, boundsHeight, width, seriesData, seriesOptions, yAxis, }: {
|
|
5
5
|
height: number;
|
|
6
|
+
boundsHeight: number;
|
|
7
|
+
width: number;
|
|
6
8
|
seriesData: ChartSeries[];
|
|
7
9
|
seriesOptions: PreparedSeriesOptions;
|
|
8
10
|
yAxis: ChartYAxis[] | undefined;
|
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
+
import { getTickValues } from '../../components/AxisY/utils';
|
|
2
3
|
import { DASH_STYLE, DEFAULT_AXIS_LABEL_FONT_SIZE, DEFAULT_AXIS_TYPE, axisCrosshairDefaults, axisLabelsDefaults, yAxisTitleDefaults, } from '../../constants';
|
|
3
|
-
import { formatAxisTickLabel, getClosestPointsRange, getDefaultMinYAxisValue, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight, getLabelsSize, getScaleTicks, isAxisRelatedSeries, wrapText, } from '../../utils';
|
|
4
|
+
import { calculateNumericProperty, formatAxisTickLabel, getClosestPointsRange, getDefaultDateFormat, getDefaultMinYAxisValue, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight, getLabelsSize, getScaleTicks, getTextSizeFn, isAxisRelatedSeries, wrapText, } from '../../utils';
|
|
4
5
|
import { createYScale } from '../useAxisScales';
|
|
5
6
|
import { getAxisCategories, prepareAxisPlotLabel } from './utils';
|
|
6
7
|
const getAxisLabelMaxWidth = async (args) => {
|
|
7
|
-
const { axis, seriesData, seriesOptions } = args;
|
|
8
|
+
const { axis, seriesData, seriesOptions, height } = args;
|
|
8
9
|
if (!axis.labels.enabled) {
|
|
9
10
|
return { height: 0, width: 0 };
|
|
10
11
|
}
|
|
11
12
|
const scale = createYScale({
|
|
12
13
|
axis,
|
|
13
|
-
boundsHeight:
|
|
14
|
+
boundsHeight: height,
|
|
14
15
|
series: seriesData,
|
|
15
16
|
seriesOptions,
|
|
16
17
|
});
|
|
18
|
+
if (!scale) {
|
|
19
|
+
return { height: 0, width: 0 };
|
|
20
|
+
}
|
|
21
|
+
const getTextSize = getTextSizeFn({ style: axis.labels.style });
|
|
22
|
+
const labelLineHeight = (await getTextSize('Tmp')).height;
|
|
23
|
+
const tickValues = getTickValues({ axis, scale, labelLineHeight });
|
|
17
24
|
const ticks = getScaleTicks(scale);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
const tickStep = getClosestPointsRange(axis, ticks);
|
|
26
|
+
if (axis.type === 'datetime' && !axis.labels.dateFormat) {
|
|
27
|
+
axis.labels.dateFormat = getDefaultDateFormat(tickStep);
|
|
28
|
+
}
|
|
29
|
+
const labels = tickValues.map((tick) => formatAxisTickLabel({
|
|
21
30
|
axis,
|
|
22
|
-
value: tick,
|
|
23
|
-
step,
|
|
31
|
+
value: tick.value,
|
|
32
|
+
step: tickStep,
|
|
24
33
|
}));
|
|
25
34
|
const size = await getLabelsSize({
|
|
26
35
|
labels,
|
|
@@ -30,7 +39,7 @@ const getAxisLabelMaxWidth = async (args) => {
|
|
|
30
39
|
});
|
|
31
40
|
return { height: size.maxHeight, width: size.maxWidth };
|
|
32
41
|
};
|
|
33
|
-
export const getPreparedYAxis = ({ height, seriesData, seriesOptions, yAxis, }) => {
|
|
42
|
+
export const getPreparedYAxis = ({ height, boundsHeight, width, seriesData, seriesOptions, yAxis, }) => {
|
|
34
43
|
const axisByPlot = [];
|
|
35
44
|
const axisItems = yAxis || [{}];
|
|
36
45
|
const hasAxisRelatedSeries = seriesData.some(isAxisRelatedSeries);
|
|
@@ -38,7 +47,7 @@ export const getPreparedYAxis = ({ height, seriesData, seriesOptions, yAxis, })
|
|
|
38
47
|
return Promise.resolve([]);
|
|
39
48
|
}
|
|
40
49
|
return Promise.all(axisItems.map(async (axisItem) => {
|
|
41
|
-
var _a, _b;
|
|
50
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
42
51
|
const plotIndex = get(axisItem, 'plotIndex', 0);
|
|
43
52
|
const firstPlotAxis = !axisByPlot[plotIndex];
|
|
44
53
|
if (firstPlotAxis) {
|
|
@@ -71,9 +80,7 @@ export const getPreparedYAxis = ({ height, seriesData, seriesOptions, yAxis, })
|
|
|
71
80
|
margin: labelsEnabled
|
|
72
81
|
? get(axisItem, 'labels.margin', axisLabelsDefaults.margin)
|
|
73
82
|
: 0,
|
|
74
|
-
padding: labelsEnabled
|
|
75
|
-
? get(axisItem, 'labels.padding', axisLabelsDefaults.padding)
|
|
76
|
-
: 0,
|
|
83
|
+
padding: labelsEnabled ? get(axisItem, 'labels.padding', 4) : 0,
|
|
77
84
|
dateFormat: get(axisItem, 'labels.dateFormat'),
|
|
78
85
|
numberFormat: get(axisItem, 'labels.numberFormat'),
|
|
79
86
|
style: labelsStyle,
|
|
@@ -81,7 +88,7 @@ export const getPreparedYAxis = ({ height, seriesData, seriesOptions, yAxis, })
|
|
|
81
88
|
width: 0,
|
|
82
89
|
height: 0,
|
|
83
90
|
lineHeight: labelsLineHeight,
|
|
84
|
-
maxWidth:
|
|
91
|
+
maxWidth: (_b = calculateNumericProperty({ base: width, value: (_a = axisItem.labels) === null || _a === void 0 ? void 0 : _a.maxWidth })) !== null && _b !== void 0 ? _b : axisLabelsDefaults.maxWidth,
|
|
85
92
|
html: labelsHtml,
|
|
86
93
|
},
|
|
87
94
|
lineColor: get(axisItem, 'lineColor'),
|
|
@@ -96,15 +103,20 @@ export const getPreparedYAxis = ({ height, seriesData, seriesOptions, yAxis, })
|
|
|
96
103
|
align: get(axisItem, 'title.align', yAxisTitleDefaults.align),
|
|
97
104
|
maxRowCount: titleMaxRowsCount,
|
|
98
105
|
},
|
|
99
|
-
min: (
|
|
106
|
+
min: (_c = get(axisItem, 'min')) !== null && _c !== void 0 ? _c : getDefaultMinYAxisValue(seriesData),
|
|
100
107
|
max: get(axisItem, 'max'),
|
|
101
108
|
maxPadding: get(axisItem, 'maxPadding', 0.05),
|
|
102
109
|
grid: {
|
|
103
110
|
enabled: get(axisItem, 'grid.enabled', firstPlotAxis ||
|
|
104
|
-
(!firstPlotAxis && !((
|
|
111
|
+
(!firstPlotAxis && !((_d = axisByPlot[plotIndex][0].visible) !== null && _d !== void 0 ? _d : true))),
|
|
105
112
|
},
|
|
106
113
|
ticks: {
|
|
107
|
-
pixelInterval:
|
|
114
|
+
pixelInterval: ((_e = axisItem.ticks) === null || _e === void 0 ? void 0 : _e.interval)
|
|
115
|
+
? calculateNumericProperty({
|
|
116
|
+
base: height,
|
|
117
|
+
value: (_f = axisItem.ticks) === null || _f === void 0 ? void 0 : _f.interval,
|
|
118
|
+
})
|
|
119
|
+
: (_g = axisItem.ticks) === null || _g === void 0 ? void 0 : _g.pixelInterval,
|
|
108
120
|
},
|
|
109
121
|
position: get(axisItem, 'position', defaultAxisPosition),
|
|
110
122
|
plotIndex: get(axisItem, 'plotIndex', 0),
|
|
@@ -142,6 +154,7 @@ export const getPreparedYAxis = ({ height, seriesData, seriesOptions, yAxis, })
|
|
|
142
154
|
axis: preparedAxis,
|
|
143
155
|
seriesData,
|
|
144
156
|
seriesOptions,
|
|
157
|
+
height: boundsHeight,
|
|
145
158
|
});
|
|
146
159
|
preparedAxis.labels.height = labelsHeight;
|
|
147
160
|
preparedAxis.labels.width =
|
|
@@ -63,11 +63,13 @@ export const useCrosshair = (props) => {
|
|
|
63
63
|
}
|
|
64
64
|
yAxes.forEach((yAxis, index, currentArr) => {
|
|
65
65
|
const yAxisScale = yScale[index];
|
|
66
|
-
if (
|
|
66
|
+
if (!yAxisScale ||
|
|
67
|
+
(index !== 0 && !yAxis.crosshair.snap && !currentArr[0].crosshair.snap)) {
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
70
|
if (yAxis.crosshair.enabled && (hovered === null || hovered === void 0 ? void 0 : hovered.length)) {
|
|
70
71
|
const crosshairDataAttr = `data-crosshair-y-line-${index}`;
|
|
72
|
+
const crosshairPosition = getAxisPlotsPosition(yAxis, split);
|
|
71
73
|
const crosshairSelection = svgElement
|
|
72
74
|
.selectAll(`[${crosshairDataAttr}]`)
|
|
73
75
|
.data(hovered.filter((node) => {
|
|
@@ -82,7 +84,7 @@ export const useCrosshair = (props) => {
|
|
|
82
84
|
.attr(plotCrosshairDataAttr, 1)
|
|
83
85
|
.attr(crosshairDataAttr, 1)
|
|
84
86
|
.style('transform', yAxis.crosshair.snap
|
|
85
|
-
?
|
|
87
|
+
? `translate(${crosshairPosition[0]}px, ${crosshairPosition[1]}px)`
|
|
86
88
|
: 'translate(0, 0)');
|
|
87
89
|
crosshairSelection
|
|
88
90
|
.append('path')
|
|
@@ -7,7 +7,7 @@ export declare const prepareAreaData: (args: {
|
|
|
7
7
|
xAxis: PreparedAxis;
|
|
8
8
|
xScale: ChartScale;
|
|
9
9
|
yAxis: PreparedAxis[];
|
|
10
|
-
yScale: ChartScale[];
|
|
10
|
+
yScale: (ChartScale | undefined)[];
|
|
11
11
|
boundsHeight: number;
|
|
12
12
|
isOutsideBounds: (x: number, y: number) => boolean;
|
|
13
13
|
}) => Promise<PreparedAreaData[]>;
|
|
@@ -71,6 +71,9 @@ export const prepareAreaData = async (args) => {
|
|
|
71
71
|
const yAxisIndex = s.yAxis;
|
|
72
72
|
const seriesYAxis = yAxis[yAxisIndex];
|
|
73
73
|
const seriesYScale = yScale[yAxisIndex];
|
|
74
|
+
if (!seriesYScale) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
74
77
|
const yMin = getYValue({
|
|
75
78
|
point: { y: 0 },
|
|
76
79
|
points: s.data,
|
|
@@ -112,6 +112,9 @@ export const prepareBarXData = async (args) => {
|
|
|
112
112
|
const yValue = sortedData[yValueIndex];
|
|
113
113
|
const yAxisIndex = yValue.series.yAxis;
|
|
114
114
|
const seriesYScale = yScale[yAxisIndex];
|
|
115
|
+
if (!seriesYScale) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
115
118
|
let xCenter;
|
|
116
119
|
if (xAxis.type === 'category') {
|
|
117
120
|
const xBandScale = xScale;
|
|
@@ -10,6 +10,13 @@ export const prepareBarYData = async (args) => {
|
|
|
10
10
|
const stackGap = seriesOptions['bar-y'].stackGap;
|
|
11
11
|
const xLinearScale = xScale;
|
|
12
12
|
const yLinearScale = yScale;
|
|
13
|
+
if (!yLinearScale) {
|
|
14
|
+
return {
|
|
15
|
+
shapes: [],
|
|
16
|
+
labels: [],
|
|
17
|
+
htmlElements: [],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
13
20
|
const yScaleRange = yLinearScale.range();
|
|
14
21
|
const plotHeight = Math.abs(yScaleRange[0] - yScaleRange[1]);
|
|
15
22
|
const sortingOptions = get(seriesOptions, 'bar-y.dataSorting');
|
|
@@ -29,7 +36,7 @@ export const prepareBarYData = async (args) => {
|
|
|
29
36
|
})();
|
|
30
37
|
const groupedData = groupBarYDataByYValue(series, yAxis);
|
|
31
38
|
const { bandSize, barGap, barSize } = yAxis[0].type === 'category'
|
|
32
|
-
? getBarYLayoutForCategoryScale({ groupedData, seriesOptions, yScale })
|
|
39
|
+
? getBarYLayoutForCategoryScale({ groupedData, seriesOptions, yScale: yLinearScale })
|
|
33
40
|
: getBarYLayoutForNumericScale({
|
|
34
41
|
groupedData,
|
|
35
42
|
seriesOptions,
|
|
@@ -8,7 +8,7 @@ export declare const prepareLineData: (args: {
|
|
|
8
8
|
xAxis: PreparedAxis;
|
|
9
9
|
xScale: ChartScale;
|
|
10
10
|
yAxis: PreparedAxis[];
|
|
11
|
-
yScale: ChartScale[];
|
|
11
|
+
yScale: (ChartScale | undefined)[];
|
|
12
12
|
split: PreparedSplit;
|
|
13
13
|
isOutsideBounds: (x: number, y: number) => boolean;
|
|
14
14
|
}) => Promise<PreparedLineData[]>;
|
|
@@ -50,6 +50,9 @@ export const prepareLineData = async (args) => {
|
|
|
50
50
|
const seriesYAxis = yAxis[yAxisIndex];
|
|
51
51
|
const yAxisTop = ((_a = split.plots[seriesYAxis.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
|
|
52
52
|
const seriesYScale = yScale[s.yAxis];
|
|
53
|
+
if (!seriesYScale) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
53
56
|
const points = s.data.map((d) => ({
|
|
54
57
|
x: getXValue({ point: d, points: s.data, xAxis, xScale }),
|
|
55
58
|
y: yAxisTop +
|
|
@@ -7,6 +7,6 @@ export declare const prepareScatterData: (args: {
|
|
|
7
7
|
xAxis: PreparedAxis;
|
|
8
8
|
xScale: ChartScale;
|
|
9
9
|
yAxis: PreparedAxis[];
|
|
10
|
-
yScale: ChartScale[];
|
|
10
|
+
yScale: (ChartScale | undefined)[];
|
|
11
11
|
isOutsideBounds: (x: number, y: number) => boolean;
|
|
12
12
|
}) => PreparedScatterData[];
|
|
@@ -9,6 +9,9 @@ export const prepareScatterData = (args) => {
|
|
|
9
9
|
const yAxisIndex = get(s, 'yAxis', 0);
|
|
10
10
|
const seriesYAxis = yAxis[yAxisIndex];
|
|
11
11
|
const seriesYScale = yScale[yAxisIndex];
|
|
12
|
+
if (!seriesYScale) {
|
|
13
|
+
return acc;
|
|
14
|
+
}
|
|
12
15
|
const filteredData = xAxis.type === 'category' || seriesYAxis.type === 'category'
|
|
13
16
|
? s.data
|
|
14
17
|
: getFilteredLinearScatterData(s.data);
|
|
@@ -16,6 +19,9 @@ export const prepareScatterData = (args) => {
|
|
|
16
19
|
var _a;
|
|
17
20
|
const x = getXValue({ point: d, xAxis, xScale });
|
|
18
21
|
const y = getYValue({ point: d, yAxis: seriesYAxis, yScale: seriesYScale });
|
|
22
|
+
if (typeof x === 'undefined' || typeof y === 'undefined') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
19
25
|
acc.push({
|
|
20
26
|
point: {
|
|
21
27
|
data: d,
|
|
@@ -55,6 +55,9 @@ function getBandWidth(args) {
|
|
|
55
55
|
export const prepareWaterfallData = async (args) => {
|
|
56
56
|
const { series, seriesOptions, xAxis, xScale, yAxis: [yAxis], yScale: [yScale], } = args;
|
|
57
57
|
const yLinearScale = yScale;
|
|
58
|
+
if (!yLinearScale) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
58
61
|
const plotHeight = yLinearScale(yLinearScale.domain()[0]);
|
|
59
62
|
const barMaxWidth = get(seriesOptions, 'waterfall.barMaxWidth');
|
|
60
63
|
const barPadding = get(seriesOptions, 'waterfall.barPadding');
|
|
@@ -72,7 +75,7 @@ export const prepareWaterfallData = async (args) => {
|
|
|
72
75
|
const rectWidth = Math.max(MIN_BAR_WIDTH, Math.min(bandWidth - rectGap, barMaxWidth));
|
|
73
76
|
const yZero = getYValue({
|
|
74
77
|
point: { y: 0 },
|
|
75
|
-
yScale,
|
|
78
|
+
yScale: yLinearScale,
|
|
76
79
|
yAxis,
|
|
77
80
|
});
|
|
78
81
|
let totalValue = 0;
|
|
@@ -92,7 +95,7 @@ export const prepareWaterfallData = async (args) => {
|
|
|
92
95
|
const height = yZero -
|
|
93
96
|
getYValue({
|
|
94
97
|
point: { y: Math.abs(yValue) },
|
|
95
|
-
yScale,
|
|
98
|
+
yScale: yLinearScale,
|
|
96
99
|
yAxis,
|
|
97
100
|
});
|
|
98
101
|
let y;
|
|
@@ -101,7 +104,7 @@ export const prepareWaterfallData = async (args) => {
|
|
|
101
104
|
point: {
|
|
102
105
|
y: yValue > 0 ? yValue : 0,
|
|
103
106
|
},
|
|
104
|
-
yScale,
|
|
107
|
+
yScale: yLinearScale,
|
|
105
108
|
yAxis,
|
|
106
109
|
});
|
|
107
110
|
}
|
|
@@ -15,5 +15,5 @@ export interface ZoomState {
|
|
|
15
15
|
* or the category index from the categories array specified in the axis settings (if the axis type is `category`).
|
|
16
16
|
* The second element is the corresponding maximum value.
|
|
17
17
|
*/
|
|
18
|
-
y: [number, number][];
|
|
18
|
+
y: ([number, number] | undefined)[];
|
|
19
19
|
}
|
|
@@ -13,11 +13,17 @@ export function selectionToZoomBounds(args) {
|
|
|
13
13
|
if (!Array.isArray(zoomState.y)) {
|
|
14
14
|
zoomState.y = [];
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const yScale = yScales[index];
|
|
17
|
+
if (yScale) {
|
|
18
|
+
zoomState.y.push(selectionYToZoomBounds({
|
|
19
|
+
yAxis,
|
|
20
|
+
yScale,
|
|
21
|
+
selection: [y1, y0],
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
zoomState.y.push(undefined);
|
|
26
|
+
}
|
|
21
27
|
});
|
|
22
28
|
break;
|
|
23
29
|
}
|
|
@@ -29,11 +35,17 @@ export function selectionToZoomBounds(args) {
|
|
|
29
35
|
if (!Array.isArray(zoomState.y)) {
|
|
30
36
|
zoomState.y = [];
|
|
31
37
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
const yScale = yScales[index];
|
|
39
|
+
if (yScale) {
|
|
40
|
+
zoomState.y.push(selectionYToZoomBounds({
|
|
41
|
+
yAxis,
|
|
42
|
+
yScale,
|
|
43
|
+
selection: [y0, y1],
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
zoomState.y.push(undefined);
|
|
48
|
+
}
|
|
37
49
|
});
|
|
38
50
|
break;
|
|
39
51
|
}
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -35,6 +35,10 @@ export interface ChartAxisLabels {
|
|
|
35
35
|
* @default false
|
|
36
36
|
* */
|
|
37
37
|
html?: boolean;
|
|
38
|
+
/** The maximum width of the axis labels(absolute or relative to the chart area).
|
|
39
|
+
* If more than that, it collapses into three points.
|
|
40
|
+
* */
|
|
41
|
+
maxWidth?: number | string;
|
|
38
42
|
}
|
|
39
43
|
export interface ChartAxis {
|
|
40
44
|
categories?: string[];
|
|
@@ -74,8 +78,14 @@ export interface ChartAxis {
|
|
|
74
78
|
};
|
|
75
79
|
ticks?: {
|
|
76
80
|
/** Pixel interval of the tick marks. Not applicable to categorized axis.
|
|
77
|
-
* The specified value is only a hint; the interval between ticks can be greater or less depending on the data.
|
|
81
|
+
* The specified value is only a hint; the interval between ticks can be greater or less depending on the data.
|
|
82
|
+
*
|
|
83
|
+
* @deprecated use `interval` instead
|
|
84
|
+
* */
|
|
78
85
|
pixelInterval?: number;
|
|
86
|
+
/** Interval of the tick marks(absolute or relative to the chart area). Not applicable to categorized axis.
|
|
87
|
+
* The specified value is only a hint; the interval between ticks can be greater or less depending on the data. */
|
|
88
|
+
interval?: number | string;
|
|
79
89
|
};
|
|
80
90
|
/** Padding of the max value relative to the length of the axis.
|
|
81
91
|
* A padding of 0.05 will make a 100px axis 5px longer.
|
|
@@ -130,4 +130,7 @@ export interface ChartTooltip<T = MeaningfulAny> {
|
|
|
130
130
|
/** Formatting settings for totals tooltip value. */
|
|
131
131
|
valueFormat?: ValueFormat;
|
|
132
132
|
};
|
|
133
|
+
/** Can be used for the UI automated test.
|
|
134
|
+
* It is assigned as a data-qa attribute to an element. */
|
|
135
|
+
qa?: string;
|
|
133
136
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getMinSpaceBetween<T>(arr: T[], iterator: (item: T) => number): number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { path, select } from 'd3';
|
|
2
|
-
import {
|
|
2
|
+
import { getAxisItems, getXAxisOffset, getXTickPosition } from '../axis';
|
|
3
3
|
import { calculateCos, calculateSin } from '../math';
|
|
4
4
|
import { getLabelsSize, setEllipsisForOverflowText } from '../text';
|
|
5
5
|
const AXIS_BOTTOM_HTML_LABELS_DATA_ATTR = 'data-axis-bottom-html-labels';
|
|
@@ -151,7 +151,7 @@ export async function axisBottom(args) {
|
|
|
151
151
|
const htmlSelection = select(htmlLayout);
|
|
152
152
|
const offset = getXAxisOffset();
|
|
153
153
|
const position = getXTickPosition({ scale, offset });
|
|
154
|
-
const values =
|
|
154
|
+
const values = getAxisItems({ scale, count: ticksCount, maxCount: maxTickCount });
|
|
155
155
|
const labelHeight = (await getLabelsSize({
|
|
156
156
|
labels: values.map(labelFormat),
|
|
157
157
|
style: labelsStyle,
|
|
@@ -183,7 +183,7 @@ export async function axisBottom(args) {
|
|
|
183
183
|
? values.map((v) => {
|
|
184
184
|
var _a;
|
|
185
185
|
return {
|
|
186
|
-
content: v,
|
|
186
|
+
content: String(v),
|
|
187
187
|
left: position(v) + offset + boundsOffsetLeft,
|
|
188
188
|
top: Math.abs(((_a = tickItems === null || tickItems === void 0 ? void 0 : tickItems[0]) === null || _a === void 0 ? void 0 : _a[1]) || 0) + labelsMargin + boundsOffsetTop,
|
|
189
189
|
};
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import type { AxisDomain, AxisScale, ScaleBand } from 'd3';
|
|
2
|
-
import type { PreparedAxis, PreparedAxisPlotBand, PreparedSplit } from '../../hooks';
|
|
2
|
+
import type { ChartScale, PreparedAxis, PreparedAxisPlotBand, PreparedSplit } from '../../hooks';
|
|
3
3
|
import type { TextRow } from './text';
|
|
4
4
|
import type { AxisDirection } from './types';
|
|
5
|
+
type Ticks = number[] | string[] | Date[];
|
|
5
6
|
export declare function getTicksCount({ axis, range }: {
|
|
6
7
|
axis: PreparedAxis;
|
|
7
8
|
range: number;
|
|
8
9
|
}): number | undefined;
|
|
9
|
-
export declare function isBandScale(scale: AxisScale<AxisDomain>): scale is ScaleBand<
|
|
10
|
-
export declare function getScaleTicks(scale: AxisScale<AxisDomain>, ticksCount?: number):
|
|
10
|
+
export declare function isBandScale(scale: ChartScale | AxisScale<AxisDomain>): scale is ScaleBand<string>;
|
|
11
|
+
export declare function getScaleTicks(scale: ChartScale | AxisScale<AxisDomain>, ticksCount?: number): Ticks;
|
|
11
12
|
export declare function getXAxisOffset(): 0 | 0.5;
|
|
12
13
|
export declare function getXTickPosition({ scale, offset }: {
|
|
13
14
|
scale: AxisScale<AxisDomain>;
|
|
14
15
|
offset: number;
|
|
15
|
-
}): (d:
|
|
16
|
-
export declare function
|
|
17
|
-
scale: AxisScale<AxisDomain>;
|
|
16
|
+
}): (d: unknown) => number;
|
|
17
|
+
export declare function getAxisItems({ scale, count, maxCount, }: {
|
|
18
|
+
scale: ChartScale | AxisScale<AxisDomain>;
|
|
18
19
|
count?: number;
|
|
19
20
|
maxCount?: number;
|
|
20
|
-
}):
|
|
21
|
+
}): Ticks;
|
|
21
22
|
export declare function getMaxTickCount({ axis, width }: {
|
|
22
23
|
axis: PreparedAxis;
|
|
23
24
|
width: number;
|
|
@@ -35,9 +36,14 @@ interface GetBandsPositionArgs {
|
|
|
35
36
|
axisScale: AxisScale<AxisDomain>;
|
|
36
37
|
axis: AxisDirection;
|
|
37
38
|
}
|
|
38
|
-
export declare const getAxisPlotsPosition: (axis: PreparedAxis, split: PreparedSplit, width?: number) =>
|
|
39
|
+
export declare const getAxisPlotsPosition: (axis: PreparedAxis, split: PreparedSplit, width?: number) => number[];
|
|
39
40
|
export declare function getBandsPosition(args: GetBandsPositionArgs): {
|
|
40
41
|
from: number;
|
|
41
42
|
to: number;
|
|
42
43
|
};
|
|
44
|
+
export declare function getClosestPointsRange(axis: PreparedAxis, points: AxisDomain[]): number | undefined;
|
|
45
|
+
export declare function getLabelFormatter({ axis, scale }: {
|
|
46
|
+
axis: PreparedAxis;
|
|
47
|
+
scale: ChartScale;
|
|
48
|
+
}): (value: AxisDomain) => string;
|
|
43
49
|
export {};
|