Repository navigation
fix(vchart): restore Sankey overflow scrolling #4748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xile611
wants to merge
3
commits into
develop
Choose a base branch
from
codex/fix-4577-sankey-scrollbar
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+221
−12
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
common/changes/@visactor/vchart/codex-fix-4577-sankey-scrollbar_2026-11-23-08-47.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "comment": "修复设置 overflow: 'scroll' 的桑基图无法滚动的问题(#4577)。", | ||
| "type": "none", | ||
| "packageName": "@visactor/vchart" | ||
| } | ||
| ], | ||
| "packageName": "@visactor/vchart", | ||
| "email": "dingling112@gmail.com" | ||
| } |
38 changes: 38 additions & 0 deletions
38
packages/vchart/__tests__/visual/cases/charts/sankey/common-sankey-scrollbar.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { assertionError } from '../../../assertions.mjs'; | ||
| import { interactionFrame } from '../../../interaction-helpers.mjs'; | ||
| import sankeyScrollbar from './sankey-scrollbar.mjs'; | ||
|
|
||
| /** | ||
| * 验证目的:组合图在已有 Stage 上启用桑基滚动后可查看被裁剪的内容。 | ||
| * 图表类型:common,包含 sankey 系列。 | ||
| * 关键配置:通过 updateSpecSync 为系列添加 overflow: 'scroll'。 | ||
| * 场景条件:三层固定流向,缩窄绘图区后链接仍宽于视口。 | ||
| * 最终检查:Stage 被复用,且真实滚轮和滑块拖动都能移动内容。 | ||
| * 覆盖边界:VChart 创建的 Stage 和横向溢出。 | ||
| */ | ||
| function createSpec(overflow) { | ||
| const { data, overflow: _overflow, ...series } = sankeyScrollbar.createSpec(); | ||
| return { | ||
| type: 'common', | ||
| data, | ||
| series: [{ ...series, dataIndex: 0, ...(overflow ? { overflow } : {}) }] | ||
| }; | ||
| } | ||
|
|
||
| export default { | ||
| createSpec: () => createSpec(), | ||
| async exercise(page) { | ||
| const reusedStage = await page.evaluate(spec => { | ||
| const chart = window.__visualChart; | ||
| const stage = chart.getStage(); | ||
| chart.updateSpecSync({ ...spec, animation: false }); | ||
| return chart.getStage() === stage; | ||
| }, createSpec('scroll')); | ||
| if (!reusedStage) { | ||
| throw assertionError('开启桑基滚动时应复用组合图的 Stage'); | ||
| } | ||
| await interactionFrame(page); | ||
| await sankeyScrollbar.exercise(page); | ||
| }, | ||
| verify: sankeyScrollbar.verify | ||
| }; |
115 changes: 115 additions & 0 deletions
115
packages/vchart/__tests__/visual/cases/charts/sankey/sankey-scrollbar.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { assertionError } from '../../../assertions.mjs'; | ||
| import { verifyRendered } from '../../../helpers.mjs'; | ||
| import { interactionFrame, interactionTarget } from '../../../interaction-helpers.mjs'; | ||
|
|
||
| /** | ||
| * 验证目的:防止 #4577 的桑基图横向滚动失效。 | ||
| * 图表类型:sankey。 | ||
| * 关键配置:overflow: 'scroll'、固定 linkWidth。 | ||
| * 场景条件:三层固定流向,缩窄绘图区后链接仍宽于视口。 | ||
| * 最终检查:真实滚轮和滑块拖动均移动内容,根组视口随绘图区调整。 | ||
| * 覆盖边界:横向溢出和桌面指针交互。 | ||
| */ | ||
| const wheelDelta = 100; | ||
|
|
||
| async function readViewport(page) { | ||
| return page.evaluate(() => { | ||
| const [series] = window.__visualChart.getChart().getAllSeries(); | ||
| const { width, height } = series.getRootMark().getProduct().attribute; | ||
| return { width, height, region: series.getRegion().getLayoutRect() }; | ||
| }); | ||
| } | ||
|
|
||
| async function readScroll(page) { | ||
| return page.evaluate(() => { | ||
| const [series] = window.__visualChart.getChart().getAllSeries(); | ||
| const group = series.getRootMark().getProduct(); | ||
| const scrollbar = group.parent.children.find( | ||
| child => child.isScrollBar && child.attribute.direction === 'horizontal' | ||
| ); | ||
| return { | ||
| offset: group.attribute.scrollX ?? 0, | ||
| range: scrollbar?.attribute.range, | ||
| name: scrollbar?.name | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| export default { | ||
| createSpec() { | ||
| return { | ||
| type: 'sankey', | ||
| overflow: 'scroll', | ||
| linkWidth: 450, | ||
| nodeWidth: 20, | ||
| categoryField: 'name', | ||
| nodeKey: 'name', | ||
| sourceField: 'source', | ||
| targetField: 'target', | ||
| valueField: 'value', | ||
| data: [ | ||
| { | ||
| values: [ | ||
| { | ||
| nodes: [{ name: 'Source' }, { name: 'Process' }, { name: 'Target' }], | ||
| links: [ | ||
| { source: 'Source', target: 'Process', value: 8 }, | ||
| { source: 'Process', target: 'Target', value: 8 } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }; | ||
| }, | ||
|
|
||
| async exercise(page) { | ||
| const initial = await readViewport(page); | ||
| await page.evaluate(() => window.__visualChart.resize(640, 520)); | ||
| await interactionFrame(page); | ||
| const resized = await readViewport(page); | ||
| const point = await interactionTarget(page, 'node'); | ||
| await page.mouse.move(point.x, point.y); | ||
| await page.mouse.wheel(wheelDelta, 0); | ||
| await interactionFrame(page); | ||
|
|
||
| const wheel = await readScroll(page); | ||
| if (wheel.offset !== -wheelDelta || !wheel.name || !(wheel.range?.[0] > 0)) { | ||
| throw assertionError(`横向滚轮应将内容偏移至 -${wheelDelta}px 并显示滚动条,实际为 ${JSON.stringify(wheel)}`); | ||
| } | ||
|
|
||
| // 从已渲染的滑块起拖,避免把轨道点击误判为拖动。 | ||
| const slider = await page.evaluate(name => { | ||
| const scrollbar = window.__visualChart.getStage().find(graphic => graphic.name === name, true); | ||
| const thumb = scrollbar.find(graphic => graphic.name === 'slider', true); | ||
| if (!thumb) throw new Error('缺少可拖动的桑基图滚动条滑块'); | ||
| const { x1, y1, x2, y2 } = thumb.globalAABBBounds; | ||
| return { x: (x1 + x2) / 2, y: (y1 + y2) / 2 }; | ||
| }, wheel.name); | ||
| await page.mouse.move(slider.x, slider.y); | ||
| await page.mouse.down(); | ||
| await page.mouse.move(slider.x + 60, slider.y, { steps: 5 }); | ||
| await page.mouse.up(); | ||
| await interactionFrame(page); | ||
| await page.evaluate(result => (window.__sankeyScrollExercise = result), { initial, resized, wheel }); | ||
| }, | ||
|
|
||
| async verify(page) { | ||
| await verifyRendered(page); | ||
| const { initial, resized, wheel } = await page.evaluate(() => window.__sankeyScrollExercise); | ||
| if ( | ||
| initial.width !== initial.region.width || | ||
| initial.height !== initial.region.height || | ||
| resized.width !== resized.region.width || | ||
| resized.height !== resized.region.height || | ||
| resized.width >= initial.width || | ||
| resized.height >= initial.height | ||
| ) { | ||
| throw assertionError('桑基图滚动视口的宽高应随绘图区缩小'); | ||
| } | ||
| const dragged = await readScroll(page); | ||
| if (!(dragged.offset < wheel.offset && dragged.range?.[0] > wheel.range[0])) { | ||
| throw assertionError(`拖动滑块应继续移动桑基图内容,实际为 ${JSON.stringify(dragged)}`); | ||
| } | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.