fix: skip default select when interactions already registers element-select - #4696
Conversation
…select When spec.interactions includes element-select (including isMultiple: true), do not also register the default single-select trigger so the two do not fight. Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
xile611
left a comment
There was a problem hiding this comment.
@dyk1454683243-sudo 已完成 review。这个改动确实修复了饼图 interactions: [{ type: 'element-select', isMultiple: true }] 与默认单选冲突的问题,但目前会关闭自定义交互作用范围以外的默认选中,建议修复这一回归后再合并。
验证基线 c4191139a340f18f0e32dcb353c51009d88a6205 与 PR 312350584a389c56dbfc6010f6cdceb8591509b0:
| 场景 | 基线 | PR |
|---|---|---|
| 饼图连续点击两个扇区(配置 selected 样式) | 仅保留一个选中 | 正确多选 |
| 柱线组合图仅对 bar 配置 element-select,点击折线 point | 正常选中 | 无法选中 |
| 折线图仅对 line 配置 element-select,点击 point | 正常选中 | 无法选中 |
本地补充用例通过真实 VChart 创建图元,在 Node + canvas 环境显式配置 select: { trigger: 'pointertap' },通过已注册的事件处理器依次发送 pointertap / click;没有手动修改系列字段或替换图元。未做浏览器鼠标实测。PR 自带 3 个测试及修改文件的 ESLint、Prettier 均通过,但未覆盖限定 markNames 的场景。
请在解析实际匹配的图元后处理冲突,保留未被自定义交互覆盖的图元的默认选中;同时补充上述局部图元、跨系列场景的回归测试。具体位置见行内意见。
| if (interactions?.some(interaction => interaction.type === TRIGGER_TYPE_ENUM.ELEMENT_SELECT)) { | ||
| const defaultSelectIndex = res.findIndex(item => item.trigger.type === TRIGGER_TYPE_ENUM.ELEMENT_SELECT); | ||
| if (defaultSelectIndex >= 0) { | ||
| res.splice(defaultSelectIndex, 1); |
There was a problem hiding this comment.
[P2] 保留自定义交互作用范围外的默认选中
这里只要存在 element-select 就删除整个默认 select,忽略了 markNames / markIds 的作用范围。例如柱线组合图在图表级配置 interactions: [{ type: 'element-select', markNames: ['bar'], isMultiple: true }]:该配置会传给两个系列,折线系列虽然没有匹配的 bar 图元,也会先删除默认 select,随后又因匹配结果为空而不注册自定义交互,最终折线点完全无法选中。单个折线图配置 markNames: ['line'] 时,未被覆盖的 point 同样失去选中能力。上述两个场景均已验证基线通过、PR 失败。请先解析实际匹配的图元,仅处理重叠范围内的冲突,保留其他图元的默认选中,并补充回归测试。
Fixes #4563
🤔 This is a ...
🔗 Related issue link
Fixes #4563
💡 Background and solution
Specs that follow the official pie multi-select example:
could not keep more than one sector selected.
Default
select.enable: truestill registered a single-selectelement-selecttrigger (pointertap, replace). The specinteractionsentry registered a second one (click, accumulate). Those configs are notisEqual, soBaseChart._initInteractionskept both live. On click, default select appliedselectedfirst; the multi-select trigger then sawhasStateand did nothing.This change skips the default select trigger when
spec.interactionsalready contains anelement-selectentry. Hover / dimension-hover defaults are unchanged.interactionsmulti-select works withoutselect: falseinteractions) stays single-selectselect: { mode: 'multiple' }withoutinteractionsstill accumulates📝 Changelog
interactionsalready registerselement-select, soisMultiplemulti-select worksinteractions已配置element-select时不再注册默认单选,使isMultiple多选生效☑️ Self-Check before Merge
Verification
eslint --quietonpackages/vchart/src/series/base/base-series.tsand the new test: cleanprettier --checkon the same files: cleanjest __tests__/unit/interaction/element-select.test.ts --runner=jest-runner --testEnvironment=node: 3 passedjest-electronrunner is the default; the node runner is enough for this non-render wiring/state regression.