How to temporarily disable flot.selection for a plot?

41 views
Skip to first unread message

MissyLaMotte

unread,
Jul 17, 2019, 3:37:54 AM7/17/19
to Flot graphs
I have a plot where the user can choose between different selection types to zoom into the displayed data. That works really well, I can switch between x, y and xy without problems.

Since the data is constantly updating, there are also situations where I would like to forbid selecting at all. Instinctively I would have thought

plot.getOptions().selection.mode = null;

would do that, but it only resets selection to the default 'xy' mode. I can unbind the plotselect event handler, of course, but selecting is still possilble (the rectangle shows up), even if nothing happens with it.

I also tried setting

plot.getOptions().selection = null;

but that leads to an error, because the selection plugin is still working and trying to access the selection mode.

Is there any way I can switch off the selection functionality altogether without having to build a new plot?

Thanks,
Jutta

Andrew Dove

unread,
Jul 17, 2019, 9:18:02 AM7/17/19
to Flot graphs
You are correct - there should be a way to turn of the selection and there isn't. Please file an issue in the flot Github repo. However there is a slightly hacky way to turn off the selection - that is to make the color transparent and then ignore the plot-selected event.

MissyLaMotte

unread,
Jul 17, 2019, 9:44:13 AM7/17/19
to Flot graphs
Thanks for the suggestion and for confirming that it indded doesn't work. I was starting to doubt my sanity ;)

I solved the problem by tweaking my local version of the plugin a bit. It now only reacts to the mousedown event if the mode is not 'null'. Otherwise it just does not start selecting.

function onMouseDown(e) {
    var o = plot.getOptions();
    if ((e.which != 1) || (o.selection.mode == null)) // only accept left-click and now also check if selection has been turned off
        return;

...

Andrew Dove

unread,
Jul 17, 2019, 9:53:48 AM7/17/19
to Flot graphs
This seems like a reasonable fix - I will use it
Reply all
Reply to author
Forward
0 new messages