@gravity-ui/charts 1.39.1 → 1.41.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/README.md +4 -24
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +2 -38
- package/dist/cjs/components/ChartInner/utils/axis.d.ts +1 -37
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/Row.js +4 -4
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/RowWithAggregation.js +3 -2
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +128 -118
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.d.ts +6 -0
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.js +41 -0
- package/dist/cjs/components/Tooltip/index.js +2 -0
- package/dist/cjs/components/Tooltip/styles.css +33 -7
- package/dist/cjs/components/index.d.ts +4 -1
- package/dist/cjs/components/index.js +8 -3
- package/dist/cjs/hooks/useAxis/index.d.ts +1 -37
- package/dist/cjs/hooks/useAxis/types.d.ts +6 -4
- package/dist/cjs/hooks/useAxisScales/index.d.ts +2 -2
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +3 -2
- package/dist/cjs/hooks/useShapes/bar-x/types.d.ts +5 -0
- package/dist/cjs/hooks/useTooltip/index.d.ts +4 -1
- package/dist/cjs/hooks/useTooltip/index.js +12 -5
- package/dist/cjs/types/chart/axis.d.ts +2 -1
- package/dist/cjs/types/chart/tooltip.d.ts +44 -1
- package/dist/cjs/utils/chart/zoom.js +2 -2
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +2 -38
- package/dist/esm/components/ChartInner/utils/axis.d.ts +1 -37
- package/dist/esm/components/Tooltip/DefaultTooltipContent/Row.js +4 -4
- package/dist/esm/components/Tooltip/DefaultTooltipContent/RowWithAggregation.js +3 -2
- package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +128 -118
- package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.d.ts +6 -0
- package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.js +41 -0
- package/dist/esm/components/Tooltip/index.js +2 -0
- package/dist/esm/components/Tooltip/styles.css +33 -7
- package/dist/esm/components/index.d.ts +4 -1
- package/dist/esm/components/index.js +8 -3
- package/dist/esm/hooks/useAxis/index.d.ts +1 -37
- package/dist/esm/hooks/useAxis/types.d.ts +6 -4
- package/dist/esm/hooks/useAxisScales/index.d.ts +2 -2
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +3 -2
- package/dist/esm/hooks/useShapes/bar-x/types.d.ts +5 -0
- package/dist/esm/hooks/useTooltip/index.d.ts +4 -1
- package/dist/esm/hooks/useTooltip/index.js +12 -5
- package/dist/esm/types/chart/axis.d.ts +2 -1
- package/dist/esm/types/chart/tooltip.d.ts +44 -1
- package/dist/esm/utils/chart/zoom.js +2 -2
- package/package.json +2 -1
|
@@ -130,6 +130,47 @@ export function getPreparedAggregation(args) {
|
|
|
130
130
|
}
|
|
131
131
|
return 'sum';
|
|
132
132
|
}
|
|
133
|
+
export function getSortedHovered(args) {
|
|
134
|
+
var _a;
|
|
135
|
+
const { hovered, sorting, xAxis, yAxis } = args;
|
|
136
|
+
if (!sorting) {
|
|
137
|
+
return hovered;
|
|
138
|
+
}
|
|
139
|
+
if (typeof sorting === 'function') {
|
|
140
|
+
return [...hovered].sort(sorting);
|
|
141
|
+
}
|
|
142
|
+
switch (sorting.key) {
|
|
143
|
+
case 'value': {
|
|
144
|
+
const values = getHoveredValues({ hovered, xAxis, yAxis });
|
|
145
|
+
const direction = (_a = sorting.direction) !== null && _a !== void 0 ? _a : 'asc';
|
|
146
|
+
const compareValue = (a, b) => {
|
|
147
|
+
const aNil = a === null || a === undefined;
|
|
148
|
+
const bNil = b === null || b === undefined;
|
|
149
|
+
if (aNil && bNil) {
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
if (aNil) {
|
|
153
|
+
return -1;
|
|
154
|
+
}
|
|
155
|
+
if (bNil) {
|
|
156
|
+
return 1;
|
|
157
|
+
}
|
|
158
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
159
|
+
return a - b;
|
|
160
|
+
}
|
|
161
|
+
return String(a).localeCompare(String(b));
|
|
162
|
+
};
|
|
163
|
+
const indices = hovered.map((_, i) => i);
|
|
164
|
+
indices.sort((i, j) => direction === 'asc'
|
|
165
|
+
? compareValue(values[i], values[j])
|
|
166
|
+
: compareValue(values[j], values[i]));
|
|
167
|
+
return indices.map((i) => hovered[i]);
|
|
168
|
+
}
|
|
169
|
+
default: {
|
|
170
|
+
return hovered;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
133
174
|
export function getTooltipRowColorSymbol({ series, color, height = 8, width = 16, }) {
|
|
134
175
|
if ((series === null || series === void 0 ? void 0 : series.type) === 'line') {
|
|
135
176
|
const colorSymbol = create('svg').attr('height', height).attr('width', width);
|
|
@@ -10,6 +10,8 @@ export const Tooltip = (props) => {
|
|
|
10
10
|
const { hovered, hoveredPlotLines, hoveredPlotBands, pointerPosition } = useTooltip({
|
|
11
11
|
dispatcher,
|
|
12
12
|
tooltip,
|
|
13
|
+
xAxis,
|
|
14
|
+
yAxis,
|
|
13
15
|
});
|
|
14
16
|
const containerRect = (svgContainer === null || svgContainer === void 0 ? void 0 : svgContainer.getBoundingClientRect()) || { left: 0, top: 0 };
|
|
15
17
|
const left = ((pointerPosition === null || pointerPosition === void 0 ? void 0 : pointerPosition[0]) || 0) + containerRect.left;
|
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
background-color: var(--g-color-infographics-tooltip-bg);
|
|
4
4
|
box-shadow: 0 2px 12px var(--g-color-sfx-shadow);
|
|
5
5
|
}
|
|
6
|
+
tr.gcharts-tooltip__content-row {
|
|
7
|
+
display: table-row;
|
|
8
|
+
padding: 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
.gcharts-tooltip__popup-content {
|
|
7
|
-
max-width: 450px;
|
|
8
12
|
text-wrap: nowrap;
|
|
9
13
|
border-radius: 4px;
|
|
10
14
|
}
|
|
@@ -20,7 +24,13 @@
|
|
|
20
24
|
.gcharts-tooltip__content-rows_pinned {
|
|
21
25
|
overflow: auto;
|
|
22
26
|
}
|
|
27
|
+
.gcharts-tooltip__content-rows-table {
|
|
28
|
+
width: 100%;
|
|
29
|
+
padding: 0;
|
|
30
|
+
border-collapse: collapse;
|
|
31
|
+
}
|
|
23
32
|
.gcharts-tooltip__series-name {
|
|
33
|
+
max-width: 450px;
|
|
24
34
|
padding: 2px 14px 6px;
|
|
25
35
|
font-size: 13px;
|
|
26
36
|
font-weight: 600;
|
|
@@ -45,8 +55,23 @@
|
|
|
45
55
|
font-weight: 600;
|
|
46
56
|
background-color: var(--g-color-base-info-medium);
|
|
47
57
|
}
|
|
48
|
-
.gcharts-tooltip__content-
|
|
58
|
+
.gcharts-tooltip__content-row_totals {
|
|
59
|
+
color: var(--g-color-text-complementary);
|
|
60
|
+
}
|
|
61
|
+
.gcharts-tooltip__content-row-totals-label {
|
|
49
62
|
overflow: hidden;
|
|
63
|
+
max-width: 400px;
|
|
64
|
+
white-space: nowrap;
|
|
65
|
+
text-overflow: ellipsis;
|
|
66
|
+
}
|
|
67
|
+
.gcharts-tooltip__content-row-totals-value {
|
|
68
|
+
flex-shrink: 0;
|
|
69
|
+
margin-inline-start: auto;
|
|
70
|
+
}
|
|
71
|
+
.gcharts-tooltip__content-row-label-cell {
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
max-width: 400px;
|
|
74
|
+
padding: 2px 4px;
|
|
50
75
|
white-space: nowrap;
|
|
51
76
|
text-overflow: ellipsis;
|
|
52
77
|
}
|
|
@@ -58,12 +83,13 @@
|
|
|
58
83
|
border-radius: 2px;
|
|
59
84
|
background-color: #dddddd;
|
|
60
85
|
}
|
|
61
|
-
.gcharts-tooltip__content-row-
|
|
62
|
-
|
|
63
|
-
|
|
86
|
+
.gcharts-tooltip__content-row-color-cell {
|
|
87
|
+
width: 16px;
|
|
88
|
+
padding: 2px 4px 2px 14px;
|
|
64
89
|
}
|
|
65
|
-
.gcharts-tooltip__content-row-
|
|
66
|
-
|
|
90
|
+
.gcharts-tooltip__content-row-value-cell {
|
|
91
|
+
padding: 2px 14px 2px 4px;
|
|
92
|
+
text-align: end;
|
|
67
93
|
}
|
|
68
94
|
.gcharts-tooltip__content-row-totals-divider {
|
|
69
95
|
margin-block: 5px 5px;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ChartData } from '../types';
|
|
3
3
|
export * from './Tooltip/ChartTooltipContent';
|
|
4
|
+
export interface ChartReflowOptions {
|
|
5
|
+
immediate?: boolean;
|
|
6
|
+
}
|
|
4
7
|
export interface ChartRef {
|
|
5
|
-
reflow: () => void;
|
|
8
|
+
reflow: (options?: ChartReflowOptions) => void;
|
|
6
9
|
}
|
|
7
10
|
export interface ChartDimentions {
|
|
8
11
|
height: number;
|
|
@@ -30,10 +30,15 @@ export const Chart = React.forwardRef(function Chart(props, forwardedRef) {
|
|
|
30
30
|
return debounced.current;
|
|
31
31
|
}, [handleResize]);
|
|
32
32
|
React.useImperativeHandle(forwardedRef, () => ({
|
|
33
|
-
reflow() {
|
|
34
|
-
|
|
33
|
+
reflow(options) {
|
|
34
|
+
if (options === null || options === void 0 ? void 0 : options.immediate) {
|
|
35
|
+
handleResize();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
debuncedHandleResize();
|
|
39
|
+
}
|
|
35
40
|
},
|
|
36
|
-
}), [debuncedHandleResize]);
|
|
41
|
+
}), [debuncedHandleResize, handleResize]);
|
|
37
42
|
React.useEffect(() => {
|
|
38
43
|
// dimensions initialize
|
|
39
44
|
handleResize();
|
|
@@ -16,43 +16,7 @@ interface UseAxesProps {
|
|
|
16
16
|
}
|
|
17
17
|
export declare function getAxes(props: UseAxesProps): Promise<{
|
|
18
18
|
xAxis: import("./types").PreparedXAxis | null;
|
|
19
|
-
yAxis:
|
|
20
|
-
type: import("../..").ChartAxisType;
|
|
21
|
-
labels: Omit<import("../..").ChartAxisLabels, "style" | "enabled" | "padding" | "autoRotation"> & Required<Pick<import("../..").ChartAxisLabels, "margin" | "enabled" | "html" | "rotation" | "padding">> & {
|
|
22
|
-
style: import("../..").BaseTextStyle;
|
|
23
|
-
rotation: number;
|
|
24
|
-
height: number;
|
|
25
|
-
width: number;
|
|
26
|
-
lineHeight: number;
|
|
27
|
-
maxWidth: number;
|
|
28
|
-
};
|
|
29
|
-
title: {
|
|
30
|
-
height: number;
|
|
31
|
-
width: number;
|
|
32
|
-
text: string;
|
|
33
|
-
margin: number;
|
|
34
|
-
style: import("../..").BaseTextStyle;
|
|
35
|
-
align: import("../..").ChartAxisTitleAlignment;
|
|
36
|
-
maxRowCount: number;
|
|
37
|
-
rotation: number;
|
|
38
|
-
maxWidth: number;
|
|
39
|
-
html: boolean;
|
|
40
|
-
};
|
|
41
|
-
min?: number;
|
|
42
|
-
grid: {
|
|
43
|
-
enabled: boolean;
|
|
44
|
-
};
|
|
45
|
-
maxPadding: number;
|
|
46
|
-
ticks: {
|
|
47
|
-
pixelInterval?: number;
|
|
48
|
-
};
|
|
49
|
-
tickMarks: import("./types").PreparedAxisTickMarks;
|
|
50
|
-
position: "left" | "right" | "top" | "bottom";
|
|
51
|
-
plotIndex: number;
|
|
52
|
-
plotLines: import("./types").PreparedAxisPlotLine[];
|
|
53
|
-
plotBands: import("./types").PreparedAxisPlotBand[];
|
|
54
|
-
crosshair: Required<import("../..").AxisCrosshair>;
|
|
55
|
-
})[];
|
|
19
|
+
yAxis: import("./types").PreparedYAxis[];
|
|
56
20
|
}>;
|
|
57
21
|
export declare function useAxis(props: UseAxesProps): AxesState;
|
|
58
22
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DashStyle } from '../../constants';
|
|
2
|
-
import type { AxisCrosshair, AxisPlotBand, BaseTextStyle, ChartAxis, ChartAxisLabels, ChartAxisRangeSlider, ChartAxisTitleAlignment, ChartAxisType, DeepRequired, MeaningfulAny, PlotLayerPlacement } from '../../types';
|
|
2
|
+
import type { AxisCrosshair, AxisPlotBand, BaseTextStyle, ChartAxis, ChartAxisLabels, ChartAxisRangeSlider, ChartAxisTitleAlignment, ChartAxisTitleRotation, ChartAxisType, DeepRequired, MeaningfulAny, PlotLayerPlacement } from '../../types';
|
|
3
3
|
type PreparedAxisLabels = Omit<ChartAxisLabels, 'enabled' | 'padding' | 'style' | 'autoRotation'> & Required<Pick<ChartAxisLabels, 'enabled' | 'padding' | 'margin' | 'rotation' | 'html'>> & {
|
|
4
4
|
style: BaseTextStyle;
|
|
5
5
|
rotation: number;
|
|
@@ -51,7 +51,7 @@ type PreparedBaseAxis = Omit<ChartAxis, 'type' | 'labels' | 'plotLines' | 'plotB
|
|
|
51
51
|
style: BaseTextStyle;
|
|
52
52
|
align: ChartAxisTitleAlignment;
|
|
53
53
|
maxRowCount: number;
|
|
54
|
-
rotation:
|
|
54
|
+
rotation: ChartAxisTitleRotation;
|
|
55
55
|
maxWidth: number;
|
|
56
56
|
html: boolean;
|
|
57
57
|
};
|
|
@@ -64,7 +64,6 @@ type PreparedBaseAxis = Omit<ChartAxis, 'type' | 'labels' | 'plotLines' | 'plotB
|
|
|
64
64
|
pixelInterval?: number;
|
|
65
65
|
};
|
|
66
66
|
tickMarks: PreparedAxisTickMarks;
|
|
67
|
-
position: 'left' | 'right' | 'top' | 'bottom';
|
|
68
67
|
plotIndex: number;
|
|
69
68
|
plotLines: PreparedAxisPlotLine[];
|
|
70
69
|
plotBands: PreparedAxisPlotBand[];
|
|
@@ -72,8 +71,11 @@ type PreparedBaseAxis = Omit<ChartAxis, 'type' | 'labels' | 'plotLines' | 'plotB
|
|
|
72
71
|
};
|
|
73
72
|
export type PreparedXAxis = PreparedBaseAxis & {
|
|
74
73
|
rangeSlider: PreparedRangeSlider;
|
|
74
|
+
position: 'bottom';
|
|
75
|
+
};
|
|
76
|
+
export type PreparedYAxis = PreparedBaseAxis & {
|
|
77
|
+
position: 'left' | 'right';
|
|
75
78
|
};
|
|
76
|
-
export type PreparedYAxis = PreparedBaseAxis;
|
|
77
79
|
export type PreparedAxis = PreparedXAxis | PreparedYAxis;
|
|
78
80
|
export type AxesState = {
|
|
79
81
|
xAxis: PreparedXAxis | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PreparedAxis, PreparedSeries, PreparedSplit, RangeSliderState, ZoomState } from '../../hooks';
|
|
1
|
+
import type { PreparedAxis, PreparedSeries, PreparedSplit, PreparedYAxis, RangeSliderState, ZoomState } from '../../hooks';
|
|
2
2
|
import type { ChartScale } from './types';
|
|
3
3
|
export { createXScale } from './x-scale';
|
|
4
4
|
export { createYScale } from './y-scale';
|
|
@@ -7,7 +7,7 @@ type Args = {
|
|
|
7
7
|
boundsHeight: number;
|
|
8
8
|
series: PreparedSeries[];
|
|
9
9
|
xAxis: PreparedAxis | null;
|
|
10
|
-
yAxis:
|
|
10
|
+
yAxis: PreparedYAxis[];
|
|
11
11
|
split: PreparedSplit;
|
|
12
12
|
isRangeSlider?: boolean;
|
|
13
13
|
rangeSliderState?: RangeSliderState;
|
|
@@ -162,6 +162,7 @@ export const prepareBarXData = async (args) => {
|
|
|
162
162
|
: yAxisTop + base + negativeStackHeight,
|
|
163
163
|
width: rectWidth,
|
|
164
164
|
height: shapeHeight,
|
|
165
|
+
_height: height,
|
|
165
166
|
opacity: get(yValue.data, 'opacity', null),
|
|
166
167
|
data: yValue.data,
|
|
167
168
|
series: yValue.series,
|
|
@@ -178,9 +179,9 @@ export const prepareBarXData = async (args) => {
|
|
|
178
179
|
}
|
|
179
180
|
if (series.some((s) => s.stacking === 'percent')) {
|
|
180
181
|
let acc = 0;
|
|
181
|
-
const ratio = plotHeight /
|
|
182
|
+
const ratio = plotHeight / positiveStackHeight;
|
|
182
183
|
stackItems.forEach((item) => {
|
|
183
|
-
item.height = item.
|
|
184
|
+
item.height = item._height * ratio;
|
|
184
185
|
item.y = plotHeight - item.height - acc;
|
|
185
186
|
acc += item.height + 1;
|
|
186
187
|
});
|
|
@@ -10,4 +10,9 @@ export type PreparedBarXData = Omit<TooltipDataChunkBarX, 'series'> & {
|
|
|
10
10
|
label?: LabelData;
|
|
11
11
|
htmlElements: HtmlItem[];
|
|
12
12
|
isLastStackItem: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* the utility field for storing the original height (for recalculations, etc.)
|
|
15
|
+
* should not be used for displaying
|
|
16
|
+
*/
|
|
17
|
+
_height: number;
|
|
13
18
|
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { Dispatch } from 'd3';
|
|
2
2
|
import type { AxisPlotBand, AxisPlotLine, PointPosition, TooltipDataChunk } from '../../types';
|
|
3
3
|
import type { PreparedTooltip } from '../types';
|
|
4
|
+
import type { PreparedXAxis, PreparedYAxis } from '../useAxis/types';
|
|
4
5
|
type Args = {
|
|
5
6
|
dispatcher: Dispatch<object>;
|
|
6
7
|
tooltip: PreparedTooltip;
|
|
8
|
+
xAxis?: PreparedXAxis | null;
|
|
9
|
+
yAxis?: PreparedYAxis;
|
|
7
10
|
};
|
|
8
|
-
export declare const useTooltip: ({ dispatcher, tooltip }: Args) => {
|
|
11
|
+
export declare const useTooltip: ({ dispatcher, tooltip, xAxis, yAxis }: Args) => {
|
|
9
12
|
hovered: TooltipDataChunk[] | undefined;
|
|
10
13
|
hoveredPlotLines: AxisPlotLine[] | undefined;
|
|
11
14
|
hoveredPlotBands: AxisPlotBand[] | undefined;
|
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import isEqual from 'lodash/isEqual';
|
|
3
|
-
|
|
3
|
+
import { getSortedHovered } from '../../components/Tooltip/DefaultTooltipContent/utils';
|
|
4
|
+
export const useTooltip = ({ dispatcher, tooltip, xAxis, yAxis }) => {
|
|
4
5
|
const [{ hovered, hoveredPlotLines, hoveredPlotBands, pointerPosition }, setTooltipState] = React.useState({});
|
|
5
6
|
const prevHovered = React.useRef(hovered);
|
|
6
7
|
React.useEffect(() => {
|
|
7
8
|
if (tooltip === null || tooltip === void 0 ? void 0 : tooltip.enabled) {
|
|
8
9
|
dispatcher.on('hover-shape.tooltip', (nextHovered, nextPointerPosition, nextHoveredPlots) => {
|
|
9
10
|
const filteredNextHovered = nextHovered === null || nextHovered === void 0 ? void 0 : nextHovered.filter((item) => 'y' in item.data ? item.data.y !== null : true);
|
|
10
|
-
const
|
|
11
|
+
const sortedHovered = getSortedHovered({
|
|
12
|
+
hovered: filteredNextHovered !== null && filteredNextHovered !== void 0 ? filteredNextHovered : [],
|
|
13
|
+
sorting: tooltip === null || tooltip === void 0 ? void 0 : tooltip.sorting,
|
|
14
|
+
xAxis,
|
|
15
|
+
yAxis,
|
|
16
|
+
});
|
|
17
|
+
const isHoveredChanged = !isEqual(prevHovered.current, sortedHovered);
|
|
11
18
|
const newTooltipState = {
|
|
12
|
-
hovered: isHoveredChanged ?
|
|
19
|
+
hovered: isHoveredChanged ? sortedHovered : prevHovered.current,
|
|
13
20
|
hoveredPlotLines: nextHoveredPlots === null || nextHoveredPlots === void 0 ? void 0 : nextHoveredPlots.lines,
|
|
14
21
|
hoveredPlotBands: nextHoveredPlots === null || nextHoveredPlots === void 0 ? void 0 : nextHoveredPlots.bands,
|
|
15
22
|
pointerPosition: nextPointerPosition,
|
|
16
23
|
};
|
|
17
24
|
if (isHoveredChanged) {
|
|
18
|
-
prevHovered.current =
|
|
25
|
+
prevHovered.current = sortedHovered;
|
|
19
26
|
}
|
|
20
27
|
setTooltipState(newTooltipState);
|
|
21
28
|
});
|
|
@@ -25,7 +32,7 @@ export const useTooltip = ({ dispatcher, tooltip }) => {
|
|
|
25
32
|
dispatcher.on('hover-shape.tooltip', null);
|
|
26
33
|
}
|
|
27
34
|
};
|
|
28
|
-
}, [dispatcher, tooltip]);
|
|
35
|
+
}, [dispatcher, tooltip, xAxis, yAxis]);
|
|
29
36
|
return {
|
|
30
37
|
hovered,
|
|
31
38
|
hoveredPlotLines,
|
|
@@ -6,6 +6,7 @@ import type { BaseTextStyle } from './base';
|
|
|
6
6
|
import type { ChartBrush } from './brush';
|
|
7
7
|
export type ChartAxisType = (typeof AXIS_TYPE)[keyof typeof AXIS_TYPE];
|
|
8
8
|
export type ChartAxisTitleAlignment = 'left' | 'center' | 'right';
|
|
9
|
+
export type ChartAxisTitleRotation = 0 | 90 | -90;
|
|
9
10
|
export interface ChartAxisLabels {
|
|
10
11
|
/** Enable or disable the axis labels. */
|
|
11
12
|
enabled?: boolean;
|
|
@@ -314,7 +315,7 @@ export interface ChartYAxisTitle extends ChartAxisTitle {
|
|
|
314
315
|
*
|
|
315
316
|
* The default values are -90 for the left axis and 90 for the right.
|
|
316
317
|
*/
|
|
317
|
-
rotation?:
|
|
318
|
+
rotation?: ChartAxisTitleRotation;
|
|
318
319
|
/**
|
|
319
320
|
* Interval of the tick marks(absolute or relative to the chart area).
|
|
320
321
|
*
|
|
@@ -113,8 +113,13 @@ export type ChartTooltipRowRendererArgs = {
|
|
|
113
113
|
value: string | number | null | undefined;
|
|
114
114
|
formattedValue?: string;
|
|
115
115
|
hovered?: TooltipDataChunk<unknown>[];
|
|
116
|
+
/**
|
|
117
|
+
* CSS class name pre-built with active/striped modifiers.
|
|
118
|
+
* Apply it to the root `<tr>` element of the returned row: `<tr className={className}>`.
|
|
119
|
+
*/
|
|
116
120
|
className?: string;
|
|
117
121
|
};
|
|
122
|
+
export type ChartTooltipSortComparator<T = MeaningfulAny> = (a: TooltipDataChunk<T>, b: TooltipDataChunk<T>) => number;
|
|
118
123
|
export interface ChartTooltip<T = MeaningfulAny> {
|
|
119
124
|
enabled?: boolean;
|
|
120
125
|
/** Specifies the renderer for the tooltip. If returned null default tooltip renderer will be used. */
|
|
@@ -122,7 +127,26 @@ export interface ChartTooltip<T = MeaningfulAny> {
|
|
|
122
127
|
/**
|
|
123
128
|
* Defines the way a single data/series is displayed (corresponding to a separate selected point/ruler/shape on the chart).
|
|
124
129
|
* It is useful in cases where you need to display additional information, but keep the general format of the tooltip.
|
|
125
|
-
*
|
|
130
|
+
*
|
|
131
|
+
* The returned React element must be a `<tr>` so that it fits into the table layout used by the tooltip.
|
|
132
|
+
* Apply the `className` arg to the root `<tr>` to get the correct active/striped styles.
|
|
133
|
+
*
|
|
134
|
+
* If a string is returned, it will be parsed as HTML and rendered as-is — the string must be a complete
|
|
135
|
+
* `<tr>...</tr>` element.
|
|
136
|
+
* @example React element
|
|
137
|
+
* ```tsx
|
|
138
|
+
* rowRenderer: ({id, name, value, className}) => (
|
|
139
|
+
* <tr key={id} className={className}>
|
|
140
|
+
* <td>{name}</td>
|
|
141
|
+
* <td>{value}</td>
|
|
142
|
+
* </tr>
|
|
143
|
+
* )
|
|
144
|
+
* ```
|
|
145
|
+
* @example Raw HTML string
|
|
146
|
+
* ```ts
|
|
147
|
+
* rowRenderer: ({name, value, className}) =>
|
|
148
|
+
* `<tr class="${className}"><td>${name}</td><td>${value}</td></tr>`
|
|
149
|
+
* ```
|
|
126
150
|
*/
|
|
127
151
|
rowRenderer?: ((args: ChartTooltipRowRendererArgs) => React.ReactElement | string) | null;
|
|
128
152
|
pin?: {
|
|
@@ -158,4 +182,23 @@ export interface ChartTooltip<T = MeaningfulAny> {
|
|
|
158
182
|
* It is assigned as a data-qa attribute to an element.
|
|
159
183
|
*/
|
|
160
184
|
qa?: string;
|
|
185
|
+
/**
|
|
186
|
+
* Controls the order of tooltip rows. Applied to `hovered` before rendering.
|
|
187
|
+
* Use a custom comparator `(a, b) => number` for arbitrary ordering.
|
|
188
|
+
*/
|
|
189
|
+
sorting?: {
|
|
190
|
+
/**
|
|
191
|
+
* Determines what data should be used to sort by.
|
|
192
|
+
* `'value'` uses the numeric value of each series point: `y` for most series
|
|
193
|
+
* (line, area, bar-x, scatter, waterfall), `x` for bar-y, and `value` for
|
|
194
|
+
* pie, radar, heatmap, treemap, funnel. `null` values are sorted as lowest.
|
|
195
|
+
* @default undefined (sorting disabled)
|
|
196
|
+
*/
|
|
197
|
+
key?: 'value' | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Sorting direction.
|
|
200
|
+
* @default 'asc'
|
|
201
|
+
*/
|
|
202
|
+
direction?: 'asc' | 'desc';
|
|
203
|
+
} | ChartTooltipSortComparator<T>;
|
|
161
204
|
}
|
|
@@ -50,9 +50,9 @@ export function getZoomedSeriesData(args) {
|
|
|
50
50
|
}
|
|
51
51
|
const zoomedSeriesData = [];
|
|
52
52
|
const zoomedShapesSeriesData = [];
|
|
53
|
-
let prevPointInRange = false;
|
|
54
|
-
let currentPointInRange = false;
|
|
55
53
|
seriesData.forEach((seriesItem) => {
|
|
54
|
+
let prevPointInRange = false;
|
|
55
|
+
let currentPointInRange = false;
|
|
56
56
|
const filteredData = [];
|
|
57
57
|
const filteredShapesData = SERIES_TYPE_WITH_HIDDEN_POINTS.includes(seriesItem.type) && (xAxis === null || xAxis === void 0 ? void 0 : xAxis.type) !== 'category'
|
|
58
58
|
? []
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/charts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.0",
|
|
4
4
|
"description": "A flexible JavaScript library for data visualization and chart rendering using React",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"d3": "^7.9.0",
|
|
74
74
|
"d3-sankey": "^0.12.3",
|
|
75
75
|
"d3-selection": "^3.0.0",
|
|
76
|
+
"html-react-parser": "^5.2.17",
|
|
76
77
|
"lodash": "^4.17.21",
|
|
77
78
|
"tslib": "^2.6.2"
|
|
78
79
|
},
|