@gravity-ui/charts 1.38.6 → 1.39.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/cjs/components/AxisX/prepare-axis-data.d.ts +1 -1
- package/dist/cjs/components/AxisX/prepare-axis-data.js +10 -10
- package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +1 -1
- package/dist/cjs/components/AxisY/prepare-axis-data.js +2 -2
- package/dist/cjs/components/ChartInner/index.js +25 -8
- package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +1 -2
- package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +5 -1
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +19 -20
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +230 -139
- package/dist/cjs/components/ChartInner/useChartInnerState.js +2 -1
- package/dist/cjs/components/ChartInner/useDefaultState.d.ts +26 -0
- package/dist/cjs/components/ChartInner/useDefaultState.js +74 -0
- package/dist/cjs/components/ChartInner/utils/axis.d.ts +44 -0
- package/dist/cjs/components/ChartInner/utils/axis.js +35 -0
- package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/chart.d.ts +2 -2
- package/dist/{esm/components/ChartInner/utils.d.ts → cjs/components/ChartInner/utils/common.d.ts} +2 -1
- package/dist/cjs/components/ChartInner/utils/index.d.ts +7 -0
- package/dist/cjs/components/ChartInner/utils/index.js +7 -0
- package/dist/cjs/components/ChartInner/utils/normalized-original-data.d.ts +33 -0
- package/dist/cjs/components/ChartInner/utils/normalized-original-data.js +21 -0
- package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/title.d.ts +2 -2
- package/dist/{esm/hooks/useChartOptions → cjs/components/ChartInner/utils}/title.js +1 -1
- package/dist/cjs/components/ChartInner/utils/tooltip.d.ts +8 -0
- package/dist/cjs/components/ChartInner/utils/tooltip.js +7 -0
- package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/zoom.d.ts +3 -3
- package/dist/{esm/hooks/useChartOptions → cjs/components/ChartInner/utils}/zoom.js +1 -1
- package/dist/cjs/components/Legend/index.d.ts +1 -1
- package/dist/cjs/components/Legend/index.js +1 -1
- package/dist/cjs/hooks/index.d.ts +1 -4
- package/dist/cjs/hooks/index.js +1 -4
- package/dist/cjs/hooks/{useChartOptions/types.d.ts → types.d.ts} +1 -1
- package/dist/cjs/hooks/useAxis/index.d.ts +41 -6
- package/dist/cjs/hooks/useAxis/index.js +55 -40
- package/dist/cjs/hooks/useAxis/types.d.ts +0 -2
- package/dist/cjs/hooks/useAxis/y-axis.js +1 -3
- package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -0
- package/dist/cjs/hooks/useAxisScales/index.js +1 -1
- package/dist/cjs/hooks/useAxisScales/x-scale.js +0 -1
- package/dist/cjs/hooks/useAxisScales/y-scale.js +0 -1
- package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
- package/dist/cjs/hooks/useRangeSlider/types.d.ts +1 -1
- package/dist/cjs/hooks/useRangeSlider/utils.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/index.d.ts +10 -14
- package/dist/cjs/hooks/useSeries/index.js +8 -80
- package/dist/cjs/hooks/useSeries/prepare-area.d.ts +2 -2
- package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepare-line.d.ts +2 -2
- package/dist/cjs/hooks/useSeries/prepare-radar.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/index.d.ts +4 -0
- package/dist/cjs/hooks/useShapes/index.js +209 -189
- package/dist/cjs/hooks/useShapes/pie/prepare-data.js +0 -1
- package/dist/cjs/hooks/useSplit/index.d.ts +5 -2
- package/dist/cjs/hooks/useSplit/index.js +27 -30
- package/dist/cjs/hooks/useTooltip/index.d.ts +1 -1
- package/dist/cjs/hooks/useZoom/index.d.ts +2 -2
- package/dist/cjs/hooks/useZoom/index.js +2 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/types/index.d.ts +24 -11
- package/dist/cjs/utils/chart/axis/common.d.ts +2 -2
- package/dist/cjs/utils/chart/axis/common.js +1 -1
- package/dist/cjs/utils/chart/chart-dimensions.d.ts +24 -0
- package/dist/cjs/{hooks/useChartDimensions/index.js → utils/chart/chart-dimensions.js} +56 -33
- package/dist/cjs/utils/chart/common.d.ts +28 -0
- package/dist/cjs/utils/chart/common.js +192 -0
- package/dist/cjs/utils/chart/get-closest-data.js +0 -1
- package/dist/cjs/utils/chart/index.d.ts +2 -28
- package/dist/cjs/utils/chart/index.js +2 -192
- package/dist/cjs/utils/chart/tooltip.d.ts +6 -0
- package/dist/cjs/{hooks/useChartOptions → utils/chart}/tooltip.js +2 -7
- package/dist/cjs/utils/chart/zoom.js +0 -2
- package/dist/esm/components/AxisX/prepare-axis-data.d.ts +1 -1
- package/dist/esm/components/AxisX/prepare-axis-data.js +10 -10
- package/dist/esm/components/AxisY/prepare-axis-data.d.ts +1 -1
- package/dist/esm/components/AxisY/prepare-axis-data.js +2 -2
- package/dist/esm/components/ChartInner/index.js +25 -8
- package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +1 -2
- package/dist/esm/components/ChartInner/useChartInnerHandlers.js +5 -1
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +19 -20
- package/dist/esm/components/ChartInner/useChartInnerProps.js +230 -139
- package/dist/esm/components/ChartInner/useChartInnerState.js +2 -1
- package/dist/esm/components/ChartInner/useDefaultState.d.ts +26 -0
- package/dist/esm/components/ChartInner/useDefaultState.js +74 -0
- package/dist/esm/components/ChartInner/utils/axis.d.ts +44 -0
- package/dist/esm/components/ChartInner/utils/axis.js +35 -0
- package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/chart.d.ts +2 -2
- package/dist/{cjs/components/ChartInner/utils.d.ts → esm/components/ChartInner/utils/common.d.ts} +2 -1
- package/dist/esm/components/ChartInner/utils/index.d.ts +7 -0
- package/dist/esm/components/ChartInner/utils/index.js +7 -0
- package/dist/esm/components/ChartInner/utils/normalized-original-data.d.ts +33 -0
- package/dist/esm/components/ChartInner/utils/normalized-original-data.js +21 -0
- package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/title.d.ts +2 -2
- package/dist/{cjs/hooks/useChartOptions → esm/components/ChartInner/utils}/title.js +1 -1
- package/dist/esm/components/ChartInner/utils/tooltip.d.ts +8 -0
- package/dist/esm/components/ChartInner/utils/tooltip.js +7 -0
- package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/zoom.d.ts +3 -3
- package/dist/{cjs/hooks/useChartOptions → esm/components/ChartInner/utils}/zoom.js +1 -1
- package/dist/esm/components/Legend/index.d.ts +1 -1
- package/dist/esm/components/Legend/index.js +1 -1
- package/dist/esm/hooks/index.d.ts +1 -4
- package/dist/esm/hooks/index.js +1 -4
- package/dist/esm/hooks/{useChartOptions/types.d.ts → types.d.ts} +1 -1
- package/dist/esm/hooks/useAxis/index.d.ts +41 -6
- package/dist/esm/hooks/useAxis/index.js +55 -40
- package/dist/esm/hooks/useAxis/types.d.ts +0 -2
- package/dist/esm/hooks/useAxis/y-axis.js +1 -3
- package/dist/esm/hooks/useAxisScales/index.d.ts +4 -0
- package/dist/esm/hooks/useAxisScales/index.js +1 -1
- package/dist/esm/hooks/useAxisScales/x-scale.js +0 -1
- package/dist/esm/hooks/useAxisScales/y-scale.js +0 -1
- package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
- package/dist/esm/hooks/useRangeSlider/types.d.ts +1 -1
- package/dist/esm/hooks/useRangeSlider/utils.d.ts +1 -1
- package/dist/esm/hooks/useSeries/index.d.ts +10 -14
- package/dist/esm/hooks/useSeries/index.js +8 -80
- package/dist/esm/hooks/useSeries/prepare-area.d.ts +2 -2
- package/dist/esm/hooks/useSeries/prepare-legend.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepare-line.d.ts +2 -2
- package/dist/esm/hooks/useSeries/prepare-radar.d.ts +1 -1
- package/dist/esm/hooks/useShapes/index.d.ts +4 -0
- package/dist/esm/hooks/useShapes/index.js +209 -189
- package/dist/esm/hooks/useShapes/pie/prepare-data.js +0 -1
- package/dist/esm/hooks/useSplit/index.d.ts +5 -2
- package/dist/esm/hooks/useSplit/index.js +27 -30
- package/dist/esm/hooks/useTooltip/index.d.ts +1 -1
- package/dist/esm/hooks/useZoom/index.d.ts +2 -2
- package/dist/esm/hooks/useZoom/index.js +2 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/types/index.d.ts +24 -11
- package/dist/esm/utils/chart/axis/common.d.ts +2 -2
- package/dist/esm/utils/chart/axis/common.js +1 -1
- package/dist/esm/utils/chart/chart-dimensions.d.ts +24 -0
- package/dist/esm/{hooks/useChartDimensions/index.js → utils/chart/chart-dimensions.js} +56 -33
- package/dist/esm/utils/chart/common.d.ts +28 -0
- package/dist/esm/utils/chart/common.js +192 -0
- package/dist/esm/utils/chart/get-closest-data.js +0 -1
- package/dist/esm/utils/chart/index.d.ts +2 -28
- package/dist/esm/utils/chart/index.js +2 -192
- package/dist/esm/utils/chart/tooltip.d.ts +6 -0
- package/dist/esm/{hooks/useChartOptions → utils/chart}/tooltip.js +2 -7
- package/dist/esm/utils/chart/zoom.js +0 -2
- package/package.json +3 -1
- package/dist/cjs/components/ChartInner/useLegend.d.ts +0 -14
- package/dist/cjs/components/ChartInner/useLegend.js +0 -34
- package/dist/cjs/hooks/useChartDimensions/index.d.ts +0 -17
- package/dist/cjs/hooks/useChartDimensions/utils.d.ts +0 -10
- package/dist/cjs/hooks/useChartDimensions/utils.js +0 -41
- package/dist/cjs/hooks/useChartOptions/tooltip.d.ts +0 -13
- package/dist/cjs/hooks/useNormalizedOriginalData/index.d.ts +0 -38
- package/dist/cjs/hooks/useNormalizedOriginalData/index.js +0 -32
- package/dist/cjs/hooks/useYAxisLabelWidth/index.d.ts +0 -11
- package/dist/cjs/hooks/useYAxisLabelWidth/index.js +0 -48
- package/dist/esm/components/ChartInner/useLegend.d.ts +0 -14
- package/dist/esm/components/ChartInner/useLegend.js +0 -34
- package/dist/esm/hooks/useChartDimensions/index.d.ts +0 -17
- package/dist/esm/hooks/useChartDimensions/utils.d.ts +0 -10
- package/dist/esm/hooks/useChartDimensions/utils.js +0 -41
- package/dist/esm/hooks/useChartOptions/tooltip.d.ts +0 -13
- package/dist/esm/hooks/useNormalizedOriginalData/index.d.ts +0 -38
- package/dist/esm/hooks/useNormalizedOriginalData/index.js +0 -32
- package/dist/esm/hooks/useYAxisLabelWidth/index.d.ts +0 -11
- package/dist/esm/hooks/useYAxisLabelWidth/index.js +0 -48
- /package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/chart.js +0 -0
- /package/dist/cjs/components/ChartInner/{utils.js → utils/common.js} +0 -0
- /package/dist/cjs/hooks/{useChartOptions/types.js → types.js} +0 -0
- /package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/chart.js +0 -0
- /package/dist/esm/components/ChartInner/{utils.js → utils/common.js} +0 -0
- /package/dist/esm/hooks/{useChartOptions/types.js → types.js} +0 -0
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import isEqual from 'lodash/isEqual';
|
|
3
|
-
import { getLegendComponents } from '../../hooks/useSeries/prepare-legend';
|
|
4
|
-
export function useLegend({ preparedLegend, preparedChart, preparedSeries, width, height, }) {
|
|
5
|
-
const [legendState, setLegend] = React.useState({
|
|
6
|
-
legendConfig: undefined,
|
|
7
|
-
legendItems: [],
|
|
8
|
-
});
|
|
9
|
-
const legendStateRunRef = React.useRef(0);
|
|
10
|
-
const prevLegendStateValue = React.useRef(legendState);
|
|
11
|
-
React.useEffect(() => {
|
|
12
|
-
legendStateRunRef.current++;
|
|
13
|
-
const currentRun = legendStateRunRef.current;
|
|
14
|
-
if (!preparedLegend) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
(async function () {
|
|
18
|
-
const newStateValue = await getLegendComponents({
|
|
19
|
-
chartWidth: width,
|
|
20
|
-
chartHeight: height,
|
|
21
|
-
chartMargin: preparedChart.margin,
|
|
22
|
-
series: preparedSeries,
|
|
23
|
-
preparedLegend,
|
|
24
|
-
});
|
|
25
|
-
if (legendStateRunRef.current === currentRun) {
|
|
26
|
-
if (!isEqual(prevLegendStateValue.current, newStateValue)) {
|
|
27
|
-
setLegend(newStateValue);
|
|
28
|
-
prevLegendStateValue.current = newStateValue;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
})();
|
|
32
|
-
}, [height, preparedChart.margin, preparedLegend, preparedSeries, width]);
|
|
33
|
-
return legendState;
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { PreparedLegend, PreparedSeries, PreparedXAxis, PreparedYAxis } from '../../hooks';
|
|
2
|
-
import type { ChartMargin, LegendConfig } from '../../types';
|
|
3
|
-
export { getBoundsWidth } from './utils';
|
|
4
|
-
type Args = {
|
|
5
|
-
height: number;
|
|
6
|
-
margin: ChartMargin;
|
|
7
|
-
preparedLegend: PreparedLegend | null;
|
|
8
|
-
preparedSeries: PreparedSeries[];
|
|
9
|
-
preparedXAxis: PreparedXAxis | null;
|
|
10
|
-
preparedYAxis: PreparedYAxis[] | null;
|
|
11
|
-
width: number;
|
|
12
|
-
legendConfig: LegendConfig | undefined;
|
|
13
|
-
};
|
|
14
|
-
export declare const useChartDimensions: (args: Args) => {
|
|
15
|
-
boundsWidth: number;
|
|
16
|
-
boundsHeight: number;
|
|
17
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { PreparedChart, PreparedYAxis } from '../../hooks';
|
|
2
|
-
export declare const getBoundsWidth: (args: {
|
|
3
|
-
chartWidth: number;
|
|
4
|
-
chartMargin: PreparedChart["margin"];
|
|
5
|
-
preparedYAxis: PreparedYAxis[] | null;
|
|
6
|
-
}) => number;
|
|
7
|
-
export declare function getYAxisWidth(axis: PreparedYAxis | undefined): number;
|
|
8
|
-
export declare function getWidthOccupiedByYAxis(args: {
|
|
9
|
-
preparedAxis: PreparedYAxis[] | null;
|
|
10
|
-
}): number;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export const getBoundsWidth = (args) => {
|
|
2
|
-
const { chartWidth, chartMargin, preparedYAxis } = args;
|
|
3
|
-
return (chartWidth -
|
|
4
|
-
chartMargin.right -
|
|
5
|
-
chartMargin.left -
|
|
6
|
-
getWidthOccupiedByYAxis({ preparedAxis: preparedYAxis }));
|
|
7
|
-
};
|
|
8
|
-
export function getYAxisWidth(axis) {
|
|
9
|
-
if (!(axis === null || axis === void 0 ? void 0 : axis.visible)) {
|
|
10
|
-
return 0;
|
|
11
|
-
}
|
|
12
|
-
let result = 0;
|
|
13
|
-
if (axis === null || axis === void 0 ? void 0 : axis.title.text) {
|
|
14
|
-
result += axis.title.margin;
|
|
15
|
-
if (axis.title.rotation === 0) {
|
|
16
|
-
result += axis.title.width;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
result += axis.title.height;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (axis === null || axis === void 0 ? void 0 : axis.labels.enabled) {
|
|
23
|
-
result += axis.labels.margin + axis.labels.width;
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
export function getWidthOccupiedByYAxis(args) {
|
|
28
|
-
const { preparedAxis } = args;
|
|
29
|
-
let leftAxisWidth = 0;
|
|
30
|
-
let rightAxisWidth = 0;
|
|
31
|
-
preparedAxis === null || preparedAxis === void 0 ? void 0 : preparedAxis.forEach((axis) => {
|
|
32
|
-
const axisWidth = getYAxisWidth(axis);
|
|
33
|
-
if (axis.position === 'right') {
|
|
34
|
-
rightAxisWidth = Math.max(rightAxisWidth, axisWidth);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
leftAxisWidth = Math.max(leftAxisWidth, axisWidth);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return leftAxisWidth + rightAxisWidth;
|
|
41
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ChartData, ChartSeries, ChartXAxis, ChartYAxis } from '../../types';
|
|
2
|
-
import type { PreparedTooltip } from './types';
|
|
3
|
-
export declare function getDefaultTooltipHeaderFormat({ seriesData, yAxes, xAxis, }: {
|
|
4
|
-
seriesData: ChartSeries[];
|
|
5
|
-
yAxes?: ChartYAxis[];
|
|
6
|
-
xAxis?: ChartXAxis;
|
|
7
|
-
}): import("../../types").ValueFormat | undefined;
|
|
8
|
-
export declare const getPreparedTooltip: (args: {
|
|
9
|
-
tooltip: ChartData["tooltip"];
|
|
10
|
-
seriesData: ChartSeries[];
|
|
11
|
-
yAxes?: ChartYAxis[];
|
|
12
|
-
xAxis?: ChartXAxis;
|
|
13
|
-
}) => PreparedTooltip;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ChartData } from '../../types';
|
|
2
|
-
interface UseOriginalDataProps {
|
|
3
|
-
seriesData: ChartData['series']['data'];
|
|
4
|
-
xAxis: ChartData['xAxis'];
|
|
5
|
-
yAxis: ChartData['yAxis'];
|
|
6
|
-
}
|
|
7
|
-
export declare function useNormalizedOriginalData(props: UseOriginalDataProps): {
|
|
8
|
-
normalizedSeriesData: import("../../types").ChartSeries[];
|
|
9
|
-
normalizedXAxis: {
|
|
10
|
-
categories: string[] | undefined;
|
|
11
|
-
rangeSlider?: import("../../types").ChartAxisRangeSlider;
|
|
12
|
-
crosshair?: import("../../types").AxisCrosshair;
|
|
13
|
-
timestamps?: number[];
|
|
14
|
-
type?: import("../../types").ChartAxisType;
|
|
15
|
-
labels?: import("../../types").ChartAxisLabels;
|
|
16
|
-
lineColor?: string;
|
|
17
|
-
title?: import("../../types").ChartAxisTitle;
|
|
18
|
-
min?: number;
|
|
19
|
-
max?: number;
|
|
20
|
-
grid?: {
|
|
21
|
-
enabled?: boolean;
|
|
22
|
-
};
|
|
23
|
-
ticks?: {
|
|
24
|
-
pixelInterval?: number;
|
|
25
|
-
interval?: number | string;
|
|
26
|
-
};
|
|
27
|
-
maxPadding?: number;
|
|
28
|
-
plotLines?: import("../../types").AxisPlotLine[];
|
|
29
|
-
plotBands?: import("../../types").AxisPlotBand[];
|
|
30
|
-
tickMarks?: import("../../types").ChartAxisTickMarks;
|
|
31
|
-
visible?: boolean;
|
|
32
|
-
order?: "sortAsc" | "sortDesc" | "reverse";
|
|
33
|
-
startOnTick?: boolean;
|
|
34
|
-
endOnTick?: boolean;
|
|
35
|
-
};
|
|
36
|
-
normalizedYAxis: import("../../types").ChartYAxis[] | undefined;
|
|
37
|
-
};
|
|
38
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { getAxisCategories, getSortedSeriesData } from '../../utils';
|
|
3
|
-
export function useNormalizedOriginalData(props) {
|
|
4
|
-
const normalizedSeriesData = React.useMemo(() => {
|
|
5
|
-
return getSortedSeriesData({
|
|
6
|
-
seriesData: props.seriesData,
|
|
7
|
-
xAxis: props.xAxis,
|
|
8
|
-
yAxis: props.yAxis,
|
|
9
|
-
});
|
|
10
|
-
}, [props.seriesData, props.xAxis, props.yAxis]);
|
|
11
|
-
const normalizedXAxis = React.useMemo(() => {
|
|
12
|
-
var _a;
|
|
13
|
-
let categories = (_a = props.xAxis) === null || _a === void 0 ? void 0 : _a.categories;
|
|
14
|
-
if (props.xAxis && props.xAxis.categories) {
|
|
15
|
-
categories = getAxisCategories(props.xAxis);
|
|
16
|
-
}
|
|
17
|
-
return Object.assign(Object.assign({}, props.xAxis), { categories });
|
|
18
|
-
}, [props.xAxis]);
|
|
19
|
-
const normalizedYAxis = React.useMemo(() => {
|
|
20
|
-
if (Array.isArray(props.yAxis) && props.yAxis.some((axis) => axis.categories)) {
|
|
21
|
-
return props.yAxis.map((axis) => {
|
|
22
|
-
let categories = axis.categories;
|
|
23
|
-
if (axis.categories) {
|
|
24
|
-
categories = getAxisCategories(axis);
|
|
25
|
-
}
|
|
26
|
-
return Object.assign(Object.assign({}, axis), { categories });
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
return props.yAxis;
|
|
30
|
-
}, [props.yAxis]);
|
|
31
|
-
return { normalizedSeriesData, normalizedXAxis, normalizedYAxis };
|
|
32
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { PreparedYAxis, SetAxes } from '../useAxis/types';
|
|
2
|
-
import type { ChartScale } from '../useAxisScales/types';
|
|
3
|
-
import type { PreparedSeries } from '../useSeries/types';
|
|
4
|
-
type UseYAxisLabelWidthProps = {
|
|
5
|
-
seriesData: PreparedSeries[];
|
|
6
|
-
setAxes: SetAxes;
|
|
7
|
-
yAxis: PreparedYAxis[];
|
|
8
|
-
yScale?: (ChartScale | undefined)[];
|
|
9
|
-
};
|
|
10
|
-
export declare function useYAxisLabelWidth(props: UseYAxisLabelWidthProps): void;
|
|
11
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import get from 'lodash/get';
|
|
3
|
-
import { getYAxisLabelMaxWidth } from '../useAxis/y-axis';
|
|
4
|
-
export function useYAxisLabelWidth(props) {
|
|
5
|
-
const { seriesData, setAxes, yAxis, yScale } = props;
|
|
6
|
-
const runRef = React.useRef(0);
|
|
7
|
-
React.useEffect(() => {
|
|
8
|
-
runRef.current++;
|
|
9
|
-
(async function () {
|
|
10
|
-
const currentRun = runRef.current;
|
|
11
|
-
const axisIndexesToRecalculateMap = new Map();
|
|
12
|
-
for (let i = 0; i < yAxis.length; i++) {
|
|
13
|
-
const axis = yAxis[i];
|
|
14
|
-
const scale = yScale === null || yScale === void 0 ? void 0 : yScale[i];
|
|
15
|
-
if (!scale) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
if (axis.startOnTick || axis.endOnTick) {
|
|
19
|
-
const axisSeriesData = seriesData.filter((s) => get(s, 'yAxis', 0) === i && s.visible);
|
|
20
|
-
if (axisSeriesData.length === 0) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const res = await getYAxisLabelMaxWidth({
|
|
24
|
-
axis,
|
|
25
|
-
seriesData: axisSeriesData,
|
|
26
|
-
scale,
|
|
27
|
-
});
|
|
28
|
-
if (res.width > axis.labels.width) {
|
|
29
|
-
axisIndexesToRecalculateMap.set(i, res.width);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (runRef.current === currentRun && axisIndexesToRecalculateMap.size > 0) {
|
|
34
|
-
setAxes((prevState) => {
|
|
35
|
-
const newYAxis = prevState.yAxis.map((axis, i) => {
|
|
36
|
-
const width = axisIndexesToRecalculateMap.get(i);
|
|
37
|
-
if (width) {
|
|
38
|
-
const axisWithRecalculatedLabels = Object.assign(Object.assign({}, axis), { labels: Object.assign(Object.assign({}, axis.labels), { width }) });
|
|
39
|
-
return axisWithRecalculatedLabels;
|
|
40
|
-
}
|
|
41
|
-
return axis;
|
|
42
|
-
});
|
|
43
|
-
return Object.assign(Object.assign({}, prevState), { yAxis: newYAxis });
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
})();
|
|
47
|
-
}, [seriesData, setAxes, yAxis, yScale]);
|
|
48
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { LegendItem, PreparedChart, PreparedLegend, PreparedSeries } from '../../hooks';
|
|
2
|
-
import type { LegendConfig } from '../../types';
|
|
3
|
-
type LegendState = {
|
|
4
|
-
legendConfig?: LegendConfig;
|
|
5
|
-
legendItems: LegendItem[][];
|
|
6
|
-
};
|
|
7
|
-
export declare function useLegend({ preparedLegend, preparedChart, preparedSeries, width, height, }: {
|
|
8
|
-
preparedLegend: PreparedLegend | null;
|
|
9
|
-
preparedChart: PreparedChart;
|
|
10
|
-
preparedSeries: PreparedSeries[];
|
|
11
|
-
width: number;
|
|
12
|
-
height: number;
|
|
13
|
-
}): LegendState;
|
|
14
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import isEqual from 'lodash/isEqual';
|
|
3
|
-
import { getLegendComponents } from '../../hooks/useSeries/prepare-legend';
|
|
4
|
-
export function useLegend({ preparedLegend, preparedChart, preparedSeries, width, height, }) {
|
|
5
|
-
const [legendState, setLegend] = React.useState({
|
|
6
|
-
legendConfig: undefined,
|
|
7
|
-
legendItems: [],
|
|
8
|
-
});
|
|
9
|
-
const legendStateRunRef = React.useRef(0);
|
|
10
|
-
const prevLegendStateValue = React.useRef(legendState);
|
|
11
|
-
React.useEffect(() => {
|
|
12
|
-
legendStateRunRef.current++;
|
|
13
|
-
const currentRun = legendStateRunRef.current;
|
|
14
|
-
if (!preparedLegend) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
(async function () {
|
|
18
|
-
const newStateValue = await getLegendComponents({
|
|
19
|
-
chartWidth: width,
|
|
20
|
-
chartHeight: height,
|
|
21
|
-
chartMargin: preparedChart.margin,
|
|
22
|
-
series: preparedSeries,
|
|
23
|
-
preparedLegend,
|
|
24
|
-
});
|
|
25
|
-
if (legendStateRunRef.current === currentRun) {
|
|
26
|
-
if (!isEqual(prevLegendStateValue.current, newStateValue)) {
|
|
27
|
-
setLegend(newStateValue);
|
|
28
|
-
prevLegendStateValue.current = newStateValue;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
})();
|
|
32
|
-
}, [height, preparedChart.margin, preparedLegend, preparedSeries, width]);
|
|
33
|
-
return legendState;
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { PreparedLegend, PreparedSeries, PreparedXAxis, PreparedYAxis } from '../../hooks';
|
|
2
|
-
import type { ChartMargin, LegendConfig } from '../../types';
|
|
3
|
-
export { getBoundsWidth } from './utils';
|
|
4
|
-
type Args = {
|
|
5
|
-
height: number;
|
|
6
|
-
margin: ChartMargin;
|
|
7
|
-
preparedLegend: PreparedLegend | null;
|
|
8
|
-
preparedSeries: PreparedSeries[];
|
|
9
|
-
preparedXAxis: PreparedXAxis | null;
|
|
10
|
-
preparedYAxis: PreparedYAxis[] | null;
|
|
11
|
-
width: number;
|
|
12
|
-
legendConfig: LegendConfig | undefined;
|
|
13
|
-
};
|
|
14
|
-
export declare const useChartDimensions: (args: Args) => {
|
|
15
|
-
boundsWidth: number;
|
|
16
|
-
boundsHeight: number;
|
|
17
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { PreparedChart, PreparedYAxis } from '../../hooks';
|
|
2
|
-
export declare const getBoundsWidth: (args: {
|
|
3
|
-
chartWidth: number;
|
|
4
|
-
chartMargin: PreparedChart["margin"];
|
|
5
|
-
preparedYAxis: PreparedYAxis[] | null;
|
|
6
|
-
}) => number;
|
|
7
|
-
export declare function getYAxisWidth(axis: PreparedYAxis | undefined): number;
|
|
8
|
-
export declare function getWidthOccupiedByYAxis(args: {
|
|
9
|
-
preparedAxis: PreparedYAxis[] | null;
|
|
10
|
-
}): number;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export const getBoundsWidth = (args) => {
|
|
2
|
-
const { chartWidth, chartMargin, preparedYAxis } = args;
|
|
3
|
-
return (chartWidth -
|
|
4
|
-
chartMargin.right -
|
|
5
|
-
chartMargin.left -
|
|
6
|
-
getWidthOccupiedByYAxis({ preparedAxis: preparedYAxis }));
|
|
7
|
-
};
|
|
8
|
-
export function getYAxisWidth(axis) {
|
|
9
|
-
if (!(axis === null || axis === void 0 ? void 0 : axis.visible)) {
|
|
10
|
-
return 0;
|
|
11
|
-
}
|
|
12
|
-
let result = 0;
|
|
13
|
-
if (axis === null || axis === void 0 ? void 0 : axis.title.text) {
|
|
14
|
-
result += axis.title.margin;
|
|
15
|
-
if (axis.title.rotation === 0) {
|
|
16
|
-
result += axis.title.width;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
result += axis.title.height;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (axis === null || axis === void 0 ? void 0 : axis.labels.enabled) {
|
|
23
|
-
result += axis.labels.margin + axis.labels.width;
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
export function getWidthOccupiedByYAxis(args) {
|
|
28
|
-
const { preparedAxis } = args;
|
|
29
|
-
let leftAxisWidth = 0;
|
|
30
|
-
let rightAxisWidth = 0;
|
|
31
|
-
preparedAxis === null || preparedAxis === void 0 ? void 0 : preparedAxis.forEach((axis) => {
|
|
32
|
-
const axisWidth = getYAxisWidth(axis);
|
|
33
|
-
if (axis.position === 'right') {
|
|
34
|
-
rightAxisWidth = Math.max(rightAxisWidth, axisWidth);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
leftAxisWidth = Math.max(leftAxisWidth, axisWidth);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return leftAxisWidth + rightAxisWidth;
|
|
41
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ChartData, ChartSeries, ChartXAxis, ChartYAxis } from '../../types';
|
|
2
|
-
import type { PreparedTooltip } from './types';
|
|
3
|
-
export declare function getDefaultTooltipHeaderFormat({ seriesData, yAxes, xAxis, }: {
|
|
4
|
-
seriesData: ChartSeries[];
|
|
5
|
-
yAxes?: ChartYAxis[];
|
|
6
|
-
xAxis?: ChartXAxis;
|
|
7
|
-
}): import("../..").ValueFormat | undefined;
|
|
8
|
-
export declare const getPreparedTooltip: (args: {
|
|
9
|
-
tooltip: ChartData["tooltip"];
|
|
10
|
-
seriesData: ChartSeries[];
|
|
11
|
-
yAxes?: ChartYAxis[];
|
|
12
|
-
xAxis?: ChartXAxis;
|
|
13
|
-
}) => PreparedTooltip;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ChartData } from '../../types';
|
|
2
|
-
interface UseOriginalDataProps {
|
|
3
|
-
seriesData: ChartData['series']['data'];
|
|
4
|
-
xAxis: ChartData['xAxis'];
|
|
5
|
-
yAxis: ChartData['yAxis'];
|
|
6
|
-
}
|
|
7
|
-
export declare function useNormalizedOriginalData(props: UseOriginalDataProps): {
|
|
8
|
-
normalizedSeriesData: import("../..").ChartSeries[];
|
|
9
|
-
normalizedXAxis: {
|
|
10
|
-
categories: string[] | undefined;
|
|
11
|
-
rangeSlider?: import("../..").ChartAxisRangeSlider;
|
|
12
|
-
crosshair?: import("../..").AxisCrosshair;
|
|
13
|
-
timestamps?: number[];
|
|
14
|
-
type?: import("../..").ChartAxisType;
|
|
15
|
-
labels?: import("../..").ChartAxisLabels;
|
|
16
|
-
lineColor?: string;
|
|
17
|
-
title?: import("../..").ChartAxisTitle;
|
|
18
|
-
min?: number;
|
|
19
|
-
max?: number;
|
|
20
|
-
grid?: {
|
|
21
|
-
enabled?: boolean;
|
|
22
|
-
};
|
|
23
|
-
ticks?: {
|
|
24
|
-
pixelInterval?: number;
|
|
25
|
-
interval?: number | string;
|
|
26
|
-
};
|
|
27
|
-
maxPadding?: number;
|
|
28
|
-
plotLines?: import("../..").AxisPlotLine[];
|
|
29
|
-
plotBands?: import("../..").AxisPlotBand[];
|
|
30
|
-
tickMarks?: import("../..").ChartAxisTickMarks;
|
|
31
|
-
visible?: boolean;
|
|
32
|
-
order?: "sortAsc" | "sortDesc" | "reverse";
|
|
33
|
-
startOnTick?: boolean;
|
|
34
|
-
endOnTick?: boolean;
|
|
35
|
-
};
|
|
36
|
-
normalizedYAxis: import("../..").ChartYAxis[] | undefined;
|
|
37
|
-
};
|
|
38
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { getAxisCategories, getSortedSeriesData } from '../../utils';
|
|
3
|
-
export function useNormalizedOriginalData(props) {
|
|
4
|
-
const normalizedSeriesData = React.useMemo(() => {
|
|
5
|
-
return getSortedSeriesData({
|
|
6
|
-
seriesData: props.seriesData,
|
|
7
|
-
xAxis: props.xAxis,
|
|
8
|
-
yAxis: props.yAxis,
|
|
9
|
-
});
|
|
10
|
-
}, [props.seriesData, props.xAxis, props.yAxis]);
|
|
11
|
-
const normalizedXAxis = React.useMemo(() => {
|
|
12
|
-
var _a;
|
|
13
|
-
let categories = (_a = props.xAxis) === null || _a === void 0 ? void 0 : _a.categories;
|
|
14
|
-
if (props.xAxis && props.xAxis.categories) {
|
|
15
|
-
categories = getAxisCategories(props.xAxis);
|
|
16
|
-
}
|
|
17
|
-
return Object.assign(Object.assign({}, props.xAxis), { categories });
|
|
18
|
-
}, [props.xAxis]);
|
|
19
|
-
const normalizedYAxis = React.useMemo(() => {
|
|
20
|
-
if (Array.isArray(props.yAxis) && props.yAxis.some((axis) => axis.categories)) {
|
|
21
|
-
return props.yAxis.map((axis) => {
|
|
22
|
-
let categories = axis.categories;
|
|
23
|
-
if (axis.categories) {
|
|
24
|
-
categories = getAxisCategories(axis);
|
|
25
|
-
}
|
|
26
|
-
return Object.assign(Object.assign({}, axis), { categories });
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
return props.yAxis;
|
|
30
|
-
}, [props.yAxis]);
|
|
31
|
-
return { normalizedSeriesData, normalizedXAxis, normalizedYAxis };
|
|
32
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { PreparedYAxis, SetAxes } from '../useAxis/types';
|
|
2
|
-
import type { ChartScale } from '../useAxisScales/types';
|
|
3
|
-
import type { PreparedSeries } from '../useSeries/types';
|
|
4
|
-
type UseYAxisLabelWidthProps = {
|
|
5
|
-
seriesData: PreparedSeries[];
|
|
6
|
-
setAxes: SetAxes;
|
|
7
|
-
yAxis: PreparedYAxis[];
|
|
8
|
-
yScale?: (ChartScale | undefined)[];
|
|
9
|
-
};
|
|
10
|
-
export declare function useYAxisLabelWidth(props: UseYAxisLabelWidthProps): void;
|
|
11
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import get from 'lodash/get';
|
|
3
|
-
import { getYAxisLabelMaxWidth } from '../useAxis/y-axis';
|
|
4
|
-
export function useYAxisLabelWidth(props) {
|
|
5
|
-
const { seriesData, setAxes, yAxis, yScale } = props;
|
|
6
|
-
const runRef = React.useRef(0);
|
|
7
|
-
React.useEffect(() => {
|
|
8
|
-
runRef.current++;
|
|
9
|
-
(async function () {
|
|
10
|
-
const currentRun = runRef.current;
|
|
11
|
-
const axisIndexesToRecalculateMap = new Map();
|
|
12
|
-
for (let i = 0; i < yAxis.length; i++) {
|
|
13
|
-
const axis = yAxis[i];
|
|
14
|
-
const scale = yScale === null || yScale === void 0 ? void 0 : yScale[i];
|
|
15
|
-
if (!scale) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
if (axis.startOnTick || axis.endOnTick) {
|
|
19
|
-
const axisSeriesData = seriesData.filter((s) => get(s, 'yAxis', 0) === i && s.visible);
|
|
20
|
-
if (axisSeriesData.length === 0) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const res = await getYAxisLabelMaxWidth({
|
|
24
|
-
axis,
|
|
25
|
-
seriesData: axisSeriesData,
|
|
26
|
-
scale,
|
|
27
|
-
});
|
|
28
|
-
if (res.width > axis.labels.width) {
|
|
29
|
-
axisIndexesToRecalculateMap.set(i, res.width);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (runRef.current === currentRun && axisIndexesToRecalculateMap.size > 0) {
|
|
34
|
-
setAxes((prevState) => {
|
|
35
|
-
const newYAxis = prevState.yAxis.map((axis, i) => {
|
|
36
|
-
const width = axisIndexesToRecalculateMap.get(i);
|
|
37
|
-
if (width) {
|
|
38
|
-
const axisWithRecalculatedLabels = Object.assign(Object.assign({}, axis), { labels: Object.assign(Object.assign({}, axis.labels), { width }) });
|
|
39
|
-
return axisWithRecalculatedLabels;
|
|
40
|
-
}
|
|
41
|
-
return axis;
|
|
42
|
-
});
|
|
43
|
-
return Object.assign(Object.assign({}, prevState), { yAxis: newYAxis });
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
})();
|
|
47
|
-
}, [seriesData, setAxes, yAxis, yScale]);
|
|
48
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|