Skip to content

fix: 修复 mini 折线图只有一个有效值时绘制异常的问题 - #3312

Merged
Alexzjt merged 4 commits into
nextfrom
copilot/fix-mini-line-chart-bug
Jan 31, 2026
Merged

Alexzjt merged 4 commits into
nextfrom
copilot/fix-mini-line-chart-bug

Conversation

Copilot AI commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Solve the issue and close #3311
当 mini 折线图数据中只有一个有效值(其他为 NaN)时,原实现会绘制一条横线,这在数据可视化语义上是错误的。

修改内容

  • 新增 filterValidChartData 函数:过滤掉 y 值为 NaN 的数据点
  • 修改 drawLine 函数逻辑:
    • 过滤后无有效数据时不绘制
    • 仅一个有效点时只画点,不画线(BI 领域通用共识)
  • 新增单元测试:覆盖 NaN 过滤和单点渲染场景

示例

// 原来:5个NaN + 1个有效值 → 绘制横线(错误)
// 现在:5个NaN + 1个有效值 → 绘制单点(正确)
const chartData = {
  type: 'line',
  data: [
    { year: '2017', value: NaN },
    { year: '2018', value: NaN },
    { year: '2019', value: NaN },
    { year: '2020', value: NaN },
    { year: '2021', value: NaN },
    { year: '2022', value: 168 },  // 唯一有效值
  ],
  encode: { x: 'year', y: 'value' },
};
Before After
❌ image ✅ image
Original prompt

分析issue #3311 是否是本仓库的代码bug,如果是,请进行修复,并解释修复思路。最终提交的PullRequest的标题和描述都应该是中文的。Pull Request的描述中需要包含 。Solve the issue and close #3311
✔ 当 mini 折线图只有一个有效值时
✔ 正确做法是「画一个点,而不是一条线」
✔ 画线在语义上是错误的,会误导用户
✔ 这是 BI / 数据可视化领域的通用共识
✔ S2 如果这样处理,会显得非常专业


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 30, 2026 14:19
Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>
Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>
Copilot AI changed the title [WIP] 修复 mini 折线图的显示逻辑 fix: 修复 mini 折线图只有一个有效值时绘制异常的问题 Jan 30, 2026
Copilot AI requested a review from Alexzjt January 30, 2026 14:26
@Alexzjt
Alexzjt marked this pull request as ready for review January 30, 2026 14:29
@github-actions github-actions Bot added pr(fix) bug fix next 2.0-next 版本的问题 labels Jan 30, 2026
@codecov-commenter

codecov-commenter commented Jan 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.48148% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.80%. Comparing base (ecdc9c8) to head (c2f6d18).
⚠️ Report is 775 commits behind head on next.

Files with missing lines Patch % Lines
packages/s2-core/src/utils/g-mini-charts.ts 81.48% 1 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3312      +/-   ##
==========================================
+ Coverage   75.77%   78.80%   +3.03%     
==========================================
  Files         257      224      -33     
  Lines       11994    12435     +441     
  Branches     2464     2807     +343     
==========================================
+ Hits         9088     9799     +711     
+ Misses       1398      946     -452     
- Partials     1508     1690     +182     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Size Change: +165 B (+0.02%)

Total Size: 740 kB

Filename Size Change
./packages/s2-core/dist/s2-extends.min.js 207 kB +68 B (+0.03%)
./packages/s2-core/dist/s2.min.js 308 kB +97 B (+0.03%)
ℹ️ View Unchanged
Filename Size
./packages/s2-core/dist/s2.min.css 581 B
./packages/s2-react-components/dist/s2-react-components.min.css 2.55 kB
./packages/s2-react-components/dist/s2-react-components.min.js 123 kB
./packages/s2-react/dist/s2-react.min.css 1.3 kB
./packages/s2-react/dist/s2-react.min.js 38.5 kB
./packages/s2-vue/dist/s2-vue.min.css 3.8 kB
./packages/s2-vue/dist/s2-vue.min.js 54.2 kB

compressed-size-action

@Alexzjt
Alexzjt merged commit 424e769 into next Jan 31, 2026
11 checks passed
@Alexzjt
Alexzjt deleted the copilot/fix-mini-line-chart-bug branch January 31, 2026 06:31
Laffery pushed a commit to Laffery/S2 that referenced this pull request Jul 17, 2026
* Initial plan

* fix: 修复 mini 折线图只有一个有效值时绘制异常的问题

Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>

* chore: 移除对 pnpm-workspace.yaml 的无关修改

Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>

* fix: 在 scale 函数中处理数据点只有 1 个(或少于 1 个)的特殊情况,避免除以零

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>
Co-authored-by: zjt <alex_zjt@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

next 2.0-next 版本的问题 pr(fix) bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛自定义绘制mini图 NaN值绘制异常

3 participants