Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dount add pielabel #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/Donut/components/PieLabel/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { FC } from 'react';
import {
Chart,
Geometry,
Tooltip,
Legend,
Coordinate,
// Axis,
Guide,
px2hd,
PieLabel,
F2,
} from '@alitajs/f2';

const TableLegend: FC<any> = props => {
const { x, y, total } = props;
return (
<PieLabel
{...props}
inflectionOffset={20}
sidePadding={15}
label1={function label1(data) {
const text = !isNaN(Number(data[x]))
? `${data[x]}/${((parseInt(data[x], 10) / total) * 100).toFixed(0)}%`
: data[x];
return {
text,
fill: '#808080',
fontSize: px2hd(22),
};
}}
label2={function label2(data) {
const text = !isNaN(Number(data[y]))
? `${data[y]}/${((parseInt(data[y], 10) / total) * 100).toFixed(0)}%`
: data[y];
return {
fill: '#000000',
text,
fontWeight: px2hd(500),
fontSize: px2hd(20),
};
}}
/>
);
};

export default TableLegend;
1 change: 1 addition & 0 deletions src/Donut/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as RightLegend } from './RightLegend';
export { default as TableLegend } from './TableLegend';
export { default as CustomTableLegend } from './CustomTableLegend';
export { default as CustomLegend } from './CustomLegend';
export { default as PieLabel } from './PieLabel';
30 changes: 28 additions & 2 deletions src/Donut/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
RightLegend,
CustomTableLegend,
CustomLegend,
PieLabel,
} from './components';
import { CustomLegendProps } from './components/CustomLegend';
import './index.less';
Expand Down Expand Up @@ -73,7 +74,8 @@ export interface DountProps {
| 'singleLeg'
| 'customTable'
| 'custom'
| 'progress';
| 'progress'
| 'pieLabel';
/**
* 对数据进行单属性过滤,比如展示数值加上单位
*/
Expand Down Expand Up @@ -170,7 +172,7 @@ export interface DountProps {
interface TableLegendProps
extends Omit<
DountProps,
'type' | 'title' | 'colDefs' | 'sumText' | 'sumTitle'
'type' | 'title' | 'colDefs' | 'sumText' | 'sumTitle' | 'pieLabel'
> {
chart?: ChartProps;
total: number;
Expand Down Expand Up @@ -301,6 +303,7 @@ const Donut: React.FC<DountProps> = props => {
const isCustomTableLegend = type === 'customTable';
const isCustomLegend = type === 'custom';
const isProgressLegend = type === 'progress';
const isPieLabel = type === 'pieLabel';

if (!data) {
return <p>data is undefined!</p>;
Expand Down Expand Up @@ -503,6 +506,29 @@ const Donut: React.FC<DountProps> = props => {
renderLegend={renderLegend}
/>
)}
{isPieLabel && (
<PieLabel
{...props}
total={total}
sidePadding={40}
label1={function label1(data) {
return {
text: data[x],
fill: '#808080',
fontWeight: px2hd(700),
fontSize: px2hd(24),
};
}}
label2={function label2(data) {
return {
fill: '#000000',
text: data[y]?.toFixed(2),
fontWeight: px2hd(700),
fontSize: px2hd(24),
};
}}
/>
)}
</Chart>
</div>
);
Expand Down