I am drawing a histogram using an array of data (counts) and an array to represent the histogram. I want to zoom into the data so that the number of points in the histogram is typically fewer than the data points that I have.
I need to map the data array to the histogram array such that when the histogram is exactly half the length of the data then each point is the sum of two data points, when it is 1.5 times then each histogram point is the sum of one data point plus half of the value of the next. Etc.
E.g
Data |2|3|1|2|2|3|4|1|
Hist | 5 | 3 | 5 | 5 |
Data | 2| 3| 1| 2| 2| 3| 4| 1|
Hist | 3.5|2.5| 3 | 4 | 4.5 |
It seems like it could be a common problem (particularly for zooming images) but I have not found a library or function to do it. Does such as JavaScript thing exist?
This seems to be a pretty straight-forward algorithm:
And call it like this:
I created a jsfiddle for you to play around with: http://jsfiddle.net/3RVKr/