@gravity-ui/charts 0.6.1 → 0.8.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 +2 -2
- package/dist/cjs/components/Axis/AxisY.d.ts +1 -0
- package/dist/cjs/components/Axis/AxisY.js +55 -13
- package/dist/cjs/components/ChartInner/index.js +3 -2
- package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +4 -0
- package/dist/cjs/components/Legend/index.js +1 -2
- package/dist/cjs/components/PlotTitle/index.js +1 -1
- package/dist/cjs/components/PlotTitle/styles.css +1 -1
- package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +2 -2
- package/dist/cjs/components/Tooltip/DefaultContent.js +19 -3
- package/dist/cjs/components/Tooltip/index.js +5 -5
- package/dist/cjs/components/Tooltip/styles.css +2 -15
- package/dist/cjs/components/index.d.ts +10 -9
- package/dist/cjs/constants/index.d.ts +1 -0
- package/dist/cjs/constants/index.js +1 -0
- package/dist/cjs/hooks/useChartOptions/types.d.ts +11 -1
- package/dist/cjs/hooks/useChartOptions/x-axis.js +1 -0
- package/dist/cjs/hooks/useChartOptions/y-axis.js +9 -1
- package/dist/cjs/hooks/useSeries/prepare-area.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-x.d.ts +2 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-x.js +2 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +2 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-y.js +3 -1
- package/dist/cjs/hooks/useSeries/prepare-line.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepare-pie.js +2 -2
- package/dist/cjs/hooks/useSeries/prepare-sankey.d.ts +11 -0
- package/dist/cjs/hooks/useSeries/prepare-sankey.js +38 -0
- package/dist/cjs/hooks/useSeries/prepareSeries.js +21 -2
- package/dist/cjs/hooks/useSeries/types.d.ts +12 -2
- package/dist/cjs/hooks/useSeries/utils.js +1 -1
- package/dist/cjs/hooks/useShapes/bar-x/index.js +16 -2
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +2 -1
- package/dist/cjs/hooks/useShapes/bar-x/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/bar-y/index.js +16 -2
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +2 -1
- package/dist/cjs/hooks/useShapes/bar-y/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/index.d.ts +2 -1
- package/dist/cjs/hooks/useShapes/index.js +19 -0
- package/dist/cjs/hooks/useShapes/line/index.js +2 -2
- package/dist/cjs/hooks/useShapes/pie/index.js +3 -3
- package/dist/cjs/hooks/useShapes/pie/prepare-data.js +37 -35
- package/dist/cjs/hooks/useShapes/pie/types.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/sankey/index.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/sankey/index.js +67 -0
- package/dist/cjs/hooks/useShapes/sankey/prepare-data.d.ts +7 -0
- package/dist/cjs/hooks/useShapes/sankey/prepare-data.js +72 -0
- package/dist/cjs/hooks/useShapes/sankey/types.d.ts +33 -0
- package/dist/cjs/hooks/useShapes/sankey/types.js +1 -0
- package/dist/cjs/hooks/useShapes/styles.css +2 -2
- package/dist/cjs/hooks/useShapes/utils.d.ts +7 -2
- package/dist/cjs/hooks/useShapes/utils.js +22 -17
- package/dist/cjs/hooks/useShapes/waterfall/index.js +1 -2
- package/dist/cjs/types/chart/area.d.ts +6 -6
- package/dist/cjs/types/chart/axis.d.ts +32 -7
- package/dist/cjs/types/chart/bar-x.d.ts +9 -4
- package/dist/cjs/types/chart/bar-y.d.ts +10 -6
- package/dist/cjs/types/chart/base.d.ts +6 -6
- package/dist/cjs/types/chart/chart.d.ts +4 -4
- package/dist/cjs/types/chart/halo.d.ts +2 -2
- package/dist/cjs/types/chart/legend.d.ts +10 -10
- package/dist/cjs/types/chart/line.d.ts +4 -4
- package/dist/cjs/types/chart/marker.d.ts +2 -2
- package/dist/cjs/types/chart/pie.d.ts +6 -4
- package/dist/cjs/types/chart/sankey.d.ts +22 -0
- package/dist/cjs/types/chart/sankey.js +1 -0
- package/dist/cjs/types/chart/scatter.d.ts +4 -4
- package/dist/cjs/types/chart/series.d.ts +21 -10
- package/dist/cjs/types/chart/split.d.ts +4 -4
- package/dist/cjs/types/chart/title.d.ts +2 -2
- package/dist/cjs/types/chart/tooltip.d.ts +27 -21
- package/dist/cjs/types/chart/treemap.d.ts +4 -4
- package/dist/cjs/types/chart/waterfall.d.ts +4 -4
- package/dist/cjs/types/chart-ui.d.ts +6 -6
- package/dist/cjs/types/formatter.d.ts +4 -4
- package/dist/cjs/types/index.d.ts +35 -4
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/utils/chart/get-closest-data.d.ts +2 -0
- package/dist/cjs/utils/chart/get-closest-data.js +39 -3
- package/dist/cjs/utils/chart/index.js +1 -1
- package/dist/cjs/utils/chart/series/index.d.ts +1 -0
- package/dist/cjs/utils/chart/series/index.js +1 -0
- package/dist/cjs/utils/chart/series/line.d.ts +2 -0
- package/dist/cjs/utils/chart/series/line.js +17 -0
- package/dist/esm/components/Axis/AxisY.d.ts +1 -0
- package/dist/esm/components/Axis/AxisY.js +55 -13
- package/dist/esm/components/ChartInner/index.js +3 -2
- package/dist/esm/components/ChartInner/useChartInnerHandlers.js +4 -0
- package/dist/esm/components/Legend/index.js +1 -2
- package/dist/esm/components/PlotTitle/index.js +1 -1
- package/dist/esm/components/PlotTitle/styles.css +1 -1
- package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +2 -2
- package/dist/esm/components/Tooltip/DefaultContent.js +19 -3
- package/dist/esm/components/Tooltip/index.js +5 -5
- package/dist/esm/components/Tooltip/styles.css +2 -15
- package/dist/esm/components/index.d.ts +10 -9
- package/dist/esm/constants/index.d.ts +1 -0
- package/dist/esm/constants/index.js +1 -0
- package/dist/esm/hooks/useChartOptions/types.d.ts +11 -1
- package/dist/esm/hooks/useChartOptions/x-axis.js +1 -0
- package/dist/esm/hooks/useChartOptions/y-axis.js +9 -1
- package/dist/esm/hooks/useSeries/prepare-area.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepare-bar-x.d.ts +2 -1
- package/dist/esm/hooks/useSeries/prepare-bar-x.js +2 -1
- package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +2 -1
- package/dist/esm/hooks/useSeries/prepare-bar-y.js +3 -1
- package/dist/esm/hooks/useSeries/prepare-line.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepare-pie.js +2 -2
- package/dist/esm/hooks/useSeries/prepare-sankey.d.ts +11 -0
- package/dist/esm/hooks/useSeries/prepare-sankey.js +38 -0
- package/dist/esm/hooks/useSeries/prepareSeries.js +21 -2
- package/dist/esm/hooks/useSeries/types.d.ts +12 -2
- package/dist/esm/hooks/useSeries/utils.js +1 -1
- package/dist/esm/hooks/useShapes/bar-x/index.js +16 -2
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +2 -1
- package/dist/esm/hooks/useShapes/bar-x/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/bar-y/index.js +16 -2
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +2 -1
- package/dist/esm/hooks/useShapes/bar-y/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/index.d.ts +2 -1
- package/dist/esm/hooks/useShapes/index.js +19 -0
- package/dist/esm/hooks/useShapes/line/index.js +2 -2
- package/dist/esm/hooks/useShapes/pie/index.js +3 -3
- package/dist/esm/hooks/useShapes/pie/prepare-data.js +37 -35
- package/dist/esm/hooks/useShapes/pie/types.d.ts +1 -1
- package/dist/esm/hooks/useShapes/sankey/index.d.ts +12 -0
- package/dist/esm/hooks/useShapes/sankey/index.js +67 -0
- package/dist/esm/hooks/useShapes/sankey/prepare-data.d.ts +7 -0
- package/dist/esm/hooks/useShapes/sankey/prepare-data.js +72 -0
- package/dist/esm/hooks/useShapes/sankey/types.d.ts +33 -0
- package/dist/esm/hooks/useShapes/sankey/types.js +1 -0
- package/dist/esm/hooks/useShapes/styles.css +2 -2
- package/dist/esm/hooks/useShapes/utils.d.ts +7 -2
- package/dist/esm/hooks/useShapes/utils.js +22 -17
- package/dist/esm/hooks/useShapes/waterfall/index.js +1 -2
- package/dist/esm/types/chart/area.d.ts +6 -6
- package/dist/esm/types/chart/axis.d.ts +32 -7
- package/dist/esm/types/chart/bar-x.d.ts +9 -4
- package/dist/esm/types/chart/bar-y.d.ts +10 -6
- package/dist/esm/types/chart/base.d.ts +6 -6
- package/dist/esm/types/chart/chart.d.ts +4 -4
- package/dist/esm/types/chart/halo.d.ts +2 -2
- package/dist/esm/types/chart/legend.d.ts +10 -10
- package/dist/esm/types/chart/line.d.ts +4 -4
- package/dist/esm/types/chart/marker.d.ts +2 -2
- package/dist/esm/types/chart/pie.d.ts +6 -4
- package/dist/esm/types/chart/sankey.d.ts +22 -0
- package/dist/esm/types/chart/sankey.js +1 -0
- package/dist/esm/types/chart/scatter.d.ts +4 -4
- package/dist/esm/types/chart/series.d.ts +21 -10
- package/dist/esm/types/chart/split.d.ts +4 -4
- package/dist/esm/types/chart/title.d.ts +2 -2
- package/dist/esm/types/chart/tooltip.d.ts +27 -21
- package/dist/esm/types/chart/treemap.d.ts +4 -4
- package/dist/esm/types/chart/waterfall.d.ts +4 -4
- package/dist/esm/types/chart-ui.d.ts +6 -6
- package/dist/esm/types/formatter.d.ts +4 -4
- package/dist/esm/types/index.d.ts +35 -4
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/utils/chart/get-closest-data.d.ts +2 -0
- package/dist/esm/utils/chart/get-closest-data.js +39 -3
- package/dist/esm/utils/chart/index.js +1 -1
- package/dist/esm/utils/chart/series/index.d.ts +1 -0
- package/dist/esm/utils/chart/series/index.js +1 -0
- package/dist/esm/utils/chart/series/line.d.ts +2 -0
- package/dist/esm/utils/chart/series/line.js +17 -0
- package/package.json +9 -4
|
@@ -5,66 +5,72 @@ import type { BarXSeries, BarXSeriesData } from './bar-x';
|
|
|
5
5
|
import type { BarYSeries, BarYSeriesData } from './bar-y';
|
|
6
6
|
import type { LineSeries, LineSeriesData } from './line';
|
|
7
7
|
import type { PieSeries, PieSeriesData } from './pie';
|
|
8
|
+
import type { SankeySeries, SankeySeriesData } from './sankey';
|
|
8
9
|
import type { ScatterSeries, ScatterSeriesData } from './scatter';
|
|
9
10
|
import type { TreemapSeries, TreemapSeriesData } from './treemap';
|
|
10
11
|
import type { WaterfallSeries, WaterfallSeriesData } from './waterfall';
|
|
11
|
-
export
|
|
12
|
+
export interface TooltipDataChunkBarX<T = MeaningfulAny> {
|
|
12
13
|
data: BarXSeriesData<T>;
|
|
13
14
|
series: BarXSeries<T>;
|
|
14
|
-
}
|
|
15
|
-
export
|
|
15
|
+
}
|
|
16
|
+
export interface TooltipDataChunkBarY<T = MeaningfulAny> {
|
|
16
17
|
data: BarYSeriesData<T>;
|
|
17
18
|
series: BarYSeries<T>;
|
|
18
|
-
}
|
|
19
|
-
export
|
|
19
|
+
}
|
|
20
|
+
export interface TooltipDataChunkPie<T = MeaningfulAny> {
|
|
20
21
|
data: PieSeriesData<T>;
|
|
21
22
|
series: {
|
|
22
23
|
type: PieSeries['type'];
|
|
23
24
|
id: string;
|
|
24
25
|
name: string;
|
|
25
26
|
};
|
|
26
|
-
}
|
|
27
|
-
export
|
|
27
|
+
}
|
|
28
|
+
export interface TooltipDataChunkScatter<T = MeaningfulAny> {
|
|
28
29
|
data: ScatterSeriesData<T>;
|
|
29
30
|
series: {
|
|
30
31
|
type: ScatterSeries['type'];
|
|
31
32
|
id: string;
|
|
32
33
|
name: string;
|
|
33
34
|
};
|
|
34
|
-
}
|
|
35
|
-
export
|
|
35
|
+
}
|
|
36
|
+
export interface TooltipDataChunkLine<T = MeaningfulAny> {
|
|
36
37
|
data: LineSeriesData<T>;
|
|
37
38
|
series: {
|
|
38
39
|
type: LineSeries['type'];
|
|
39
40
|
id: string;
|
|
40
41
|
name: string;
|
|
41
42
|
};
|
|
42
|
-
}
|
|
43
|
-
export
|
|
43
|
+
}
|
|
44
|
+
export interface TooltipDataChunkArea<T = MeaningfulAny> {
|
|
44
45
|
data: AreaSeriesData<T>;
|
|
45
46
|
series: {
|
|
46
47
|
type: AreaSeries['type'];
|
|
47
48
|
id: string;
|
|
48
49
|
name: string;
|
|
49
50
|
};
|
|
50
|
-
}
|
|
51
|
-
export
|
|
51
|
+
}
|
|
52
|
+
export interface TooltipDataChunkTreemap<T = MeaningfulAny> {
|
|
52
53
|
data: TreemapSeriesData<T>;
|
|
53
54
|
series: TreemapSeries<T>;
|
|
54
|
-
}
|
|
55
|
-
export
|
|
55
|
+
}
|
|
56
|
+
export interface TooltipDataChunkSankey<T = MeaningfulAny> {
|
|
57
|
+
data: SankeySeriesData<T>;
|
|
58
|
+
target?: SankeySeriesData<T>;
|
|
59
|
+
series: SankeySeries<T>;
|
|
60
|
+
}
|
|
61
|
+
export interface TooltipDataChunkWaterfall<T = MeaningfulAny> {
|
|
56
62
|
data: WaterfallSeriesData<T>;
|
|
57
63
|
series: WaterfallSeries<T>;
|
|
58
|
-
}
|
|
59
|
-
export type TooltipDataChunk<T = MeaningfulAny> = (TooltipDataChunkBarX<T> | TooltipDataChunkBarY<T> | TooltipDataChunkPie<T> | TooltipDataChunkScatter<T> | TooltipDataChunkLine<T> | TooltipDataChunkArea<T> | TooltipDataChunkTreemap<T> | TooltipDataChunkWaterfall<T>) & {
|
|
64
|
+
}
|
|
65
|
+
export type TooltipDataChunk<T = MeaningfulAny> = (TooltipDataChunkBarX<T> | TooltipDataChunkBarY<T> | TooltipDataChunkPie<T> | TooltipDataChunkScatter<T> | TooltipDataChunkLine<T> | TooltipDataChunkArea<T> | TooltipDataChunkTreemap<T> | TooltipDataChunkSankey<T> | TooltipDataChunkWaterfall<T>) & {
|
|
60
66
|
closest?: boolean;
|
|
61
67
|
};
|
|
62
|
-
export
|
|
68
|
+
export interface ChartTooltipRendererArgs<T = MeaningfulAny> {
|
|
63
69
|
hovered: TooltipDataChunk<T>[];
|
|
64
70
|
xAxis?: ChartXAxis;
|
|
65
71
|
yAxis?: ChartYAxis;
|
|
66
|
-
}
|
|
67
|
-
export
|
|
72
|
+
}
|
|
73
|
+
export interface ChartTooltip<T = MeaningfulAny> {
|
|
68
74
|
enabled?: boolean;
|
|
69
75
|
/** Specifies the renderer for the tooltip. If returned null default tooltip renderer will be used. */
|
|
70
76
|
renderer?: (args: ChartTooltipRendererArgs<T>) => React.ReactElement | null;
|
|
@@ -72,4 +78,4 @@ export type ChartTooltip<T = MeaningfulAny> = {
|
|
|
72
78
|
enabled?: boolean;
|
|
73
79
|
modifierKey?: 'altKey' | 'metaKey';
|
|
74
80
|
};
|
|
75
|
-
}
|
|
81
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { LayoutAlgorithm, SeriesType } from '../../constants';
|
|
|
2
2
|
import type { MeaningfulAny } from '../misc';
|
|
3
3
|
import type { BaseSeries, BaseSeriesData } from './base';
|
|
4
4
|
import type { ChartLegend, RectLegendSymbolOptions } from './legend';
|
|
5
|
-
export
|
|
5
|
+
export interface TreemapSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
|
|
6
6
|
/** The name of the node (used in legend, tooltip etc). */
|
|
7
7
|
name: string | string[];
|
|
8
8
|
/** The value of the node. All nodes should have this property except nodes that have children. */
|
|
@@ -14,8 +14,8 @@ export type TreemapSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
|
|
|
14
14
|
* If no nodes has a matching id, or this option is undefined, then the parent will be set to the root.
|
|
15
15
|
*/
|
|
16
16
|
parentId?: string;
|
|
17
|
-
}
|
|
18
|
-
export
|
|
17
|
+
}
|
|
18
|
+
export interface TreemapSeries<T = MeaningfulAny> extends BaseSeries {
|
|
19
19
|
type: typeof SeriesType.Treemap;
|
|
20
20
|
data: TreemapSeriesData<T>[];
|
|
21
21
|
/** The name of the series (used in legend, tooltip etc). */
|
|
@@ -43,4 +43,4 @@ export type TreemapSeries<T = MeaningfulAny> = BaseSeries & {
|
|
|
43
43
|
/** Horizontal alignment of the data label inside the tile. */
|
|
44
44
|
align?: 'left' | 'center' | 'right';
|
|
45
45
|
};
|
|
46
|
-
}
|
|
46
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { SeriesType } from '../../constants';
|
|
|
2
2
|
import type { MeaningfulAny } from '../misc';
|
|
3
3
|
import type { BaseSeries, BaseSeriesData } from './base';
|
|
4
4
|
import type { ChartLegend, RectLegendSymbolOptions } from './legend';
|
|
5
|
-
export
|
|
5
|
+
export interface WaterfallSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
|
|
6
6
|
/**
|
|
7
7
|
* The `x` value. Depending on the context , it may represents:
|
|
8
8
|
* - numeric value (for `linear` x axis)
|
|
@@ -21,8 +21,8 @@ export type WaterfallSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
|
|
|
21
21
|
opacity?: number;
|
|
22
22
|
/** When this property is true, the point display the total sum across the entire series. */
|
|
23
23
|
total?: boolean;
|
|
24
|
-
}
|
|
25
|
-
export
|
|
24
|
+
}
|
|
25
|
+
export interface WaterfallSeries<T = MeaningfulAny> extends BaseSeries {
|
|
26
26
|
type: typeof SeriesType.Waterfall;
|
|
27
27
|
data: WaterfallSeriesData<T>[];
|
|
28
28
|
/** The name of the series (used in legend, tooltip etc). */
|
|
@@ -37,4 +37,4 @@ export type WaterfallSeries<T = MeaningfulAny> = BaseSeries & {
|
|
|
37
37
|
legend?: ChartLegend & {
|
|
38
38
|
symbol?: RectLegendSymbolOptions;
|
|
39
39
|
};
|
|
40
|
-
}
|
|
40
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BaseTextStyle } from './chart/base';
|
|
2
|
-
export
|
|
2
|
+
export interface LabelData {
|
|
3
3
|
text: string;
|
|
4
4
|
x: number;
|
|
5
5
|
y: number;
|
|
@@ -13,8 +13,8 @@ export type LabelData = {
|
|
|
13
13
|
id: string;
|
|
14
14
|
};
|
|
15
15
|
active?: boolean;
|
|
16
|
-
}
|
|
17
|
-
export
|
|
16
|
+
}
|
|
17
|
+
export interface HtmlItem {
|
|
18
18
|
x: number;
|
|
19
19
|
y: number;
|
|
20
20
|
content: string;
|
|
@@ -22,7 +22,7 @@ export type HtmlItem = {
|
|
|
22
22
|
width: number;
|
|
23
23
|
height: number;
|
|
24
24
|
};
|
|
25
|
-
}
|
|
26
|
-
export
|
|
25
|
+
}
|
|
26
|
+
export interface ShapeDataWithHtmlItems {
|
|
27
27
|
htmlElements: HtmlItem[];
|
|
28
|
-
}
|
|
28
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface FormatOptions {
|
|
2
2
|
precision?: number | 'auto';
|
|
3
3
|
unitRate?: number;
|
|
4
4
|
showRankDelimiter?: boolean;
|
|
5
5
|
lang?: string;
|
|
6
6
|
labelMode?: string;
|
|
7
|
-
}
|
|
8
|
-
export
|
|
7
|
+
}
|
|
8
|
+
export interface FormatNumberOptions extends FormatOptions {
|
|
9
9
|
format?: 'number' | 'percent';
|
|
10
10
|
multiplier?: number;
|
|
11
11
|
prefix?: string;
|
|
12
12
|
postfix?: string;
|
|
13
13
|
unit?: 'auto' | 'k' | 'm' | 'b' | 't' | null;
|
|
14
|
-
}
|
|
14
|
+
}
|
|
@@ -25,18 +25,49 @@ export * from './chart/tooltip';
|
|
|
25
25
|
export * from './chart/halo';
|
|
26
26
|
export * from './chart/treemap';
|
|
27
27
|
export * from './chart/waterfall';
|
|
28
|
-
export
|
|
28
|
+
export * from './chart/sankey';
|
|
29
|
+
export interface ChartData<T = MeaningfulAny> {
|
|
30
|
+
/**
|
|
31
|
+
* General options for the chart.
|
|
32
|
+
*/
|
|
29
33
|
chart?: ChartOptions;
|
|
34
|
+
/**
|
|
35
|
+
* The legend displays a labeled box for each data element in the chart.
|
|
36
|
+
* It shows a distinctive symbol paired with a name for every series.
|
|
37
|
+
*/
|
|
30
38
|
legend?: ChartLegend;
|
|
39
|
+
/**
|
|
40
|
+
* Represents the series data and series options.
|
|
41
|
+
*/
|
|
31
42
|
series: {
|
|
43
|
+
/**
|
|
44
|
+
* Contains data points to be plotted.
|
|
45
|
+
*/
|
|
32
46
|
data: ChartSeries<T>[];
|
|
47
|
+
/**
|
|
48
|
+
* Allows for customizing the appearance and behavior of the series.
|
|
49
|
+
*/
|
|
33
50
|
options?: ChartSeriesOptions;
|
|
34
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* The main title of the chart.
|
|
54
|
+
*/
|
|
35
55
|
title?: ChartTitle;
|
|
56
|
+
/**
|
|
57
|
+
* Options for the tooltip that appears when the user hovers over a series or point.
|
|
58
|
+
*/
|
|
36
59
|
tooltip?: ChartTooltip<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Options for the the X axis.
|
|
62
|
+
*/
|
|
37
63
|
xAxis?: ChartXAxis;
|
|
64
|
+
/**
|
|
65
|
+
* Options for the the Y axis or multiple Y axes.
|
|
66
|
+
*/
|
|
38
67
|
yAxis?: ChartYAxis[];
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
68
|
+
/**
|
|
69
|
+
* Setting for displaying charts on different plots.
|
|
70
|
+
* It can be used to visualize related information on multiple charts.
|
|
71
|
+
*/
|
|
41
72
|
split?: ChartSplit;
|
|
42
|
-
}
|
|
73
|
+
}
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -35,7 +35,7 @@ function getSeriesType(shapeData) {
|
|
|
35
35
|
return get(shapeData, 'series.type') || get(shapeData, 'point.series.type');
|
|
36
36
|
}
|
|
37
37
|
export function getClosestPoints(args) {
|
|
38
|
-
const { position, shapesData } = args;
|
|
38
|
+
const { position, shapesData, boundsHeight, boundsWidth } = args;
|
|
39
39
|
const [pointerX, pointerY] = position;
|
|
40
40
|
const result = [];
|
|
41
41
|
const groups = groupBy(shapesData, getSeriesType);
|
|
@@ -135,13 +135,13 @@ export function getClosestPoints(args) {
|
|
|
135
135
|
case 'pie': {
|
|
136
136
|
const points = list.map((d) => d.segments).flat();
|
|
137
137
|
const closestPoint = points.find((p) => {
|
|
138
|
-
const { center
|
|
138
|
+
const { center } = p.data.pie;
|
|
139
139
|
const x = pointerX - center[0];
|
|
140
140
|
const y = pointerY - center[1];
|
|
141
141
|
let angle = Math.atan2(y, x) + 0.5 * Math.PI;
|
|
142
142
|
angle = angle < 0 ? Math.PI * 2 + angle : angle;
|
|
143
143
|
const polarRadius = Math.sqrt(x * x + y * y);
|
|
144
|
-
return angle >= p.startAngle && angle <= p.endAngle && polarRadius < radius;
|
|
144
|
+
return (angle >= p.startAngle && angle <= p.endAngle && polarRadius < p.data.radius);
|
|
145
145
|
});
|
|
146
146
|
if (closestPoint) {
|
|
147
147
|
result.push({
|
|
@@ -166,7 +166,43 @@ export function getClosestPoints(args) {
|
|
|
166
166
|
}
|
|
167
167
|
break;
|
|
168
168
|
}
|
|
169
|
+
case 'sankey': {
|
|
170
|
+
const [data] = list;
|
|
171
|
+
const closestLink = data.links.find((d) => {
|
|
172
|
+
var _a;
|
|
173
|
+
return isInsidePath({
|
|
174
|
+
path: (_a = d.path) !== null && _a !== void 0 ? _a : '',
|
|
175
|
+
strokeWidth: d.strokeWidth,
|
|
176
|
+
point: [pointerX, pointerY],
|
|
177
|
+
width: boundsWidth,
|
|
178
|
+
height: boundsHeight,
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
if (closestLink) {
|
|
182
|
+
result.push({
|
|
183
|
+
data: closestLink.source,
|
|
184
|
+
target: closestLink.target,
|
|
185
|
+
series: data.series,
|
|
186
|
+
closest: true,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
169
191
|
}
|
|
170
192
|
});
|
|
171
193
|
return result;
|
|
172
194
|
}
|
|
195
|
+
function isInsidePath(args) {
|
|
196
|
+
const { path, point, width, height, strokeWidth } = args;
|
|
197
|
+
const canvas = document.createElement('canvas');
|
|
198
|
+
canvas.width = width;
|
|
199
|
+
canvas.height = height;
|
|
200
|
+
const ctx = canvas.getContext('2d');
|
|
201
|
+
if (ctx) {
|
|
202
|
+
ctx.lineWidth = strokeWidth;
|
|
203
|
+
const path2D = new Path2D(path);
|
|
204
|
+
ctx.stroke(path2D);
|
|
205
|
+
return ctx.isPointInPath(path2D, ...point) || ctx.isPointInStroke(path2D, ...point);
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
@@ -15,7 +15,7 @@ export * from './legend';
|
|
|
15
15
|
export * from './symbol';
|
|
16
16
|
export * from './series';
|
|
17
17
|
export * from './color';
|
|
18
|
-
const CHARTS_WITHOUT_AXIS = ['pie', 'treemap'];
|
|
18
|
+
const CHARTS_WITHOUT_AXIS = ['pie', 'treemap', 'sankey'];
|
|
19
19
|
export const CHART_SERIES_WITH_VOLUME_ON_Y_AXIS = [
|
|
20
20
|
'bar-x',
|
|
21
21
|
'area',
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function getLineDashArray(dashStyle, strokeWidth = 2) {
|
|
2
|
+
const value = dashStyle.toLowerCase();
|
|
3
|
+
const arrayValue = value
|
|
4
|
+
.replace('shortdashdotdot', '3,1,1,1,1,1,')
|
|
5
|
+
.replace('shortdashdot', '3,1,1,1')
|
|
6
|
+
.replace('shortdot', '1,1,')
|
|
7
|
+
.replace('shortdash', '3,1,')
|
|
8
|
+
.replace('longdash', '8,3,')
|
|
9
|
+
.replace(/dot/g, '1,3,')
|
|
10
|
+
.replace('dash', '4,3,')
|
|
11
|
+
.replace(/,$/, '')
|
|
12
|
+
.split(',')
|
|
13
|
+
.map((part) => {
|
|
14
|
+
return `${parseInt(part, 10) * strokeWidth}`;
|
|
15
|
+
});
|
|
16
|
+
return arrayValue.join(',').replace(/NaN/g, 'none');
|
|
17
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { axisLeft, axisRight, line, select } from 'd3';
|
|
3
|
-
import { block, calculateCos, calculateSin, formatAxisTickLabel, getAxisHeight, getAxisTitleRows, getClosestPointsRange, getScaleTicks, getTicksCount, handleOverflowingText, parseTransformStyle, setEllipsisForOverflowTexts, wrapText, } from '../../utils';
|
|
3
|
+
import { block, calculateCos, calculateSin, formatAxisTickLabel, getAxisHeight, getAxisTitleRows, getClosestPointsRange, getLineDashArray, getScaleTicks, getTicksCount, handleOverflowingText, parseTransformStyle, setEllipsisForOverflowTexts, wrapText, } from '../../utils';
|
|
4
4
|
import './styles.css';
|
|
5
5
|
const b = block('d3-axis');
|
|
6
6
|
function transformLabel(args) {
|
|
@@ -79,7 +79,7 @@ function getTitlePosition(args) {
|
|
|
79
79
|
return { x, y };
|
|
80
80
|
}
|
|
81
81
|
export const AxisY = (props) => {
|
|
82
|
-
const { axes, width, height: totalHeight, scale, split } = props;
|
|
82
|
+
const { axes, width, height: totalHeight, scale, split, plotRef } = props;
|
|
83
83
|
const height = getAxisHeight({ split, boundsHeight: totalHeight });
|
|
84
84
|
const ref = React.useRef(null);
|
|
85
85
|
React.useEffect(() => {
|
|
@@ -88,26 +88,34 @@ export const AxisY = (props) => {
|
|
|
88
88
|
}
|
|
89
89
|
const svgElement = select(ref.current);
|
|
90
90
|
svgElement.selectAll('*').remove();
|
|
91
|
+
const getAxisPosition = (axis) => {
|
|
92
|
+
var _a;
|
|
93
|
+
const top = ((_a = split.plots[axis.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
|
|
94
|
+
if (axis.position === 'left') {
|
|
95
|
+
return `translate(0, ${top}px)`;
|
|
96
|
+
}
|
|
97
|
+
return `translate(${width}px, 0)`;
|
|
98
|
+
};
|
|
99
|
+
const plotLines = axes.reduce((acc, axis) => {
|
|
100
|
+
if (axis.plotLines.length) {
|
|
101
|
+
acc.push(...axis.plotLines.map((plotLine) => {
|
|
102
|
+
return Object.assign(Object.assign({}, plotLine), { transform: getAxisPosition(axis) });
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
return acc;
|
|
106
|
+
}, []);
|
|
91
107
|
const axisSelection = svgElement
|
|
92
108
|
.selectAll('axis')
|
|
93
109
|
.data(axes)
|
|
94
110
|
.join('g')
|
|
95
111
|
.attr('class', b())
|
|
96
|
-
.style('transform', (d) =>
|
|
97
|
-
var _a;
|
|
98
|
-
const top = ((_a = split.plots[d.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
|
|
99
|
-
if (d.position === 'left') {
|
|
100
|
-
return `translate(0, ${top}px)`;
|
|
101
|
-
}
|
|
102
|
-
return `translate(${width}px, 0)`;
|
|
103
|
-
});
|
|
112
|
+
.style('transform', (d) => getAxisPosition(d));
|
|
104
113
|
axisSelection.each((d, index, node) => {
|
|
105
114
|
const seriesScale = scale[index];
|
|
106
115
|
const axisItem = select(node[index]);
|
|
116
|
+
const axisScale = seriesScale;
|
|
107
117
|
const yAxisGenerator = getAxisGenerator({
|
|
108
|
-
axisGenerator: d.position === 'left'
|
|
109
|
-
? axisLeft(seriesScale)
|
|
110
|
-
: axisRight(seriesScale),
|
|
118
|
+
axisGenerator: d.position === 'left' ? axisLeft(axisScale) : axisRight(axisScale),
|
|
111
119
|
preparedAxis: d,
|
|
112
120
|
height,
|
|
113
121
|
width,
|
|
@@ -148,6 +156,40 @@ export const AxisY = (props) => {
|
|
|
148
156
|
})
|
|
149
157
|
.remove();
|
|
150
158
|
}
|
|
159
|
+
if (plotRef && d.plotLines.length > 0) {
|
|
160
|
+
const plotLineClassName = b('plotLine');
|
|
161
|
+
const plotLineContainer = select(plotRef.current);
|
|
162
|
+
plotLineContainer.selectAll(`.${plotLineClassName}`).remove();
|
|
163
|
+
const plotLinesSelection = plotLineContainer
|
|
164
|
+
.selectAll(`.${plotLineClassName}`)
|
|
165
|
+
.data(plotLines)
|
|
166
|
+
.join('g')
|
|
167
|
+
.attr('class', plotLineClassName)
|
|
168
|
+
.style('transform', (plotLine) => plotLine.transform);
|
|
169
|
+
plotLinesSelection
|
|
170
|
+
.append('path')
|
|
171
|
+
.attr('d', (plotLine) => {
|
|
172
|
+
const plotLineValue = Number(axisScale(plotLine.value));
|
|
173
|
+
const points = [
|
|
174
|
+
[0, plotLineValue],
|
|
175
|
+
[width, plotLineValue],
|
|
176
|
+
];
|
|
177
|
+
return line()(points);
|
|
178
|
+
})
|
|
179
|
+
.attr('stroke', (plotLine) => plotLine.color)
|
|
180
|
+
.attr('stroke-width', (plotLine) => plotLine.width)
|
|
181
|
+
.attr('stroke-dasharray', (plotLine) => getLineDashArray(plotLine.dashStyle, plotLine.width))
|
|
182
|
+
.attr('opacity', (plotLine) => plotLine.opacity);
|
|
183
|
+
plotLinesSelection.each((plotLineData, i, nodes) => {
|
|
184
|
+
const plotLineSelection = select(nodes[i]);
|
|
185
|
+
if (plotLineData.layerPlacement === 'before') {
|
|
186
|
+
plotLineSelection.lower();
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
plotLineSelection.raise();
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
151
193
|
return axisItem;
|
|
152
194
|
});
|
|
153
195
|
axisSelection
|
|
@@ -15,6 +15,7 @@ export const ChartInner = (props) => {
|
|
|
15
15
|
const { width, height, data } = props;
|
|
16
16
|
const svgRef = React.useRef(null);
|
|
17
17
|
const htmlLayerRef = React.useRef(null);
|
|
18
|
+
const plotRef = React.useRef(null);
|
|
18
19
|
const dispatcher = React.useMemo(() => getD3Dispatcher(), []);
|
|
19
20
|
const { boundsHeight, boundsOffsetLeft, boundsOffsetTop, boundsWidth, handleLegendItemClick, legendConfig, legendItems, preparedSeries, preparedSplit, preparedLegend, prevHeight, prevWidth, shapes, shapesData, title, tooltip, xAxis, xScale, yAxis, yScale, } = useChartInnerProps(Object.assign(Object.assign({}, props), { dispatcher, htmlLayout: htmlLayerRef.current }));
|
|
20
21
|
const { tooltipPinned, togglePinTooltip, unpinTooltip } = useChartInnerState({
|
|
@@ -63,9 +64,9 @@ export const ChartInner = (props) => {
|
|
|
63
64
|
React.createElement("g", { transform: `translate(0, ${boundsOffsetTop})` }, preparedSplit.plots.map((plot, index) => {
|
|
64
65
|
return React.createElement(PlotTitle, { key: `plot-${index}`, title: plot.title });
|
|
65
66
|
})),
|
|
66
|
-
React.createElement("g", { width: boundsWidth, height: boundsHeight, transform: `translate(${[boundsOffsetLeft, boundsOffsetTop].join(',')})
|
|
67
|
+
React.createElement("g", { width: boundsWidth, height: boundsHeight, transform: `translate(${[boundsOffsetLeft, boundsOffsetTop].join(',')})`, ref: plotRef },
|
|
67
68
|
xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length) && (React.createElement(React.Fragment, null,
|
|
68
|
-
React.createElement(AxisY, { axes: yAxis, width: boundsWidth, height: boundsHeight, scale: yScale, split: preparedSplit }),
|
|
69
|
+
React.createElement(AxisY, { axes: yAxis, width: boundsWidth, height: boundsHeight, scale: yScale, split: preparedSplit, plotRef: plotRef }),
|
|
69
70
|
React.createElement("g", { transform: `translate(0, ${boundsHeight})` },
|
|
70
71
|
React.createElement(AxisX, { axis: xAxis, width: boundsWidth, height: boundsHeight, scale: xScale, split: preparedSplit })))),
|
|
71
72
|
shapes),
|
|
@@ -24,6 +24,8 @@ export function useChartInnerHandlers(props) {
|
|
|
24
24
|
const closest = getClosestPoints({
|
|
25
25
|
position: [x, y],
|
|
26
26
|
shapesData,
|
|
27
|
+
boundsHeight,
|
|
28
|
+
boundsWidth,
|
|
27
29
|
});
|
|
28
30
|
dispatcher.call(EventType.HOVER_SHAPE, event.target, closest, [pointerX, pointerY]);
|
|
29
31
|
dispatcher.call(EventType.POINTERMOVE_CHART, {}, {
|
|
@@ -65,6 +67,8 @@ export function useChartInnerHandlers(props) {
|
|
|
65
67
|
const items = getClosestPoints({
|
|
66
68
|
position: [x, y],
|
|
67
69
|
shapesData,
|
|
70
|
+
boundsHeight,
|
|
71
|
+
boundsWidth,
|
|
68
72
|
});
|
|
69
73
|
const selected = items === null || items === void 0 ? void 0 : items.find((item) => item.closest);
|
|
70
74
|
if (!selected) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { line as lineGenerator, scaleLinear, select, symbol } from 'd3';
|
|
3
3
|
import { CONTINUOUS_LEGEND_SIZE } from '../../constants';
|
|
4
|
-
import { getLineDashArray } from '../../hooks/useShapes/utils';
|
|
5
4
|
import { formatNumber } from '../../libs';
|
|
6
|
-
import { block, createGradientRect, getContinuesColorFn, getLabelsSize, getSymbol, } from '../../utils';
|
|
5
|
+
import { block, createGradientRect, getContinuesColorFn, getLabelsSize, getLineDashArray, getSymbol, } from '../../utils';
|
|
7
6
|
import { axisBottom } from '../../utils/chart/axis-generators';
|
|
8
7
|
import './styles.css';
|
|
9
8
|
const b = block('d3-legend');
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ChartTooltip, ChartXAxis, ChartYAxis, TooltipDataChunk } from '../../types';
|
|
3
|
-
export
|
|
3
|
+
export interface ChartTooltipContentProps {
|
|
4
4
|
hovered?: TooltipDataChunk[];
|
|
5
5
|
xAxis?: ChartXAxis;
|
|
6
6
|
yAxis?: ChartYAxis;
|
|
7
7
|
renderer?: ChartTooltip['renderer'];
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
export declare const ChartTooltipContent: (props: ChartTooltipContentProps) => React.JSX.Element | null;
|
|
@@ -3,7 +3,7 @@ import { dateTime } from '@gravity-ui/date-utils';
|
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import { formatNumber } from '../../libs';
|
|
5
5
|
import { block, getDataCategoryValue, getWaterfallPointSubtotal } from '../../utils';
|
|
6
|
-
const b = block('
|
|
6
|
+
const b = block('tooltip');
|
|
7
7
|
const DEFAULT_DATE_FORMAT = 'DD.MM.YY';
|
|
8
8
|
const getRowData = (fieldName, data, axis) => {
|
|
9
9
|
switch (axis === null || axis === void 0 ? void 0 : axis.type) {
|
|
@@ -29,7 +29,7 @@ const getXRowData = (data, xAxis) => getRowData('x', data, xAxis);
|
|
|
29
29
|
const getYRowData = (data, yAxis) => getRowData('y', data, yAxis);
|
|
30
30
|
const getMeasureValue = (data, xAxis, yAxis) => {
|
|
31
31
|
var _a, _b;
|
|
32
|
-
if (data.every((item) => ['pie', 'treemap', 'waterfall'].includes(item.series.type))) {
|
|
32
|
+
if (data.every((item) => ['pie', 'treemap', 'waterfall', 'sankey'].includes(item.series.type))) {
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
35
|
if (data.some((item) => item.series.type === 'bar-y')) {
|
|
@@ -41,7 +41,9 @@ export const DefaultContent = ({ hovered, xAxis, yAxis }) => {
|
|
|
41
41
|
const measureValue = getMeasureValue(hovered, xAxis, yAxis);
|
|
42
42
|
return (React.createElement(React.Fragment, null,
|
|
43
43
|
measureValue && React.createElement("div", null, measureValue),
|
|
44
|
-
hovered.map((
|
|
44
|
+
hovered.map((seriesItem, i) => {
|
|
45
|
+
var _a;
|
|
46
|
+
const { data, series, closest } = seriesItem;
|
|
45
47
|
const id = `${get(series, 'id')}_${i}`;
|
|
46
48
|
const color = get(series, 'color');
|
|
47
49
|
switch (series.type) {
|
|
@@ -93,6 +95,20 @@ export const DefaultContent = ({ hovered, xAxis, yAxis }) => {
|
|
|
93
95
|
"\u00A0"),
|
|
94
96
|
React.createElement("span", null, seriesData.value)));
|
|
95
97
|
}
|
|
98
|
+
case 'sankey': {
|
|
99
|
+
const { target, data: source } = seriesItem;
|
|
100
|
+
const value = (_a = source.links.find((d) => d.name === (target === null || target === void 0 ? void 0 : target.name))) === null || _a === void 0 ? void 0 : _a.value;
|
|
101
|
+
return (React.createElement("div", { key: id, className: b('content-row') },
|
|
102
|
+
React.createElement("div", { className: b('color'), style: { backgroundColor: source.color } }),
|
|
103
|
+
React.createElement("div", { style: { display: 'flex', gap: 8, verticalAlign: 'center' } },
|
|
104
|
+
source.name,
|
|
105
|
+
" ",
|
|
106
|
+
React.createElement("span", null, "\u2192"),
|
|
107
|
+
" ", target === null || target === void 0 ? void 0 :
|
|
108
|
+
target.name,
|
|
109
|
+
": ",
|
|
110
|
+
value)));
|
|
111
|
+
}
|
|
96
112
|
default: {
|
|
97
113
|
return null;
|
|
98
114
|
}
|