daattali / timevis

📅 Create interactive timeline visualizations in R
http://daattali.com/shiny/timevis-demo/
Other
655 stars 157 forks source link

Documentation needs JS code example showing how JS obj of timeline is accessed #58

Closed knbknb closed 6 years ago

knbknb commented 6 years ago

This is just a suggestion, thank for providing this R package, great work!

I want to modify the timeline object with Javascript after it has been created from R, and the timeline webpage already exists.

The timevis.js documentation says about the setOptions(options) method :

Set or update options. It is possible to change any option of the timeline at any time. You can for example switch orientation on the fly

Thus, I think the documentation for your library containing the R binding for visjs would be so much more useful to programmers if it also contained a little code example on how the JS timeline object can be accessed with Javascript code.

Looking at the source code of a generated web page does not really help, because everything is hidden in scripts, minified and obfuscated. Looking at the browser's dev tools or cosole does not really help because the autocompleter gives so many objects internal to the browser that the real timeline object is impossible to find interactively.

I have managed to create a new timeline object with JS from embedded JSON data after, say, a user clicked a button, but there must be a more elegant way.

daattali commented 6 years ago

The timeline object itself is not meant to be explicitly exported. I tried to provide an API to access most of what I thought would be needed. For example, setOptions() should work, you don't need to have access to the javascript object, it should be doable using timevis(data) %>% setOptions(...).

It's been a while since I wrote this package and looked at its code so I don't remember exactly how it works. Have you looked at the javascript source code for timevis? (under inst/htmlwidgets/timevis.js) I believe there is a way to retrieve the original visjs timeline object. You may need to consult the visjs timeline documentation to see how to retrieve an existing timeline object based on an id or something of the sort.

knbknb commented 6 years ago

Thanks for responding. What I intended to do was putting a few extra buttons on the generated web page tht adds some interactivity (e.g., stack/unstack, set opacity of items with jQuery("#vis-item").css(), and related actions. Putting buttons on the page is awkward to do in R, at least for me). I thought further customizations like that are a quite common use case.

Maybe I fork your package and write this extra documentation myself. I was just thinking maybe you remember the details and I can spare the effort.

I think I'll close this for now. Will reopen when I have something new.

daattali commented 6 years ago

If any of your new features are things that make sense in general to others and are not shiny specific, I would urge you to fork the actual visjs library and submit a PR there so that your contributions would be available to everyone using the library. For example, the +/- zoom buttons is something that did not exist in visjs so I first added it to timevis but later on also submitted a PR to visjs and now it's in the actual library (IIRC)

On Jul 19, 2018 14:25, "Knut Behrends" notifications@github.com wrote:

Thanks for responding. What I intended to do was putting a few extra buttons on the generated web page tht adds some interactivity (e.g., stack/unstack, set opacity of items with jQuery("#vis-item").css(), and related actions. Putting buttons on the page is awkward to do in R, at least for me). I thought further customizations like that are a quite common use case.

Maybe I fork your package and write this extra documentation myself. I was just thinking maybe you remember the details and I can spare the effort.

I think I'll close this for now. Will reopen when I have something new.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/daattali/timevis/issues/58#issuecomment-406370834, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6IFCzxbrx3lFqCGAS1jH3WOKphAfTOks5uIM8lgaJpZM4VV4_h .