AntV Infographic
Home
Learn
Reference
Gallery
Icon
Editor
AI
Enterprise

目录

  • Overview
  • Bounds
  • JSXElement
  • JSXNode
  • ComponentType
  • Padding
  • SVGOptions
  • ExportOptions
  • SVGExportOptions
  • PNGExportOptions
  • DesignOptions
  • BaseItemProps
  • ItemOptions
  • Item
  • BaseStructureProps
  • Structure
  • StructureOptions
  • Data
  • ItemDatum
  • ThemeConfig
  • BaseAttributes
  • ThemeSeed
  • ThemeColors
  • Font
  • IconAttributes
  • ShapeAttributes
  • TextAttributes
  • ElementProps
  • IPlugin
  • IInteraction
  • ResourceConfig
  • ResourceLoader
  • DynamicAttributes
  • Palette
  • StylizeConfig
  • RoughConfig
  • PatternConfig
  • PatternStyle
  • GradientConfig
  • TemplateOptions
  • 其他类型
  • WithType
  • WithProps
  • Infographic
    • API
    • 配置项
    • 类型定义
    • 导出内容
  • JSX
    • 原语节点
    • 创建布局
    • 工具函数
  • 设计资产
    • 内置结构
    • 内置数据项
    • 内置模版
    • 内置主题
    • 内置色板
    • 内置图案
    • 内置组件
API Reference
Infographic

类型定义

信息图语法的顶层配置即 InfographicOptions。本页补充其中涉及到的复合类型,方便在查阅语法表格时快速定位到字段的结构。

Bounds

描述元素的包围盒,常用于布局和工具函数。

TS
type Bounds = {x: number; y: number; width: number; height: number};

JSXElement

低层渲染使用的 JSX 节点定义。

