Repository navigation
fix: reconcile label lines during label updates #2161
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
1
commit into
develop
Choose a base branch
from
codex/fix-label-line-update
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.
+148
−6
Open
Changes from all commits
Commits
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
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
61 changes: 61 additions & 0 deletions
61
packages/vrender/__tests__/visual/cases/label-line-update.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,61 @@ | ||
| import { assertionError } from '../assertions.mjs'; | ||
|
|
||
| /** 创建带引线的柱条标签。标签位置变化时,引线随实际布局生成。 */ | ||
| export function createSpec(v, stage) { | ||
| const bar = v.createRect({ x: 60, y: 60, width: 160, height: 56, fill: '#a6c8f2' }); | ||
| const label = new v.RectLabel({ | ||
| type: 'rect', | ||
| data: [{ id: 'total', text: 'Total' }], | ||
| getBaseMarks: () => [bar], | ||
| position: 'right', | ||
| offset: 24, | ||
| line: { visible: true, style: { stroke: '#2d548c', lineWidth: 2 } }, | ||
| textStyle: { fontSize: 18, fontFamily: 'Arial', fill: '#222222' }, | ||
| smartInvert: false, | ||
| overlap: false, | ||
| animationEnter: false, | ||
| animationExit: false, | ||
| animationUpdate: { duration: 100, easing: 'linear', increaseEffect: false } | ||
| }); | ||
| stage.defaultLayer.add(bar); | ||
| stage.defaultLayer.add(label); | ||
| return { bar, label }; | ||
| } | ||
|
|
||
| /** 通过公开更新接口将同一标签移入柱条,再移回外侧。 */ | ||
| export async function exercise(page) { | ||
| const removed = await page.evaluate(() => { | ||
| const objects = window.__visualObjects; | ||
| const { label } = objects; | ||
| const oldLine = label.getChildren().find(child => child.type === 'line'); | ||
| if (!oldLine) return false; | ||
|
|
||
| objects.oldLine = oldLine; | ||
| objects.outsideX = label.getChildren().find(child => child.type === 'text').attribute.x; | ||
| label.setAttribute('position', 'inside-middle'); | ||
| return !oldLine.parent && label.getChildren().every(child => child.type !== 'line'); | ||
| }); | ||
| if (!removed) throw assertionError('标签移入柱条后引线未移除'); | ||
| await page.waitForFunction(() => { | ||
| const { bar, label } = window.__visualObjects; | ||
| return label.getChildren().find(child => child.type === 'text').attribute.x < bar.AABBBounds.x2; | ||
| }); | ||
| await page.evaluate(() => window.__visualObjects.label.setAttribute('position', 'right')); | ||
| } | ||
|
|
||
| /** 更新动画结束后,确认同一标签外侧只绘制一条引线。 */ | ||
| export async function verify(page) { | ||
| await page.waitForFunction(() => { | ||
| const { label, outsideX } = window.__visualObjects; | ||
| const text = label.getChildren().find(child => child.type === 'text'); | ||
| return Math.abs(text.attribute.x - outsideX) < 0.01; | ||
| }); | ||
| const ok = await page.evaluate(() => { | ||
| const { label, oldLine } = window.__visualObjects; | ||
| const children = label.getChildren(); | ||
| const lines = children.filter(child => child.type === 'line'); | ||
| window.__visualStage.render(); | ||
| return children.length === 2 && lines.length === 1 && lines[0] !== oldLine && lines[0].attribute.points.length === 2; | ||
| }); | ||
| if (!ok) throw assertionError('外侧标签和引线的最终绘制不正确'); | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Keep a restored label line aligned with the animated text
When a label moves from
inside-middleback torightwithanimationUpdateenabled (the new visual case does exactly this),_createLabelLinebuildscurLabelLinefrom the destination text bounds._runUpdateAnimationanimates the existing text, butLabelUpdate.onBindonly animates a line when bothprevLabelLineandcurLabelLineexist. This branch therefore adds the new line immediately at its final points while the displayed text is still moving from inside the bar. The connector is visibly detached for the animation duration. Start or update the restored line in sync with the text, and assert an intermediate animation frame in the visual case.