epochjs / epoch

A general purpose, real-time visualization library.
http://epochjs.github.io/epoch
MIT License
4.97k stars 279 forks source link

Created addData method #218

Open Marco-Sulla opened 8 years ago

Marco-Sulla commented 8 years ago

I created an addData method, useful if you want append new data instead of replace it entirely. This is useful to me because server does not send 1 datum to my clients every 1 second, but it sends an array of data every 50 seconds. So I can't use time.line.

Code is written in Javascript. I do not know CoffeScript, so I can't create a pull request.

  Base.prototype.addData = function(data, options) {
    var prepared;
    if (options == null) {
      options = {};
    }
    prepared = this._prepareData((this.rawData = this._formatData(data)));

    var values;
    var toadd_values;
    var add_data = this._annotateLayers(prepared);

    for (var i=0; i<this.data.length; i+=1) {
        values = this.data[i].values;
        toadd_values = add_data[i].values;

        values.push.apply(values, toadd_values);
    }

    return this.data;
  };
rsandor commented 8 years ago

So Coffeescript is a 1-to-1 translation of JavaScript. This means that your implementation should be able to be easily transformed in its current state. Please give it a go (even if it doesn't work right off the bat) and I can help you get it all the way via a PR :)

To get started check out the various methods already implemented in the library and use this as a simple reference: http://coffeescript.org/

Marco-Sulla commented 8 years ago

Well, check it: https://github.com/epochjs/epoch/pull/220

PS: do you think it's possible to change the behavior of time.line so push() can accept an array of values instead of a single value only?