plotly_click handler return value is ignored, no way to cancel event processing from custom handler
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 18.3k
- 派生
- 2k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 28
描述
I'm currently using a plotly_click custom handler (via react-plotly onClick prop) on a treemap, where I would like to cancel the default zoom-in / zoom-out behaviour if the user is pressing control.
For plotly_legendclick for example, the convention is to return false from the custom handler, which will stop default event processing. See https://community.plotly.com/t/disable-legend-click-functionality-hiding-traces/1345/4 for @alexcjohnson 's reply in this regard.
However, for the plotly_click event I've traced the code into this little section in plotlyjs attachFxHandlers.onClick():
var clickVal = Events.triggerHandler(gd, 'plotly_' + trace.type + 'click', typeClickEvtData);
if(clickVal !== false && fullLayoutNow.hovermode) {
gd._hoverdata = [makeEventData(pt, traceNow, opts.eventDataKeys)];
Fx.click(gd, d3.event);
}
// 2 lines ommitted
// if custom handler returns false, we're done!
if(clickVal === false) return;
So the event for plotly_treemapclick in this case will honour the convention as can be seen from the clickVal = ..., but the standard plotly_click handler is invoked by the Fx.click() invocation, which ignores the handler return values.
Unfortunately, the call chain from Fx.click() is quite deep: onClick() -> click() -> emitClick() -> plotObj.emit() -> emit() -> emitOne() -> customHandler. To bring back the return value is going to be quite the adventure. Also, at some spots along the chain, return values are used for a different purpose.
Alternatively, the code in the uppermost onClick() could for example check event.defaultPrevented -- this is not quite the Plotly convention, but then again that convention is not very well documented at all, and this would be far more straight-forward to implement rather than bringing back the custom handler return value. Furthermore, many javascript programmers know to look for preventDefault.
In addition, this fix would immediately also work from React.
What do people think about this?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 attachFxHandlers.onClick() 开始,然后沿着文档记录的 Fx.click() 调用链跟踪 click()、emitClick()、plotObj.emit()、emit() 和 emitOne()。将 plotly_treemapclick 的返回值处理与标准的 plotly_click 路径进行比较,并确定取消应如何传播。当返回 false 或以其他受支持的方式处理的自定义处理程序能够阻止默认点击处理(包括通过 React)时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, react
- 领域
- data-visualization, frontend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 32/100