添加自定义 dataFilter

This commit is contained in:
2betop 2020-03-04 20:37:18 +08:00
parent 363814e0b4
commit d212362e6e
1 changed files with 12 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import {ScopedContext, IScopedContext} from '../Scoped';
export interface ChartProps extends RendererProps {
chartRef?: (echart: any) => void;
onDataFilter?: (config: any) => any;
dataFilter?: string;
api?: Api;
source?: string;
config?: object;
@ -193,13 +194,22 @@ export class Chart extends React.Component<ChartProps> {
if (!this.echarts) {
return;
}
const onDataFilter = this.props.onDataFilter;
let onDataFilter = this.props.onDataFilter;
const dataFilter = this.props.dataFilter;
if (!onDataFilter && typeof dataFilter === 'string') {
onDataFilter = new Function('config', 'echarts', dataFilter) as any;
}
config = config || this.pending;
if (typeof config === 'string') {
config = new Function('return ' + config)();
}
onDataFilter && (config = onDataFilter(config) || config);
try {
onDataFilter && (config = onDataFilter(config) || config);
} catch (e) {
console.warn(e);
}
if (config) {
try {