TS
interface JSXElement { type: string | symbol | ((props?: any) => JSXNode); // 节点类型 props: Record<string, any>; // 属性对象 key?: string | null; // 可选稳定标识 }

JSXNode

通用的 JSX 节点类型。

TS
type JSXNode = | JSXElement | string | number | boolean | null | undefined | JSXNode[];

JSXNode 代表渲染树上的任意节点;JSXElement 仅指带 type/props 的节点。

ComponentType

声明组件签名的通用类型,组件接受 children 并返回 JSXNode。

TS
type ComponentType<P = {}> = (props: P & {children?: JSXNode}) => JSXNode; // 输入包含 children,输出 JSXNode

Padding

内边距,可以是单个数字(表示所有边的内边距相同),也可以是一个数字数组,表示上、右、下、左四个边的内边距,顺序如下:

TS
type Padding = number | number[];

SVGOptions

SVG 容器上的附加配置,允许为根节点设置样式、属性与标识。

属性类型必填说明
styleRecord<string, string | number>否内联样式
attributesRecord<string, string | number | boolean>否额外属性
idstring否元素 id
classNamestring否元素类名

ExportOptions

导出为 SVG 或 PNG 的参数联合类型。

TS
type ExportOptions = SVGExportOptions | PNGExportOptions;

SVGExportOptions

属性类型必填说明
type'svg'是导出类型标识
embedResourcesboolean否是否内嵌远程资源,默认 true
removeIdsboolean否是否移除 id 依赖,默认 false

PNGExportOptions

属性类型必填说明
type'png'是导出类型标识
dprnumber否导出时的设备像素比,默认使用浏览器 devicePixelRatio

DesignOptions

设计配置项

属性类型必填说明
structurestring | WithType<StructureOptions>否结构
titlestring | WithType<TitleOptions>否标题
itemstring | WithType<ItemOptions>否数据项
itemsstring | WithType<ItemOptions>[]否针对层级布局,不同层级使用不同 item

BaseItemProps

渲染单个数据项时组件可接收的基础属性。

属性类型必填说明
xnumber否组件左上角 X 坐标
ynumber否组件左上角 Y 坐标
idstring否自定义 id
indexesnumber[]是当前数据项在层级中的索引路径
dataData是整体数据对象
datumItemDatum是当前数据项
themeColorsThemeColors是当前主题色集合
positionH'normal' | 'center' | 'flipped'否水平朝向
positionV'normal' | 'middle' | 'flipped'否垂直朝向
valueFormatter(value: number) => string | number否数值格式化函数
[key: string]any否其他扩展属性,会透传到组件内部

ItemOptions

数据项的可选配置,等同于 Partial<BaseItemProps>。

TS
type ItemOptions = Partial<BaseItemProps>;

Item

描述一个数据项的组件及其组合能力。

TS
interface Item<T extends BaseItemProps = BaseItemProps> { component: ComponentType<T>; // 用于渲染的组件 composites: string[]; // 可组合的结构类型 options?: ItemOptions; // 默认项配置 }

BaseStructureProps

结构组件接收的渲染属性。

TS
interface BaseStructureProps { Title?: ComponentType<Pick<TitleProps, 'title' | 'desc'>>; // 可选标题组件 Item: ComponentType< Omit<BaseItemProps, 'themeColors'> & Partial<Pick<BaseItemProps, 'themeColors'>> >; // 当前层级数据项组件 Items: ComponentType<Omit<BaseItemProps, 'themeColors'>>[]; // 按层级选择的数据项组件列表 data: Data; // 完整数据 options: ParsedInfographicOptions; // 解析后的配置 }

Structure

定义结构组件及其组合关系。

TS
interface Structure { component: ComponentType<BaseStructureProps>; // 结构组件实现 composites: string[]; // 结构包含组成部分,用于为 AI 生成类型说明 }

StructureOptions

结构配置项的扩展字典。

TS
type StructureOptions = Record<string, any>;

Data

信息图展示的数据结构。

属性类型必填说明
titlestring否数据标题
descstring否数据描述
itemsItemDatum[]是数据项列表
[key: string]any否扩展字段

ItemDatum

属性类型必填说明
iconstring | ResourceConfig否图标资源
labelstring否标题
descstring否描述
valuenumber否数值
illusstring | ResourceConfig否插画
childrenItemDatum[]否嵌套项
[key: string]any否自定义字段

ThemeConfig

主题配置项

属性类型必填说明
colorBgstring否背景色
colorPrimarystring否整体主色
base{ global?: DynamicAttributes<BaseAttributes>; shape?: ShapeAttributes; text?: TextAttributes; }否全局基础样式
base.globalDynamicAttributes<BaseAttributes>否全局基础配置
base.shapeShapeAttributes否全局图形配置
base.textTextAttributes否全局文本配置
palettePalette否色板
titleTextAttributes否标题样式
descTextAttributes否描述样式
itemobject否数据项配置
item.iconDynamicAttributes<IconAttributes>否图标配置
item.labelDynamicAttributes<TextAttributes>否标签配置
item.descDynamicAttributes<TextAttributes>否描述配置
item.valueDynamicAttributes<TextAttributes>否值配置
stylizeStylizeConfig | null否风格化

BaseAttributes

基础属性集合,用于定义通用的填充与透明度。

属性类型必填说明
opacitynumber | string否不透明度
fillstring否填充色
fill-opacitynumber | string否填充不透明度
strokestring否描边颜色
stroke-opacitynumber | string否描边不透明度

ThemeSeed

主题输入种子。

属性类型必填说明
colorPrimarystring是原始主色
colorBgstring否背景色
isDarkModeboolean否是否为暗色模式

ThemeColors

根据 ThemeSeed 计算出的完整主题色值。

属性类型必填说明
colorPrimarystring是原始主色
colorPrimaryBgstring是主色浅色背景
colorPrimaryTextstring是主色背景上的文本颜色
colorTextstring是最深文本颜色
colorTextSecondarystring是次要文本颜色
colorWhitestring是纯白色
colorBgstring是画布背景色
colorBgElevatedstring是卡片背景色
isDarkModeboolean是是否为暗色模式

Font

字体资源的配置。

TS
type FontWeightName = | 'thin' | 'extralight' | 'light' | 'regular' | 'medium' | 'semibold' | 'bold' | 'extrabold' | 'black' | 'extrablack'; interface Font { fontFamily: string; // 字体族名 name: string; // 展示用名称 baseUrl: string; // 字体文件基地址或 CSS 地址 fontWeight: {[keys in FontWeightName]?: string}; // 各字重映射到实际资源 }

IconAttributes

图标(通常为 <use> 或 <image>)可配置的属性。

属性类型必填说明
idnumber | string否元素 id
classnumber | string否元素类名
xnumber | string否X 坐标
ynumber | string否Y 坐标
widthnumber | string否宽度
heightnumber | string否高度
hrefnumber | string否资源地址
fillnumber | string否填充色
fill-opacitynumber | string否填充不透明
opacitynumber | string否不透明度

ShapeAttributes

属性类型必填说明
opacitynumber | string否不透明度
fillstring否填充色
fill-opacitynumber | string否填充不透明度
fill-rule'nonzero' | 'evenodd' | 'inherit'否填充规则
strokestring否描边颜色
stroke-widthnumber | string否描边宽度
stroke-linecapnumber | string否描边端点样式
stroke-linejoinnumber | string否描边连接样式
stroke-dasharraynumber | string否描边虚线数组
stroke-dashoffsetnumber | string否描边虚线偏移
stroke-opacitynumber | string否描边不透明度

TextAttributes

属性类型必填说明
xnumber | string否X 坐标
ynumber | string否Y 坐标
widthnumber | string否宽度
heightnumber | string否高度
text-alignmentstring否文本对齐方式
font-familystring否字体族
font-sizenumber | string否字体大小
font-weightnumber | string否字体粗细
font-stylenumber | string否字体样式
font-variantnumber | string否字体变体
letter-spacingnumber | string否字符间距
line-heightnumber | string否行高
fillnumber | string否填充色
strokenumber | string否描边颜色
stroke-widthnumber | string否描边宽度
text-anchornumber | string否文本锚点
dominant-baselinenumber | string否基线对齐

ElementProps

编辑模式下可追加的图形元素定义,既支持基础图形也支持文本。

TS
type ElementProps = GeometryProps | TextProps; interface GeometryProps { type: | 'rectangle' | 'circle' | 'ellipse' | 'line' | 'polyline' | 'polygon' | 'path' | 'image'; attributes: Record<string, any>; } interface TextProps { type: 'text'; textContent: string; attributes: TextAttributes; }

IPlugin

编辑器插件接口,便于扩展编辑能力。

TS
interface IPlugin { name: string; init(options: { emitter: any; editor: any; commander: any; plugin: any; state: any; }): void; destroy(): void; }

init 会收到编辑器上下文(事件、命令、状态等),在 destroy 中清理绑定与副作用。

IInteraction

交互扩展接口,用于处理选中、拖拽等用户行为。

TS
interface IInteraction { name: string; init(options: {emitter: any; editor: any; commander: any; interaction: any}): void; destroy(): void; }

ResourceConfig

描述需要加载的图形、图片或远程资源。

属性类型必填说明
type'image' | 'svg' | 'remote' | 'custom'是资源类型
datastring是资源的标识或数据
[key: string]any否资源扩展配置

ResourceLoader

自定义资源加载器的签名。

TS
type ResourceLoader = ( config: ResourceConfig ) => Promise<SVGSymbolElement | null>;

// 入参为资源配置,返回解析好的 SVGSymbolElement 或 null。

DynamicAttributes

泛型工具类型,可以让属性既支持直接赋值,也支持使用函数根据运行时上下文动态生成。

TS
type DynamicAttributes<T extends object> = { [key in keyof T]?: | T[key] | ((value: T[key], node: SVGElement) => T[key] | undefined); };
  • T:目标属性映射,例如 TextAttributes。
  • node:当前属性所在的 SVG 元素,可用于按节点上下文返回差异化样式。

Palette

主题色板的类型别名,支持多种定义方式:

TS
type Palette = | string | string[] | ((ratio: number, index: number, count: number) => string);
  • string:使用注册的色板。
  • string[]:离散颜色列表,数据项将按顺序循环使用。
  • 函数:根据数据项占比(ratio)、索引(index)以及总数(count)返回颜色。

如果要注册色板,参考自定义色板。

StylizeConfig

风格化配置的联合类型,支持三种风格:手绘、图案、渐变。

TS
type StylizeConfig = RoughConfig | PatternConfig | GradientConfig;

RoughConfig

属性类型必填说明
type'rough'是启用手绘风格
roughnessnumber否抖动强度
bowingnumber否弯曲程度
fillWeightnumber否填充线粗细
hachureGapnumber否线条间距

PatternConfig

属性类型必填说明
type'pattern'是启用图案填充
patternstring是图案名称(见内置图案)
backgroundColorstring | null否背景色
foregroundColorstring | null否前景色
scalenumber | null否缩放比例

PatternStyle

PatternStyle 为 PatternConfig 的公共样式片段,字段含义同上:backgroundColor、foregroundColor、scale。

GradientConfig

渐变配置的联合类型:

TS
type GradientConfig = LinearGradient | RadialGradient;

LinearGradient

属性类型必填说明
type'linear-gradient'是线性渐变类型
colorsstring[] | { color: string; offset: string }[]否渐变色列表
anglenumber否渐变角度

RadialGradient

属性类型必填说明
type'radial-gradient'是径向渐变类型
colorsstring[] | { color: string; offset: string }[]否渐变色列表

TemplateOptions

在 InfographicOptions 的基础上移除了 container、template、data 属性。

TS
type TemplateOptions = Omit< InfographicOptions, 'container' | 'template' | 'data' >;

其他类型

WithType

为任意类型追加 type 字段,常用于显式声明组件类型:

TS
type WithType\<T\> = T & {type: string};

WithProps

为任意类型附加 props 扩展字段,便于携带渲染所需的额外参数:

TS
type WithProps<T, P = any> = T & {props?: P};
Previous配置项
Next导出内容

AntV Infographic
Copyright © Ant Group Co.
Docs
Quick Start
Core Concepts
Custom Design
Infographic Theory
API Reference
JSX
API
Design Assets
More
More Examples
AI Generated Infographics
GitHub
Contribute
Friendly Links
AntV
G2
G6
L7
TS
type Bounds = {x: number; y: number; width: number; height: number};
TS
interface JSXElement {
type: string | symbol | ((props?: any) => JSXNode); // 节点类型
props: Record<string, any>; // 属性对象
key?: string | null; // 可选稳定标识
}
TS
type JSXNode =
| JSXElement
| string
| number
| boolean
| null
| undefined
| JSXNode[];
TS
type ComponentType<P = {}> = (props: P & {children?: JSXNode}) => JSXNode; // 输入包含 children,输出 JSXNode
TS
type Padding = number | number[];
TS
type ExportOptions = SVGExportOptions | PNGExportOptions;
TS
type ItemOptions = Partial<BaseItemProps>;
TS
interface Item<T extends BaseItemProps = BaseItemProps> {
component: ComponentType<T>; // 用于渲染的组件
composites: string[]; // 可组合的结构类型
options?: ItemOptions; // 默认项配置
}
TS
interface BaseStructureProps {
Title?: ComponentType<Pick<TitleProps, 'title' | 'desc'>>; // 可选标题组件
Item: ComponentType<
Omit<BaseItemProps, 'themeColors'> &
Partial<Pick<BaseItemProps, 'themeColors'>>
>; // 当前层级数据项组件
Items: ComponentType<Omit<BaseItemProps, 'themeColors'>>[]; // 按层级选择的数据项组件列表
data: Data; // 完整数据
options: ParsedInfographicOptions; // 解析后的配置
}
TS
interface Structure {
component: ComponentType<BaseStructureProps>; // 结构组件实现
composites: string[]; // 结构包含组成部分,用于为 AI 生成类型说明
}
TS
type StructureOptions = Record<string, any>;
TS
type FontWeightName =
| 'thin'
| 'extralight'
| 'light'
| 'regular'
| 'medium'
| 'semibold'
| 'bold'
| 'extrabold'
| 'black'
| 'extrablack';

interface Font {
fontFamily: string; // 字体族名
name: string; // 展示用名称
baseUrl: string; // 字体文件基地址或 CSS 地址
fontWeight: {[keys in FontWeightName]?: string}; // 各字重映射到实际资源
}
TS
type ElementProps = GeometryProps | TextProps;

interface GeometryProps {
type:
| 'rectangle'
| 'circle'
| 'ellipse'
| 'line'
| 'polyline'
| 'polygon'
| 'path'
| 'image';
attributes: Record<string, any>;
}

interface TextProps {
type: 'text';
textContent: string;
attributes: TextAttributes;
}
TS
interface IPlugin {
name: string;
init(options: {
emitter: any;
editor: any;
commander: any;
plugin: any;
state: any;
}): void;
destroy(): void;
}
TS
interface IInteraction {
name: string;
init(options: {emitter: any; editor: any; commander: any; interaction: any}): void;
destroy(): void;
}
TS
type ResourceLoader = (
config: ResourceConfig
) => Promise<SVGSymbolElement | null>;
TS
type DynamicAttributes<T extends object> = {
[key in keyof T]?:
| T[key]
| ((value: T[key], node: SVGElement) => T[key] | undefined);
};
TS
type Palette =
| string
| string[]
| ((ratio: number, index: number, count: number) => string);
TS
type StylizeConfig = RoughConfig | PatternConfig | GradientConfig;
TS
type GradientConfig = LinearGradient | RadialGradient;
TS
type TemplateOptions = Omit<
InfographicOptions,
'container' | 'template' | 'data'
>;
TS
type WithType\<T\> = T & {type: string};
TS
type WithProps<T, P = any> = T & {props?: P};