Additive zoom level decomposition for e-profile Part II

How to add adaptive zoom levels to your interactive graphics

 

Today the first approach  failed, badly.

If you give your data a fixed grid for the zoom levels you will fail on isolated datapoints.

Imagine you have a single datapoint for a whole day. If you apply the 2^N grid the datapoint will arbitraribly be placed on a zoom level.

812141218

111111111

212121212

111111111

412141214

111111111

212121212

111111111

812141218

 

But you would like to have it on the top zoom level.

So I needed a new algorithm with the following recursive speudo code:

def set_zoom_level(interval, zoom_level)
    How many datapoints are in the interval?

        If 0, then return.

        If  1, assign this datapoint the current zoom_level and return

        if > 1:

            assigne first datapoint zoom_level

            Interval1, interval2 =  left/right part of interval

            set_zoom_level(interval1, zoom_level + 1)

            set_zoom_level(interval2, zoom_level + 1)

 

While I was quite sure what I was looking for it took me some time to find the appropriate algorithm: Quad Tree area subdivision.

There is a really capable Python implementation I shamelessly borrowed from.

But the Quadtree as such does not solved my problems for zooming. It had to be modified - stay tuned for the solution.

Please read on in Part III

Update: The modification of the quadtree algorithm in Part III is not optimal. 

Plaese proced to Part IV