Search code examples
javascriptdygraphs

Avoid cleaning canvas in updateOptions call


I am working in a signals plot program trying to simulate the 'persistence' feature as available in many oscilloscopes.

I would like to prevent dygraph canvas to clean for every updateOptions call. Instead of that, my plot should be preserved until an explicit call for cleaning. This feature will allow me to check if a signal preserves its phase during a certain amount of time.

I tried to use block_redraw parameter set to false in updateOptions function without no success.

Any ideas?


Solution

  • This isn't really something dygraphs is designed to do. You're asking it to render the full history of its data source, rather than the current state of its data source.

    That being said, here's the code that clears the plotting canvas:

    DygraphCanvasRenderer.prototype.clear = function() {
      this.elementContext.clearRect(0, 0, this.width, this.height);
    };
    

    So if you override that, it might do what you want:

    DygraphCanvasRenderer.prototype.clear = function() {};
    

    That being said, this is liable to break lots of things (like zooming and panning) in addition to giving you the behavior you want. You can see this if you visit the live random data demo page and copy that snippet into the JS console.

    Good luck!