@gravity-ui/charts 1.10.2 → 1.11.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/Axis/AxisY.js +3 -0
- package/dist/cjs/components/ChartInner/index.js +8 -3
- package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +2 -1
- package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +1 -5
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +2 -0
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +11 -3
- package/dist/cjs/components/ChartInner/utils.d.ts +1 -1
- package/dist/cjs/components/ChartInner/utils.js +3 -3
- package/dist/cjs/components/Legend/index.js +4 -1
- package/dist/cjs/hooks/hooks-utils/zoom.d.ts +1 -1
- package/dist/cjs/hooks/hooks-utils/zoom.js +2 -2
- package/dist/cjs/hooks/useAxisScales/index.js +49 -18
- package/dist/cjs/hooks/useChartOptions/x-axis.js +3 -14
- package/dist/cjs/hooks/useChartOptions/y-axis.js +5 -24
- package/dist/cjs/hooks/useSeries/prepare-area.js +2 -1
- package/dist/cjs/hooks/useSeries/prepare-legend.js +2 -2
- package/dist/cjs/hooks/useShapes/area/index.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/area/index.js +13 -9
- package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +4 -3
- package/dist/cjs/hooks/useShapes/area/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/bar-x/index.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/bar-x/index.js +2 -2
- package/dist/cjs/hooks/useShapes/bar-y/index.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/bar-y/index.js +2 -2
- package/dist/cjs/hooks/useShapes/index.d.ts +2 -0
- package/dist/cjs/hooks/useShapes/index.js +146 -137
- package/dist/cjs/hooks/useShapes/line/index.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/line/index.js +16 -12
- package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +2 -1
- package/dist/cjs/hooks/useShapes/line/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/marker.js +6 -0
- package/dist/cjs/hooks/useShapes/scatter/prepare-data.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +6 -3
- package/dist/cjs/hooks/useShapes/scatter/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/waterfall/index.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/waterfall/index.js +2 -2
- package/dist/cjs/hooks/useZoom/index.js +1 -1
- package/dist/cjs/hooks/useZoom/utils.d.ts +1 -1
- package/dist/cjs/hooks/useZoom/utils.js +3 -3
- package/dist/cjs/types/chart/axis.d.ts +4 -5
- package/dist/cjs/utils/chart/axis-generators/bottom.js +3 -1
- package/dist/cjs/utils/chart/index.d.ts +2 -0
- package/dist/cjs/utils/chart/index.js +31 -0
- package/dist/esm/components/Axis/AxisY.js +3 -0
- package/dist/esm/components/ChartInner/index.js +8 -3
- package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +2 -1
- package/dist/esm/components/ChartInner/useChartInnerHandlers.js +1 -5
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +2 -0
- package/dist/esm/components/ChartInner/useChartInnerProps.js +11 -3
- package/dist/esm/components/ChartInner/utils.d.ts +1 -1
- package/dist/esm/components/ChartInner/utils.js +3 -3
- package/dist/esm/components/Legend/index.js +4 -1
- package/dist/esm/hooks/hooks-utils/zoom.d.ts +1 -1
- package/dist/esm/hooks/hooks-utils/zoom.js +2 -2
- package/dist/esm/hooks/useAxisScales/index.js +49 -18
- package/dist/esm/hooks/useChartOptions/x-axis.js +3 -14
- package/dist/esm/hooks/useChartOptions/y-axis.js +5 -24
- package/dist/esm/hooks/useSeries/prepare-area.js +2 -1
- package/dist/esm/hooks/useSeries/prepare-legend.js +2 -2
- package/dist/esm/hooks/useShapes/area/index.d.ts +1 -0
- package/dist/esm/hooks/useShapes/area/index.js +13 -9
- package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -0
- package/dist/esm/hooks/useShapes/area/prepare-data.js +4 -3
- package/dist/esm/hooks/useShapes/area/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/bar-x/index.d.ts +1 -0
- package/dist/esm/hooks/useShapes/bar-x/index.js +2 -2
- package/dist/esm/hooks/useShapes/bar-y/index.d.ts +1 -0
- package/dist/esm/hooks/useShapes/bar-y/index.js +2 -2
- package/dist/esm/hooks/useShapes/index.d.ts +2 -0
- package/dist/esm/hooks/useShapes/index.js +146 -137
- package/dist/esm/hooks/useShapes/line/index.d.ts +1 -0
- package/dist/esm/hooks/useShapes/line/index.js +16 -12
- package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -0
- package/dist/esm/hooks/useShapes/line/prepare-data.js +2 -1
- package/dist/esm/hooks/useShapes/line/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/marker.js +6 -0
- package/dist/esm/hooks/useShapes/scatter/prepare-data.d.ts +1 -0
- package/dist/esm/hooks/useShapes/scatter/prepare-data.js +6 -3
- package/dist/esm/hooks/useShapes/scatter/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/waterfall/index.d.ts +1 -0
- package/dist/esm/hooks/useShapes/waterfall/index.js +2 -2
- package/dist/esm/hooks/useZoom/index.js +1 -1
- package/dist/esm/hooks/useZoom/utils.d.ts +1 -1
- package/dist/esm/hooks/useZoom/utils.js +3 -3
- package/dist/esm/types/chart/axis.d.ts +4 -5
- package/dist/esm/utils/chart/axis-generators/bottom.js +3 -1
- package/dist/esm/utils/chart/index.d.ts +2 -0
- package/dist/esm/utils/chart/index.js +31 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function selectionToZoomBounds(args) {
|
|
2
|
-
const { selection, xAxis, xScale,
|
|
2
|
+
const { selection, xAxis, xScale, yAxes, yScales, zoomType } = args;
|
|
3
3
|
const zoomState = {};
|
|
4
4
|
switch (zoomType) {
|
|
5
5
|
case 'x': {
|
|
@@ -9,7 +9,7 @@ export function selectionToZoomBounds(args) {
|
|
|
9
9
|
}
|
|
10
10
|
case 'y': {
|
|
11
11
|
const [y1, y0] = selection;
|
|
12
|
-
|
|
12
|
+
yAxes.forEach((yAxis, index) => {
|
|
13
13
|
if (!Array.isArray(zoomState.y)) {
|
|
14
14
|
zoomState.y = [];
|
|
15
15
|
}
|
|
@@ -25,7 +25,7 @@ export function selectionToZoomBounds(args) {
|
|
|
25
25
|
const [x0, y0] = selection[0];
|
|
26
26
|
const [x1, y1] = selection[1];
|
|
27
27
|
zoomState.x = selectionXToZoomBounds({ xAxis, xScale, selection: [x0, x1] });
|
|
28
|
-
|
|
28
|
+
yAxes.forEach((yAxis, index) => {
|
|
29
29
|
if (!Array.isArray(zoomState.y)) {
|
|
30
30
|
zoomState.y = [];
|
|
31
31
|
}
|
|
@@ -53,6 +53,8 @@ export interface ChartAxis {
|
|
|
53
53
|
};
|
|
54
54
|
/** The minimum value of the axis. If undefined the min value is automatically calculate. */
|
|
55
55
|
min?: number;
|
|
56
|
+
/** The maximum value of the axis. If undefined the max value is automatically calculate. */
|
|
57
|
+
max?: number;
|
|
56
58
|
/** The grid lines settings. */
|
|
57
59
|
grid?: {
|
|
58
60
|
/** Enable or disable the grid lines.
|
|
@@ -130,11 +132,8 @@ export interface AxisCrosshair extends Omit<AxisPlotLine, 'value'> {
|
|
|
130
132
|
enabled?: boolean;
|
|
131
133
|
}
|
|
132
134
|
export interface ChartYAxis extends ChartAxis {
|
|
133
|
-
/** Axis location.
|
|
134
|
-
* Possible values - 'left' and 'right'.
|
|
135
|
-
* */
|
|
135
|
+
/** Axis location. */
|
|
136
136
|
position?: 'left' | 'right';
|
|
137
|
-
/** Property for splitting charts. Determines which area the axis is located in.
|
|
138
|
-
* */
|
|
137
|
+
/** Property for splitting charts. Determines which area the axis is located in. */
|
|
139
138
|
plotIndex?: number;
|
|
140
139
|
}
|
|
@@ -106,6 +106,7 @@ export async function axisBottom(args) {
|
|
|
106
106
|
.remove();
|
|
107
107
|
// add an ellipsis to the labels that go beyond the boundaries of the chart
|
|
108
108
|
labels.each(function (_d, i, nodes) {
|
|
109
|
+
var _a;
|
|
109
110
|
if (i === 0) {
|
|
110
111
|
const currentElement = this;
|
|
111
112
|
const text = select(currentElement);
|
|
@@ -113,7 +114,8 @@ export async function axisBottom(args) {
|
|
|
113
114
|
const nextElement = nodes[i + 1];
|
|
114
115
|
const nextElementPosition = nextElement === null || nextElement === void 0 ? void 0 : nextElement.getBoundingClientRect();
|
|
115
116
|
if (currentElementPosition.left < leftmostLimit) {
|
|
116
|
-
const
|
|
117
|
+
const rightmostPossiblePoint = (_a = nextElementPosition === null || nextElementPosition === void 0 ? void 0 : nextElementPosition.left) !== null && _a !== void 0 ? _a : right;
|
|
118
|
+
const remainSpace = rightmostPossiblePoint -
|
|
117
119
|
currentElementPosition.right +
|
|
118
120
|
x -
|
|
119
121
|
labelsMargin;
|
|
@@ -44,6 +44,8 @@ export declare function isSeriesWithCategoryValues(series: UnknownSeries): serie
|
|
|
44
44
|
};
|
|
45
45
|
export declare const getDomainDataXBySeries: (series: UnknownSeries[]) => unknown[];
|
|
46
46
|
export declare function getDefaultMaxXAxisValue(series: UnknownSeries[]): 0 | undefined;
|
|
47
|
+
export declare function getDefaultMinXAxisValue(series: UnknownSeries[]): number | undefined;
|
|
48
|
+
export declare function getDefaultMinYAxisValue(series?: UnknownSeries[]): number | undefined;
|
|
47
49
|
export declare const getDomainDataYBySeries: (series: UnknownSeries[]) => unknown[];
|
|
48
50
|
export declare const getSeriesNames: (series: ChartSeries[]) => string[];
|
|
49
51
|
export declare const getOnlyVisibleSeries: <T extends {
|
|
@@ -6,6 +6,7 @@ import sortBy from 'lodash/sortBy';
|
|
|
6
6
|
import { DEFAULT_AXIS_LABEL_FONT_SIZE } from '../../constants';
|
|
7
7
|
import { getSeriesStackId } from '../../hooks/useSeries/utils';
|
|
8
8
|
import { formatNumber, getNumberUnitRate } from '../../libs/format-number';
|
|
9
|
+
import { getWaterfallPointSubtotal } from './series/waterfall';
|
|
9
10
|
import { getDefaultDateFormat } from './time';
|
|
10
11
|
export * from './math';
|
|
11
12
|
export * from './text';
|
|
@@ -90,6 +91,36 @@ export function getDefaultMaxXAxisValue(series) {
|
|
|
90
91
|
}
|
|
91
92
|
return undefined;
|
|
92
93
|
}
|
|
94
|
+
export function getDefaultMinXAxisValue(series) {
|
|
95
|
+
if (series === null || series === void 0 ? void 0 : series.some((s) => CHART_SERIES_WITH_VOLUME_ON_X_AXIS.includes(s.type))) {
|
|
96
|
+
return series.reduce((minValue, s) => {
|
|
97
|
+
// https://github.com/gravity-ui/charts/issues/160
|
|
98
|
+
// @ts-expect-error
|
|
99
|
+
const minXValue = s.data.reduce((res, d) => Math.min(res, get(d, 'x', 0)), 0);
|
|
100
|
+
return Math.min(minValue, minXValue);
|
|
101
|
+
}, 0);
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
export function getDefaultMinYAxisValue(series) {
|
|
106
|
+
if (series === null || series === void 0 ? void 0 : series.some((s) => CHART_SERIES_WITH_VOLUME_ON_Y_AXIS.includes(s.type))) {
|
|
107
|
+
return series.reduce((minValue, s) => {
|
|
108
|
+
switch (s.type) {
|
|
109
|
+
case 'waterfall': {
|
|
110
|
+
const minSubTotal = s.data.reduce((res, d) => Math.min(res, getWaterfallPointSubtotal(d, s) || 0), 0);
|
|
111
|
+
return Math.min(minValue, minSubTotal);
|
|
112
|
+
}
|
|
113
|
+
default: {
|
|
114
|
+
// https://github.com/gravity-ui/charts/issues/160
|
|
115
|
+
// @ts-expect-error
|
|
116
|
+
const minYValue = s.data.reduce((res, d) => Math.min(res, get(d, 'y', 0)), 0);
|
|
117
|
+
return Math.min(minValue, minYValue);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, 0);
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
93
124
|
export const getDomainDataYBySeries = (series) => {
|
|
94
125
|
const groupedSeries = group(series, (item) => item.type);
|
|
95
126
|
return Array.from(groupedSeries).reduce((acc, [type, seriesList]) => {
|