Skip to content

feat: add unified annotation system - #436

Open
interstellarmt wants to merge 1 commit into
aifrom
feat/annotation-v0-1
Open

feat: add unified annotation system #436
interstellarmt wants to merge 1 commit into
aifrom
feat/annotation-v0-1

Conversation

@interstellarmt

Copy link
Copy Markdown
Member
  • 为 GPT-Vis 建立通用 Annotation 系统,并完成 Line 图表的首个适配版本
image

里程碑

阶段 目标 当前状态
V0.1 定义通用 Annotation 协议,完成 Line 图表和四类基础标注 ✅ 本 PR 已完成
V0.2 将通用协议适配到其他笛卡尔图表,如 Area、Column、Bar、Scatter ⏳ 待开始
V0.3 扩展饼图、漏斗图、关系图等非笛卡尔图表的目标定位与标注能力 ⏳ 待开始
V0.4 增加统一的全局图表样式定制,包括 Annotation、坐标轴等视觉配置 ⏳ 待开始
V0.5 增加 Annotation 事件和结构化 diagnostics,支持上层应用联动 ⏳ 待开始

新增标注类型

英文名 中文名 作用
reference-line 参考线 在指定的 X 或 Y 值上绘制参考线,例如目标线、均值线或事件时间线
reference-band 参考区间 标记一段连续的 X 或 Y 范围,例如正常区间、目标区间或活动周期
highlight 数据高亮 强调图表中的指定数据点,突出异常值或关键数据
callout 文字标注 在指定数据点旁显示解释文字,说明变化原因或分析结论

配置说明

{
  type: 'reference-band',
  channel: 'y',
  from: 90,
  to: 110,
  label: '健康区间',
  tone: 'positive',
}
参数 示例值 作用
type 'reference-band' 指定 Annotation 类型为参考区间,用连续色带标记一段范围
channel 'y' 指定区间作用于 Y 轴;设置为 'x' 时表示 X 轴区间
from 90 区间起始值
to 110 区间结束值,必须与 from 类型一致且大于起始值
label '健康区间' 显示在参考区间旁的说明文字,可选
tone 'positive' 使用正向语义色呈现标注;还支持 neutralinfowarningnegative

Copilot AI lite review requested due to automatic review settings September 9, 2026 07:47
@changeset-bot

changeset-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a37c953

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

✅ Preview is ready!

PR preview ✅ Ready ✅ Ready
🔗 Preview https://antvis-GPT-Vis-preview-pr-436.surge.sh
📝 Commita37c953
⏱️ Build time0.01s
📦 Size8.8 MB · 181 files
🪵 LogsView logs
📱 MobileScan to open preview on mobile

↩️ Previous: ⚡️ a37c953 · antvis-GPT-Vis-preview-pr-436.surge.sh (open ↗) · 2026-09-09 07:49:14 UTC

🤖 Powered by surge-preview

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Annotation normalization currently allows string values for channel: 'y' reference annotations, which can silently generate invalid numeric-axis marks without diagnostics.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR introduces a unified, reusable Annotation system for GPT-Vis and wires it into the Line chart as the first adapted chart type, including initial test coverage for annotation compilation and layering.

Changes:

  • Added a new src/annotation/ module (types, theme, normalization, and Cartesian compilation) to support reference lines/bands and data-targeted highlight/callout annotations.
  • Integrated annotation compilation into src/vis/line/index.ts, inserting background annotations before data marks and foreground annotations after data marks, with diagnostics reporting.
  • Added Vitest coverage for annotation normalization/compilation and Line chart child-mark ordering with annotations.
File summaries
File Description
src/vis/line/index.ts Accepts annotations in LineConfig and injects compiled annotation marks into the G2 children pipeline.
src/index.ts Re-exports public annotation-related TypeScript types from the package entry point.
src/annotation/types.ts Defines the unified annotation protocol (types + diagnostics) and AnnotatableConfig.
src/annotation/theme.ts Adds tone-based and theme-aware visual tokens for annotations.
src/annotation/normalize.ts Normalizes/validates annotation inputs and produces diagnostics for invalid entries.
src/annotation/index.ts Barrel exports for annotation module APIs and types.
src/annotation/cartesian.ts Compiles normalized Cartesian annotations into G2 mark definitions (background/foreground) and reports diagnostics.
tests/line.test.ts Adds Line annotation rendering/ordering tests with a mocked G2 Chart.
tests/annotation.test.ts Adds unit tests for annotation normalization and Cartesian compilation behavior.
Review details

Suppressed comments (1)

src/annotation/normalize.ts:119

  • reference-band validation also allows string from/to when channel: 'y'. For numeric Y axes this can lead to invalid rangeY marks without any diagnostic. Tighten the check so Y bands require finite numbers, while X bands can still be string/number as today.
      const validValues =
        isValidValue(annotation.from) &&
        isValidValue(annotation.to) &&
        hasValidOptionalLabel(annotation.label);
      const matchingTypes = typeof annotation.from === typeof annotation.to;
  • Files reviewed: 9/9 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +89 to +104
if (annotation.type === 'reference-line') {
if (
(annotation.channel !== 'x' && annotation.channel !== 'y') ||
!isValidValue(annotation.value) ||
!hasValidOptionalLabel(annotation.label)
) {
diagnostics.push({
code: 'INVALID_ANNOTATION_VALUE',
message: `Invalid reference line at index ${index}.`,
});
continue;
}

normalized.push(annotation as unknown as Annotation);
continue;
}
@hustcc

hustcc commented Sep 9, 2026

Copy link
Copy Markdown
Member

@interstellarmt 有几种 annotation?分别长什么样子,目前看示例中的圆点的 ui 不好看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants