@gravity-ui/charts 1.17.0 → 1.18.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/AxisY/prepare-axis-data.d.ts +4 -2
- package/dist/cjs/components/AxisY/prepare-axis-data.js +11 -10
- package/dist/cjs/components/AxisY/utils.d.ts +4 -2
- package/dist/cjs/components/AxisY/utils.js +47 -23
- package/dist/cjs/components/ChartInner/index.js +11 -5
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +1 -1
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +3 -2
- 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 +3 -3
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.d.ts +4 -3
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.js +6 -9
- package/dist/cjs/components/Tooltip/index.js +1 -1
- package/dist/cjs/hooks/useAxisScales/index.d.ts +3 -4
- package/dist/cjs/hooks/useAxisScales/index.js +82 -28
- 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/utils.d.ts +5 -2
- package/dist/cjs/hooks/useChartOptions/utils.js +2 -3
- package/dist/cjs/hooks/useChartOptions/x-axis.js +21 -9
- package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +1 -3
- package/dist/cjs/hooks/useChartOptions/y-axis.js +23 -12
- package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
- package/dist/cjs/hooks/useCrosshair/index.js +2 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-y.js +3 -1
- 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 +5 -3
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +46 -20
- package/dist/cjs/hooks/useShapes/index.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/index.js +2 -0
- 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 +46 -18
- package/dist/cjs/hooks/utils/bar-y.d.ts +7 -10
- package/dist/cjs/hooks/utils/bar-y.js +33 -18
- 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 +12 -0
- package/dist/cjs/utils/chart/format.js +2 -2
- package/dist/cjs/utils/chart/index.d.ts +1 -0
- package/dist/cjs/utils/chart/index.js +3 -1
- package/dist/cjs/utils/chart/labels.d.ts +27 -5
- package/dist/cjs/utils/chart/labels.js +39 -3
- package/dist/cjs/utils/chart/zoom.js +14 -8
- package/dist/esm/components/AxisY/prepare-axis-data.d.ts +4 -2
- package/dist/esm/components/AxisY/prepare-axis-data.js +11 -10
- package/dist/esm/components/AxisY/utils.d.ts +4 -2
- package/dist/esm/components/AxisY/utils.js +47 -23
- package/dist/esm/components/ChartInner/index.js +11 -5
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +1 -1
- package/dist/esm/components/ChartInner/useChartInnerProps.js +3 -2
- 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 +3 -3
- package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.d.ts +4 -3
- package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.js +6 -9
- package/dist/esm/components/Tooltip/index.js +1 -1
- package/dist/esm/hooks/useAxisScales/index.d.ts +3 -4
- package/dist/esm/hooks/useAxisScales/index.js +82 -28
- 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/utils.d.ts +5 -2
- package/dist/esm/hooks/useChartOptions/utils.js +2 -3
- package/dist/esm/hooks/useChartOptions/x-axis.js +21 -9
- package/dist/esm/hooks/useChartOptions/y-axis.d.ts +1 -3
- package/dist/esm/hooks/useChartOptions/y-axis.js +23 -12
- package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
- package/dist/esm/hooks/useCrosshair/index.js +2 -1
- package/dist/esm/hooks/useSeries/prepare-bar-y.js +3 -1
- 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 +5 -3
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +46 -20
- package/dist/esm/hooks/useShapes/index.d.ts +1 -1
- package/dist/esm/hooks/useShapes/index.js +2 -0
- 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 +46 -18
- package/dist/esm/hooks/utils/bar-y.d.ts +7 -10
- package/dist/esm/hooks/utils/bar-y.js +33 -18
- 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 +12 -0
- package/dist/esm/utils/chart/format.js +2 -2
- package/dist/esm/utils/chart/index.d.ts +1 -0
- package/dist/esm/utils/chart/index.js +3 -1
- package/dist/esm/utils/chart/labels.d.ts +27 -5
- package/dist/esm/utils/chart/labels.js +39 -3
- package/dist/esm/utils/chart/zoom.js +14 -8
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChartSeries, ChartTitle, ChartTooltip, ChartOptions as GeneralChartOptions } from '../../types';
|
|
1
|
+
import type { ChartSeries, ChartTitle, ChartTooltip, ChartXAxis, ChartYAxis, ChartOptions as GeneralChartOptions } from '../../types';
|
|
2
2
|
import type { ChartOptions } from './types';
|
|
3
3
|
type Args = {
|
|
4
4
|
seriesData: ChartSeries[];
|
|
@@ -6,6 +6,8 @@ type Args = {
|
|
|
6
6
|
colors?: string[];
|
|
7
7
|
title?: ChartTitle;
|
|
8
8
|
tooltip?: ChartTooltip;
|
|
9
|
+
yAxes?: ChartYAxis[];
|
|
10
|
+
xAxis?: ChartXAxis;
|
|
9
11
|
};
|
|
10
12
|
export declare const useChartOptions: (args: Args) => ChartOptions;
|
|
11
13
|
export {};
|
|
@@ -4,10 +4,10 @@ import { getPreparedChart } from './chart';
|
|
|
4
4
|
import { getPreparedTitle } from './title';
|
|
5
5
|
import { getPreparedTooltip } from './tooltip';
|
|
6
6
|
export const useChartOptions = (args) => {
|
|
7
|
-
const { chart, colors, seriesData, title, tooltip } = args;
|
|
7
|
+
const { chart, colors, seriesData, title, tooltip, yAxes, xAxis } = args;
|
|
8
8
|
const options = React.useMemo(() => {
|
|
9
9
|
const preparedTitle = getPreparedTitle({ title });
|
|
10
|
-
const preparedTooltip = getPreparedTooltip({ tooltip });
|
|
10
|
+
const preparedTooltip = getPreparedTooltip({ tooltip, seriesData, yAxes, xAxis });
|
|
11
11
|
const preparedChart = getPreparedChart({
|
|
12
12
|
chart,
|
|
13
13
|
preparedTitle,
|
|
@@ -19,6 +19,6 @@ export const useChartOptions = (args) => {
|
|
|
19
19
|
title: preparedTitle,
|
|
20
20
|
tooltip: preparedTooltip,
|
|
21
21
|
};
|
|
22
|
-
}, [chart, colors, seriesData, title, tooltip]);
|
|
22
|
+
}, [chart, colors, seriesData, title, tooltip, xAxis, yAxes]);
|
|
23
23
|
return options;
|
|
24
24
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { ChartData } from '../../types';
|
|
1
|
+
import type { ChartData, ChartSeries, ChartXAxis, ChartYAxis } from '../../types';
|
|
2
2
|
import type { PreparedTooltip } from './types';
|
|
3
3
|
export declare const getPreparedTooltip: (args: {
|
|
4
4
|
tooltip: ChartData["tooltip"];
|
|
5
|
+
seriesData: ChartSeries[];
|
|
6
|
+
yAxes?: ChartYAxis[];
|
|
7
|
+
xAxis?: ChartXAxis;
|
|
5
8
|
}) => PreparedTooltip;
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
+
import { getDefaultValueFormat } from '../../components/Tooltip/DefaultTooltipContent/utils';
|
|
3
|
+
import { getDomainDataXBySeries, getDomainDataYBySeries, getMinSpaceBetween } from '../../utils';
|
|
4
|
+
function getDefaultHeaderFormat({ seriesData, yAxes, xAxis, }) {
|
|
5
|
+
if (seriesData.every((item) => ['pie', 'treemap', 'waterfall', 'sankey', 'radar'].includes(item.type))) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
if (seriesData.some((item) => item.type === 'bar-y')) {
|
|
9
|
+
const domainData = getDomainDataYBySeries(seriesData);
|
|
10
|
+
const closestPointsRange = getMinSpaceBetween(domainData, (d) => d);
|
|
11
|
+
return getDefaultValueFormat({ axis: yAxes === null || yAxes === void 0 ? void 0 : yAxes[0], closestPointsRange });
|
|
12
|
+
}
|
|
13
|
+
const domainData = getDomainDataXBySeries(seriesData);
|
|
14
|
+
const closestPointsRange = getMinSpaceBetween(domainData, (d) => d);
|
|
15
|
+
return getDefaultValueFormat({ axis: xAxis, closestPointsRange });
|
|
16
|
+
}
|
|
2
17
|
export const getPreparedTooltip = (args) => {
|
|
3
|
-
var _a;
|
|
4
|
-
const { tooltip } = args;
|
|
5
|
-
return Object.assign(Object.assign({}, tooltip), { enabled: get(tooltip, 'enabled', true), throttle: (_a = tooltip === null || tooltip === void 0 ? void 0 : tooltip.throttle) !== null && _a !== void 0 ? _a : 0 });
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const { tooltip, seriesData, yAxes, xAxis } = args;
|
|
20
|
+
return Object.assign(Object.assign({}, tooltip), { enabled: get(tooltip, 'enabled', true), throttle: (_a = tooltip === null || tooltip === void 0 ? void 0 : tooltip.throttle) !== null && _a !== void 0 ? _a : 0, headerFormat: (_b = tooltip === null || tooltip === void 0 ? void 0 : tooltip.headerFormat) !== null && _b !== void 0 ? _b : getDefaultHeaderFormat({ seriesData, yAxes, xAxis }) });
|
|
6
21
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AxisPlot,
|
|
1
|
+
import type { AxisPlot, ChartAxis } from '../../types';
|
|
2
2
|
export declare function prepareAxisPlotLabel(d: AxisPlot): {
|
|
3
3
|
text: string;
|
|
4
4
|
style: {
|
|
@@ -8,4 +8,7 @@ export declare function prepareAxisPlotLabel(d: AxisPlot): {
|
|
|
8
8
|
};
|
|
9
9
|
padding: number;
|
|
10
10
|
};
|
|
11
|
-
export declare function getAxisCategories(
|
|
11
|
+
export declare function getAxisCategories({ categories, order, }?: {
|
|
12
|
+
categories?: string[];
|
|
13
|
+
order?: ChartAxis['order'];
|
|
14
|
+
}): string[] | undefined;
|
|
@@ -8,10 +8,9 @@ export function prepareAxisPlotLabel(d) {
|
|
|
8
8
|
padding: (_e = (_d = d.label) === null || _d === void 0 ? void 0 : _d.padding) !== null && _e !== void 0 ? _e : 5,
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
export function getAxisCategories(
|
|
12
|
-
const categories = axis === null || axis === void 0 ? void 0 : axis.categories;
|
|
11
|
+
export function getAxisCategories({ categories, order, } = {}) {
|
|
13
12
|
if (categories) {
|
|
14
|
-
switch (
|
|
13
|
+
switch (order) {
|
|
15
14
|
case 'reverse': {
|
|
16
15
|
return reverse(categories);
|
|
17
16
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
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, calculateNumericProperty, formatAxisTickLabel, getAxisItems, getClosestPointsRange, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight, getLabelsSize, getMaxTickCount, getTicksCount, hasOverlappingLabels, wrapText, } from '../../utils';
|
|
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
14
|
const ticks = getAxisItems({
|
|
10
15
|
scale: scale,
|
|
@@ -12,6 +17,9 @@ async function getLabelSettings({ axis, seriesData, seriesOptions, width, autoRo
|
|
|
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, _b, _c;
|
|
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);
|
|
@@ -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,11 +1,9 @@
|
|
|
1
1
|
import type { ChartSeries, ChartYAxis } from '../../types';
|
|
2
|
-
import type { PreparedSeriesOptions } from '../useSeries/types';
|
|
3
2
|
import type { PreparedAxis } from './types';
|
|
4
|
-
export declare const getPreparedYAxis: ({ height, boundsHeight, width, seriesData,
|
|
3
|
+
export declare const getPreparedYAxis: ({ height, boundsHeight, width, seriesData, yAxis, }: {
|
|
5
4
|
height: number;
|
|
6
5
|
boundsHeight: number;
|
|
7
6
|
width: number;
|
|
8
7
|
seriesData: ChartSeries[];
|
|
9
|
-
seriesOptions: PreparedSeriesOptions;
|
|
10
8
|
yAxis: ChartYAxis[] | undefined;
|
|
11
9
|
}) => Promise<PreparedAxis[]>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import { getTickValues } from '../../components/AxisY/utils';
|
|
3
3
|
import { DASH_STYLE, DEFAULT_AXIS_LABEL_FONT_SIZE, DEFAULT_AXIS_TYPE, axisCrosshairDefaults, axisLabelsDefaults, yAxisTitleDefaults, } from '../../constants';
|
|
4
|
-
import { calculateNumericProperty, getDefaultMinYAxisValue, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight,
|
|
4
|
+
import { calculateNumericProperty, formatAxisTickLabel, getClosestPointsRange, getDefaultDateFormat, getDefaultMinYAxisValue, getHorizontalHtmlTextHeight, getHorizontalSvgTextHeight, getLabelsSize, getScaleTicks, getTextSizeFn, isAxisRelatedSeries, wrapText, } from '../../utils';
|
|
5
5
|
import { createYScale } from '../useAxisScales';
|
|
6
6
|
import { getAxisCategories, prepareAxisPlotLabel } from './utils';
|
|
7
7
|
const getAxisLabelMaxWidth = async (args) => {
|
|
8
|
-
const { axis, seriesData,
|
|
8
|
+
const { axis, seriesData, height } = args;
|
|
9
9
|
if (!axis.labels.enabled) {
|
|
10
10
|
return { height: 0, width: 0 };
|
|
11
11
|
}
|
|
@@ -13,13 +13,23 @@ const getAxisLabelMaxWidth = async (args) => {
|
|
|
13
13
|
axis,
|
|
14
14
|
boundsHeight: height,
|
|
15
15
|
series: seriesData,
|
|
16
|
-
seriesOptions,
|
|
17
16
|
});
|
|
17
|
+
if (!scale) {
|
|
18
|
+
return { height: 0, width: 0 };
|
|
19
|
+
}
|
|
18
20
|
const getTextSize = getTextSizeFn({ style: axis.labels.style });
|
|
19
21
|
const labelLineHeight = (await getTextSize('Tmp')).height;
|
|
20
|
-
const tickValues = getTickValues({ axis, scale, labelLineHeight });
|
|
21
|
-
const
|
|
22
|
-
const
|
|
22
|
+
const tickValues = getTickValues({ axis, scale, labelLineHeight, series: seriesData });
|
|
23
|
+
const ticks = getScaleTicks(scale);
|
|
24
|
+
const tickStep = getClosestPointsRange(axis, ticks);
|
|
25
|
+
if (axis.type === 'datetime' && !axis.labels.dateFormat) {
|
|
26
|
+
axis.labels.dateFormat = getDefaultDateFormat(tickStep);
|
|
27
|
+
}
|
|
28
|
+
const labels = tickValues.map((tick) => formatAxisTickLabel({
|
|
29
|
+
axis,
|
|
30
|
+
value: tick.value,
|
|
31
|
+
step: tickStep,
|
|
32
|
+
}));
|
|
23
33
|
const size = await getLabelsSize({
|
|
24
34
|
labels,
|
|
25
35
|
style: axis.labels.style,
|
|
@@ -28,7 +38,7 @@ const getAxisLabelMaxWidth = async (args) => {
|
|
|
28
38
|
});
|
|
29
39
|
return { height: size.maxHeight, width: size.maxWidth };
|
|
30
40
|
};
|
|
31
|
-
export const getPreparedYAxis = ({ height, boundsHeight, width, seriesData,
|
|
41
|
+
export const getPreparedYAxis = ({ height, boundsHeight, width, seriesData, yAxis, }) => {
|
|
32
42
|
const axisByPlot = [];
|
|
33
43
|
const axisItems = yAxis || [{}];
|
|
34
44
|
const hasAxisRelatedSeries = seriesData.some(isAxisRelatedSeries);
|
|
@@ -100,10 +110,12 @@ export const getPreparedYAxis = ({ height, boundsHeight, width, seriesData, seri
|
|
|
100
110
|
(!firstPlotAxis && !((_d = axisByPlot[plotIndex][0].visible) !== null && _d !== void 0 ? _d : true))),
|
|
101
111
|
},
|
|
102
112
|
ticks: {
|
|
103
|
-
pixelInterval: (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
pixelInterval: ((_e = axisItem.ticks) === null || _e === void 0 ? void 0 : _e.interval)
|
|
114
|
+
? calculateNumericProperty({
|
|
115
|
+
base: height,
|
|
116
|
+
value: (_f = axisItem.ticks) === null || _f === void 0 ? void 0 : _f.interval,
|
|
117
|
+
})
|
|
118
|
+
: (_g = axisItem.ticks) === null || _g === void 0 ? void 0 : _g.pixelInterval,
|
|
107
119
|
},
|
|
108
120
|
position: get(axisItem, 'position', defaultAxisPosition),
|
|
109
121
|
plotIndex: get(axisItem, 'plotIndex', 0),
|
|
@@ -140,7 +152,6 @@ export const getPreparedYAxis = ({ height, boundsHeight, width, seriesData, seri
|
|
|
140
152
|
const { height: labelsHeight, width: labelsWidth } = await getAxisLabelMaxWidth({
|
|
141
153
|
axis: preparedAxis,
|
|
142
154
|
seriesData,
|
|
143
|
-
seriesOptions,
|
|
144
155
|
height: boundsHeight,
|
|
145
156
|
});
|
|
146
157
|
preparedAxis.labels.height = labelsHeight;
|
|
@@ -63,7 +63,8 @@ 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)) {
|
|
@@ -9,7 +9,9 @@ async function prepareDataLabels(series) {
|
|
|
9
9
|
const style = Object.assign({}, DEFAULT_DATALABELS_STYLE, (_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.style);
|
|
10
10
|
const html = get(series, 'dataLabels.html', false);
|
|
11
11
|
const labels = enabled
|
|
12
|
-
? series.data
|
|
12
|
+
? series.data
|
|
13
|
+
.filter((d) => Boolean(d.x || d.label))
|
|
14
|
+
.map((d) => getFormattedValue(Object.assign({ value: d.x || d.label }, series.dataLabels)))
|
|
13
15
|
: [];
|
|
14
16
|
const { maxHeight = 0, maxWidth = 0 } = await getLabelsSize({
|
|
15
17
|
labels,
|
|
@@ -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;
|
|
@@ -2,11 +2,13 @@ import type { ChartScale } from '../../useAxisScales';
|
|
|
2
2
|
import type { PreparedAxis } from '../../useChartOptions/types';
|
|
3
3
|
import type { PreparedBarYSeries, PreparedSeriesOptions } from '../../useSeries/types';
|
|
4
4
|
import type { BarYShapesArgs } from './types';
|
|
5
|
-
export declare
|
|
5
|
+
export declare function prepareBarYData(args: {
|
|
6
|
+
boundsHeight: number;
|
|
7
|
+
boundsWidth: number;
|
|
6
8
|
series: PreparedBarYSeries[];
|
|
7
9
|
seriesOptions: PreparedSeriesOptions;
|
|
8
10
|
xAxis: PreparedAxis;
|
|
9
11
|
xScale: ChartScale;
|
|
10
12
|
yAxis: PreparedAxis[];
|
|
11
|
-
yScale: ChartScale[];
|
|
12
|
-
})
|
|
13
|
+
yScale: (ChartScale | undefined)[];
|
|
14
|
+
}): Promise<BarYShapesArgs>;
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { ascending, descending, sort } from 'd3';
|
|
2
2
|
import get from 'lodash/get';
|
|
3
|
-
import { filterOverlappingLabels, getLabelsSize, getTextSizeFn } from '../../../utils';
|
|
3
|
+
import { filterOverlappingLabels, getHtmlLabelConstraintedPosition, getLabelsSize, getSvgLabelConstraintedPosition, getTextSizeFn, } from '../../../utils';
|
|
4
4
|
import { getFormattedValue } from '../../../utils/chart/format';
|
|
5
|
-
import {
|
|
5
|
+
import { getBarYLayout, groupBarYDataByYValue } from '../../utils';
|
|
6
6
|
const DEFAULT_LABEL_PADDING = 7;
|
|
7
|
-
export
|
|
7
|
+
export async function prepareBarYData(args) {
|
|
8
8
|
var _a;
|
|
9
|
-
const { series, seriesOptions, yAxis, xScale, yScale: [yScale], } = args;
|
|
9
|
+
const { boundsHeight, boundsWidth, series, seriesOptions, yAxis, xScale, yScale: [yScale], } = 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
|
-
const plotHeight = Math.abs(yScaleRange[0] - yScaleRange[1]);
|
|
15
21
|
const sortingOptions = get(seriesOptions, 'bar-y.dataSorting');
|
|
16
22
|
const comparator = (sortingOptions === null || sortingOptions === void 0 ? void 0 : sortingOptions.direction) === 'desc' ? descending : ascending;
|
|
17
23
|
const sortKey = (() => {
|
|
@@ -28,13 +34,13 @@ export const prepareBarYData = async (args) => {
|
|
|
28
34
|
}
|
|
29
35
|
})();
|
|
30
36
|
const groupedData = groupBarYDataByYValue(series, yAxis);
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
const plotHeight = Math.abs(yScaleRange[0] - yScaleRange[1]);
|
|
38
|
+
const { bandSize, barGap, barSize } = getBarYLayout({
|
|
39
|
+
groupedData,
|
|
40
|
+
seriesOptions,
|
|
41
|
+
plotHeight,
|
|
42
|
+
scale: yScale,
|
|
43
|
+
});
|
|
38
44
|
const result = [];
|
|
39
45
|
const baseRangeValue = xLinearScale.range()[0];
|
|
40
46
|
Object.entries(groupedData).forEach(([yValue, val]) => {
|
|
@@ -99,7 +105,7 @@ export const prepareBarYData = async (args) => {
|
|
|
99
105
|
});
|
|
100
106
|
});
|
|
101
107
|
let labels = [];
|
|
102
|
-
|
|
108
|
+
let htmlElements = [];
|
|
103
109
|
const map = new Map();
|
|
104
110
|
for (let i = 0; i < result.length; i++) {
|
|
105
111
|
const prepared = result[i];
|
|
@@ -117,12 +123,20 @@ export const prepareBarYData = async (args) => {
|
|
|
117
123
|
style: dataLabels.style,
|
|
118
124
|
html: dataLabels.html,
|
|
119
125
|
});
|
|
120
|
-
|
|
126
|
+
const constrainedPosition = getHtmlLabelConstraintedPosition({
|
|
127
|
+
boundsHeight,
|
|
128
|
+
boundsWidth,
|
|
129
|
+
height,
|
|
130
|
+
width,
|
|
121
131
|
x,
|
|
122
132
|
y: y - height / 2,
|
|
133
|
+
});
|
|
134
|
+
htmlElements.push({
|
|
123
135
|
content,
|
|
124
136
|
size: { width, height },
|
|
125
137
|
style: dataLabels.style,
|
|
138
|
+
x: constrainedPosition.x,
|
|
139
|
+
y: constrainedPosition.y,
|
|
126
140
|
});
|
|
127
141
|
}
|
|
128
142
|
else {
|
|
@@ -131,24 +145,36 @@ export const prepareBarYData = async (args) => {
|
|
|
131
145
|
}
|
|
132
146
|
const getTextSize = map.get(dataLabels.style);
|
|
133
147
|
const { width, height } = await getTextSize(content);
|
|
134
|
-
|
|
148
|
+
const constrainedPosition = getSvgLabelConstraintedPosition({
|
|
149
|
+
boundsHeight,
|
|
150
|
+
boundsWidth,
|
|
151
|
+
height,
|
|
152
|
+
width,
|
|
135
153
|
x,
|
|
136
154
|
y: y + height / 2,
|
|
155
|
+
});
|
|
156
|
+
labels.push({
|
|
157
|
+
size: { width, height },
|
|
158
|
+
series: prepared.series,
|
|
159
|
+
style: dataLabels.style,
|
|
137
160
|
text: content,
|
|
138
161
|
textAnchor: dataLabels.inside ? 'middle' : 'right',
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
size: { width, height },
|
|
162
|
+
x: constrainedPosition.x,
|
|
163
|
+
y: constrainedPosition.y,
|
|
142
164
|
});
|
|
143
165
|
}
|
|
144
166
|
}
|
|
145
167
|
}
|
|
146
|
-
|
|
168
|
+
const allowOverlap = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.series.dataLabels.allowOverlap;
|
|
169
|
+
if (labels.length && !allowOverlap) {
|
|
147
170
|
labels = filterOverlappingLabels(labels);
|
|
148
171
|
}
|
|
172
|
+
else if (htmlElements.length && !allowOverlap) {
|
|
173
|
+
htmlElements = filterOverlappingLabels(htmlElements);
|
|
174
|
+
}
|
|
149
175
|
return {
|
|
150
176
|
shapes: result,
|
|
151
177
|
labels,
|
|
152
178
|
htmlElements,
|
|
153
179
|
};
|
|
154
|
-
}
|
|
180
|
+
}
|
|
@@ -56,6 +56,8 @@ export const useShapes = (args) => {
|
|
|
56
56
|
case 'bar-y': {
|
|
57
57
|
if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
|
|
58
58
|
const preparedData = await prepareBarYData({
|
|
59
|
+
boundsHeight,
|
|
60
|
+
boundsWidth,
|
|
59
61
|
series: chartSeries,
|
|
60
62
|
seriesOptions,
|
|
61
63
|
xAxis,
|
|
@@ -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
|
}
|