|
|
@@ -2,50 +2,157 @@
|
|
|
* 总体统计图
|
|
|
*/
|
|
|
import React from 'react'
|
|
|
+import { message } from 'antd'
|
|
|
import EmptyContent from '../../common/emptyContent/index'
|
|
|
import './aggregateTableView.less'
|
|
|
-
|
|
|
class AggregateTableView extends React.Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
this.state = {}
|
|
|
}
|
|
|
|
|
|
- getTableHeader = () => {
|
|
|
+ getTableBody = () => {
|
|
|
const { chartOption } = this.props;
|
|
|
- const { statistics, direction } = chartOption;
|
|
|
- return <thead>
|
|
|
+ const { group1Name, group2Name } = chartOption;
|
|
|
+
|
|
|
+ try{
|
|
|
+ if(!!group1Name) {
|
|
|
+ if(!!group2Name) {
|
|
|
+ return this.createTableBodyInTwoGroups(chartOption);
|
|
|
+ }else {
|
|
|
+ return this.createTableBodyInOneGroups(chartOption);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return this.createTableBodyInNoGroups(chartOption);
|
|
|
+ }
|
|
|
+ }catch(e) {
|
|
|
+ console.error(e.message);
|
|
|
+ message.error('总体统计图渲染错误');
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 无分组
|
|
|
+ createTableBodyInNoGroups = (chartOption) => {
|
|
|
+ const { targetColumn, direction, group1Name, group2Name, group1s, group2s, statistics, data } = chartOption;
|
|
|
+ if(direction === 'vertical') {
|
|
|
+ return <tbody>
|
|
|
+ <tr>
|
|
|
+ <th rowSpan={`${statistics.length + 1}`}>{targetColumn.label}</th>
|
|
|
+ </tr>
|
|
|
+ {
|
|
|
+ statistics.map((s, i) => <tr key={i}>
|
|
|
+ <td>{s.label}</td>
|
|
|
+ <td>{data[s.name]}</td>
|
|
|
+ </tr>)
|
|
|
+ }
|
|
|
+ </tbody>
|
|
|
+ }
|
|
|
+ return <tbody>
|
|
|
+ <tr>
|
|
|
+ <th colSpan={`${statistics.length}`}>{targetColumn.label}</th>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ { statistics.map((s, i) => <td key={i}>{s.label}</td>) }
|
|
|
+ </tr>
|
|
|
<tr>
|
|
|
- <th colSpan={direction === 'vertical' ? '2' : statistics.length + ''} style={{ textAlign: 'center' }}>{chartOption.targetColumn.label}</th>
|
|
|
+ { statistics.map((s, i) => <td key={i}>{data[s.name]}</td>) }
|
|
|
</tr>
|
|
|
- </thead>
|
|
|
+ </tbody>;
|
|
|
}
|
|
|
- getTableBody = () => {
|
|
|
- const { chartOption } = this.props;
|
|
|
- const { statistics, direction } = chartOption;
|
|
|
+
|
|
|
+ // 有一个分组
|
|
|
+ createTableBodyInOneGroups = (chartOption) => {
|
|
|
+ const { targetColumn, direction, group1Name, group2Name, group1s, group2s, statistics, data } = chartOption;
|
|
|
if(direction === 'vertical') {
|
|
|
return <tbody>
|
|
|
- {statistics.map((s, i) => (
|
|
|
- <tr key={i}>
|
|
|
+ <tr>
|
|
|
+ <td colSpan="2"></td>
|
|
|
+ { group1s.map((g, i) => <td key={i}>{g}</td>) }
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th rowSpan={`${statistics.length + 1}`}>{targetColumn.label}</th>
|
|
|
+ </tr>
|
|
|
+ {
|
|
|
+ statistics.map((s, si) => <tr key={si}>
|
|
|
<td>{s.label}</td>
|
|
|
- <td>{Number(Number(s.value).toFixed(4))}</td>
|
|
|
- </tr>
|
|
|
- ))}
|
|
|
+ { group1s.map((g1, gi) => <td key={gi}>{data[gi][s.name]}</td>) }
|
|
|
+ </tr>)
|
|
|
+ }
|
|
|
</tbody>
|
|
|
- }else {
|
|
|
+ }
|
|
|
+ return <tbody>
|
|
|
+ <tr>
|
|
|
+ <th colSpan={`${statistics.length + 1}`}>{targetColumn.label}</th>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td></td>
|
|
|
+ {
|
|
|
+ statistics.map((s, i) => <td key={i}>{s.label}</td>)
|
|
|
+ }
|
|
|
+ </tr>
|
|
|
+ {
|
|
|
+ group1s.map((g, gi) => <tr key={gi}>
|
|
|
+ <td>{g}</td>
|
|
|
+ {
|
|
|
+ statistics.map((s, si) => <td key={si}>{data[gi][s.name]}</td>)
|
|
|
+ }
|
|
|
+ </tr>)
|
|
|
+ }
|
|
|
+ </tbody>
|
|
|
+ }
|
|
|
+
|
|
|
+ // 有两个分组
|
|
|
+ createTableBodyInTwoGroups = (chartOption) => {
|
|
|
+ const { targetColumn, direction, group1Name, group2Name, group1s, group2s, statistics, data } = chartOption;
|
|
|
+ if(direction === 'vertical') {
|
|
|
return <tbody>
|
|
|
<tr>
|
|
|
- {statistics.map((s, i) => (
|
|
|
- <td key={i}>{s.label}</td>
|
|
|
- ))}
|
|
|
+ <td colSpan="3"></td>
|
|
|
+ {group1s.map((g, i) => <td key={i}>{g}</td>)}
|
|
|
</tr>
|
|
|
<tr>
|
|
|
- {statistics.map((s, i) => (
|
|
|
- <td key={i}>{Number(Number(s.value).toFixed(4))}</td>
|
|
|
- ))}
|
|
|
+ <th rowSpan={`${group2s.length * statistics.length + 1}`}>{targetColumn.label}</th>
|
|
|
</tr>
|
|
|
+ {
|
|
|
+ group2s.map((g2, idx2) => {
|
|
|
+ return statistics.map((s, i) => <tr key={i}>
|
|
|
+ { i === 0 && <td rowSpan={`${statistics.length}`}>{g2}</td>}
|
|
|
+ <td>{s.label}</td>
|
|
|
+ {group1s.map((g1, idx1) => {
|
|
|
+ let values = data[idx1].data[idx2];
|
|
|
+ return <td key={idx1}>{values[s.name]}</td>
|
|
|
+ })}
|
|
|
+ </tr>)
|
|
|
+ })
|
|
|
+ }
|
|
|
</tbody>
|
|
|
}
|
|
|
+ return <tbody>
|
|
|
+ <tr>
|
|
|
+ <th colSpan={direction === 'vertical' ? group1s.length + 3 : statistics.length * group2s.length + 1}>{targetColumn.label}</th>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td rowSpan={2}></td>
|
|
|
+ { group2s.map((g, i) => <td colSpan={statistics.length} key={i}>{g}</td>) }
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ { group2s.map((g, i) => statistics.map(s => <td key={i}>{s.label}</td>)) }
|
|
|
+ </tr>
|
|
|
+ {
|
|
|
+ data.map((d1, d1i) => {
|
|
|
+ let data2 = d1.data;
|
|
|
+ return <tr key={d1i}>
|
|
|
+ <td>{ d1[group1Name] }</td>
|
|
|
+ { data2.map(d2 => {
|
|
|
+ return statistics.map((s, si) => {
|
|
|
+ return <td key={si}>{d2[s.name]}</td>
|
|
|
+ })
|
|
|
+ }) }
|
|
|
+ </tr>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </tbody>
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
@@ -53,10 +160,13 @@ class AggregateTableView extends React.Component {
|
|
|
if(!chartOption || !chartOption.targetColumn || !chartOption.statistics || chartOption.statistics.length === 0) {
|
|
|
return <EmptyContent />
|
|
|
}
|
|
|
+ let body = this.getTableBody();
|
|
|
+ if(!body) {
|
|
|
+ return <EmptyContent />
|
|
|
+ }
|
|
|
return <div ref={ node => this.formRef = node } className='aggregate-container'>
|
|
|
<table className={`aggregate-table`} border='1'>
|
|
|
- { this.getTableHeader() }
|
|
|
- { this.getTableBody() }
|
|
|
+ { body }
|
|
|
</table>
|
|
|
</div>
|
|
|
}
|