@gravity-ui/chartkit 4.6.1 → 4.7.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/build/plugins/d3/examples/bar-x/Basic.d.ts +4 -0
- package/build/plugins/d3/examples/bar-x/Basic.js +78 -0
- package/build/plugins/d3/examples/bar-x/GroupedColumns.d.ts +2 -0
- package/build/plugins/d3/examples/bar-x/GroupedColumns.js +44 -0
- package/build/plugins/d3/examples/bar-x/StackedColumns.d.ts +2 -0
- package/build/plugins/d3/examples/bar-x/StackedColumns.js +45 -0
- package/build/plugins/d3/examples/nintendoGames.d.ts +62 -0
- package/build/plugins/d3/examples/nintendoGames.js +12037 -0
- package/build/plugins/d3/examples/pie/Basic.d.ts +2 -0
- package/build/plugins/d3/examples/pie/Basic.js +30 -0
- package/build/plugins/d3/examples/pie/Donut.d.ts +2 -0
- package/build/plugins/d3/examples/pie/Donut.js +31 -0
- package/build/plugins/d3/examples/scatter/Basic.d.ts +2 -0
- package/build/plugins/d3/examples/scatter/Basic.js +66 -0
- package/build/plugins/d3/renderer/components/AxisX.js +6 -7
- package/build/plugins/d3/renderer/components/AxisY.js +50 -18
- package/build/plugins/d3/renderer/components/Chart.js +24 -16
- package/build/plugins/d3/renderer/components/Legend.js +20 -22
- package/build/plugins/d3/renderer/components/Title.js +1 -1
- package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.d.ts +2 -2
- package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.js +8 -0
- package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.d.ts +14 -0
- package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.js +70 -0
- package/build/plugins/d3/renderer/components/Tooltip/index.d.ts +5 -3
- package/build/plugins/d3/renderer/components/Tooltip/index.js +4 -2
- package/build/plugins/d3/renderer/components/styles.css +3 -0
- package/build/plugins/d3/renderer/constants/defaults/axis.d.ts +9 -0
- package/build/plugins/d3/renderer/constants/defaults/axis.js +6 -0
- package/build/plugins/d3/renderer/constants/defaults/index.d.ts +1 -0
- package/build/plugins/d3/renderer/constants/defaults/index.js +1 -0
- package/build/plugins/d3/renderer/constants/defaults/series-options.d.ts +11 -0
- package/build/plugins/d3/renderer/constants/defaults/series-options.js +41 -0
- package/build/plugins/d3/renderer/constants/index.d.ts +0 -1
- package/build/plugins/d3/renderer/constants/index.js +0 -1
- package/build/plugins/d3/renderer/d3-dispatcher.d.ts +1 -0
- package/build/plugins/d3/renderer/d3-dispatcher.js +4 -0
- package/build/plugins/d3/renderer/hooks/index.d.ts +0 -1
- package/build/plugins/d3/renderer/hooks/index.js +0 -1
- package/build/plugins/d3/renderer/hooks/useAxisScales/index.d.ts +6 -5
- package/build/plugins/d3/renderer/hooks/useAxisScales/index.js +2 -1
- package/build/plugins/d3/renderer/hooks/useChartDimensions/index.js +8 -41
- package/build/plugins/d3/renderer/hooks/useChartDimensions/utils.d.ts +3 -0
- package/build/plugins/d3/renderer/hooks/useChartDimensions/utils.js +17 -4
- package/build/plugins/d3/renderer/hooks/useChartOptions/chart.d.ts +2 -4
- package/build/plugins/d3/renderer/hooks/useChartOptions/chart.js +4 -23
- package/build/plugins/d3/renderer/hooks/useChartOptions/index.d.ts +1 -1
- package/build/plugins/d3/renderer/hooks/useChartOptions/index.js +2 -10
- package/build/plugins/d3/renderer/hooks/useChartOptions/title.d.ts +1 -1
- package/build/plugins/d3/renderer/hooks/useChartOptions/title.js +1 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/types.d.ts +8 -5
- package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.d.ts +5 -3
- package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.js +61 -6
- package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.d.ts +1 -1
- package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +20 -12
- package/build/plugins/d3/renderer/hooks/useSeries/index.d.ts +1 -0
- package/build/plugins/d3/renderer/hooks/useSeries/index.js +8 -2
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-legend.js +8 -3
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-options.d.ts +3 -0
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-options.js +5 -0
- package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.js +6 -3
- package/build/plugins/d3/renderer/hooks/useSeries/types.d.ts +5 -1
- package/build/plugins/d3/renderer/hooks/useShapes/bar-x/index.d.ts +12 -0
- package/build/plugins/d3/renderer/hooks/useShapes/bar-x/index.js +91 -0
- package/build/plugins/d3/renderer/hooks/useShapes/bar-x/prepare-data.d.ts +19 -0
- package/build/plugins/d3/renderer/hooks/useShapes/{bar-x.js → bar-x/prepare-data.js} +7 -87
- package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +13 -10
- package/build/plugins/d3/renderer/hooks/useShapes/index.js +28 -13
- package/build/plugins/d3/renderer/hooks/useShapes/pie.d.ts +6 -4
- package/build/plugins/d3/renderer/hooks/useShapes/pie.js +98 -20
- package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.d.ts +15 -0
- package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.js +89 -0
- package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.d.ts +19 -0
- package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.js +55 -0
- package/build/plugins/d3/renderer/hooks/useShapes/styles.css +1 -9
- package/build/plugins/d3/renderer/hooks/useTooltip/index.d.ts +6 -6
- package/build/plugins/d3/renderer/hooks/useTooltip/index.js +15 -17
- package/build/plugins/d3/renderer/hooks/useTooltip/types.d.ts +0 -6
- package/build/plugins/d3/renderer/utils/axis-generators/bottom.d.ts +3 -1
- package/build/plugins/d3/renderer/utils/axis-generators/bottom.js +32 -22
- package/build/plugins/d3/renderer/utils/index.d.ts +5 -0
- package/build/plugins/d3/renderer/utils/index.js +13 -8
- package/build/plugins/d3/renderer/utils/math.d.ts +2 -0
- package/build/plugins/d3/renderer/utils/math.js +8 -0
- package/build/plugins/d3/renderer/utils/text.d.ts +6 -6
- package/build/plugins/d3/renderer/utils/text.js +24 -14
- package/build/types/widget-data/axis.d.ts +10 -0
- package/build/types/widget-data/series.d.ts +51 -0
- package/build/types/widget-data/tooltip.d.ts +18 -7
- package/package.json +2 -2
- package/build/plugins/d3/renderer/hooks/useChartEvents/index.d.ts +0 -5
- package/build/plugins/d3/renderer/hooks/useChartEvents/index.js +0 -15
- package/build/plugins/d3/renderer/hooks/useShapes/bar-x.d.ts +0 -21
- package/build/plugins/d3/renderer/hooks/useShapes/defaults.d.ts +0 -5
- package/build/plugins/d3/renderer/hooks/useShapes/defaults.js +0 -5
- package/build/plugins/d3/renderer/hooks/useShapes/scatter.d.ts +0 -19
- package/build/plugins/d3/renderer/hooks/useShapes/scatter.js +0 -89
|
@@ -8,13 +8,13 @@ export declare function hasOverlappingLabels({ width, labels, padding, style, }:
|
|
|
8
8
|
style?: BaseTextStyle;
|
|
9
9
|
padding?: number;
|
|
10
10
|
}): boolean;
|
|
11
|
-
export declare function getLabelsMaxWidth({ labels, style,
|
|
11
|
+
export declare function getLabelsMaxWidth({ labels, style, rotation, }: {
|
|
12
12
|
labels: string[];
|
|
13
|
-
style?:
|
|
14
|
-
|
|
13
|
+
style?: Record<string, string>;
|
|
14
|
+
rotation?: number;
|
|
15
15
|
}): number;
|
|
16
|
-
export declare function getLabelsMaxHeight({ labels, style,
|
|
16
|
+
export declare function getLabelsMaxHeight({ labels, style, rotation, }: {
|
|
17
17
|
labels: string[];
|
|
18
|
-
style?:
|
|
19
|
-
|
|
18
|
+
style?: Record<string, string>;
|
|
19
|
+
rotation?: number;
|
|
20
20
|
}): number;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { select } from 'd3';
|
|
2
2
|
export function setEllipsisForOverflowText(selection, maxWidth) {
|
|
3
|
-
var _a, _b;
|
|
3
|
+
var _a, _b, _c, _d;
|
|
4
4
|
let text = selection.text();
|
|
5
5
|
selection.text(null).append('title').text(text);
|
|
6
|
-
const tSpan = selection.append('tspan').text(text);
|
|
7
|
-
let textLength = ((_a = tSpan.node()) === null || _a === void 0 ? void 0 : _a.
|
|
6
|
+
const tSpan = selection.append('tspan').text(text).style('alignment-baseline', 'inherit');
|
|
7
|
+
let textLength = ((_b = (_a = tSpan.node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width) || 0;
|
|
8
8
|
while (textLength > maxWidth && text.length > 1) {
|
|
9
9
|
text = text.slice(0, -1);
|
|
10
10
|
tSpan.text(text + '…');
|
|
11
|
-
textLength = ((
|
|
11
|
+
textLength = ((_d = (_c = tSpan.node()) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect()) === null || _d === void 0 ? void 0 : _d.width) || 0;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
export function setEllipsisForOverflowTexts(selection, maxWidth) {
|
|
@@ -29,12 +29,14 @@ export function hasOverlappingLabels({ width, labels, padding = 0, style, }) {
|
|
|
29
29
|
textElement.remove();
|
|
30
30
|
return result;
|
|
31
31
|
}
|
|
32
|
-
function renderLabels(selection, { labels, style,
|
|
33
|
-
const text = selection
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
function renderLabels(selection, { labels, style = {}, attrs = {}, }) {
|
|
33
|
+
const text = selection.append('g').append('text');
|
|
34
|
+
Object.entries(style).forEach(([name, value]) => {
|
|
35
|
+
text.style(name, value);
|
|
36
|
+
});
|
|
37
|
+
Object.entries(attrs).forEach(([name, value]) => {
|
|
38
|
+
text.attr(name, value);
|
|
39
|
+
});
|
|
38
40
|
text.selectAll('tspan')
|
|
39
41
|
.data(labels)
|
|
40
42
|
.enter()
|
|
@@ -44,18 +46,26 @@ function renderLabels(selection, { labels, style, transform, }) {
|
|
|
44
46
|
.text((d) => d);
|
|
45
47
|
return text;
|
|
46
48
|
}
|
|
47
|
-
export function getLabelsMaxWidth({ labels, style,
|
|
49
|
+
export function getLabelsMaxWidth({ labels, style, rotation, }) {
|
|
48
50
|
var _a, _b;
|
|
49
51
|
const svg = select(document.body).append('svg');
|
|
50
|
-
svg
|
|
52
|
+
const textSelection = renderLabels(svg, { labels, style });
|
|
53
|
+
if (rotation) {
|
|
54
|
+
textSelection.attr('text-anchor', 'end').style('transform', `rotate(${rotation}deg)`);
|
|
55
|
+
}
|
|
51
56
|
const maxWidth = ((_b = (_a = svg.select('g').node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width) || 0;
|
|
52
57
|
svg.remove();
|
|
53
58
|
return maxWidth;
|
|
54
59
|
}
|
|
55
|
-
export function getLabelsMaxHeight({ labels, style,
|
|
60
|
+
export function getLabelsMaxHeight({ labels, style, rotation, }) {
|
|
56
61
|
var _a, _b;
|
|
57
62
|
const svg = select(document.body).append('svg');
|
|
58
|
-
svg
|
|
63
|
+
const textSelection = renderLabels(svg, { labels, style });
|
|
64
|
+
if (rotation) {
|
|
65
|
+
textSelection
|
|
66
|
+
.attr('text-anchor', rotation > 0 ? 'start' : 'end')
|
|
67
|
+
.style('transform', `rotate(${rotation}deg)`);
|
|
68
|
+
}
|
|
59
69
|
const maxHeight = ((_b = (_a = svg.select('g').node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.height) || 0;
|
|
60
70
|
svg.remove();
|
|
61
71
|
return maxHeight;
|
|
@@ -21,6 +21,11 @@ export type ChartKitWidgetAxisLabels = {
|
|
|
21
21
|
* If there is enough space, labels are not rotated.
|
|
22
22
|
* As the chart gets narrower, it will start rotating the labels -45 degrees. */
|
|
23
23
|
autoRotation?: boolean;
|
|
24
|
+
/** Rotation of the labels in degrees.
|
|
25
|
+
*
|
|
26
|
+
* @default: 0
|
|
27
|
+
*/
|
|
28
|
+
rotation?: number;
|
|
24
29
|
};
|
|
25
30
|
export type ChartKitWidgetAxis = {
|
|
26
31
|
categories?: string[];
|
|
@@ -32,6 +37,11 @@ export type ChartKitWidgetAxis = {
|
|
|
32
37
|
lineColor?: string;
|
|
33
38
|
title?: {
|
|
34
39
|
text?: string;
|
|
40
|
+
/** The pixel distance between the axis labels or line and the title.
|
|
41
|
+
*
|
|
42
|
+
* Defaults to 4 for horizontal axes, 8 for vertical.
|
|
43
|
+
* */
|
|
44
|
+
margin?: number;
|
|
35
45
|
};
|
|
36
46
|
/** The minimum value of the axis. If undefined the min value is automatically calculate. */
|
|
37
47
|
min?: number;
|
|
@@ -7,6 +7,37 @@ export type ChartKitWidgetSeriesData<T = any> = ScatterSeriesData<T> | PieSeries
|
|
|
7
7
|
export type DataLabelRendererData<T = any> = {
|
|
8
8
|
data: ChartKitWidgetSeriesData<T>;
|
|
9
9
|
};
|
|
10
|
+
type BasicHoverState = {
|
|
11
|
+
/**
|
|
12
|
+
* Enable separate styles for the hovered series.
|
|
13
|
+
*
|
|
14
|
+
* @default true
|
|
15
|
+
* */
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* How much to brighten/darken the point on hover. Use positive to brighten, negative to darken.
|
|
19
|
+
* The behavior of this property is dependent on the implementing color space ([more details](https://d3js.org/d3-color#color_brighter)).
|
|
20
|
+
* For example in case of using rgb color you can use floating point number from `-5.0` to `5.0`.
|
|
21
|
+
* Rgb color space is used by default.
|
|
22
|
+
*
|
|
23
|
+
* @default 0.3
|
|
24
|
+
*/
|
|
25
|
+
brightness?: number;
|
|
26
|
+
};
|
|
27
|
+
type BasicInactiveState = {
|
|
28
|
+
/**
|
|
29
|
+
* Enable separate styles for the inactive series.
|
|
30
|
+
*
|
|
31
|
+
* @default true
|
|
32
|
+
* */
|
|
33
|
+
enabled?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Opacity of series elements (bars, data labels)
|
|
36
|
+
*
|
|
37
|
+
* @default 0.5
|
|
38
|
+
* */
|
|
39
|
+
opacity?: number;
|
|
40
|
+
};
|
|
10
41
|
export type ChartKitWidgetSeriesOptions = {
|
|
11
42
|
/** Individual data label for each point. */
|
|
12
43
|
dataLabels?: {
|
|
@@ -45,5 +76,25 @@ export type ChartKitWidgetSeriesOptions = {
|
|
|
45
76
|
* */
|
|
46
77
|
direction?: 'asc' | 'desc';
|
|
47
78
|
};
|
|
79
|
+
/** Options for the series states that provide additional styling information to the series. */
|
|
80
|
+
states?: {
|
|
81
|
+
hover?: BasicHoverState;
|
|
82
|
+
inactive?: BasicInactiveState;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
pie?: {
|
|
86
|
+
/** Options for the series states that provide additional styling information to the series. */
|
|
87
|
+
states?: {
|
|
88
|
+
hover?: BasicHoverState;
|
|
89
|
+
inactive?: BasicInactiveState;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
scatter?: {
|
|
93
|
+
/** Options for the series states that provide additional styling information to the series. */
|
|
94
|
+
states?: {
|
|
95
|
+
hover?: BasicHoverState;
|
|
96
|
+
inactive?: BasicInactiveState;
|
|
97
|
+
};
|
|
48
98
|
};
|
|
49
99
|
};
|
|
100
|
+
export {};
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import type { BarXSeries, BarXSeriesData } from './bar-x';
|
|
3
|
+
import type { PieSeries, PieSeriesData } from './pie';
|
|
4
|
+
import type { ScatterSeries, ScatterSeriesData } from './scatter';
|
|
5
|
+
export type TooltipDataChunkBarX<T = any> = {
|
|
6
|
+
data: BarXSeriesData<T>;
|
|
7
|
+
series: BarXSeries<T>;
|
|
6
8
|
};
|
|
9
|
+
export type TooltipDataChunkPie<T = any> = {
|
|
10
|
+
data: PieSeriesData<T>;
|
|
11
|
+
series: Omit<PieSeries<T>, 'data'>;
|
|
12
|
+
};
|
|
13
|
+
export type TooltipDataChunkScatter<T = any> = {
|
|
14
|
+
data: ScatterSeriesData<T>;
|
|
15
|
+
series: ScatterSeries<T>;
|
|
16
|
+
};
|
|
17
|
+
export type TooltipDataChunk<T = any> = TooltipDataChunkBarX<T> | TooltipDataChunkPie<T> | TooltipDataChunkScatter<T>;
|
|
7
18
|
export type ChartKitWidgetTooltip<T = any> = {
|
|
8
19
|
enabled?: boolean;
|
|
9
20
|
/** Specifies the renderer for the tooltip. If returned null default tooltip renderer will be used. */
|
|
10
|
-
renderer?: (
|
|
11
|
-
hovered:
|
|
12
|
-
}) => React.ReactElement;
|
|
21
|
+
renderer?: (args: {
|
|
22
|
+
hovered: TooltipDataChunk<T>[];
|
|
23
|
+
}) => React.ReactElement | null;
|
|
13
24
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/chartkit",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "React component used to render charts based on any sources you need",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "git@github.com:gravity-ui/ChartKit.git",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@bem-react/classname": "^1.6.0",
|
|
50
50
|
"@gravity-ui/date-utils": "^1.4.1",
|
|
51
|
-
"@gravity-ui/yagr": "^3.
|
|
51
|
+
"@gravity-ui/yagr": "^3.10.0",
|
|
52
52
|
"d3": "^7.8.5",
|
|
53
53
|
"lodash": "^4.17.21",
|
|
54
54
|
"react-split-pane": "^0.1.92"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export const useChartEvents = () => {
|
|
3
|
-
const [chartHovered, setChartHovered] = React.useState(false);
|
|
4
|
-
const handleMouseEnter = React.useCallback(() => {
|
|
5
|
-
setChartHovered(true);
|
|
6
|
-
}, []);
|
|
7
|
-
const handleMouseLeave = React.useCallback(() => {
|
|
8
|
-
setChartHovered(false);
|
|
9
|
-
}, []);
|
|
10
|
-
return {
|
|
11
|
-
chartHovered,
|
|
12
|
-
handleMouseEnter,
|
|
13
|
-
handleMouseLeave,
|
|
14
|
-
};
|
|
15
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { ChartKitWidgetSeriesOptions } from '../../../../../types';
|
|
3
|
-
import type { ChartScale } from '../useAxisScales';
|
|
4
|
-
import type { ChartOptions } from '../useChartOptions/types';
|
|
5
|
-
import type { OnSeriesMouseLeave, OnSeriesMouseMove } from '../useTooltip/types';
|
|
6
|
-
import type { PreparedBarXSeries } from '../useSeries/types';
|
|
7
|
-
type Args = {
|
|
8
|
-
top: number;
|
|
9
|
-
left: number;
|
|
10
|
-
series: PreparedBarXSeries[];
|
|
11
|
-
seriesOptions?: ChartKitWidgetSeriesOptions;
|
|
12
|
-
xAxis: ChartOptions['xAxis'];
|
|
13
|
-
xScale: ChartScale;
|
|
14
|
-
yAxis: ChartOptions['yAxis'];
|
|
15
|
-
yScale: ChartScale;
|
|
16
|
-
onSeriesMouseMove?: OnSeriesMouseMove;
|
|
17
|
-
onSeriesMouseLeave?: OnSeriesMouseLeave;
|
|
18
|
-
svgContainer: SVGSVGElement | null;
|
|
19
|
-
};
|
|
20
|
-
export declare function BarXSeriesShapes(args: Args): React.JSX.Element;
|
|
21
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { ScatterSeries } from '../../../../../types/widget-data';
|
|
3
|
-
import type { ChartScale } from '../useAxisScales';
|
|
4
|
-
import type { PreparedAxis } from '../useChartOptions/types';
|
|
5
|
-
import type { OnSeriesMouseLeave, OnSeriesMouseMove } from '../useTooltip/types';
|
|
6
|
-
type ScatterSeriesShapeProps = {
|
|
7
|
-
top: number;
|
|
8
|
-
left: number;
|
|
9
|
-
series: ScatterSeries;
|
|
10
|
-
xAxis: PreparedAxis;
|
|
11
|
-
xScale: ChartScale;
|
|
12
|
-
yAxis: PreparedAxis[];
|
|
13
|
-
yScale: ChartScale;
|
|
14
|
-
svgContainer: SVGSVGElement | null;
|
|
15
|
-
onSeriesMouseMove?: OnSeriesMouseMove;
|
|
16
|
-
onSeriesMouseLeave?: OnSeriesMouseLeave;
|
|
17
|
-
};
|
|
18
|
-
export declare function ScatterSeriesShape(props: ScatterSeriesShapeProps): React.JSX.Element;
|
|
19
|
-
export {};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { pointer, select } from 'd3';
|
|
3
|
-
import get from 'lodash/get';
|
|
4
|
-
import { block } from '../../../../../utils/cn';
|
|
5
|
-
import { getDataCategoryValue } from '../../utils';
|
|
6
|
-
const b = block('d3-scatter');
|
|
7
|
-
const DEFAULT_SCATTER_POINT_RADIUS = 4;
|
|
8
|
-
const prepareLinearScatterData = (data) => {
|
|
9
|
-
return data.filter((d) => typeof d.x === 'number' && typeof d.y === 'number');
|
|
10
|
-
};
|
|
11
|
-
const getCxAttr = (args) => {
|
|
12
|
-
const { point, xAxis, xScale } = args;
|
|
13
|
-
let cx;
|
|
14
|
-
if (xAxis.type === 'category') {
|
|
15
|
-
const xBandScale = xScale;
|
|
16
|
-
const categories = get(xAxis, 'categories', []);
|
|
17
|
-
const dataCategory = getDataCategoryValue({ axisDirection: 'x', categories, data: point });
|
|
18
|
-
cx = (xBandScale(dataCategory) || 0) + xBandScale.step() / 2;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
const xLinearScale = xScale;
|
|
22
|
-
cx = xLinearScale(point.x);
|
|
23
|
-
}
|
|
24
|
-
return cx;
|
|
25
|
-
};
|
|
26
|
-
const getCyAttr = (args) => {
|
|
27
|
-
const { point, yAxis, yScale } = args;
|
|
28
|
-
let cy;
|
|
29
|
-
if (yAxis.type === 'category') {
|
|
30
|
-
const yBandScale = yScale;
|
|
31
|
-
const categories = get(yAxis, 'categories', []);
|
|
32
|
-
const dataCategory = getDataCategoryValue({ axisDirection: 'y', categories, data: point });
|
|
33
|
-
cy = (yBandScale(dataCategory) || 0) + yBandScale.step() / 2;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const yLinearScale = yScale;
|
|
37
|
-
cy = yLinearScale(point.y);
|
|
38
|
-
}
|
|
39
|
-
return cy;
|
|
40
|
-
};
|
|
41
|
-
export function ScatterSeriesShape(props) {
|
|
42
|
-
const { series, xAxis, xScale, yAxis, yScale, svgContainer, left, top, onSeriesMouseMove, onSeriesMouseLeave, } = props;
|
|
43
|
-
const ref = React.useRef(null);
|
|
44
|
-
React.useEffect(() => {
|
|
45
|
-
var _a;
|
|
46
|
-
if (!ref.current) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const svgElement = select(ref.current);
|
|
50
|
-
const preparedData = xAxis.type === 'category' || ((_a = yAxis[0]) === null || _a === void 0 ? void 0 : _a.type) === 'category'
|
|
51
|
-
? series.data
|
|
52
|
-
: prepareLinearScatterData(series.data);
|
|
53
|
-
svgElement
|
|
54
|
-
.selectAll('circle')
|
|
55
|
-
.data(preparedData)
|
|
56
|
-
.join((enter) => enter.append('circle').attr('class', b('point')), (update) => update, (exit) => exit.remove())
|
|
57
|
-
.attr('fill', (d) => d.color || series.color || '')
|
|
58
|
-
.attr('r', (d) => d.radius || DEFAULT_SCATTER_POINT_RADIUS)
|
|
59
|
-
.attr('cx', (d) => getCxAttr({ point: d, xAxis, xScale }))
|
|
60
|
-
.attr('cy', (d) => getCyAttr({ point: d, yAxis: yAxis[0], yScale }))
|
|
61
|
-
.on('mousemove', (e, d) => {
|
|
62
|
-
const [x, y] = pointer(e, svgContainer);
|
|
63
|
-
onSeriesMouseMove === null || onSeriesMouseMove === void 0 ? void 0 : onSeriesMouseMove({
|
|
64
|
-
hovered: {
|
|
65
|
-
data: d,
|
|
66
|
-
series,
|
|
67
|
-
},
|
|
68
|
-
pointerPosition: [x - left, y - top],
|
|
69
|
-
});
|
|
70
|
-
})
|
|
71
|
-
.on('mouseleave', () => {
|
|
72
|
-
if (onSeriesMouseLeave) {
|
|
73
|
-
onSeriesMouseLeave();
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}, [
|
|
77
|
-
series,
|
|
78
|
-
xAxis,
|
|
79
|
-
xScale,
|
|
80
|
-
yAxis,
|
|
81
|
-
yScale,
|
|
82
|
-
svgContainer,
|
|
83
|
-
left,
|
|
84
|
-
top,
|
|
85
|
-
onSeriesMouseMove,
|
|
86
|
-
onSeriesMouseLeave,
|
|
87
|
-
]);
|
|
88
|
-
return React.createElement("g", { ref: ref, className: b() });
|
|
89
|
-
}
|