equals - How to calculate axis ticks at a uniform distribution? -
given data range minimum , maximum value, how can 1 calculate distribution of buckets on axis?
the requirements are:
- axis ticks shall evenly distributed (equal size).
- further, ticks shall appear numbers 10, 20, 30, ...
or -0.3, 0.1, 0.2, 0.4, ...
- calculation shall accept parameter defines number of buckets wanted.
the following example calculates maximum of 10 buckets or less.
num buckets = 10 range length = 500 500 / 10 = 50 log_10(50) = 1,69 round up(1,69) = 2 10^2 = 100 bucket size 500 / 100 = 5 buckets
result: there 5 buckets each @ size of 100.
steps produce buckets based on 10^x
0.01, 0.1, 1, 10, 100, 1000 ...
how can 1 calculate buckets size 42 buckets?
i not sure think code can (adapted javascript yui yahoo.util.dragdrop.js)
var initposition = 0; var rangelength = 500; var maxposition = (initposition + rangelength); getticks: function(bucketsize) { var axisticks = []; var tickmap = {}; (i = initposition; <= maxposition; = + bucketsize) { if (!tickmap[i]) { axisticks[axisticks.length] = i; tickmap[i] = true; } } return axisticks; }
the drawback because, sometimes, axis ticks not evenly distributed ((initposition + rangelength) / bucketsize) not return plain integer
Comments
Post a Comment