It's quite simple.
Imagine you have 1M points and 1K pixels wide canvas (for sake of simplicity).
You can't draw all 1M points, many of them will overlap in the same pixel.
Divide amount of points you have by the width of the canvas (in pixels).
In example above you'll end up with 1K points per canvas pixel (width-wise).
All this 1K points can be represented using only two points as a single vertical line resulting in 98% compression.
Just go through the points and record lowest and highest Y value, then create a line using those two values and X of the canvas pixel and you're done.
Repeat it 1K times and you'll end up with 98% less data to draw.
You have to do that every time data or canvas size changes. Also when you zoom in, you effectivley change the data available to draw so you have to recalculate.
Bookmarks