Forum Discussion
Issue implementing a context menu
Hi angelflight,
Try casting your eventTarget to d3.BaseType, e.g.:
let dataPoint = d3.select(<d3.BaseType>eventTarget).datum();
Here's the pointer to a working example in one of my visuals for context.
Regards,
Daniel
- angelflight5 years agoFrequent Visitor
Thank you dm-p and Greg_Deckler for your suggestions. Neither quite worked for me. Pardon my lack of experience, but EventTarget does not appear to have any attributes, leading me to think one needs to use that reference in some selector to get at the attributes. Setting the type like this let dataPoint = d3.select(<d3.BaseType>eventTarget).datum(); worked somewhat, but then dataPoint did not have a selectionId attribute. Seems like d3.select wants the selector to be a string. Ultimately, I solved the problem by cheating. Since I only want one context menu to appear no matter where the user clicks, I hard-coded the reference:
svg.on('contextmenu', () => {
const mouseEvent: MouseEvent = d3.event as MouseEvent;
let dataPoint: any = d3.select("svg").datum();
this.selectionManager.showContextMenu(dataPoint ? dataPoint.selectionId : {}, {
x: mouseEvent.clientX,
y: mouseEvent.clientY
});
mouseEvent.preventDefault();
});Thanks again for your help!