Signal for mouse right click undefined?

232 views
Skip to first unread message

Olivia Xu

unread,
Sep 20, 2016, 2:24:01 AM9/20/16
to vega-js
view.on('contextmenu', (event, item) => { console.log(item); }); would give me streams.js:218 Uncaught TypeError: Cannot read property 'addListener' of undefined.
Same for view.onSignal for a signal of type contextmenu. 

Am I missing something here? What should be the right event type to listen to if I want to detect mouse right click?

Arvind Satyanarayan

unread,
Sep 20, 2016, 1:33:15 PM9/20/16
to Olivia Xu, vega-js
Hi Olivia,

That error suggests that you're referencing a signal value in your specification that does not exist. view.on/onSignal should not hit that specific line. Perhaps you have a typo?

You should use view.on to register event handlers (i.e., for normal DOM events such as mousedown, click, etc.). The callback function has the signature you have above (event, item). view.onSignal registers a *signal* listener instead -- i.e., the callback fires only when the given signal value changes. This callback has a signature of (name, value). More information is available at the bottom of https://github.com/vega/vega/wiki/Runtime

Hope that helps!

-Arvind
-----
Arvind Satyanarayan <http://arvindsatya.com/>

--
You received this message because you are subscribed to the Google Groups "vega-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vega-js+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Olivia Xu

unread,
Sep 20, 2016, 4:28:25 PM9/20/16
to vega-js, ee07...@gmail.com
Right. I think that was a typo. The error comes from 

"signals": [{
"name": "rightclick",
"streams": [{
"type": "contextmenu",
"expr": "eventItem()"
}]

I think vega doesn't support right click (contextmenu) for signal type?
To unsubscribe from this group and stop receiving emails from it, send an email to vega-js+u...@googlegroups.com.

Olivia Xu

unread,
Sep 21, 2016, 12:13:09 AM9/21/16
to vega-js, ee07...@gmail.com

Roy I

unread,
Sep 21, 2016, 6:05:33 PM9/21/16
to vega-js
Try: 
      view.on("mousedown", function(event, item) { if(event.button == 3){ ... } })

For example, in the Vega online example "shiftclick-select" at
try changing the line 
      "streams": [{"type": "click", "expr": "event.shiftKey"}]
to:
      "streams": [{"type": "mousedown", "expr": "event.button == 3"}]

Notes:
1. event.button == 3 works on my computer (Windows 7, IE11 / Google Chrome 53.0.2785.116 m)
   (event.button == 2 did not work for me but may work on other computers).
   See:

2. The browser also shows it's own context pop-up menu with right click.

Olivia Xu

unread,
Oct 18, 2016, 4:51:59 PM10/18/16
to vega-js
It seems like only button 2 works for me for both Windows and mac.
Reply all
Reply to author
Forward
0 new messages