Created on September 23, 2014 03:03 | Updated about 5 years ago

**Link:** https://gist.github.com/jywarren/b2d8138f34c9b587cffe

Clip off the top and bottom 2% by area from each end of the data (averaging for multiple graphs) for a better use of graph real-estate on SpectralWorkbench.org

// clip off the top and bottom 2% by area from each end of the data (averaging for multiple graphs) for a better use of graph real-estate on SpectralWorkbench.org setup: function() { // code to run on startup var area = 0, end = 0, start = 0 // go through each spectrum $.each($W.data,function(index,spectrum){ // calculate total area: $.each(spectrum.data,function(i,v){ area += v[1] }) }) // average area: area /= $W.data.length // start at beginning $.each($W.data,function(index,spectrum){ // now find the halfway point var count = 0 $.each(spectrum.data,function(i,v){ // continue if still under 2% of area: if (count < area/50) { count += v[1] } else { start += v[0] return false } }) // start at end var count = 0 $.each(spectrum.data.reverse(),function(i,v){ // continue if still under 2% of area: if (count < area/50) { count += v[1] } else { end += v[0] return false } }) }) end /= $W.data.length start /= $W.data.length flotoptions.xaxis.min = start flotoptions.xaxis.max = end $W.plot = $.plot($("#graph"),$W.data,flotoptions); }, draw: function() { // code to run every frame }