From fc178e55d95844d18a92d11b8040e46ab96ef008 Mon Sep 17 00:00:00 2001
From: niko <644506165@qq.com>
Date: Sun, 25 Mar 2018 02:09:56 +0800
Subject: [PATCH] Fixed: #1142 (#1160)
* fixed: #1142
* fix typo
* fix typo
* fix typo
* add missing fix
---
src/components/Charts/ChartCard/index.d.ts | 2 +-
src/components/Charts/ChartCard/index.js | 59 +++++++++++----------
src/components/Charts/Pie/index.d.ts | 4 +-
src/components/Charts/Pie/index.js | 11 ++--
src/components/Charts/demo/chart-card.md | 60 ++++++++++++++++------
src/components/Charts/demo/mix.md | 1 +
src/components/Charts/demo/pie.md | 19 ++++---
src/components/Charts/index.md | 4 +-
src/routes/Dashboard/Analysis.js | 12 +++--
9 files changed, 106 insertions(+), 66 deletions(-)
diff --git a/src/components/Charts/ChartCard/index.d.ts b/src/components/Charts/ChartCard/index.d.ts
index 76470460..ad450dfa 100644
--- a/src/components/Charts/ChartCard/index.d.ts
+++ b/src/components/Charts/ChartCard/index.d.ts
@@ -2,7 +2,7 @@ import * as React from "react";
export interface IChartCardProps {
title: React.ReactNode;
action?: React.ReactNode;
- total?: React.ReactNode | number;
+ total?: React.ReactNode | function | number;
footer?: React.ReactNode;
contentHeight?: number;
avatar?: React.ReactNode;
diff --git a/src/components/Charts/ChartCard/index.js b/src/components/Charts/ChartCard/index.js
index 2fd10e6f..035b3131 100644
--- a/src/components/Charts/ChartCard/index.js
+++ b/src/components/Charts/ChartCard/index.js
@@ -10,8 +10,8 @@ const renderTotal = (total) => {
case undefined:
totalDom = null;
break;
- case 'string':
- totalDom =
;
+ case 'function':
+ totalDom = {total()}
;
break;
default:
totalDom = {total}
;
@@ -20,18 +20,22 @@ const renderTotal = (total) => {
};
const ChartCard = ({
- loading = false, contentHeight, title, avatar, action, total, footer, children, ...rest
+ loading = false,
+ contentHeight,
+ title,
+ avatar,
+ action,
+ total,
+ footer,
+ children,
+ ...rest
}) => {
const content = (
-
- {
- avatar
- }
-
+
{avatar}
{title}
@@ -40,31 +44,26 @@ const ChartCard = ({
{renderTotal(total)}
- {
- children && (
-
- )
- }
- {
- footer && (
-
- {footer}
-
- )
- }
+ {children && (
+
+ )}
+ {footer && (
+
+ {footer}
+
+ )}
);
return (
-
- {{content}}
+
+ {
+
+ {content}
+
+ }
);
};
diff --git a/src/components/Charts/Pie/index.d.ts b/src/components/Charts/Pie/index.d.ts
index e9dcd1d4..5b19208d 100644
--- a/src/components/Charts/Pie/index.d.ts
+++ b/src/components/Charts/Pie/index.d.ts
@@ -10,10 +10,10 @@ export interface IPieProps {
x: string | string;
y: number;
}>;
- total?: string;
+ total?: string | function;
title?: React.ReactNode;
tooltip?: boolean;
- valueFormat?: (value: string) => string;
+ valueFormat?: (value: string) => string | React.ReactNode;
subTitle?: React.ReactNode;
}
diff --git a/src/components/Charts/Pie/index.js b/src/components/Charts/Pie/index.js
index 528b2519..2784ad60 100644
--- a/src/components/Charts/Pie/index.js
+++ b/src/components/Charts/Pie/index.js
@@ -221,7 +221,9 @@ export default class Pie extends Component {
{subTitle &&
{subTitle}
}
{/* eslint-disable-next-line */}
- {total &&
}
+ {total && (
+
{typeof total === 'function' ? total() : total}
+ )}
)}
@@ -240,12 +242,7 @@ export default class Pie extends Component {
{`${(isNaN(item.percent) ? 0 : item.percent * 100).toFixed(2)}%`}
-
+ {valueFormat ? valueFormat(item.y) : item.y}
))}
diff --git a/src/components/Charts/demo/chart-card.md b/src/components/Charts/demo/chart-card.md
index 51204793..4da852b7 100644
--- a/src/components/Charts/demo/chart-card.md
+++ b/src/components/Charts/demo/chart-card.md
@@ -5,7 +5,7 @@ title: 图表卡片
用于展示图表的卡片容器,可以方便的配合其它图表套件展示丰富信息。
-````jsx
+```jsx
import { ChartCard, yuan, Field } from 'ant-design-pro/lib/Charts';
import Trend from 'ant-design-pro/lib/Trend';
import { Row, Col, Icon, Tooltip } from 'antd';
@@ -16,18 +16,33 @@ ReactDOM.render(
}
- total={yuan(126560)}
- footer={}
+ action={
+
+
+
+ }
+ total={() => (
+
+ )}
+ footer={
+
+ }
contentHeight={46}
>
周同比
- 12%
+
+ 12%
+
日环比
- 11%
+
+ 11%
+
@@ -41,25 +56,40 @@ ReactDOM.render(
alt="indicator"
/>
}
- action={}
- total={yuan(126560)}
- footer={}
+ action={
+
+
+
+ }
+ total={() => (
+
+ )}
+ footer={
+
+ }
/>
+ }
+ action={
+
+
+
+ }
+ total={() => (
+
)}
- action={}
- total={yuan(126560)}
/>
-
-, mountNode);
-````
+ ,
+ mountNode,
+);
+```
diff --git a/src/components/Charts/demo/mix.md b/src/components/Charts/demo/mix.md
index 0c158e5f..fc64110a 100644
--- a/src/components/Charts/demo/mix.md
+++ b/src/components/Charts/demo/mix.md
@@ -27,6 +27,7 @@ ReactDOM.render(
now.y + pre, 0))}
+ total={() => (
+ now.y + pre, 0))
+ }}
+ />
+ )}
data={salesPieData}
- valueFormat={val => yuan(val)}
+ valueFormat={val => }
height={294}
- />
-, mountNode);
-````
+ />,
+ mountNode,
+);
+```
diff --git a/src/components/Charts/index.md b/src/components/Charts/index.md
index e48220e5..e292a247 100644
--- a/src/components/Charts/index.md
+++ b/src/components/Charts/index.md
@@ -19,7 +19,7 @@ Ant Design Pro 提供的业务中常用的图表类型,都是基于 [G2](https
|----------|------------------------------------------|-------------|-------|
| title | 卡片标题 | ReactNode\|string | - |
| action | 卡片操作 | ReactNode | - |
-| total | 数据总量 | ReactNode \| number | - |
+| total | 数据总量 | ReactNode \| number \| function | - |
| footer | 卡片底部 | ReactNode | - |
| contentHeight | 内容区域高度 | number | - |
| avatar | 右侧图标 | React.ReactNode | - |
@@ -78,7 +78,7 @@ Ant Design Pro 提供的业务中常用的图表类型,都是基于 [G2](https
| valueFormat | 显示值的格式化函数 | function | - |
| title | 图表标题 | ReactNode\|string | - |
| subTitle | 图表子标题 | ReactNode\|string | - |
-| total | 图标中央的总数 | string | - |
+| total | 图标中央的总数 | string | function | - |
### Radar
diff --git a/src/routes/Dashboard/Analysis.js b/src/routes/Dashboard/Analysis.js
index 9cb55a9a..b7582b03 100644
--- a/src/routes/Dashboard/Analysis.js
+++ b/src/routes/Dashboard/Analysis.js
@@ -252,7 +252,7 @@ export default class Analysis extends Component {
}
- total={yuan(126560)}
+ total={() => }
footer={}
contentHeight={46}
>
@@ -451,9 +451,15 @@ export default class Analysis extends Component {
now.y + pre, 0))}
+ total={() => (
+ now.y + pre, 0)),
+ }}
+ />
+ )}
data={salesPieData}
- valueFormat={val => yuan(val)}
+ valueFormat={val => }
height={248}
lineWidth={4}
/>
--
GitLab