跳到主要内容

关于策略生成器

tactics.tsx

import React from 'react';
import map from 'lodash/map';

import {
AreaChartOutlined,
LineChartOutlined,
TableOutlined,
BarChartOutlined,
PieChartOutlined,
} from "@ant-design/icons";


/**
* 字典 shape as [value, label, Icon][].
* @summary 图表类型
* @readonly
*/
const AnalysisCharts = [
['line', '趋势图', LineChartOutlined],
['table', '数据表', TableOutlined],
['stack', '堆积图', AreaChartOutlined],
['lineSum', '累计图', LineChartOutlined],
['bar', '柱状分布图', BarChartOutlined],
['pie', '饼状分布图', PieChartOutlined],
] as const;

/**
* 策略接口
* @example
* {
* value: 'line',
* label: '趋势图',
* icon: <LineChartOutlined />,
* }
*/
export interface ChartOption {
value: typeof AnalysisCharts[number][0];
label: typeof AnalysisCharts[number][1];
icon: React.ReactNode;
}

/**
* 策略生成器
* @param {typeof AnalysisCharts} ls 字典列表
* @returns {ChartOption[]} 策略列表
*/
const generator = (ls: typeof AnalysisCharts): ChartOption[] =>
map(ls, ([value, label, Icon]): ChartOption => (
{
value,
label,
icon: <Icon />,
}
));

export const chartOption = generator(AnalysisCharts);

调用


import { chartOption } from 'tactics'