infographic-creation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
An infographic (Infographic) transforms data, information, and knowledge into perceivable visual language. It combines visual design with data visualization, using intuitive symbols to compress complex information and help audiences quickly understand and remember key points.
Infographic = Information Structure + Visual Expression
This is a task that utilizes AntV Infographic to create visual infographics.
Before you start the task, you need to understand the AntV Infographic Syntax specification, including template lists, data structures, themes, and more.
信息图(Infographic)将数据、信息和知识转化为可感知的视觉语言。它结合视觉设计与数据可视化,通过直观的符号压缩复杂信息,帮助受众快速理解并记住关键点。
Infographic = 信息结构 + 视觉表达
本任务将使用AntV Infographic创建可视化信息图。
开始任务前,你需要了解AntV Infographic语法规范,包括模板列表、数据结构、主题等内容。

SPECs

规范说明

AntV Infographic Syntax

AntV Infographic语法

AntV Infographic Syntax is a mermaid-like DSL for describing infographic rendering configuration. It uses indentation to describe information, has strong robustness, and makes it easy to render infographics through AI streaming output. It mainly contains the following information:
  1. template: Use template to express text information structure.
  2. data: the infographic data, which contains title, desc, items, etc. The items is an array containing label, value, desc, icon, children, etc.
  3. theme: Theme contains palette, font, and other styling options.
e.g.:
plain
infographic list-row-horizontal-icon-arrow
data
  title Title
  desc Description
  items
    - label Label
      value 12.5
      desc Explanation
      icon mdi/rocket-launch
theme
  palette #3b82f6 #8b5cf6 #f97316
AntV Infographic语法是一种类Mermaid的DSL,用于描述信息图的渲染配置。它使用缩进描述信息,鲁棒性强,便于通过AI流式输出来渲染信息图。主要包含以下内容:
  1. template:用于表达文本信息结构的模板。
  2. data:信息图数据,包含标题、描述、条目等。条目是一个数组,包含标签、数值、描述、图标、子项等。
  3. theme:主题包含调色板、字体等样式选项。
示例:
plain
infographic list-row-horizontal-icon-arrow
data
  title Title
  desc Description
  items
    - label Label
      value 12.5
      desc Explanation
      icon mdi/rocket-launch
theme
  palette #3b82f6 #8b5cf6 #f97316

The Syntax

语法规则

  • The first line starts with
    infographic <template-name>
    , and the template is selected from the list below (the Available Templates section).
  • Use blocks to describe data / theme, with two-space indentation
  • Key-value pairs are expressed as "key value", and arrays are expressed as "-" items
  • The icon value is provided directly with keywords or icon names (such as
    mdi/chart-line
    )
  • data
    should contain title/desc/items (which can be omitted according to semantics)
  • data.items
    should contain label(string)/value(number)/desc(string)/icon(string)/children(object), where children represents the hierarchical structure
  • For comparison templates (template names starting with
    compare-
    ), construct exactly two root nodes and place every comparison item under them as children to keep the hierarchy clear
  • theme
    field is for customizing the theme of the infographic, including palette, font, etc. e.g. dark theme with custom palette:
    plain
    infographic list-row-simple-horizontal-arrow
    theme dark
      palette
        - #61DDAA
        - #F6BD16
        - #F08BB4
    data
      items
        - label Step 1
          desc Start
        - label Step 2
          desc In Progress
        - label Step 3
          desc Complete
  • Use
    theme.base.text.font-family
    to specify fonts, such as the handwriting style '851tegakizatsu'
  • Use
    theme.stylize
    to select built-in styles and pass parameters Common stylization types include:
    • rough
      : Apply hand-drawn style to make graphics look like they were drawn by hand.
    • pattern
      : Apply pattern fill to add repeated pattern effects to graphics.
    • linear-gradient
      /
      radial-gradient
      : Apply gradient fill to add linear or radial gradient effects to graphics.
    e.g: Hand-drawn style (rough):
    plain
    infographic list-row-simple-horizontal-arrow
    theme
      stylize rough
      base
        text
          font-family 851tegakizatsu
    data
      items
        - label Step 1
          desc Start
        - label Step 2
          desc In Progress
        - label Step 3
          desc Complete
