diff --git a/site/.vitepress/config.mts b/site/.vitepress/config.mts index 82f007fa..51ed8f62 100644 --- a/site/.vitepress/config.mts +++ b/site/.vitepress/config.mts @@ -12,6 +12,7 @@ const createLangConfig = (lang: string, label: string) => { nav: [ { text: 'AI', link: '/chat/index', target: 'chat' }, { text: 'Tutorial', link: `/${lang}/tutorial/quick-start` }, + { text: 'Examples', link: `/${lang}/examples` }, { text: 'Syntax', link: `/${lang}/syntax/index` }, { text: 'API', link: `/${lang}/api/` }, ], diff --git a/site/.vitepress/theme/components/T8Example.vue b/site/.vitepress/theme/components/T8Example.vue new file mode 100644 index 00000000..a2417490 --- /dev/null +++ b/site/.vitepress/theme/components/T8Example.vue @@ -0,0 +1,145 @@ + + + + + diff --git a/site/.vitepress/theme/index.ts b/site/.vitepress/theme/index.ts index 5d151df9..cf42d825 100644 --- a/site/.vitepress/theme/index.ts +++ b/site/.vitepress/theme/index.ts @@ -4,6 +4,7 @@ import type { Theme } from 'vitepress'; import DefaultTheme from 'vitepress/theme'; import './style.css'; import CopyOrDownloadAsMarkdownButtons from './components/CopyOrDownloadAsMarkdownButtons.vue'; +import T8Example from './components/T8Example.vue'; import { Sandbox } from 'vitepress-plugin-sandpack'; import MySandbox from './components/MySandbox.vue'; import 'vitepress-plugin-sandpack/dist/style.css'; @@ -17,6 +18,7 @@ export default { }, enhanceApp({ app }) { app.component('CopyOrDownloadAsMarkdownButtons', CopyOrDownloadAsMarkdownButtons); + app.component('T8Example', T8Example); app.component('Sandbox', Sandbox); app.component('MySandbox', MySandbox); }, diff --git a/site/en/examples.md b/site/en/examples.md new file mode 100644 index 00000000..1da4f739 --- /dev/null +++ b/site/en/examples.md @@ -0,0 +1,105 @@ +--- +title: Interactive Examples +--- + + + +# Interactive Examples + +Explore comprehensive examples of T8 features and capabilities. Each example demonstrates different aspects of T8's text visualization power and includes the full T8 Syntax source code. + +## Example: 2024 Smartphone Market Analysis + +This comprehensive example showcases T8's capabilities for rendering data-driven narrative text with rich entity annotations and inline visualizations. The example includes: + +- Multiple entity types (metrics, dimensions, trends, ratios, etc.) +- Inline mini-charts (distributions, correlations, seasonality) +- Complex data relationships (rankings, proportions, comparisons) +- Structured markdown with sections and subsections + +### Streaming Render + +Watch the content render incrementally, simulating real-time data streaming or AI-generated content. Perfect for scenarios where data arrives progressively. + + + +### Dark Theme with Custom Settings + +The same content rendered with a dark theme and custom typography settings (12px font size, 20px line height). + + + +### Custom Plugin - Styled Dimension Values + +This example demonstrates how to customize entity rendering using plugins. Here, dimension values (like country/region names) are styled with custom colors and fonts. + + + +## Understanding T8 Syntax + +The examples above use **T8 Syntax** - a markdown-based declarative language for narrative text visualization. Key features demonstrated: + +### Entity Annotations + +Entities are marked using bracket notation: `[text](entity_type, properties)` + +- `[smartphone shipments](metric_name)` - Metric names +- `[1.2 billion units](metric_value, origin=1200000000)` - Metric values with raw data +- `[2024](time_desc)` - Time descriptions +- `[modest decline of 2.1%](ratio_value, origin=-0.021, assessment="negative")` - Ratios with sentiment +- `[Asia-Pacific](dim_value)` - Dimension values (categories, regions, etc.) +- `[resilience](trend_desc, assessment="positive")` - Trend descriptions +- `[ranked 1st](rank, detail=[320, 180, 90, 65, 45])` - Rankings with data + +### Inline Visualizations + +- `[distribution](distribution, detail=[15, 25, 35, 15, 10])` - Mini bar charts +- `[strong correlation](association, detail=[...])` - Scatter plots +- `[clear seasonality](seasonality, detail={...})` - Line charts +- `[gap of 140M units](difference, detail=[200, 180, 160, 140])` - Difference indicators + +### Markdown Formatting + +Standard markdown syntax is supported: + +- `**bold**` for emphasis +- `*italic*` for subtle emphasis +- `__underline__` for highlighting +- Headers (`#`, `##`, `###`) for structure +- Lists (numbered and bulleted) +- Links + +Learn more in the [T8 Syntax Documentation](/en/syntax/). diff --git a/site/zh/examples.md b/site/zh/examples.md new file mode 100644 index 00000000..c498bbe1 --- /dev/null +++ b/site/zh/examples.md @@ -0,0 +1,105 @@ +--- +title: 交互式示例 +--- + + + +# 交互式示例 + +探索 T8 功能和特性的综合示例。每个示例展示了 T8 文本可视化能力的不同方面,并包含完整的 T8 语法源代码。 + +## 示例:2024 年智能手机市场分析 + +这个综合示例展示了 T8 在渲染具有丰富实体注释和内联可视化的数据驱动叙事文本方面的能力。该示例包括: + +- 多种实体类型(指标、维度、趋势、比率等) +- 内联迷你图表(分布、相关性、季节性) +- 复杂的数据关系(排名、比例、比较) +- 带有章节和小节的结构化 Markdown + +### 流式渲染 + +观看内容逐步渲染,模拟实时数据流或 AI 生成的内容。非常适合数据逐步到达的场景。 + + + +### 暗色主题与自定义设置 + +使用暗色主题和自定义排版设置(12px 字体大小,20px 行高)渲染相同的内容。 + + + +### 自定义插件 - 样式化维度值 + +此示例展示了如何使用插件自定义实体渲染。在这里,维度值(如国家/地区名称)使用自定义颜色和字体进行样式化。 + + + +## 理解 T8 语法 + +以上示例使用 **T8 语法** - 一种基于 Markdown 的声明式语言,用于叙事文本可视化。演示的主要功能: + +### 实体注释 + +实体使用括号表示法标记:`[文本](entity_type, properties)` + +- `[智能手机出货量](metric_name)` - 指标名称 +- `[12 亿台](metric_value, origin=1200000000)` - 带有原始数据的指标值 +- `[2024 年](time_desc)` - 时间描述 +- `[适度下降 2.1%](ratio_value, origin=-0.021, assessment="negative")` - 带有情感的比率 +- `[亚太地区](dim_value)` - 维度值(类别、地区等) +- `[韧性](trend_desc, assessment="positive")` - 趋势描述 +- `[排名第 1](rank, detail=[320, 180, 90, 65, 45])` - 带有数据的排名 + +### 内联可视化 + +- `[分布](distribution, detail=[15, 25, 35, 15, 10])` - 迷你条形图 +- `[强相关性](association, detail=[...])` - 散点图 +- `[明显的季节性](seasonality, detail={...})` - 折线图 +- `[1.4 亿台差距](difference, detail=[200, 180, 160, 140])` - 差异指示器 + +### Markdown 格式 + +支持标准 Markdown 语法: + +- `**粗体**` 表示强调 +- `*斜体*` 表示轻微强调 +- `__下划线__` 表示突出显示 +- 标题(`#`、`##`、`###`)用于结构 +- 列表(编号和项目符号) +- 链接 + +在 [T8 语法文档](/zh/syntax/)中了解更多。 diff --git a/src/charts/utils/createSvg.ts b/src/charts/utils/createSvg.ts index 26d44f05..fe397c30 100644 --- a/src/charts/utils/createSvg.ts +++ b/src/charts/utils/createSvg.ts @@ -12,6 +12,7 @@ export const createSvg = (container: Element, width: number, height: number): Se const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.style.margin = '0px 4px'; svg.style.transform = 'translate(0px, 0.125em)'; + svg.style.display = 'inline-block'; svg.setAttribute('height', String(height)); svg.setAttribute('width', String(width)); diff --git a/src/plugin/presets/createCompare.ts b/src/plugin/presets/createCompare.ts index a42fd4a3..c6e21180 100644 --- a/src/plugin/presets/createCompare.ts +++ b/src/plugin/presets/createCompare.ts @@ -74,6 +74,7 @@ function createArrow(direction: 'up' | 'down', size: number): Element { svg.setAttribute('height', `${size}px`); svg.setAttribute('viewBox', '0 0 8 9'); svg.style.marginRight = `${MARGIN_RIGHT}px`; + svg.style.display = 'inline-block'; svg.setAttribute('version', '1.1'); const g = document.createElementNS('http://www.w3.org/2000/svg', 'g');