Mouse Coordinates while holding mouse button

Hi All,

I’m trying to collect the mouse coordinates while using the box selection tool. In essence, I would like to trace the path the user takes while creating the box selection. I’m stuck on cb_data. What properties does this object have? Is there a mouse coordinates property?

I know I need to modify these lines:

// get data source from Callback args
var data = source.get('data');

/// get BoxSelectTool dimensions from cb_data parameter of Callback
var geometry = cb_data['geometry'];

Thanks.

Nobody knows???

Either this is so easy that its obvious or this cant be done. Someone please tell me which it is.

···

On Monday, 21 December 2015 09:04:39 UTC-5, RedRaven wrote:

Hi All,

I’m trying to collect the mouse coordinates while using the box selection tool. In essence, I would like to trace the path the user takes while creating the box selection. I’m stuck on cb_data. What properties does this object have? Is there a mouse coordinates property?

I know I need to modify these lines:

// get data source from Callback args
var data = source.get('data');

/// get BoxSelectTool dimensions from cb_data parameter of Callback
var geometry = cb_data['geometry'];

Thanks.

cb_obj is the "callback object" which it typically whatever object you added a callback too. In this case, a BoxSelectionTool. Callbacks also get an optional hash cb_data that the obejct can pass additional object-specific data in. Tor the BoxSelextionTool, it passes the geometry (used to perform selection hit testing) as a cb_data['geometry']. This geometry depends on the tool that created it: lasso selection tool will define a polygon geometry to hit test with, a tap tool will define a point geometry, and a BoxSelectionTool will generate a rectangle geometry, which looks something like this:

  geometry = { type: 'rect' vx0: vx0 vx1: vx1 vy0: vy0 vy1: vy1 }

Where the vx0, vy0, etc are the "view coordinates" of the opposite corners of the rectangle. To convert them to true canvas coordinates, you'd do something like:

    canvas = @plot_model.get('canvas')

    sx0 = canvas.vx_to_sx(geometry.vx0)
    sx1 = canvas.vx_to_sx(geometry.vx1)
    sy0 = canvas.vy_to_sy(geometry.vy0)
    sy1 = canvas.vy_to_sy(geometry.vy1)

However, this selection geometry only actually occurs (and triggers a callback) when selection events happen. By default this is only on mouse-up (when the selection is "finished". It is possible to set "select_every_mousemove" to true, on the BoxSelectionTool, but this will cause hit testing and selection events every mouse move, which may not be what you want.

So, that's kind of a lot. A few observations:

It should be possible to create a custom Bokeh model that just does what you want and nothing else, and this might be the simples route. See, e.g.:

  https://github.com/bokeh/bokeh/blob/master/examples/glyphs/custom.py

For some examples of custom models.

Finally, most of us are really focused on the UX from python (and that is where most of our experience is) and I would say the JS interface has suffered somewhat for this. If you have experience or suggestions to help the JS side they are definitely welcome.

Thanks,

Bryan

···

On Dec 22, 2015, at 1:41 PM, RedRaven <[email protected]> wrote:

Nobody knows???

Either this is so easy that its obvious or this cant be done. Someone please tell me which it is.

On Monday, 21 December 2015 09:04:39 UTC-5, RedRaven wrote:
Hi All,

I'm trying to collect the mouse coordinates while using the box selection tool. In essence, I would like to trace the path the user takes while creating the box selection. I'm stuck on cb_data. What properties does this object have? Is there a mouse coordinates property?

I know I need to modify these lines:
// get data source from Callback args
var data = source.get('data');

/// get BoxSelectTool dimensions from cb_data parameter of Callback
var geometry = cb_data['geometry'];

Thanks.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/a41526ef-49a8-4df4-b177-612adfee2c97%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.