Typescript definition for data field:
ts
interface Data {
  title?: string;
  desc?: string;
  items: ItemDatum[];
  [key: string]: any;
}

interface ItemDatum {
  icon?: string;
  label?: string;
  desc?: string;
  value?: number;
  illus?: string;
  children?: ItemDatum[];
  [key: string]: any;
}
  • 第一行以
    infographic <template-name>
    开头,模板从下方的「可用模板」列表中选择。
  • 使用代码块描述data / theme,采用两个空格缩进
  • 键值对以「key value」形式表示,数组以「-」条目形式表示
  • 图标值直接使用关键词或图标名称(如
    mdi/chart-line
  • data
    应包含title/desc/items(可根据语义省略)
  • data.items
    应包含label(字符串)/value(数值)/desc(字符串)/icon(字符串)/children(对象),其中children表示层级结构
  • 对于对比类模板(名称以
    compare-
    开头),需构建恰好两个根节点,并将所有对比项作为子项置于其下,以保持层级清晰
  • theme
    字段用于自定义信息图主题,包括调色板、字体等 示例:带自定义调色板的深色主题:
    plain
    infographic list-row-simple-horizontal-arrow
    theme dark
      palette
        - #61DDAA
        - #F6BD16
        - #F08BB4
    data
      items
        - label Step 1
          desc Start
        - label Step 2
          desc In Progress
        - label Step 3
          desc Complete
  • 使用
    theme.base.text.font-family
    指定字体,例如手写风格的'851tegakizatsu'
  • 使用
    theme.stylize
    选择内置样式并传递参数 常见样式类型包括:
    • rough
      :应用手绘风格,使图形看起来像是手绘的。
    • pattern
      :应用图案填充,为图形添加重复图案效果。
    • linear-gradient
      /
      radial-gradient
      :应用渐变填充,添加线性或径向渐变效果。
    示例:手绘风格(rough):
    plain
    infographic list-row-simple-horizontal-arrow
    theme
      stylize rough
      base
        text
          font-family 851tegakizatsu
    data
      items
        - label Step 1
          desc Start
        - label Step 2
          desc In Progress
        - label Step 3
          desc Complete
数据字段的Typescript定义:
ts
interface Data {
  title?: string;
  desc?: string;
  items: ItemDatum[];
  [key: string]: any;
}

interface ItemDatum {
  icon?: string;
  label?: string;
  desc?: string;
  value?: number;
  illus?: string;
  children?: ItemDatum[];
  [key: string]: any;
}

Icon and Illustration Resources

图标与插图资源

Icons (from Iconify):
  • Format:
    <collection>/<icon-name>
    , e.g.,
    mdi/rocket-launch
  • Popular collections:
    • mdi/*
      - Material Design Icons (most commonly used)
    • fa/*
      - Font Awesome
    • bi/*
      - Bootstrap Icons
    • heroicons/*
      - Heroicons
  • Browse at: https://icon-sets.iconify.design/
  • Common icon examples:
    • Tech:
      mdi/code-tags
      ,
      mdi/database
      ,
      mdi/api
      ,
      mdi/cloud
    • Business:
      mdi/chart-line
      ,
      mdi/briefcase
      ,
      mdi/currency-usd
    • Process:
      mdi/check-circle
      ,
      mdi/arrow-right
      ,
      mdi/cog
    • People:
      mdi/account
      ,
      mdi/account-group
      ,
      mdi/shield-account
Illustrations (from unDraw):
  • Format: illustration filename (without .svg), e.g.,
    coding
  • Browse at: https://undraw.co/illustrations
  • Common themes:
    • Tech:
      coding
      ,
      programmer
      ,
      server
      ,
      cloud-sync
    • Business:
      business-plan
      ,
      team-work
      ,
      analytics
    • Abstract:
      abstract
      ,
      building-blocks
      ,
      connection
  • Note: Use sparingly as illustrations are larger and more detailed than icons
Usage Tips:
  • For
    sequence-*
    and
    list-*
    templates → use
    icon
  • For larger illustration needs → use
    illus
  • Not all templates support both icon and illus - refer to template examples
图标(来自Iconify):
  • 格式:
    <collection>/<icon-name>
    ,例如
    mdi/rocket-launch
  • 热门图标库:
    • mdi/*
      - Material Design Icons(最常用)
    • fa/*
      - Font Awesome
    • bi/*
      - Bootstrap Icons
    • heroicons/*
      - Heroicons
  • 浏览地址:https://icon-sets.iconify.design/
  • 常见图标示例:
    • 科技类:
      mdi/code-tags
      ,
      mdi/database
      ,
      mdi/api
      ,
      mdi/cloud
    • 商务类:
      mdi/chart-line
      ,
      mdi/briefcase
      ,
      mdi/currency-usd
    • 流程类:
      mdi/check-circle
      ,
      mdi/arrow-right
      ,
      mdi/cog
    • 人物类:
      mdi/account
      ,
      mdi/account-group
      ,
      mdi/shield-account
插图(来自unDraw):
  • 格式:插图文件名(不含.svg),例如
    coding
  • 浏览地址:https://undraw.co/illustrations
  • 常见主题:
    • 科技类:
      coding
      ,
      programmer
      ,
      server
      ,
      cloud-sync
    • 商务类:
      business-plan
      ,
      team-work
      ,
      analytics
    • 抽象类:
      abstract
      ,
      building-blocks
      ,
      connection
  • 注意:插图比图标更大、更详细,应谨慎使用
使用技巧:
  • 对于
    sequence-*
    list-*
    模板 → 使用
    icon
  • 若需要更大的插图 → 使用
    illus
  • 并非所有模板都同时支持icon和illus,请参考模板示例

Available Templates

可用模板

  • sequence-zigzag-steps-underline-text
  • sequence-horizontal-zigzag-underline-text
  • sequence-horizontal-zigzag-simple-illus
  • sequence-circular-simple
  • sequence-filter-mesh-simple
  • sequence-mountain-underline-text
  • sequence-cylinders-3d-simple
  • sequence-color-snake-steps-horizontal-icon-line
  • sequence-pyramid-simple
  • sequence-roadmap-vertical-simple
  • sequence-roadmap-vertical-plain-text
  • sequence-zigzag-pucks-3d-simple
  • sequence-ascending-steps
  • sequence-ascending-stairs-3d-underline-text
  • sequence-snake-steps-compact-card
  • sequence-snake-steps-underline-text
  • sequence-snake-steps-simple
  • sequence-stairs-front-compact-card
  • sequence-stairs-front-pill-badge
  • sequence-timeline-simple
  • sequence-timeline-rounded-rect-node
  • sequence-timeline-simple-illus
  • compare-binary-horizontal-simple-fold
  • compare-hierarchy-left-right-circle-node-pill-badge
  • compare-swot
  • quadrant-quarter-simple-card
  • quadrant-quarter-circular
  • quadrant-simple-illus
  • relation-circle-icon-badge
  • relation-circle-circular-progress
  • compare-binary-horizontal-badge-card-arrow
  • compare-binary-horizontal-underline-text-vs
  • hierarchy-tree-tech-style-capsule-item
  • hierarchy-tree-curved-line-rounded-rect-node
  • hierarchy-tree-tech-style-badge-card
  • chart-column-simple
  • chart-bar-plain-text
  • chart-line-plain-text
  • chart-pie-plain-text
  • chart-pie-compact-card
  • chart-pie-donut-plain-text
  • chart-pie-donut-pill-badge
  • chart-wordcloud
  • list-grid-badge-card
  • list-grid-candy-card-lite
  • list-grid-ribbon-card
  • list-row-horizontal-icon-arrow
  • list-row-simple-illus
  • list-sector-plain-text
  • list-column-done-list
  • list-column-vertical-icon-arrow
  • list-column-simple-vertical-arrow
Template Selection Guidelines:
  • For strict sequential order: processes/steps/development trends →
    sequence-*
    series
    • Timeline →
      sequence-timeline-*
    • Staircase diagram →
      sequence-stairs-*
    • Roadmap →
      sequence-roadmap-vertical-*
    • Zigzag steps →
      sequence-zigzag-*
    • Circular progress →
      sequence-circular-simple
    • Color snake steps →
      sequence-color-snake-steps-*
    • Pyramid diagram →
      sequence-pyramid-simple
  • For listing viewpoints →
    list-row-*
    series or
    list-column-*
    series
  • For comparative analysis (comparing pros and cons of two parties) →
    compare-binary-*
    series
  • For SWOT analysis →
    compare-swot
  • For hierarchical structure (tree diagram) →
    hierarchy-tree-*
  • For data charts →
    chart-*
    series
  • For quadrant analysis →
    quadrant-*
    series
  • For grid lists (bullet points) →
    list-grid-*
    series
  • For relationship display →
    relation-circle-*
  • For word cloud →
    chart-wordcloud
  • sequence-zigzag-steps-underline-text
  • sequence-horizontal-zigzag-underline-text
  • sequence-horizontal-zigzag-simple-illus
  • sequence-circular-simple
  • sequence-filter-mesh-simple
  • sequence-mountain-underline-text
  • sequence-cylinders-3d-simple
  • sequence-color-snake-steps-horizontal-icon-line
  • sequence-pyramid-simple
  • sequence-roadmap-vertical-simple
  • sequence-roadmap-vertical-plain-text
  • sequence-zigzag-pucks-3d-simple
  • sequence-ascending-steps
  • sequence-ascending-stairs-3d-underline-text
  • sequence-snake-steps-compact-card
  • sequence-snake-steps-underline-text
  • sequence-snake-steps-simple
  • sequence-stairs-front-compact-card
  • sequence-stairs-front-pill-badge
  • sequence-timeline-simple
  • sequence-timeline-rounded-rect-node
  • sequence-timeline-simple-illus
  • compare-binary-horizontal-simple-fold
  • compare-hierarchy-left-right-circle-node-pill-badge
  • compare-swot
  • quadrant-quarter-simple-card
  • quadrant-quarter-circular
  • quadrant-simple-illus
  • relation-circle-icon-badge
  • relation-circle-circular-progress
  • compare-binary-horizontal-badge-card-arrow
  • compare-binary-horizontal-underline-text-vs
  • hierarchy-tree-tech-style-capsule-item
  • hierarchy-tree-curved-line-rounded-rect-node
  • hierarchy-tree-tech-style-badge-card
  • chart-column-simple
  • chart-bar-plain-text
  • chart-line-plain-text
  • chart-pie-plain-text
  • chart-pie-compact-card
  • chart-pie-donut-plain-text
  • chart-pie-donut-pill-badge
  • chart-wordcloud
  • list-grid-badge-card
  • list-grid-candy-card-lite
  • list-grid-ribbon-card
  • list-row-horizontal-icon-arrow
  • list-row-simple-illus
  • list-sector-plain-text
  • list-column-done-list
  • list-column-vertical-icon-arrow
  • list-column-simple-vertical-arrow
模板选择指南:
  • 若展示严格的顺序关系:流程/步骤/发展趋势 → 使用
    sequence-*
    系列
    • 时间线 →
      sequence-timeline-*
    • 阶梯图 →
      sequence-stairs-*
    • 路线图 →
      sequence-roadmap-vertical-*
    • 之字形步骤 →
      sequence-zigzag-*
    • 环形进度 →
      sequence-circular-simple
    • 彩色蛇形步骤 →
      sequence-color-snake-steps-*
    • 金字塔图 →
      sequence-pyramid-simple
  • 若展示观点列表 → 使用
    list-row-*
    系列或
    list-column-*
    系列
  • 若进行对比分析(对比两方优缺点) → 使用
    compare-binary-*
    系列
  • 若进行SWOT分析 → 使用
    compare-swot
  • 若展示层级结构(树形图) → 使用
    hierarchy-tree-*
    系列
  • 若展示数据图表 → 使用
    chart-*
    系列
  • 若进行象限分析 → 使用
    quadrant-*
    系列
  • 若展示网格列表(项目符号) → 使用
    list-grid-*
    系列
  • 若展示关系 → 使用
    relation-circle-*
  • 若展示词云 → 使用
    chart-wordcloud

Example

示例

Draw an information graph of the Internet technology evolution
plain
infographic list-row-horizontal-icon-arrow
data
  title Internet Technology Evolution
  desc From Web 1.0 to AI era, key milestones
  items
    - time 1991
      label Web 1.0
      desc Tim Berners-Lee published the first website, opening the Internet era
      icon mdi/web
    - time 2004
      label Web 2.0
      desc Social media and user-generated content become mainstream
      icon mdi/account-multiple
    - time 2007
      label Mobile
      desc iPhone released, smartphone changes the world
      icon mdi/cellphone
    - time 2015
      label Cloud Native
      desc Containerization and microservices architecture are widely used
      icon mdi/cloud
    - time 2020
      label Low Code
      desc Visual development lowers the technology threshold
      icon mdi/application-brackets
    - time 2023
      label AI Large Model
      desc ChatGPT ignites the generative AI revolution
      icon mdi/brain
绘制互联网技术演进信息图
plain
infographic list-row-horizontal-icon-arrow
data
  title Internet Technology Evolution
  desc From Web 1.0 to AI era, key milestones
  items
    - time 1991
      label Web 1.0
      desc Tim Berners-Lee published the first website, opening the Internet era
      icon mdi/web
    - time 2004
      label Web 2.0
      desc Social media and user-generated content become mainstream
      icon mdi/account-multiple
    - time 2007
      label Mobile
      desc iPhone released, smartphone changes the world
      icon mdi/cellphone
    - time 2015
      label Cloud Native
      desc Containerization and microservices architecture are widely used
      icon mdi/cloud
    - time 2020
      label Low Code
      desc Visual development lowers the technology threshold
      icon mdi/application-brackets
    - time 2023
      label AI Large Model
      desc ChatGPT ignites the generative AI revolution
      icon mdi/brain

Example 2: Using Illustrations

示例2:使用插图

plain
infographic sequence-horizontal-zigzag-simple-illus
data
  title Product Development Phases
  desc Key stages in our development process
  items
    - label Research
      desc Understanding user needs
      illus user-research
    - label Design
      desc Creating user experience
      illus design-thinking
    - label Development
      desc Building the product
      illus coding
    - label Launch
      desc Going to market
      illus launch-day
plain
infographic sequence-horizontal-zigzag-simple-illus
data
  title Product Development Phases
  desc Key stages in our development process
  items
    - label Research
      desc Understanding user needs
      illus user-research
    - label Design
      desc Creating user experience
      illus design-thinking
    - label Development
      desc Building the product
      illus coding
    - label Launch
      desc Going to market
      illus launch-day

Creation Process

创建流程

Step 1: Understanding User Requirements

步骤1:理解用户需求

Before creating the infographic, it is important to understand the user's requirements and the information they want to present. This will help in defining the template and the data structure.
If the user provides a clear and concise description of the information they want to present, break down the information into a clear and concise structure.
Otherwise, ask the user for clarification (e.g., "Please provide a clear and concise description of the information you want to present.", "Which template would you prefer to use?")
  • Extract key information structure (title, description, items, etc).
  • Identify the required data fields (e.g., title, description, items, labels, values, icons, etc.).
  • Select an appropriate template.
  • Use the AntV Infographic Syntax to describe the content of the infographic
    {syntax}
    .
CRITICAL NOTE: Must respect the language of the user's input content. e.g. if the user's input content is in Chinese, the text content in infographic syntax must be in Chinese.
在创建信息图前,务必理解用户需求以及他们想要展示的信息。这将有助于确定模板和数据结构。
如果用户提供了清晰简洁的展示信息描述,请将信息拆解为清晰简洁的结构。
否则,请向用户请求澄清(例如:“请提供您想要展示的信息的清晰简洁描述。”,“您倾向于使用哪种模板?”)
  • 提取关键信息结构(标题、描述、条目等)。
  • 确定所需数据字段(例如:标题、描述、条目、标签、数值、图标等)。
  • 选择合适的模板。
  • 使用AntV Infographic语法描述信息图内容
    {syntax}
重要提示: 必须尊重用户输入内容的语言。例如,如果用户输入内容为中文,信息图语法中的文本内容必须为中文。

Step 2: Rendering the Infographic

步骤2:渲染信息图

Once you have the final AntV Infographic Syntax, you can generate the complete infographic HTML file by following these steps:
  1. Create a complete HTML file with the following structure:
    • DOCTYPE and HTML meta tags (charset: utf-8)
    • Title:
      {title} - Infographic
    • Include AntV Infographic library script:
      https://unpkg.com/@antv/infographic@latest/dist/infographic.min.js
    • Add a resource loader script that handles icon loading from Iconify and illustration loading from unDraw
    • Create a container div with id
      container
      where the infographic will render
    • Initialize the Infographic instance with
      width: '100%'
      and
      height: '100%'
    • Replace the placeholder
      {title}
      with the actual title
    • Replace the placeholder
      {syntax}
      with the actual AntV Infographic Syntax
    • Include export functionality that allows users to download the infographic as SVG
      const svgDataUrl = await infographic.toDataURL({ type: 'svg' });
The Html template you can follow:
html
<div id="container"></div>
<script src="https://unpkg.com/@antv/infographic@latest/dist/infographic.min.js"></script>
<script>
// Resource Loader Script
// Use the following resource loader script to handle icon and illustration loading:
const svgTextCache = new Map();
const pendingRequests = new Map();

AntVInfographic.registerResourceLoader(async (config) => {
    const { data, scene } = config;

    try {
        const key = `${scene}::${data}`;
        let svgText;

        // 1. Check cache
        if (svgTextCache.has(key)) {
            svgText = svgTextCache.get(key);
        }
        // 2. Check if request is already in progress
        else if (pendingRequests.has(key)) {
            svgText = await pendingRequests.get(key);
        }
        // 3. Make new request
        else {
            const fetchPromise = (async () => {
                try {
                    let url;

                    if (scene === 'icon') {
                        url = `https://api.iconify.design/${data}.svg`;
                    } else if (scene === 'illus') {
                        url = `https://raw.githubusercontent.com/balazser/undraw-svg-collection/refs/heads/main/svgs/${data}.svg`;
                    } else return null;

                    if (!url) return null;

                    const response = await fetch(url, { referrerPolicy: 'no-referrer' });

                    if (!response.ok) {
                        console.error(`HTTP ${response.status}: Failed to load ${url}`);
                        return null;
                    }

                    const text = await response.text();

                    if (!text || !text.trim().startsWith('<svg')) {
                        console.error(`Invalid SVG content from ${url}`);
                        return null;
                    }

                    svgTextCache.set(key, text);
                    return text;
                } catch (fetchError) {
                    console.error(`Failed to fetch resource ${key}:`, fetchError);
                    return null;
                }
            })();

            pendingRequests.set(key, fetchPromise);

            try {
                svgText = await fetchPromise;
            } catch (error) {
                pendingRequests.delete(key);
                console.error(`Error loading resource ${key}:`, error);
                return null;
            } finally {
                pendingRequests.delete(key);
            }
        }

        if (!svgText) {
            return null;
        }

        const resource = AntVInfographic.loadSVGResource(svgText);

        if (!resource) {
            console.error(`loadSVGResource returned null for ${key}`);
            svgTextCache.delete(key);
            return null;
        }

        return resource;
    } catch (error) {
        console.error('Unexpected error in resource loader:', error);
        return null;
    }
});
</script>
<script>
 const infographic = new AntVInfographic.Infographic({
    container: '#container',
    width: '100%',
    height: '100%',
  });
  infographic.render(`{syntax}`);
</script>
  1. Write the HTML file named
    <title>-infographic.html
    using the Write tool
  2. Display to the user:
    • The generated file path with instruction: "Open this file directly in a browser to view and save the SVG"
    • Display your output syntax with instruction: "If you need to adjust the template/colors/content, just let me know"
Note: The HTML file must include:
  • Complete resource loader for handling icon and illustration assets from external sources
  • SVG export functionality via the export button
  • Responsive container that takes 100% width and height
  • Proper error handling for failed resource loads
获得最终的AntV Infographic语法后,可按照以下步骤生成完整的信息图HTML文件:
  1. 创建具有以下结构的完整HTML文件:
    • DOCTYPE和HTML元标签(字符集:utf-8)
    • 标题:
      {title} - Infographic
    • 引入AntV Infographic库脚本:
      https://unpkg.com/@antv/infographic@latest/dist/infographic.min.js
    • 添加资源加载器脚本,处理来自Iconify的图标加载和来自unDraw的插图加载
    • 创建id为
      container
      的容器div,用于渲染信息图
    • 初始化Infographic实例,设置
      width: '100%'
      height: '100%'
    • 将占位符
      {title}
      替换为实际标题
    • 将占位符
      {syntax}
      替换为实际的AntV Infographic语法
    • 包含导出功能,允许用户将信息图下载为SVG:
      const svgDataUrl = await infographic.toDataURL({ type: 'svg' });
可遵循的HTML模板:
html
<div id="container"></div>
<script src="https://unpkg.com/@antv/infographic@latest/dist/infographic.min.js"></script>
<script>
// Resource Loader Script
// Use the following resource loader script to handle icon and illustration loading:
const svgTextCache = new Map();
const pendingRequests = new Map();

AntVInfographic.registerResourceLoader(async (config) => {
    const { data, scene } = config;

    try {
        const key = `${scene}::${data}`;
        let svgText;

        // 1. Check cache
        if (svgTextCache.has(key)) {
            svgText = svgTextCache.get(key);
        }
        // 2. Check if request is already in progress
        else if (pendingRequests.has(key)) {
            svgText = await pendingRequests.get(key);
        }
        // 3. Make new request
        else {
            const fetchPromise = (async () => {
                try {
                    let url;

                    if (scene === 'icon') {
                        url = `https://api.iconify.design/${data}.svg`;
                    } else if (scene === 'illus') {
                        url = `https://raw.githubusercontent.com/balazser/undraw-svg-collection/refs/heads/main/svgs/${data}.svg`;
                    } else return null;

                    if (!url) return null;

                    const response = await fetch(url, { referrerPolicy: 'no-referrer' });

                    if (!response.ok) {
                        console.error(`HTTP ${response.status}: Failed to load ${url}`);
                        return null;
                    }

                    const text = await response.text();

                    if (!text || !text.trim().startsWith('<svg')) {
                        console.error(`Invalid SVG content from ${url}`);
                        return null;
                    }

                    svgTextCache.set(key, text);
                    return text;
                } catch (fetchError) {
                    console.error(`Failed to fetch resource ${key}:`, fetchError);
                    return null;
                }
            })();

            pendingRequests.set(key, fetchPromise);

            try {
                svgText = await fetchPromise;
            } catch (error) {
                pendingRequests.delete(key);
                console.error(`Error loading resource ${key}:`, error);
                return null;
            } finally {
                pendingRequests.delete(key);
            }
        }

        if (!svgText) {
            return null;
        }

        const resource = AntVInfographic.loadSVGResource(svgText);

        if (!resource) {
            console.error(`loadSVGResource returned null for ${key}`);
            svgTextCache.delete(key);
            return null;
        }

        return resource;
    } catch (error) {
        console.error('Unexpected error in resource loader:', error);
        return null;
    }
});
</script>
<script>
 const infographic = new AntVInfographic.Infographic({
    container: '#container',
    width: '100%',
    height: '100%',
  });
  infographic.render(`{syntax}`);
</script>
  1. 使用Write工具将HTML文件命名为
    <title>-infographic.html
  2. 向用户展示:
    • 生成的文件路径及说明:“直接在浏览器中打开此文件即可查看并保存SVG”
    • 展示你的输出语法及说明:“若需要调整模板/颜色/内容,请随时告知我”
注意: HTML文件必须包含:
  • 完整的资源加载器,用于处理来自外部源的图标和插图资源
  • 通过导出按钮实现的SVG导出功能
  • 占满100%宽高的响应式容器
  • 针对资源加载失败的适当错误处理