|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import { observer } from 'mobx-react';
|
|
|
|
|
import { DualAxes } from '@ant-design/plots';
|
|
|
|
|
import { merge, pick, cloneDeep } from '../utils/commons';
|
|
|
|
|
import { Line } from '@ant-design/plots';
|
|
|
|
|
import { merge, isEmpty } from '../utils/commons';
|
|
|
|
|
import { dataFieldAlias } from '../libs/ht';
|
|
|
|
|
|
|
|
|
|
const uniqueByKey = (array, key, pickLast) => {
|
|
|
|
@ -26,46 +26,28 @@ const uniqueByKey = (array, key, pickLast) => {
|
|
|
|
|
export default observer((props) => {
|
|
|
|
|
const { config, dataSource, ...extProps } = props;
|
|
|
|
|
const kpiKey = dataFieldAlias[config.yField]?.nestkey?.v;
|
|
|
|
|
const _data = uniqueByKey(dataSource, config.xField, true); // debug:
|
|
|
|
|
const mergeConfig = merge(
|
|
|
|
|
// color: ['#1979C9', '#F4664A', '#FAAD14'],
|
|
|
|
|
|
|
|
|
|
// padding: 'auto',
|
|
|
|
|
// xField: 'groupDateVal',
|
|
|
|
|
// yField: 'SumML',
|
|
|
|
|
// seriesField: 'groupsLabel',
|
|
|
|
|
{
|
|
|
|
|
...pick(config, ['padding', 'xField', 'seriesField']),
|
|
|
|
|
yField: [config.yField, kpiKey],
|
|
|
|
|
legend: false,
|
|
|
|
|
xAxis: {
|
|
|
|
|
type: 'cat',
|
|
|
|
|
},
|
|
|
|
|
meta: { ...cloneDeep(dataFieldAlias) },
|
|
|
|
|
geometryOptions: [
|
|
|
|
|
{
|
|
|
|
|
geometry: 'line',
|
|
|
|
|
smooth: true,
|
|
|
|
|
point: {
|
|
|
|
|
size: 4,
|
|
|
|
|
shape: 'cicle',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
geometry: 'line',
|
|
|
|
|
smooth: true,
|
|
|
|
|
point: {
|
|
|
|
|
size: 4,
|
|
|
|
|
shape: 'cicle',
|
|
|
|
|
},
|
|
|
|
|
lineStyle: {
|
|
|
|
|
lineWidth: 1,
|
|
|
|
|
lineDash: [5, 5],
|
|
|
|
|
},
|
|
|
|
|
color: '#F4664A',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
const _data = dataSource.reduce((r, v) => {
|
|
|
|
|
r.push(v);
|
|
|
|
|
if ( ! isEmpty(v[kpiKey])) { // 有设目标才多显示一条虚线 颜色: #F4664A
|
|
|
|
|
r.push({...v, [config.yField]: v[kpiKey], [config.seriesField]: dataFieldAlias[kpiKey].label});
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return <DualAxes {...mergeConfig} data={[_data, _data]} />;
|
|
|
|
|
return r;
|
|
|
|
|
}, []);
|
|
|
|
|
const mergeLineConfig = merge({
|
|
|
|
|
color: ['#598cf3', '#F4664A', '#FAAD14'],
|
|
|
|
|
lineStyle: (data) => {
|
|
|
|
|
console.log(data);
|
|
|
|
|
if (data[config.seriesField].includes('目标')) {
|
|
|
|
|
return {
|
|
|
|
|
lineDash: [4, 4],
|
|
|
|
|
opacity: 0.5,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
opacity: 1,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
}, config);
|
|
|
|
|
return <Line {...mergeLineConfig} data={_data} />;
|
|
|
|
|
});
|
|
|
|
|