@gravity-ui/charts 1.22.0 → 1.23.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/ChartInner/useChartInnerProps.d.ts +1 -1
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.d.ts +2 -2
- package/dist/cjs/constants/index.d.ts +1 -0
- package/dist/cjs/constants/index.js +1 -0
- package/dist/cjs/constants/zoom.d.ts +6 -0
- package/dist/cjs/constants/zoom.js +5 -0
- package/dist/cjs/hooks/useBrush/index.js +7 -6
- package/dist/cjs/hooks/useBrush/types.d.ts +3 -2
- package/dist/cjs/hooks/useChartOptions/chart.js +1 -82
- package/dist/cjs/hooks/useChartOptions/zoom.d.ts +11 -0
- package/dist/cjs/hooks/useChartOptions/zoom.js +88 -0
- package/dist/cjs/hooks/useSeries/prepare-area.js +15 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-x.js +13 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +2 -2
- package/dist/cjs/hooks/useSeries/prepare-bar-y.js +13 -1
- package/dist/cjs/hooks/useSeries/prepare-heatmap.js +13 -1
- package/dist/cjs/hooks/useSeries/prepare-legend.js +1 -1
- package/dist/cjs/hooks/useSeries/prepare-line.js +15 -1
- package/dist/cjs/hooks/useSeries/prepare-pie.js +15 -2
- package/dist/cjs/hooks/useSeries/prepare-scatter.js +16 -1
- package/dist/cjs/hooks/useSeries/prepare-waterfall.js +18 -2
- package/dist/cjs/hooks/useShapes/area/index.js +2 -0
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +37 -22
- package/dist/cjs/hooks/useShapes/area/types.d.ts +5 -2
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +8 -2
- package/dist/cjs/hooks/useShapes/bar-y/index.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/bar-y/index.js +19 -22
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +24 -5
- package/dist/cjs/hooks/useShapes/bar-y/types.d.ts +2 -2
- package/dist/cjs/hooks/useShapes/bar-y/utils.d.ts +3 -0
- package/dist/cjs/hooks/useShapes/bar-y/utils.js +44 -0
- package/dist/cjs/hooks/useShapes/heatmap/prepare-data.js +7 -3
- package/dist/cjs/hooks/useShapes/line/index.js +1 -0
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +41 -16
- package/dist/cjs/hooks/useShapes/line/types.d.ts +7 -3
- package/dist/cjs/hooks/useShapes/pie/prepare-data.js +8 -4
- package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +1 -1
- package/dist/cjs/hooks/useShapes/utils.d.ts +14 -6
- package/dist/cjs/hooks/useShapes/utils.js +66 -18
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +18 -8
- package/dist/cjs/hooks/useTooltip/index.js +8 -4
- package/dist/cjs/hooks/useZoom/index.js +2 -0
- package/dist/cjs/hooks/useZoom/utils.d.ts +3 -2
- package/dist/cjs/hooks/useZoom/utils.js +4 -3
- package/dist/cjs/hooks/utils/bar-y.d.ts +8 -1
- package/dist/cjs/hooks/utils/bar-y.js +4 -0
- package/dist/cjs/i18n/keysets/en.json +2 -2
- package/dist/cjs/i18n/keysets/ru.json +2 -2
- package/dist/cjs/types/chart/area.d.ts +11 -1
- package/dist/cjs/types/chart/bar-x.d.ts +10 -1
- package/dist/cjs/types/chart/bar-y.d.ts +10 -1
- package/dist/cjs/types/chart/heatmap.d.ts +10 -1
- package/dist/cjs/types/chart/line.d.ts +11 -1
- package/dist/cjs/types/chart/pie.d.ts +10 -1
- package/dist/cjs/types/chart/scatter.d.ts +11 -2
- package/dist/cjs/types/chart/waterfall.d.ts +10 -1
- package/dist/cjs/types/chart/zoom.d.ts +2 -1
- package/dist/cjs/utils/chart/get-closest-data.js +12 -7
- package/dist/cjs/utils/chart/series/sorting.js +17 -4
- package/dist/cjs/utils/chart/zoom.js +4 -2
- package/dist/cjs/validation/index.js +3 -3
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +1 -1
- package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.d.ts +2 -2
- package/dist/esm/constants/index.d.ts +1 -0
- package/dist/esm/constants/index.js +1 -0
- package/dist/esm/constants/zoom.d.ts +6 -0
- package/dist/esm/constants/zoom.js +5 -0
- package/dist/esm/hooks/useBrush/index.js +7 -6
- package/dist/esm/hooks/useBrush/types.d.ts +3 -2
- package/dist/esm/hooks/useChartOptions/chart.js +1 -82
- package/dist/esm/hooks/useChartOptions/zoom.d.ts +11 -0
- package/dist/esm/hooks/useChartOptions/zoom.js +88 -0
- package/dist/esm/hooks/useSeries/prepare-area.js +15 -1
- package/dist/esm/hooks/useSeries/prepare-bar-x.js +13 -1
- package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +2 -2
- package/dist/esm/hooks/useSeries/prepare-bar-y.js +13 -1
- package/dist/esm/hooks/useSeries/prepare-heatmap.js +13 -1
- package/dist/esm/hooks/useSeries/prepare-legend.js +1 -1
- package/dist/esm/hooks/useSeries/prepare-line.js +15 -1
- package/dist/esm/hooks/useSeries/prepare-pie.js +15 -2
- package/dist/esm/hooks/useSeries/prepare-scatter.js +16 -1
- package/dist/esm/hooks/useSeries/prepare-waterfall.js +18 -2
- package/dist/esm/hooks/useShapes/area/index.js +2 -0
- package/dist/esm/hooks/useShapes/area/prepare-data.js +37 -22
- package/dist/esm/hooks/useShapes/area/types.d.ts +5 -2
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +8 -2
- package/dist/esm/hooks/useShapes/bar-y/index.d.ts +1 -1
- package/dist/esm/hooks/useShapes/bar-y/index.js +19 -22
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +24 -5
- package/dist/esm/hooks/useShapes/bar-y/types.d.ts +2 -2
- package/dist/esm/hooks/useShapes/bar-y/utils.d.ts +3 -0
- package/dist/esm/hooks/useShapes/bar-y/utils.js +44 -0
- package/dist/esm/hooks/useShapes/heatmap/prepare-data.js +7 -3
- package/dist/esm/hooks/useShapes/line/index.js +1 -0
- package/dist/esm/hooks/useShapes/line/prepare-data.js +41 -16
- package/dist/esm/hooks/useShapes/line/types.d.ts +7 -3
- package/dist/esm/hooks/useShapes/pie/prepare-data.js +8 -4
- package/dist/esm/hooks/useShapes/scatter/prepare-data.js +1 -1
- package/dist/esm/hooks/useShapes/utils.d.ts +14 -6
- package/dist/esm/hooks/useShapes/utils.js +66 -18
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +18 -8
- package/dist/esm/hooks/useTooltip/index.js +8 -4
- package/dist/esm/hooks/useZoom/index.js +2 -0
- package/dist/esm/hooks/useZoom/utils.d.ts +3 -2
- package/dist/esm/hooks/useZoom/utils.js +4 -3
- package/dist/esm/hooks/utils/bar-y.d.ts +8 -1
- package/dist/esm/hooks/utils/bar-y.js +4 -0
- package/dist/esm/i18n/keysets/en.json +2 -2
- package/dist/esm/i18n/keysets/ru.json +2 -2
- package/dist/esm/types/chart/area.d.ts +11 -1
- package/dist/esm/types/chart/bar-x.d.ts +10 -1
- package/dist/esm/types/chart/bar-y.d.ts +10 -1
- package/dist/esm/types/chart/heatmap.d.ts +10 -1
- package/dist/esm/types/chart/line.d.ts +11 -1
- package/dist/esm/types/chart/pie.d.ts +10 -1
- package/dist/esm/types/chart/scatter.d.ts +11 -2
- package/dist/esm/types/chart/waterfall.d.ts +10 -1
- package/dist/esm/types/chart/zoom.d.ts +2 -1
- package/dist/esm/utils/chart/get-closest-data.js +12 -7
- package/dist/esm/utils/chart/series/sorting.js +17 -4
- package/dist/esm/utils/chart/zoom.js +4 -2
- package/dist/esm/validation/index.js +3 -3
- package/package.json +1 -1
|
@@ -37,7 +37,7 @@ export declare function useChartInnerProps(props: Props): {
|
|
|
37
37
|
preparedSeries: import("../../hooks").PreparedSeries[];
|
|
38
38
|
preparedSplit: import("../../hooks").PreparedSplit;
|
|
39
39
|
preparedZoom: Required<{
|
|
40
|
-
type?: ("
|
|
40
|
+
type?: import("../../constants").ZoomType | undefined;
|
|
41
41
|
brush?: Required<{
|
|
42
42
|
style?: Required<{
|
|
43
43
|
fillOpacity?: number | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ChartSeriesData, ChartTooltip, ChartTooltipTotalsAggregationValue, ChartTooltipTotalsBuiltInAggregation, ChartXAxis, ChartYAxis, TooltipDataChunk, ValueFormat } from '../../../types';
|
|
2
2
|
export type HoveredValue = string | number | null | undefined;
|
|
3
|
-
export declare function getXRowData(data: ChartSeriesData, xAxis?: ChartXAxis | null): string | number | undefined;
|
|
3
|
+
export declare function getXRowData(data: ChartSeriesData, xAxis?: ChartXAxis | null): string | number | null | undefined;
|
|
4
4
|
export declare function getDefaultValueFormat({ axis, closestPointsRange, }: {
|
|
5
5
|
axis?: ChartXAxis | ChartYAxis | null;
|
|
6
6
|
closestPointsRange?: number;
|
|
@@ -14,7 +14,7 @@ export declare const getMeasureValue: ({ data, xAxis, yAxis, headerFormat, }: {
|
|
|
14
14
|
value: string | null;
|
|
15
15
|
formattedValue?: undefined;
|
|
16
16
|
} | {
|
|
17
|
-
value: string | number | undefined;
|
|
17
|
+
value: string | number | null | undefined;
|
|
18
18
|
formattedValue: string;
|
|
19
19
|
} | null;
|
|
20
20
|
export declare function getHoveredValues(args: {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { brush, brushX, brushY, select } from 'd3';
|
|
3
|
+
import { ZOOM_TYPE } from '../../constants';
|
|
3
4
|
import { block } from '../../utils';
|
|
4
5
|
import './styles.css';
|
|
5
6
|
const b = block('brush');
|
|
6
7
|
export function useBrush(props) {
|
|
7
|
-
const { areas, brushOptions, node, type, onBrushStart, onBrush, onBrushEnd } = props;
|
|
8
|
+
const { areas, brushOptions, disabled, node, type, onBrushStart, onBrush, onBrushEnd } = props;
|
|
8
9
|
React.useEffect(() => {
|
|
9
|
-
if (!node || !areas.length) {
|
|
10
|
+
if (!node || !areas.length || disabled) {
|
|
10
11
|
return () => { };
|
|
11
12
|
}
|
|
12
13
|
const brushes = [];
|
|
@@ -15,15 +16,15 @@ export function useBrush(props) {
|
|
|
15
16
|
areas.forEach((area) => {
|
|
16
17
|
let brushFn;
|
|
17
18
|
switch (type) {
|
|
18
|
-
case
|
|
19
|
+
case ZOOM_TYPE.X: {
|
|
19
20
|
brushFn = brushX;
|
|
20
21
|
break;
|
|
21
22
|
}
|
|
22
|
-
case
|
|
23
|
+
case ZOOM_TYPE.Y: {
|
|
23
24
|
brushFn = brushY;
|
|
24
25
|
break;
|
|
25
26
|
}
|
|
26
|
-
case
|
|
27
|
+
case ZOOM_TYPE.XY:
|
|
27
28
|
default: {
|
|
28
29
|
brushFn = brush;
|
|
29
30
|
break;
|
|
@@ -66,5 +67,5 @@ export function useBrush(props) {
|
|
|
66
67
|
selection === null || selection === void 0 ? void 0 : selection.remove();
|
|
67
68
|
});
|
|
68
69
|
};
|
|
69
|
-
}, [areas, brushOptions, node, type, onBrushStart, onBrush, onBrushEnd]);
|
|
70
|
+
}, [areas, brushOptions, disabled, node, type, onBrushStart, onBrush, onBrushEnd]);
|
|
70
71
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BrushBehavior } from 'd3';
|
|
2
|
+
import type { ZoomType } from '../../constants';
|
|
2
3
|
import type { PreparedZoom } from '../useChartOptions/types';
|
|
3
|
-
type BrushType = PreparedZoom['type'];
|
|
4
4
|
type BrushSelection = [number, number] | [[number, number], [number, number]];
|
|
5
5
|
export interface BrushArea {
|
|
6
6
|
/**
|
|
@@ -15,8 +15,9 @@ export interface BrushArea {
|
|
|
15
15
|
export interface UseBrushProps {
|
|
16
16
|
areas: BrushArea[];
|
|
17
17
|
node: SVGGElement | null;
|
|
18
|
-
type?:
|
|
18
|
+
type?: ZoomType;
|
|
19
19
|
brushOptions?: PreparedZoom['brush'];
|
|
20
|
+
disabled?: boolean;
|
|
20
21
|
onBrushStart?: (this: SVGGElement, brushInstance: BrushBehavior<unknown>) => void;
|
|
21
22
|
onBrush?: (this: SVGGElement, brushInstance: BrushBehavior<unknown>, selection: BrushSelection) => void;
|
|
22
23
|
onBrushEnd?: (this: SVGGElement, brushInstance: BrushBehavior<unknown>, selection: BrushSelection | null) => void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
-
import
|
|
3
|
-
import { SeriesType } from '../../constants';
|
|
2
|
+
import { getPreparedZoom } from './zoom';
|
|
4
3
|
const getMarginTop = (args) => {
|
|
5
4
|
const { chart, preparedTitle } = args;
|
|
6
5
|
let marginTop = get(chart, 'margin.top', 0);
|
|
@@ -13,86 +12,6 @@ const getMarginRight = (args) => {
|
|
|
13
12
|
const { chart } = args;
|
|
14
13
|
return get(chart, 'margin.right', 0);
|
|
15
14
|
};
|
|
16
|
-
function mapSeriesTypeToZoomType(seriesType) {
|
|
17
|
-
switch (seriesType) {
|
|
18
|
-
case SeriesType.Area: {
|
|
19
|
-
return ['x', 'y', 'xy'];
|
|
20
|
-
}
|
|
21
|
-
case SeriesType.BarX: {
|
|
22
|
-
return ['x'];
|
|
23
|
-
}
|
|
24
|
-
case SeriesType.BarY: {
|
|
25
|
-
return ['y'];
|
|
26
|
-
}
|
|
27
|
-
case SeriesType.Line: {
|
|
28
|
-
return ['x', 'y', 'xy'];
|
|
29
|
-
}
|
|
30
|
-
case SeriesType.Scatter: {
|
|
31
|
-
return ['x', 'y', 'xy'];
|
|
32
|
-
}
|
|
33
|
-
case SeriesType.Waterfall: {
|
|
34
|
-
return ['x', 'y', 'xy'];
|
|
35
|
-
}
|
|
36
|
-
default: {
|
|
37
|
-
return [];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function getDefaultZoomType(seriesType) {
|
|
42
|
-
switch (seriesType) {
|
|
43
|
-
case SeriesType.BarY: {
|
|
44
|
-
return 'y';
|
|
45
|
-
}
|
|
46
|
-
case SeriesType.Scatter: {
|
|
47
|
-
return 'xy';
|
|
48
|
-
}
|
|
49
|
-
default: {
|
|
50
|
-
return 'x';
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function getZoomType(args) {
|
|
55
|
-
const { seriesData, zoomType } = args;
|
|
56
|
-
const possibleDefaultZoomTypes = seriesData.map((s) => {
|
|
57
|
-
return getDefaultZoomType(s.type);
|
|
58
|
-
});
|
|
59
|
-
const availableDefaultZoomTypes = intersection(possibleDefaultZoomTypes);
|
|
60
|
-
if (zoomType) {
|
|
61
|
-
const possibleZoomTypes = seriesData.map((s) => {
|
|
62
|
-
return mapSeriesTypeToZoomType(s.type);
|
|
63
|
-
});
|
|
64
|
-
const availableZoomTypes = intersection(...possibleZoomTypes);
|
|
65
|
-
if (availableZoomTypes.includes(zoomType)) {
|
|
66
|
-
return zoomType;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (availableDefaultZoomTypes.length) {
|
|
70
|
-
return availableDefaultZoomTypes[0];
|
|
71
|
-
}
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
function getPreparedZoom(args) {
|
|
75
|
-
var _a, _b, _c, _d;
|
|
76
|
-
const { zoom, seriesData } = args;
|
|
77
|
-
if (!(zoom === null || zoom === void 0 ? void 0 : zoom.enabled)) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
const type = getZoomType({ seriesData, zoomType: zoom.type });
|
|
81
|
-
if (!type) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
type,
|
|
86
|
-
brush: {
|
|
87
|
-
style: Object.assign({ fillOpacity: 1 }, (_a = zoom === null || zoom === void 0 ? void 0 : zoom.brush) === null || _a === void 0 ? void 0 : _a.style),
|
|
88
|
-
},
|
|
89
|
-
resetButton: {
|
|
90
|
-
align: ((_b = zoom === null || zoom === void 0 ? void 0 : zoom.resetButton) === null || _b === void 0 ? void 0 : _b.align) || 'top-right',
|
|
91
|
-
offset: Object.assign({ x: 0, y: 0 }, (_c = zoom === null || zoom === void 0 ? void 0 : zoom.resetButton) === null || _c === void 0 ? void 0 : _c.offset),
|
|
92
|
-
relativeTo: ((_d = zoom === null || zoom === void 0 ? void 0 : zoom.resetButton) === null || _d === void 0 ? void 0 : _d.relativeTo) || 'chart-box',
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
15
|
export const getPreparedChart = (args) => {
|
|
97
16
|
const { chart, preparedTitle, seriesData } = args;
|
|
98
17
|
const marginTop = getMarginTop({ chart, preparedTitle });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ZoomType } from '../../constants';
|
|
2
|
+
import type { ChartSeries, ChartZoom } from '../../types';
|
|
3
|
+
import type { PreparedZoom } from './types';
|
|
4
|
+
export declare function getZoomType(args: {
|
|
5
|
+
seriesData: ChartSeries[];
|
|
6
|
+
zoomType?: ZoomType;
|
|
7
|
+
}): ZoomType | undefined;
|
|
8
|
+
export declare function getPreparedZoom(args: {
|
|
9
|
+
zoom?: ChartZoom;
|
|
10
|
+
seriesData: ChartSeries[];
|
|
11
|
+
}): PreparedZoom | null;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import intersection from 'lodash/intersection';
|
|
2
|
+
import { SeriesType, ZOOM_TYPE } from '../../constants';
|
|
3
|
+
function mapSeriesTypeToZoomType(seriesType) {
|
|
4
|
+
switch (seriesType) {
|
|
5
|
+
case SeriesType.Area: {
|
|
6
|
+
return [ZOOM_TYPE.X, ZOOM_TYPE.XY, ZOOM_TYPE.Y];
|
|
7
|
+
}
|
|
8
|
+
case SeriesType.BarX: {
|
|
9
|
+
return [ZOOM_TYPE.X];
|
|
10
|
+
}
|
|
11
|
+
case SeriesType.BarY: {
|
|
12
|
+
return [ZOOM_TYPE.Y];
|
|
13
|
+
}
|
|
14
|
+
case SeriesType.Line: {
|
|
15
|
+
return [ZOOM_TYPE.X, ZOOM_TYPE.XY, ZOOM_TYPE.Y];
|
|
16
|
+
}
|
|
17
|
+
case SeriesType.Scatter: {
|
|
18
|
+
return [ZOOM_TYPE.X, ZOOM_TYPE.XY, ZOOM_TYPE.Y];
|
|
19
|
+
}
|
|
20
|
+
case SeriesType.Waterfall: {
|
|
21
|
+
return [ZOOM_TYPE.X, ZOOM_TYPE.XY, ZOOM_TYPE.Y];
|
|
22
|
+
}
|
|
23
|
+
default: {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function getDefaultZoomType(seriesType) {
|
|
29
|
+
switch (seriesType) {
|
|
30
|
+
case SeriesType.BarY: {
|
|
31
|
+
return ZOOM_TYPE.Y;
|
|
32
|
+
}
|
|
33
|
+
case SeriesType.Scatter: {
|
|
34
|
+
return ZOOM_TYPE.XY;
|
|
35
|
+
}
|
|
36
|
+
case SeriesType.Area:
|
|
37
|
+
case SeriesType.BarX:
|
|
38
|
+
case SeriesType.Line:
|
|
39
|
+
case SeriesType.Waterfall: {
|
|
40
|
+
return ZOOM_TYPE.X;
|
|
41
|
+
}
|
|
42
|
+
default: {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function getZoomType(args) {
|
|
48
|
+
const { seriesData, zoomType } = args;
|
|
49
|
+
const possibleZoomTypes = seriesData.map((s) => {
|
|
50
|
+
return mapSeriesTypeToZoomType(s.type);
|
|
51
|
+
});
|
|
52
|
+
const availableZoomTypes = intersection(...possibleZoomTypes);
|
|
53
|
+
if (zoomType && availableZoomTypes.includes(zoomType)) {
|
|
54
|
+
return zoomType;
|
|
55
|
+
}
|
|
56
|
+
const possibleDefaultZoomTypes = seriesData
|
|
57
|
+
.map((s) => {
|
|
58
|
+
return getDefaultZoomType(s.type);
|
|
59
|
+
})
|
|
60
|
+
.filter(Boolean);
|
|
61
|
+
const availableDefaultZoomTypes = intersection(possibleDefaultZoomTypes, ...possibleZoomTypes);
|
|
62
|
+
if (availableDefaultZoomTypes.length) {
|
|
63
|
+
return availableDefaultZoomTypes[0];
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
export function getPreparedZoom(args) {
|
|
68
|
+
var _a, _b, _c, _d;
|
|
69
|
+
const { zoom, seriesData } = args;
|
|
70
|
+
if (!(zoom === null || zoom === void 0 ? void 0 : zoom.enabled)) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const type = getZoomType({ seriesData, zoomType: zoom.type });
|
|
74
|
+
if (!type) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
type,
|
|
79
|
+
brush: {
|
|
80
|
+
style: Object.assign({ fillOpacity: 1 }, (_a = zoom === null || zoom === void 0 ? void 0 : zoom.brush) === null || _a === void 0 ? void 0 : _a.style),
|
|
81
|
+
},
|
|
82
|
+
resetButton: {
|
|
83
|
+
align: ((_b = zoom === null || zoom === void 0 ? void 0 : zoom.resetButton) === null || _b === void 0 ? void 0 : _b.align) || 'top-right',
|
|
84
|
+
offset: Object.assign({ x: 0, y: 0 }, (_c = zoom === null || zoom === void 0 ? void 0 : zoom.resetButton) === null || _c === void 0 ? void 0 : _c.offset),
|
|
85
|
+
relativeTo: ((_d = zoom === null || zoom === void 0 ? void 0 : zoom.resetButton) === null || _d === void 0 ? void 0 : _d.relativeTo) || 'chart-box',
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -24,6 +24,20 @@ function prepareMarker(series, seriesOptions) {
|
|
|
24
24
|
},
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
+
function prepareSeriesData(series) {
|
|
28
|
+
var _a;
|
|
29
|
+
const nullMode = (_a = series.nullMode) !== null && _a !== void 0 ? _a : 'skip';
|
|
30
|
+
const data = series.data;
|
|
31
|
+
switch (nullMode) {
|
|
32
|
+
case 'zero':
|
|
33
|
+
return data.map((p) => { var _a; return (Object.assign(Object.assign({}, p), { y: (_a = p.y) !== null && _a !== void 0 ? _a : 0 })); });
|
|
34
|
+
case 'connect':
|
|
35
|
+
return data.filter((p) => p.y !== null);
|
|
36
|
+
case 'skip':
|
|
37
|
+
default:
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
27
41
|
export function prepareArea(args) {
|
|
28
42
|
const { colorScale, series: seriesList, seriesOptions, legend } = args;
|
|
29
43
|
const defaultAreaWidth = get(seriesOptions, 'area.lineWidth', DEFAULT_LINE_WIDTH);
|
|
@@ -45,7 +59,7 @@ export function prepareArea(args) {
|
|
|
45
59
|
enabled: get(series, 'legend.enabled', legend.enabled),
|
|
46
60
|
symbol: prepareLegendSymbol(series),
|
|
47
61
|
},
|
|
48
|
-
data: series
|
|
62
|
+
data: prepareSeriesData(series),
|
|
49
63
|
stacking: series.stacking,
|
|
50
64
|
stackId: getSeriesStackId(series),
|
|
51
65
|
dataLabels: {
|
|
@@ -3,6 +3,18 @@ import { DEFAULT_DATALABELS_STYLE } from '../../constants';
|
|
|
3
3
|
import { getUniqId } from '../../utils';
|
|
4
4
|
import { DEFAULT_DATALABELS_PADDING } from './constants';
|
|
5
5
|
import { getSeriesStackId, prepareLegendSymbol } from './utils';
|
|
6
|
+
function prepareSeriesData(series) {
|
|
7
|
+
var _a;
|
|
8
|
+
const nullMode = (_a = series.nullMode) !== null && _a !== void 0 ? _a : 'skip';
|
|
9
|
+
const data = series.data;
|
|
10
|
+
switch (nullMode) {
|
|
11
|
+
case 'zero':
|
|
12
|
+
return data.map((p) => { var _a; return (Object.assign(Object.assign({}, p), { y: (_a = p.y) !== null && _a !== void 0 ? _a : 0 })); });
|
|
13
|
+
case 'skip':
|
|
14
|
+
default:
|
|
15
|
+
return data.filter((p) => p.y !== null);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
6
18
|
export function prepareBarXSeries(args) {
|
|
7
19
|
const { colorScale, series: seriesList, seriesOptions, legend } = args;
|
|
8
20
|
return seriesList.map((series) => {
|
|
@@ -19,7 +31,7 @@ export function prepareBarXSeries(args) {
|
|
|
19
31
|
enabled: get(series, 'legend.enabled', legend.enabled),
|
|
20
32
|
symbol: prepareLegendSymbol(series),
|
|
21
33
|
},
|
|
22
|
-
data: series
|
|
34
|
+
data: prepareSeriesData(series),
|
|
23
35
|
stacking: series.stacking,
|
|
24
36
|
stackId: getSeriesStackId(series),
|
|
25
37
|
dataLabels: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ScaleOrdinal } from 'd3';
|
|
2
|
-
import type { BarYSeries, ChartSeriesOptions } from '../../types';
|
|
2
|
+
import type { BarYSeries, BarYSeriesData, ChartSeriesOptions } from '../../types';
|
|
3
3
|
import type { PreparedLegend } from './types';
|
|
4
4
|
type PrepareBarYSeriesArgs = {
|
|
5
5
|
colorScale: ScaleOrdinal<string, string>;
|
|
@@ -9,7 +9,7 @@ type PrepareBarYSeriesArgs = {
|
|
|
9
9
|
};
|
|
10
10
|
export declare function prepareBarYSeries(args: PrepareBarYSeriesArgs): Promise<({
|
|
11
11
|
type: BarYSeries["type"];
|
|
12
|
-
data:
|
|
12
|
+
data: BarYSeriesData[];
|
|
13
13
|
stackId: string;
|
|
14
14
|
stacking: BarYSeries["stacking"];
|
|
15
15
|
dataLabels: {
|
|
@@ -3,6 +3,18 @@ import { DEFAULT_DATALABELS_STYLE } from '../../constants';
|
|
|
3
3
|
import { getLabelsSize, getUniqId } from '../../utils';
|
|
4
4
|
import { getFormattedValue } from '../../utils/chart/format';
|
|
5
5
|
import { getSeriesStackId, prepareLegendSymbol } from './utils';
|
|
6
|
+
function prepareSeriesData(series) {
|
|
7
|
+
var _a;
|
|
8
|
+
const nullMode = (_a = series.nullMode) !== null && _a !== void 0 ? _a : 'skip';
|
|
9
|
+
const data = series.data;
|
|
10
|
+
switch (nullMode) {
|
|
11
|
+
case 'zero':
|
|
12
|
+
return data.map((p) => { var _a; return (Object.assign(Object.assign({}, p), { x: (_a = p.x) !== null && _a !== void 0 ? _a : 0 })); });
|
|
13
|
+
case 'skip':
|
|
14
|
+
default:
|
|
15
|
+
return data.filter((p) => p.x !== null);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
6
18
|
async function prepareDataLabels(series) {
|
|
7
19
|
var _a, _b, _c, _d;
|
|
8
20
|
const enabled = get(series, 'dataLabels.enabled', false);
|
|
@@ -46,7 +58,7 @@ export function prepareBarYSeries(args) {
|
|
|
46
58
|
enabled: get(series, 'legend.enabled', legend.enabled),
|
|
47
59
|
symbol: prepareLegendSymbol(series),
|
|
48
60
|
},
|
|
49
|
-
data: series
|
|
61
|
+
data: prepareSeriesData(series),
|
|
50
62
|
stacking: series.stacking,
|
|
51
63
|
stackId: getSeriesStackId(series),
|
|
52
64
|
dataLabels: await prepareDataLabels(series),
|
|
@@ -3,6 +3,18 @@ import { DEFAULT_DATALABELS_STYLE } from '../../constants';
|
|
|
3
3
|
import { getUniqId } from '../../utils';
|
|
4
4
|
import { DEFAULT_DATALABELS_PADDING } from './constants';
|
|
5
5
|
import { prepareLegendSymbol } from './utils';
|
|
6
|
+
function prepareSeriesData(series) {
|
|
7
|
+
var _a;
|
|
8
|
+
const nullMode = (_a = series.nullMode) !== null && _a !== void 0 ? _a : 'skip';
|
|
9
|
+
const data = series.data;
|
|
10
|
+
switch (nullMode) {
|
|
11
|
+
case 'zero':
|
|
12
|
+
return data.map((p) => { var _a; return (Object.assign(Object.assign({}, p), { value: (_a = p.value) !== null && _a !== void 0 ? _a : 0 })); });
|
|
13
|
+
case 'skip':
|
|
14
|
+
default:
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
6
18
|
export function prepareHeatmapSeries(args) {
|
|
7
19
|
const { colorScale, series: seriesList, seriesOptions, legend } = args;
|
|
8
20
|
return seriesList.map((series) => {
|
|
@@ -19,7 +31,7 @@ export function prepareHeatmapSeries(args) {
|
|
|
19
31
|
enabled: get(series, 'legend.enabled', legend.enabled),
|
|
20
32
|
symbol: prepareLegendSymbol(series),
|
|
21
33
|
},
|
|
22
|
-
data: series
|
|
34
|
+
data: prepareSeriesData(series),
|
|
23
35
|
dataLabels: {
|
|
24
36
|
enabled: ((_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.enabled) || false,
|
|
25
37
|
style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.style),
|
|
@@ -150,7 +150,7 @@ function getPagination(args) {
|
|
|
150
150
|
if (!pages[currentPageIndex]) {
|
|
151
151
|
pages[currentPageIndex] = { start: i, end: i };
|
|
152
152
|
}
|
|
153
|
-
const legendLineHeight = Math.max(...item.map((
|
|
153
|
+
const legendLineHeight = Math.max(...item.map(({ height }) => height));
|
|
154
154
|
currentHeight += legendLineHeight;
|
|
155
155
|
if (currentHeight > maxLegendHeight - paginatorHeight) {
|
|
156
156
|
pages[currentPageIndex].end = i;
|
|
@@ -41,6 +41,20 @@ function prepareMarker(series, seriesOptions) {
|
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
+
function prepareSeriesData(series) {
|
|
45
|
+
var _a;
|
|
46
|
+
const nullMode = (_a = series.nullMode) !== null && _a !== void 0 ? _a : 'skip';
|
|
47
|
+
const data = series.data;
|
|
48
|
+
switch (nullMode) {
|
|
49
|
+
case 'zero':
|
|
50
|
+
return data.map((p) => { var _a; return (Object.assign(Object.assign({}, p), { y: (_a = p.y) !== null && _a !== void 0 ? _a : 0 })); });
|
|
51
|
+
case 'connect':
|
|
52
|
+
return data.filter((p) => p.y !== null);
|
|
53
|
+
case 'skip':
|
|
54
|
+
default:
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
44
58
|
export function prepareLineSeries(args) {
|
|
45
59
|
const { colorScale, series: seriesList, seriesOptions, legend } = args;
|
|
46
60
|
const defaultLineWidth = get(seriesOptions, 'line.lineWidth', DEFAULT_LINE_WIDTH);
|
|
@@ -62,7 +76,7 @@ export function prepareLineSeries(args) {
|
|
|
62
76
|
enabled: get(series, 'legend.enabled', legend.enabled),
|
|
63
77
|
symbol: prepareLineLegendSymbol(series, seriesOptions),
|
|
64
78
|
},
|
|
65
|
-
data: series
|
|
79
|
+
data: prepareSeriesData(series),
|
|
66
80
|
dataLabels: {
|
|
67
81
|
enabled: ((_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.enabled) || false,
|
|
68
82
|
style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.style),
|
|
@@ -4,13 +4,26 @@ import { DEFAULT_DATALABELS_STYLE } from '../../constants';
|
|
|
4
4
|
import { getUniqId } from '../../utils';
|
|
5
5
|
import { DEFAULT_DATALABELS_PADDING } from './constants';
|
|
6
6
|
import { prepareLegendSymbol } from './utils';
|
|
7
|
+
function prepareSeriesData(series) {
|
|
8
|
+
var _a;
|
|
9
|
+
const nullMode = (_a = series.nullMode) !== null && _a !== void 0 ? _a : 'skip';
|
|
10
|
+
const data = series.data;
|
|
11
|
+
switch (nullMode) {
|
|
12
|
+
case 'zero':
|
|
13
|
+
return data.map((p) => { var _a; return (Object.assign(Object.assign({}, p), { value: (_a = p.value) !== null && _a !== void 0 ? _a : 0 })); });
|
|
14
|
+
case 'skip':
|
|
15
|
+
default:
|
|
16
|
+
return data.filter((p) => p.value !== null);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
7
19
|
export function preparePieSeries(args) {
|
|
8
20
|
const { series, seriesOptions, legend, colors } = args;
|
|
9
|
-
const
|
|
21
|
+
const preparedData = prepareSeriesData(series);
|
|
22
|
+
const dataNames = preparedData.map((d) => d.name);
|
|
10
23
|
const colorScale = scaleOrdinal(dataNames, colors);
|
|
11
24
|
const stackId = getUniqId();
|
|
12
25
|
const seriesHoverState = get(seriesOptions, 'pie.states.hover');
|
|
13
|
-
const preparedSeries =
|
|
26
|
+
const preparedSeries = preparedData.map((dataItem, i) => {
|
|
14
27
|
var _a, _b, _c, _d, _e, _f;
|
|
15
28
|
const result = {
|
|
16
29
|
type: 'pie',
|
|
@@ -20,6 +20,21 @@ function prepareMarker(series, seriesOptions, index) {
|
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
function prepareSeriesData(series) {
|
|
24
|
+
var _a;
|
|
25
|
+
const nullMode = (_a = series.nullMode) !== null && _a !== void 0 ? _a : 'skip';
|
|
26
|
+
const data = series.data;
|
|
27
|
+
switch (nullMode) {
|
|
28
|
+
case 'zero':
|
|
29
|
+
return data.map((p) => {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
return (Object.assign(Object.assign({}, p), { x: (_a = p.x) !== null && _a !== void 0 ? _a : 0, y: (_b = p.y) !== null && _b !== void 0 ? _b : 0 }));
|
|
32
|
+
});
|
|
33
|
+
case 'skip':
|
|
34
|
+
default:
|
|
35
|
+
return data.filter((p) => p.y !== null && p.x !== null);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
23
38
|
export function prepareScatterSeries(args) {
|
|
24
39
|
const { colorScale, series, seriesOptions, legend } = args;
|
|
25
40
|
return series.map((s, index) => {
|
|
@@ -36,7 +51,7 @@ export function prepareScatterSeries(args) {
|
|
|
36
51
|
enabled: get(s, 'legend.enabled', legend.enabled),
|
|
37
52
|
symbol: prepareLegendSymbol(s, symbolType),
|
|
38
53
|
},
|
|
39
|
-
data: s
|
|
54
|
+
data: prepareSeriesData(s),
|
|
40
55
|
marker: prepareMarker(s, seriesOptions, index),
|
|
41
56
|
cursor: get(s, 'cursor', null),
|
|
42
57
|
yAxis: get(s, 'yAxis', 0),
|
|
@@ -3,6 +3,21 @@ import { DEFAULT_DATALABELS_STYLE } from '../../constants';
|
|
|
3
3
|
import { getUniqId } from '../../utils';
|
|
4
4
|
import { DEFAULT_DATALABELS_PADDING } from './constants';
|
|
5
5
|
import { prepareLegendSymbol } from './utils';
|
|
6
|
+
function prepareSeriesData(series) {
|
|
7
|
+
var _a;
|
|
8
|
+
const nullMode = (_a = series.nullMode) !== null && _a !== void 0 ? _a : 'skip';
|
|
9
|
+
const data = series.data;
|
|
10
|
+
switch (nullMode) {
|
|
11
|
+
case 'zero':
|
|
12
|
+
return data.map((d) => {
|
|
13
|
+
var _a;
|
|
14
|
+
return (Object.assign(Object.assign({}, d), { y: d.total ? d.y : ((_a = d.y) !== null && _a !== void 0 ? _a : 0) }));
|
|
15
|
+
});
|
|
16
|
+
case 'skip':
|
|
17
|
+
default:
|
|
18
|
+
return data.filter((d) => d.y !== null);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
6
21
|
export function prepareWaterfallSeries(args) {
|
|
7
22
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
8
23
|
const { colorScale, series: seriesList, legend, colors } = args;
|
|
@@ -33,14 +48,15 @@ export function prepareWaterfallSeries(args) {
|
|
|
33
48
|
const positive = Object.assign(Object.assign({}, common), { name: (_g = (_f = (_e = series.legend) === null || _e === void 0 ? void 0 : _e.itemText) === null || _f === void 0 ? void 0 : _f.positive) !== null && _g !== void 0 ? _g : `${series.name} ↑`, id: getUniqId(), color: series.positiveColor || positiveColor, data: [] });
|
|
34
49
|
const negative = Object.assign(Object.assign({}, common), { name: (_k = (_j = (_h = series.legend) === null || _h === void 0 ? void 0 : _h.itemText) === null || _j === void 0 ? void 0 : _j.negative) !== null && _k !== void 0 ? _k : `${series.name} ↓`, id: getUniqId(), color: series.negativeColor || negativeColor, data: [] });
|
|
35
50
|
const totals = Object.assign(Object.assign({}, common), { name: (_o = (_m = (_l = series.legend) === null || _l === void 0 ? void 0 : _l.itemText) === null || _m === void 0 ? void 0 : _m.totals) !== null && _o !== void 0 ? _o : series.name, id: getUniqId(), data: [] });
|
|
36
|
-
|
|
51
|
+
const preparedData = prepareSeriesData(series);
|
|
52
|
+
preparedData.forEach((d, index) => {
|
|
37
53
|
var _a;
|
|
38
54
|
const value = (_a = d === null || d === void 0 ? void 0 : d.y) !== null && _a !== void 0 ? _a : 0;
|
|
39
55
|
const dataItem = Object.assign(Object.assign({}, d), { index });
|
|
40
56
|
if (d === null || d === void 0 ? void 0 : d.total) {
|
|
41
57
|
totals.data.push(dataItem);
|
|
42
58
|
}
|
|
43
|
-
else if (value
|
|
59
|
+
else if (value >= 0) {
|
|
44
60
|
positive.data.push(dataItem);
|
|
45
61
|
}
|
|
46
62
|
else if (value < 0) {
|
|
@@ -22,6 +22,7 @@ export const AreaSeriesShapes = (args) => {
|
|
|
22
22
|
const inactiveOptions = get(seriesOptions, 'area.states.inactive');
|
|
23
23
|
const line = lineGenerator()
|
|
24
24
|
.x((d) => d.x)
|
|
25
|
+
.defined((d) => d.y !== null)
|
|
25
26
|
.y((d) => d.y);
|
|
26
27
|
plotSvgElement.selectAll('*').remove();
|
|
27
28
|
markersSvgElement.selectAll('*').remove();
|
|
@@ -41,6 +42,7 @@ export const AreaSeriesShapes = (args) => {
|
|
|
41
42
|
.attr('stroke-linejoin', 'round')
|
|
42
43
|
.attr('stroke-linecap', 'round');
|
|
43
44
|
const area = areaGenerator()
|
|
45
|
+
.defined((d) => d.y !== null)
|
|
44
46
|
.x((d) => d.x)
|
|
45
47
|
.y0((d) => d.y0)
|
|
46
48
|
.y1((d) => d.y);
|