dygraphs icon indicating copy to clipboard operation
dygraphs copied to clipboard

Attaching and detaching interaction model on button click

Open vdtidake opened this issue 9 years ago • 12 comments

Hi, I want to enable zoom and pan only on a particular button click. I am trying to update interactionmodel using updateoptions but it seems it is not working. Are there any other way to do this?

vdtidake avatar Jul 04 '15 08:07 vdtidake

you could use preventDefault() on the mouse/click events of these regions and enable it with a click or hide the pan and show it on button click, there are many ways of doing this.

mkirkor avatar Jul 06 '15 12:07 mkirkor

I don't think the question is how to do this, but that the mechanism (update options) doesn't work when changing the interaction model. I have experienced that issue was well.

On Monday, July 6, 2015, mkirkor [email protected] wrote:

you could use preventDefault() on the mouse/click events of these regions and enable it with a click or hide the pan and show it on button click, there are many ways of doing this.

— Reply to this email directly or view it on GitHub https://github.com/danvk/dygraphs/issues/640#issuecomment-118847404.

lBowlin avatar Jul 06 '15 14:07 lBowlin

The question is literally : Are there any other way to do this?

mkirkor avatar Jul 06 '15 15:07 mkirkor

Apologies for my reading skills and not making my point well.

You can hijack event listeners from the document, but tracking against the listeners established by Dygraphs (to target the specific region easily) would require hooking into the interaction model right? Or is it possible to hijack dygraphs click/mouse down listeners without utilizing the interaction model at all?

My question (which you have accurately pointed out is different from this one) is why doesn't the built in mechanism for exactly this task not work?

On Monday, July 6, 2015, mkirkor [email protected] wrote:

The question is literraly : Are there any other way to do this?

— Reply to this email directly or view it on GitHub https://github.com/danvk/dygraphs/issues/640#issuecomment-118898640.

lBowlin avatar Jul 06 '15 15:07 lBowlin

Let me clarify my problem statement. I want to enable zoom/pan on a particular button click. By default I don't want any interaction model for the graph. It is not possible to attach interaction model on button click using updateoption. I managed to achieve this using writing conditions in interaction model.

IF button-clicked
      Start Zoom/Pan
ESLE
       Nothing

But this also caused problem in calling pointClickedcallback

vdtidake avatar Jul 06 '15 16:07 vdtidake

You can play with dateWindow and valuerange inside the zoomcallback. Here is a jsfiddle with your desired behavior I believe : http://jsfiddle.net/eM2Mg/6500/

mkirkor avatar Jul 06 '15 16:07 mkirkor

The above simply just masks the problem. If the user were to pan, then try to zoom with the mouse, it would just reset since the zoomCallback is set to the default view. Which means, you would need to modify other callback functions.

I'm having the same issue where calling updateOptions with the interactionModel parameter does not update the interactivity of the graph as initially intended. So this is probably a bug.

LaughDonor avatar Aug 04 '15 21:08 LaughDonor

You are specifically not allowed to update interactionModel. We decided the complexity of supporting that just wasn't worth it.

danvk avatar Aug 04 '15 21:08 danvk

Maybe then a console warning should be delivered to denote this intentional functionality when someone tries to update the interactionModel... Or something.

LaughDonor avatar Aug 04 '15 21:08 LaughDonor

That seems reasonable. Feel free to file an issue (or send a PR).

danvk avatar Aug 04 '15 21:08 danvk

"You are specifically not allowed to update interactionModel. We decided the complexity of supporting that just wasn't worth it."

Then maybe you should remove this:

image

Pierre-Bartet avatar Oct 15 '18 08:10 Pierre-Bartet

As there is no plan to add this feature a ridiculous solution that works is to simply reinitialize the graph with or without your custom interactionModel whenever you need to switch between custom or default behavior.

var options = {
    ...
    interactionModel: { /* your custom model */ },
};
if (default_pan_zoom_behavior) {
    delete options.interactionModel;
}
new Dygraph(element, data, options);

gowhari avatar Jan 23 '20 11:01 gowhari