plotly_click handler return value is ignored, no way to cancel event processing from custom handler
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 18.3k
- Forks
- 2k
- Ø Merge
- 2 T. 12 Std.
- Gemergte PRs (30 T.)
- 28
Beschreibung
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?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne bei attachFxHandlers.onClick() und verfolge anschließend die dokumentierte Fx.click()-Kette durch click(), emitClick(), plotObj.emit(), emit() und emitOne(). Vergleiche die Behandlung des Rückgabewerts von plotly_treemapclick mit dem standardmäßigen plotly_click-Pfad und ermittle, wie sich die Abbruchanforderung fortpflanzen sollte. Als erledigt gilt die Aufgabe, wenn ein benutzerdefinierter Handler, der false zurückgibt oder auf andere Weise unterstützt wird, die standardmäßige Klickverarbeitung verhindern kann, auch über React.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, react
- Bereich
- data-visualization, frontend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 32/100