@antv/g2plot
Version:
G2 Plot, a market of plots built with the Grammar of Graphics'
285 lines (284 loc) • 7.46 kB
TypeScript
/**
* G2-Plot配置项
* 注意事项:
* 1. 命名采用驼峰
* 2. 如果是枚举值,不使用enum,全部列出
* 3. 减少嵌套,尽量平铺配置
*/
import { Option } from '@antv/g2';
import { AttributeCfg, LabelOptions } from '@antv/g2/lib/element/base';
import { AdjustCfg } from '@antv/g2/lib/interface';
import { LooseMap } from './types';
export interface ITitle {
visible: boolean;
text: string;
style?: {};
alignWithAxis?: boolean;
}
export interface IDescription {
visible: boolean;
text: string;
style?: {};
alignWithAxis?: boolean;
}
declare type IEvents = LooseMap<string>;
export declare type Formatter = (text: string, item: any, idx: number) => string;
export interface IStyleConfig {
[key: string]: string | number | boolean;
}
export interface IBaseAxis {
/** 轴是否需要显示,默认true */
visible?: boolean;
/** 轴类型,对应scale类型 */
type?: 'linear' | 'time' | 'cat' | 'dateTime' | 'category' | 'log' | 'pow' | 'timeCat';
/** 轴位置,默认下和左 */
line?: {
visible?: boolean;
style?: IStyleConfig;
};
grid?: {
/** 网格线是否显示 */
visible?: boolean;
style?: IStyleConfig | ((text: string, idx: number, count: number) => IStyleConfig);
};
/** 网格线样式 */
gridType?: 'line' | 'arc';
/** 网格设置交替的颜色,指定一个值则先渲染奇数层,两个值则交替渲染 */
gridAlternateColor?: string | string[];
autoRotateLabel?: boolean | number[];
autoHideLabel?: boolean;
autoRotateTitle?: boolean;
label?: {
visible?: boolean;
formatter?: (...args: any[]) => string;
offset?: number;
offsetX?: number;
offsetY?: number;
rotate?: number;
useHtml?: boolean;
htmlTemplate?: string;
style?: IStyleConfig;
};
title?: {
visible?: boolean;
autoRotate?: boolean;
text?: string;
offset?: number;
style?: IStyleConfig;
};
tickLine?: {
visible?: boolean;
style?: IStyleConfig;
};
events?: IEvents;
}
/** Linear型 */
export interface IValueAxis extends IBaseAxis {
type?: 'linear';
/** tick相关配置 */
min?: number;
max?: number;
minLimit?: number;
maxLimit?: number;
tickCount?: number;
tickInterval?: number;
}
/** 时间型 */
export interface ITimeAxis extends IBaseAxis {
type?: 'time';
/** tick相关配置 */
tickInterval?: string;
tickCount?: number;
groupBy?: string;
}
/** 离散类目型 */
export interface ICatAxis extends IBaseAxis {
type?: 'category';
/** tick相关配置 */
tickInterval?: number;
tickCount?: number;
groupBy?: string;
}
export declare type Axis = ICatAxis | IValueAxis | ITimeAxis;
export interface Label {
visible: boolean;
type?: string;
formatter?: (text: string, item: any, idx: number, ...extras: any[]) => string;
/** 精度配置,可通过自定义精度来固定数值类型 label 格式 */
precision?: number;
/** 添加后缀 */
suffix?: string;
style?: {};
offset?: number;
offsetX?: number;
offsetY?: number;
events?: IEvents;
position?: string;
adjustColor?: boolean;
adjustPosition?: boolean;
autoRotate?: boolean;
labelLine?: any;
}
export interface Legend {
visible?: boolean;
/** 位置 */
position?: string;
/** 翻页 */
flipPage?: boolean;
events?: IEvents;
formatter?: (...args: any) => string;
offsetX?: number;
offsetY?: number;
clickable?: boolean;
}
export interface Tooltip {
visible: boolean;
shared: boolean;
/** html */
showTitle?: boolean;
html?: HTMLDivElement;
formatter?: (...args: any) => string;
htmlContent?: (title: string, items: any[]) => string;
containerTpl?: string;
itemTpl?: string;
/** 辅助线 */
crosshair?: 'x' | 'y' | 'cross' | boolean;
crosshairs?: {
type: string;
style?: IStyleConfig;
};
style?: IStyleConfig;
}
export interface Theme {
}
export interface ElementOption {
type: string;
position: {
fields: string[];
};
color?: AttributeCfg;
size?: AttributeCfg;
shape?: AttributeCfg;
style?: IStyleConfig;
label?: LabelOptions | false;
animate?: {};
adjust?: AdjustCfg[];
connectNulls?: boolean;
widthRatio?: {
[type: string]: number;
};
}
export interface G2Config {
scales: Option.ScalesOption;
legends: Option.LegendOption | Option.LegendsOption | boolean;
tooltip: Option.TooltipOption | boolean;
axes: Option.AxesOption | boolean;
coord: Option.CoordinateOption;
element?: ElementOption;
elements: ElementOption[];
annotations: any[];
interactions: {};
theme: any;
panelRange: any;
animate: any;
}
export interface IColorConfig {
fields?: string[];
values?: string[];
callback?: (...args: any[]) => any;
}
export declare const timeIntervals: {
second: {
value: number;
format: string;
};
miniute: {
value: number;
format: string;
};
hour: {
value: number;
format: string;
};
day: {
value: number;
format: string;
};
week: {
value: number;
format: string;
};
month: {
value: number;
format: string;
};
year: {
value: number;
format: string;
};
};
interface StateCondition {
name: string;
exp: () => boolean | string | number;
}
export interface StateConfig {
condition: () => any | StateCondition;
style?: IStyleConfig;
related?: string[];
}
export interface SliderConfig {
visible?: boolean;
start?: number;
end?: number;
foregroundColor?: string;
backgroundColor?: string;
height?: number;
paddingTop?: number;
paddingBottom?: number;
}
export interface ISliderInteractionConfig {
/** 在图表中的位置,默认 horizontal */
type?: 'horizontal' | 'vertical';
/** 宽度,在 vertical 下生效 */
width?: number;
/** 高度,在 horizontal 下生效 */
height?: number;
/** 可选 padding */
padding?: [number, number, number, number];
/** 前景框颜色 */
foregroundColor?: string;
/** 背景框颜色 */
backgroundColor?: string;
/** 默认开始位置, 0~1 */
start?: number;
/** 默认结束位置, 0~1 */
end?: number;
}
export interface IScrollBarInteractionConfig {
/** 在图表中的位置,默认 horizontal */
type?: 'horizontal' | 'vertical';
/** 宽度,在 vertical 下生效 */
width?: number;
/** 高度,在 horizontal 下生效 */
height?: number;
/** 可选 padding */
padding?: [number, number, number, number];
/** 对应水平滚动条,为X轴每个分类字段的宽度;对于垂直滚动条,为X轴每个分类字段的高度 */
categorySize?: number;
}
export declare type IInteractionConfig = IScrollBarInteractionConfig | ISliderInteractionConfig;
export interface IInteractions {
type: string;
cfg?: IInteractionConfig;
}
/**
* 一个点位置
*/
export interface Point {
readonly x: number;
readonly y: number;
}
export interface DataItem {
[field: string]: string | number | null | undefined;
}
export {};