fix: moasic chart's crosshair can not render rect shape#4561
fix: moasic chart's crosshair can not render rect shape#4561kkxxkk2019 wants to merge 1 commit intodevelopfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes crosshair rect rendering for mosaic-like (reversed start/end) continuous data ranges by normalizing range comparisons and positioning.
Changes:
- Update
getDatumByValueto match values within a range regardless of whetherstartFieldis less than or greater thanendField. - Adjust cartesian crosshair layout logic to anchor
coordat the left edge of a continuous range band (usingMath.min(posStart, posEnd)). - Add unit tests covering reversed-field range lookup and rect crosshair layout behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
packages/vchart/src/component/crosshair/utils/common.ts |
Makes datum lookup range-direction agnostic via min/max bounds. |
packages/vchart/src/component/crosshair/utils/cartesian.ts |
Fixes continuous range band positioning so rect crosshair spans the expected interval (incl. mosaic). |
packages/vchart/__tests__/unit/component/crosshair/crosshair-util.test.ts |
Adds unit coverage for reversed ranges and rect layout/clamping behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| bandSize = Math.abs(posStart - posEnd); | ||
| coord = Math.min(posStart, posEnd); | ||
| value = `${datum[field1]} ~ ${datum[field2]}`; |
There was a problem hiding this comment.
When field2 exists and the underlying data uses reversed start/end fields (e.g. mosaic where field1 can be the larger bound), the label text ${datum[field1]} ~ ${datum[field2]} will render in reversed order (e.g. 0.6 ~ 0.2). Since coord is normalized with Math.min(posStart, posEnd), consider also normalizing the displayed range to ascending order (based on the datum values) so the crosshair label matches the visual rect direction.
| bandSize = Math.abs(posStart - posEnd); | |
| coord = Math.min(posStart, posEnd); | |
| value = `${datum[field1]} ~ ${datum[field2]}`; | |
| const startValue = datum[field1]; | |
| const endValue = datum[field2]; | |
| const [rangeStartValue, rangeEndValue] = | |
| startValue <= endValue ? [startValue, endValue] : [endValue, startValue]; | |
| bandSize = Math.abs(posStart - posEnd); | |
| coord = Math.min(posStart, posEnd); | |
| value = `${rangeStartValue} ~ ${rangeEndValue}`; |
xuefei1313
left a comment
There was a problem hiding this comment.
自动 Review(机器人):
- 关注点:本次 PR 为修复 Mosaic 图的 crosshair 渲染(rect 形状)。
- 建议自查:
- 是否新增/更新了对应的 demo 或单测,覆盖 rect/line 等不同形状;
- crosshair 在不同主题/缩放/高清屏下的边界与对齐;
- 是否影响 tooltip / axis pointer 等相关交互;
- 请以 CI 结果为准,如 CI 全绿且本地验证通过,可考虑合入。
(本评论为自动化提示,不代替人工 Review)
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
🔗 Related PR link
🐞 Bugserver case id
💡 Background and solution
📝 Changelog
☑️ Self-Check before Merge
🚀 Summary
copilot:summary
🔍 Walkthrough
copilot:walkthrough