import { LooseObject, ShapeAttrs } from '@antv/g-base'; import { Chart, Element, Scale, Types, View } from '@antv/g2'; import { AdjustOption, AdjustType, ScaleOption } from '@antv/g2/lib/interface'; import { PropsWithChildren } from 'react'; import { Interceptor } from './hooks/useInterceptors'; import { LegendObject } from './legends/useLegends'; export interface Actions { instance: Chart | undefined; views: View[]; config: ChartConfig | undefined; options: ChartOptions | undefined; render: any; update: any; legend: any; clear: any; } export declare enum ChartType { LINE = "line", BAR = "bar", COLUMN = "column", FUNNEL = "funnel", AREA = "area", DONUT = "donut", BUBBLE = "bubble", GAUGE = "gauge", BOX = "box", DoubleAxes = "double-axes", HotMap = "hotMap" } export interface ShapeStyle extends Omit { lineDash?: boolean | number[] | null; } export interface Legend { /** * 图表Chart的类型,可为BAR、LINE等 */ type?: ChartType | string; /** * 控制label的key,与控制图形的color一致 */ controlKey?: string; name: string; alias?: string; active?: boolean; color?: string; opacity?: number; dashed?: boolean; lineDash?: boolean | number[]; dodgeBy?: string; width?: number; } export interface Legends { [key: string]: Legend; } export interface ChartOptions extends LooseObject { id?: HTMLElement; data?: LooseObject | LooseObject[]; /** * this is used to render the chart whether to subtract the legend height or not. */ legendObject?: LegendObject; chart?: Actions; theme?: LooseObject; dict?: LooseObject; /** * chart title */ title?: string; /** * set default styles for line or interval */ defaultStyles?: ShapeStyle; interceptors?: Interceptor; } export interface BaseChartConfig extends LooseObject { /** * 自动适应宽高 */ autoFit?: boolean; /** * 设置Chart的高度 */ height?: number; /** * 当为true时;渲染图表不显示动画。 */ closeAnimate?: boolean; /** * set the theme for chart */ theme?: LooseObject | string; } export interface LegendOptions { tile?: boolean; } export interface ChartConfig extends LooseObject { /** * 定义Chart的基础属性 */ chart?: BaseChartConfig; /** * 用来显示或隐藏Legend图例 * 在gio-design-charts中,legend被重新定义,G2默认的legend配置将无效,在这里配置legend: false可用来隐藏Legend */ legend?: boolean | LooseObject; legendOptions?: LegendOptions; /** * 1. chart.scale({ sale: { min: 0, max: 100} }); * 2. chart.scale('sale', { min: 0, max: 100}); * 3. chart.scale({ sale: { min: 0, max: 100} }, { nice: true }); * 更多内容请参考: https://g2.antv.vision/zh/docs/api/general/scale#scaleoptionmintickinterval */ scale?: Record | (string | ScaleOption)[]; annotations?: Annotation[]; customSizeConfig?: { minColumnWidth?: number; maxColumnWidth?: number; intervalPadding?: number; dodgePadding?: number; }; } export interface AreaConfig extends ChartConfig { /** * 用来创建面积图的配置 */ area: Shape; } export interface BoxConfig extends ChartConfig { /** * 用来创建箱型图的配置 */ box: Shape; } export interface BubbleConfig extends ChartConfig { /** * 用来创建气泡图 */ bubble: Shape; } export interface LineConfig extends ChartConfig { /** * 用来创建折线图的配置 */ line: Shape; } export interface GaugeConfig extends ChartConfig { /** * 用来创建仪表图的配置 */ gauge: Shape; } export interface ColumnConfig extends ChartConfig { /** * 用来创建柱状图的配置 */ column: Shape; } export interface DonutConfig extends Omit { /** * 用来创建环形图的配置 */ donut: Shape; } export interface BarConfig extends ChartConfig { /** * 用来创建条形图的配置 */ bar: Shape; } export interface FunnelConfig extends ChartConfig { /** * 用来创建漏斗图的配置 */ funnel: Shape & { contrast?: string; }; } export interface HotMapConfig extends ChartConfig { /** * 用来创建漏斗图的配置 */ hotMap: Shape & { contrast?: string; }; } export interface DoubleAxesConfig extends ChartConfig { /** * 用来创建柱状图的配置 */ column: Shape; /** * 用来创建折线图的配置 */ line: Shape; } export interface ChartRef { getInstance?: () => Chart; } export interface ChartProps { children?: React.ReactNode; /** * 显示图表的title */ title?: string; /** * Chart的基础配置,设定theme, scale, tooltip */ config: PropsWithChildren; /** * Chart数据 */ data: LooseObject[]; loading?: boolean; errorTemplate?: (e: Error) => JSX.Element | JSX.Element[]; noData?: () => JSX.Element; /** * 图例数组,是字符串或者图例对象 * */ legends?: (Legend | string)[]; } export interface TinyChartProps extends Omit { data: number[]; } export interface AdjustOpt extends Omit { type: AdjustType | string; marginRatio?: number; dodgeBy?: string; } export declare type AdjustOptionType = string | string[] | AdjustOption | AdjustOption[]; export declare type AdjustOptType = string | string[] | AdjustOpt | AdjustOpt[]; export interface Shape extends LooseObject { position?: string; xField?: string; yField?: string; zField?: string; /** * 设置数据调整方式 * 参考: https://g2.antv.vision/zh/docs/api/general/adjust * @param {AdjustOption} */ adjust?: AdjustOptType; /** * 颜色通道 */ color?: string; } export interface ReportThing { elements?: Element[]; scale?: Scale; } export interface CustomInfo { isStack?: boolean; topData?: LooseObject; chartType?: string; useDash?: boolean; type?: string; dodgeBy?: string; contrastDodge?: boolean; legendObject?: LegendObject; defaultStyles?: ShapeStyle; xField?: string; yField?: string; zField?: string; } declare type AnnotationOption = Types.ArcOption | Types.ImageOption | Types.LineOption | Types.TextOption | Types.RegionOption | Types.RegionFilterOption | Types.DataMarkerOption | Types.DataRegionOption | Types.ShapeAnnotationOption | Types.HtmlAnnotationOption; export declare type Annotation = { id?: string; } & AnnotationOption; export {};