danchitnis/webgl-plot

Auto scale canvas

Tenshinra opened this issue · 1 comments

Describe the bug
Is there any way to have the canvas auto scale based on the received data? For example if at the beginning we receive 1,2,3,4 and we plot those points but then we get 800, 900, 1000, any way to plot those points without them being out of the canvas?

yes absolutely. you can do this by changing the gScaleY parameter. you need to find the maximum value yourself and then set a new gScaleY according to the new scale that you want to display. Don't forget to update(). Notice that the scaling happens on the GPU and you can run it at every frame with little to no overhead, however, finding the maximum is CPU based and may slow down your process.

See this example. (you may need to click the refresh icon in the preview window on the right side)