|
|
@@ -1,9 +1,10 @@
|
|
|
-import { message } from 'antd'
|
|
|
-import * as service from '../services/index'
|
|
|
-import URLS from '../constants/url'
|
|
|
-import parseChartOption from './parseChartOption'
|
|
|
-import { deepAssign } from '../utils/baseUtils'
|
|
|
-import moment from 'moment'
|
|
|
+import { message } from 'antd';
|
|
|
+import * as service from '../services/index';
|
|
|
+import URLS from '../constants/url';
|
|
|
+import parseChartOption from './parseChartOption';
|
|
|
+import { deepAssign } from '../utils/baseUtils';
|
|
|
+import STATISTICS_OPTION from '../components/chartDesigner/sections/statisticsOption.json';
|
|
|
+import moment from 'moment';
|
|
|
|
|
|
function getBodyFilters(filters) {
|
|
|
let bodyFilters = [];
|
|
|
@@ -697,12 +698,23 @@ export default {
|
|
|
try {
|
|
|
const chartDesigner = yield select(state => state.present.chartDesigner);
|
|
|
const { code, aggregateTableConfig, filters, theme, styleConfig } = chartDesigner;
|
|
|
- const { targetColumn, statistics } = aggregateTableConfig;
|
|
|
+ const { targetColumn, statistics: statisticsNames } = aggregateTableConfig;
|
|
|
+
|
|
|
+ let statistics = statisticsNames.map(s => {
|
|
|
+ if(!s.name) {
|
|
|
+ let f = STATISTICS_OPTION.find(o => o.value === s);
|
|
|
+ return !!f ? {
|
|
|
+ name: f.value,
|
|
|
+ label: f.label
|
|
|
+ } : null;
|
|
|
+ }
|
|
|
+ return s
|
|
|
+ }).filter(s => !!s);
|
|
|
|
|
|
const body = {
|
|
|
id: code,
|
|
|
columnName: targetColumn.name,
|
|
|
- operatorList: statistics,
|
|
|
+ operatorList: statistics.map(s => s.name || s),
|
|
|
groupByList: aggregateTableConfig.groupBy && aggregateTableConfig.groupBy.length > 0 ? aggregateTableConfig.groupBy.map(g => g.key) : [],
|
|
|
filters: getBodyFilters(filters),
|
|
|
testPage: {
|
|
|
@@ -788,155 +800,235 @@ export default {
|
|
|
message.error('请求指标数据失败: ' + e.message);
|
|
|
}
|
|
|
},
|
|
|
- /**
|
|
|
- * 将图表数据以表格的方式作为预览
|
|
|
- */
|
|
|
- *remoteChartDataList(action, { select, call, put }) {
|
|
|
+ *getChartTableData(action, { select, call, put }) {
|
|
|
try {
|
|
|
- const chartDesigner = yield select(state => state.present.chartDesigner);
|
|
|
- const { code, baseConfig, aggregateTableConfig, lineConfig, barConfig, pieConfig, scatterConfig, dataViewConfig, filters } = chartDesigner;
|
|
|
- const { viewType } = baseConfig;
|
|
|
- const { page, pageSize } = action;
|
|
|
-
|
|
|
+ const { chartCode, chartType, chartOption, filters } = action;
|
|
|
let columns = [];
|
|
|
- let columnListName = [];
|
|
|
- let sortColumn = null;
|
|
|
-
|
|
|
- if(viewType === 'aggregateTable') {
|
|
|
- const { groupBy, targetColumn } = aggregateTableConfig;
|
|
|
- groupBy.map(g => ({
|
|
|
- label: g.label,
|
|
|
- name: g.key,
|
|
|
- })).concat([targetColumn]).filter(x => !!x.name).forEach(x => {
|
|
|
- if(!columns.find(c => c.name === x.name)) {
|
|
|
- columns.push(x);
|
|
|
- }
|
|
|
- });;
|
|
|
- sortColumn = targetColumn.name;
|
|
|
- }else if(viewType === 'line') {
|
|
|
- const { groupBy, xAxis, yAxis } = lineConfig;
|
|
|
- [{
|
|
|
- label: groupBy ? groupBy.label : '',
|
|
|
- name: groupBy ? groupBy.key : '',
|
|
|
- type: groupBy ? groupBy.type : '',
|
|
|
- }, {
|
|
|
- label: xAxis.column.label,
|
|
|
- name: xAxis.column.value,
|
|
|
- type: xAxis.column.type,
|
|
|
- }, {
|
|
|
- label: yAxis.column.label,
|
|
|
- name: yAxis.column.value,
|
|
|
- type: yAxis.column.type,
|
|
|
- }].filter(x => !!x.name).forEach(x => {
|
|
|
- if(!columns.find(c => c.name === x.name)) {
|
|
|
- columns.push(x);
|
|
|
+ let dataSource = [];
|
|
|
+ switch(chartType) {
|
|
|
+ case 'bar':
|
|
|
+ case 'line': {
|
|
|
+ const { baseOption } = chartOption;
|
|
|
+ const { originConfig, xAxis, series } = baseOption;
|
|
|
+ const { xAxis: oxAxis, yAxis: oyAxis, groupBy: ogroupBy } = originConfig;
|
|
|
+ columns = [{
|
|
|
+ title: `${oxAxis.column.label}${oxAxis.granularity.value ? `(${oxAxis.granularity.label})` : ''}`,
|
|
|
+ dataIndex: 'xAxis',
|
|
|
+ type: 'string'
|
|
|
+ }, {
|
|
|
+ title: `${oyAxis.column.label}${oyAxis.gauge.value ? `(${oyAxis.gauge.label})` : ''}`,
|
|
|
+ dataIndex: 'yAxis',
|
|
|
+ type: 'scale'
|
|
|
+ }];
|
|
|
+ if(ogroupBy && ogroupBy.key) {
|
|
|
+ columns.push({
|
|
|
+ title: ogroupBy.label,
|
|
|
+ dataIndex: 'groupBy',
|
|
|
+ type: 'string'
|
|
|
+ });
|
|
|
}
|
|
|
- });;
|
|
|
- sortColumn = xAxis.column.value;
|
|
|
- }else if(viewType === 'bar') {
|
|
|
- const { groupBy, xAxis, yAxis } = barConfig;
|
|
|
- [{
|
|
|
- label: groupBy ? groupBy.label : '',
|
|
|
- name: groupBy ? groupBy.key : '',
|
|
|
- type: groupBy ? groupBy.type : '',
|
|
|
- }, {
|
|
|
- label: xAxis.column.label,
|
|
|
- name: xAxis.column.value,
|
|
|
- type: xAxis.column.type,
|
|
|
- }, {
|
|
|
- label: yAxis.column.label,
|
|
|
- name: yAxis.column.value,
|
|
|
- type: yAxis.column.type,
|
|
|
- }].filter(x => !!x.name).forEach(x => {
|
|
|
- if(!columns.find(c => c.name === x.name)) {
|
|
|
- columns.push(x);
|
|
|
- }
|
|
|
- });;
|
|
|
- sortColumn = xAxis.column.value;
|
|
|
- }else if(viewType === 'pie') {
|
|
|
- const { xAxis, yAxis } = pieConfig;
|
|
|
- [{
|
|
|
- label: xAxis.column.label,
|
|
|
- name: xAxis.column.value,
|
|
|
- type: xAxis.column.type,
|
|
|
- }, {
|
|
|
- label: yAxis.column.label,
|
|
|
- name: yAxis.column.value,
|
|
|
- type: yAxis.column.type,
|
|
|
- }].filter(x => !!x.name).forEach(x => {
|
|
|
- if(!columns.find(c => c.name === x.name)) {
|
|
|
- columns.push(x);
|
|
|
+ xAxis[0].data.forEach((d, i) => {
|
|
|
+ if(ogroupBy && ogroupBy.key) {
|
|
|
+ series.forEach(xs => {
|
|
|
+ dataSource.push({
|
|
|
+ xAxis: d,
|
|
|
+ yAxis: xs.data[i],
|
|
|
+ groupBy: xs.name
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }else {
|
|
|
+ dataSource.push({
|
|
|
+ xAxis: d,
|
|
|
+ yAxis: series[0].data[i]
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'pie': {
|
|
|
+ const { baseOption } = chartOption;
|
|
|
+ const { originConfig, series } = baseOption;
|
|
|
+ const { xAxis: oxAxis, yAxis: oyAxis } = originConfig;
|
|
|
+ columns = [{
|
|
|
+ title: `${oxAxis.column.label}${oxAxis.granularity.value ? `(${oxAxis.granularity.label})` : ''}`,
|
|
|
+ dataIndex: 'xAxis',
|
|
|
+ type: 'string'
|
|
|
+ }, {
|
|
|
+ title: `${oyAxis.column.label}${oyAxis.gauge.value ? `(${oyAxis.gauge.label})` : ''}`,
|
|
|
+ dataIndex: 'yAxis',
|
|
|
+ type: 'scale'
|
|
|
+ }];
|
|
|
+ dataSource = series[0].data.map(d => ({
|
|
|
+ xAxis: d.name,
|
|
|
+ yAxis: d.value
|
|
|
+ }))
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'scatter': {
|
|
|
+ const { baseOption } = chartOption;
|
|
|
+ const { originConfig, series } = baseOption;
|
|
|
+ const { xAxis: oxAxis, yAxis: oyAxis, groupBy: ogroupBy } = originConfig;
|
|
|
+ columns = [{
|
|
|
+ title: oxAxis.column.label,
|
|
|
+ dataIndex: 'xAxis',
|
|
|
+ type: 'scale'
|
|
|
+ }, {
|
|
|
+ title: `${oyAxis.column.label}${oyAxis.gauge.value ? `(${oyAxis.gauge.label})` : ''}`,
|
|
|
+ dataIndex: 'yAxis',
|
|
|
+ type: 'scale'
|
|
|
+ }];
|
|
|
+ if(ogroupBy && ogroupBy.key) {
|
|
|
+ columns.push({
|
|
|
+ title: ogroupBy.label,
|
|
|
+ dataIndex: 'groupBy',
|
|
|
+ type: 'string'
|
|
|
+ });
|
|
|
}
|
|
|
- });;
|
|
|
- sortColumn = xAxis.column.value;
|
|
|
- }else if(viewType === 'scatter') {
|
|
|
- const { groupBy, xAxis, yAxis } = scatterConfig;
|
|
|
- [{
|
|
|
- label: groupBy ? groupBy.label : '',
|
|
|
- name: groupBy ? groupBy.key : '',
|
|
|
- type: groupBy ? groupBy.type : '',
|
|
|
- }, {
|
|
|
- label: xAxis.column.label,
|
|
|
- name: xAxis.column.value,
|
|
|
- type: xAxis.column.type,
|
|
|
- }, {
|
|
|
- label: yAxis.column.label,
|
|
|
- name: yAxis.column.value,
|
|
|
- type: yAxis.column.type,
|
|
|
- }].filter(x => !!x.name).forEach(x => {
|
|
|
- if(!columns.find(c => c.name === x.name)) {
|
|
|
- columns.push(x);
|
|
|
+ series.forEach(xs => {
|
|
|
+ xs.data.forEach(xd => {
|
|
|
+ if(ogroupBy && ogroupBy.key) {
|
|
|
+ dataSource.push({
|
|
|
+ xAxis: xd[0],
|
|
|
+ yAxis: xd[1],
|
|
|
+ groupBy: xs.name
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ dataSource.push({
|
|
|
+ xAxis: xd[0],
|
|
|
+ yAxis: xd[1]
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'dataView': {
|
|
|
+ const { originConfig } = chartOption;
|
|
|
+ const { viewColumns } = originConfig;
|
|
|
+ columns = viewColumns.map(c => ({
|
|
|
+ title: c.label,
|
|
|
+ dataIndex: c.name,
|
|
|
+ type: 'string'
|
|
|
+ }));
|
|
|
+ const body = {
|
|
|
+ id: chartCode,
|
|
|
+ columnListName: viewColumns.map(c => c.name),
|
|
|
+ sortColumn: originConfig.sortColumn ? originConfig.sortColumn.key : originConfig.viewColumns[0].name,
|
|
|
+ sort: originConfig.sortType || 'asc',
|
|
|
+ filters: getBodyFilters(filters),
|
|
|
+ testPage: {
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 9999999,
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ let res = yield call(service.fetch, {
|
|
|
+ url: URLS.CHART_DATAVIEW_OPTION,
|
|
|
+ body: body,
|
|
|
+ timeout: 30000
|
|
|
+ });
|
|
|
+ if(res.code > 0) {
|
|
|
+ res.data.valueList.list.forEach(l => {
|
|
|
+ let r = {};
|
|
|
+ viewColumns.forEach(c => {
|
|
|
+ let v = l[c.name];
|
|
|
+ if(c.type === 'time') {
|
|
|
+ v = moment(v).isValid() ? moment(v).format('YYYY-MM-DD'): v;
|
|
|
+ }
|
|
|
+ r[c.name] = v;
|
|
|
+ });
|
|
|
+ dataSource.push(r);
|
|
|
+ })
|
|
|
+ }else {
|
|
|
+ console.error(res.msg);
|
|
|
}
|
|
|
- });;
|
|
|
- sortColumn = xAxis.column.value;
|
|
|
- }else if(viewType === 'dataView') {
|
|
|
- columns = dataViewConfig.viewColumns;
|
|
|
- sortColumn = dataViewConfig.sortColumn.key;
|
|
|
- }
|
|
|
-
|
|
|
- if(columns.length === 0) {
|
|
|
- // message.error('');
|
|
|
- return false;
|
|
|
- }
|
|
|
- columnListName = columns.map(c => c.name);
|
|
|
-
|
|
|
- const body = {
|
|
|
- id: code,
|
|
|
- columnListName: columnListName,
|
|
|
- sortColumn: sortColumn,
|
|
|
- sort: 'asc',
|
|
|
- filters: getBodyFilters(filters),
|
|
|
- testPage: {
|
|
|
- pageNum: page || 1,
|
|
|
- pageSize: pageSize || 25,
|
|
|
+ break;
|
|
|
}
|
|
|
- };
|
|
|
+ case 'aggregateTable': {
|
|
|
+ const { originConfig, data, group1Name, group2Name, group1s, group2s } = chartOption;
|
|
|
+ const { groupBy, statistics: statisticsNames } = originConfig;
|
|
|
|
|
|
- yield put({ type: 'dataList/setField', name: 'loading', value: true });
|
|
|
- let res = yield call(service.fetch, {
|
|
|
- url: URLS.CHART_DATAVIEW_OPTION,
|
|
|
- body: body,
|
|
|
- timeout: 30000
|
|
|
- });
|
|
|
- if(res.code > 0) {
|
|
|
+ let statistics = statisticsNames.map(s => {
|
|
|
+ if(!s.name) {
|
|
|
+ let f = STATISTICS_OPTION.find(o => o.value === s);
|
|
|
+ return !!f ? {
|
|
|
+ name: f.value,
|
|
|
+ label: f.label
|
|
|
+ } : null;
|
|
|
+ }
|
|
|
+ return s
|
|
|
+ }).filter(s => !!s);
|
|
|
|
|
|
- const { valueList } = res.data;
|
|
|
- const { list: dataSource, pageSize, total } = valueList;
|
|
|
+ columns = groupBy.map((g, i) => ({ title: g.label, dataIndex: `groupBy${i+1}`, type: 'string' })).concat(statistics.map(s => ({ title: s.label, dataIndex: s.name, type: 'scale' })));
|
|
|
|
|
|
- yield put({ type: 'dataList/setFields', fields: [
|
|
|
- { name: 'columns', value: columns },
|
|
|
- { name: 'dataSource', value: dataSource },
|
|
|
- { name: 'pageSize', value: pageSize },
|
|
|
- { name: 'total', value: total }
|
|
|
- ] });
|
|
|
- }else {
|
|
|
- message.error('请求列表数据失败: ' + res.msg);
|
|
|
- // yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
|
|
|
+ if(!group1Name) { // 无分组
|
|
|
+ let obj = {};
|
|
|
+ statistics.forEach(s => {
|
|
|
+ obj[s.name] = data[s.name];
|
|
|
+ });
|
|
|
+ dataSource.push(obj);
|
|
|
+ }else {
|
|
|
+ if(!group2Name) { // 只有一个分组
|
|
|
+ dataSource = group1s.map((g, i) => {
|
|
|
+ let obj = {};
|
|
|
+ obj['groupBy1'] = g;
|
|
|
+ statistics.forEach(s => {
|
|
|
+ obj[s.name] = data[i][s.name];
|
|
|
+ });
|
|
|
+ return obj;
|
|
|
+ });
|
|
|
+ }else { // 有两个分组
|
|
|
+ group1s.forEach((g1, i1) => {
|
|
|
+ let d = data[i1];
|
|
|
+ group2s.forEach((g2, i2) => {
|
|
|
+ let obj = {};
|
|
|
+ obj['groupBy1'] = g1;
|
|
|
+ obj['groupBy2'] = g2;
|
|
|
+ statistics.forEach(s => {
|
|
|
+ obj[s.name] = d.data[i2][s.name];
|
|
|
+ })
|
|
|
+ dataSource.push(obj);
|
|
|
+ })
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(columns, dataSource);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'indicator': {
|
|
|
+ let { originConfig, data } = chartOption;
|
|
|
+ let { xAxis, yAxis, otherColumn } = (originConfig || {});
|
|
|
+ columns = [{
|
|
|
+ title: xAxis.column.label,
|
|
|
+ dataIndex: 'xAxis',
|
|
|
+ type: xAxis.column.type
|
|
|
+ }, {
|
|
|
+ title: `${yAxis.column.label}${yAxis.gauge.value ? `(${yAxis.gauge.label})` : ''}`,
|
|
|
+ dataIndex: 'yAxis',
|
|
|
+ type: yAxis.column.type
|
|
|
+ }].concat(otherColumn.map((c, i) => ({
|
|
|
+ title: c.label,
|
|
|
+ dataIndex: `other${i}`,
|
|
|
+ type: c.type
|
|
|
+ })));
|
|
|
+ dataSource = data.map(d => {
|
|
|
+ let obj = {};
|
|
|
+ obj['xAxis'] = d.name;
|
|
|
+ obj['yAxis'] = d.value;
|
|
|
+ d.others.forEach((o, i) => {
|
|
|
+ obj[`other${i}`] = o.value;
|
|
|
+ })
|
|
|
+ return obj;
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
+ return { columns, dataSource};
|
|
|
}catch(e) {
|
|
|
- message.error('请求数据列表失败: ' + e.message);
|
|
|
- }finally {
|
|
|
- yield put({ type: 'dataList/setField', name: 'loading', value: false });
|
|
|
+ message.error('解析数据失败: ' + e.message);
|
|
|
+ return { columns: [], dataSource: []}
|
|
|
}
|
|
|
},
|
|
|
},
|