epochjs / epoch

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

Variable range on realtime (line) plots #156

Closed Dav1dde closed 9 years ago

Dav1dde commented 9 years ago

E.g. I have this graph representing memory useage of a process: screenshot from 2015-02-22 12 42 05

Now I can't set a fixed range from 0 to let's say 1GiB, because memory useage depends heavily on the circumstances, or in this example the memory useage doesn't change for the duration of the plot, as you can see, that really messes with Epoch, also triggering an exception (line 8, Uncaught TypeError: Cannot read property 'x' of undefined):

    Plot.prototype._updateTicks = function(newTime) {
      if (!(this.hasAxis('top') || this.hasAxis('bottom'))) {
        return;
      }
      if (!((++this._tickTimer) % this.options.ticks.time)) {
        this._pushTick(this.options.windowSize, newTime, true);
      }
      if (!(this._ticks[0].x - (this.w() / this.pixelRatio) >= 0)) {
        return this._ticks[0].exit = true;
      }
    };

I am not sure how to properly fix this, maybe replace the range option with an extent function (as called from the code)? Or an extent option which takes precedence over the range option.

rsandor commented 9 years ago

@Dav1dde - Can you provide me with some sample data so I can test on my end?

cbdonohue commented 9 years ago

I can confirm this. If the real time chart only receives the same value over and over it never draws the Y axis ticks or values.

cbdonohue commented 9 years ago

any idea how we can set a minimum Y axis scale to prevent this from happening?

Dav1dde commented 9 years ago

I did patch this functionallity into epoch manually. You can check the last commits https://github.com/Dav1dde/epoch/commits/master - this is just a quick and dirty (not even fix) workaround which adds a range option to pick the min and max based on the current values shown.

cbdonohue commented 9 years ago

Thanks, @Dav1dde , I grabbed your changes. However, the scale is now always the same and doesn't expand like before. I wish there was some way to set a minimum value and still allow the graph to expand if necessary.

Dav1dde commented 9 years ago

@cbdonohue This should work, use a function as range option. You can see it in action here: https://github.com/Dav1dde/mcw/blob/master/mcw/static/js/backend.js#L67-L73 (disclaimer the code is pretty messy, again ..)

rsandor commented 9 years ago

Looks like a fix for this exists, but hasn't been implemented as a PR on the repository. Any takers?

rsandor commented 9 years ago

@Dav1dde, @cbdonohue - Looking over this again I see that this ticket is actually reporting two problems that have been reported by others and are now fixed as of the latest version of epoch.

The first problem, an error being thrown with cannot property 'x' of undefined was fixed with #203. The second, variable extent-based axes for real-time charts, was fixed with the introduction of multi-axes in #198.

Seeing as the issues are now resolved, I am going to close this ticket. Feel free to ask questions here or continue the conversation.