Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for adding multiple events? #432

Closed
anurag6792 opened this issue Nov 30, 2016 · 5 comments
Closed

API for adding multiple events? #432

anurag6792 opened this issue Nov 30, 2016 · 5 comments

Comments

@anurag6792
Copy link

Is there an API for adding multiple events?

@sehmon
Copy link
Member

sehmon commented Nov 30, 2016

Hi!

Can you please elaborate what kind of API you were imagining for this feature?

Thanks!

@anurag6792
Copy link
Author

What I need is that , if it was possible to add multiple events . As of now I found that the 'add' method adds only one event.In our case there are more than one event that needs to be added.What we are doing is that we are looping in each event that needs to be added.So there is a performance issue in that.The browser hangs till the loop finishes.So can you suggest something for it?
Apart from this I have more question that dragging along the timeline doesn't work.But when we swipe through mouse pad of laptop it works.Is this an issue?

Thanks!

@shaula
Copy link

shaula commented Feb 17, 2017

I had the same issue and I hacked into the library a bit...but it fails to work properly.

I added just this code to my custom JS:

    TL.Timeline.prototype.addBatch = function (events) {
      for (var i in events) {
        this._addDeferred(events[i]);
      }

      // FIXME: Sorting destroys grouping
      TL.DateUtil.sortByDate(this.config.events);
      TL.DateUtil.sortByDate(this.config.eras);

      this._storyslider._updateDrawSlides();
      this._timenav._updateDrawTimeline(false);

      for (i in events) {
        this.fire("added", {unique_id: events[i].unique_id});
      }
    };

    TL.Timeline.prototype._addDeferred = function (data) {
      var unique_id = this.config.addEvent(data, true); // defer sorting

      var n = this._getEventIndex(unique_id);
      var d = this.config.events[n];

      this._storyslider.createSlide(d, this.config.title ? n+1 : n);
      this._timenav.createMarker(d, n);
    };

From the outside just call timeline.addBatch(eventArray);.
The issue with this code is (see https://jsfiddle.net/0qta1cu8/3/):

  • "Group A" is shown twice - this is a bug described also in Duplicate group on zoom at specific browser sizes #378.
  • The date ordering is wrong when adding in batch mode, but good when doing one by one. Additionally the group assignment is wrong (not only the label).
    • If I omit (comment out) the 2 lines for sortByDate, then it looks better, but the navigation is broken.

Maybe you can give me a hint where I made a mistake.

@randragon42
Copy link

@shaula were you able to come up with a solution that worked? I am currently facing the same issue.

@JoeGermuska
Copy link
Member

We will readily admit that TimelineJS was not really developed with a full MVC model. That is, when event "model objects" are added or changed, the corresponding views don't automatically update.

Support for that was not a primary use case, and to correct the data/lifecycle issues in the current codebase would be no small project, especially given that our design target for TimelineJS is storytelling, which is usually not so dynamic.

You are almost certainly better off just manipulating a JSON representation of the timeline and instantiating a new timeline when you need it. If you wanted the viewer to stay on the same slide they were at, you'd need to take some more steps, but that would still probably be easier than reimplementing the existing codebase as proper MVC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants