Skip to content

Commit b419d8c

Browse files
wangyuhuwangxingkang
authored andcommitted
feat: 漏斗图
1 parent 5abbe73 commit b419d8c

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { StyleConfig } from './types';
2+
3+
export const DEFAULT_STYLE_CONFIG: StyleConfig = {
4+
// TODO: 黑色主题的颜色配置
5+
stroke: 'white',
6+
lineWidth: 2,
7+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { forwardRef } from 'react';
2+
import { Funnel as AntFunnel } from '@ant-design/plots';
3+
import type { Chart } from '@ant-design/plots/es/interface';
4+
import { Renderer as SVGRenderer } from '@antv/g-svg';
5+
import type { FunnelConfig as AntFunnelConfig } from '@ant-design/plots';
6+
import { getItemConfig } from '../../helpers/utils';
7+
import { DEFAULT_INSET_LEFT, DEFAULT_INSET_RIGHT } from '../../config';
8+
import { DEFAULT_STYLE_CONFIG } from './config';
9+
import type { StyleConfig } from './types';
10+
11+
export interface FunnelConfig extends Omit<AntFunnelConfig, 'style'> {
12+
style?: AntFunnelConfig['style'] | boolean;
13+
}
14+
15+
export const Funnel = forwardRef<Chart, FunnelConfig>(
16+
(props, ref) => {
17+
const {
18+
insetLeft = DEFAULT_INSET_LEFT,
19+
insetRight = DEFAULT_INSET_RIGHT,
20+
label = false,
21+
style = true,
22+
...rest
23+
} = props;
24+
25+
const styleConfig = getItemConfig<StyleConfig>(style, DEFAULT_STYLE_CONFIG);
26+
27+
return (
28+
<AntFunnel
29+
insetLeft={insetLeft}
30+
insetRight={insetRight}
31+
label={label}
32+
style={styleConfig}
33+
{...rest}
34+
ref={ref}
35+
renderer={new SVGRenderer()}
36+
/>
37+
);
38+
},
39+
);
40+
41+
export default Funnel;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { FunnelConfig } from '@ant-design/plots';
2+
3+
export type StyleConfig = NonNullable<FunnelConfig['style']>;

@sensoro-design/plots/src/components/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ export type { RadarConfig } from './Radar';
2424

2525
export { Rose } from './Rose';
2626
export type { RoseConfig } from './Rose';
27+
28+
export { Funnel } from './Funnel';
29+
export type { FunnelConfig } from './Funnel';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import { Funnel, type FunnelConfig } from '@sensoro-design/plots';
3+
4+
const data = [
5+
{ stage: '简历筛选', number: 253 },
6+
{ stage: '初试人数', number: 151 },
7+
{ stage: '复试人数', number: 113 },
8+
{ stage: '录取人数', number: 87 },
9+
{ stage: '入职人数', number: 59 },
10+
];
11+
12+
const meta = {
13+
title: 'Charts/Funnel',
14+
};
15+
16+
export default meta;
17+
18+
export function Basic() {
19+
const config: FunnelConfig = {
20+
title: '漏斗图',
21+
data,
22+
xField: 'stage',
23+
yField: 'number',
24+
width: 500,
25+
};
26+
27+
return (
28+
<Funnel {...config} />
29+
);
30+
}

0 commit comments

Comments
 (0)