data-vis-ui
Version:
## [使用文档](https://temp-static-domain.jd.com/data-vis-ui)
182 lines (171 loc) • 5.47 kB
TypeScript
import { CSSProperties, PureComponent } from 'react';
import { EChartsReactProps } from 'echarts-for-react';
import ReactEcharts from 'echarts-for-react';
import * as echarts from 'echarts';
export type ChartType = 'line' | 'bar' | 'pie';
export type Params = Record<string, any>;
export type RequestData<T> = {
data: T;
msg?: string;
code?: string;
} & Record<string, any>;
export interface SmartChartProps<T = Record<string, any>> extends _EChartsReactProps {
/**
* @description 图表支持的类型
* @type 'line' | 'bar' | 'pie';
*/
type?: 'line' | 'bar' | 'pie';
/**
* @description echarts 的 option 与 echarts 文档保持一致
*/
readonly option?: EChartsOption;
/**
* @description request 的参数,修改之后会触发更新
* @default {}
*/
params?: T;
/**
* @description 一个获得 dataSource 的方法
*/
request?: (params: T) => Promise<Partial<RequestData<ChartDataType>>>;
/**
* @description 是否手动出发请求
* @default false
*/
manual?: boolean;
/**
* @description 轮询间隔,单位为毫秒。如果值大于 0,则启动轮询模式。
*/
polling?: number;
/**
* @description 在页面隐藏时,是否继续轮询。如果设置为 false,在页面隐藏时会暂时停止轮询,页面重新显示时继续上次轮询。
* @default true
*/
pollingWhenHidden?: boolean;
/**
* @description useRequest 的配置参数,如果有防抖节流缓存等其他需求,在此处填写配置,字段跟useRequest一致
* @default {}
*/
requestConfig?: Record<string, any>;
/**
* @description 初始化的参数,可以获取到 chartRequest 挂载 useRequest 的 相关action,获取 chartRef 用来操作 chart,
*/
actionRef?: React.MutableRefObject<ActionType>;
/**
* @description ECharts 的 options 发生变化是回调
*/
onOptionChange?: (o: EChartsOption) => void;
/**
* @description 数据加载失败时触发
*/
onRequestError?: (e: Error) => void;
/** 数据加载完成后触发 */
onLoad?: (data: any) => void;
/** 默认的数据 */
defaultData?: ChartDataType;
/**
* @@description 错误边界自定义
* @default null
*/
ErrorBoundary?: any;
}
export type ActionType = {
chartRequest: {
cancel?: (p: Record<string, any>) => void; // Fetch<TData, TParams>['cancel'];
refresh?: (p: Record<string, any>) => void; // Fetch<TData, TParams>['refresh'];
refreshAsync?: (p: Record<string, any>) => void; // Fetch<TData, TParams>['refreshAsync'];
run?: (p: Record<string, any>) => void; // Fetch<TData, TParams>['run'];
runAsync?: (p: Record<string, any>) => void; // Fetch<TData, TParams>['runAsync'];
mutate?: (p: Record<string, any>) => void; // Fetch<TData, TParams>['mutate'];
};
chartRef: React.LegacyRef<ReactEcharts>;
};
export type AxisType = string[] & Record<string, any>[];
export type SeriesItem = {
id?: string | number;
name: string;
value: (number | string | number[] | any)[];
} & Record<string, any>;
export type SeriesType = SeriesItem[];
export type ChartDataType = {
axis?: any[];
series: any;
};
export declare type EChartsOption = echarts.EChartsOption | { [key: string]: any };
export declare type EChartsInstance = any;
export declare type Opts = {
readonly devicePixelRatio?: number;
readonly renderer?: 'canvas' | 'svg';
readonly width?: number | null | undefined | 'auto';
readonly height?: number | null | undefined | 'auto';
readonly locale?: string;
};
export declare interface _EChartsReactProps extends EChartsReactProps {
/**
* @description echarts 入口,如有必要,可将其用于导入。
*/
readonly echarts?: any;
/**
* @description 自定义类名
*/
readonly className?: string;
/**
* @description 自定义属性
*/
readonly style?: CSSProperties;
/**
* @description 指定echarts.registerTheme注册的主题,使用见echarts手册
*/
readonly theme?: string | Record<string, any>;
/**
* @description 是否不跟之前设置的 option 进行合并。默认为false。即表示合并。
* @default false
*/
readonly notMerge?: boolean;
/**
* @description lazyUpdate 可选。在设置完 option 后是否不立即更新图表,默认为 false,即同步立即更新。如果为 true,则会在下一个 animation frame 中,才更新图表。
* @default false
*/
readonly lazyUpdate?: boolean;
/**
* @description 是否展示加载中
* @default false
*/
readonly showLoading?: boolean;
/**
* @description loading 样式
* @type
* {
* text: string,
* color: string,
* textColor: string,
* maskColor: string,
* zlevel: number
*}
* @default {}
*/
readonly loadingOption?: Record<string, any>;
/**
* @description opts
* @default {}
*/
readonly opts?: Opts;
/**
* @description 在图表重新排序之后,执行回调
*/
readonly onChartReady?: (instance: EChartsInstance) => void;
/**
* @description 绑定事件
* @type
* {
* click: (param, echarts)=>{},
* legendselectchanged: (param, echarts)=>{}
*}
* @default {}
*/
readonly onEvents?: Record<string, Function>;
/**
* @description echarts 重建前判断,返回 false 不重建,默认返回 true
*/
readonly shouldSetOption?: (prevProps: EChartsReactProps, props: EChartsReactProps) => boolean;
}